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.dialog;
051:
052: import java.awt.*;
053: import java.awt.event.ActionEvent;
054: import java.awt.event.ActionListener;
055: import java.beans.PropertyVetoException;
056: import java.text.ParseException;
057: import javax.swing.*;
058: import org.apache.commons.logging.Log;
059: import org.apache.commons.logging.LogFactory;
060: import org.obe.designer.editor.EntityEditor;
061: import org.obe.designer.panel.*;
062: import org.obe.util.ErrorHandler;
063: import org.obe.xpdl.model.workflow.WorkflowProcess;
064:
065: public class EditWorkflowProcessDialog extends JDialog {
066: public static final int APPROVE_OPTION = 3;
067: public static final int CANCEL_OPTION = 2;
068: private static final Log log = LogFactory
069: .getLog(NewWorkflowProcessDialog.class);
070:
071: private ApplicationSelectorPanel applicationSelectorPanel;
072: private JButton cancelButton;
073: private DataFieldSelectorPanel dataFieldSelectorPanel;
074: private EntityEditor entityEditor;
075: private JButton okButton;
076: private ParticipantSelectorPanel participantSelectorPanel;
077: private ProcessHeaderPanel processHeaderPanel;
078: private RedefinableHeaderPanel redefinableHeaderPanel;
079: private int result = CANCEL_OPTION;
080: private JTabbedPane tabbedPane;
081: private WorkflowProcess workflowProcess;
082:
083: public EditWorkflowProcessDialog() {
084: init();
085: }
086:
087: public EditWorkflowProcessDialog(WorkflowProcess workflowProcess) {
088: init();
089: setWorkflowProcess(workflowProcess);
090: }
091:
092: public void close() {
093: dispose();
094: }
095:
096: private JPanel createButtonPanel() {
097: JPanel panel = new JPanel();
098:
099: okButton = new JButton("OK");
100: okButton.addActionListener(new ActionListener() {
101: public void actionPerformed(ActionEvent evt) {
102: try {
103: if (save()) {
104: result = APPROVE_OPTION;
105: close();
106: }
107: } catch (Exception e) {
108: ErrorHandler.handleError(e);
109: }
110: }
111: });
112: panel.add(okButton);
113:
114: cancelButton = new JButton("Cancel");
115: cancelButton.addActionListener(new ActionListener() {
116: public void actionPerformed(ActionEvent evt) {
117: result = CANCEL_OPTION;
118: close();
119: }
120: });
121: panel.add(cancelButton);
122:
123: return panel;
124: }
125:
126: public WorkflowProcess getWorkflowProcess() {
127: return workflowProcess;
128: }
129:
130: private void init() {
131: setModal(true);
132:
133: entityEditor = new EntityEditor();
134: processHeaderPanel = new ProcessHeaderPanel();
135: redefinableHeaderPanel = new RedefinableHeaderPanel();
136: participantSelectorPanel = new ParticipantSelectorPanel();
137: applicationSelectorPanel = new ApplicationSelectorPanel();
138: dataFieldSelectorPanel = new DataFieldSelectorPanel();
139:
140: tabbedPane = new JTabbedPane();
141: tabbedPane.add("General", new JScrollPane(entityEditor));
142: tabbedPane.add("Header", new JScrollPane(processHeaderPanel));
143: tabbedPane.add("Properties", new JScrollPane(
144: redefinableHeaderPanel));
145: tabbedPane.add("Participants", new JScrollPane(
146: participantSelectorPanel));
147: tabbedPane.add("Applications", new JScrollPane(
148: applicationSelectorPanel));
149: tabbedPane.add("Data Fields", new JScrollPane(
150: dataFieldSelectorPanel));
151:
152: getContentPane().setLayout(new BorderLayout());
153: getContentPane().add(tabbedPane, BorderLayout.CENTER);
154: getContentPane().add(createButtonPanel(), BorderLayout.SOUTH);
155:
156: getRootPane().setDefaultButton(okButton);
157:
158: setTitle("New Workflow Process");
159: pack();
160: }
161:
162: public void revert() {
163: entityEditor.revert();
164: processHeaderPanel.revert();
165: redefinableHeaderPanel.revert();
166: }
167:
168: public boolean save() throws PropertyVetoException, ParseException {
169: if (!processHeaderPanel.save())
170: return false;
171: if (!redefinableHeaderPanel.save())
172: return false;
173: if (!entityEditor.save())
174: return false;
175:
176: workflowProcess.setRedefinableHeader(redefinableHeaderPanel
177: .getRedefinableHeader());
178:
179: return true;
180: }
181:
182: public void setWorkflowProcess(WorkflowProcess workflowProcess) {
183: this .workflowProcess = workflowProcess;
184: entityEditor.setElement(workflowProcess);
185: processHeaderPanel.setProcessHeader(workflowProcess
186: .getProcessHeader());
187: redefinableHeaderPanel.setRedefinableHeader(workflowProcess
188: .getRedefinableHeader());
189: participantSelectorPanel.setResourceContainer(workflowProcess);
190: applicationSelectorPanel.setResourceContainer(workflowProcess);
191: dataFieldSelectorPanel.setResourceContainer(workflowProcess);
192: }
193:
194: public int showDialog() {
195: setVisible(true);
196: return result;
197: }
198: }
|