Commits

Anonymous committed 8c87daa

Added support for overriding or extending the default palette, via -Dpalette.default and -Dpalette.extend. First we look on filesystem, then in classpath

  • Participants
  • Parent commits 5f84f12

Comments (0)

Files changed (3)

File src/designer/com/opensymphony/workflow/designer/WorkflowDesigner.java

 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.InputStream;
 import java.io.PrintWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Locale;
+import java.util.PropertyResourceBundle;
 import java.util.ResourceBundle;
 import java.util.StringTokenizer;
 import javax.swing.*;
     setJMenuBar(BarFactory.createMenubar(manager, service.getVerb()));
     splash.setProgress(30);
     navigator = new WorkspaceNavigator(this);
-    JScrollPane sp = new JScrollPane(detailPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+    JScrollPane sp = new JScrollPane(detailPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
     detailFramePanel = new FramePanel(ResourceManager.getString("details"), false);
     detailFramePanel.setContent(sp);
 
         System.exit(1);
       }
 
-      InputStream is = WorkflowDesigner.class.getResourceAsStream("/META-INF/palette.xml");
+      String defaultPalette =  System.getProperty("palette.default", "META-INF/palette");
+      
+      PropertyResourceBundle bundle = (PropertyResourceBundle) ResourceBundle.getBundle(defaultPalette, Locale.getDefault(), getClass().getClassLoader());
+      EnhancedResourceBundle erb;
+
+      String extendedPalette = System.getProperty("palette.extend");
+      PropertyResourceBundle extendedBundle = null;
+      if(extendedPalette != null)
+      {
+        if(new File(extendedPalette).exists())
+          extendedBundle = new PropertyResourceBundle(new FileInputStream(extendedPalette + ".properties"));
+        else if(getClass().getClassLoader().getResource(extendedPalette) != null)
+        {
+          extendedBundle = new PropertyResourceBundle(getClass().getClassLoader().getResourceAsStream(extendedPalette + ".properties"));
+        }
+      }
+      
+      erb = new EnhancedResourceBundle(bundle, extendedBundle);
+
+      InputStream is = WorkflowDesigner.class.getClassLoader().getResourceAsStream(defaultPalette +".xml");
       Document doc = db.parse(is);
-      ResourceBundle bundle = ResourceBundle.getBundle("META-INF/palette", Locale.getDefault(), getClass().getClassLoader());
-      Element root = (Element)doc.getElementsByTagName("plugin").item(0);
+      Element root = (Element) doc.getElementsByTagName("plugin").item(0);
+      palette = new PaletteDescriptor(root, erb);
 
-      palette = new PaletteDescriptor(root, new EnhancedResourceBundle(bundle));
+      // extends configuration
+      if (extendedPalette != null)
+      {
+        InputStream extendedStream = null;
+        String extendedXml = extendedPalette + ".xml";
+        if(new File(extendedXml).exists())
+        {
+          extendedStream = new FileInputStream(extendedXml);
+        }
+        else if(getClass().getClassLoader().getResource(extendedXml) != null)
+        {
+          extendedStream = getClass().getClassLoader().getResourceAsStream(extendedXml);
+        }
+        if(extendedStream != null)
+        {
+          Document extendedDoc = db.parse(extendedStream);
+          Element extendedRoot = (Element) extendedDoc.getElementsByTagName("plugin").item(0);
+          palette.init(extendedRoot);
+        }
+        else
+        {
+          System.out.println("WARNING: Cannot find extended palette " + extendedXml);
+        }
+      }
     }
     catch(Exception e)
     {

File src/designer/com/opensymphony/workflow/designer/swing/EnhancedResourceBundle.java

 package com.opensymphony.workflow.designer.swing;
 
-import java.util.ResourceBundle;
-import java.util.MissingResourceException;
-import java.text.MessageFormat;
-import java.text.FieldPosition;
 import java.io.InputStream;
 import java.net.URL;
-import javax.swing.*;
+import java.text.FieldPosition;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.MissingResourceException;
+import java.util.PropertyResourceBundle;
+import java.util.ResourceBundle;
+
+import javax.swing.ImageIcon;
 
 /**
  * User: Hani Suleiman
  * Date: Dec 29, 2003
  * Time: 4:08:58 PM
  */
-public class EnhancedResourceBundle
+public class EnhancedResourceBundle extends ResourceBundle
 {
-	private ResourceBundle bundle;
-	private ClassLoader loader = EnhancedResourceBundle.class.getClassLoader();
+  private PropertyResourceBundle bundle1;
+  private PropertyResourceBundle bundle2;
 
-	public EnhancedResourceBundle(String baseName)
-	{
-		this.bundle = ResourceBundle.getBundle(baseName);
-	}
+  private ClassLoader loader = EnhancedResourceBundle.class.getClassLoader();
 
-	public EnhancedResourceBundle(ResourceBundle bundle)
-	{
-		this.bundle = bundle;
-	}
+  public EnhancedResourceBundle(String bundleName)
+  {
+    this.bundle1 = (PropertyResourceBundle)ResourceBundle.getBundle(bundleName);
+  }
 
-	public ResourceBundle getBundle()
-	{
-		return bundle;
-	}
+  public EnhancedResourceBundle(PropertyResourceBundle bundle)
+  {
+    this.bundle1 = bundle;
+  }
 
-	public String getString(String key)
-	{
-		return getString(key, key);
-	}
+  public EnhancedResourceBundle(PropertyResourceBundle bundle1, PropertyResourceBundle bundle2)
+  {
+    this.bundle1 = bundle1;
+    this.bundle2 = bundle2;
+  }
 
-	public String getString(String key, String defaultValue)
-	{
-		try
-		{
-		  return bundle.getString(key);
-		}
-		catch(MissingResourceException e)
-		{
-		  return defaultValue;
-		}
-	}
+  public ResourceBundle getBundle()
+  {
+    return this;
+  }
 
-	public String getString(String key, Object args)
-	{
+  public String getString(String key, String defaultValue)
+  {
+    try
+    {
+      return bundle1.getString(key);
+    }
+    catch(MissingResourceException e)
+    {
+    }
 
-	  try
-	  {
-	    String value = bundle.getString(key);
-	    MessageFormat format = new MessageFormat(value);
-	    return format.format(args, new StringBuffer(), new FieldPosition(0)).toString();
-	  }
-	  catch(MissingResourceException e)
-	  {
-	    return key;
-	  }
-	}
+    if(bundle2 != null)
+    {
+      try
+      {
+        return bundle2.getString(key);
+      }
+      catch(MissingResourceException e)
+      {
+      }
+    }
 
-	public ImageIcon getIcon(String key)
-	{
-	  String path = getString("image." + key);
-	  if(path == null)
-	  {
-	    return null;
-	  }
-	  else if(path.length() == 0)
-	  {
-	    return null;
-	  }
-	  else
-	    return readImageIcon(path);
-	}
+    return defaultValue;
+  }
 
-	public InputStream getInputStream(String path)
-	{
-	  return loader.getResourceAsStream(path);
-	}
+  public String getString(String key, Object args)
+  {
 
-	public ImageIcon readImageIcon(String path)
-	{
-	  URL url = loader.getResource(path);
-	  return null == url ? null : new ImageIcon(url);
-	}
+    try
+    {
+      String value = bundle1.getString(key);
+      MessageFormat format = new MessageFormat(value);
+      return format.format(args, new StringBuffer(), new FieldPosition(0)).toString();
+    }
+    catch(MissingResourceException e)
+    {
+    }
+
+    if(bundle2 != null)
+    {
+      try
+      {
+        String value = bundle2.getString(key);
+        MessageFormat format = new MessageFormat(value);
+        return format.format(args, new StringBuffer(), new FieldPosition(0)).toString();
+      }
+      catch(MissingResourceException e)
+      {
+      }
+    }
+
+    return key;
+  }
+
+  protected Object handleGetObject(String key)
+  {
+    Object o = bundle1.handleGetObject(key);
+
+    if(o == null && bundle2 != null)
+    {
+      o = bundle2.handleGetObject(key);
+    }
+
+    return o;
+  }
+
+  public Enumeration getKeys()
+  {
+    ArrayList keys = Collections.list(bundle1.getKeys());
+
+    if(bundle2 != null)
+    {
+      keys.addAll(Collections.list(bundle1.getKeys()));
+    }
+
+    return Collections.enumeration(keys);
+  }
+
+  public ImageIcon getIcon(String key)
+  {
+    String path = getString("image." + key);
+    if(path == null)
+    {
+      return null;
+    }
+    else if(path.length() == 0)
+    {
+      return null;
+    }
+    else return readImageIcon(path);
+  }
+
+  public InputStream getInputStream(String path)
+  {
+    return loader.getResourceAsStream(path);
+  }
+
+  public ImageIcon readImageIcon(String path)
+  {
+    URL url = loader.getResource(path);
+    return null == url ? null : new ImageIcon(url);
+  }
+
 }

File src/designer/com/opensymphony/workflow/loader/PaletteDescriptor.java

     throw new UnsupportedOperationException();
   }
 
-  protected void init(Element root)
+  public void init(Element root)
   {
     // argtypes
     Element a = XMLUtil.getChildElement(root, "argtypes");