001: package com.opensymphony.workflow.designer.swing;
002:
003: import java.util.*;
004:
005: import javax.swing.*;
006:
007: import com.jgoodies.forms.layout.FormLayout;
008: import com.jgoodies.forms.builder.DefaultFormBuilder;
009: import com.opensymphony.workflow.designer.ResourceManager;
010: import com.opensymphony.workflow.designer.UIFactory;
011: import com.opensymphony.workflow.loader.ArgsAware;
012: import com.opensymphony.workflow.loader.ArgType;
013:
014: /**
015: * @author Gulei
016: */
017: public class MapPanel extends JPanel {
018: private Map edits = new HashMap();
019: private Map buttons = new HashMap();
020:
021: public Map getEdits() {
022: return edits;
023: }
024:
025: public Map getButtons() {
026: return buttons;
027: }
028:
029: public MapPanel(final ArgsAware descriptor, String type,
030: String owner) {
031: //FormLayout layout = new FormLayout("2dlu, left:max(40dlu;pref), 3dlu, pref:grow, 7dlu");
032: FormLayout layout = new FormLayout(
033: "2dlu, left:max(40dlu;pref), 3dlu, pref:grow, 3dlu, pref:grow, 2dlu");
034: DefaultFormBuilder builder = new DefaultFormBuilder(this ,
035: layout, ResourceManager.getBundle());
036: builder.setLeadingColumnOffset(1);
037: builder.appendI15dSeparator("info");
038: builder.appendI15d("type", new JLabel(noNull(type)));
039: builder.nextLine();
040: builder.appendI15d("name", new JLabel(noNull(descriptor
041: .getName())));
042: builder.nextLine();
043: builder.appendI15d("description", new JLabel(noNull(descriptor
044: .getDescription())));
045: builder.nextLine();
046:
047: if (owner != null) {
048: JTextField tf = new JTextField(15);
049: tf.setText(noNull(owner));
050: builder.appendI15d("owner", tf);
051: edits.put("Owner", tf);
052: builder.nextLine();
053: }
054: Map args = descriptor.getArgs();
055: if (args.size() > 0) {
056: builder.appendI15dSeparator("args");
057: }
058:
059: List keys = new ArrayList(args.keySet());
060: Collections.sort(keys, new Comparator() {
061: public int compare(Object o1, Object o2) {
062: String key1 = (String) o1;
063: String key2 = (String) o2;
064: boolean mod1 = descriptor.isArgModifiable(key1);
065: boolean mod2 = descriptor.isArgModifiable(key2);
066: if (mod1 && !mod2)
067: return 1;
068: if (mod2 && !mod1)
069: return -1;
070: String value1 = descriptor.getPalette().getBundle()
071: .getString(descriptor.getName() + "." + key1,
072: key1);
073: String value2 = descriptor.getPalette().getBundle()
074: .getString(descriptor.getName() + "." + key2,
075: key2);
076: return value1.compareTo(value2);
077: }
078: });
079: Iterator iter = keys.iterator();
080: while (iter.hasNext()) {
081: String key = (String) iter.next();
082: JTextField field = descriptor.isArgModifiable(key) ? new JTextField(
083: 30)
084: : UIFactory.createReadOnlyTextField(30);
085: if (args.get(key) != null) {
086: field.setText((String) args.get(key));
087: }
088: String value = descriptor.getPalette().getBundle()
089: .getString(descriptor.getName() + "." + key, key);
090: //builder.append(value, field);
091: edits.put(key, field);
092: ArgType argType = descriptor.getArgType(key);
093: if (argType != null) {
094: // button displaying list of predefined arguments
095: JButton button = new JButton("...");
096: //builder.append(button);
097: builder.append(value, field, button);
098: buttons.put(key, button);
099: button.addActionListener(new ArgListAction(button,
100: field, argType));
101: } else {
102: builder.append(value, field);
103: }
104: builder.nextLine();
105: }
106: builder.appendI15dSeparator("");
107: }
108:
109: private static String noNull(String s) {
110: return s == null ? "" : s;
111: }
112: }
|