From: <mwl...@us...> - 2008-03-28 20:30:26
|
Revision: 741 http://cishell.svn.sourceforge.net/cishell/?rev=741&view=rev Author: mwlinnem Date: 2008-03-28 13:30:10 -0700 (Fri, 28 Mar 2008) Log Message: ----------- Result of merge between CIShell 1.0 updated org.cishell.framework and the preference changes. Modified Paths: -------------- branches/user_prefs/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java Modified: branches/user_prefs/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF =================================================================== --- branches/user_prefs/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2008-03-28 16:51:07 UTC (rev 740) +++ branches/user_prefs/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2008-03-28 20:30:10 UTC (rev 741) @@ -2,21 +2,21 @@ Bundle-ManifestVersion: 2 Bundle-Name: Menu Manager Plug-in Bundle-SymbolicName: org.cishell.reference.gui.menumanager;singleton:=true -Bundle-Version: 0.6.0 +Bundle-Version: 1.0.0 Bundle-Activator: org.cishell.reference.gui.menumanager.Activator -Bundle-Localization: plugin Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime Eclipse-LazyStart: true -Import-Package: org.cishell.app.service.datamanager, - org.cishell.app.service.scheduler, - org.cishell.framework, - org.cishell.framework.algorithm, - org.cishell.framework.data, - org.cishell.framework.preference, +Import-Package: org.cishell.app.service.datamanager;version="1.0.0", + org.cishell.app.service.scheduler;version="1.0.0", + org.cishell.framework;version="1.0.0", + org.cishell.framework.algorithm;version="1.0.0", + org.cishell.framework.data;version="1.0.0", + org.cishell.framework.userprefs;version="1.0.0", org.cishell.reference.gui.workspace, - org.cishell.service.conversion, - org.cishell.service.guibuilder, + org.cishell.reference.service.metatype, + org.cishell.service.conversion;version="1.0.0", + org.cishell.service.guibuilder;version="1.0.0", org.osgi.service.cm;version="1.2.0", org.osgi.service.log;version="1.3.0", - org.osgi.service.metatype;version="1.1.0" + org.osgi.service.metatype;version="1.1.0", Modified: branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java 2008-03-28 16:51:07 UTC (rev 740) +++ branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java 2008-03-28 20:30:10 UTC (rev 741) @@ -12,6 +12,7 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; /** * The activator class controls the plug-in life cycle @@ -24,7 +25,7 @@ // The shared instance private static Activator plugin; - private static final int DELAY_TIME = 500; + private static BundleContext context; MenuAdapter menuAdapter; @@ -41,14 +42,16 @@ public void start(BundleContext context) throws Exception { super.start(context); + Activator.context = context; + while (getWorkbench() == null) { - Thread.sleep(DELAY_TIME); + Thread.sleep(500); } IWorkbenchWindow[] windows = getWorkbench().getWorkbenchWindows(); while (windows.length == 0) { - Thread.sleep(DELAY_TIME); + Thread.sleep(500); windows = getWorkbench().getWorkbenchWindows(); } @@ -79,6 +82,16 @@ super.stop(context); } + + public static Object getService(String service_pid) { + ServiceReference ref = context.getServiceReference(service_pid); + + if (ref != null) { + return context.getService(ref); + } else { + return null; + } + } /** * Returns the shared instance Modified: branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2008-03-28 16:51:07 UTC (rev 740) +++ branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2008-03-28 20:30:10 UTC (rev 741) @@ -77,8 +77,6 @@ dataSelected(dataManager.getSelectedData()); } - - public void run() { //hmm... should probably change this.. maybe use the scheduler... new Thread("Menu Item Runner") { @@ -97,13 +95,9 @@ bContext.getService(bContext.getServiceReference( SchedulerService.class.getName())); - printAlgorithmInformation(); - - - - - scheduler.schedule(new AlgorithmWrapper(ref, bContext, ciContext, originalData, data, converters, ca), ref); + + scheduler.schedule(new AlgorithmWrapper(ref, ciContext, bContext, originalData, data, converters, ca), ref); } catch (Throwable e) { e.printStackTrace(); } @@ -113,33 +107,31 @@ //adjust to log the whole acknowledgement in one block LogService logger = (LogService) ciContext.getService(LogService.class.getName()); StringBuffer acknowledgement = new StringBuffer(); - String label = (String)ref.getProperty("label"); + 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"); + String implementers = (String)ref.getProperty(IMPLEMENTERS); if (implementers != null) acknowledgement.append("Implementer(s): "+implementers+"\n"); - String integrators = (String)ref.getProperty("integrators"); + String integrators = (String)ref.getProperty(INTEGRATORS); if (integrators != null) acknowledgement.append("Integrator(s): "+integrators+"\n"); - String reference = (String)ref.getProperty("reference"); - String reference_url = (String)ref.getProperty("reference_url"); + String reference = (String)ref.getProperty(REFERENCE); + String reference_url = (String)ref.getProperty(REFERENCE_URL); if (reference != null && reference_url != null ) acknowledgement.append("Reference: "+reference+ " ("+reference_url+")\n"); else if (reference != null && reference_url == null ) acknowledgement.append("Reference: "+reference+"\n"); - String docu = (String)ref.getProperty("docu"); + String docu = (String)ref.getProperty(DOCUMENTATION_URL); if (docu != null) - acknowledgement.append("Docu: "+docu+"\n"); + 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) { @@ -198,34 +190,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; @@ -252,6 +216,4 @@ public ServiceReference getServiceReference(){ return ref; } - - } \ No newline at end of file Modified: branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-03-28 16:51:07 UTC (rev 740) +++ branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-03-28 20:30:10 UTC (rev 741) @@ -28,12 +28,15 @@ import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.AlgorithmProperty; import org.cishell.framework.algorithm.DataValidator; +import org.cishell.framework.algorithm.ParameterMutator; import org.cishell.framework.algorithm.ProgressMonitor; import org.cishell.framework.algorithm.ProgressTrackable; import org.cishell.framework.data.Data; import org.cishell.framework.data.DataProperty; -import org.cishell.framework.preference.PreferenceProperty; +import org.cishell.framework.userprefs.UserPrefsProperty; +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.Converter; import org.cishell.service.guibuilder.GUIBuilderService; import org.osgi.framework.BundleContext; @@ -44,290 +47,344 @@ import org.osgi.service.log.LogService; import org.osgi.service.metatype.AttributeDefinition; import org.osgi.service.metatype.MetaTypeProvider; +import org.osgi.service.metatype.MetaTypeService; import org.osgi.service.metatype.ObjectClassDefinition; - public class AlgorithmWrapper implements Algorithm, AlgorithmProperty, ProgressTrackable { - protected ServiceReference ref; - protected BundleContext bContext; - protected CIShellContext ciContext; - protected Data[] originalData; - protected Data[] data; - protected Converter[][] converters; - protected Dictionary parameters; - protected Map idToLabelMap; - protected MetaTypeProvider provider; - protected ProgressMonitor progressMonitor; - protected Algorithm algorithm; - - protected ConfigurationAdmin ca; - - //ConfigurationAdmin may be null - public AlgorithmWrapper(ServiceReference ref, BundleContext bContext, - CIShellContext ciContext, Data[] originalData, Data[] data, - Converter[][] converters, ConfigurationAdmin ca) { - this.ref = ref; - this.bContext = bContext; - this.ciContext = ciContext; - this.originalData = originalData; - this.data = data; - this.converters = converters; - - this.ca = ca; + protected ServiceReference algFactoryRef; + protected BundleContext bContext; + protected CIShellContext ciContext; + protected Data[] originalData; + protected Data[] convertableData; + protected Converter[][] converters; + protected ProgressMonitor progressMonitor; - this.idToLabelMap = new HashMap(); - this.progressMonitor = null; - - - } + protected ConfigurationAdmin ca; + protected GUIBuilderService builder; + protected DataManagerService dataManager; - /** - * @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); - return null; - } - } - - this.provider = factory.createParameters(data); - if (this.provider != null) { - this.provider = wrapProvider(this.ref, this.provider); - } - String pid = determineParameterPID(ref, provider); - - this.parameters = new Hashtable(); - if (provider != null) { - this.parameters = builder.createGUIandWait(pid, provider); - } + // 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; - if(this.parameters == null) { - return new Data[0]; - } - - algorithm = factory.createAlgorithm(data, parameters, ciContext); - - printParameters(); - - if (progressMonitor != null && algorithm instanceof ProgressTrackable) { - ((ProgressTrackable)algorithm).setProgressMonitor(progressMonitor); - } - - 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]; - } - } - - //wrap the provider to provide special functionality, such as overriding default values of attributes through preferences. - protected MetaTypeProvider wrapProvider(ServiceReference algRef, MetaTypeProvider unwrappedProvider) { - if (ca != null && hasParamDefaultPreferences(algRef)) { - String standardServicePID = (String) algRef.getProperty(Constants.SERVICE_PID); - String paramOverrideConfPID = standardServicePID + PreferenceProperty.PARAM_PREFS_CONF_SUFFIX; - try { - Configuration defaultParamValueOverrider = ca.getConfiguration(paramOverrideConfPID, null); - Dictionary defaultParamOverriderDict = defaultParamValueOverrider.getProperties(); - MetaTypeProvider wrappedProvider = new ParamMetaTypeProvider(unwrappedProvider, defaultParamOverriderDict); - return wrappedProvider; - } catch (IOException e) { - return unwrappedProvider; - } - } else { - } - - return unwrappedProvider; - } - - protected String determineParameterPID(ServiceReference ref, MetaTypeProvider provider) { - String overridePID = (String) ref.getProperty(AlgorithmProperty.PARAMETER_PID); - if (overridePID != null) { - return overridePID; - } else { - return (String) ref.getProperty(Constants.SERVICE_PID); - } - } - - protected void printParameters() { - LogService logger = getLogService(); - setupIdToLabelMap(); - - if (logger != null) { - if (!this.parameters.isEmpty()) { - //adjust to log all input parameters in one block - StringBuffer inputParams = new StringBuffer("\n"+"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); - inputParams.append("\n"+key+": "+value); - - } - logger.log(LogService.LOG_INFO, inputParams.toString()); - } - } - } - - 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 - //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())); + this.ca = ca; + this.progressMonitor = null; + this.builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); + this.dataManager = (DataManagerService) bContext.getService(bContext + .getServiceReference(DataManagerService.class.getName())); + } + + /** + * @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]; } - - return log; } + // 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[] providedData, Converter[][] converters) throws Exception { + // convert data into the in_data format of the algorithm we are trying to run + Data[] readyData = new Data[providedData.length]; + + for (int i = 0; i < providedData.length; i++) { + if (converters[i] != null) { + // WARNING: arbitrarily chooses first converter out of a list of possible converters + readyData[i] = converters[i][0].convert(providedData[i]); + + if (readyData[i] == null && i < (readyData.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 readyData; + } + + protected boolean testDataValidityIfPossible(AlgorithmFactory algFactory, Data[] dataInQuestion) { + 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; + } + + 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) { - return progressMonitor; + ((ProgressTrackable) algorithm).setProgressMonitor(progressMonitor); } - else { + } + + 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; } } - public void setProgressMonitor(ProgressMonitor monitor) { - progressMonitor = monitor; + // wrap the provider to provide special functionality, such as overriding default values of attributes through + // preferences. + protected MetaTypeProvider wrapProvider(ServiceReference algRef, MetaTypeProvider unwrappedProvider) { + if (ca != null && hasParamDefaultPreferences(algRef)) { + String standardServicePID = (String) algRef.getProperty(Constants.SERVICE_PID); + String paramOverrideConfPID = standardServicePID + UserPrefsProperty.PARAM_PREFS_CONF_SUFFIX; + try { + Configuration defaultParamValueOverrider = ca.getConfiguration(paramOverrideConfPID, null); + Dictionary defaultParamOverriderDict = defaultParamValueOverrider.getProperties(); + MetaTypeProvider wrappedProvider = new ParamMetaTypeProvider(unwrappedProvider, + defaultParamOverriderDict); + return wrappedProvider; + } catch (IOException e) { + return unwrappedProvider; + } + } else { + } + + return unwrappedProvider; } - - private boolean hasParamDefaultPreferences(ServiceReference algRef) { - String prefsToPublish = (String) algRef.getProperty(PreferenceProperty.PREFS_PUBLISHED_KEY); + + 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 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; + } + + // 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() { + ServiceReference serviceReference = bContext.getServiceReference(DataManagerService.class.getName()); + LogService log = null; + + if (serviceReference != null) { + 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; } - - if (prefsToPublish.contains(PreferenceProperty.PUBLISH_PARAM_DEFAULT_PREF_VALUE)) { + + if (prefsToPublish.contains(UserPrefsProperty.PUBLISH_PARAM_DEFAULT_PREFS_VALUE)) { return true; } else { return false; } } + + protected void showGenericExecutionError(Throwable e) { + builder.showError("Error!", "The Algorithm: \"" + algFactoryRef.getProperty(AlgorithmProperty.LABEL) + + "\" had an error while executing.", e); + } } Modified: branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java =================================================================== --- branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2008-03-28 16:51:07 UTC (rev 740) +++ branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2008-03-28 20:30:10 UTC (rev 741) @@ -13,7 +13,6 @@ * ***************************************************************************/ package org.cishell.reference.gui.menumanager.menu; -//Java import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -53,12 +52,6 @@ import org.xml.sax.SAXException; -/* - * Bonnie's comments: - * weird, why implements AlgorithmProperty? It does not define any abstract interface. - * Micah's comment, several millenia later: - * It's so you can say things like "== LOSSLESS" as oppose to "== AlgorithmProperty.LOSSLESS". - */ public class MenuAdapter implements AlgorithmProperty { private IMenuManager menuBar; private Shell shell; @@ -121,7 +114,7 @@ // initializeMenu(); } catch (InvalidSyntaxException e) { - getLog().log(LogService.LOG_ERROR, "Invalid Syntax", e); + getLog().log(LogService.LOG_DEBUG, "Invalid Syntax", e); } attemptToObtainConfigurationAdmin(bContext); @@ -163,7 +156,6 @@ } } } - } /* * Parse default_menu.xml file. For each menu node, get the value of the attribut "pid" @@ -187,7 +179,6 @@ private void processTopMenu (Element topMenuNode){ MenuManager topMenuBar = null; - /* * The File and Help menus are created in ApplicationActionBarAdvisor.java @@ -237,7 +228,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()); } @@ -276,10 +267,10 @@ 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 - } else{ //check if the pid has registered in pidToServiceReferenceMap @@ -295,7 +286,7 @@ } else{ //otherwise log the error - getLog().log(LogService.LOG_WARNING, + getLog().log(LogService.LOG_DEBUG, "Can not find an algorithm package associated with Menu: " +menuName+" and pid: " +pid+ ". Skip to show it on the menu."); } @@ -386,19 +377,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]; @@ -416,8 +403,8 @@ Display.getDefault().asyncExec(updateAction); } else { -// getLog().log(LogService.LOG_WARNING, -// "Bad menu path for Algorithm: " + ref.getProperty(LABEL)); + getLog().log(LogService.LOG_DEBUG, + "Bad menu path for Algorithm: " + ref.getProperty(LABEL)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |