|
From: <mwl...@us...> - 2008-03-21 15:55:52
|
Revision: 661
http://cishell.svn.sourceforge.net/cishell/?rev=661&view=rev
Author: mwlinnem
Date: 2008-03-21 08:55:02 -0700 (Fri, 21 Mar 2008)
Log Message:
-----------
Branched for user preferences.
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
Added Paths:
-----------
branches/user_prefs/org.cishell.reference.gui.menumanager/
Copied: branches/user_prefs/org.cishell.reference.gui.menumanager (from rev 659, trunk/clients/gui/org.cishell.reference.gui.menumanager)
Modified: branches/user_prefs/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF
===================================================================
--- trunk/clients/gui/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2008-03-14 20:03:15 UTC (rev 659)
+++ branches/user_prefs/org.cishell.reference.gui.menumanager/META-INF/MANIFEST.MF 2008-03-21 15:55:02 UTC (rev 661)
@@ -13,8 +13,10 @@
org.cishell.framework,
org.cishell.framework.algorithm,
org.cishell.framework.data,
+ org.cishell.framework.preference,
org.cishell.reference.gui.workspace,
org.cishell.service.conversion,
org.cishell.service.guibuilder,
+ org.osgi.service.cm;version="1.2.0",
org.osgi.service.log;version="1.3.0",
org.osgi.service.metatype;version="1.1.0"
Modified: branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java
===================================================================
--- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java 2008-03-14 20:03:15 UTC (rev 659)
+++ branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/Activator.java 2008-03-21 15:55:02 UTC (rev 661)
@@ -24,6 +24,8 @@
// The shared instance
private static Activator plugin;
+ private static final int DELAY_TIME = 500;
+
MenuAdapter menuAdapter;
/**
@@ -40,13 +42,13 @@
super.start(context);
while (getWorkbench() == null) {
- Thread.sleep(500);
+ Thread.sleep(DELAY_TIME);
}
IWorkbenchWindow[] windows = getWorkbench().getWorkbenchWindows();
while (windows.length == 0) {
- Thread.sleep(500);
+ Thread.sleep(DELAY_TIME);
windows = getWorkbench().getWorkbenchWindows();
}
Modified: branches/user_prefs/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-14 20:03:15 UTC (rev 659)
+++ branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2008-03-21 15:55:02 UTC (rev 661)
@@ -28,12 +28,8 @@
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;
-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 {
@@ -44,10 +40,14 @@
protected Data[] originalData;
protected Converter[][] converters;
- public AlgorithmAction(ServiceReference ref, BundleContext bContext, CIShellContext ciContext) {
+ protected ConfigurationAdmin ca;
+
+ //ConfigurationAdmin can be null
+ public AlgorithmAction(ServiceReference ref, BundleContext bContext, CIShellContext ciContext, ConfigurationAdmin ca) {
this.ref = ref;
this.ciContext = ciContext;
this.bContext = bContext;
+ this.ca = ca;
setText((String)ref.getProperty(LABEL));
setToolTipText((String)ref.getProperty(AlgorithmProperty.DESCRIPTION));
@@ -101,9 +101,9 @@
printAlgorithmInformation();
+
-
- scheduler.schedule(new AlgorithmWrapper(ref, bContext, ciContext, originalData, data, converters), ref);
+ scheduler.schedule(new AlgorithmWrapper(ref, bContext, ciContext, originalData, data, converters, ca), ref);
} catch (Throwable e) {
e.printStackTrace();
}
Modified: branches/user_prefs/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-14 20:03:15 UTC (rev 659)
+++ branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-03-21 15:55:02 UTC (rev 661)
@@ -13,6 +13,7 @@
* ***************************************************************************/
package org.cishell.reference.gui.menumanager.menu;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Enumeration;
@@ -31,11 +32,15 @@
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.reference.gui.menumanager.menu.metatypewrapper.ParamMetaTypeProvider;
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.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.log.LogService;
import org.osgi.service.metatype.AttributeDefinition;
import org.osgi.service.metatype.MetaTypeProvider;
@@ -55,15 +60,20 @@
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) {
+ 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;
this.idToLabelMap = new HashMap();
this.progressMonitor = null;
@@ -111,19 +121,22 @@
}
this.provider = factory.createParameters(data);
- String pid = (String)ref.getProperty(Constants.SERVICE_PID);
+ 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);
}
-
+
if(this.parameters == null) {
return new Data[0];
}
algorithm = factory.createAlgorithm(data, parameters, ciContext);
-
+
printParameters();
if (progressMonitor != null && algorithm instanceof ProgressTrackable) {
@@ -165,6 +178,34 @@
}
}
+ //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();
@@ -276,4 +317,17 @@
public void setProgressMonitor(ProgressMonitor monitor) {
progressMonitor = monitor;
}
+
+ private boolean hasParamDefaultPreferences(ServiceReference algRef) {
+ String prefsToPublish = (String) algRef.getProperty(PreferenceProperty.PREFS_PUBLISHED_KEY);
+ if (prefsToPublish == null) {
+ return true;
+ }
+
+ if (prefsToPublish.contains(PreferenceProperty.PUBLISH_PARAM_DEFAULT_PREF_VALUE)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
Modified: branches/user_prefs/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-14 20:03:15 UTC (rev 659)
+++ branches/user_prefs/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2008-03-21 15:55:02 UTC (rev 661)
@@ -43,6 +43,7 @@
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;
@@ -55,6 +56,8 @@
/*
* 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;
@@ -65,6 +68,8 @@
private Map itemToParentMap;
private ContextListener listener;
private IWorkbenchWindow window;
+
+ private ConfigurationAdmin ca;
/*
* This map holds a pid as a key and the corresponding
* ServiceReference as a value.
@@ -118,8 +123,24 @@
} catch (InvalidSyntaxException e) {
getLog().log(LogService.LOG_ERROR, "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
@@ -137,7 +158,6 @@
}
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]);
}
@@ -256,7 +276,6 @@
private void processAMenuNode(Element menuNode, MenuManager parentMenuBar ){
String menuName = menuNode.getAttribute(ATTR_NAME);
String pid = menuNode.getAttribute(ATTR_PID);
- //System.out.println(">>>pid="+pid);
if (pid == null || pid.length()==0){
//check if the name is one of the preserved one
//if so add the default action
@@ -268,7 +287,8 @@
ServiceReference ref = (ServiceReference) pidToServiceReferenceMapCopy.
get(pid.toLowerCase().trim());
pidToServiceReferenceMap.remove(pid.toLowerCase().trim());
- AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext);
+ attemptToObtainConfigurationAdmin(bContext);
+ AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext, ca);
action.setId(getItemID(ref));
action.setText(menuName);
parentMenuBar.add(action);
@@ -292,7 +312,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 +357,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:
@@ -356,7 +374,8 @@
String[] items = (path == null) ? null : path.split("/");
IMenuManager menu = null;
if (items != null && items.length > 1) {
- AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext);
+ attemptToObtainConfigurationAdmin(bContext);
+ AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext, ca);
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.
|