From: <hu...@us...> - 2008-07-29 21:35:29
|
Revision: 791 http://cishell.svn.sourceforge.net/cishell/?rev=791&view=rev Author: huangb Date: 2008-07-29 21:35:26 +0000 (Tue, 29 Jul 2008) Log Message: ----------- Make the following fix. 1. If there's no default_menu.xml under {nwb_installation_dir}/configuration, the tool should not crash and should display all plug-ins that have been specified menu_path and label in the properties files. Note: in this case, there's no control of the order of top menu and submenus. It completely depends on which plug-in has been loaded first when the tool starts up every time. 2. If there's a default_menu.xml under {nwb_installation_dir}/configuration, use it for constructing the layout of the top menu and submenus. However, there's a preference about what name/label should show up on the menu. 2.1)If an alg's properties file has specified the label, and the corresponding name in the default_menu xml file (share the same pid) is not specified or blank, use the label specified in the properties file. If the name in the xml is not blank, use the name to overwrite the label. If both the label in the properties file and the name in the xml file are blank, this is an error that need to be fixed. 2.2)If an alg didn't specified in the xml file, use the menu_path and label in the properties file to add this alg to the menu. Modified Paths: -------------- 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/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 2008-07-25 21:00:08 UTC (rev 790) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2008-07-29 21:35:26 UTC (rev 791) @@ -14,9 +14,12 @@ package org.cishell.reference.gui.menumanager.menu; import java.io.IOException; +import java.io.File; import java.util.HashMap; import java.util.Map; +import java.net.URI; + import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -63,9 +66,21 @@ /* * This map holds a pid as a key and the corresponding - * ServiceReference as a value. + * ServiceReference as a value. It is built when + * preprocessServiceBundles() is invoked. Then the entries + * are gradually removed when the pids are specified in + * the defaul_menu.xml. If any entries are left, in + * processLeftServiceBundles(), those plug-ins that have + * specified the menu_path and label but are not listed in + * default_menu.xml will be added on to the menu. */ private Map pidToServiceReferenceMap; + /* + * This is the exactly same copy of pidToServiceReferenceMap. + * Since some plug-ins could display on menu more than once, it + * provides a map between a pid and a ref while in pidToServiceReferenceMap + * that pid has been removed. + */ private Map pidToServiceReferenceMapCopy; private Document dom; private static String DEFAULT_MENU_FILE_NAME = "default_menu.xml"; @@ -106,11 +121,15 @@ listener = new ContextListener(); bContext.addServiceListener(listener, filter); preprocessServiceBundles(); - createMenuFromXML(); - processLeftServiceBundles(); + URI fullpath=URI.create(System.getProperty("osgi.configuration.area") + DEFAULT_MENU_FILE_NAME); + if (new File(fullpath).exists()){ + createMenuFromXML(fullpath.toString()); + processLeftServiceBundles(); + }else{ + initializeMenu(); + } Display.getDefault().asyncExec(updateAction); -// initializeMenu(); } catch (InvalidSyntaxException e) { getLog().log(LogService.LOG_DEBUG, "Invalid Syntax", e); } @@ -118,9 +137,10 @@ /* * This method scans all service bundles. If a bundle specifies - * menu_path, get service.pid of this bundle (key), let the service + * menu_path and label, get service.pid of this bundle (key), let the service * reference as the value, and put key/value pair * to pidToServiceReferenceMap for further processing. + * */ private void preprocessServiceBundles() throws InvalidSyntaxException{ ServiceReference[] refs = bContext.getAllServiceReferences( @@ -128,6 +148,7 @@ if (refs != null){ for (int i=0; i < refs.length; i++) { String path = (String)refs[i].getProperty(MENU_PATH); + String label = (String)refs[i].getProperty(LABEL); if (path == null){ continue; } @@ -144,9 +165,16 @@ * check if the pid exists in pidToServiceReferenceMap. If so, get the action and add to the parent menu * If not, ignore this menu. At the end of each top menu or subgroup menu or before help menu, * add "additions" so that new algorithms can be added on later + * + * What is the reasonable logic? + * If a plug-in has been specified in the default_menu.xml, always use that menu layout + * If a plug-in has not been specified in the default_menu.xml, use the menu_path + * specified in the properties file. + * If a plug-in specifies a label in the properties file, always use it. + * */ - private void createMenuFromXML() throws InvalidSyntaxException{ - parseXmlFile(); + private void createMenuFromXML(String menuFilePath) throws InvalidSyntaxException{ + parseXmlFile(menuFilePath); //get the root elememt Element docEle = dom.getDocumentElement(); //get a nodelist of the top menu elements @@ -249,7 +277,6 @@ private void processAMenuNode(Element menuNode, MenuManager parentMenuBar ){ String menuName = menuNode.getAttribute(ATTR_NAME); String pid = menuNode.getAttribute(ATTR_PID); - //System.out.println(">>>pid="+pid); if (pid == null || pid.length()==0){ //check if the name is one of the preserved one //if so add the default action @@ -261,9 +288,25 @@ get(pid.toLowerCase().trim()); pidToServiceReferenceMap.remove(pid.toLowerCase().trim()); AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext); - action.setId(getItemID(ref)); - action.setText(menuName); - parentMenuBar.add(action); + String menuLabel = (String)ref.getProperty(LABEL); + if(menuName!= null && !menuName.isEmpty()){ + //use the name specified in the xml to overwrite the label + action.setText(menuName); + action.setId(getItemID(ref)); + parentMenuBar.add(action); + } + else{ + if (menuLabel!= null && !menuLabel.isEmpty()){ + action.setText(menuLabel); + action.setId(getItemID(ref)); + parentMenuBar.add(action); + } + else { + //this is a problem -- no label is specified in the plug-in's properties file + //and no name is specified in the xml file. + } + } + } else{ //otherwise log the error @@ -274,7 +317,7 @@ } } - private void parseXmlFile(){ + private void parseXmlFile(String menuFilePath){ //get the factory DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setCoalescing(true); @@ -282,9 +325,8 @@ //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); - //parse using builder to get DOM representation of the XML file - String fullpath=System.getProperty("osgi.configuration.area") + DEFAULT_MENU_FILE_NAME; - dom = db.parse(fullpath); + //parse using builder to get DOM representation of the XML file + dom = db.parse(menuFilePath); // printElementAttributes(dom); }catch(ParserConfigurationException pce) { @@ -311,7 +353,7 @@ } } -/* + private void initializeMenu() throws InvalidSyntaxException{ ServiceReference[] refs = bContext.getAllServiceReferences( AlgorithmFactory.class.getName(), null); @@ -323,7 +365,7 @@ } } -*/ + private class ContextListener implements ServiceListener { public void serviceChanged(ServiceEvent event) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |