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.beans.PropertyVetoException;
054: import java.util.StringTokenizer;
055: import javax.swing.*;
056: import org.apache.commons.logging.Log;
057: import org.apache.commons.logging.LogFactory;
058: import org.obe.xpdl.model.misc.PublicationStatus;
059: import org.obe.xpdl.model.misc.RedefinableHeader;
060:
061: public class RedefinableHeaderPanel extends JPanel {
062:
063: public static final String RESPONSIBLES_SEPARATOR = ",";
064:
065: private static final Log log = LogFactory
066: .getLog(RedefinableHeader.class);
067:
068: private RedefinableHeader redefinableHeader;
069:
070: private JLabel authorLabel;
071: private JTextField authorField;
072: private JLabel versionLabel;
073: private JTextField versionField;
074: private JLabel codepageLabel;
075: private JTextField codepageField;
076: private JLabel countrykeyLabel;
077: private JTextField countrykeyField;
078: private JLabel responsiblesLabel;
079: private JTextField responsiblesField;
080: private JLabel publicationStatusLabel;
081: private JComboBox publicationStatusComboBox;
082:
083: public RedefinableHeaderPanel() {
084: init();
085: redefinableHeader = new RedefinableHeader();
086: revert();
087: }
088:
089: public RedefinableHeader getRedefinableHeader() {
090: return redefinableHeader;
091: }
092:
093: public void setRedefinableHeader(RedefinableHeader redefinableHeader) {
094: if (redefinableHeader == null) {
095: log.info("Constructing new RedefinableHeader.");
096: this .redefinableHeader = new RedefinableHeader();
097: } else {
098: this .redefinableHeader = redefinableHeader;
099: }
100: revert();
101: }
102:
103: public boolean save() throws PropertyVetoException {
104: redefinableHeader.setAuthor(authorField.getText());
105: redefinableHeader.setVersion(versionField.getText());
106: redefinableHeader.setCodepage(codepageField.getText());
107: redefinableHeader.setCountrykey(countrykeyField.getText());
108: redefinableHeader
109: .setPublicationStatus((PublicationStatus) publicationStatusComboBox
110: .getSelectedItem());
111:
112: // convert a String to a list of responsibles
113: StringTokenizer tk = new StringTokenizer(responsiblesField
114: .getText(), RESPONSIBLES_SEPARATOR);
115: redefinableHeader.clear(RedefinableHeader.RESPONSIBLE);
116: while (tk.hasMoreTokens())
117: redefinableHeader.add(tk.nextToken().trim());
118:
119: return true;
120: }
121:
122: public void revert() {
123: if (redefinableHeader == null) {
124: return;
125: }
126:
127: String author = redefinableHeader.getAuthor();
128: if (author != null) {
129: authorField.setText(author);
130: }
131:
132: String version = redefinableHeader.getVersion();
133: if (version != null) {
134: versionField.setText(version);
135: }
136:
137: String codepage = redefinableHeader.getCodepage();
138: if (codepage != null) {
139: codepageField.setText(codepage);
140: }
141:
142: String countrykey = redefinableHeader.getCountrykey();
143: if (countrykey != null) {
144: countrykeyField.setText(countrykey);
145: }
146:
147: PublicationStatus publicationStatus = redefinableHeader
148: .getPublicationStatus();
149: if (publicationStatus != null) {
150: publicationStatusComboBox
151: .setSelectedItem(publicationStatus);
152: }
153:
154: StringBuffer buffer = new StringBuffer();
155: String[] responsibles = redefinableHeader.getResponsible();
156: for (int i = 0, n = responsibles.length; i < n; i++) {
157: buffer.append(responsibles[i]);
158: if (i < n - 1)
159: buffer.append(',');
160: }
161: responsiblesField.setText(buffer.toString());
162: }
163:
164: private void init() {
165: GridBagLayout gbl = new GridBagLayout();
166: GridBagConstraints gbc = new GridBagConstraints();
167: setLayout(gbl);
168:
169: gbc.insets = new Insets(2, 2, 2, 2);
170: gbc.anchor = GridBagConstraints.WEST;
171: gbc.fill = GridBagConstraints.HORIZONTAL;
172:
173: authorLabel = new JLabel("Author");
174: gbc.weightx = 0;
175: gbc.gridwidth = 1;
176: gbl.setConstraints(authorLabel, gbc);
177: add(authorLabel);
178:
179: authorField = new JTextField();
180: gbc.weightx = 1;
181: gbc.gridwidth = GridBagConstraints.REMAINDER;
182: gbl.setConstraints(authorField, gbc);
183: add(authorField);
184:
185: versionLabel = new JLabel("Version");
186: gbc.weightx = 0;
187: gbc.gridwidth = 1;
188: gbl.setConstraints(versionLabel, gbc);
189: add(versionLabel);
190:
191: versionField = new JTextField();
192: gbc.weightx = 1;
193: gbc.gridwidth = GridBagConstraints.REMAINDER;
194: gbl.setConstraints(versionField, gbc);
195: add(versionField);
196:
197: codepageLabel = new JLabel("Codepage");
198: gbc.weightx = 0;
199: gbc.gridwidth = 1;
200: gbl.setConstraints(codepageLabel, gbc);
201: add(codepageLabel);
202:
203: codepageField = new JTextField();
204: gbc.weightx = 1;
205: gbc.gridwidth = GridBagConstraints.REMAINDER;
206: gbl.setConstraints(codepageField, gbc);
207: add(codepageField);
208:
209: countrykeyLabel = new JLabel("Country Key");
210: gbc.weightx = 0;
211: gbc.gridwidth = 1;
212: gbl.setConstraints(countrykeyLabel, gbc);
213: add(countrykeyLabel);
214:
215: countrykeyField = new JTextField();
216: gbc.weightx = 1;
217: gbc.gridwidth = GridBagConstraints.REMAINDER;
218: gbl.setConstraints(countrykeyField, gbc);
219: add(countrykeyField);
220:
221: responsiblesLabel = new JLabel("Responsibles");
222: gbc.weightx = 0;
223: gbc.gridwidth = 1;
224: gbl.setConstraints(responsiblesLabel, gbc);
225: add(responsiblesLabel);
226:
227: responsiblesField = new JTextField();
228: gbc.weightx = 1;
229: gbc.gridwidth = GridBagConstraints.REMAINDER;
230: gbl.setConstraints(responsiblesField, gbc);
231: add(responsiblesField);
232:
233: publicationStatusLabel = new JLabel("Publication Status");
234: gbc.weightx = 0;
235: gbc.gridwidth = 1;
236: gbl.setConstraints(publicationStatusLabel, gbc);
237: add(publicationStatusLabel);
238:
239: publicationStatusComboBox = new JComboBox(
240: PublicationStatus.VALUES.toArray());
241: gbc.weightx = 1;
242: gbc.gridwidth = GridBagConstraints.REMAINDER;
243: gbl.setConstraints(publicationStatusComboBox, gbc);
244: add(publicationStatusComboBox);
245:
246: /*
247: JPanel p = new JPanel();
248: gbc.weighty = 1;
249: gbl.setConstraints(p, gbc);
250: add(p);
251: */
252: }
253:
254: }
|