001: /*
002: * (C) Copyright SimulacraMedia 2003. All rights reserved.
003: *
004: * Created on 23-Feb-2004
005: *
006: */
007: package org.openharmonise.him.editors.report;
008:
009: import java.awt.Color;
010: import java.awt.Component;
011: import java.awt.Container;
012: import java.awt.Dimension;
013: import java.awt.Font;
014: import java.awt.LayoutManager;
015: import java.awt.event.ActionEvent;
016: import java.awt.event.ActionListener;
017:
018: import javax.swing.JComboBox;
019: import javax.swing.JLabel;
020: import javax.swing.JPanel;
021:
022: import org.openharmonise.him.*;
023: import org.openharmonise.him.editors.report.rqom.*;
024: import org.openharmonise.him.editors.report.swing.*;
025: import org.openharmonise.him.harmonise.*;
026: import org.openharmonise.vfs.metadata.*;
027: import org.openharmonise.vfs.metadata.range.*;
028: import org.openharmonise.vfs.servers.ServerList;
029:
030: /**
031: * Panel for the workflow stage field in the report query editor.
032: *
033: * @author Matthew Large
034: * @version $Revision: 1.2 $
035: *
036: */
037: public class WorkflowStagePanel extends JPanel implements
038: LayoutManager, ActionListener {
039:
040: /**
041: * Report query.
042: */
043: private ReportQuery m_reportQuery = null;
044:
045: /**
046: * Workflow stage.
047: */
048: private WorkflowStage m_stage = null;
049:
050: /**
051: * Workflow selector.
052: */
053: private JComboTree m_workflowCombo = null;
054:
055: /**
056: * Workflow stage selector.
057: */
058: private JComboTree m_workflowStageCombo = null;
059:
060: private JLabel m_propLabel = null;
061:
062: private JLabel m_valLabel = null;
063:
064: private JComboBox m_completedCombo = null;
065:
066: private JLabel m_completedLabel = null;
067:
068: /**
069: * Constructs a new workflow stage panel.
070: *
071: * @param query Report query
072: * @param stage Workflow stage
073: */
074: public WorkflowStagePanel(ReportQuery query, WorkflowStage stage) {
075: super ();
076: this .m_stage = stage;
077: this .m_reportQuery = query;
078: this .setup();
079: }
080:
081: /**
082: * Configures this component.
083: *
084: */
085: private void setup() {
086: this .setLayout(this );
087: String fontName = "Dialog";
088: int fontSize = 11;
089: Font font = new Font(fontName, Font.PLAIN, fontSize);
090:
091: this .m_workflowCombo = new JComboTree();
092: this .m_workflowCombo.setActionCommand("WRKFLOW");
093: this .m_workflowCombo.addActionListener(this );
094: this .m_workflowCombo
095: .addCollectionPath(HarmonisePaths.PATH_WORKFLOW_PROPS);
096: this .m_workflowCombo.setAllowClear(false);
097: this .m_workflowCombo.setShowLeafNodes(true);
098: this .m_workflowCombo.setSelectedLeafOnly(true);
099:
100: if (this .m_stage.getPath() != null) {
101: this .m_workflowCombo.setPath(ServerList.getInstance()
102: .getHarmoniseServer().getVFS(), this .m_stage
103: .getPath());
104: }
105:
106: this .add(m_workflowCombo);
107:
108: this .m_workflowStageCombo = new JComboTree();
109: this .m_workflowStageCombo.setActionCommand("STAGE");
110: this .m_workflowStageCombo.setAllowClear(false);
111: this .m_workflowStageCombo.setShowLeafNodes(true);
112: this .m_workflowStageCombo.setSelectedLeafOnly(true);
113: this .m_workflowStageCombo.addActionListener(this );
114:
115: String[] sData = new String[] { "Yes", "No" };
116: this .m_completedCombo = new JComboBox(sData);
117: this .m_completedCombo.addActionListener(this );
118: this .m_completedCombo.setActionCommand("COMPLETED");
119: this .m_completedCombo.setBackground(Color.WHITE);
120: this .m_completedCombo.setFont(font);
121: if (m_stage.isCompleted()) {
122: this .m_completedCombo.setSelectedItem("Yes");
123: } else {
124: this .m_completedCombo.setSelectedItem("No");
125: }
126: this .add(m_completedCombo);
127:
128: if (this .m_stage.getPath() != null
129: && this .m_stage.getStagePath() != null) {
130: String sWorkflowPath = this .m_workflowCombo.getPath();
131: Property workflowProp = PropertyCache.getInstance()
132: .getPropertyByPath(sWorkflowPath);
133: Range range = workflowProp.getRange();
134: String sStagesPath = (String) ((ResourceRange) range)
135: .getHREFs().get(0);
136: this .m_workflowStageCombo.addCollectionPath(sStagesPath);
137:
138: this .m_workflowStageCombo.setPath(ServerList.getInstance()
139: .getHarmoniseServer().getVFS(), this .m_stage
140: .getStagePath());
141:
142: this .add(this .m_workflowStageCombo);
143: }
144:
145: this .m_propLabel = new JLabel("Select a workflow");
146: this .m_propLabel.setFont(font);
147: this .add(this .m_propLabel);
148:
149: this .m_valLabel = new JLabel("Select a stage");
150: this .m_valLabel.setFont(font);
151: this .add(this .m_valLabel);
152:
153: this .m_completedLabel = new JLabel("Completed");
154: this .m_completedLabel.setFont(font);
155: this .add(m_completedLabel);
156: }
157:
158: /**
159: * Returns the workflow stage.
160: *
161: * @return Workflow stage
162: */
163: public WorkflowStage getStage() {
164: return this .m_stage;
165: }
166:
167: /* (non-Javadoc)
168: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
169: */
170: public void layoutContainer(Container arg0) {
171: int nWidth = 0;
172:
173: this .m_propLabel.setSize(this .m_propLabel.getPreferredSize());
174: this .m_propLabel.setLocation(nWidth, 0);
175:
176: this .m_workflowCombo.setSize(this .m_workflowCombo
177: .getPreferredSize());
178: this .m_workflowCombo.setLocation(nWidth, 15);
179:
180: nWidth += this .m_workflowCombo.getSize().width + 20;
181:
182: if (this .m_workflowStageCombo.getParent() != null
183: && this .m_workflowStageCombo.getParent() == this ) {
184: this .m_valLabel.setSize(this .m_valLabel.getPreferredSize());
185: this .m_valLabel.setLocation(nWidth, 0);
186:
187: this .m_workflowStageCombo.setSize(this .m_workflowStageCombo
188: .getPreferredSize());
189: this .m_workflowStageCombo.setLocation(nWidth, 15);
190:
191: nWidth += this .m_workflowStageCombo.getSize().width + 10;
192:
193: this .m_completedLabel.setSize(m_completedLabel
194: .getPreferredSize());
195: this .m_completedLabel.setLocation(nWidth, 0);
196:
197: this .m_completedCombo.setSize(this .m_completedCombo
198: .getPreferredSize());
199: this .m_completedCombo.setLocation(nWidth, 15);
200: }
201: }
202:
203: /* (non-Javadoc)
204: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
205: */
206: public void actionPerformed(ActionEvent ae) {
207: if (ae.getActionCommand().equals("WRKFLOW")) {
208: this .remove(this .m_workflowStageCombo);
209:
210: String sWorkflowPath = this .m_workflowCombo.getPath();
211: Property workflowProp = PropertyCache.getInstance()
212: .getPropertyByPath(sWorkflowPath);
213: Range range = workflowProp.getRange();
214: if (range != null && range instanceof ResourceRange) {
215: this .m_workflowStageCombo = new JComboTree();
216: this .m_workflowStageCombo.setActionCommand("STAGE");
217: this .m_workflowStageCombo.addActionListener(this );
218: this .m_workflowStageCombo.setAllowClear(false);
219: this .m_workflowStageCombo.setShowLeafNodes(true);
220: this .m_workflowStageCombo.setSelectedLeafOnly(true);
221:
222: String sStagesPath = (String) ((ResourceRange) range)
223: .getHREFs().get(0);
224: this .m_workflowStageCombo
225: .addCollectionPath(sStagesPath);
226:
227: this .add(this .m_workflowStageCombo);
228: this .m_stage.setPath(sWorkflowPath);
229: }
230: } else if (ae.getActionCommand().equals("STAGE")) {
231: String sStagePath = this .m_workflowStageCombo.getPath();
232: this .m_stage.setStagePath(sStagePath);
233: } else if (ae.getActionCommand().equals("COMPLETED")) {
234: String sCompleted = (String) this .m_completedCombo
235: .getSelectedItem();
236: if (sCompleted.equals("Yes")) {
237: this .m_stage.setCompleted(true);
238: } else {
239: this .m_stage.setCompleted(false);
240: }
241: }
242: }
243:
244: /* (non-Javadoc)
245: * @see java.awt.Component#getPreferredSize()
246: */
247: public Dimension getPreferredSize() {
248: return new Dimension(430, 35);
249: }
250:
251: /**
252: *
253: */
254: private WorkflowStagePanel() {
255: super ();
256: }
257:
258: /**
259: * @param arg0
260: */
261: private WorkflowStagePanel(boolean arg0) {
262: super (arg0);
263: }
264:
265: /**
266: * @param arg0
267: */
268: private WorkflowStagePanel(LayoutManager arg0) {
269: super (arg0);
270: }
271:
272: /**
273: * @param arg0
274: * @param arg1
275: */
276: private WorkflowStagePanel(LayoutManager arg0, boolean arg1) {
277: super (arg0, arg1);
278: }
279:
280: /* (non-Javadoc)
281: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
282: */
283: public void removeLayoutComponent(Component arg0) {
284: }
285:
286: /* (non-Javadoc)
287: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
288: */
289: public void addLayoutComponent(String arg0, Component arg1) {
290: }
291:
292: /* (non-Javadoc)
293: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
294: */
295: public Dimension minimumLayoutSize(Container arg0) {
296: return this .getPreferredSize();
297: }
298:
299: /* (non-Javadoc)
300: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
301: */
302: public Dimension preferredLayoutSize(Container arg0) {
303: return this.getPreferredSize();
304: }
305:
306: }
|