1 package com.opensymphony.workflow.designer.dialogs; 2 3 import java.util.ArrayList ; 4 import java.awt.*; 5 import java.awt.event.ItemListener ; 6 import java.awt.event.ItemEvent ; 7 import javax.swing.*; 8 9 import com.opensymphony.workflow.designer.*; 10 import com.opensymphony.workflow.loader.*; 11 import com.jgoodies.forms.builder.DefaultFormBuilder; 12 13 19 public class ActionTypeDialog extends BaseDialog implements ItemListener 20 { 21 private JComboBox actionType = new JComboBox(new String []{ResourceManager.getString("result.conditional"), ResourceManager.getString("result.unconditional")}); 22 private JComboBox relatedAction; 23 private StepDescriptor source; 24 private WorkflowGraphModel model; 25 26 public ActionTypeDialog(Frame owner, StepDescriptor source) throws HeadlessException 27 { 28 super(owner, ResourceManager.getString("result.select"), true); 29 this.source = source; 30 getBanner().setTitle(ResourceManager.getString("result.create.title")); 31 getBanner().setSubtitle(ResourceManager.getString("result.create.subtitle")); 32 DefaultFormBuilder builder = UIFactory.getDialogBuilder(null, getContentPane()); 33 builder.append(ResourceManager.getString("result.select.long"), actionType); 34 35 java.util.List relatedActions = new ArrayList (source.getActions()); 36 relatedActions.add(0, ResourceManager.getString("result.create.newaction")); 37 relatedAction = new JComboBox(relatedActions.toArray()); 38 relatedAction.setEditable(true); 39 relatedAction.setRenderer(new DefaultListCellRenderer() 40 { 41 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) 42 { 43 JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 44 if(value instanceof ActionDescriptor) 45 { 46 ActionDescriptor action = (ActionDescriptor)value; 47 label.setText(action.getName()); 48 } 49 return label; 50 } 51 }); 52 relatedAction.addItemListener(this); 53 actionType.addItemListener(this); 54 55 builder.append(ResourceManager.getString("result.related.action"), relatedAction); 56 builder.appendRow(builder.getLineGapSpec()); 57 builder.nextLine(); 58 } 59 60 public int getType() 61 { 62 switch(actionType.getSelectedIndex()) 63 { 64 case 0: 65 return ConnectHelper.CONDITIONAL; 66 default: 67 return ConnectHelper.UNCONDITIONAL; 68 } 69 } 70 71 public ActionDescriptor getRelatedAction() 72 { 73 int index = relatedAction.getSelectedIndex(); 74 if(index < 1) 75 { 76 ActionDescriptor sourceAction = DescriptorBuilder.createAction(source, index == 0 ? source.getName() : (String )relatedAction.getEditor().getItem(), Utils.getNextId(model.getContext())); 77 Utils.checkId(model.getContext(), sourceAction); 78 return sourceAction; 79 } 80 return (ActionDescriptor)relatedAction.getSelectedItem(); 81 } 82 83 public WorkflowGraphModel getModel() 84 { 85 return model; 86 } 87 88 public void setModel(WorkflowGraphModel model) 89 { 90 this.model = model; 91 } 92 93 public void itemStateChanged(ItemEvent e) 94 { 95 if(e.getStateChange() == ItemEvent.SELECTED) 96 { 97 if(e.getSource() == relatedAction || e.getSource() == actionType) 98 { 99 if(actionType.getSelectedIndex() == 1 && relatedAction.getSelectedIndex() > 0) 101 { 102 ActionDescriptor action = (ActionDescriptor)relatedAction.getSelectedItem(); 103 if(action.getUnconditionalResult() != null) 104 { 105 JOptionPane.showMessageDialog(this, "Action already has an unconditional result.\nTo create a new one, delete the existing one first.", "Duplicate unconditional result", JOptionPane.ERROR_MESSAGE); 106 if(e.getSource() == relatedAction) 107 relatedAction.setSelectedIndex(0); 108 else 109 actionType.setSelectedIndex(1); 110 } 111 } 112 } 113 } 114 } 115 } | Popular Tags |