KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > designer > editor > JoinEditor


1 package com.opensymphony.workflow.designer.editor;
2
3 import java.awt.event.ActionEvent JavaDoc;
4 import java.awt.event.ActionListener JavaDoc;
5 import javax.swing.*;
6
7 import com.jgoodies.forms.builder.PanelBuilder;
8 import com.jgoodies.forms.layout.CellConstraints;
9 import com.jgoodies.forms.layout.FormLayout;
10 import com.opensymphony.workflow.designer.JoinCell;
11 import com.opensymphony.workflow.designer.UIFactory;
12 import com.opensymphony.workflow.designer.ResourceManager;
13 import com.opensymphony.workflow.designer.beanutils.BeanConnector;
14 import com.opensymphony.workflow.designer.model.ConditionsTableModel;
15 import com.opensymphony.workflow.designer.model.ResultsTableModel;
16 import com.opensymphony.workflow.loader.ConditionDescriptor;
17 import com.opensymphony.workflow.loader.JoinDescriptor;
18
19 public class JoinEditor extends DetailPanel implements ActionListener JavaDoc
20 {
21   private JTextField id = UIFactory.createReadOnlyTextField(12);
22
23   private JComboBox conditionTypes = new JComboBox(new String JavaDoc[]{"OR", "AND"});
24
25   private ConditionsTableModel conditionsModel = new ConditionsTableModel();
26   private JTable conditionsTable;
27
28   private ResultsTableModel resultsModel = new ResultsTableModel();
29   private JTable resultsTable;
30   private BeanConnector connector = new BeanConnector();
31
32   public JoinEditor()
33   {
34   }
35
36   protected void initComponents()
37   {
38     FormLayout layout = new FormLayout("2dlu, max(30dlu;pref), 2dlu, pref:grow, 4dlu", "pref, 2dlu, pref, 2dlu, pref, 3dlu, pref, 2dlu, 60dlu, pref, 2dlu");
39     PanelBuilder builder = new PanelBuilder(this, layout);
40     CellConstraints cc = new CellConstraints();
41     builder.addSeparator(ResourceManager.getString("info"), cc.xywh(2, 1, 3, 1));
42     builder.addLabel(ResourceManager.getString("id"), cc.xy(2, 3));
43     builder.add(id, cc.xy(4, 3));
44     connector.connect(id, "id");
45
46     builder.addLabel(ResourceManager.getString("condition.type"), cc.xy(2, 5));
47
48     builder.add(conditionTypes, cc.xy(4, 5));
49     connector.connect(conditionTypes, "conditionType");
50     builder.addSeparator(ResourceManager.getString("conditions"), cc.xywh(2, 7, 3, 1));
51
52     conditionsModel.setGraphModel(getModel());
53     conditionsModel.setType(ConditionsTableModel.JOIN);
54     conditionsTable = new JTable(conditionsModel);
55     builder.add(UIFactory.createTablePanel(conditionsTable), cc.xywh(2, 9, 3, 1));
56
57     builder.add(UIFactory.getAddRemovePropertiesBar(this, "cond", new String JavaDoc[]{"add", "remove", "edit"}), cc.xywh(2, 10, 3, 1));
58
59   }
60
61   public String JavaDoc getTitle()
62   {
63     return ResourceManager.getString("title.join", new Object JavaDoc[]{id.getText()});
64   }
65
66   protected void updateView()
67   {
68     JoinCell cell = (JoinCell)getCell();
69
70     JoinDescriptor descriptor = cell.getJoinDescriptor();
71
72     conditionsModel.setList(descriptor.getConditions());
73     connector.setSource(descriptor);
74
75     // if (cell.getJoinDescriptor().getResult() != null) {
76
// List list = new ArrayList();
77
// list.add(cell.getJoinDescriptor().getResult());
78
// resultsModel.setList(list);
79
// }
80
// else{
81
// resultsModel.setList(new ArrayList());
82
// }
83
}
84
85   public void actionPerformed(ActionEvent JavaDoc e)
86   {
87     String JavaDoc command = e.getActionCommand().toLowerCase();
88     if(command.equals("condadd"))
89     {
90       add();
91     }
92     else if(command.equals("condremove"))
93     {
94       remove();
95     }
96     else if(command.equals("condedit"))
97     {
98       modify();
99     }
100
101   }
102
103   private void add()
104   {
105     JoinConditionEditor editor = new JoinConditionEditor((JoinCell)this.getCell());
106     editor.setModel(getModel());
107     ConditionDescriptor cond = editor.add();
108     if(cond != null)
109     {
110       conditionsModel.add(cond);
111     }
112   }
113
114   private void remove()
115   {
116     int[] rows = conditionsTable.getSelectedRows();
117     for(int i = 0; i < rows.length; i++)
118     {
119       conditionsModel.remove(i);
120     }
121   }
122
123   private void modify()
124   {
125     int[] rows = conditionsTable.getSelectedRows();
126     for(int i = 0; i < rows.length; i++)
127     {
128       modify(i);
129     }
130
131   }
132
133   private void modify(int selected)
134   {
135     JoinConditionEditor editor = new JoinConditionEditor((JoinCell)getCell());
136     editor.setModel(getModel());
137     ConditionDescriptor cond = (ConditionDescriptor)conditionsModel.get(selected);
138     editor.modify(cond);
139     conditionsModel.fireTableDataChanged();
140
141   }
142 }
Popular Tags