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:
054: import javax.swing.Action;
055: import javax.swing.JMenuItem;
056: import javax.swing.JPopupMenu;
057:
058: import com.jgraph.graph.DefaultGraphCell;
059:
060: import org.obe.designer.menu.ZoomMenu;
061:
062: /** Popup menu which appears over the OBE Graph.
063:
064: @author Anthony Eden
065: */
066:
067: public class OBEGraphPopup extends JPopupMenu {
068:
069: private OBEDesigner app;
070: private OBEGraph parent;
071:
072: private ZoomMenu zoomMenu;
073:
074: private JMenuItem addActivityMenuItem;
075: private JMenuItem addTransitionMenuItem;
076: private JMenuItem editMenuItem;
077: private JMenuItem deleteMenuItem;
078:
079: private Object object;
080:
081: public OBEGraphPopup(OBEDesigner app, OBEGraph parent) {
082: this (app, parent, null);
083: }
084:
085: public OBEGraphPopup(OBEDesigner app, OBEGraph parent, Object object) {
086: this .app = app;
087: this .parent = parent;
088: this .object = object;
089: init();
090: }
091:
092: public void loadResources() {
093: zoomMenu.setText("Zoom");
094:
095: if (addActivityMenuItem != null) {
096: addActivityMenuItem.setText("Add Activity...");
097: }
098:
099: if (addTransitionMenuItem != null) {
100: addTransitionMenuItem.setText("Add Transition...");
101: }
102:
103: if (editMenuItem != null) {
104: editMenuItem.setText("Edit...");
105: }
106:
107: if (deleteMenuItem != null) {
108: deleteMenuItem.setText("Delete");
109: }
110: }
111:
112: private void init() {
113: boolean needsSeparator = true;
114:
115: Map actions = parent.getActions();
116:
117: zoomMenu = new ZoomMenu(app);
118: add(zoomMenu);
119:
120: if (canAddActivity(object)) {
121: if (needsSeparator) {
122: addSeparator();
123: needsSeparator = false;
124: }
125: addActivityMenuItem = add((Action) actions
126: .get("graph.addActivity"));
127: }
128:
129: if (canAddTransition(object)) {
130: if (needsSeparator) {
131: addSeparator();
132: needsSeparator = false;
133: }
134: addTransitionMenuItem = add((Action) actions
135: .get("graph.addTransition"));
136: }
137:
138: if (canEdit(object)) {
139: addSeparator();
140: editMenuItem = add((Action) actions.get("graph.edit"));
141: }
142:
143: if (canDelete(object)) {
144: addSeparator();
145: deleteMenuItem = add((Action) actions.get("graph.delete"));
146: }
147:
148: loadResources();
149: }
150:
151: private boolean canAddActivity(Object object) {
152: /*ObjectDescriptor od = getObjectDescriptor(object);
153: if(od != null){
154: if( od instanceof TaskDescriptor ){
155: return true;
156: }
157: }
158: return false;
159: */
160: return true;
161: }
162:
163: private boolean canAddTransition(Object object) {
164: /*
165: ObjectDescriptor od = getObjectDescriptor(object);
166: if(od != null){
167: if( od instanceof TaskDescriptor ){
168: return true;
169: }
170: }
171: return false;
172: */
173: return true;
174: }
175:
176: private boolean canEdit(Object object) {
177: /*
178: ObjectDescriptor od = getObjectDescriptor(object);
179: if(od != null){
180: if( od instanceof TaskDescriptor ||
181: od instanceof ConditionDescriptor){
182: return true;
183: }
184: }
185: return false;
186: */
187: return true;
188: }
189:
190: private boolean canDelete(Object object) {
191: /*ObjectDescriptor od = getObjectDescriptor(object);
192: if(od != null){
193: if( od instanceof TaskDescriptor ||
194: od instanceof ConditionDescriptor ||
195: od instanceof StopPointDescriptor){
196: return true;
197: }
198: }
199: return false;
200: */
201: return true;
202: }
203:
204: /*
205: private ObjectDescriptor getObjectDescriptor(Object object){
206: if(object instanceof DefaultGraphCell){
207: Object userObject = ((DefaultGraphCell)object).getUserObject();
208: if(userObject instanceof RouteNode){
209: return (ObjectDescriptor)((RouteNode)userObject).value();
210: }
211: }
212: return null;
213: }
214: */
215:
216: }
|