ViewerWindowManager.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.viewer.window;
00002 
00003 import java.util.Vector;
00004 
00005 import org.eclipse.jface.dialogs.MessageDialog;
00006 import org.eclipse.ui.IWorkbenchWindow;
00007 
00008 import edu.rice.cs.hpc.viewer.util.WindowTitle;
00009 
00026 public class ViewerWindowManager {
00030     private static Vector<ViewerWindow> vWindows = new Vector<ViewerWindow>(3);
00031 
00037     static public int getWindowNumber (IWorkbenchWindow window) {
00038         for (int i=0 ; i<vWindows.size() ; i++) {
00039             if (vWindows.get(i) == null) {
00040                 continue;
00041             }
00042             // if this is our callers window, return its index
00043             if (vWindows.get(i).getWinObj().equals(window)) {
00044                 return i;
00045             }
00046         }
00047         return -1;
00048     }
00049 
00053     public void addNewWindow (IWorkbenchWindow window) {
00054         // get a new viewer window object and set the workbench window it is tied to
00055         ViewerWindow vWin = new ViewerWindow();
00056         vWin.setWinObj(window);
00057 
00058         // see if there are any unused slots
00059         vWindows.add(vWin);
00060         
00061         // after the new window is added, we must update all the old windows titles
00062         WindowTitle wt = new WindowTitle();
00063         wt.refreshAllTitles();
00064         return;
00065     }
00066 
00070     static public Boolean removeWindow (IWorkbenchWindow window) {
00071         for (int i=0 ; i<vWindows.size() ; i++) {
00072             final ViewerWindow vw = vWindows.get(i);
00073             if (vw == null) {
00074                 continue;
00075             }
00076 
00077             // if this is the one to remove, set it to null so it can be reused later
00078             if (vw.getWinObj().equals(window)) {
00079                 vw.dispose();
00080                 // set this to something that will cause problems if used before being reset
00081                 vWindows.remove(i);
00082                 // after the window is removed, we must update remaining window titles (may need to remove window numbers)
00083                 WindowTitle wt = new WindowTitle();
00084                 wt.refreshAllTitles();
00085                 return true;
00086             }
00087         }
00088 
00089         MessageDialog.openError(window.getShell(), 
00090                 "Error: Removing Window from Database Manager.", 
00091                 "Window " + window.toString() + " not found in the list of window objects.");
00092         return false;
00093     }
00094 
00095     /***
00096      * return the number of opened database for a specified window
00097      * @param window
00098      * @return
00099      */
00100     static public int getNumberOfDatabases(IWorkbenchWindow window) {
00101         ViewerWindow vw = ViewerWindowManager.getViewerWindow(window);
00102         if (vw != null) {
00103             return vw.getOpenDatabases();
00104         }
00105         return 0;
00106     }
00107 
00111     static public ViewerWindow getViewerWindow(IWorkbenchWindow window) {
00112         for (int i=0 ; i<vWindows.size() ; i++) {
00113             if (vWindows.get(i) == null) {
00114                 continue;
00115             }
00116             if (window.equals(vWindows.get(i).getWinObj())) {
00117                 return vWindows.get(i);
00118             }
00119         }
00120 
00121         MessageDialog.openError(window.getShell(), 
00122             "Error: Current Window Unknown.", 
00123             "Unable to find hpcviewer window associated with " + window.toString());
00124         return null;
00125     }
00126     
00127     static public int size() {
00128         return vWindows.size();
00129     }
00130     
00131     static public ViewerWindow getViewerWindow(int index) {
00132         return vWindows.get(index);
00133     }
00134 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1