Math2mat

/home/ythoma/docs/math2mat/svn/wp1/framework/m2mGUI/src/m2m/frontend/actions/ViewDotFlatFile.java

Go to the documentation of this file.
00001 
00020 package m2m.frontend.actions;
00021 
00022 import java.io.File;
00023 
00024 import org.eclipse.swt.widgets.Display;
00025 import org.eclipse.ui.IViewReference;
00026 import org.eclipse.ui.IWorkbenchPage;
00027 import org.eclipse.ui.IWorkbenchWindow;
00028 import org.eclipse.ui.PartInitException;
00029 import org.eclipse.ui.PlatformUI;
00030 
00031 import m2m.backend.processing.ExternalRuns;
00032 import m2m.frontend.ErrorProcessing;
00033 import m2m.frontend.actions.M2MAction;
00034 import m2m.frontend.view.ImageViewer;
00035 
00036 public class ViewDotFlatFile extends M2MAction {
00037 
00038         public ViewDotFlatFile(IWorkbenchWindow window, String label) {
00039                 super(window,label);
00040             // The id is used to refer to the action in a menu or toolbar
00041                 setId(ICommandIds.CMD_DOTFLATVIEW);
00042             // Associate the action with a pre-defined command, to allow key bindings.
00043                 setActionDefinitionId(ICommandIds.CMD_DOTFLATVIEW);
00044 //                      setImageDescriptor(m2mgui.Activator.getImageDescriptor("/icons/octave.gif"));
00045         }
00046 
00050         public void run() {
00051 
00052                 if (!getEditor("Error","Select a correct M2M editor"))
00053                         return;
00054                 
00055                 if (!editor.getM2MProject().generateFlatDotFile()) {
00056                         System.out.println("Can not generate Dot file\n");
00057                 }
00058                 
00059                 File file = editor.getInputFile();
00060                 
00061                 
00062                 String dotName = (file.getAbsolutePath().lastIndexOf(".") == -1 ? "" :
00063                 file.getAbsolutePath().substring(0, file.getAbsolutePath().lastIndexOf(".")));
00064                 
00065                 if (!ExternalRuns.runDot(dotName+"_flat.gv", dotName+"_flat.png")) {
00066                         ErrorProcessing.processLastError(Display.getCurrent());
00067                         return;
00068                 }
00069                 
00070                 
00071             //open a new editor with the file's content
00072             IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
00073                     
00074             int i = 0;
00075 
00076             IViewReference aViewReference;
00077         do {
00078               i++;
00079           aViewReference = page.findViewReference(ImageViewer.ID, 
00080                           String.valueOf(i));
00081           if (aViewReference != null) {
00082                   if (aViewReference.getPartName().equalsIgnoreCase((file.getName().lastIndexOf(".") == -1 ? "" :
00083                                                                                         file.getName().substring(0, file.getName().lastIndexOf("."))+"_flat.png"))) {
00084                           page.activate(aViewReference.getPart(false));
00085                           break;
00086                   }
00087           }
00088         } while (aViewReference != null);
00089             
00090             
00091             try {
00092                 page.showView(ImageViewer.ID, String.valueOf(i), IWorkbenchPage.VIEW_ACTIVATE);
00093                 ImageViewer imViewer = (ImageViewer)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
00094                 imViewer.setImage(dotName+"_flat.png");
00095             } catch (PartInitException e1) {
00096                 // TODO Auto-generated catch block
00097                 e1.printStackTrace();
00098             }
00099         }
00100 }
00101 
 All Classes Namespaces Files Functions Variables Enumerations