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.util.Map;
053: import java.util.Iterator;
054:
055: import javax.swing.Action;
056: import javax.swing.JMenuItem;
057: import javax.swing.JPopupMenu;
058:
059: import com.jgraph.graph.DefaultGraphCell;
060:
061: import org.apache.commons.logging.Log;
062: import org.apache.commons.logging.LogFactory;
063:
064: import org.obe.designer.menu.JoinMenu;
065: import org.obe.designer.menu.ModeMenu;
066: import org.obe.designer.menu.ZoomMenu;
067: import org.obe.designer.menu.SplitMenu;
068: import org.obe.designer.menu.AddActivityMenu;
069: import org.obe.designer.view.ActivityView;
070:
071: public class OBEGraphActivityModePopup extends JPopupMenu {
072:
073: private static final Log log = LogFactory
074: .getLog(OBEGraphActivityModePopup.class);
075:
076: private Designer app;
077: private OBEGraph parent;
078:
079: private ZoomMenu zoomMenu;
080: private ModeMenu modeMenu;
081: private AddActivityMenu addActivityMenu;
082: private JoinMenu joinMenu;
083: private SplitMenu splitMenu;
084:
085: private JMenuItem editMenuItem;
086: private JMenuItem deleteMenuItem;
087:
088: private Object object;
089:
090: public OBEGraphActivityModePopup(Designer app, OBEGraph parent) {
091: this (app, parent, null);
092: }
093:
094: public OBEGraphActivityModePopup(Designer app, OBEGraph parent,
095: Object object) {
096: this .app = app;
097: this .parent = parent;
098: this .object = object;
099: init();
100: }
101:
102: public void loadResources() {
103: zoomMenu.setText("Zoom");
104: modeMenu.setText("Mode");
105: addActivityMenu.setText("Add Activity");
106:
107: if (joinMenu != null) {
108: joinMenu.setText("Join");
109: }
110:
111: if (splitMenu != null) {
112: splitMenu.setText("Split");
113: }
114:
115: if (editMenuItem != null) {
116: editMenuItem.setText("Edit...");
117: }
118:
119: if (deleteMenuItem != null) {
120: deleteMenuItem.setText("Delete");
121: }
122: }
123:
124: private void init() {
125: boolean needsSeparator = true;
126:
127: Map actions = parent.getActions();
128:
129: zoomMenu = new ZoomMenu(app);
130: add(zoomMenu);
131:
132: modeMenu = new ModeMenu(app);
133: add(modeMenu);
134:
135: addActivityMenu = new AddActivityMenu(app, parent);
136: add(addActivityMenu);
137:
138: if (canJoin(object)) {
139: joinMenu = new JoinMenu(parent);
140: joinMenu.setEnabled(false);
141: if (isJoinEnabled(object)) {
142: ActivityView activityView = (ActivityView) ((OBEGraphCell) object)
143: .getUserObject();
144: joinMenu.setEnabled(true);
145: joinMenu.setActivity(activityView.getActivity());
146: }
147: add(joinMenu);
148: }
149:
150: if (canSplit(object)) {
151: splitMenu = new SplitMenu(parent);
152: splitMenu.setEnabled(false);
153: if (isSplitEnabled(object)) {
154: ActivityView activityView = (ActivityView) ((OBEGraphCell) object)
155: .getUserObject();
156: splitMenu.setEnabled(true);
157: splitMenu.setActivity(activityView.getActivity());
158: }
159: add(splitMenu);
160: }
161:
162: if (canEdit(object)) {
163: addSeparator();
164: editMenuItem = add((Action) actions.get("graph.edit"));
165: }
166:
167: if (canDelete(object)) {
168: addSeparator();
169: deleteMenuItem = add((Action) actions.get("graph.delete"));
170: }
171:
172: loadResources();
173: }
174:
175: private boolean canEdit(Object object) {
176: return object != null;
177: }
178:
179: private boolean canDelete(Object object) {
180: return object != null;
181: }
182:
183: private boolean canJoin(Object object) {
184: return object != null;
185: }
186:
187: private boolean canSplit(Object object) {
188: return object != null;
189: }
190:
191: protected boolean isJoinEnabled(Object object) {
192: if (object == null)
193: return false;
194:
195: log.info("Object type: " + object.getClass());
196: if (object instanceof OBEGraphCell) {
197: OBEGraphCell cell = (OBEGraphCell) object;
198: int i = 0;
199: Iterator iter = cell.getLeftPort().edges();
200: if (iter.hasNext()) {
201: iter.next();
202: if (iter.hasNext()) {
203: return true;
204: }
205: }
206: }
207: return false;
208: }
209:
210: protected boolean isSplitEnabled(Object object) {
211: if (object == null)
212: return false;
213:
214: if (object instanceof OBEGraphCell) {
215: OBEGraphCell cell = (OBEGraphCell) object;
216: int i = 0;
217: Iterator iter = cell.getRightPort().edges();
218: if (iter.hasNext()) {
219: iter.next();
220: if (iter.hasNext()) {
221: return true;
222: }
223: }
224: }
225: return false;
226: }
227:
228: }
|