showXML.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.viewer.actions;
00002 
00003 import java.io.FileNotFoundException;
00004 
00005 import org.eclipse.core.commands.AbstractHandler;
00006 import org.eclipse.core.commands.ExecutionEvent;
00007 import org.eclipse.core.commands.ExecutionException;
00008 import org.eclipse.jface.dialogs.MessageDialog;
00009 import org.eclipse.ui.IWorkbenchWindow;
00010 import org.eclipse.ui.handlers.HandlerUtil;
00011 import edu.rice.cs.hpc.data.experiment.Experiment;
00012 import edu.rice.cs.hpc.viewer.editor.EditorManager;
00013 import edu.rice.cs.hpc.viewer.util.Utilities;
00014 
00015 
00016 /********************************************************************************
00017  * 
00018  * menu handler to show the XML code based on the current active view or editor
00019  * if the current active view or editor has information about the database,
00020  *  then we display its XML file.
00021  * otherwise this will do nothing
00022  *
00023  ********************************************************************************/
00024 public class showXML extends AbstractHandler {
00025 
00026     /*
00027      * (non-Javadoc)
00028      * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
00029      */
00030     public Object execute(ExecutionEvent event) throws ExecutionException 
00031     {
00032         final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
00033         final Experiment experiment = Utilities.getActiveExperiment(window);
00034         
00035         if (experiment != null)
00036             showXMLEditor( window, experiment);
00037         else
00038         {
00039             // display an error message here (but not a dialog box, it's annoying)
00040         }
00041         
00042         return null;
00043     }
00044 
00045     
00046     /***
00047      * show the read-only editor for xml file
00048      * 
00049      * @param window
00050      * @param experiment
00051      */
00052     private void showXMLEditor( IWorkbenchWindow window, Experiment experiment )
00053     {
00054         // get the the experiment XML file for the database this program scope is part of
00055         String filePath = experiment.getXMLExperimentFile().getPath();
00056 
00057         // prepare the editor
00058         EditorManager editor = new EditorManager(window);
00059         try {
00060             // database numbers start with 0 but titles start with 1
00061             editor.openFileEditor(filePath, experiment);
00062         } catch (FileNotFoundException e) {
00063             // can not find the file (or something goes wrong)
00064             MessageDialog.openError( window.getShell(), "Error: File not found", e.getMessage() );
00065         }
00066     }
00067 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1