Commits

hani  committed a2c8b70

Config descriptors now have explicit refs to their palette
Refactored convenience bundle stuff into EnhancedResourceBundle
More stuff in ArgsAware
MapPanel now shows args sorted
i18n support for config descriptor args

  • Participants
  • Parent commits 694e987

Comments (0)

Files changed (17)

File src/designer/META-INF/palette.properties

 #conditions
 allow.owner.only=Allow Owner Only
 allow.owner.only.long=Allow Owner Only
+
 check.status=Check Status
 check.status.long=Check whether the workflow is in the specified status
+
 check.usergroup=Check User Group
 check.usergroup.long=Check that the current user belongs in the specified group
 
 set.caller.long=Set caller variable
 set.most.recent.owner=Set Most Recent Owner
 set.most.recent.owner.long=Set mostRecentOwner variable
+
+send.email=Send Email
+send.email.long=Send an email message
+send.email.from=1. From
+send.email.to=2. To
+send.email.cc=3. CC
+send.email.smtpHost=4. SMTP Host
+send.email.message=5. Message Body

File src/designer/META-INF/palette.xml

       <arg name="class.name">com.opensymphony.workflow.util.MostRecentOwner</arg>
       <name>set.most.recent.owner</name>
     </function>
+    <function type="class">
+      <arg name="class.name">com.opensymphony.workflow.util.SendEmail</arg>
+      <arg name="to" modifiable="true"></arg>
+      <arg name="from" modifiable="true"></arg>
+      <arg name="cc" modifiable="true"></arg>
+      <arg name="message" modifiable="true"></arg>
+      <arg name="smtpHost" modifiable="true"></arg>
+      <name>send.email</name>
+    </function>
 	</functions>
 
 	<permissionconditions>

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

 package com.opensymphony.workflow.designer;
 
 import java.io.*;
-import java.net.URL;
-import java.util.MissingResourceException;
 import java.util.ResourceBundle;
-import java.text.MessageFormat;
-import java.text.FieldPosition;
 import javax.swing.*;
 
+import com.opensymphony.workflow.designer.swing.EnhancedResourceBundle;
+
 public final class ResourceManager
 {
   private static final ResourceManager INSTANCE = new ResourceManager();
 
-  private ResourceBundle bundle;
-
-  private ClassLoader loader = ResourceManager.class.getClassLoader();
+  private EnhancedResourceBundle bundle;
 
   private ResourceManager()
   {
-    bundle = ResourceBundle.getBundle(getClass().getName());
+    bundle = new EnhancedResourceBundle(getClass().getName());
   }
 
   public static ResourceBundle getBundle()
   {
-    return INSTANCE.bundle;
+    return INSTANCE.bundle.getBundle();
   }
 
   public static String getString(String key)
   {
-    try
-    {
-      return INSTANCE.bundle.getString(key);
-    }
-    catch(MissingResourceException e)
-    {
-      return key;
-    }
+	  return getString(key, key);
   }
 
+	public static String getString(String key, String defaultValue)
+	{
+		return INSTANCE.bundle.getString(key);
+	}
+
   public static String getString(String key, Object args)
   {
-
-    try
-    {
-      String value = INSTANCE.bundle.getString(key);
-      MessageFormat format = new MessageFormat(value);
-      return format.format(args, new StringBuffer(), new FieldPosition(0)).toString();
-    }
-    catch(MissingResourceException e)
-    {
-      return key;
-    }
+	  return INSTANCE.bundle.getString(key, args);
   }
 
   public static 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 INSTANCE.bundle.getIcon(key);
   }
 
   public static InputStream getInputStream(String path)
   {
-    return INSTANCE.loader.getResourceAsStream(path);
+    return INSTANCE.bundle.getInputStream(path);
   }
 
   public static ImageIcon readImageIcon(String path)
   {
-    URL url = INSTANCE.loader.getResource(path);
-    return null == url ? null : new ImageIcon(url);
+	  return INSTANCE.bundle.readImageIcon(path);
   }
 
   public static String readTextFromFile(String path)
       }
     }
   }
-
 }

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

 	    ResourceBundle bundle = ResourceBundle.getBundle("META-INF/palette", Locale.getDefault(), getClass().getClassLoader());
       Element root = (Element)doc.getElementsByTagName("plugin").item(0);
 
