From: <hu...@us...> - 2006-10-04 15:39:03
|
Revision: 244 http://svn.sourceforge.net/cishell/?rev=244&view=rev Author: huangb Date: 2006-10-04 08:38:05 -0700 (Wed, 04 Oct 2006) Log Message: ----------- clean up the converter after using it for the data conversion Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2006-10-03 19:20:18 UTC (rev 243) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2006-10-04 15:38:05 UTC (rev 244) @@ -158,6 +158,7 @@ for (int j=0; j < data.length; j++) { if (converters[j] != null && converters[j].length > 0) { data[j] = converters[j][0].convert(data[j]); + converters[j] = null; } } Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2006-10-03 19:20:18 UTC (rev 243) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2006-10-04 15:38:05 UTC (rev 244) @@ -54,6 +54,7 @@ for (int i=0; i < data.length; i++) { if (converters[i] != null) { data[i] = converters[i][0].convert(data[i]); + converters[i] = null; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bh...@us...> - 2006-10-24 14:05:56
|
Revision: 311 http://svn.sourceforge.net/cishell/?rev=311&view=rev Author: bh2 Date: 2006-10-24 07:05:50 -0700 (Tue, 24 Oct 2006) Log Message: ----------- * makes sure parents are from original input data and not the converted data * added support for "parentage=default" Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2006-10-24 05:17:17 UTC (rev 310) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2006-10-24 14:05:50 UTC (rev 311) @@ -42,6 +42,7 @@ protected BundleContext bContext; protected ServiceReference ref; protected Data[] data; + protected Data[] originalData; protected Converter[][] converters; public AlgorithmAction(ServiceReference ref, BundleContext bContext, CIShellContext ciContext) { @@ -90,7 +91,7 @@ } if (params != null) { - scheduler.schedule(new AlgorithmWrapper(ref, bContext, ciContext, data, converters, params), ref); + scheduler.schedule(new AlgorithmWrapper(ref, bContext, ciContext, originalData, data, converters, params), ref); } } catch (Throwable e) { e.printStackTrace(); @@ -142,6 +143,13 @@ } } } + + if (data != null) { + originalData = (Data[]) data.clone(); + } else { + originalData = null; + } + setEnabled(data != null && isValid()); } @@ -157,6 +165,7 @@ //FIXME: Could cause concurrency problems... for (int j=0; j < data.length; j++) { if (converters[j] != null && converters[j].length > 0) { + //does not work for large inputs... data[j] = converters[j][0].convert(data[j]); converters[j] = null; } Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2006-10-24 05:17:17 UTC (rev 310) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2006-10-24 14:05:50 UTC (rev 311) @@ -13,7 +13,9 @@ * ***************************************************************************/ package org.cishell.reference.gui.menumanager.menu; +import java.util.ArrayList; import java.util.Dictionary; +import java.util.List; import org.cishell.app.service.datamanager.DataManagerService; import org.cishell.framework.CIShellContext; @@ -21,6 +23,7 @@ import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.AlgorithmProperty; import org.cishell.framework.data.Data; +import org.cishell.framework.data.DataProperty; import org.cishell.service.conversion.Converter; import org.cishell.service.guibuilder.GUIBuilderService; import org.osgi.framework.BundleContext; @@ -31,16 +34,18 @@ protected ServiceReference ref; protected BundleContext bContext; protected CIShellContext ciContext; + protected Data[] originalData; protected Data[] data; protected Converter[][] converters; protected Dictionary parameters; - public AlgorithmWrapper(ServiceReference ref, BundleContext bContext, - CIShellContext ciContext, Data[] data, Converter[][] converters, - Dictionary parameters) { + public AlgorithmWrapper(ServiceReference ref, BundleContext bContext, + CIShellContext ciContext, Data[] originalData, Data[] data, + Converter[][] converters, Dictionary parameters) { this.ref = ref; this.bContext = bContext; this.ciContext = ciContext; + this.originalData = originalData; this.data = data; this.converters = converters; this.parameters = parameters; @@ -70,7 +75,18 @@ bContext.getService(bContext.getServiceReference( DataManagerService.class.getName())); + doParentage(outData); + + List goodData = new ArrayList(); for (int i=0; i < outData.length; i++) { + if (outData[i] != null) { + goodData.add(outData[i]); + } + } + + outData = (Data[]) goodData.toArray(new Data[0]); + + if (outData.length != 0) { dataManager.setSelectedData(outData); } } @@ -86,4 +102,44 @@ return new Data[0]; } } + + //only does anything if parentage=default so far... + protected void doParentage(Data[] outData) { + //make sure the parent set is the original Data and not the + //converted data... + if (outData != null && data != null && originalData != null + && originalData.length == data.length) { + for (int i=0; i < outData.length; i++) { + Object parent = outData[i].getMetaData().get(DataProperty.PARENT); + + if (parent != null) { + for (int j=0; j < data.length; i++) { + if (parent == data[j]) { + outData[i].getMetaData().put(DataProperty.PARENT, + originalData[j]); + break; + } + } + } + } + } + + //check and act on parentage settings + String parentage = (String)ref.getProperty("parentage"); + if (parentage != null) { + parentage = parentage.trim(); + if (parentage.equalsIgnoreCase("default")) { + if (originalData != null && originalData.length > 0 && originalData[0] != null) { + + for (int i=0; i < outData.length; i++) { + //if they don't have a parent set already then we set one + if (outData[i] != null && + outData[i].getMetaData().get(DataProperty.PARENT) == null) { + outData[i].getMetaData().put(DataProperty.PARENT, originalData[0]); + } + } + } + } + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hu...@us...> - 2006-10-26 18:25:25
|
Revision: 321 http://svn.sourceforge.net/cishell/?rev=321&view=rev Author: huangb Date: 2006-10-26 11:22:21 -0700 (Thu, 26 Oct 2006) Log Message: ----------- minus change to adjust the printout messages on the console. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2006-10-26 17:52:03 UTC (rev 320) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2006-10-26 18:22:21 UTC (rev 321) @@ -82,9 +82,10 @@ LogService logger = (LogService) ciContext.getService(LogService.class.getName()); String label = (String)ref.getProperty("label"); - if (label != null) + if (label != null){ + logger.log(LogService.LOG_INFO, ".........."); logger.log(LogService.LOG_INFO, label+" was selected."); - + } String authors = (String)ref.getProperty("authors"); if (authors != null) logger.log(LogService.LOG_INFO, "Author(s): "+authors); Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2006-10-26 17:52:03 UTC (rev 320) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2006-10-26 18:22:21 UTC (rev 321) @@ -72,7 +72,7 @@ if (logger != null) { if (!this.parameters.isEmpty()) { logger.log(LogService.LOG_INFO, ""); - logger.log(LogService.LOG_INFO, "Input Parameters Used:"); + logger.log(LogService.LOG_INFO, "Input Parameters:"); for (Enumeration e = this.parameters.keys(); e .hasMoreElements();) { String key = (String) e.nextElement(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bh...@us...> - 2006-10-27 20:21:47
|
Revision: 328 http://svn.sourceforge.net/cishell/?rev=328&view=rev Author: bh2 Date: 2006-10-27 13:21:33 -0700 (Fri, 27 Oct 2006) Log Message: ----------- cleaned up input parameter printing in the console Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2006-10-27 19:54:39 UTC (rev 327) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2006-10-27 20:21:33 UTC (rev 328) @@ -75,38 +75,7 @@ //save the current data Data[] data = this.data; Converter[][] converters = this.converters; - - //Print out acknowledge info. Not sure this is the right place. - //But it seems working fine. - LogService logger = (LogService) ciContext.getService(LogService.class.getName()); - - String label = (String)ref.getProperty("label"); - if (label != null){ - logger.log(LogService.LOG_INFO, ".........."); - logger.log(LogService.LOG_INFO, label+" was selected."); - } - String authors = (String)ref.getProperty("authors"); - if (authors != null) - logger.log(LogService.LOG_INFO, "Author(s): "+authors); - String implementers = (String)ref.getProperty("implementers"); - if (implementers != null) - logger.log(LogService.LOG_INFO, "Implementer(s): "+implementers); - String integrators = (String)ref.getProperty("integrators"); - if (integrators != null) - logger.log(LogService.LOG_INFO, "Integrator(s): "+integrators); - String reference = (String)ref.getProperty("reference"); - String reference_url = (String)ref.getProperty("reference_url"); - if (reference != null && reference_url != null ) - logger.log(LogService.LOG_INFO, "Reference: "+reference+ - " ( "+reference_url+" )"); - else if (reference != null && reference_url == null ) - logger.log(LogService.LOG_INFO, "Reference: "+reference); - String docu = (String)ref.getProperty("docu"); - if (docu != null) - logger.log(LogService.LOG_INFO, "Docu: "+docu); -/////////////////////////// - SchedulerService scheduler = (SchedulerService) bContext.getService(bContext.getServiceReference( SchedulerService.class.getName())); @@ -116,6 +85,8 @@ AlgorithmFactory factory = (AlgorithmFactory) bContext.getService(ref); MetaTypeProvider provider = factory.createParameters(null); String pid = (String)ref.getProperty(Constants.SERVICE_PID); + + printAlgorithmInformation(); Dictionary params = new Hashtable(); if (provider != null) { @@ -123,13 +94,43 @@ } if (params != null) { - scheduler.schedule(new AlgorithmWrapper(ref, bContext, ciContext, originalData, data, converters, params), ref); + scheduler.schedule(new AlgorithmWrapper(ref, bContext, ciContext, originalData, data, converters, provider, params), ref); } } catch (Throwable e) { e.printStackTrace(); } } + private void printAlgorithmInformation() { + LogService logger = (LogService) ciContext.getService(LogService.class.getName()); + + String label = (String)ref.getProperty("label"); + if (label != null){ + logger.log(LogService.LOG_INFO, ".........."); + logger.log(LogService.LOG_INFO, label+" was selected."); + } + String authors = (String)ref.getProperty("authors"); + if (authors != null) + logger.log(LogService.LOG_INFO, "Author(s): "+authors); + String implementers = (String)ref.getProperty("implementers"); + if (implementers != null) + logger.log(LogService.LOG_INFO, "Implementer(s): "+implementers); + String integrators = (String)ref.getProperty("integrators"); + if (integrators != null) + logger.log(LogService.LOG_INFO, "Integrator(s): "+integrators); + String reference = (String)ref.getProperty("reference"); + String reference_url = (String)ref.getProperty("reference_url"); + if (reference != null && reference_url != null ) + logger.log(LogService.LOG_INFO, "Reference: "+reference+ + " ( "+reference_url+" )"); + else if (reference != null && reference_url == null ) + logger.log(LogService.LOG_INFO, "Reference: "+reference); + String docu = (String)ref.getProperty("docu"); + if (docu != null) + logger.log(LogService.LOG_INFO, "Docu: "+docu); + + } + public void dataSelected(Data[] selectedData) { String inDataString = (String)ref.getProperty(IN_DATA); String[] inData = ("" + inDataString).split(","); Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2006-10-27 19:54:39 UTC (rev 327) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2006-10-27 20:21:33 UTC (rev 328) @@ -16,7 +16,9 @@ import java.util.ArrayList; import java.util.Dictionary; import java.util.Enumeration; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.cishell.app.service.datamanager.DataManagerService; import org.cishell.framework.CIShellContext; @@ -28,8 +30,12 @@ import org.cishell.service.conversion.Converter; import org.cishell.service.guibuilder.GUIBuilderService; import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; +import org.osgi.service.metatype.AttributeDefinition; +import org.osgi.service.metatype.MetaTypeProvider; +import org.osgi.service.metatype.ObjectClassDefinition; public class AlgorithmWrapper implements Algorithm, AlgorithmProperty { @@ -40,10 +46,13 @@ protected Data[] data; protected Converter[][] converters; protected Dictionary parameters; + protected Map idToLabelMap; + protected MetaTypeProvider provider; public AlgorithmWrapper(ServiceReference ref, BundleContext bContext, CIShellContext ciContext, Data[] originalData, Data[] data, - Converter[][] converters, Dictionary parameters) { + Converter[][] converters, MetaTypeProvider provider, + Dictionary parameters) { this.ref = ref; this.bContext = bContext; this.ciContext = ciContext; @@ -51,6 +60,8 @@ this.data = data; this.converters = converters; this.parameters = parameters; + this.provider = provider; + this.idToLabelMap = new HashMap(); } /** @@ -68,19 +79,7 @@ AlgorithmFactory factory = (AlgorithmFactory) bContext.getService(ref); Algorithm alg = factory.createAlgorithm(data, parameters, ciContext); - LogService logger = getLogService(); - if (logger != null) { - if (!this.parameters.isEmpty()) { - logger.log(LogService.LOG_INFO, ""); - logger.log(LogService.LOG_INFO, "Input Parameters:"); - for (Enumeration e = this.parameters.keys(); e - .hasMoreElements();) { - String key = (String) e.nextElement(); - logger.log(LogService.LOG_INFO, key + ": " - + this.parameters.get(key)); - } - } - } + printParameters(); Data[] outData = alg.execute(); @@ -117,6 +116,49 @@ } } + protected void printParameters() { + LogService logger = getLogService(); + setupIdToLabelMap(); + + if (logger != null) { + if (!this.parameters.isEmpty()) { + logger.log(LogService.LOG_INFO, ""); + logger.log(LogService.LOG_INFO, "Input Parameters:"); + for (Enumeration e = this.parameters.keys(); e + .hasMoreElements();) { + String key = (String) e.nextElement(); + Object value = this.parameters.get(key); + + key = (String) idToLabelMap.get(key); + + logger.log(LogService.LOG_INFO, key+": "+value); + } + } + } + } + + protected void setupIdToLabelMap() { + if (provider != null) { + ObjectClassDefinition ocd = null; + try { + String pid = (String) ref.getProperty(Constants.SERVICE_PID); + ocd = provider.getObjectClassDefinition(pid, null); + + if (ocd != null) { + AttributeDefinition[] attr = + ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); + + for (int i=0; i < attr.length; i++) { + String id = attr[i].getID(); + String label = attr[i].getName(); + + idToLabelMap.put(id, label); + } + } + } catch (IllegalArgumentException e) {} + } + } + //only does anything if parentage=default so far... protected void doParentage(Data[] outData) { //make sure the parent set is the original Data and not the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fu...@us...> - 2007-02-21 16:26:27
|
Revision: 365 http://svn.sourceforge.net/cishell/?rev=365&view=rev Author: fugu13 Date: 2007-02-21 08:26:00 -0800 (Wed, 21 Feb 2007) Log Message: ----------- Now algorithms don't ask for parameters until after data conversion, meaning parameters can be data-dependent. This also means 'canceled' algorithms show up in the scheduler, but we just need to add a way to indicate an algorithm was canceled. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2007-01-22 22:23:02 UTC (rev 364) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2007-02-21 16:26:00 UTC (rev 365) @@ -79,23 +79,14 @@ SchedulerService scheduler = (SchedulerService) bContext.getService(bContext.getServiceReference( SchedulerService.class.getName())); - GUIBuilderService builder = (GUIBuilderService) - ciContext.getService(GUIBuilderService.class.getName()); - AlgorithmFactory factory = (AlgorithmFactory) bContext.getService(ref); - MetaTypeProvider provider = factory.createParameters(null); - String pid = (String)ref.getProperty(Constants.SERVICE_PID); printAlgorithmInformation(); - Dictionary params = new Hashtable(); - if (provider != null) { - params = builder.createGUIandWait(pid, provider); - } - if (params != null) { - scheduler.schedule(new AlgorithmWrapper(ref, bContext, ciContext, originalData, data, converters, provider, params), ref); - } + + + scheduler.schedule(new AlgorithmWrapper(ref, bContext, ciContext, originalData, data, converters), ref); } catch (Throwable e) { e.printStackTrace(); } Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2007-01-22 22:23:02 UTC (rev 364) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2007-02-21 16:26:00 UTC (rev 365) @@ -17,6 +17,7 @@ import java.util.Dictionary; import java.util.Enumeration; import java.util.HashMap; +import java.util.Hashtable; import java.util.List; import java.util.Map; @@ -55,21 +56,18 @@ public AlgorithmWrapper(ServiceReference ref, BundleContext bContext, CIShellContext ciContext, Data[] originalData, Data[] data, - Converter[][] converters, MetaTypeProvider provider, - Dictionary parameters) { + Converter[][] converters) { this.ref = ref; this.bContext = bContext; this.ciContext = ciContext; this.originalData = originalData; this.data = data; this.converters = converters; - this.parameters = parameters; - this.provider = provider; + this.idToLabelMap = new HashMap(); this.progressMonitor = null; - AlgorithmFactory factory = (AlgorithmFactory) bContext.getService(ref); - algorithm = factory.createAlgorithm(data, parameters, ciContext); + } /** @@ -83,7 +81,25 @@ converters[i] = null; } } - + + GUIBuilderService builder = (GUIBuilderService) + ciContext.getService(GUIBuilderService.class.getName()); + + AlgorithmFactory factory = (AlgorithmFactory) bContext.getService(ref); + this.provider = factory.createParameters(data); + String pid = (String)ref.getProperty(Constants.SERVICE_PID); + + this.parameters = new Hashtable(); + if (provider != null) { + this.parameters = builder.createGUIandWait(pid, provider); + } + + if(this.parameters == null) { + return new Data[0]; + } + + algorithm = factory.createAlgorithm(data, parameters, ciContext); + printParameters(); if (progressMonitor != null && algorithm instanceof ProgressTrackable) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tea...@us...> - 2007-05-10 18:09:43
|
Revision: 394 http://svn.sourceforge.net/cishell/?rev=394&view=rev Author: teakettle22 Date: 2007-05-10 11:09:40 -0700 (Thu, 10 May 2007) Log Message: ----------- Adjusted the menu managers so that the File and Help menus are initially created and added to the beginning and end respectively. All other menus are created in between Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.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/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2007-05-09 14:30:55 UTC (rev 393) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2007-05-10 18:09:40 UTC (rev 394) @@ -22,15 +22,18 @@ import org.cishell.app.service.scheduler.SchedulerService; import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.AlgorithmProperty; -//import org.cishell.framework.algorithm.DataValidator; import org.cishell.framework.data.Data; import org.cishell.service.conversion.Converter; import org.cishell.service.conversion.DataConversionService; import org.eclipse.jface.action.Action; import org.osgi.framework.BundleContext; -//import org.osgi.framework.Constants; import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; public class AlgorithmAction extends Action implements AlgorithmProperty, DataManagerListener { @@ -248,4 +251,6 @@ public ServiceReference getServiceReference(){ return ref; } + + } \ No newline at end of file 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 2007-05-09 14:30:55 UTC (rev 393) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2007-05-10 18:09:40 UTC (rev 394) @@ -14,25 +14,17 @@ package org.cishell.reference.gui.menumanager.menu; //Java +import java.io.IOException; import java.util.HashMap; import java.util.Map; -import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -//CIShell import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.AlgorithmProperty; - -//Eclipse import org.eclipse.jface.action.Action; import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.IContributionItem; @@ -41,12 +33,10 @@ import org.eclipse.jface.action.Separator; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; - -//OSGi import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; import org.osgi.framework.InvalidSyntaxException; @@ -54,6 +44,12 @@ import org.osgi.framework.ServiceListener; import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; /* @@ -170,36 +166,26 @@ } private void processTopMenu (Element topMenuNode){ - MenuManager topMenuBar; + MenuManager topMenuBar = null; - //First create and add topMenuBar to the menuBar - String topMenuName = topMenuNode.getAttribute(ATTR_NAME); - if (topMenuName.equalsIgnoreCase("file")){ - topMenuBar= new MenuManager("&File", IWorkbenchActionConstants.M_FILE); - } - else if (topMenuName.equalsIgnoreCase("help")){ - topMenuBar= new MenuManager("&Help", - IWorkbenchActionConstants.M_HELP); - //allow to append new top level menu before "Help" - menuBar.add(new GroupMarker(START_GROUP)); - menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); - menuBar.add(new GroupMarker(END_GROUP)); - - //allow to append new sub menu under "Help" and before "/Help/About" - topMenuBar.add(new GroupMarker(START_GROUP)); - topMenuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); - topMenuBar.add(new GroupMarker(END_GROUP)); - - IWorkbenchAction aboutAction = ActionFactory.ABOUT.create(window); - topMenuBar.add(new Separator()); - topMenuBar.add(aboutAction); - + + /* + * The File and Help menus are created in ApplicationActionBarAdvisor.java + * This function now parses the XML file and appends the new menus/menu items to the correct group + * We first check to see if the menu already exists in our MenuBar. If it does, we modify the already + * existing menu. If not, then we create a new Menu. + * + * Modified by: Tim Kelley + * Date: May 8-9, 2007 + * Additional code at: org.cishell.reference.gui.workspace.ApplicationActionBarAdvisor.java + */ + + String topMenuName = topMenuNode.getAttribute(ATTR_NAME); + if((topMenuBar = (MenuManager)menuBar.findUsingPath(topMenuName)) == null){ //Check to see if menu exists + topMenuBar= new MenuManager(topMenuName, topMenuName.toLowerCase()); //Create a new menu if it doesn't + menuBar.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, topMenuBar); } - else { - topMenuBar= new MenuManager(topMenuName, topMenuName.toLowerCase()); - } - menuBar.add(topMenuBar); //Second process submenu processSubMenu(topMenuNode, topMenuBar); } @@ -270,7 +256,7 @@ private void processAMenuNode(Element menuNode, MenuManager parentMenuBar ){ String menuName = menuNode.getAttribute(ATTR_NAME); String pid = menuNode.getAttribute(ATTR_PID); -// System.out.println(">>>pid="+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 @@ -299,7 +285,7 @@ private void parseXmlFile(){ //get the factory DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - + dbf.setCoalescing(true); try { //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); @@ -307,7 +293,8 @@ //parse using builder to get DOM representation of the XML file String fullpath=System.getProperty("osgi.configuration.area") + DEFAULT_MENU_FILE_NAME; // System.out.println(">>parse file: "+fullpath); - dom = db.parse(fullpath); + dom = db.parse(fullpath); + // printElementAttributes(dom); }catch(ParserConfigurationException pce) { pce.printStackTrace(); @@ -367,7 +354,7 @@ private void makeMenuItem(ServiceReference ref) { String path = (String)ref.getProperty(MENU_PATH); String[] items = (path == null) ? null : path.split("/"); - + IMenuManager menu = null; if (items != null && items.length > 1) { AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext); action.setId(getItemID(ref)); @@ -376,28 +363,35 @@ String group = items[items.length-1]; for (int i=0; i < items.length-1; i++) { - IMenuManager menu = targetMenu.findMenuUsingPath(items[i]); - + + menu = targetMenu.findMenuUsingPath(items[i]); + if (menu == null && items[i] != null) { menu = targetMenu.findMenuUsingPath(items[i].toLowerCase()); + } if (menu == null) { + menu = createMenu(items[i],items[i]); targetMenu.appendToGroup(ADDITIONS_GROUP, menu); } targetMenu = menu; + + } group = items[items.length-1]; IContributionItem groupItem = targetMenu.find(group); + if (groupItem == null) { groupItem = new GroupMarker(group); targetMenu.appendToGroup(ADDITIONS_GROUP, groupItem); } targetMenu.appendToGroup(group, action); + targetMenu.appendToGroup(group, new Separator()); algorithmToItemMap.put(getItemID(ref), action); itemToParentMap.put(action, targetMenu); @@ -489,4 +483,40 @@ private LogService getLog() { return (LogService) ciContext.getService(LogService.class.getName()); } + /* + * printElementAttributes takes in a xml document, gets the nodes, then prints the attributes. + * Copied from Java Tutorial on XML Parsing by Tim Kelley for debugging purposes. + */ + static void printElementAttributes(Document doc) + { + NodeList nl = doc.getElementsByTagName("*"); + Element e; + Node n; + NamedNodeMap nnm; + + String attrname; + String attrval; + int i, len; + + len = nl.getLength(); + + for (int j=0; j < len; j++) + { + e = (Element)nl.item(j); + System.err.println(e.getTagName() + ":"); + nnm = e.getAttributes(); + + if (nnm != null) + { + for (i=0; i<nnm.getLength(); i++) + { + n = nnm.item(i); + attrname = n.getNodeName(); + attrval = n.getNodeValue(); + System.err.print(" " + attrname + " = " + attrval); + } + } + System.err.println(); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bh...@us...> - 2008-03-27 18:35:41
|
Revision: 729 http://cishell.svn.sourceforge.net/cishell/?rev=729&view=rev Author: bh2 Date: 2008-03-27 11:35:36 -0700 (Thu, 27 Mar 2008) Log Message: ----------- Updated menumanager, cleaning up a bit, and better handling exceptions. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.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/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2008-03-27 17:46:12 UTC (rev 728) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2008-03-27 18:35:36 UTC (rev 729) @@ -72,8 +72,6 @@ dataSelected(dataManager.getSelectedData()); } - - public void run() { //hmm... should probably change this.. maybe use the scheduler... new Thread("Menu Item Runner") { @@ -92,13 +90,9 @@ bContext.getService(bContext.getServiceReference( SchedulerService.class.getName())); - printAlgorithmInformation(); - - - - - scheduler.schedule(new AlgorithmWrapper(ref, bContext, ciContext, originalData, data, converters), ref); + + scheduler.schedule(new AlgorithmWrapper(ref, bContext, ciContext, originalData, data, converters), ref); } catch (Throwable e) { e.printStackTrace(); } @@ -110,10 +104,9 @@ StringBuffer acknowledgement = new StringBuffer(); String label = (String)ref.getProperty(LABEL); if (label != null){ - acknowledgement.append("..........\n"+ - label+" was selected.\n"); + acknowledgement.append("..........\n"+label+" was selected.\n"); } - String authors = (String)ref.getProperty("authors"); + String authors = (String)ref.getProperty(AUTHORS); if (authors != null) acknowledgement.append("Author(s): "+authors+"\n"); String implementers = (String)ref.getProperty(IMPLEMENTERS); @@ -133,8 +126,7 @@ if (docu != null) acknowledgement.append("Documentation: "+docu+"\n"); if(acknowledgement.length()>1) - logger.log(LogService.LOG_INFO, acknowledgement.toString()); - + logger.log(LogService.LOG_INFO, acknowledgement.toString()); } public void dataSelected(Data[] selectedData) { @@ -193,34 +185,6 @@ setEnabled(data != null); //&& isValid()); } - //This method will be disabled until we can find a better solution - //for extra validation beyond input/output checking -/* private boolean isValid() { - String valid = null; - String[] classes = (String[]) ref.getProperty(Constants.OBJECTCLASS); - - if (classes != null && data != null) { - for (int i=0; i < classes.length; i++) { - if (classes[i].equals(DataValidator.class.getName())) { - DataValidator validator = (DataValidator) bContext.getService(ref); - - //FIXME: Could cause concurrency problems... - for (int j=0; j < data.length; j++) { - if (converters[j] != null && converters[j].length > 0) { - //does not work for large inputs... - data[j] = converters[j][0].convert(data[j]); - converters[j] = null; - } - } - - valid = validator.validate(data); - } - } - } - - return valid == null || valid.length() == 0; - } -*/ private boolean isAsignableFrom(String type, Data datum) { Object data = datum.getData(); boolean assignable = false; @@ -247,6 +211,4 @@ public ServiceReference getServiceReference(){ return ref; } - - } \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-03-27 17:46:12 UTC (rev 728) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-03-27 18:35:36 UTC (rev 729) @@ -24,6 +24,7 @@ import org.cishell.app.service.datamanager.DataManagerService; import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.AlgorithmProperty; import org.cishell.framework.algorithm.DataValidator; @@ -34,6 +35,7 @@ import org.cishell.framework.data.DataProperty; import org.cishell.reference.gui.menumanager.Activator; import org.cishell.reference.service.metatype.BasicMetaTypeProvider; +import org.cishell.service.conversion.ConversionException; import org.cishell.service.conversion.Converter; import org.cishell.service.guibuilder.GUIBuilderService; import org.osgi.framework.BundleContext; @@ -70,128 +72,133 @@ this.converters = converters; this.idToLabelMap = new HashMap(); - this.progressMonitor = null; - - + this.progressMonitor = null; } /** * @see org.cishell.framework.algorithm.Algorithm#execute() */ public Data[] execute() { - try { - for (int i=0; i < data.length; i++) { - if (converters[i] != null) { - data[i] = converters[i][0].convert(data[i]); - - if (data[i] == null && i < (data.length - 1)) { - Exception e = - new Exception("The converter " + - converters[i].getClass().getName() + - " returned a null result where data was expected."); - throw e; - } - converters[i] = null; - } - } - - GUIBuilderService builder = (GUIBuilderService) - ciContext.getService(GUIBuilderService.class.getName()); - - AlgorithmFactory factory = (AlgorithmFactory) bContext.getService(ref); - - if (factory instanceof DataValidator) { - String validation = ((DataValidator) factory).validate(data); - - if (validation != null && validation.length() > 0) { - String label = (String) ref.getProperty(LABEL); - if (label == null) { - label = "Algorithm"; - } - - builder.showError("Invalid Data", "The data given to \""+label+"\" is incompatible for this reason: "+validation , (String) null); + for (int i=0; i < data.length; i++) { + if (converters[i] != null) { + try { + data[i] = converters[i][0].convert(data[i]); + } catch (ConversionException e) { + log(LogService.LOG_ERROR,"The conversion of data to give" + + " the algorithm failed for this reason: "+e.getMessage(), e); return null; } - } - - String pid = (String)ref.getProperty(Constants.SERVICE_PID); - - String metatype_pid = (String) ref.getProperty(PARAMETERS_PID); - if (metatype_pid == null) { - metatype_pid = pid; - } - this.provider = null; - - MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); - if (metaTypeService != null) { - provider = metaTypeService.getMetaTypeInformation(ref.getBundle()); + if (data[i] == null && i < (data.length - 1)) { + log(LogService.LOG_ERROR, "The converter: " + + converters[i].getClass().getName() + + " returned a null result where data was expected when" + + " converting the data to give the algorithm."); + return null; + } + converters[i] = null; } + } + + GUIBuilderService builder = (GUIBuilderService) + ciContext.getService(GUIBuilderService.class.getName()); + + AlgorithmFactory factory = (AlgorithmFactory) bContext.getService(ref); + + if (factory instanceof DataValidator) { + String validation = ((DataValidator) factory).validate(data); + + if (validation != null && validation.length() > 0) { + String label = (String) ref.getProperty(LABEL); + if (label == null) { + label = "Algorithm"; + } + + builder.showError("Invalid Data", "The data given to \""+label+"\" is incompatible for this reason: "+validation , (String) null); + return null; + } + } + + String pid = (String)ref.getProperty(Constants.SERVICE_PID); + + String metatype_pid = (String) ref.getProperty(PARAMETERS_PID); + if (metatype_pid == null) { + metatype_pid = pid; + } - if (factory instanceof ParameterMutator && provider != null) { - try { - ObjectClassDefinition ocd = provider.getObjectClassDefinition(metatype_pid, null); - - ocd = ((ParameterMutator) factory).mutateParameters(data, ocd); - - if (ocd != null) { - provider = new BasicMetaTypeProvider(ocd); - } - } catch (IllegalArgumentException e) { - log(LogService.LOG_DEBUG, pid+" has an invalid metatype id: "+metatype_pid); + this.provider = null; + + MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); + if (metaTypeService != null) { + provider = metaTypeService.getMetaTypeInformation(ref.getBundle()); + } + + if (factory instanceof ParameterMutator && provider != null) { + try { + ObjectClassDefinition ocd = provider.getObjectClassDefinition(metatype_pid, null); + + ocd = ((ParameterMutator) factory).mutateParameters(data, ocd); + + if (ocd != null) { + provider = new BasicMetaTypeProvider(ocd); } - } + } catch (IllegalArgumentException e) { + log(LogService.LOG_DEBUG, pid+" has an invalid metatype id: "+metatype_pid); + } + } + + this.parameters = new Hashtable(); + if (provider != null) { + this.parameters = builder.createGUIandWait(metatype_pid, provider); + } + + //check to see if the user cancelled the operation + if(this.parameters == null) { + return null; + } + + algorithm = factory.createAlgorithm(data, parameters, ciContext); + + printParameters(); + + if (progressMonitor != null && algorithm instanceof ProgressTrackable) { + ((ProgressTrackable)algorithm).setProgressMonitor(progressMonitor); + } + + Data[] outData = null; + try { + outData = algorithm.execute(); + } catch (AlgorithmExecutionException e) { + log(LogService.LOG_ERROR, + "The Algorithm: \""+ref.getProperty(AlgorithmProperty.LABEL)+ + "\" had an error while executing: "+e.getMessage()); + } catch (RuntimeException e) { + builder.showError("Error!", "An unexpected exception occurred while " + +"executing \""+ref.getProperty(AlgorithmProperty.LABEL)+".\"", e); + } + + if (outData != null) { + DataManagerService dataManager = (DataManagerService) + bContext.getService(bContext.getServiceReference( + DataManagerService.class.getName())); - this.parameters = new Hashtable(); - if (provider != null) { - this.parameters = builder.createGUIandWait(pid, provider); - } + doParentage(outData); - if(this.parameters == null) { - return new Data[0]; + List goodData = new ArrayList(); + for (int i=0; i < outData.length; i++) { + if (outData[i] != null) { + goodData.add(outData[i]); + } } - algorithm = factory.createAlgorithm(data, parameters, ciContext); + outData = (Data[]) goodData.toArray(new Data[0]); - printParameters(); - - if (progressMonitor != null && algorithm instanceof ProgressTrackable) { - ((ProgressTrackable)algorithm).setProgressMonitor(progressMonitor); + if (outData.length != 0) { + dataManager.setSelectedData(outData); } - - Data[] outData = algorithm.execute(); - - if (outData != null) { - DataManagerService dataManager = (DataManagerService) - bContext.getService(bContext.getServiceReference( - DataManagerService.class.getName())); - - doParentage(outData); - - List goodData = new ArrayList(); - for (int i=0; i < outData.length; i++) { - if (outData[i] != null) { - goodData.add(outData[i]); - } - } - - outData = (Data[]) goodData.toArray(new Data[0]); - - if (outData.length != 0) { - dataManager.setSelectedData(outData); - } - } - - return outData; - } catch (Throwable e) { - GUIBuilderService guiBuilder = (GUIBuilderService) - ciContext.getService(GUIBuilderService.class.getName()); - guiBuilder.showError("Error!", - "The Algorithm: \""+ref.getProperty(AlgorithmProperty.LABEL)+ - "\" had an error while executing.", e); - - return new Data[0]; } + + return outData; } protected void log(int logLevel, String message) { @@ -202,6 +209,16 @@ System.out.println(message); } } + + protected void log(int logLevel, String message, Throwable exception) { + LogService log = (LogService) Activator.getService(LogService.class.getName()); + if (log != null) { + log.log(logLevel, message, exception); + } else { + System.out.println(message); + exception.printStackTrace(); + } + } protected void printParameters() { LogService logger = getLogService(); 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-03-27 17:46:12 UTC (rev 728) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2008-03-27 18:35:36 UTC (rev 729) @@ -13,7 +13,6 @@ * ***************************************************************************/ package org.cishell.reference.gui.menumanager.menu; -//Java import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -52,10 +51,6 @@ import org.xml.sax.SAXException; -/* - * Bonnie's comments: - * weird, why implements AlgorithmProperty? It does not define any abstract interface. - */ public class MenuAdapter implements AlgorithmProperty { private IMenuManager menuBar; private Shell shell; @@ -137,13 +132,11 @@ } else{ String pid = (String)refs[i].getProperty(PRESERVED_SERVICE_PID); -// System.out.println("pid="+pid); pidToServiceReferenceMap.put(pid.toLowerCase().trim(), refs[i]); pidToServiceReferenceMapCopy.put(pid.toLowerCase().trim(), refs[i]); } } } - } /* * Parse default_menu.xml file. For each menu node, get the value of the attribut "pid" @@ -167,7 +160,6 @@ private void processTopMenu (Element topMenuNode){ MenuManager topMenuBar = null; - /* * The File and Help menus are created in ApplicationActionBarAdvisor.java @@ -217,7 +209,7 @@ processSubMenu(el, groupMenuBar); } else if (menu_type.equalsIgnoreCase(PRESERVED_BREAK)){ - //It seems that Framework automatially takes care of issues + //It seems that Framework automatically takes care of issues //such as double separators, a separator at the top or bottom parentMenuBar.add(new Separator()); } @@ -260,7 +252,6 @@ if (pid == null || pid.length()==0){ //check if the name is one of the preserved one //if so add the default action - } else{ //check if the pid has registered in pidToServiceReferenceMap @@ -292,7 +283,6 @@ //parse using builder to get DOM representation of the XML file String fullpath=System.getProperty("osgi.configuration.area") + DEFAULT_MENU_FILE_NAME; -// System.out.println(">>parse file: "+fullpath); dom = db.parse(fullpath); // printElementAttributes(dom); @@ -338,7 +328,6 @@ public void serviceChanged(ServiceEvent event) { switch (event.getType()) { case ServiceEvent.REGISTERED: -// System.out.println(">>>receive ServiceEvent.Registered"); makeMenuItem(event.getServiceReference()); break; case ServiceEvent.UNREGISTERING: @@ -367,19 +356,15 @@ menu = targetMenu.findMenuUsingPath(items[i]); if (menu == null && items[i] != null) { - menu = targetMenu.findMenuUsingPath(items[i].toLowerCase()); - + menu = targetMenu.findMenuUsingPath(items[i].toLowerCase()); } - if (menu == null) { - + if (menu == null) { menu = createMenu(items[i],items[i]); targetMenu.appendToGroup(ADDITIONS_GROUP, menu); } targetMenu = menu; - - } group = items[items.length-1]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bh...@us...> - 2008-04-03 16:05:19
|
Revision: 773 http://cishell.svn.sourceforge.net/cishell/?rev=773&view=rev Author: bh2 Date: 2008-04-03 09:04:19 -0700 (Thu, 03 Apr 2008) Log Message: ----------- * moved retrieving of ConfigurationAdmin to where it is actually used by using the bundle context * stopped creating a temporary thread in AlgorithmAction to put the algorithm directly into the scheduler. This used to be necessary when we did some data conversion before going to the scheduler * combined micah's putting stuff into functions and adding userprefs with the other bug fixes/"refactors" I had simultaneously applied At some point we do need to factor some of the 'good bits' out to something... Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.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/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2008-04-02 19:37:27 UTC (rev 772) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2008-04-03 16:04:19 UTC (rev 773) @@ -21,6 +21,7 @@ import org.cishell.app.service.datamanager.DataManagerService; import org.cishell.app.service.scheduler.SchedulerService; import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmProperty; import org.cishell.framework.data.Data; import org.cishell.service.conversion.Converter; @@ -28,7 +29,6 @@ import org.eclipse.jface.action.Action; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; -import org.osgi.service.cm.ConfigurationAdmin; import org.osgi.service.log.LogService; @@ -40,14 +40,10 @@ protected Data[] originalData; protected Converter[][] converters; - protected ConfigurationAdmin ca; - - //ConfigurationAdmin can be null - public AlgorithmAction(ServiceReference ref, BundleContext bContext, CIShellContext ciContext, ConfigurationAdmin ca) { + public AlgorithmAction(ServiceReference ref, BundleContext bContext, CIShellContext ciContext) { this.ref = ref; this.ciContext = ciContext; this.bContext = bContext; - this.ca = ca; setText((String)ref.getProperty(LABEL)); setToolTipText((String)ref.getProperty(AlgorithmProperty.DESCRIPTION)); @@ -58,7 +54,6 @@ dataManager.addDataManagerListener(this); dataSelected(dataManager.getSelectedData()); - } public AlgorithmAction(String label, ServiceReference ref, BundleContext bContext, CIShellContext ciContext) { @@ -76,34 +71,22 @@ dataManager.addDataManagerListener(this); dataSelected(dataManager.getSelectedData()); } - + public void run() { - //hmm... should probably change this.. maybe use the scheduler... - new Thread("Menu Item Runner") { - public void run() { - runTask(); - }}.start(); - } - - public void runTask() { try { - //save the current data - Data[] data = this.data; - Converter[][] converters = this.converters; - - SchedulerService scheduler = (SchedulerService) - bContext.getService(bContext.getServiceReference( - SchedulerService.class.getName())); - - printAlgorithmInformation(); + printAlgorithmInformation(ref, ciContext); - scheduler.schedule(new AlgorithmWrapper(ref, ciContext, bContext, originalData, data, converters, ca), ref); + Algorithm algorithm = new AlgorithmWrapper(ref, bContext, ciContext, originalData, data, converters); + SchedulerService scheduler = (SchedulerService) getService(SchedulerService.class); + + scheduler.schedule(algorithm, ref); } catch (Throwable e) { + //Just in case an uncaught exception occurs. Eclipse will swallow errors thrown here... e.printStackTrace(); } } - private void printAlgorithmInformation() { + private void printAlgorithmInformation(ServiceReference ref, CIShellContext ciContext) { //adjust to log the whole acknowledgement in one block LogService logger = (LogService) ciContext.getService(LogService.class.getName()); StringBuffer acknowledgement = new StringBuffer(); @@ -185,9 +168,8 @@ } else { originalData = null; } - - setEnabled(data != null); //&& isValid()); + setEnabled(data != null); } private boolean isAssignableFrom(String type, Data datum) { @@ -213,6 +195,15 @@ public void dataLabelChanged(Data data, String label) {} public void dataRemoved(Data data) {} + private Object getService(Class clas) { + ServiceReference ref = bContext.getServiceReference(clas.getName()); + if (ref != null) { + return bContext.getService(ref); + } + + return null; + } + public ServiceReference getServiceReference(){ return ref; } Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-04-02 19:37:27 UTC (rev 772) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-04-03 16:04:19 UTC (rev 773) @@ -25,6 +25,7 @@ import org.cishell.app.service.datamanager.DataManagerService; import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.AlgorithmProperty; import org.cishell.framework.algorithm.DataValidator; @@ -37,6 +38,7 @@ import org.cishell.reference.gui.menumanager.Activator; import org.cishell.reference.gui.menumanager.menu.metatypewrapper.ParamMetaTypeProvider; import org.cishell.reference.service.metatype.BasicMetaTypeProvider; +import org.cishell.service.conversion.ConversionException; import org.cishell.service.conversion.Converter; import org.cishell.service.guibuilder.GUIBuilderService; import org.osgi.framework.BundleContext; @@ -50,224 +52,221 @@ import org.osgi.service.metatype.MetaTypeService; import org.osgi.service.metatype.ObjectClassDefinition; + public class AlgorithmWrapper implements Algorithm, AlgorithmProperty, ProgressTrackable { - protected ServiceReference algFactoryRef; - protected BundleContext bContext; - protected CIShellContext ciContext; - protected Data[] originalData; - protected Data[] convertableData; - protected Converter[][] converters; - protected ProgressMonitor progressMonitor; + protected ServiceReference ref; + protected BundleContext bContext; + protected CIShellContext ciContext; + protected Data[] originalData; + protected Data[] data; + protected Converter[][] converters; + protected ProgressMonitor progressMonitor; + protected Algorithm algorithm; + + public AlgorithmWrapper(ServiceReference ref, BundleContext bContext, + CIShellContext ciContext, Data[] originalData, Data[] data, + Converter[][] converters) { + this.ref = ref; + this.bContext = bContext; + this.ciContext = ciContext; + this.originalData = originalData; + this.data = data; + this.converters = converters; + this.progressMonitor = null; + } - protected ConfigurationAdmin ca; - protected GUIBuilderService builder; - protected DataManagerService dataManager; + /** + * @see org.cishell.framework.algorithm.Algorithm#execute() + */ + public Data[] execute() { + AlgorithmFactory factory = (AlgorithmFactory) bContext.getService(ref); + String pid = (String)ref.getProperty(Constants.SERVICE_PID); + + // convert input data to the correct format + boolean conversionSuccessful = tryConvertingDataToRequiredFormat(data, converters); + if (!conversionSuccessful) return null; + boolean inputIsValid = testDataValidityIfPossible(factory, data); + if (!inputIsValid) return null; + + // create algorithm parameters + String metatype_pid = getMetaTypeID(ref); + + MetaTypeProvider provider = getPossiblyMutatedMetaTypeProvider(metatype_pid, pid, factory); + Dictionary parameters = getUserEnteredParameters(metatype_pid, provider); + + // check to see if the user cancelled the operation + if(parameters == null) return null; + + printParameters(metatype_pid, provider, parameters); + + // create the algorithm + algorithm = factory.createAlgorithm(data, parameters, ciContext); + trackAlgorithmIfPossible(algorithm); + + // execute the algorithm + Data[] outData = tryExecutingAlgorithm(algorithm); + if (outData == null) return null; + + // process and return the algorithm's output + doParentage(outData); + outData = removeNullData(outData); + addDataToDataManager(outData); - // ConfigurationAdmin may be null - public AlgorithmWrapper(ServiceReference ref, CIShellContext ciContext, BundleContext bContext, - Data[] originalData, Data[] data, Converter[][] converters, ConfigurationAdmin ca) { - this.algFactoryRef = ref; - this.bContext = bContext; - this.ciContext = ciContext; - this.originalData = originalData; - this.convertableData = data; - this.converters = converters; + return outData; + } + + protected Data[] removeNullData(Data[] outData) { + if (outData != null) { + List goodData = new ArrayList(); + for (int i=0; i < outData.length; i++) { + if (outData[i] != null) { + goodData.add(outData[i]); + } + } + + outData = (Data[]) goodData.toArray(new Data[0]); + } + + return outData; + } + + protected void addDataToDataManager(Data[] outData) { + if (outData != null) { + DataManagerService dataManager = (DataManagerService) + bContext.getService(bContext.getServiceReference( + DataManagerService.class.getName())); + + if (outData.length != 0) { + dataManager.setSelectedData(outData); + } + } + } + + protected Data[] tryExecutingAlgorithm(Algorithm algorithm) { + Data[] outData = null; + try { + outData = algorithm.execute(); + } catch (AlgorithmExecutionException e) { + log(LogService.LOG_ERROR, + "The Algorithm: \""+ref.getProperty(AlgorithmProperty.LABEL)+ + "\" had an error while executing: "+e.getMessage()); + } catch (RuntimeException e) { + GUIBuilderService builder = (GUIBuilderService) + ciContext.getService(GUIBuilderService.class.getName()); + + builder.showError("Error!", "An unexpected exception occurred while " + +"executing \""+ref.getProperty(AlgorithmProperty.LABEL)+".\"", e); + } + + return outData; + } + + protected boolean tryConvertingDataToRequiredFormat(Data[] data, Converter[][] converters) { + for (int i=0; i < data.length; i++) { + if (converters[i] != null) { + try { + data[i] = converters[i][0].convert(data[i]); + } catch (ConversionException e) { + log(LogService.LOG_ERROR,"The conversion of data to give" + + " the algorithm failed for this reason: "+e.getMessage(), e); + return false; + } - this.ca = ca; - this.progressMonitor = null; - this.builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); - this.dataManager = (DataManagerService) bContext.getService(bContext - .getServiceReference(DataManagerService.class.getName())); - } + if (data[i] == null && i < (data.length - 1)) { + log(LogService.LOG_ERROR, "The converter: " + + converters[i].getClass().getName() + + " returned a null result where data was expected when" + + " converting the data to give the algorithm."); + return false; + } + converters[i] = null; + } + } + + return true; + } + + protected boolean testDataValidityIfPossible(AlgorithmFactory factory, Data[] data) { + if (factory instanceof DataValidator) { + String validation = ((DataValidator) factory).validate(data); + + if (validation != null && validation.length() > 0) { + String label = (String) ref.getProperty(LABEL); + if (label == null) { + label = "Algorithm"; + } + + log(LogService.LOG_ERROR,"INVALID DATA: The data given to \""+label+"\" is incompatible for this reason: "+validation); + return false; + } + } + + return true; + } + + protected String getMetaTypeID(ServiceReference ref) { + String pid = (String)ref.getProperty(Constants.SERVICE_PID); + String metatype_pid = (String) ref.getProperty(PARAMETERS_PID); + + if (metatype_pid == null) { + metatype_pid = pid; + } + + return metatype_pid; + } + + protected MetaTypeProvider getPossiblyMutatedMetaTypeProvider(String metatype_pid, String pid, AlgorithmFactory factory) { + MetaTypeProvider provider = null; + + MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); + if (metaTypeService != null) { + provider = metaTypeService.getMetaTypeInformation(ref.getBundle()); + } - /** - * @see org.cishell.framework.algorithm.Algorithm#execute() - */ - public Data[] execute() { - try { - // prepare to run the algorithm - Data[] data = convertDataToRequiredFormat(this.convertableData, this.converters); - AlgorithmFactory algFactory = (AlgorithmFactory) bContext.getService(algFactoryRef); - boolean inputIsValid = testDataValidityIfPossible(algFactory, data); - if (!inputIsValid) return null; - - // create algorithm parameters - - MetaTypeProvider parameterSetupInfo = obtainParameterSetupInfo(algFactory, data); - Dictionary parameters = createParameters(parameterSetupInfo); - printParameters(parameters, parameterSetupInfo); - - // create the algorithm - - Algorithm algorithm = algFactory.createAlgorithm(data, parameters, ciContext); - trackAlgorithmProgressIfPossible(algorithm); - - // execute the algorithm - - Data[] rawOutData = algorithm.execute(); - - // return the algorithm's output - - Data[] processedOutData = processOutData(rawOutData); - return processedOutData; - - } catch (Throwable e) { - // show any errors to the user - - showGenericExecutionError(e); - return new Data[0]; - } - } - - // should return null if algorithm is not progress trackable - public ProgressMonitor getProgressMonitor() { - return progressMonitor; - } - - public void setProgressMonitor(ProgressMonitor monitor) { - progressMonitor = monitor; - } - - protected Data[] convertDataToRequiredFormat(Data[] data, Converter[][] converters) throws Exception { - // convert data into the in_data format of the algorithm we are trying to run - for (int i = 0; i < data.length; i++) { - if (converters[i] != null) { - // WARNING: arbitrarily chooses first converter out of a list of possible converters - data[i] = converters[i][0].convert(data[i]); - if (data[i] == null && i < (data.length - 1)) { - Exception e = new Exception("The converter " + converters[i].getClass().getName() - + " returned a null result where data was expected."); - throw e; - } - converters[i] = null; - } - } - - return data; - } - - protected boolean testDataValidityIfPossible(AlgorithmFactory algFactory, Data[] dataInQuestion) { - if (algFactory instanceof DataValidator) { - String validation = ((DataValidator) algFactory).validate(dataInQuestion); - - if (validation != null && validation.length() > 0) { - String label = (String) algFactoryRef.getProperty(LABEL); - if (label == null) { - label = "Algorithm"; - } - - builder.showError("Invalid Data", "The data given to \"" + label + "\" is incompatible for this reason: " - + validation, (String) null); - return false; - } - return true; - } else { - //counts as valid if there is no validator available. - return true; - } - } - - protected MetaTypeProvider obtainParameterSetupInfo(AlgorithmFactory algFactory, Data[] data) { - - MetaTypeProvider provider = null; - - // first, get the standard parameter setup info for the algorithm factory. - - MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); - if (metaTypeService != null) { - provider = metaTypeService.getMetaTypeInformation(algFactoryRef.getBundle()); - } - - // if the algorithm factory wants to mutate the parameter setup info, allow it to. - if (algFactory instanceof ParameterMutator && provider != null) { - String parameterPID = determineParameterPID(algFactoryRef, provider); - try { - ObjectClassDefinition ocd = provider.getObjectClassDefinition(parameterPID, null); - - ocd = ((ParameterMutator) algFactory).mutateParameters(data, ocd); - - if (ocd != null) { - provider = new BasicMetaTypeProvider(ocd); - } - } catch (IllegalArgumentException e) { - LogService logger = getLogService(); - logger.log(LogService.LOG_DEBUG, algFactoryRef.getProperty(Constants.SERVICE_PID) - + " has an invalid metatype parameter id: " + parameterPID); - } - } - - // wrap the parameter setup info so that default parameter values - // specified in the user preference service are filled in. - - if (provider != null) { - provider = wrapProvider(this.algFactoryRef, provider); - } - - return provider; - } - - protected Dictionary createParameters(MetaTypeProvider parameterSetupInfo) { - // ask the user to specify the values for algorithm's parameters - String parameterPID = determineParameterPID(algFactoryRef, parameterSetupInfo); - Dictionary parameters = new Hashtable(); - if (parameterSetupInfo != null) { - parameters = builder.createGUIandWait(parameterPID, parameterSetupInfo); - } - return parameters; - } - - protected void printParameters(Dictionary parameters, MetaTypeProvider parameterSetupInfo) { - LogService logger = getLogService(); - Map idToLabelMap = createIdToLabelMap(parameterSetupInfo); - - if (logger != null) { - if (parameters.isEmpty()) { - // adjust to log all input parameters in one block - StringBuffer inputParams = new StringBuffer("\n" + "Input Parameters:"); - - for (Enumeration e = parameters.keys(); e.hasMoreElements();) { - String key = (String) e.nextElement(); - Object value = parameters.get(key); - - key = (String) idToLabelMap.get(key); - inputParams.append("\n" + key + ": " + value); - - } - logger.log(LogService.LOG_INFO, inputParams.toString()); - } - } - } - - protected void trackAlgorithmProgressIfPossible(Algorithm algorithm) { - if (algorithm instanceof ProgressTrackable) { - ((ProgressTrackable) algorithm).setProgressMonitor(progressMonitor); - } - } - - protected Data[] processOutData(Data[] rawOutData) { - if (rawOutData != null) { - doParentage(rawOutData); - List goodData = new ArrayList(); - for (int i = 0; i < rawOutData.length; i++) { - if (rawOutData[i] != null) { - goodData.add(rawOutData[i]); - } - } - - Data[] processedOutData = (Data[]) goodData.toArray(new Data[goodData.size()]); - if (rawOutData.length != 0) { - dataManager.setSelectedData(rawOutData); - } - - return processedOutData; - } else { - return null; - } - } - + if (factory instanceof ParameterMutator && provider != null) { + try { + ObjectClassDefinition ocd = provider.getObjectClassDefinition(metatype_pid, null); + + ocd = ((ParameterMutator) factory).mutateParameters(data, ocd); + + if (ocd != null) { + provider = new BasicMetaTypeProvider(ocd); + } + } catch (IllegalArgumentException e) { + log(LogService.LOG_DEBUG, pid+" has an invalid metatype id: "+metatype_pid); + } + } + + if (provider != null) { + provider = wrapProvider(ref, provider); + } + + return provider; + } + + protected void trackAlgorithmIfPossible(Algorithm algorithm) { + if (progressMonitor != null && algorithm instanceof ProgressTrackable) { + ((ProgressTrackable)algorithm).setProgressMonitor(progressMonitor); + } + } + + protected Dictionary getUserEnteredParameters(String metatype_pid, MetaTypeProvider provider) { + Dictionary parameters = new Hashtable(); + if (provider != null) { + GUIBuilderService builder = (GUIBuilderService) + ciContext.getService(GUIBuilderService.class.getName()); + + parameters = builder.createGUIandWait(metatype_pid, provider); + } + + return parameters; + } + // wrap the provider to provide special functionality, such as overriding default values of attributes through // preferences. protected MetaTypeProvider wrapProvider(ServiceReference algRef, MetaTypeProvider unwrappedProvider) { + ConfigurationAdmin ca = getConfigurationAdmin(); + if (ca != null && hasParamDefaultPreferences(algRef)) { String standardServicePID = (String) algRef.getProperty(Constants.SERVICE_PID); String paramOverrideConfPID = standardServicePID + UserPrefsProperty.PARAM_PREFS_CONF_SUFFIX; @@ -285,107 +284,156 @@ return unwrappedProvider; } - - protected String determineParameterPID(ServiceReference ref, MetaTypeProvider provider) { - String overridePID = (String) ref.getProperty(AlgorithmProperty.PARAMETERS_PID); - if (overridePID != null) { - return overridePID; - } else { - return (String) ref.getProperty(Constants.SERVICE_PID); + + protected boolean hasParamDefaultPreferences(ServiceReference algRef) { + String prefsToPublish = (String) algRef.getProperty(UserPrefsProperty.PREFS_PUBLISHED_KEY); + if (prefsToPublish == null) { + return true; } - } - protected Map createIdToLabelMap(MetaTypeProvider parameterSetupInfo) { - Map idToLabelMap = new HashMap(); - if (parameterSetupInfo != null) { - ObjectClassDefinition ocd = null; - try { - String parameterPID = determineParameterPID(algFactoryRef, parameterSetupInfo); - ocd = parameterSetupInfo.getObjectClassDefinition(parameterPID, null); - - if (ocd != null) { - AttributeDefinition[] attr = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); - - for (int i = 0; i < attr.length; i++) { - String id = attr[i].getID(); - String label = attr[i].getName(); - - idToLabelMap.put(id, label); - } - } - } catch (IllegalArgumentException e) { - } - } - - return idToLabelMap; + return prefsToPublish.contains(UserPrefsProperty.PUBLISH_PARAM_DEFAULT_PREFS_VALUE); } + + protected void log(int logLevel, String message) { + LogService log = (LogService) ciContext.getService(LogService.class.getName()); + if (log != null) { + log.log(logLevel, message); + } else { + System.out.println(message); + } + } - // only does anything if parentage=default so far... - protected void doParentage(Data[] outData) { - // make sure the parent set is the original Data and not the - // converted data... - if (outData != null && convertableData != null && originalData != null - && originalData.length == convertableData.length) { - for (int i = 0; i < outData.length; i++) { - if (outData[i] != null) { - Object parent = outData[i].getMetadata().get(DataProperty.PARENT); - - if (parent != null) { - for (int j = 0; j < convertableData.length; i++) { - if (parent == convertableData[j]) { - outData[i].getMetadata().put(DataProperty.PARENT, originalData[j]); - break; - } - } - } - } - } - } - - // check and act on parentage settings - String parentage = (String) algFactoryRef.getProperty("parentage"); - if (parentage != null) { - parentage = parentage.trim(); - if (parentage.equalsIgnoreCase("default")) { - if (originalData != null && originalData.length > 0 && originalData[0] != null) { - - for (int i = 0; i < outData.length; i++) { - // if they don't have a parent set already then we set one - if (outData[i] != null && outData[i].getMetadata().get(DataProperty.PARENT) == null) { - outData[i].getMetadata().put(DataProperty.PARENT, originalData[0]); - } - } - } - } - } - } - - protected LogService getLogService() { + protected void log(int logLevel, String message, Throwable exception) { + LogService log = (LogService) ciContext.getService(LogService.class.getName()); + if (log != null) { + log.log(logLevel, message, exception); + } else { + System.out.println(message); + exception.printStackTrace(); + } + } + + protected void printParameters(String metatype_pid, MetaTypeProvider provider, Dictionary parameters) { + LogService logger = getLogService(); + Map idToLabelMap = setupIdToLabelMap(metatype_pid, provider); + + if (logger != null && !parameters.isEmpty()) { + //adjust to log all input parameters in one block + StringBuffer inputParams = new StringBuffer("\n"+"Input Parameters:"); + + for (Enumeration e = parameters.keys(); e + .hasMoreElements();) { + String key = (String) e.nextElement(); + Object value = parameters.get(key); + + key = (String) idToLabelMap.get(key); + inputParams.append("\n"+key+": "+value); + + } + logger.log(LogService.LOG_INFO, inputParams.toString()); + } + } + + protected Map setupIdToLabelMap(String metatype_pid, MetaTypeProvider provider) { + Map idToLabelMap = new HashMap(); + if (provider != null) { + ObjectClassDefinition ocd = null; + try { + ocd = provider.getObjectClassDefinition(metatype_pid, null); + + if (ocd != null) { + AttributeDefinition[] attr = + ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); + + for (int i=0; i < attr.length; i++) { + String id = attr[i].getID(); + String label = attr[i].getName(); + + idToLabelMap.put(id, label); + } + } + } catch (IllegalArgumentException e) {} + } + + return idToLabelMap; + } + + //only does anything if parentage=default so far... + protected void doParentage(Data[] outData) { + //make sure the parent set is the original Data and not the + //converted data... + if (outData != null && data != null && originalData != null + && originalData.length == data.length) { + for (int i=0; i < outData.length; i++) { + if (outData[i] != null) { + Object parent = outData[i].getMetadata().get(DataProperty.PARENT); + + if (parent != null) { + for (int j=0; j < data.length; i++) { + if (parent == data[j]) { + outData[i].getMetadata().put(DataProperty.PARENT, + originalData[j]); + break; + } + } + } + } + } + } + + //check and act on parentage settings + String parentage = (String)ref.getProperty("parentage"); + if (parentage != null) { + parentage = parentage.trim(); + if (parentage.equalsIgnoreCase("default")) { + if (originalData != null && originalData.length > 0 && originalData[0] != null) { + + for (int i=0; i < outData.length; i++) { + //if they don't have a parent set already then we set one + if (outData[i] != null && + outData[i].getMetadata().get(DataProperty.PARENT) == null) { + outData[i].getMetadata().put(DataProperty.PARENT, originalData[0]); + } + } + } + } + } + } + + private LogService getLogService() { ServiceReference serviceReference = bContext.getServiceReference(DataManagerService.class.getName()); LogService log = null; - + if (serviceReference != null) { - log = (LogService) bContext.getService(bContext.getServiceReference(LogService.class.getName())); + log = (LogService) bContext.getService( + bContext.getServiceReference(LogService.class.getName())); } - + return log; } - - protected boolean hasParamDefaultPreferences(ServiceReference algRef) { - String prefsToPublish = (String) algRef.getProperty(UserPrefsProperty.PREFS_PUBLISHED_KEY); - if (prefsToPublish == null) { - return true; + + private ConfigurationAdmin getConfigurationAdmin() { + ServiceReference serviceReference = bContext.getServiceReference(ConfigurationAdmin.class.getName()); + ConfigurationAdmin ca = null; + + if (serviceReference != null) { + ca = (ConfigurationAdmin) bContext.getService( + bContext.getServiceReference(ConfigurationAdmin.class.getName())); } + + return ca; + } - if (prefsToPublish.contains(UserPrefsProperty.PUBLISH_PARAM_DEFAULT_PREFS_VALUE)) { - return true; - } else { - return false; + public ProgressMonitor getProgressMonitor() { + if (algorithm instanceof ProgressTrackable) { + return progressMonitor; } + else { + return null; + } } - protected void showGenericExecutionError(Throwable e) { - builder.showError("Error!", "The Algorithm: \"" + algFactoryRef.getProperty(AlgorithmProperty.LABEL) - + "\" had an error while executing.", e); + public void setProgressMonitor(ProgressMonitor monitor) { + progressMonitor = monitor; } } 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-04-02 19:37:27 UTC (rev 772) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2008-04-03 16:04:19 UTC (rev 773) @@ -42,7 +42,6 @@ import org.osgi.framework.ServiceEvent; import org.osgi.framework.ServiceListener; import org.osgi.framework.ServiceReference; -import org.osgi.service.cm.ConfigurationAdmin; import org.osgi.service.log.LogService; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -62,7 +61,6 @@ private ContextListener listener; private IWorkbenchWindow window; - private ConfigurationAdmin ca; /* * This map holds a pid as a key and the corresponding * ServiceReference as a value. @@ -116,24 +114,8 @@ } catch (InvalidSyntaxException e) { getLog().log(LogService.LOG_DEBUG, "Invalid Syntax", e); } - - attemptToObtainConfigurationAdmin(bContext); } - - private void attemptToObtainConfigurationAdmin(BundleContext bContext) { - if (ca == null) { - try { - ServiceReference caRef = bContext.getServiceReference(ConfigurationAdmin.class.getName()); - if (caRef != null) { - ConfigurationAdmin ca = (ConfigurationAdmin) bContext.getService(caRef); - this.ca = ca; //may or may not be null, but if it is null, its the same as if we never tried to set it (that is to say, ok) - } - } catch (NoClassDefFoundError e) { - //do nothing - } - } - } - + /* * This method scans all service bundles. If a bundle specifies * menu_path, get service.pid of this bundle (key), let the service @@ -278,8 +260,7 @@ ServiceReference ref = (ServiceReference) pidToServiceReferenceMapCopy. get(pid.toLowerCase().trim()); pidToServiceReferenceMap.remove(pid.toLowerCase().trim()); - attemptToObtainConfigurationAdmin(bContext); - AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext, ca); + AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext); action.setId(getItemID(ref)); action.setText(menuName); parentMenuBar.add(action); @@ -365,8 +346,7 @@ String[] items = (path == null) ? null : path.split("/"); IMenuManager menu = null; if (items != null && items.length > 1) { - attemptToObtainConfigurationAdmin(bContext); - AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext, ca); + AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext); action.setId(getItemID(ref)); IMenuManager targetMenu = menuBar; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2008-05-09 13:51:05
|
Revision: 777 http://cishell.svn.sourceforge.net/cishell/?rev=777&view=rev Author: mwlinnem Date: 2008-05-09 06:50:16 -0700 (Fri, 09 May 2008) Log Message: ----------- Added additional error handling. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamAD.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-05-08 17:51:48 UTC (rev 776) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-05-09 13:50:16 UTC (rev 777) @@ -100,7 +100,8 @@ printParameters(metatype_pid, provider, parameters); // create the algorithm - algorithm = factory.createAlgorithm(data, parameters, ciContext); + algorithm = createAlgorithm(factory, data, parameters, ciContext); + if (algorithm == null) return null; trackAlgorithmIfPossible(algorithm); // execute the algorithm @@ -115,6 +116,20 @@ return outData; } + protected Algorithm createAlgorithm(AlgorithmFactory factory, Data[] data, Dictionary parameters, CIShellContext ciContext) { + try { + return factory.createAlgorithm(data, parameters, ciContext); + } catch (Exception e) { + String errorMessage = "Unexpected error occurred while creating algorithm " + + " \""+ref.getProperty(AlgorithmProperty.LABEL)+".\""; + GUIBuilderService builder = (GUIBuilderService) + ciContext.getService(GUIBuilderService.class.getName()); + builder.showError("Error!", errorMessage, e); + log(LogService.LOG_ERROR, errorMessage, e); + return null; + } + } + protected Data[] removeNullData(Data[] outData) { if (outData != null) { List goodData = new ArrayList(); @@ -217,7 +232,6 @@ protected MetaTypeProvider getPossiblyMutatedMetaTypeProvider(String metatype_pid, String pid, AlgorithmFactory factory) { MetaTypeProvider provider = null; - MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); if (metaTypeService != null) { provider = metaTypeService.getMetaTypeInformation(ref.getBundle()); @@ -226,14 +240,20 @@ if (factory instanceof ParameterMutator && provider != null) { try { ObjectClassDefinition ocd = provider.getObjectClassDefinition(metatype_pid, null); - + if (ocd == null) logNullOCDWarning(pid, metatype_pid); ocd = ((ParameterMutator) factory).mutateParameters(data, ocd); - if (ocd != null) { provider = new BasicMetaTypeProvider(ocd); } } catch (IllegalArgumentException e) { log(LogService.LOG_DEBUG, pid+" has an invalid metatype id: "+metatype_pid); + } catch (Exception e) { + GUIBuilderService builder = (GUIBuilderService) + ciContext.getService(GUIBuilderService.class.getName()); + String errorMessage = "An error occurred while preparing to run the algorithm " + +ref.getProperty(AlgorithmProperty.LABEL)+".\""; + builder.showError("Error!", errorMessage, e); + log(LogService.LOG_ERROR, errorMessage, e); } } @@ -423,6 +443,11 @@ return ca; } + + private void logNullOCDWarning(String pid, String metatype_pid) { + this.log(LogService.LOG_WARNING, + "Warning: could not get object class definition '" + metatype_pid + "' from the algorithm '" + pid + "'"); + } public ProgressMonitor getProgressMonitor() { if (algorithm instanceof ProgressTrackable) { Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamAD.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamAD.java 2008-05-08 17:51:48 UTC (rev 776) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/metatypewrapper/ParamAD.java 2008-05-09 13:50:16 UTC (rev 777) @@ -61,6 +61,7 @@ private String[] replaceSpecialValues(String[] overrideValues) { try { String[] defaultValues = realAD.getDefaultValue(); + if (defaultValues == null) return new String[0]; String[] replacedValues = new String[defaultValues.length]; for (int i = 0; i < defaultValues.length; i++) { if (defaultValues[i] != null && defaultValues[i].contains(":") && overrideValues[i] != null && overrideValues[i].equals("")) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |