Util.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.common.ui;
00002 
00003 import org.eclipse.core.commands.Command;
00004 import org.eclipse.core.commands.State;
00005 import org.eclipse.jface.action.IStatusLineManager;
00006 import org.eclipse.jface.dialogs.MessageDialog;
00007 import org.eclipse.swt.widgets.Shell;
00008 import org.eclipse.ui.IEditorSite;
00009 import org.eclipse.ui.IViewSite;
00010 import org.eclipse.ui.IWorkbenchPartSite;
00011 import org.eclipse.ui.IWorkbenchWindow;
00012 import org.eclipse.ui.PlatformUI;
00013 import org.eclipse.ui.commands.ICommandService;
00014 import org.eclipse.ui.handlers.RegistryToggleState;
00015 import org.eclipse.ui.part.EditorPart;
00016 
00017 import edu.rice.cs.hpc.data.util.JavaValidator;
00018 
00019 public class Util {
00020     
00021     /****
00022      * utility to get a window's command object of a given ID
00023      * @param window : window ID
00024      * @param commandID : command ID
00025      * 
00026      * @return the command (usually a menu command)
00027      */
00028     static public Command getCommand( IWorkbenchWindow window, String commandID ) {
00029         Command command = null;
00030         ICommandService commandService = (ICommandService) window.getService(ICommandService.class);
00031 
00032         if (commandService != null)
00033             command = commandService.getCommand( commandID );
00034         
00035         return command;
00036     }
00037     
00038     /***
00039      * verify if the menu "Show trace records" is checked
00040      * 
00041      * @return true of the menu is checked. false otherwise
00042      */
00043     static public boolean isOptionEnabled(Command command)
00044     {
00045         boolean isEnabled = false;
00046 
00047         final State state = command.getState(RegistryToggleState.STATE_ID);
00048         if (state != null)
00049         {
00050             final Boolean b = (Boolean) state.getValue();
00051             isEnabled = b.booleanValue();
00052         }
00053         return isEnabled;
00054     }
00055 
00056     /****
00057      * get the status line of the current active window
00058      * 
00059      * @return IStatusLineManager the status line manager
00060      */
00061     public static IStatusLineManager getActiveStatusLineManager() {
00062         final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
00063         if (window == null) {
00064             return null;
00065         }
00066 
00067         final IWorkbenchPartSite site = window.getActivePage().getActivePart().getSite();
00068         
00069         IStatusLineManager statusLine = null;
00070         
00071         // --------------------------------------------------------------
00072         // the current active site can be either editor or view
00073         // if none of them is active, then we have nothing
00074         //
00075         //  @TODO ugly code: this is a hack version to identify the current "site"
00076         //         status bar is hosted in a view site or editor site. Other than that, we are doomed.
00077         // --------------------------------------------------------------
00078         if (site instanceof IViewSite)
00079             statusLine = ((IViewSite)site).getActionBars().getStatusLineManager();
00080         else if (site instanceof IEditorSite)
00081             statusLine = ((IEditorSite)site).getActionBars().getStatusLineManager();
00082         else if (site instanceof EditorPart){
00083             statusLine = ((EditorPart) site).getEditorSite().getActionBars().getStatusLineManager();
00084         } else {
00085             System.out.println("unknown active site: " + site + " \t class: " + site.getClass());
00086         }
00087 
00088         return statusLine;
00089     }
00090 
00091     
00092     static public Shell getActiveShell() {
00093         final IWorkbenchWindow window = getActiveWindow();
00094         return window.getShell();
00095     }
00096     
00097     static public IWorkbenchWindow getActiveWindow() {
00098         final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
00099         return window;
00100     }
00101     
00102     /****
00103      * check if we run the correct version of JVM (assuming all JVM except GIJ will work)
00104      * Up to now, only Gnu Java (GCJ) that doesn't work properly with Eclipse. 
00105      * It works most cases, but it can crash if we use Java API that is not fully supported
00106      *  by GCJ
00107      * 
00108      * @param shell
00109      * @return true if we can continue, false otherwise
00110      */
00111     static public boolean checkJavaVendor(Shell shell) {
00112         boolean ok  = true;
00113         if (JavaValidator.isGCJ()) {
00114             String vendor = JavaValidator.getJavaVendor();
00115             ok = MessageDialog.openQuestion(shell, "Java vendor is not supported", 
00116                     "Warning ! JVM vendor is not supported: " + vendor + "\n" + 
00117                     "The application may not work properly with this JVM\nDo you want to continue ?");
00118         }
00119         return ok;
00120     }
00121 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1