1 package com.opensymphony.workflow.designer.editor; 2 3 import java.awt.event.ActionEvent ; 4 import java.awt.event.ActionListener ; 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.InitialActionCell; 11 import com.opensymphony.workflow.designer.ResourceManager; 12 import com.opensymphony.workflow.designer.UIFactory; 13 import com.opensymphony.workflow.designer.beanutils.BeanConnector; 14 import com.opensymphony.workflow.designer.model.ConditionsTableModel; 15 import com.opensymphony.workflow.designer.model.FunctionsTableModel; 16 import com.opensymphony.workflow.loader.*; 17 18 22 public class InitialActionEditor extends DetailPanel implements ActionListener 23 { 24 private static final String [] BUTTONS = new String []{"add", "remove", "edit"}; 25 26 private JTextField id = UIFactory.createReadOnlyTextField(12); 27 private JTextField name = new JTextField(12); 28 private JTextField view = new JTextField(12); 29 private JComboBox restrict = new JComboBox(new String []{"AND", "OR"}); 30 31 private ConditionsTableModel conditionsModel = new ConditionsTableModel(); 32 private JTable conditionsTable; 33 34 private FunctionsTableModel preModel = new FunctionsTableModel(); 35 private JTable pre; 36 37 private FunctionsTableModel postModel = new FunctionsTableModel(); 38 private JTable post; 39 40 private BeanConnector connector = new BeanConnector(); 41 private ActionDescriptor descriptor; 42 43 public InitialActionEditor() 44 { 45 } 46 47 protected void initComponents() 48 { 49 FormLayout layout = new FormLayout("2dlu, max(30dlu;pref), 2dlu, pref:grow, 4dlu", "pref, 2dlu, " + "pref, 2dlu, " + "pref, 2dlu, " + "pref, 2dlu, " + "pref, 2dlu, " + "pref, 2dlu, " + "50dlu:grow, " + "pref, 2dlu, " + "pref, 2dlu, " + "50dlu:grow, " + "pref, 2dlu, " + "pref, 2dlu, " + "50dlu:grow, " + "pref, 2dlu"); 65 PanelBuilder builder = new PanelBuilder(this, layout); 66 CellConstraints cc = new CellConstraints(); 67 68 builder.addSeparator(ResourceManager.getString("info"), cc.xywh(2, 1, 3, 1)); 69 70 builder.addLabel(ResourceManager.getString("id"), cc.xy(2, 3)); 71 connector.connect(id, "id"); 72 builder.add(id, cc.xy(4, 3)); 73 74 builder.addLabel(ResourceManager.getString("name"), cc.xy(2, 5)); 75 connector.connect(name, "name"); 76 builder.add(name, cc.xy(4, 5)); 77 78 builder.addLabel(ResourceManager.getString("view"), cc.xy(2, 7)); 79 connector.connect(view, "view"); 80 builder.add(view, cc.xy(4, 7)); 81 82 builder.addSeparator(ResourceManager.getString("permissions"), cc.xywh(2, 9, 3, 1)); 83 84 builder.addLabel(ResourceManager.getString("type"), cc.xy(2, 11)); 85 connector.connect(restrict, "restriction.conditionType"); 86 builder.add(restrict, cc.xy(4, 11)); 87 88 conditionsTable = new JTable(conditionsModel); 89 conditionsModel.setType(ConditionsTableModel.PERMISSION); 90 conditionsModel.setGraphModel(getModel()); 91 builder.add(UIFactory.createTablePanel(conditionsTable), cc.xywh(2, 13, 3, 1)); 92 builder.add(UIFactory.getAddRemovePropertiesBar(this, "permission", BUTTONS), cc.xywh(2, 14, 3, 1)); 93 94 builder.addSeparator(ResourceManager.getString("prefunctions"), cc.xywh(2, 16, 3, 1)); 95 96 pre = new JTable(preModel); 97 preModel.setGraphModel(getModel()); 98 builder.add(UIFactory.createTablePanel(pre), cc.xywh(2, 18, 3, 1)); 99 builder.add(UIFactory.getAddRemovePropertiesBar(this, "pre", BUTTONS), cc.xywh(2, 19, 3, 1)); 100 101 builder.addSeparator(ResourceManager.getString("postfunctions"), cc.xywh(2, 21, 3, 1)); 102 103 post = new JTable(postModel); 104 postModel.setGraphModel(getModel()); 105 builder.add(UIFactory.createTablePanel(post), cc.xywh(2, 23, 3, 1)); 106 builder.add(UIFactory.getAddRemovePropertiesBar(this, "post", BUTTONS), cc.xywh(2, 24, 3, 1)); 107 } 108 109 public String getTitle() 110 { 111 return ResourceManager.getString("title.start"); 112 } 113 114 protected void viewClosed() 115 { 116 if(conditionsTable.isEditing()) 117 { 118 conditionsTable.getCellEditor().stopCellEditing(); 119 } 120 121 if(pre.isEditing()) 122 { 123 pre.getCellEditor().stopCellEditing(); 124 } 125 126 if(post.isEditing()) 127 { 128 post.getCellEditor().stopCellEditing(); 129 } 130 131 } 132 133 protected void updateView() 134 { 135 InitialActionCell cell = (InitialActionCell)getCell(); 136 descriptor = cell.getActionDescriptor(); 137 RestrictionDescriptor restriction = descriptor.getRestriction(); 138 if(restriction == null) 139 { 140 restriction = new RestrictionDescriptor(); 141 restriction.setParent(descriptor); 142 ConditionsDescriptor conditions = new ConditionsDescriptor(); 143 restriction.getConditions().add(conditions); 144 conditions.setParent(restriction); 145 conditions.setType((String )restrict.getSelectedItem()); 146 descriptor.setRestriction(restriction); 147 } 148 conditionsModel.setList(((ConditionsDescriptor)restriction.getConditions().get(0)).getConditions()); 149 conditionsTable.getSelectionModel().clearSelection(); 150 151 preModel.setList(descriptor.getPreFunctions()); 152 pre.getSelectionModel().clearSelection(); 153 154 postModel.setList(descriptor.getPostFunctions()); 155 post.getSelectionModel().clearSelection(); 156 157 connector.setSource(descriptor); 158 } 159 160 public void actionPerformed(ActionEvent e) 161 { 162 String command = e.getActionCommand(); 163 164 if(command.equals("permissionadd")) 165 { 166 add(); 167 } 168 else if(command.equals("permissionremove")) 169 { 170 remove(); 171 } 172 else if(command.equals("permissionedit")) 173 { 174 modify(); 175 } 176 else if(command.equals("preadd")) 177 { 178 preadd(); 179 } 180 else if(command.equals("preremove")) 181 { 182 preremove(); 183 } 184 else if(command.equals("preedit")) 185 { 186 premodify(); 187 } 188 else if(command.equals("postadd")) 189 { 190 postadd(); 191 } 192 else if(command.equals("postremove")) 193 { 194 postremove(); 195 } 196 else if(command.equals("postedit")) 197 { 198 postmodify(); 199 } 200 } 201 202 private void add() 203 { 204 StartPermissionEditor editor = new StartPermissionEditor((InitialActionCell)getCell()); 205 editor.setModel(getModel()); 206 ConditionDescriptor cond = editor.add(); 207 if(cond != null) 208 { 209 conditionsModel.add(cond); 210 } 211 } 212 213 private void remove() 214 { 215 int[] rows = conditionsTable.getSelectedRows(); 216 for(int i = 0; i < rows.length; i++) 217 { 218 conditionsModel.remove(rows[i]); 219 } 220 } 221 222 private void modify() 223 { 224 int[] rows = conditionsTable.getSelectedRows(); 225 for(int i = 0; i < rows.length; i++) 226 { 227 modify(rows[i]); 228 } 229 230 } 231 232 private void modify(int selected) 233 { 234 ConditionDescriptor cond = (ConditionDescriptor)conditionsModel.get(selected); 235 236 StartPermissionEditor editor = new StartPermissionEditor((InitialActionCell)getCell()); 237 editor.setModel(getModel()); 238 editor.modify(cond); 239 240 conditionsModel.fireTableDataChanged(); 241 } 242 243 private void preadd() 244 { 245 StartFunctionEditor editor = new StartFunctionEditor((InitialActionCell)getCell()); 246 editor.setModel(getModel()); 247 FunctionDescriptor func = editor.add(); 248 if(func != null) 249 { 250 preModel.add(func); 251 } 252 } 253 254 private void preremove() 255 { 256 int[] rows = pre.getSelectedRows(); 257 for(int i = 0; i < rows.length; i++) 258 { 259 preModel.remove(rows[i]); 260 } 261 } 262 263 private void premodify() 264 { 265 int[] rows = pre.getSelectedRows(); 266 for(int i = 0; i < rows.length; i++) 267 { 268 premodify(rows[i]); 269 } 270 271 } 272 273 private void premodify(int selected) 274 { 275 FunctionDescriptor func = (FunctionDescriptor)preModel.get(selected); 276 277 StartFunctionEditor editor = new StartFunctionEditor((InitialActionCell)getCell()); 278 editor.setModel(getModel()); 279 editor.modify(func); 280 281 preModel.fireTableDataChanged(); 282 } 283 284 private void postadd() 285 { 286 StartFunctionEditor editor = new StartFunctionEditor((InitialActionCell)getCell()); 287 editor.setModel(getModel()); 288 FunctionDescriptor func = editor.add(); 289 if(func != null) 290 { 291 postModel.add(func); 292 } 293 } 294 295 private void postremove() 296 { 297 int[] rows = post.getSelectedRows(); 298 for(int i = 0; i < rows.length; i++) 299 { 300 postModel.remove(rows[i]); 301 } 302 } 303 304 private void postmodify() 305 { 306 int[] rows = post.getSelectedRows(); 307 for(int i = 0; i < rows.length; i++) 308 { 309 postmodify(rows[i]); 310 } 311 312 } 313 314 private void postmodify(int selected) 315 { 316 FunctionDescriptor func = (FunctionDescriptor)postModel.get(selected); 317 318 StartFunctionEditor editor = new StartFunctionEditor((InitialActionCell)getCell()); 319 editor.setModel(getModel()); 320 editor.modify(func); 321 322 postModel.fireTableDataChanged(); 323 } 324 325 } 326 | Popular Tags |