From: <pat...@us...> - 2010-09-28 22:21:18
|
Revision: 1138 http://cishell.svn.sourceforge.net/cishell/?rev=1138&view=rev Author: pataphil Date: 2010-09-28 22:21:12 +0000 (Tue, 28 Sep 2010) Log Message: ----------- * The warning message displayed to users when a bundle on the menu isn't found now prints the actual tool's (i.e. Sci2, EpiC, Network Workbench) name instead of Network Workbench for all tools. * The above warning message also displays the appropriate bug tracker URL. * Reviewed by Micah. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2010-09-28 22:19:35 UTC (rev 1137) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2010-09-28 22:21:12 UTC (rev 1138) @@ -17,6 +17,7 @@ org.cishell.reference.service.metatype, org.cishell.service.conversion;version="1.0.0", org.cishell.service.guibuilder;version="1.0.0", + org.cishell.utilities, org.osgi.service.cm;version="1.2.0", org.osgi.service.log;version="1.3.0", org.osgi.service.metatype;version="1.1.0" Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java 2010-09-28 22:19:35 UTC (rev 1137) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java 2010-09-28 22:21:12 UTC (rev 1138) @@ -1,9 +1,14 @@ package org.cishell.reference.gui.menumanager; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + import org.cishell.framework.CIShellContext; import org.cishell.framework.LocalCIShellContext; import org.cishell.reference.gui.menumanager.menu.MenuAdapter; import org.cishell.reference.gui.workspace.CIShellApplication; +import org.cishell.utilities.StringUtilities; import org.eclipse.jface.action.IMenuManager; import org.eclipse.swt.SWT; import org.eclipse.swt.awt.SWT_AWT; @@ -14,35 +19,33 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; -/** - * The activator class controls the plug-in life cycle - */ public class Activator extends AbstractUIPlugin implements IStartup { - - // The plug-in ID public static final String PLUGIN_ID = "org.cishell.reference.gui.menumanager"; - // The shared instance + public static final String CONFIGURATION_DIRECTORY = "configuration"; + public static final String WELCOME_TEXT_FILE_NAME = "Welcome.properties"; + + public static final String DEFAULT_TOOL_NAME = "CIShell"; + public static final String TOOL_NAME_PROPERTY = "toolName"; + public static final String DEFAULT_TOOL_TICKET_URL = + "http://cns-jira.slis.indiana.edu/secure/CreateIssue.jspa?issuetype=1"; + public static final String TOOL_TICKET_URL_PROPERTY = "toolTicketURL"; + + // The shared instance. private static Activator plugin; - - private static BundleContext context; - - MenuAdapter menuAdapter; - - /** - * The constructor - */ + private static BundleContext bundleContext; + + @SuppressWarnings("unused") + private MenuAdapter menuAdapter; + public Activator() { - plugin = this; + Activator.plugin = this; } - /** - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext context) throws Exception { - super.start(context); + public void start(BundleContext bundleContext) throws Exception { + super.start(bundleContext); - Activator.context = context; + Activator.bundleContext = bundleContext; while (getWorkbench() == null) { Thread.sleep(500); @@ -57,15 +60,25 @@ final Shell shell = windows[0].getShell(); IMenuManager menuManager = CIShellApplication.getMenuManager(); - CIShellContext ciContext = new LocalCIShellContext(context); + CIShellContext ciShellContext = new LocalCIShellContext(bundleContext); + Properties properties = getProperties(); + String toolName = getToolName(properties); + String toolTicketURL = getToolTicketURL(properties); - menuAdapter = new MenuAdapter(menuManager,shell,context,ciContext, windows[0]); + this.menuAdapter = new MenuAdapter( + toolName, + toolTicketURL, + menuManager, + shell, + bundleContext, + ciShellContext, + windows[0]); try { - //Fix to make swing based algorithms work on Macs + // Fix to make swing based algorithms work on Macs. shell.getDisplay().syncExec(new Runnable(){ public void run() { - //This will simply initialize the SWT_AWT compatibility mode + // This will simply initialize the SWT_AWT compatibility mode. SWT_AWT.new_Frame(new Shell(SWT.EMBEDDED)); }}); } catch (Exception e) { @@ -73,36 +86,62 @@ } } - /** - * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) - */ public void stop(BundleContext context) throws Exception { - plugin = null; - menuAdapter = null; + Activator.plugin = null; + this.menuAdapter = null; super.stop(context); } - public static Object getService(String service_pid) { - ServiceReference ref = context.getServiceReference(service_pid); - - if (ref != null) { - return context.getService(ref); + public static Object getService(String servicePID) { + ServiceReference serviceReference = + Activator.bundleContext.getServiceReference(servicePID); + + if (serviceReference != null) { + return Activator.bundleContext.getService(serviceReference); } else { return null; } } - /** - * Returns the shared instance - * - * @return the shared instance - */ public static Activator getDefault() { - return plugin; + return Activator.plugin; } public void earlyStartup() { - } + + private static Properties getProperties() { + Properties brandBundleProperties = new Properties(); + + try { + URL welcomeTextFileURL = new URL(new URL( + System.getProperty("osgi.configuration.area")), WELCOME_TEXT_FILE_NAME); + brandBundleProperties.load(welcomeTextFileURL.openStream()); + } catch (IOException e) { + throw new RuntimeException(e.getMessage(), e); + } + + return brandBundleProperties; + } + + private static String getToolName(Properties properties) { + String toolName = properties.getProperty(TOOL_NAME_PROPERTY); + + if (!StringUtilities.isNull_Empty_OrWhitespace(toolName)) { + return toolName; + } else { + return DEFAULT_TOOL_NAME; + } + } + + private static String getToolTicketURL(Properties properties) { + String toolTicketURL = properties.getProperty(TOOL_TICKET_URL_PROPERTY); + + if (!StringUtilities.isNull_Empty_OrWhitespace(toolTicketURL)) { + return toolTicketURL; + } else { + return DEFAULT_TOOL_TICKET_URL; + } + } } Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2010-09-28 22:19:35 UTC (rev 1137) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2010-09-28 22:21:12 UTC (rev 1138) @@ -67,12 +67,16 @@ public static final String PRESERVED_SERVICE_PID = "service.pid"; public static final String PRESERVED = "preserved"; + public static final String HELP_DESK_EMAIL_ADDRESS = "nwb...@go..."; + + private String toolName; + private String toolTicketURL; private IMenuManager menuManager; private Shell shell; private BundleContext bundleContext; private CIShellContext ciShellContext; - private Map algorithmsToItems; - private Map itemsToParents; + private Map<String, Action> algorithmsToActions; + private Map<Action, IMenuManager> actionsToMenuManagers; private ContextListener contextListener; private IWorkbenchWindow workbenchWindow; private LogService logger; @@ -85,13 +89,13 @@ * the menu_path and label but are not listed in DEFAULT_MENU_FILE_NAME will be added on to * the menu. */ - private Map pidsToServiceReferences; + private Map<String, ServiceReference> pidsToServiceReferences; /* * This is the exactly same copy of pidsToServiceReferences. * Since some plug-ins could display on menu more than once, it provides a map between a pid * and a serviceReference while in pidsToServiceReferences that pid has been removed. */ - private Map pidsToServiceReferencesCopy; + private Map<String, ServiceReference> pidsToServiceReferencesCopy; private Document documentObjectModel; private Runnable updateAction = new Runnable() { @@ -103,34 +107,38 @@ private Runnable stopAction = new Runnable() { public void run() { String[] algorithmKeys = - (String[])MenuAdapter.this.algorithmsToItems.keySet().toArray(new String[]{}); + MenuAdapter.this.algorithmsToActions.keySet().toArray(new String[]{}); for (int ii = 0; ii < algorithmKeys.length; ii++) { - Action item = (Action)algorithmsToItems.get(algorithmKeys[ii]); - IMenuManager targetMenu = (IMenuManager)MenuAdapter.this.itemsToParents.get(item); + Action item = MenuAdapter.this.algorithmsToActions.get(algorithmKeys[ii]); + IMenuManager targetMenu = MenuAdapter.this.actionsToMenuManagers.get(item); targetMenu.remove(item.getId()); - MenuAdapter.this.algorithmsToItems.remove(algorithmKeys[ii]); - MenuAdapter.this.itemsToParents.remove(item); + MenuAdapter.this.algorithmsToActions.remove(algorithmKeys[ii]); + MenuAdapter.this.actionsToMenuManagers.remove(item); } } }; public MenuAdapter( + String toolName, + String toolTicketURL, IMenuManager menuManager, Shell shell, BundleContext bundleContext, CIShellContext ciShellContext, IWorkbenchWindow workbenchWindow) { + this.toolName = toolName; + this.toolTicketURL = toolTicketURL; this.menuManager = menuManager; this.shell = shell; this.bundleContext = bundleContext; this.ciShellContext = ciShellContext; this.workbenchWindow = workbenchWindow; - this.algorithmsToItems = new HashMap(); - this.itemsToParents = new HashMap(); - this.pidsToServiceReferences = new HashMap(); - this.pidsToServiceReferencesCopy = new HashMap(); + this.algorithmsToActions = new HashMap<String, Action>(); + this.actionsToMenuManagers = new HashMap<Action, IMenuManager>(); + this.pidsToServiceReferences = new HashMap<String, ServiceReference>(); + this.pidsToServiceReferencesCopy = new HashMap<String, ServiceReference>(); this.logger = (LogService)this.ciShellContext.getService(LogService.class.getName()); /* @@ -244,8 +252,8 @@ continue; } else { String pid = (String)serviceReferences[ii].getProperty(PRESERVED_SERVICE_PID); - pidsToServiceReferences.put(pid.toLowerCase().trim(), serviceReferences[ii]); - pidsToServiceReferencesCopy.put( + this.pidsToServiceReferences.put(pid.toLowerCase().trim(), serviceReferences[ii]); + this.pidsToServiceReferencesCopy.put( pid.toLowerCase().trim(), serviceReferences[ii]); } } @@ -386,8 +394,7 @@ // Check if the PID has registered in pidsToServiceReferences. if (this.pidsToServiceReferencesCopy.containsKey(pid.toLowerCase().trim())){ ServiceReference serviceReference = - (ServiceReference)this.pidsToServiceReferencesCopy.get( - pid.toLowerCase().trim()); + this.pidsToServiceReferencesCopy.get(pid.toLowerCase().trim()); this.pidsToServiceReferences.remove(pid.toLowerCase().trim()); AlgorithmAction action = new AlgorithmAction(serviceReference, this.bundleContext, this.ciShellContext); @@ -414,14 +421,24 @@ } } else { + String algorithmNotFoundFormat = + "Oops! %s tried to place an algorithm with the id '%s' " + + "on the menu, but the algorithm could not be found."; String algorithmNotFoundMessage = - "Oops! Network Workbench tried to place an algorithm with the id '" + - pid + - "' on the menu, but the algorithm could not be found."; - String contactInformationMessage = - "If you see this error, please contact nwb...@go..., or " + - "post a ticket on our bug tracker at: " + - "http://cns-trac.slis.indiana.edu/trac/nwb ."; + String.format(algorithmNotFoundFormat, this.toolName, pid); +// String algorithmNotFoundMessage = +// "Oops! Network Workbench tried to place an algorithm with the id '" + +// pid + +// "' on the menu, but the algorithm could not be found."; + String contactInformationFormat = + "If you see this error, please contact %s, " + + "or post a ticket on our bug tracker at: %s ."; + String contactInformationMessage = String.format( + contactInformationFormat, HELP_DESK_EMAIL_ADDRESS, this.toolTicketURL); +// String contactInformationMessage = +// "If you see this error, please contact nwb...@go..., or " + +// "post a ticket on our bug tracker at: " + +// "http://cns-trac.slis.indiana.edu/trac/nwb ."; this.logger.log(LogService.LOG_DEBUG, algorithmNotFoundMessage); this.logger.log(LogService.LOG_DEBUG, contactInformationMessage); } @@ -452,13 +469,17 @@ */ private void processLeftServiceBundles() { if (!this.pidsToServiceReferences.isEmpty()){ - Object[] keys = this.pidsToServiceReferences.keySet().toArray(); - - for (int ii = 0; ii < keys.length; ii++) { - ServiceReference serviceReference = - (ServiceReference)this.pidsToServiceReferences.get((String)keys[ii]); + for (String key : this.pidsToServiceReferences.keySet()) { + ServiceReference serviceReference = this.pidsToServiceReferences.get(key); makeMenuItem(serviceReference); - } + } +// Object[] keys = this.pidsToServiceReferences.keySet().toArray(); +// +// for (int ii = 0; ii < keys.length; ii++) { +// ServiceReference serviceReference = +// (ServiceReference)this.pidsToServiceReferences.get((String)keys[ii]); +// makeMenuItem(serviceReference); +// } } } @@ -536,8 +557,8 @@ targetMenu.appendToGroup(group, action); handleActionAccelerator(action, targetMenu, serviceReference); targetMenu.appendToGroup(group, new Separator()); - algorithmsToItems.put(getItemID(serviceReference), action); - itemsToParents.put(action, targetMenu); + algorithmsToActions.put(getItemID(serviceReference), action); + actionsToMenuManagers.put(action, targetMenu); Display.getDefault().asyncExec(this.updateAction); } else { @@ -564,7 +585,7 @@ } private void updateMenuItem(ServiceReference serviceReference) { - Action item = (Action)this.algorithmsToItems.get(getItemID(serviceReference)); + Action item = (Action)this.algorithmsToActions.get(getItemID(serviceReference)); if (item != null) { this.logger.log( @@ -575,7 +596,7 @@ private void removeMenuItem(ServiceReference serviceReference) { String path = (String)serviceReference.getProperty(MENU_PATH); - final Action item = (Action)this.algorithmsToItems.get(getItemID(serviceReference)); + final Action item = this.algorithmsToActions.get(getItemID(serviceReference)); if ((path != null) && (item != null)) { int index = path.lastIndexOf('/'); @@ -593,8 +614,8 @@ }); } - this.algorithmsToItems.remove(getItemID(serviceReference)); - this.itemsToParents.remove(item); + this.algorithmsToActions.remove(getItemID(serviceReference)); + this.actionsToMenuManagers.remove(item); } } } @@ -646,7 +667,7 @@ String shortcutString = (String)serviceReference.getProperty(SHORTCUT); if (shortcutString != null) { - return action.convertAccelerator(shortcutString); + return Action.convertAccelerator(shortcutString); } else { return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |