Math2mat
|
00001 00020 package m2m.frontend.actions; 00021 00022 /* 00023 import java.io.File; 00024 import java.io.FileWriter; 00025 import java.io.IOException; 00026 00027 import org.eclipse.core.filesystem.EFS; 00028 import org.eclipse.core.filesystem.IFileStore; 00029 import org.eclipse.core.runtime.CoreException; 00030 import org.eclipse.swt.SWT; 00031 import org.eclipse.swt.widgets.FileDialog; 00032 import org.eclipse.swt.widgets.MessageBox; 00033 import org.eclipse.ui.IWorkbenchPage; 00034 import org.eclipse.ui.PlatformUI; 00035 import org.eclipse.ui.ide.FileStoreEditorInput; 00036 00037 import m2mgui.view.Editor; 00038 import m2mgui.view.NavigationView; 00039 00040 import m2mproject.ProjectProperties; 00041 */ 00042 00043 import org.eclipse.ui.IWorkbenchWindow; 00044 00045 import m2m.frontend.actions.M2MAction; 00046 00047 public class NewFileAction extends M2MAction { 00048 00049 public NewFileAction(IWorkbenchWindow window, String label) { 00050 super(window,label); 00051 00052 } 00053 /* 00054 public NewFileAction(IWorkbenchWindow window, String label) { 00055 super(window,label); 00056 // The id is used to refer to the action in a menu or toolbar 00057 setId(ICommandIds.CMD_NEW); 00058 // Associate the action with a pre-defined command, to allow key bindings. 00059 setActionDefinitionId(ICommandIds.CMD_NEW); 00060 setImageDescriptor(m2mgui.Activator.getImageDescriptor("/icons/new.gif")); 00061 } 00062 */ 00066 /* 00067 public void run() { 00068 //open a file dialog box 00069 FileDialog dialog = new FileDialog(window.getShell(), SWT.SAVE); 00070 dialog.setText("Create new project"); 00071 String path = dialog.open(); 00072 if (path == null) 00073 return; 00074 00075 //create a new file 00076 File file = new File(path); 00077 00078 //get the file extension 00079 String ext = (file.getName().lastIndexOf(".") == -1 ? "" : 00080 file.getName().substring(file.getName().lastIndexOf(".")+1, file.getName().length())); 00081 00082 if (ext.equalsIgnoreCase("m2m")) { 00083 00084 File sourceFile = new File(file.getPath().substring(0, file.getPath().lastIndexOf(".")+1)+"m"); 00085 00086 try { 00087 FileWriter fileWriter = new FileWriter(file); 00088 FileWriter sourceFileWriter = new FileWriter(sourceFile); 00089 sourceFileWriter.close(); 00090 00091 //create the base content of the project file 00092 ProjectProperties properties = new ProjectProperties(); 00093 properties.setSourceFilePath(sourceFile.getName()); 00094 PropertiesXML propertiesXML = new PropertiesXML(properties); 00095 fileWriter.write(propertiesXML.toXML()); 00096 fileWriter.close(); 00097 } catch (IOException e) { 00098 MessageBox messageBox = new MessageBox(window.getShell(), SWT.ICON_ERROR | SWT.OK); 00099 messageBox.setMessage("File I/O Error."); 00100 messageBox.setText("Error"); 00101 messageBox.open(); 00102 return; 00103 } 00104 00105 //open a new editor for the file 00106 IWorkbenchPage page= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); 00107 try { 00108 IFileStore fileStore= EFS.getStore(file.toURI()); 00109 page.openEditor(new FileStoreEditorInput(fileStore), Editor.ID, true); 00110 NavigationView.addList(file.getAbsolutePath()); 00111 } catch (CoreException e) { 00112 e.printStackTrace(); 00113 } 00114 } 00115 } 00116 */ 00117 }