KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > range > swing > workflow > WorkflowRangeDisplay


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.metadata.range.swing.workflow;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import java.util.*;
24
25 import javax.swing.*;
26
27 import org.openharmonise.him.*;
28 import org.openharmonise.him.metadata.range.swing.*;
29 import org.openharmonise.vfs.authentication.*;
30 import org.openharmonise.vfs.metadata.*;
31 import org.openharmonise.vfs.metadata.value.*;
32 import org.openharmonise.vfs.servers.ServerList;
33 import org.openharmonise.workfloweditor.vfs.*;
34
35
36 /**
37  *
38  * @author Matthew Large
39  * @version $Revision: 1.2 $
40  *
41  */

42 public class WorkflowRangeDisplay
43     extends AbstractRangeDisplay
44     implements RangeDisplay, LayoutManager, ActionListener {
45
46     private ArrayList m_stages = new ArrayList();
47
48     /**
49      * @param propInstance
50      */

51     public WorkflowRangeDisplay(PropertyInstance propInstance) {
52         super(propInstance);
53         this.setup();
54     }
55     
56     private void setup() {
57         this.setLayout(this);
58         
59         this.orderStages();
60         
61         int nCount = 1;
62         Iterator itor = this.m_stages.iterator();
63         while (itor.hasNext()) {
64             StageDetails stageDetails = (StageDetails) itor.next();
65             
66             this.add(stageDetails.getCheckBox());
67             
68             nCount++;
69         }
70         
71         SwingUtilities.invokeLater(
72                 new Runnable JavaDoc() {
73                     public void run() {
74                         checkAllDependencies();
75                     }
76                 });
77         
78         this.layoutContainer(null);
79     }
80     
81     public void checkAllDependencies() {
82         Iterator itor = this.m_stages.iterator();
83         while (itor.hasNext()) {
84             StageDetails stageDetails = (StageDetails) itor.next();
85             
86             stageDetails.checkDependencies();
87         }
88         this.validate();
89     }
90
91     /* (non-Javadoc)
92      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
93      */

94     public void actionPerformed(ActionEvent arg0) {
95     }
96
97     /* (non-Javadoc)
98      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
99      */

100     public void layoutContainer(Container arg0) {
101         int nHeight = 10;
102
103         Iterator itor = this.m_stages.iterator();
104         while (itor.hasNext()) {
105             StageDetails stageDetails = (StageDetails) itor.next();
106             JCheckBox check = stageDetails.getCheckBox();
107             check.setSize(check.getPreferredSize());
108             check.setLocation(10, nHeight);
109             nHeight = nHeight + 25;
110             stageDetails.setEnabled(this.isEnabled());
111         }
112     }
113     
114     private void orderStages() {
115         VFSUser user = ServerList.getInstance().getHarmoniseServer().getVFS().getAuthentication().getUser();
116         Property prop = this.getPropertyInstance().getDefinition();
117         
118         VFSWorkflowModel model = new VFSWorkflowModel("", prop);
119         Iterator itor = model.getWorkflowStages().iterator();
120         while (itor.hasNext()) {
121             VFSWorkflowStage stage = (VFSWorkflowStage) itor.next();
122             
123             ResourceValue value = null;
124             Iterator itor2 = this.getPropertyInstance().getValues().iterator();
125             while (itor2.hasNext()) {
126                 ResourceValue tempValue = (ResourceValue) itor2.next();
127                 if(tempValue.getValue().equals(stage.getPath())) {
128                     value=tempValue;
129                     break;
130                 }
131             }
132             StageDetails stageDetails = new StageDetails(stage, this.getPropertyInstance(), user, value, this);
133             this.m_stages.add(stageDetails);
134         }
135         
136         itor = this.m_stages.iterator();
137         while (itor.hasNext()) {
138             StageDetails stageDetails = (StageDetails) itor.next();
139             VFSWorkflowStage stage = stageDetails.getStage();
140             Iterator itor2 = this.m_stages.iterator();
141             while (itor2.hasNext()) {
142                 StageDetails tempStageDetails = (StageDetails) itor2.next();
143                 Iterator itor3 = tempStageDetails.getStage().getDependancies().iterator();
144                 while (itor3.hasNext()) {
145                     VFSWorkflowStage innerStage = (VFSWorkflowStage) itor3.next();
146                     if(innerStage==stage) {
147                         stageDetails.addDependentStage(tempStageDetails);
148                     }
149                 }
150                 Iterator itor4 = stage.getDependancies().iterator();
151                 while (itor4.hasNext()) {
152                     VFSWorkflowStage dependency = (VFSWorkflowStage) itor4.next();
153                     if(tempStageDetails.getStage()==dependency) {
154                         stageDetails.addDependency(tempStageDetails);
155                     }
156                 }
157             }
158         }
159         
160         ArrayList tempList = (ArrayList) this.m_stages.clone();
161         itor = tempList.iterator();
162         while (itor.hasNext()) {
163             StageDetails stageDetails = (StageDetails) itor.next();
164             Iterator itor2 = stageDetails.getDependencies().iterator();
165             while (itor2.hasNext()) {
166                 StageDetails dependency = (StageDetails) itor2.next();
167                 if(this.m_stages.indexOf(dependency)>this.m_stages.indexOf(stageDetails)) {
168                     this.m_stages.remove(dependency);
169                     this.m_stages.add(this.m_stages.indexOf(stageDetails), dependency);
170                 }
171             }
172         }
173         
174         itor = this.m_stages.iterator();
175         while (itor.hasNext()) {
176             StageDetails stageDetails = (StageDetails) itor.next();
177             stageDetails.setIndex(this.m_stages.indexOf(stageDetails)+1);
178         }
179         
180         itor = this.m_stages.iterator();
181         while (itor.hasNext()) {
182             StageDetails stageDetails = (StageDetails) itor.next();
183             stageDetails.renderText();
184             stageDetails.checkDependencies();
185             stageDetails.setEnabled(this.isEnabled());
186         }
187     }
188
189     /* (non-Javadoc)
190      * @see java.awt.Component#getPreferredSize()
191      */

192     public Dimension getPreferredSize() {
193         return new Dimension(400,400);
194     }
195
196     /* (non-Javadoc)
197      * @see java.awt.Component#isValid()
198      */

199     public boolean isMetadataValid() {
200         boolean bStagesComplete = true;
201         
202         Iterator itor = this.m_stages.iterator();
203         while (itor.hasNext()) {
204             StageDetails stage = (StageDetails) itor.next();
205             if(stage.isMandatory() && !stage.isSelected()) {
206                 bStagesComplete = false;
207             }
208         }
209         
210         return bStagesComplete;
211     }
212
213     /* (non-Javadoc)
214      * @see com.simulacramedia.contentmanager.metadata.range.swing.RangeDisplay#getPanel()
215      */

216     public JPanel getPanel() {
217         return this;
218     }
219
220     /* (non-Javadoc)
221      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
222      */

223     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
224     }
225
226     /* (non-Javadoc)
227      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
228      */

229     public void removeLayoutComponent(Component arg0) {
230     }
231
232     /* (non-Javadoc)
233      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
234      */

235     public Dimension minimumLayoutSize(Container arg0) {
236         return this.getPreferredSize();
237     }
238
239     /* (non-Javadoc)
240      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
241      */

242     public Dimension preferredLayoutSize(Container arg0) {
243         return this.getPreferredSize();
244     }
245     
246     public void validateWorkflow() {
247         super.validateTab();
248     }
249
250 }
251
Popular Tags