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
00024
00025
00026
00027
00028
00029 static public boolean splitBegin(IWorkbenchPage page, Experiment experiment) {
00030
00031 if (page == null) {
00032 throw new IllegalArgumentException();
00033 }
00034
00035
00036
00037
00038 IEditorReference[] editorReferences = page.getEditorReferences();
00039
00040
00041 boolean needNewPartition = false;
00042
00043 if (editorReferences.length > 0) {
00044 needNewPartition = true;
00045 }
00046
00047
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
00055 if (expEditor != null) {
00056 final String expEditorFile = expEditor.getXMLExperimentFile().getPath();
00057 if (expFile.equals(expEditorFile)) {
00058
00059 needNewPartition = false;
00060
00061 page.activate(editor.getSite().getPart());
00062 break;
00063 }
00064 }
00065 }
00066 }
00067
00068 return needNewPartition;
00069 }
00070
00071
00072
00073
00074
00075
00076
00077 static public void splitEnd(boolean needNewPartition, IEditorPart iep) {
00078
00079 if (needNewPartition == true) {
00080 splitEditorArea(iep);
00081 }
00082
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00095
00096 private static void splitEditorArea(IEditorPart iep) {
00097 PartPane partPane = ((PartSite) iep.getSite()).getPane();
00098
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
00111
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
00122 ((PartSashContainer) cont).add(newPart);
00123 }
00124 }
00125 }
00132
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 }