001: /*
002: * argun 1.0
003: * Web 2.0 delivery framework
004: * Copyright (C) 2007 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.biz
021: * e-Mail: support@hammurapi.biz
022: */
023: package biz.hammurapi.web.process;
024:
025: import java.awt.GridBagConstraints;
026: import java.awt.GridBagLayout;
027: import java.awt.Insets;
028: import java.awt.event.ActionEvent;
029: import java.awt.event.ActionListener;
030:
031: import javax.swing.JButton;
032: import javax.swing.JEditorPane;
033: import javax.swing.JFrame;
034: import javax.swing.JLabel;
035: import javax.swing.JOptionPane;
036: import javax.swing.JScrollPane;
037: import javax.swing.JTabbedPane;
038: import javax.swing.JTextArea;
039: import javax.swing.JTextField;
040: import javax.swing.JTextPane;
041:
042: /**
043: * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
044: * Builder, which is free for non-commercial use. If Jigloo is being used
045: * commercially (ie, by a corporation, company or business for any purpose
046: * whatever) then you should purchase a license for each developer using Jigloo.
047: * Please visit www.cloudgarden.com for details. Use of Jigloo implies
048: * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
049: * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
050: * ANY CORPORATE OR COMMERCIAL PURPOSE.
051: */
052: public class ProcessElementPropertiesDialog extends javax.swing.JDialog {
053: private JButton okButton;
054:
055: private JButton cancelButton;
056:
057: private JTextArea actionTextArea;
058:
059: private JScrollPane actionScrollPane;
060:
061: private JTextArea guardTextArea;
062:
063: private JScrollPane guardScrollPane;
064:
065: private JLabel nameLabel;
066:
067: private JEditorPane summaryEditorPane;
068:
069: private JScrollPane summaryScrollPane;
070:
071: private JTabbedPane tabbedPanel;
072:
073: private JTextField nameField;
074:
075: private ProcessElement data;
076:
077: /**
078: * Auto-generated main method to display this JDialog
079: */
080: public static void main(String[] args) {
081: JFrame frame = new JFrame();
082: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
083: ProcessElementPropertiesDialog inst = new ProcessElementPropertiesDialog(
084: frame, null);
085: inst.setVisible(true);
086: frame.dispose();
087: //System.exit(0);
088: }
089:
090: public ProcessElementPropertiesDialog(JFrame frame,
091: ProcessElement data) {
092: super (frame);
093: this .data = data;
094: initGUI();
095: nameField.setText(data.getName());
096: summaryEditorPane.setText(data.getSummary());
097: actionTextArea.setText(data.getAction());
098: guardTextArea.setText(data.getGuard());
099: }
100:
101: private void initGUI() {
102: try {
103: GridBagLayout this Layout = new GridBagLayout();
104: this Layout.rowWeights = new double[] { 0.0, 0.1, 0.0 };
105: this Layout.rowHeights = new int[] { 32, 303, 7 };
106: this Layout.columnWeights = new double[] { 0.0, 0.1, 0.0 };
107: this Layout.columnWidths = new int[] { 45, 354, 7 };
108: getContentPane().setLayout(this Layout);
109: this .setName("Properties");
110: this .setModal(true);
111: this .setTitle("Properties");
112: {
113: nameField = new JTextField();
114: getContentPane().add(
115: nameField,
116: new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0,
117: GridBagConstraints.WEST,
118: GridBagConstraints.HORIZONTAL,
119: new Insets(0, 0, 0, 0), 0, 0));
120: nameField.setText("Task name");
121: nameField.setSize(200, 20);
122: }
123: {
124: okButton = new JButton();
125: getContentPane().add(
126: okButton,
127: new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
128: GridBagConstraints.EAST,
129: GridBagConstraints.NONE, new Insets(3,
130: 0, 3, 3), 0, 0));
131: okButton.setText("OK");
132: okButton.addActionListener(new ActionListener() {
133: public void actionPerformed(ActionEvent evt) {
134: okButtonActionPerformed(evt);
135: }
136: });
137: }
138: {
139: cancelButton = new JButton();
140: getContentPane().add(
141: cancelButton,
142: new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0,
143: GridBagConstraints.WEST,
144: GridBagConstraints.NONE, new Insets(3,
145: 0, 3, 3), 0, 0));
146: cancelButton.setText("Cancel");
147: cancelButton.addActionListener(new ActionListener() {
148: public void actionPerformed(ActionEvent evt) {
149: cancelButtonActionPerformed(evt);
150: }
151: });
152: }
153: {
154: tabbedPanel = new JTabbedPane();
155: getContentPane().add(
156: tabbedPanel,
157: new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0,
158: GridBagConstraints.NORTHWEST,
159: GridBagConstraints.BOTH, new Insets(0,
160: 0, 0, 0), 0, 0));
161: {
162: summaryScrollPane = new JScrollPane();
163: tabbedPanel.addTab("Summary", null,
164: summaryScrollPane, null);
165: summaryScrollPane
166: .setPreferredSize(new java.awt.Dimension(
167: 360, 159));
168: summaryScrollPane.setAutoscrolls(true);
169: {
170: summaryEditorPane = new JTextPane();
171: summaryScrollPane
172: .setViewportView(summaryEditorPane);
173: summaryEditorPane.setText("Summary");
174: summaryEditorPane
175: .setPreferredSize(new java.awt.Dimension(
176: 185, 74));
177: }
178: }
179: {
180: guardScrollPane = new JScrollPane();
181: tabbedPanel.addTab("Guard", null, guardScrollPane,
182: null);
183: {
184: guardTextArea = new JTextArea();
185: guardScrollPane.setViewportView(guardTextArea);
186: guardTextArea
187: .setText("// Put condition code here");
188: guardTextArea.setFont(new java.awt.Font(
189: "Courier New", 0, 11));
190: guardTextArea.setTabSize(4);
191: }
192: }
193: {
194: actionScrollPane = new JScrollPane();
195: tabbedPanel.addTab("Action", null,
196: actionScrollPane, null);
197: {
198: actionTextArea = new JTextArea();
199: actionScrollPane
200: .setViewportView(actionTextArea);
201: actionTextArea
202: .setText("// Put action code here");
203: actionTextArea.setFont(new java.awt.Font(
204: "Courier New", 0, 11));
205: actionTextArea.setTabSize(4);
206: }
207: }
208: }
209: {
210: nameLabel = new JLabel();
211: getContentPane().add(
212: nameLabel,
213: new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
214: GridBagConstraints.CENTER,
215: GridBagConstraints.NONE, new Insets(0,
216: 0, 0, 5), 0, 0));
217: nameLabel.setText("Name");
218: }
219: this .setSize(500, 400);
220: } catch (Exception e) {
221: e.printStackTrace();
222: }
223: }
224:
225: public static boolean compareStrings(String str1, String str2) {
226: if (str1 == str2) {
227: return true;
228: }
229: if (str1 == null || str1.trim().length() == 0) {
230: return str2 == null || str2.trim().length() == 0;
231: }
232:
233: return str1.equals(str2);
234: }
235:
236: private void okButtonActionPerformed(ActionEvent evt) {
237: if (data instanceof Task) {
238: if (nameField.getText() == null
239: || nameField.getText().trim().length() == 0) {
240: JOptionPane.showMessageDialog(this ,
241: "Task name shall not be blank");
242: return;
243: } else if (!compareStrings(nameField.getText(), data
244: .getName())
245: && data.getProcess().checkDuplicateTaskName(
246: nameField.getText())) {
247:
248: JOptionPane.showMessageDialog(this ,
249: "Duplicate task name");
250: return;
251: }
252: }
253:
254: data.setName(nameField.getText());
255: data.setSummary(summaryEditorPane.getText());
256: data.setAction(actionTextArea.getText());
257: data.setGuard(guardTextArea.getText());
258: data.getProcess().getApplet().modelChanged();
259: cancelButtonActionPerformed(evt);
260: }
261:
262: private void cancelButtonActionPerformed(ActionEvent evt) {
263: setVisible(false);
264: dispose();
265: }
266: }
|