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;
051:
052: import java.awt.Point;
053: import java.awt.event.MouseEvent;
054: import java.awt.event.MouseAdapter;
055:
056: import javax.swing.JScrollPane;
057: import javax.swing.JTabbedPane;
058: import javax.swing.event.ListDataEvent;
059: import javax.swing.event.ListDataListener;
060:
061: import com.anthonyeden.lib.util.XArrayList;
062:
063: import org.apache.commons.logging.Log;
064: import org.apache.commons.logging.LogFactory;
065: import org.obe.xpdl.model.workflow.WorkflowProcess;
066:
067: public class OBETabbedPane extends JTabbedPane implements
068: ListDataListener {
069:
070: private static final Log log = LogFactory
071: .getLog(OBETabbedPane.class);
072:
073: private OBEDesigner parent;
074: private XArrayList workflowProcesses;
075: private XArrayList graphs;
076:
077: public OBETabbedPane(OBEDesigner parent) {
078: this .parent = parent;
079:
080: graphs = new XArrayList();
081:
082: workflowProcesses = new XArrayList();
083: workflowProcesses.addListDataListener(this );
084:
085: addMouseListener(new MouseAdapter() {
086: public void mousePressed(MouseEvent evt) {
087: if (evt.isPopupTrigger()) {
088: showPopup(evt.getPoint());
089: }
090: }
091:
092: public void mouseReleased(MouseEvent evt) {
093: if (evt.isPopupTrigger()) {
094: showPopup(evt.getPoint());
095: }
096: }
097: });
098: }
099:
100: public XArrayList getWorkflowProcesses() {
101: return workflowProcesses;
102: }
103:
104: public XArrayList getGraphs() {
105: return graphs;
106: }
107:
108: public void showPopup(Point p) {
109: OBETabbedPanePopupMenu menu = new OBETabbedPanePopupMenu(parent);
110: menu.show(this , p.x, p.y);
111: }
112:
113: public WorkflowProcess getSelectedWorkflowProcess() {
114: int index = getSelectedIndex();
115: if (index >= 0 && index < workflowProcesses.size()) {
116: return (WorkflowProcess) workflowProcesses.get(index);
117: } else {
118: return null;
119: }
120: }
121:
122: public OBEGraph getSelectedGraph() {
123: int index = getSelectedIndex();
124: if (index >= 0 && index < graphs.size()) {
125: return (OBEGraph) graphs.get(index);
126: } else {
127: return null;
128: }
129: }
130:
131: public void intervalAdded(ListDataEvent evt) {
132: int start = evt.getIndex0();
133: int end = evt.getIndex1();
134:
135: for (int i = start; i <= end; i++) {
136: WorkflowProcess wp = (WorkflowProcess) workflowProcesses
137: .get(i);
138: OBEGraph graph = new OBEGraph(parent, new OBEGraphModel());
139: graph.setWorkflowProcess(wp);
140: add(wp.getName(), new JScrollPane(graph));
141: graphs.add(graph);
142: }
143:
144: setSelectedIndex(end);
145: }
146:
147: public void intervalRemoved(ListDataEvent evt) {
148: int start = evt.getIndex0();
149: int end = evt.getIndex1();
150:
151: log.debug("Interval removed " + start + ',' + end);
152:
153: for (int i = start; i < end; i++) {
154: try {
155: log.debug("Removing tab " + i);
156: remove(0);
157: graphs.remove(0);
158: } catch (Throwable t) {
159: log.error("Error removing tab: " + t.getMessage());
160: t.printStackTrace();
161: }
162: }
163: }
164:
165: public void contentsChanged(ListDataEvent evt) {
166: int start = evt.getIndex0();
167: int end = evt.getIndex1();
168:
169: for (int i = start; i <= end; i++) {
170: WorkflowProcess wp = (WorkflowProcess) workflowProcesses
171: .get(i);
172: setTitleAt(i, wp.getName());
173: }
174: }
175:
176: }
|