1 19 package org.openharmonise.him.metadata.range.swing.workflow; 20 21 import java.awt.*; 22 import java.awt.event.*; 23 import java.util.*; 24 import java.util.List ; 25 26 import javax.swing.*; 27 28 import org.openharmonise.vfs.authentication.*; 29 import org.openharmonise.vfs.metadata.*; 30 import org.openharmonise.vfs.metadata.value.*; 31 import org.openharmonise.workfloweditor.vfs.*; 32 33 34 40 public class StageDetails implements ActionListener { 41 42 private ArrayList m_dependents = new ArrayList(); 43 private ArrayList m_dependencies = new ArrayList(); 44 45 private JCheckBox m_checkBox = null; 46 47 private PropertyInstance m_propInst = null; 48 private ResourceValue m_value = null; 49 50 private VFSWorkflowStage m_stage = null; 51 52 private boolean m_bIsSelected = false; 53 private boolean m_bIsEnabled = true; 54 55 private VFSUser m_user = null; 56 57 private int m_nIndex = -1; 58 59 private WorkflowRangeDisplay m_display = null; 60 61 64 public StageDetails(VFSWorkflowStage stage, PropertyInstance propInst, VFSUser user, WorkflowRangeDisplay display) { 65 this(stage, propInst, user, null, display); 66 } 67 68 71 public StageDetails(VFSWorkflowStage stage, PropertyInstance propInst, VFSUser user, ResourceValue value, WorkflowRangeDisplay display) { 72 super(); 73 this.m_stage = stage; 74 this.m_user = user; 75 this.m_propInst = propInst; 76 this.m_value = value; 77 this.m_display = display; 78 this.setup(); 79 } 80 81 private void setup() { 82 83 String fontName = "Dialog"; 84 int fontSize = 11; 85 Font font = new Font(fontName, Font.PLAIN, fontSize); 86 Font boldFont = new Font(fontName, Font.BOLD, fontSize); 87 88 this.m_checkBox = new JCheckBox(this.m_stage.getTitle()); 89 this.m_checkBox.addActionListener(this); 90 if(this.m_stage.isMandatory()) { 91 this.m_checkBox.setFont(boldFont); 92 } else { 93 this.m_checkBox.setFont(font); 94 } 95 if(this.m_value!=null) { 96 this.m_bIsSelected = true; 97 this.m_checkBox.setSelected(true); 98 } 99 } 100 101 public boolean isMandatory() { 102 return this.m_stage.isMandatory(); 103 } 104 105 public JCheckBox getCheckBox() { 106 return this.m_checkBox; 107 } 108 109 public boolean isSelected() { 110 return this.m_bIsSelected; 111 } 112 113 public boolean isEnabled() { 114 return this.m_bIsEnabled; 115 } 116 117 public void setEnabled(boolean bIsEnabled) { 118 this.m_bIsEnabled = bIsEnabled; 119 this.m_checkBox.setEnabled(bIsEnabled); 120 this.m_checkBox.revalidate(); 121 } 122 123 public void setIndex(int nIndex) { 124 this.m_nIndex = nIndex; 125 this.m_checkBox.setText( nIndex + ") " + this.m_stage.getTitle()); 126 } 127 128 public int getIndex() { 129 return this.m_nIndex; 130 } 131 132 public void addDependentStage(StageDetails stage) { 133 this.m_dependents.add(stage); 134 } 135 136 public List getDependencies() { 137 return this.m_dependencies; 138 } 139 140 public void addDependency(StageDetails stage) { 141 this.m_dependencies.add(stage); 142 } 143 144 public void renderText() { 145 String sTitle = this.m_nIndex + ") " + this.m_stage.getTitle(); 146 boolean bFirstLoop = true; 147 148 Iterator itor = this.m_dependencies.iterator(); 149 while (itor.hasNext()) { 150 StageDetails stageDetails = (StageDetails) itor.next(); 151 if(bFirstLoop) { 152 sTitle = sTitle + " depends on "; 153 bFirstLoop=false; 154 } else { 155 sTitle = sTitle + ", "; 156 } 157 sTitle = sTitle + stageDetails.getIndex(); 158 } 159 this.m_checkBox.setText(sTitle); 160 this.m_checkBox.revalidate(); 161 } 162 163 public boolean isChangeAllowed() { 164 boolean bOk = true; 165 166 if(!this.m_user.isSuperUser()) { 167 String sRolePath = this.m_user.getRolePath(); 168 List roles = this.m_stage.getRoles(); 169 if(roles.size()==0) { 170 roles = this.m_stage.getDefinition().getRoles(); 171 } 172 boolean bFound = false; 173 Iterator itor = roles.iterator(); 174 while (itor.hasNext()) { 175 VFSRole role = (VFSRole) itor.next(); 176 if(role.getValuePath().equals(sRolePath)) { 177 bFound = true; 178 } 179 } 180 if(!bFound) { 181 bOk = false; 182 } 183 } 184 return bOk; 185 } 186 187 public void checkDependencies() { 188 boolean bOk = true; 189 190 if(!this.isChangeAllowed()) { 191 bOk=false; 192 } 193 194 Iterator itor = this.m_dependencies.iterator(); 195 while (itor.hasNext()) { 196 StageDetails stageDetails = (StageDetails) itor.next(); 197 if(!stageDetails.isChangeAllowed() || !stageDetails.isSelected()) { 198 bOk = false; 199 } 200 } 201 itor = this.m_dependents.iterator(); 202 while (itor.hasNext()) { 203 StageDetails stageDetails = (StageDetails) itor.next(); 204 if(stageDetails.isSelected()) { 205 bOk = false; 206 } 207 } 208 this.m_bIsEnabled = bOk; 209 this.m_checkBox.setEnabled(this.m_bIsEnabled); 210 this.m_checkBox.revalidate(); 211 } 212 213 public VFSWorkflowStage getStage() { 214 return this.m_stage; 215 } 216 217 220 public void actionPerformed(ActionEvent ae) { 221 this.m_bIsSelected = !this.m_bIsSelected; 222 223 if(this.m_bIsSelected && this.m_value==null) { 224 if(this.m_value==null) { 225 this.m_value = (ResourceValue) this.m_propInst.getNewValueInstance(); 226 this.m_value.setValue(this.m_stage.getPath()); 227 } 228 if(!this.m_propInst.getValues().contains(this.m_value)) { 229 this.m_propInst.addValue(m_value); 230 } 231 } else { 232 this.m_propInst.removeValue(m_value); 233 } 234 235 this.m_checkBox.setSelected(m_bIsSelected); 236 Iterator itor = this.m_dependents.iterator(); 237 while (itor.hasNext()) { 238 StageDetails stageDetails = (StageDetails) itor.next(); 239 stageDetails.checkDependencies(); 240 } 241 itor = this.m_dependencies.iterator(); 242 while (itor.hasNext()) { 243 StageDetails stageDetails = (StageDetails) itor.next(); 244 stageDetails.checkDependencies(); 245 } 246 this.m_display.validateWorkflow(); 247 } 248 } 249 | Popular Tags |