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.awt.event.ActionEvent;
054: import java.awt.event.ActionListener;
055: import java.beans.PropertyVetoException;
056: import javax.swing.*;
057: import org.obe.designer.dialog.EditExternalPackageDialog;
058: import org.obe.designer.renderer.ExternalPackageListCellRenderer;
059: import org.obe.xpdl.model.pkg.ExternalPackage;
060: import org.obe.xpdl.model.pkg.XPDLPackage;
061: import org.obe.util.ErrorHandler;
062:
063: public class ExternalPackageSelectorPanel extends JPanel {
064:
065: private XPDLPackage pkg;
066:
067: private JList objectList;
068: // private WrappedListModel listModel;
069:
070: private JButton addButton;
071: private JButton editButton;
072: private JButton removeButton;
073:
074: public ExternalPackageSelectorPanel() {
075: init();
076: }
077:
078: public void setPackage(XPDLPackage pkg) {
079: this .pkg = pkg;
080: // listModel = new WrappedListModel(pkg);
081: objectList.setModel(pkg
082: .getListModel(XPDLPackage.EXTERNAL_PACKAGE));
083: }
084:
085: public void add() throws PropertyVetoException {
086: EditExternalPackageDialog d = new EditExternalPackageDialog();
087: d.setTitle("Add External Package");
088: if (d.showDialog() == EditExternalPackageDialog.APPROVE_OPTION) {
089: ExternalPackage externalPackage = d.getExternalPackage();
090: pkg.add(externalPackage);
091: // listModel.fireIntervalAdded(externalPackages.size(),
092: // externalPackages.size());
093: }
094: }
095:
096: public void edit() {
097: EditExternalPackageDialog d = new EditExternalPackageDialog();
098: d.setTitle("Edit External Package");
099: ExternalPackage externalPackage = getSelectedExternalPackage();
100: if (externalPackage != null) {
101: d.setExternalPackage(externalPackage);
102: d.showDialog();
103: }
104: }
105:
106: public void remove() {
107: }
108:
109: public ExternalPackage getSelectedExternalPackage() {
110: return (ExternalPackage) objectList.getSelectedValue();
111: }
112:
113: private void init() {
114: GridBagLayout gbl = new GridBagLayout();
115: GridBagConstraints gbc = new GridBagConstraints();
116: setLayout(gbl);
117:
118: gbc.insets = new Insets(1, 1, 1, 1);
119: gbc.fill = GridBagConstraints.BOTH;
120: gbc.anchor = GridBagConstraints.NORTHWEST;
121:
122: objectList = new JList();
123: objectList
124: .setCellRenderer(new ExternalPackageListCellRenderer());
125: JScrollPane scrollPane = new JScrollPane(objectList);
126: gbc.gridwidth = 1;
127: gbc.gridheight = 3;
128: gbc.weightx = 1;
129: gbc.weighty = 1;
130: gbl.setConstraints(scrollPane, gbc);
131: add(scrollPane);
132:
133: gbc.weightx = 0;
134: gbc.weighty = 0;
135: gbc.gridwidth = GridBagConstraints.REMAINDER;
136: gbc.gridheight = 1;
137: gbc.fill = GridBagConstraints.HORIZONTAL;
138:
139: addButton = new JButton("Add...");
140: addButton.addActionListener(new ActionListener() {
141: public void actionPerformed(ActionEvent evt) {
142: try {
143: add();
144: } catch (PropertyVetoException e) {
145: ErrorHandler.handleError(e);
146: }
147: }
148: });
149: gbl.setConstraints(addButton, gbc);
150: add(addButton);
151:
152: editButton = new JButton("Edit...");
153: editButton.addActionListener(new ActionListener() {
154: public void actionPerformed(ActionEvent evt) {
155: edit();
156: }
157: });
158: gbl.setConstraints(editButton, gbc);
159: add(editButton);
160:
161: removeButton = new JButton("Remove");
162: removeButton.addActionListener(new ActionListener() {
163: public void actionPerformed(ActionEvent evt) {
164: remove();
165: }
166: });
167: gbl.setConstraints(removeButton, gbc);
168: add(removeButton);
169: }
170:
171: }
|