-      palette = new PaletteDescriptor(root, bundle);
+      palette = new PaletteDescriptor(root, new EnhancedResourceBundle(bundle));
     }
     catch(SAXException e)
     {

File src/designer/com/opensymphony/workflow/designer/dialogs/DialogUtils.java

       null);							// initial select
   }
 
-  public static Map getMapDialog(ArgsAware descriptor, String type, String name, String description, String owner)
+  public static Map getMapDialog(ArgsAware descriptor, String type, String owner)
   {
-    MapPanel panel = new MapPanel(descriptor, type, name, description, owner);
+    MapPanel panel = new MapPanel(descriptor, type, owner);
     JOptionPane pane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
     JDialog dialog = pane.createDialog(null, ResourceManager.getString("specify.properties"));
 	  dialog.setResizable(true);
     {
       return null;
     }
-
     Map edits = panel.getEdits();
     Map args = descriptor.getArgs();
     Set keys = args.keySet();
       String newValue = field.getText();
       args.put(key, newValue);
     }
-
     return args;
   }
 }

File src/designer/com/opensymphony/workflow/designer/editor/ConditionEditor.java

     }
     else
     {
-      condition = new ConfigConditionDescriptor();
+      condition = new ConfigConditionDescriptor(getModel().getPalette());
       condition.setType(cond.getType());
     }
 

File src/designer/com/opensymphony/workflow/designer/editor/FunctionEditor.java

     }
     else
     {
-      function = new ConfigFunctionDescriptor();
+      function = new ConfigFunctionDescriptor(getModel().getPalette());
       function.setType(func.getType());
     }
 

File src/designer/com/opensymphony/workflow/designer/spi/DefaultConditionPlugin.java

  */
 public class DefaultConditionPlugin implements ConditionPlugin
 {
-
   private ConfigConditionDescriptor condition;
 
   public void setCondition(ConfigConditionDescriptor descriptor)
   {
     condition = descriptor;
-
   }
 
   public ConfigConditionDescriptor getCondition()
 
   public boolean editCondition(Map args)
   {
-    Map newArg = DialogUtils.getMapDialog(condition, condition.getType(), condition.getDisplayName(), condition.getDescription(), null);
+    Map newArg = DialogUtils.getMapDialog(condition, condition.getType(), null);
     if(newArg == null)
     {
       return false;
     }
-
     condition.getArgs().putAll(newArg);
     return true;
   }
-
 }

