001: /*--
002:
003: Copyright (C) 2002 Anthony Eden.
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: 1. Redistributions of source code must retain the above copyright
011: notice, this list of conditions, and the following disclaimer.
012:
013: 2. Redistributions in binary form must reproduce the above copyright
014: notice, this list of conditions, and the disclaimer that follows
015: these conditions in the documentation and/or other materials
016: provided with the distribution.
017:
018: 3. The names "OBE" and "Open Business Engine" must not be used to
019: endorse or promote products derived from this software without prior
020: written permission. For written permission, please contact
021: me@anthonyeden.com.
022:
023: 4. Products derived from this software may not be called "OBE" or
024: "Open Business Engine", nor may "OBE" or "Open Business Engine"
025: appear in their name, without prior written permission from
026: Anthony Eden (me@anthonyeden.com).
027:
028: In addition, I request (but do not require) that you include in the
029: end-user documentation provided with the redistribution and/or in the
030: software itself an acknowledgement equivalent to the following:
031: "This product includes software developed by
032: Anthony Eden (http://www.anthonyeden.com/)."
033:
034: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
038: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
039: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
040: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
041: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
042: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
043: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
044: POSSIBILITY OF SUCH DAMAGE.
045:
046: For more information on OBE, please see <http://obe.sourceforge.net/>.
047:
048: */
049:
050: package org.obe.designer.panel;
051:
052: import java.awt.*;
053: import java.text.ParseException;
054: import java.util.Date;
055: import javax.swing.*;
056: import org.obe.util.DateUtilities;
057: import org.obe.xpdl.model.misc.Duration;
058: import org.obe.xpdl.model.workflow.ProcessHeader;
059:
060: public class ProcessHeaderPanel extends JPanel {
061: private static final DateUtilities dateUtil = DateUtilities
062: .getInstance();
063:
064: private ProcessHeader processHeader;
065: private JLabel createdLabel;
066: private JTextField createdField;
067: private JLabel priorityLabel;
068: private JTextField priorityField;
069: private JLabel limitLabel;
070: private JTextField limitField;
071: private JLabel validFromLabel;
072: private JTextField validFromField;
073: private JLabel validToLabel;
074: private JTextField validToField;
075: private TimeEstimationPanel timeEstimationPanel;
076:
077: public ProcessHeaderPanel() {
078: init();
079: processHeader = new ProcessHeader();
080: processHeader.setCreated(new Date());
081: revert();
082: }
083:
084: public ProcessHeader getProcessHeader() {
085: return processHeader;
086: }
087:
088: public void setProcessHeader(ProcessHeader processHeader) {
089: this .processHeader = processHeader;
090: revert();
091: }
092:
093: public boolean save() throws ParseException {
094: processHeader.setPriority(priorityField.getText());
095: processHeader.setLimit(Duration.valueOf(limitField.getText()));
096: processHeader.setValidFrom(dateUtil.parse(validFromField
097: .getText()));
098: processHeader
099: .setValidTo(dateUtil.parse(validToField.getText()));
100:
101: if (!timeEstimationPanel.save()) {
102: return false;
103: } else {
104: processHeader.setTimeEstimation(timeEstimationPanel
105: .getTimeEstimation());
106: }
107:
108: return true;
109: }
110:
111: public void revert() {
112: Date created = processHeader.getCreated();
113: if (created != null)
114: createdField.setText(dateUtil.format(created));
115:
116: priorityField.setText(processHeader.getPriority());
117:
118: Duration limit = processHeader.getLimit();
119: if (limit != null) {
120: limitField.setText(limit.toString());
121: }
122:
123: Date validFrom = processHeader.getValidFrom();
124: if (validFrom != null)
125: validFromField.setText(dateUtil.format(validFrom));
126:
127: Date validTo = processHeader.getValidTo();
128: if (validTo != null)
129: validToField.setText(dateUtil.format(validTo));
130:
131: timeEstimationPanel.setTimeEstimation(processHeader
132: .getTimeEstimation());
133: }
134:
135: private void init() {
136: GridBagLayout gbl = new GridBagLayout();
137: GridBagConstraints gbc = new GridBagConstraints();
138: setLayout(gbl);
139:
140: gbc.insets = new Insets(2, 2, 2, 2);
141: gbc.anchor = GridBagConstraints.WEST;
142: gbc.fill = GridBagConstraints.HORIZONTAL;
143:
144: createdLabel = new JLabel("Created");
145: gbc.weightx = 0;
146: gbc.gridwidth = 1;
147: gbl.setConstraints(createdLabel, gbc);
148: add(createdLabel);
149:
150: createdField = new JTextField();
151: createdField.setEditable(false);
152: gbc.weightx = 1;
153: gbc.gridwidth = GridBagConstraints.REMAINDER;
154: gbl.setConstraints(createdField, gbc);
155: add(createdField);
156:
157: priorityLabel = new JLabel("Priority");
158: gbc.weightx = 0;
159: gbc.gridwidth = 1;
160: gbl.setConstraints(priorityLabel, gbc);
161: add(priorityLabel);
162:
163: priorityField = new JTextField();
164: gbc.weightx = 1;
165: gbc.gridwidth = GridBagConstraints.REMAINDER;
166: gbl.setConstraints(priorityField, gbc);
167: add(priorityField);
168:
169: limitLabel = new JLabel("Limit");
170: gbc.weightx = 0;
171: gbc.gridwidth = 1;
172: gbl.setConstraints(limitLabel, gbc);
173: add(limitLabel);
174:
175: limitField = new JTextField();
176: gbc.weightx = 1;
177: gbc.gridwidth = GridBagConstraints.REMAINDER;
178: gbl.setConstraints(limitField, gbc);
179: add(limitField);
180:
181: validFromLabel = new JLabel("Valid From");
182: gbc.weightx = 0;
183: gbc.gridwidth = 1;
184: gbl.setConstraints(validFromLabel, gbc);
185: add(validFromLabel);
186:
187: validFromField = new JTextField();
188: gbc.weightx = 1;
189: gbc.gridwidth = GridBagConstraints.REMAINDER;
190: gbl.setConstraints(validFromField, gbc);
191: add(validFromField);
192:
193: validToLabel = new JLabel("Valid To");
194: gbc.weightx = 0;
195: gbc.gridwidth = 1;
196: gbl.setConstraints(validToLabel, gbc);
197: add(validToLabel);
198:
199: validToField = new JTextField();
200: gbc.weightx = 1;
201: gbc.gridwidth = GridBagConstraints.REMAINDER;
202: gbl.setConstraints(validToField, gbc);
203: add(validToField);
204:
205: timeEstimationPanel = new TimeEstimationPanel();
206: timeEstimationPanel.setBorder(BorderFactory
207: .createTitledBorder("Time Estimation"));
208: gbl.setConstraints(timeEstimationPanel, gbc);
209: add(timeEstimationPanel);
210:
211: JPanel p = new JPanel();
212: gbc.weighty = 1;
213: gbl.setConstraints(p, gbc);
214: add(p);
215: }
216:
217: }
|