1 package org.dbe.studio.tools.ssl2sdl.plugin.action;
2
3 import java.io.FileWriter;
4 import java.io.IOException;
5
6 import org.dbe.studio.tools.ssl2sdl.util.ObtainSSLfromBML;
7 import org.dbe.studio.tools.ssl2sdl.util.SSL2SDLMessages;
8 import org.dbe.studio.tools.ssl2sdl.util.SSL2SDLTransformation;
9 import org.eclipse.jface.action.IAction;
10 import org.eclipse.jface.dialogs.MessageDialog;
11 import org.eclipse.jface.viewers.ISelection;
12 import org.eclipse.jface.viewers.StructuredSelection;
13 import org.eclipse.swt.widgets.DirectoryDialog;
14 import org.eclipse.swt.widgets.Shell;
15 import org.eclipse.ui.IObjectActionDelegate;
16 import org.eclipse.ui.IWorkbenchPart;
17
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.core.resources.IProject;
20 import org.eclipse.core.resources.IWorkspaceRoot;
21 import org.eclipse.core.resources.ResourcesPlugin;
22 import org.eclipse.core.runtime.CoreException;
23 import org.eclipse.core.runtime.IPath;
24
25
26
27 public class SslCompiler2SdlAction implements IObjectActionDelegate
28 {
29
30 org.eclipse.core.internal.resources.File selectedFile;
31
32 private String fileLocation;
33 private IProject pr;
34 private String prName;
35
36 /***
37 * Constructor for Action1.
38 */
39 public SslCompiler2SdlAction()
40 {
41 super();
42 }
43
44 /***
45 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
46 */
47 public void setActivePart(IAction action, IWorkbenchPart targetPart)
48 {
49 }
50
51
52 /***
53 * @see IActionDelegate#run(IAction)
54 */
55 public void run(IAction action)
56 {
57 SSL2SDLTransformation transformation = new SSL2SDLTransformation();
58
59 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
60
61
62 prName = pr.getName();
63 IProject project = root.getProject(prName);
64
65
66 IFile file = project.getFile("aaaaa.txt");
67
68 String inFileString = null;
69 java.io.File temp = null;
70 try {
71 if(selectedFile.toString().endsWith("bml")){
72
73 String fileContent = ObtainSSLfromBML.loadFile(new java.io.File(fileLocation));
74
75 if(fileContent.indexOf("<SSL") > -1){
76
77 inFileString = ObtainSSLfromBML.getSSLfromBML(ObtainSSLfromBML.loadFile(new java.io.File(fileLocation)));
78 temp = java.io.File.createTempFile("temp",null);
79 FileWriter fw = new FileWriter(temp);
80 fw.write(inFileString);
81 fw.close();
82
83 transformation.executeTransformation(project, file, temp);
84 MessageDialog.openInformation(null, SSL2SDLMessages.MESSAGEDIALOG_TITLE, SSL2SDLMessages.MESSAGEDIALOG_BODY_BML);
85
86
87
88 }else{
89 MessageDialog.openWarning(null,SSL2SDLMessages.MESSAGEDIALOG_TITLE, SSL2SDLMessages.MESSAGEDIALOG_WARNIND_NO_SSL);
90 }
91
92 }else if (selectedFile.toString().endsWith("ssl")){
93 java.io.File inFile = new java.io.File(fileLocation);
94
95 transformation.executeTransformation(project, file, inFile);
96 MessageDialog.openInformation(null, SSL2SDLMessages.MESSAGEDIALOG_TITLE, SSL2SDLMessages.MESSAGEDIALOG_BODY_SSL);
97
98 }
99 } catch (Exception e) {
100
101 System.err.println(e.getMessage());
102 MessageDialog.openError(null, SSL2SDLMessages.MESSAGEDIALOG_TITLE, this.getClass().getName()+ " " + e.getMessage());
103 e.printStackTrace();
104 }
105 }
106
107 /***
108 * @see IActionDelegate#selectionChanged(IAction, ISelection)
109 */
110 public void selectionChanged(IAction action, ISelection selection)
111 {
112
113 selectedFile = (org.eclipse.core.internal.resources.File) ((StructuredSelection) selection)
114 .getFirstElement();
115 fileLocation = selectedFile.getLocation().toString();
116 pr = selectedFile.getProject();
117 return;
118
119 }
120
121 }