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.util.List;
056: import javax.swing.*;
057: import javax.swing.event.ListDataListener;
058: import org.apache.commons.logging.Log;
059: import org.apache.commons.logging.LogFactory;
060: import org.obe.xpdl.model.pkg.XPDLPackage;
061: import org.obe.xpdl.model.workflow.WorkflowProcess;
062:
063: public class WorkflowProcessSelectorPanel extends JPanel {
064: private static final Log log = LogFactory
065: .getLog(WorkflowProcessSelectorPanel.class);
066:
067: private JList workflowProcessList;
068: // private JButton newButton;
069: private JButton detailsButton;
070:
071: public WorkflowProcessSelectorPanel() {
072: init();
073: }
074:
075: public void setWorkflowPackage(XPDLPackage workflowPackage) {
076: workflowProcessList.setModel(workflowPackage
077: .getListModel(XPDLPackage.WORKFLOW_PROCESS));
078: }
079:
080: public String getSelectedId() {
081: WorkflowProcess selectedProcess = (WorkflowProcess) workflowProcessList
082: .getSelectedValue();
083: if (selectedProcess == null) {
084: return null;
085: } else {
086: return selectedProcess.getId();
087: }
088: }
089:
090: public void setSelectedId(String id) {
091: ListModel listModel = workflowProcessList.getModel();
092: for (int i = 0; i < listModel.getSize(); i++) {
093: WorkflowProcess wp = (WorkflowProcess) listModel
094: .getElementAt(i);
095: if (wp.getId().equals(id)) {
096: workflowProcessList.setSelectedIndex(i);
097: return;
098: }
099: }
100: }
101:
102: private void init() {
103: GridBagLayout gbl = new GridBagLayout();
104: GridBagConstraints gbc = new GridBagConstraints();
105: setLayout(gbl);
106:
107: gbc.insets = new Insets(1, 1, 1, 1);
108: gbc.anchor = GridBagConstraints.NORTHWEST;
109:
110: workflowProcessList = new JList();
111: workflowProcessList
112: .setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
113: workflowProcessList
114: .setCellRenderer(new InternalListCellRenderer());
115: JScrollPane sp = new JScrollPane(workflowProcessList);
116: gbc.weightx = 1;
117: gbc.weighty = 1;
118: gbc.gridwidth = 1;
119: gbc.gridheight = 1;
120: gbc.fill = GridBagConstraints.BOTH;
121: gbl.setConstraints(sp, gbc);
122: add(sp);
123:
124: gbc.weightx = 0;
125: gbc.weighty = 0;
126: gbc.fill = GridBagConstraints.HORIZONTAL;
127: gbc.gridwidth = GridBagConstraints.REMAINDER;
128: gbc.gridheight = 1;
129:
130: detailsButton = new JButton("Details...");
131: detailsButton.addActionListener(new ActionListener() {
132: public void actionPerformed(ActionEvent evt) {
133:
134: }
135: });
136: gbl.setConstraints(detailsButton, gbc);
137: add(detailsButton);
138: }
139:
140: class WorkflowProcessListModel implements ListModel {
141:
142: WorkflowProcessListModel(List workflowProcesses) {
143: this .workflowProcesses = workflowProcesses;
144: }
145:
146: public int getSize() {
147: return workflowProcesses.size();
148: }
149:
150: public Object getElementAt(int index) {
151: return workflowProcesses.get(index);
152: }
153:
154: public void addListDataListener(ListDataListener l) {
155:
156: }
157:
158: public void removeListDataListener(ListDataListener l) {
159:
160: }
161:
162: private List workflowProcesses;
163:
164: }
165:
166: class InternalListCellRenderer extends DefaultListCellRenderer {
167:
168: public Component getListCellRendererComponent(JList list,
169: Object value, int index, boolean isSelected,
170: boolean cellHasFocus) {
171: return super .getListCellRendererComponent(list,
172: ((WorkflowProcess) value).getName(), index,
173: isSelected, cellHasFocus);
174: }
175:
176: }
177:
178: }
|