1 package org.dbe.studio.tools.sdlCompiler2Java.plugin.action;
2
3 import org.dbe.studio.tools.sdlCompiler2Java.Sdl2Java;
4 import org.dbe.studio.tools.sdlCompiler2Java.Sdl2JavaMessages;
5 import org.dbe.studio.tools.sdlCompiler2Java.plugin.SdlCompiler2JavaPlugin;
6 import org.eclipse.core.internal.resources.File;
7 import org.eclipse.core.resources.IProject;
8 import org.eclipse.core.resources.IWorkspaceRoot;
9 import org.eclipse.core.resources.ResourcesPlugin;
10 import org.eclipse.jface.action.IAction;
11 import org.eclipse.jface.dialogs.MessageDialog;
12 import org.eclipse.jface.viewers.ISelection;
13 import org.eclipse.jface.viewers.StructuredSelection;
14 import org.eclipse.swt.widgets.DirectoryDialog;
15 import org.eclipse.ui.IActionDelegate;
16 import org.eclipse.ui.IObjectActionDelegate;
17 import org.eclipse.ui.IWorkbenchPart;
18
19 public class SdlCompiler2WsdlAction implements IActionDelegate{
20
21 org.eclipse.core.internal.resources.File selectedFile;
22 private String fileLocation;
23 private String fileName;
24
25 private IProject pr;
26 private String prName;
27 private String saveDir;
28
29 /***
30 * Constructor for Action1.
31 */
32 public SdlCompiler2WsdlAction() {
33 super();
34 }
35
36 /***
37 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
38 */
39 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
40 }
41
42 /***
43 * @see IActionDelegate#run(IAction)
44 */
45 public void run(IAction action) {
46
47 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
48 prName = pr.getName();
49 IProject project = root.getProject(prName);
50 String basePath = project.getLocation().toFile().getAbsolutePath();
51
52
53 DirectoryDialog dd = new DirectoryDialog(new org.eclipse.swt.widgets.Shell());
54 dd.setFilterPath(basePath);
55 saveDir = dd.open();
56 if ( saveDir == null ) {
57 return;
58 }
59
60 try {
61
62
63 Sdl2Java sdl2java = new Sdl2Java();
64
65
66 sdl2java.setSdl2wsdlTransform(SdlCompiler2JavaPlugin.getXSLContent("sdl2wsdl.xsl"));
67 sdl2java.setWsdl2mjavaTransform(SdlCompiler2JavaPlugin.getXSLContent("wsdl2mJava.xsl"));
68 sdl2java.setMjava2javaTransform(SdlCompiler2JavaPlugin.getXSLContent("mJava2Java.xsl"));
69
70
71 String java = sdl2java.sdl2wsdl(Sdl2Java.loadFile(new java.io.File(fileLocation)));
72
73
74 Sdl2Java.saveFile(new java.io.File(saveDir, fileName.replaceAll(".sdl","") + ".wsdl"), java);
75
76
77 MessageDialog.openInformation(null, Sdl2JavaMessages.MSG_SUCC_SAVE_TITLE, Sdl2JavaMessages.MSG_SUCC_SAVE_WSDL);
78
79 pr.refreshLocal(2,null);
80
81 } catch (Exception e) {
82 System.err.println(e.getMessage());
83 MessageDialog.openError(null, this.getClass().getName(), e.getMessage());
84 e.printStackTrace(System.err);
85 }
86 }
87
88 /***
89 * @see IActionDelegate#selectionChanged(IAction, ISelection)
90 */
91 public void selectionChanged(IAction action, ISelection selection) {
92
93 selectedFile = (File)((StructuredSelection)selection).getFirstElement();
94 fileName = selectedFile.getName();
95 fileLocation = selectedFile.getLocation().toString();
96 pr = selectedFile.getProject();
97
98 return;
99 }
100
101 /***
102 *
103 * @return directory where the file is saved
104 */
105 public String getSaveDir() {
106
107 return saveDir;
108
109 }
110
111 }