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 javax.swing.*;
057: import org.obe.designer.editor.EntityEditor;
058: import org.obe.designer.panel.*;
059: import org.obe.xpdl.model.pkg.XPDLPackage;
060: import org.obe.util.ErrorHandler;
061:
062: public class EditPackageDialog extends JDialog {
063:
064: public static final int APPROVE_OPTION = 1;
065: public static final int CANCEL_OPTION = 2;
066:
067: private int result = CANCEL_OPTION;
068:
069: private XPDLPackage workflowPackage;
070:
071: private JTabbedPane tabbedPane;
072: private EntityEditor entityEditor;
073: private PackageHeaderPanel packageHeaderPanel;
074: private RedefinableHeaderPanel redefinableHeaderPanel;
075: private ConformanceClassPanel conformanceClassPanel;
076: private ScriptPanel scriptPanel;
077: private ExternalPackageSelectorPanel externalPackageSelectorPanel;
078: private TypeDeclarationSelectorPanel typeDeclarationSelectorPanel;
079: private ParticipantSelectorPanel participantSelectorPanel;
080: private ApplicationSelectorPanel applicationSelectorPanel;
081: private DataFieldSelectorPanel dataFieldSelectorPanel;
082:
083: private JButton okButton;
084: private JButton cancelButton;
085:
086: public EditPackageDialog() {
087: init();
088: }
089:
090: public XPDLPackage getWorkflowPackage() {
091: return workflowPackage;
092: }
093:
094: public void setWorkflowPackage(XPDLPackage workflowPackage) {
095: this .workflowPackage = workflowPackage;
096: entityEditor.setElement(workflowPackage);
097: packageHeaderPanel.setPackageHeader(workflowPackage
098: .getPackageHeader());
099: redefinableHeaderPanel.setRedefinableHeader(workflowPackage
100: .getRedefinableHeader());
101: conformanceClassPanel.setConformanceClass(workflowPackage
102: .getConformanceClass());
103: scriptPanel.setScript(workflowPackage.getScript());
104:
105: externalPackageSelectorPanel.setPackage(workflowPackage);
106: typeDeclarationSelectorPanel.setPackage(workflowPackage);
107: participantSelectorPanel.setResourceContainer(workflowPackage);
108: applicationSelectorPanel.setResourceContainer(workflowPackage);
109: dataFieldSelectorPanel.setResourceContainer(workflowPackage);
110: }
111:
112: public boolean save() throws PropertyVetoException {
113: if (!entityEditor.save())
114: return false;
115: if (!packageHeaderPanel.save())
116: return false;
117: if (!redefinableHeaderPanel.save())
118: return false;
119: if (!conformanceClassPanel.save())
120: return false;
121: if (!scriptPanel.save())
122: return false;
123:
124: workflowPackage.setRedefinableHeader(redefinableHeaderPanel
125: .getRedefinableHeader());
126: workflowPackage.setConformanceClass(conformanceClassPanel
127: .getConformanceClass());
128: workflowPackage.setScript(scriptPanel.getScript());
129:
130: return true;
131: }
132:
133: public void revert() {
134: entityEditor.revert();
135: packageHeaderPanel.revert();
136: redefinableHeaderPanel.revert();
137: conformanceClassPanel.revert();
138: scriptPanel.revert();
139: }
140:
141: public int showDialog() {
142: setVisible(true);
143: return result;
144: }
145:
146: public void close() {
147: dispose();
148: }
149:
150: private void init() {
151: entityEditor = new EntityEditor();
152: packageHeaderPanel = new PackageHeaderPanel();
153: redefinableHeaderPanel = new RedefinableHeaderPanel();
154: conformanceClassPanel = new ConformanceClassPanel();
155: scriptPanel = new ScriptPanel();
156: externalPackageSelectorPanel = new ExternalPackageSelectorPanel();
157: typeDeclarationSelectorPanel = new TypeDeclarationSelectorPanel();
158: participantSelectorPanel = new ParticipantSelectorPanel();
159: applicationSelectorPanel = new ApplicationSelectorPanel();
160: dataFieldSelectorPanel = new DataFieldSelectorPanel();
161:
162: tabbedPane = new JTabbedPane();
163: tabbedPane
164: .add("General", new JScrollPane(createGeneralPanel()));
165: tabbedPane.add("External Packages", new JScrollPane(
166: externalPackageSelectorPanel));
167: tabbedPane.add("Type Declarations", new JScrollPane(
168: typeDeclarationSelectorPanel));
169: tabbedPane.add("Participants", new JScrollPane(
170: participantSelectorPanel));
171: tabbedPane.add("Applications", new JScrollPane(
172: applicationSelectorPanel));
173: tabbedPane.add("Data Fields", new JScrollPane(
174: dataFieldSelectorPanel));
175:
176: getContentPane().setLayout(new BorderLayout());
177: getContentPane().add(tabbedPane, BorderLayout.CENTER);
178: getContentPane().add(createButtonPanel(), BorderLayout.SOUTH);
179:
180: getRootPane().setDefaultButton(okButton);
181:
182: setTitle("Edit Package");
183: setModal(true);
184:
185: pack();
186: }
187:
188: private JPanel createButtonPanel() {
189: JPanel panel = new JPanel();
190:
191: okButton = new JButton("OK");
192: okButton.addActionListener(new ActionListener() {
193: public void actionPerformed(ActionEvent evt) {
194: try {
195: if (save()) {
196: result = APPROVE_OPTION;
197: close();
198: }
199: } catch (PropertyVetoException e) {
200: ErrorHandler.handleError(e);
201: }
202: }
203: });
204: panel.add(okButton);
205:
206: cancelButton = new JButton("Cancel");
207: cancelButton.addActionListener(new ActionListener() {
208: public void actionPerformed(ActionEvent evt) {
209: result = CANCEL_OPTION;
210: close();
211: }
212: });
213: panel.add(cancelButton);
214:
215: return panel;
216: }
217:
218: private JPanel createGeneralPanel() {
219: JPanel panel = new JPanel();
220:
221: GridBagLayout gbl = new GridBagLayout();
222: GridBagConstraints gbc = new GridBagConstraints();
223: panel.setLayout(gbl);
224:
225: gbc.insets = new Insets(1, 1, 1, 1);
226: gbc.fill = GridBagConstraints.HORIZONTAL;
227: gbc.weightx = 1;
228: gbc.gridwidth = GridBagConstraints.REMAINDER;
229:
230: entityEditor.setBorder(BorderFactory.createEtchedBorder());
231: gbl.setConstraints(entityEditor, gbc);
232: panel.add(entityEditor);
233:
234: packageHeaderPanel
235: .setBorder(BorderFactory.createEtchedBorder());
236: gbl.setConstraints(packageHeaderPanel, gbc);
237: panel.add(packageHeaderPanel);
238:
239: redefinableHeaderPanel.setBorder(BorderFactory
240: .createEtchedBorder());
241: gbl.setConstraints(redefinableHeaderPanel, gbc);
242: panel.add(redefinableHeaderPanel);
243:
244: conformanceClassPanel.setBorder(BorderFactory
245: .createEtchedBorder());
246: gbl.setConstraints(conformanceClassPanel, gbc);
247: panel.add(conformanceClassPanel);
248:
249: scriptPanel.setBorder(BorderFactory
250: .createTitledBorder("Script"));
251: gbl.setConstraints(scriptPanel, gbc);
252: panel.add(scriptPanel);
253:
254: JPanel p = new JPanel();
255: gbc.weighty = 1;
256: gbl.setConstraints(p, gbc);
257: panel.add(p);
258:
259: return panel;
260: }
261:
262: }
|