Math2mat

/home/ythoma/docs/math2mat/svn/wp1/framework/m2mGUI/src/m2m/frontend/actions/ViewDotTreeFile.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 ViewDotTreeFile extends M2MAction {
00037 
00038         public ViewDotTreeFile(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_DOTTREEVIEW);
00042             // Associate the action with a pre-defined command, to allow key bindings.
00043                 setActionDefinitionId(ICommandIds.CMD_DOTTREEVIEW);
00044         }
00045 
00049         public void run() {
00050 
00051                 if (!getEditor("Error","Select a correct M2M editor"))
00052                         return;
00053 
00054                 if (!editor.getM2MProject().generateTreeDotFile()) {
00055                         System.out.println("Can not generate Dot file\n");
00056                 }
00057                 File file = editor.getInputFile();
00058                         
00059                         
00060                 String dotName = (file.getAbsolutePath().lastIndexOf(".") == -1 ? "" :
00061                 file.getAbsolutePath().substring(0, file.getAbsolutePath().lastIndexOf(".")));
00062                 
00063                 if (!ExternalRuns.runDot(dotName+"_tree.gv", dotName+"_tree.png")) {
00064                         ErrorProcessing.processLastError(Display.getCurrent());
00065                         return;
00066                 }       
00067                 
00068                 //open a new editor with the file's content
00069                 IWorkbenchPage page= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
00070                                     
00071                 int i = 0;
00072 
00073             IViewReference aViewReference;
00074             do {
00075                   i++;
00076               aViewReference = page.findViewReference(ImageViewer.ID, 
00077                           String.valueOf(i));
00078               if (aViewReference != null) {
00079                   if (aViewReference.getPartName().equalsIgnoreCase((file.getName().lastIndexOf(".") == -1 ? "" :
00080                                                                                         file.getName().substring(0, file.getName().lastIndexOf("."))+"_tree.png"))) {
00081                           page.activate(aViewReference.getPart(false));
00082                           break;
00083                   }
00084               }
00085             } while (aViewReference != null);
00086 
00087                     
00088                 try {
00089                         page.showView(ImageViewer.ID, String.valueOf(i), IWorkbenchPage.VIEW_ACTIVATE);
00090                         ImageViewer imViewer = (ImageViewer)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
00091                         imViewer.setImage(dotName+"_tree.png");
00092                 } catch (PartInitException e1) {
00093                         // TODO Auto-generated catch block
00094                         e1.printStackTrace();
00095                 }
00096         }
00097 }
 All Classes Namespaces Files Functions Variables Enumerations