File src/designer/com/opensymphony/workflow/designer/spi/DefaultFunctionPlugin.java

 
   public boolean editFunction(Map args)
   {
-    Map newArg = DialogUtils.getMapDialog(func, func.getType(), func.getDisplayName(), func.getDescription(), null);
+    Map newArg = DialogUtils.getMapDialog(func, func.getType(), null);
     if(newArg == null)
     {
       return false;

File src/designer/com/opensymphony/workflow/designer/spi/DefaultPermissionPlugin.java

 
   public boolean editPermissionCondition(Map args)
   {
-    Map newArg = DialogUtils.getMapDialog(perm, perm.getType(), perm.getName(), perm.getDescription(), perm.getOwner());
+    Map newArg = DialogUtils.getMapDialog(perm, perm.getType(), perm.getOwner());
     if(newArg == null)
     {
       return false;

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.*;
+
+/**
+ * User: Hani Suleiman
+ * Date: Dec 29, 2003
+ * Time: 4:08:58 PM
+ */
+public class EnhancedResourceBundle
+{
+	private ResourceBundle bundle;
+	private ClassLoader loader = EnhancedResourceBundle.class.getClassLoader();
+
+	public EnhancedResourceBundle(String baseName)
+	{
+		this.bundle = ResourceBundle.getBundle(baseName);
+	}
+
+	public EnhancedResourceBundle(ResourceBundle bundle)
+	{
+		this.bundle = bundle;
+	}
+
+	public ResourceBundle getBundle()
+	{
+		return bundle;
+	}
+
+	public String getString(String key)
+	{
+		return getString(key, key);
+	}
+
+	public String getString(String key, String defaultValue)
+	{
+		try
+		{
+		  return bundle.getString(key);
+		}
+		catch(MissingResourceException e)
+		{
+		  return defaultValue;
+		}
+	}
+
+	public String getString(String key, Object args)
+	{
+
+	  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;
+	  }
+	}
+
+	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/designer/swing/MapPanel.java

 package com.opensymphony.workflow.designer.swing;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 import javax.swing.*;
 
     return edits;
   }
 
-  public MapPanel(ArgsAware descriptor, String type, String name, String description, String owner)
+  public MapPanel(final ArgsAware descriptor, String type, String owner)
   {
     FormLayout layout = new FormLayout("2dlu, left:max(40dlu;pref), 3dlu, 110dlu:grow, 7dlu");
 		DefaultFormBuilder builder = new DefaultFormBuilder(this, layout, ResourceManager.getBundle());
 	  builder.setLeadingColumnOffset(1);
     builder.appendI15dSeparator("info");
     builder.appendI15d("type", new JLabel(noNull(type)));
-	  builder.appendI15d("name", new JLabel(noNull(name)));
-	  builder.appendI15d("description", new JLabel(noNull(description)));
+	  builder.appendI15d("name", new JLabel(noNull(descriptor.getName())));
+	  builder.appendI15d("description", new JLabel(noNull(descriptor.getDescription())));
 		if(owner!=null)
 		{
 			JTextField tf = new JTextField(15);
       builder.appendI15dSeparator("args");
     }
 
-    Set keys = args.keySet();
+    List keys = new ArrayList(args.keySet());
+	  Collections.sort(keys, new Comparator()
+	  {
+		  public int compare(Object o1, Object o2)
+		  {
+			  String key1 = (String)o1;
+			  String key2 = (String)o2;
+			  boolean mod1 = descriptor.isArgModifiable(key1);
+			  boolean mod2 = descriptor.isArgModifiable(key2);
+			  if(mod1 && !mod2) return 1;
+			  if(mod2 && !mod1) return -1;
+			  String value1 =  descriptor.getPalette().getBundle().getString(descriptor.getName() + "." + key1, key1);
+			  String value2 =  descriptor.getPalette().getBundle().getString(descriptor.getName() + "." + key2, key2);
+			  return value1.compareTo(value2);
+		  }
+	  });
     Iterator iter = keys.iterator();
     while(iter.hasNext())
     {
       {
         field.setText((String)args.get(key));
       }
-	    builder.append(key, field);
+	    String value = descriptor.getPalette().getBundle().getString(descriptor.getName() + "." + key, key);
+	    builder.append(value, field);
       edits.put(key, field);
     }
   }

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

  */
 public interface ArgsAware
 {
+	public String getName();
+	public String getDescription();
+	public PaletteDescriptor getPalette();
   public boolean isArgModifiable(String name);
   public Map getArgs();
 }

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

   protected String description;
 	protected String displayName;
   protected List modifiableArgs = new ArrayList();
+	private PaletteDescriptor palette;
 
-  public ConfigConditionDescriptor()
+	public ConfigConditionDescriptor(PaletteDescriptor palette)
   {
-
+		this.palette = palette;
   }
 
-  public ConfigConditionDescriptor(Element condition)
+  public ConfigConditionDescriptor(PaletteDescriptor palette, Element condition)
   {
+	  this.palette = palette;
     init(condition);
   }
 
 	  displayName = other.displayName;
 	  description = other.description;
     modifiableArgs = other.modifiableArgs;
+	  palette = other.palette;
   }
 
+	public PaletteDescriptor getPalette()
+	{
+		return palette;
+	}
+
+	public void setPalette(PaletteDescriptor palette)
+	{
+		this.palette = palette;
+	}
+
   protected void init(Element condition)
   {
     type = condition.getAttribute("type");

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

   protected String description;
 	protected String displayName;
   protected List modifiableArgs = new ArrayList();
+	private PaletteDescriptor palette;
 
-  public ConfigFunctionDescriptor()
+  public ConfigFunctionDescriptor(PaletteDescriptor palette)
   {
+	  this.palette = palette;
   }
 
-  public ConfigFunctionDescriptor(Element function)
+  public ConfigFunctionDescriptor(PaletteDescriptor palette, Element function)
   {
+	  this.palette = palette;
     init(function);
   }
 
 	  displayName = other.displayName;
 	  description = other.description;
     modifiableArgs = other.modifiableArgs;
+	  palette = other.palette;
   }
 
+	public PaletteDescriptor getPalette()
+	{
+		return palette;
+	}
+
+	public void setPalette(PaletteDescriptor palette)
+	{
+		this.palette = palette;
+	}
+
   public void writeXML(PrintWriter writer, int indent)
   {
     throw new UnsupportedOperationException();

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

 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.ResourceBundle;
 
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
+import com.opensymphony.workflow.designer.swing.EnhancedResourceBundle;
+import com.opensymphony.workflow.designer.ResourceManager;
 
 /**
  * @author jackflit
   protected List resultList = new ArrayList();
   protected String defaultOldStatus = null;
   protected String defaultNextStatus = null;
-	private ResourceBundle bundle;
+	private EnhancedResourceBundle bundle;
 
-	public PaletteDescriptor(Element root, ResourceBundle bundle)
+	public PaletteDescriptor(Element root, EnhancedResourceBundle bundle)
   {
 	  this.bundle = bundle;
     init(root);
       for(int i = 0; i < joins.getLength(); i++)
       {
         Element condition = (Element)joins.item(i);
-        ConfigConditionDescriptor jcd = new ConfigConditionDescriptor(condition);
+        ConfigConditionDescriptor jcd = new ConfigConditionDescriptor(this, condition);
 	      jcd.setDescription(bundle.getString(jcd.getName() + ".long"));
 	      jcd.setDisplayName(bundle.getString(jcd.getName()));
         jcd.setParent(this);
       for(int i = 0; i < joins.getLength(); i++)
       {
         Element function = (Element)joins.item(i);
-        ConfigFunctionDescriptor pd = new ConfigFunctionDescriptor(function);
+        ConfigFunctionDescriptor pd = new ConfigFunctionDescriptor(this, function);
 	      pd.setDescription(bundle.getString(pd.getName() + ".long"));
 	      pd.setDisplayName(bundle.getString(pd.getName()));
         pd.setParent(this);
       for(int i = 0; i < joins.getLength(); i++)
       {
         Element condition = (Element)joins.item(i);
-        PermissionConditionDescriptor pcd = new PermissionConditionDescriptor(condition);
+        PermissionConditionDescriptor pcd = new PermissionConditionDescriptor(this, condition);
 	      pcd.setDescription(bundle.getString(pcd.getName() + ".long"));
 	      pcd.setDisplayName(bundle.getString(pcd.getName()));
         pcd.setParent(this);
       for(int i = 0; i < joins.getLength(); i++)
       {
         Element condition = (Element)joins.item(i);
-        ConfigConditionDescriptor rcd = new ConfigConditionDescriptor(condition);
+        ConfigConditionDescriptor rcd = new ConfigConditionDescriptor(this, condition);
 	      rcd.setDescription(bundle.getString(rcd.getName() + ".long"));
 	      rcd.setDisplayName(bundle.getString(rcd.getName()));
         rcd.setParent(this);
 
   }
 
+	public EnhancedResourceBundle getBundle()
+	{
+		return bundle;
+	}
 }

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

 {
   protected String owner;
 
-  public PermissionConditionDescriptor()
+  public PermissionConditionDescriptor(PaletteDescriptor palette)
   {
+	  super(palette);
   }
 
-  public PermissionConditionDescriptor(Element condition)
+  public PermissionConditionDescriptor(PaletteDescriptor palette, Element condition)
   {
-    init(condition);
+	  super(palette, condition);
   }
 
   public PermissionConditionDescriptor(PermissionConditionDescriptor permission)
   {
-    type = permission.getType();
-    plugin = permission.getPlugin();
-    name = permission.getName();
-    description = permission.getDescription();
+	  super(permission);
     owner = permission.getOwner();
-    args.putAll(permission.getArgs());
-    modifiableArgs = permission.modifiableArgs;
   }
 
   public void writeXML(PrintWriter writer, int indent)
   {
     owner = string;
   }
-
 }