BaseWindowTitle.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.viewer.util;
00002 
00003 import org.eclipse.ui.IEditorPart;
00004 import org.eclipse.ui.IViewPart;
00005 import org.eclipse.ui.IWorkbenchWindow;
00006 import edu.rice.cs.hpc.data.experiment.Experiment;
00007 import edu.rice.cs.hpc.viewer.editor.IViewerEditor;
00008 import edu.rice.cs.hpc.viewer.scope.BaseScopeView;
00009 import edu.rice.cs.hpc.viewer.window.ViewerWindow;
00010 import edu.rice.cs.hpc.viewer.window.ViewerWindowManager;
00011 
00012 public class BaseWindowTitle implements IWindowTitle {
00013 
00014     final private static String MAIN_TITLE = "hpcviewer";
00015 
00016     public BaseWindowTitle() {
00017     }
00018 
00019     /***
00020      * Get the title of the main window
00021      * 
00022      * @param window
00023      * @param experiment
00024      * @return the new title
00025      */
00026     public String getWindowTitle(IWorkbenchWindow window) {
00027         String winTitle = MAIN_TITLE;
00028         int numDB =  ViewerWindowManager.getNumberOfDatabases(window);
00029         // get the number of open main windows
00030         int numWin = ViewerWindowManager.size();
00031 
00032         if (numWin > 1) {
00033             // if multiple windows open add the window number
00034             winTitle = (ViewerWindowManager.getWindowNumber(window)+1) + "-" + MAIN_TITLE;
00035         }
00036         if (numDB > 1) {  // if more than 1 DB open only display the app title
00037             return winTitle;
00038         }
00039         // if we only have one opened database, get its name for the window title
00040         if (numDB == 1) {
00041             ViewerWindow vw = ViewerWindowManager.getViewerWindow(window);
00042             Experiment exp[] = vw.getExperiments();
00043             if (exp != null) {
00044                 return winTitle + ": "+exp[0].getName();
00045             }
00046         }
00047         return winTitle;
00048     }
00049 
00050     /***
00051      * Set the title of the view window
00052      * 
00053      * @param window
00054      * @param view
00055      * @return the new title
00056      */
00057     public String setTitle(IWorkbenchWindow window, IViewPart view) { 
00058 
00059         if (view instanceof BaseScopeView) {
00060             String sTitle = ((BaseScopeView) view).getRootScope().getRootName();
00061             if (ViewerWindowManager.getNumberOfDatabases(window) <= 1) {
00062                 ((BaseScopeView) view).setViewTitle(sTitle);
00063                 return sTitle;
00064             }
00065             final BaseScopeView scopeView = (BaseScopeView) view;
00066             final Experiment experiment = scopeView.getExperiment();
00067             ViewerWindow vw = ViewerWindowManager.getViewerWindow(window);
00068             int dbNum = 1 + vw.getDbNum(experiment);
00069             sTitle = dbNum + "-" + sTitle + "("+experiment.getName()+")";
00070             ((BaseScopeView) view).setViewTitle(sTitle);
00071             return sTitle;
00072 
00073         }
00074         return null;
00075     }
00076 
00077     /***
00078      * Set the title of the Editor window
00079      * 
00080      * @param window
00081      * @param experiment
00082      * @param sTitle
00083      * @return the new title
00084      */
00085     public String setEditorTitle(IWorkbenchWindow window, IEditorPart editorPart) { 
00086 
00087         if (editorPart instanceof IViewerEditor) {
00088             IViewerEditor editor = (IViewerEditor) editorPart;
00089             String sTitle = editor.getEditorPartName();
00090             int numDB =  ViewerWindowManager.getNumberOfDatabases(window);
00091             Experiment exp = editor.getExperiment();
00092             if ((exp == null) || (numDB <= 1)) {
00093                 editor.setEditorPartName(sTitle);
00094                 return sTitle;
00095             }
00096 
00097             ViewerWindow vw = ViewerWindowManager.getViewerWindow(window);
00098             numDB = 1 + vw.getDbNum(exp);
00099             String sResult = numDB + "-" + sTitle ;
00100             editor.setEditorPartName(sResult);
00101             return sResult;
00102         }
00103         return null;
00104     }
00105 
00106 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1