BaseEditorManager.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.viewer.editor;
00002 
00003 import org.eclipse.ui.IEditorPart;
00004 import org.eclipse.ui.IEditorReference;
00005 import org.eclipse.ui.IWorkbenchPage;
00006 import org.eclipse.ui.PlatformUI;
00007 import org.eclipse.ui.internal.EditorSashContainer;
00008 import org.eclipse.ui.internal.EditorStack;
00009 import org.eclipse.ui.internal.ILayoutContainer;
00010 import org.eclipse.ui.internal.LayoutPart;
00011 import org.eclipse.ui.internal.PartPane;
00012 import org.eclipse.ui.internal.PartSashContainer;
00013 import org.eclipse.ui.internal.PartSite;
00014 import org.eclipse.ui.internal.PartStack;
00015 import org.eclipse.ui.internal.WorkbenchPage;
00016 
00017 import edu.rice.cs.hpc.data.experiment.Experiment;
00018 
00019 public abstract class BaseEditorManager {
00020 
00021     
00022     /***
00023      * prepare to split the editor  pane
00024      * 
00025      * @param page
00026      * @param experiment
00027      * @return
00028      */
00029     static public boolean splitBegin(IWorkbenchPage page, Experiment experiment) {
00030         //sanity checks
00031         if (page == null) {
00032             throw new IllegalArgumentException();
00033         }
00034 
00035         // If there is already a editor area partition for this database, give one of its editors focus 
00036         // so that this new editor will display in the same partition.  If not we will create a new partition
00037         // and put the new editor in it after we open the editor.
00038         IEditorReference[] editorReferences = page.getEditorReferences();
00039         
00040         // assume there are no editors open and that we will not need a new partition
00041         boolean needNewPartition = false;
00042         // if at lease one editor already open, we may need new partition (see below)
00043         if (editorReferences.length > 0) {
00044             needNewPartition = true;
00045         }
00046         
00047         // check if there is already an editor opened for this database
00048         final String expFile = experiment.getXMLExperimentFile().getPath();
00049         for(IEditorReference editorRef: editorReferences) {
00050             IEditorPart editor = editorRef.getEditor(false);
00051             
00052             if (editor instanceof IViewerEditor) {
00053                 Experiment expEditor = ((IViewerEditor)editor).getExperiment();
00054                 // if there is no experiment associated with this editor, just ignore it
00055                 if (expEditor != null) {
00056                     final String expEditorFile = expEditor.getXMLExperimentFile().getPath();
00057                     if (expFile.equals(expEditorFile)) {
00058                         // An editor has already opened, do not split the pane
00059                         needNewPartition = false;
00060                         // make this editor active so the new editor will end up in its pane
00061                         page.activate(editor.getSite().getPart());
00062                         break;
00063                     }
00064                 }
00065             }
00066         }
00067         
00068         return needNewPartition;
00069     }
00070 
00071     /***
00072      * finalize the split if necessary
00073      * 
00074      * @param needNewPartition
00075      * @param iep
00076      */
00077     static public void splitEnd(boolean needNewPartition, IEditorPart iep) {
00078         // if this is the first editor from this database, create new partition to put it in
00079         if (needNewPartition == true) {
00080             splitEditorArea(iep);
00081         }
00082 
00083     }
00084     
00085     
00086     //=====================================================================================================
00087     // Split editor
00088     // Attention: this split part uses Eclipse internal methods which are not portable across revisions
00089     //            it has to be replaced by other approach if possible
00090     //=====================================================================================================
00091     
00095 //  @SuppressWarnings("restriction")
00096     private static void splitEditorArea(IEditorPart iep) {
00097         PartPane partPane = ((PartSite) iep.getSite()).getPane();
00098         // Get PartPane that correspond to the active editor
00099         PartPane currentEditorPartPane = ((PartSite) iep.getSite()).getPane();
00100         EditorSashContainer editorSashContainer = null;
00101         ILayoutContainer rootLayoutContainer = partPane.getPart().getContainer();
00102         if (rootLayoutContainer instanceof LayoutPart) {
00103             ILayoutContainer editorSashLayoutContainer = ((LayoutPart) rootLayoutContainer).getContainer();
00104             if (editorSashLayoutContainer instanceof EditorSashContainer) {
00105                 editorSashContainer = ((EditorSashContainer) editorSashLayoutContainer);
00106             }
00107         }
00108 
00109         /*
00110          * Create a new part stack (i.e. a workbook) to home the
00111          * currentEditorPartPane which hold the active editor
00112          */
00113         PartStack newPart = createStack(editorSashContainer);
00114         
00115         if (editorSashContainer != null)
00116             editorSashContainer.stack(currentEditorPartPane, newPart);
00117 
00118         if (rootLayoutContainer instanceof LayoutPart) {
00119             ILayoutContainer cont = ((LayoutPart) rootLayoutContainer).getContainer();
00120             if (cont instanceof PartSashContainer) {
00121                 // "Split" the editor area by adding the new part
00122                 ((PartSashContainer) cont).add(newPart);
00123             }
00124         }
00125     }
00132 //  @SuppressWarnings("restriction")
00133     private static PartStack createStack(EditorSashContainer editorSashContainer) {
00134         IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
00135         EditorStack newWorkbook = EditorStack.newEditorWorkbook(editorSashContainer, (WorkbenchPage)workbenchPage);
00136         return newWorkbook;
00137     }
00138 
00139 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1