Math2mat

/home/ythoma/docs/math2mat/svn/wp1/framework/m2mGUI/src/m2m/frontend/view/Editor.java

Go to the documentation of this file.
00001 
00020 package m2m.frontend.view;
00021 
00022 import java.io.BufferedReader;
00023 import java.io.File;
00024 import java.io.FileInputStream;
00025 import java.io.FileNotFoundException;
00026 import java.io.FileWriter;
00027 import java.io.IOException;
00028 import java.io.InputStreamReader;
00029 import java.util.Stack;
00030 
00031 
00032 import org.eclipse.core.filesystem.EFS;
00033 import org.eclipse.core.filesystem.IFileStore;
00034 import org.eclipse.core.runtime.CoreException;
00035 import org.eclipse.core.runtime.IProgressMonitor;
00036 import org.eclipse.jface.dialogs.IDialogConstants;
00037 import org.eclipse.jface.dialogs.MessageDialog;
00038 import org.eclipse.jface.text.Document;
00039 import org.eclipse.jface.text.source.*;
00040 import org.eclipse.swt.SWT;
00041 import org.eclipse.swt.custom.ExtendedModifyEvent;
00042 import org.eclipse.swt.custom.ExtendedModifyListener;
00043 import org.eclipse.swt.custom.StyledText;
00044 import org.eclipse.swt.events.DisposeEvent;
00045 import org.eclipse.swt.events.DisposeListener;
00046 import org.eclipse.swt.events.ModifyEvent;
00047 import org.eclipse.swt.events.ModifyListener;
00048 import org.eclipse.swt.graphics.Color;
00049 import org.eclipse.swt.graphics.Point;
00050 import org.eclipse.swt.layout.FillLayout;
00051 import org.eclipse.swt.layout.GridData;
00052 import org.eclipse.swt.widgets.Composite;
00053 import org.eclipse.swt.widgets.Display;
00054 import org.eclipse.swt.widgets.Event;
00055 import org.eclipse.swt.widgets.FileDialog;
00056 import org.eclipse.swt.widgets.Listener;
00057 import org.eclipse.swt.widgets.Menu;
00058 import org.eclipse.swt.widgets.MenuItem;
00059 import org.eclipse.swt.widgets.MessageBox;
00060 import org.eclipse.swt.widgets.Shell;
00061 import org.eclipse.ui.IEditorInput;
00062 import org.eclipse.ui.IEditorPart;
00063 import org.eclipse.ui.IEditorSite;
00064 import org.eclipse.ui.ISaveablePart2;
00065 import org.eclipse.ui.IWorkbenchPage;
00066 import org.eclipse.ui.PartInitException;
00067 import org.eclipse.ui.PlatformUI;
00068 import org.eclipse.ui.ide.FileStoreEditorInput;
00069 import org.eclipse.ui.part.EditorPart;
00070 
00071 
00072 import m2m.backend.octaveparser.ParsingException;
00073 import m2m.backend.project.M2MProject;
00074 import m2m.backend.project.OptimisationProperties;
00075 import m2m.backend.project.SimulationProperties;
00076 import m2m.backend.utils.FileUtils;
00077 import m2m.frontend.MatlabLineStyler;
00078 import m2m.frontend.actions.TextChange;
00079 import m2m.frontend.dynamicview.Model;
00080 import m2m.frontend.dynamicview.MyGraphicalEditor;
00081 import m2m.frontend.dynamicview.MyGraphicalProperty;
00082 import m2m.frontend.dynamicview.ThreadRouteConnections;
00083 
00084 
00085 public class Editor extends EditorPart implements ISaveablePart2
00086 {
00087 
00088         public static final String ID = "m2mgui.editor";
00089         protected static final int UNDO_LIMIT = 200;
00090         private MatlabLineStyler lineStyler = new MatlabLineStyler();
00091         private FileInputStream fileToRead = null;
00092         private BufferedReader br;
00093         private Composite top;
00094         private StyledText styledText;
00095         private String filePath; 
00096         private File inputFile;
00097         private boolean parseDone = false;
00098         private Stack<TextChange> undoChanges;
00099         private Stack<TextChange> redoChanges;
00100         private boolean ignoreUndo = false;
00101         private Model model;
00102         private M2MProject m2mProject;
00103         
00104         public Shell getShell() {
00105                 return this.getSite().getShell();
00106         }
00107         
00111         public void createPartControl(final Composite parent) {
00112                 undoChanges = new Stack<TextChange>();
00113                 redoChanges = new Stack<TextChange>();
00114 
00115                 top = new Composite(parent, SWT.NONE);
00116                 FillLayout layout = new FillLayout();
00117 
00118                 top.setLayout(layout);
00119                 
00120                 //Create rules for the SourceViewer
00121                 CompositeRuler ruler = new CompositeRuler();
00122         LineNumberRulerColumn rulerColumn = new LineNumberRulerColumn();
00123         //add the line number decorator to the rules
00124         rulerColumn.setBackground(new Color(parent.getDisplay(), 230, 230, 230));
00125                 ruler.addDecorator(1, rulerColumn);
00126                 
00127                 //Create the SourceViewer. Contrary to a simple StyledText, the SourceViewer allows to add decorator such as the
00128                 //line number on the left column of the editor
00129                 SourceViewer viewer = new SourceViewer(top, ruler, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
00130                 
00131                 
00132                 //set the document of the SourceViewer. If you don't do this, impossible to write text in the viewer... and don't know why
00133                 Document document = new Document();
00134                 viewer.setDocument(document);
00135                 
00136                 //Get the StyledText. The StyledText allows to add syntax coloring for special keywords
00137                 styledText = viewer.getTextWidget();
00138                 
00139                 styledText.setLayoutData(new GridData(GridData.FILL_BOTH));
00140                 //add the syntax coloring
00141                 styledText.addLineStyleListener(lineStyler);
00142                 
00143                 //get the source file path
00144                 filePath = this.getEditorInput().getToolTipText();
00145                 
00146                 try {
00147                         fileToRead = new FileInputStream(filePath);
00148                         br = new BufferedReader(new InputStreamReader(fileToRead));
00149                 } catch (FileNotFoundException e) {
00150                         e.printStackTrace();
00151                 }
00152                 try {
00153                         //print the text of the source file in the editor
00154                         String strLine;
00155                         while ((strLine = br.readLine()) != null)
00156                                 styledText.append(strLine + "\n");
00157                 } catch (IOException e) {
00158                         e.printStackTrace();
00159                 }
00160 
00161                 styledText.addModifyListener(new ModifyListener() {
00162                         @Override
00163                         public void modifyText(ModifyEvent e) 
00164                         {
00165                                 /* Add "*" to the name of the changed file */
00166                                 if (!m2mProject.isModified()) 
00167                                 {
00168                                         m2mProject.setModified(true);
00169                                         firePropertyChange(IEditorPart.PROP_DIRTY);
00170                                 }
00171                 
00172                                 m2mProject.clearStructTreatment();
00173                                 setParseDone(true);
00174                                                                 
00175                                 /* Clear the console */
00176                                 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
00177                                 if((M2MConsole)page.findView(M2MConsole.ID) == null)
00178                                 {
00179                                         try {
00180                                                 page.showView(M2MConsole.ID);
00181                                         }
00182                                         catch (PartInitException e1) {
00183                                                 e1.printStackTrace();
00184                                         }
00185                                 }       
00186                                 ((M2MConsole)page.findView(M2MConsole.ID)).clearConsole();
00187                                 
00188                                 /* Parsing of the text of the editor */
00189                                 try {
00190                                         m2mProject.getStructTreatment().parse(styledText.getText());
00191                                 }
00192                                 catch (ParsingException e1) {
00193                                         System.err.println(e1.getMessage());
00194                                         setParseDone(false);
00195                                 }
00196                                 if (parseDone)
00197                                 {
00198                                         getEditorSite().getActionBars().getStatusLineManager().setMessage("Parsing succesfull.");
00199                                 
00200                                         /* Get both dynamic views */            
00201                             MyGraphicalProperty graphProp = ((MyGraphicalProperty)page.findView(MyGraphicalProperty.ID));
00202                             MyGraphicalEditor graphEditor = ((MyGraphicalEditor)page.findView(MyGraphicalEditor.ID));
00203                             
00204                             if(graphProp != null && graphEditor != null)
00205                             {   
00206                                 /* Update both dynamic view */
00207                                         model = new Model (m2mProject.getStructTreatment(), m2mProject);
00208                                     graphProp.getGraphicalViewer().setContents(model.getSchema());
00209                                     graphEditor.getGraphicalViewer().setContents(model.getSchema());
00210                                 Display.getCurrent().asyncExec(new ThreadRouteConnections());
00211                             }
00212                                 }
00213                                 else
00214                                         getEditorSite().getActionBars().getStatusLineManager().setMessage("Parsing Error. The dynamic view does not match with the octave code.");      
00215                         }
00216                 });
00217         
00218                 
00219                 //remove the file entry in the Navigation view
00220                 styledText.addDisposeListener(new DisposeListener() {
00221                         @Override
00222                         public void widgetDisposed(DisposeEvent event) 
00223                         {
00224                                 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
00225                                 page.hideView(((MyGraphicalEditor)page.findView(MyGraphicalEditor.ID)));
00226                                 page.hideView(((MyGraphicalProperty)page.findView(MyGraphicalProperty.ID)));
00227                                 model = null;
00228 
00229                                 NavigationView.remList(m2mProject.getProperties().getProjectFullFilename());
00230                         }
00231                 });
00232                         
00233                 
00234                 //store undo information
00235                 styledText.addExtendedModifyListener(new ExtendedModifyListener() {
00236                         public void modifyText(ExtendedModifyEvent event) {
00237                                 if (!ignoreUndo) {
00238                                         undoChanges.push(new TextChange(event.start, event.length, event.replacedText));
00239                                         if (undoChanges.size() > UNDO_LIMIT)
00240                                                 undoChanges.remove(0);
00241                                 } else {
00242                                         redoChanges.push(new TextChange(event.start, event.length, event.replacedText));
00243                                         if (redoChanges.size() > UNDO_LIMIT)
00244                                                 redoChanges.remove(0);
00245                                 }
00246                         }
00247                 });
00248         
00249                 
00250                 //Right click menu
00251                 Menu popupMenu = new Menu(styledText);
00252                 
00253                 //copy action
00254                 MenuItem copyItem = new MenuItem(popupMenu, SWT.PUSH);
00255                 copyItem.setText("Copy\tCtrl+C");
00256                 copyItem.addListener(SWT.Selection, new Listener() {
00257                         public void handleEvent(Event event) {
00258                                 styledText.copy();
00259                         }
00260                 });
00261                 
00262                 //paste action
00263                 MenuItem pasteItem = new MenuItem(popupMenu, SWT.PUSH);
00264                 pasteItem.setText("Paste\tCtrl+V");
00265                 pasteItem.addListener(SWT.Selection, new Listener() {
00266                         public void handleEvent(Event event) {
00267                                 styledText.paste();
00268                         }
00269                 });
00270                 
00271                 //cut action
00272                 MenuItem cutItem = new MenuItem(popupMenu, SWT.PUSH);
00273                 cutItem.setText("Cut\tCtrl+X");
00274                 cutItem.addListener(SWT.Selection, new Listener() {
00275                         public void handleEvent(Event event) {
00276                                 styledText.cut();
00277                         }
00278                 });
00279                 
00280                 //add a separator
00281                 new MenuItem(popupMenu, SWT.SEPARATOR);
00282                 
00283                 //delete action
00284                 MenuItem deleteItem = new MenuItem(popupMenu, SWT.PUSH);
00285                 deleteItem.setText("Delete\tDelete");
00286                 deleteItem.addListener(SWT.Selection, new Listener() {
00287                         public void handleEvent(Event event) {
00288                                 delete();
00289                         }
00290                 });
00291                 
00292                 //add a separator
00293                 new MenuItem(popupMenu, SWT.SEPARATOR);
00294                 
00295                 //comment/uncomment action
00296                 MenuItem comUncomItem = new MenuItem(popupMenu, SWT.PUSH);
00297                 comUncomItem.setText("Comment/Uncomment");
00298                 comUncomItem.addListener(SWT.Selection, new Listener() {
00299                         public void handleEvent(Event event) {
00300                                 Point selRange = styledText.getSelectionRange();
00301                                 int firstLine = styledText.getLineAtOffset(selRange.x);
00302                                 int lastLine = styledText.getLineAtOffset(selRange.x + selRange.y);
00303                                 
00304                                 ignoreUndo = true;
00305                                 
00306                                 StyledText commentText = new StyledText(top, SWT.FILL);
00307                                 commentText.setText(styledText.getText(styledText.getOffsetAtLine(firstLine), selRange.x + selRange.y));
00308                                 Point commentRange = styledText.getSelectionRange();
00309                                 
00310                                 for(int i = 0; i <= lastLine - firstLine; i++) {
00311                                         //get the first character of the line
00312                                         char firstChar = commentText.getText().charAt(commentText.getOffsetAtLine(i));
00313                                         if (firstChar == '%') {
00314                                                 commentText.replaceTextRange(commentText.getOffsetAtLine(i), 1, "");
00315                                                 if (i == 0 && selRange.x != styledText.getOffsetAtLine(firstLine))
00316                                                         commentRange.x--;
00317                                                 else
00318                                                         commentRange.y--;
00319                                         } else {
00320                                                 commentText.replaceTextRange(commentText.getOffsetAtLine(i), 0, "%");
00321                                                 if (i == 0 && selRange.x != styledText.getOffsetAtLine(firstLine))
00322                                                         commentRange.x++;
00323                                                 else
00324                                                         commentRange.y++;
00325                                         }
00326                                 }
00327                                 
00328                                 ignoreUndo = false;
00329                                 
00330                                 styledText.replaceTextRange(styledText.getOffsetAtLine(firstLine), selRange.y + (selRange.x - styledText.getOffsetAtLine(firstLine) + 1), commentText.getText());
00331                                 styledText.setSelection(commentRange.x, commentRange.x + commentRange.y);
00332                         }
00333                 });
00334                 
00335                 
00336                 //Add the right click menu
00337                 styledText.setMenu(popupMenu);
00338         }
00339         
00340         public void copy() {
00341                 styledText.copy();
00342         }
00343         
00344         public void cut() {
00345                 styledText.cut();
00346         }
00347         
00348         public void paste() {
00349                 styledText.paste();
00350         }
00351 
00352         public void selectAll() {
00353                 styledText.selectAll();
00354         }
00355         
00356         public void delete() {
00357                 int start = styledText.getSelectionRange().x;
00358                 int length = styledText.getSelectionRange().y;
00359                 styledText.replaceTextRange(start, length, "");
00360         }
00361         
00362         public void undo() {
00363                 int oldLength = 0;
00364                 int newLength = 0;
00365                 
00366                 if (!undoChanges.empty()) {
00367                         TextChange change = (TextChange)undoChanges.pop();
00368                         
00369                         ignoreUndo = true;
00370                         
00371                         oldLength = styledText.getText().length();
00372                         styledText.replaceTextRange(change.getStart(), change.getLength(), change.getReplacedText());
00373                         newLength = styledText.getText().length();
00374                         
00375                         if ((oldLength - newLength) > 0)
00376                                 styledText.setCaretOffset(change.getStart());
00377                         else
00378                                 styledText.setCaretOffset(change.getStart() + change.getReplacedText().length());
00379                         
00380                         styledText.setTopIndex(styledText.getLineAtOffset(change.getStart()));
00381                         ignoreUndo = false;
00382                 }
00383         }
00384         
00385         public void redo() {
00386                 int oldLength = 0;
00387                 int newLength = 0;
00388                 
00389                 if (!redoChanges.empty()) {
00390                         TextChange change = (TextChange)redoChanges.pop();
00391 
00392                         oldLength = styledText.getText().length();
00393                         styledText.replaceTextRange(change.getStart(), change.getLength(), change.getReplacedText());
00394                         newLength = styledText.getText().length();
00395 
00396                         if ((oldLength - newLength) > 0)
00397                                 styledText.setCaretOffset(change.getStart());
00398                         else
00399                                 styledText.setCaretOffset(change.getStart() + change.getReplacedText().length());
00400                         
00401                         styledText.setTopIndex(styledText.getLineAtOffset(change.getStart()));
00402                 }
00403         }
00404         
00405         public void comUncom() {
00406                 Point selRange = styledText.getSelectionRange();
00407                 int firstLine = styledText.getLineAtOffset(selRange.x);
00408                 int lastLine = styledText.getLineAtOffset(selRange.x + selRange.y);
00409                 
00410                 ignoreUndo = true;
00411                 
00412                 StyledText commentText = new StyledText(top, SWT.FILL);
00413                 commentText.setText(styledText.getText(styledText.getOffsetAtLine(firstLine), selRange.x + selRange.y));
00414                 Point commentRange = styledText.getSelectionRange();
00415                 
00416                 for(int i = 0; i <= lastLine - firstLine; i++) {
00417                         //get the first character of the line
00418                         char firstChar = commentText.getText().charAt(commentText.getOffsetAtLine(i));
00419                         if (firstChar == '%') {
00420                                 //uncomment if the line is already commented
00421                                 commentText.replaceTextRange(commentText.getOffsetAtLine(i), 1, "");
00422                                 if (i == 0 && selRange.x != styledText.getOffsetAtLine(firstLine))
00423                                         commentRange.x--;
00424                                 else
00425                                         commentRange.y--;
00426                         } else {
00427                                 commentText.replaceTextRange(commentText.getOffsetAtLine(i), 0, "%");
00428                                 if (i == 0 && selRange.x != styledText.getOffsetAtLine(firstLine))
00429                                         commentRange.x++;
00430                                 else
00431                                         commentRange.y++;
00432                         }
00433                 }
00434                 
00435                 ignoreUndo = false;
00436                 
00437                 styledText.replaceTextRange(styledText.getOffsetAtLine(firstLine), selRange.y + (selRange.x - styledText.getOffsetAtLine(firstLine) + 1), commentText.getText());
00438                 styledText.setSelection(commentRange.x, commentRange.x + commentRange.y);
00439         }
00440         
00441         public void comment() {
00442                 Point selRange = styledText.getSelectionRange();
00443                 int firstLine = styledText.getLineAtOffset(selRange.x);
00444                 int lastLine = styledText.getLineAtOffset(selRange.x + selRange.y);
00445                 
00446                 ignoreUndo = true;
00447                 
00448                 StyledText commentText = new StyledText(top, SWT.FILL);
00449                 commentText.setText(styledText.getText(styledText.getOffsetAtLine(firstLine), selRange.x + selRange.y));
00450                 Point commentRange = styledText.getSelectionRange();
00451                 
00452                 for(int i = 0; i <= lastLine - firstLine; i++) {
00453                         commentText.replaceTextRange(commentText.getOffsetAtLine(i), 0, "%");
00454                         if (i == 0 && selRange.x != styledText.getOffsetAtLine(firstLine))
00455                                 commentRange.x++;
00456                         else
00457                                 commentRange.y++;
00458                 }
00459                 
00460                 ignoreUndo = false;
00461                 
00462                 styledText.replaceTextRange(styledText.getOffsetAtLine(firstLine), selRange.y + (selRange.x - styledText.getOffsetAtLine(firstLine) + 1), commentText.getText());
00463                 styledText.setSelection(commentRange.x, commentRange.x + commentRange.y);
00464         }
00465         
00466         public void uncomment() {
00467                 Point selRange = styledText.getSelectionRange();
00468                 int firstLine = styledText.getLineAtOffset(selRange.x);
00469                 int lastLine = styledText.getLineAtOffset(selRange.x + selRange.y);
00470                 
00471                 ignoreUndo = true;
00472                 
00473                 StyledText commentText = new StyledText(top, SWT.FILL);
00474                 commentText.setText(styledText.getText(styledText.getOffsetAtLine(firstLine), selRange.x + selRange.y));
00475                 Point commentRange = styledText.getSelectionRange();
00476                 
00477                 for(int i = 0; i <= lastLine - firstLine; i++) {
00478                         //get the first character of the line
00479                         char firstChar = commentText.getText().charAt(commentText.getOffsetAtLine(i));
00480                         if (firstChar == '%')
00481                                 commentText.replaceTextRange(commentText.getOffsetAtLine(i), 1, "");
00482                         if (i == 0 && selRange.x != styledText.getOffsetAtLine(firstLine))
00483                                 commentRange.x--;
00484                         else
00485                                 commentRange.y--;
00486                 }
00487                 
00488                 ignoreUndo = false;
00489                 
00490                 styledText.replaceTextRange(styledText.getOffsetAtLine(firstLine), selRange.y + (selRange.x - styledText.getOffsetAtLine(firstLine) + 1), commentText.getText());
00491                 styledText.setSelection(commentRange.x, commentRange.x + commentRange.y);
00492         }
00493         
00494         public void setFocus() {
00495 
00496         }
00497 
00498 
00499 
00500         @Override
00504         public void doSaveAs() {
00505                 String fileName; //name of the file entered in the "Save dialog box"
00506                 FileDialog dialog = new FileDialog(top.getShell(), SWT.SAVE);
00507                 dialog.setText("Save File");
00508                 dialog.setFilterPath(m2mProject.getProperties().getAbsoluteSourceFilename());
00509         String[] filterExt = { "*.m" };
00510         dialog.setFilterExtensions(filterExt);
00511         String path = dialog.open();
00512         if (path == null)
00513             return;
00514 
00515         //test if the name of the file the user wants to save contains the chosen extension or not
00516         //if not, add the extension to the file name
00517         if ((path.lastIndexOf(".") == -1 ? "" : path.substring(path.lastIndexOf(".")+1, path.length())).equalsIgnoreCase(dialog.getFilterExtensions()[dialog.getFilterIndex()].substring(2))) {
00518                 fileName = path;
00519         } else {
00520                 String filterExtension = dialog.getFilterExtensions()[dialog.getFilterIndex()];
00521                 fileName = path+filterExtension.substring(1, filterExtension.length());
00522         }
00523         
00524         if (!FileUtils.copyFile(m2mProject.getProperties().getAbsoluteSourceFilename(),fileName))
00525         return;
00526         
00527         File file = new File(fileName);
00528         m2mProject.getProperties().setSourceFile(file);
00529 
00530         this.setPartName(m2mProject.getSourceFile().getName());
00531             
00532 
00533                 try {
00534                         IFileStore fileStore = EFS.getStore(m2mProject.getSourceFile().toURI());
00535                 this.setInput(new FileStoreEditorInput(fileStore));
00536                 } catch (CoreException e) {
00537                         e.printStackTrace();
00538                 }
00539                 
00540                 saveProject();
00541         //file has been saved, reset the boolean "fileModified"
00542         firePropertyChange(IEditorPart.PROP_DIRTY);
00543         
00544                 }
00545 
00549         public void doSave() {
00550 
00551                 //get the file extension
00552      //   String ext = (m2mProject.getProperties().getProjectFullFilename().lastIndexOf(".") == -1 ? "" :
00553      //         m2mProject.getProperties().getProjectFullFilename().substring(m2mProject.getProperties().getProjectFullFilename().lastIndexOf(".")+1, m2mProject.getProperties().getProjectFullFilename().length()));
00554         
00555         try {
00556                 FileWriter fileWriter = new FileWriter(m2mProject.getSourceFile());
00557                 fileWriter.write(styledText.getText());
00558                 fileWriter.close();
00559         } catch (IOException e) {
00560                 MessageBox messageBox = new MessageBox(top.getShell(), SWT.ICON_ERROR | SWT.OK);
00561                 messageBox.setMessage("File I/O Error.");
00562                 messageBox.setText("Error");
00563                 messageBox.open();
00564                 return;
00565         }
00566 
00567         saveProject();
00568         
00569         //file has been saved, reset the boolean "fileModified"
00570         firePropertyChange(IEditorPart.PROP_DIRTY);
00571         }
00572         
00573         public void setModified(boolean modif) {
00574                 /* Add "*" to the name of the changed file */
00575                 if (m2mProject.isModified()!=modif) 
00576                 {
00577                         m2mProject.setModified(modif);
00578                         firePropertyChange(IEditorPart.PROP_DIRTY);
00579                 }
00580         }
00581 
00582         
00583         @Override
00587         public void init(IEditorSite site, IEditorInput input)
00588                         throws PartInitException {
00589                 if (input != null) { 
00590                         this.setSite(site);
00591                         if (input instanceof M2MFileStoreEditorInput)
00592                         {
00593                                 
00594                                 this.m2mProject= ((M2MFileStoreEditorInput)input).getProject();
00595 
00596 //                              this.setPartName(this.m2mProject.getSourceFile().getName());
00597                                 this.setPartName(new File(this.m2mProject.getProjectFilename()).getName());
00598                                 inputFile = this.m2mProject.getSourceFile();
00599                                 try {
00600                                         if (inputFile != null) {
00601                                                 IFileStore fileStore= EFS.getStore(inputFile.toURI());
00602                                                 this.setInput(new FileStoreEditorInput(fileStore));
00603                                         } else {
00604                                                 
00605                                         }
00606                                 } catch (CoreException e) {
00607                                         e.printStackTrace();
00608                                 }
00609                         }
00610                 }
00611         }
00612 
00613         @Override
00614         public boolean isDirty() {
00615                 return m2mProject.isModified();
00616         }
00617 
00618         @Override
00619         public boolean isSaveAsAllowed() {
00620                 return true;
00621         }
00622         
00627         public M2MProject getM2MProject() {
00628                 return m2mProject;
00629         }
00630         
00634         public void saveProject() {
00635                 m2mProject.save();
00636         }
00637         
00643         public File getInputFile() {
00644                 return inputFile;
00645         }
00646         
00652         public String getText() {
00653                 return styledText.getText();
00654         }
00655         
00656         
00662         public boolean getParseDone() {
00663                 return parseDone;
00664         }
00665         
00671         public void setOptimisationProperties(OptimisationProperties optimProp) {
00672                 m2mProject.getProperties().setOptimisationProperties(optimProp);
00673         }
00679         public void setSimulationProperties(SimulationProperties simProp) {
00680                 m2mProject.getProperties().setSimulationProperties(simProp);
00681         }
00682         
00688         public void setParseDone(boolean bool) {
00689                 this.parseDone = bool;
00690         }
00691         
00692 
00693         
00694         
00699         public void setModel(Model model) {
00700                 this.model = model;
00701         }
00702         
00707         public Model getModel() {
00708                 return model;
00709         }
00710         
00715         public StyledText getStyledText() {
00716                 return styledText;
00717         }
00718         
00723         public String getFilePath()
00724         {
00725                 return filePath;
00726         }
00727 
00728         @Override
00732         public int promptToSaveOnClose() 
00733         {
00734                 MessageDialog dg = new MessageDialog(getEditorSite().getShell(), "Math2Mat", null,
00735                 m2mProject.getSourceFile().getName()+" has changed, do you want to save changes?",
00736                 MessageDialog.QUESTION_WITH_CANCEL, 
00737                 new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL},
00738                 0
00739                 );
00740                 
00741                 int result = dg.open();
00742                 
00743                 if(result == 0)
00744                         doSave();
00745 
00746                 return result;
00747         }
00748         
00749         @Override
00750         public void doSave(IProgressMonitor monitor) {
00751         }
00752 }
 All Classes Namespaces Files Functions Variables Enumerations