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
00023
00024
00025
00026
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
00040
00041
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
00058
00059
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
00073
00074
00075
00076
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
00104
00105
00106
00107
00108
00109
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 }