001: /*
002: * argun 1.0
003: * Web 2.0 delivery framework
004: * Copyright (C) 2007 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.biz
021: * e-Mail: support@hammurapi.biz
022: */
023: package biz.hammurapi.web.webdiagram;
024:
025: import java.awt.Color;
026: import java.awt.Frame;
027: import java.awt.event.ActionEvent;
028: import java.util.HashMap;
029: import java.util.Iterator;
030: import java.util.Map;
031:
032: import javax.swing.AbstractAction;
033: import javax.swing.JPopupMenu;
034: import javax.swing.SwingUtilities;
035:
036: import org.jgraph.JGraph;
037: import org.jgraph.graph.DefaultPort;
038: import org.jgraph.graph.GraphConstants;
039: import org.jgraph.graph.GraphLayoutCache;
040:
041: import biz.hammurapi.diagram.DiagramApplet;
042: import biz.hammurapi.diagram.DiagramEdge;
043: import biz.hammurapi.diagram.DiagramModel;
044: import biz.hammurapi.diagram.data.Edge;
045:
046: public class OperationPermission extends DiagramEdge {
047:
048: public OperationPermission(DiagramModel owner, Edge data) {
049: super (owner, data);
050: }
051:
052: public void setAttributes(Map attributes) {
053: super .setAttributes(attributes);
054: GraphConstants.setLineEnd(attributes,
055: GraphConstants.ARROW_SIMPLE);
056: GraphConstants.setLineColor(attributes, "yes"
057: .equals(getProperty("deny")) ? Color.red : Color.GREEN);
058: GraphConstants.setEditable(attributes, false);
059: }
060:
061: public boolean acceptsSource(Object port) {
062: if (port instanceof DefaultPort) {
063: Iterator it = ((DefaultPort) port).getEdges().iterator();
064: while (it.hasNext()) {
065: Object next = it.next();
066: if (next != this
067: && next instanceof OperationPermission
068: && ((OperationPermission) next).getTarget() == getTarget()) {
069: return false;
070: }
071: }
072: }
073:
074: return port != null
075: && ((DefaultPort) port).getParent() instanceof Role;
076: }
077:
078: public boolean acceptsTarget(Object port) {
079: if (port instanceof DefaultPort) {
080: Iterator it = ((DefaultPort) port).getEdges().iterator();
081: while (it.hasNext()) {
082: Object next = it.next();
083: if (next != this
084: && next instanceof OperationPermission
085: && ((OperationPermission) next).getSource() == getSource()) {
086: return false;
087: }
088: }
089: }
090:
091: return port != null
092: && ((DefaultPort) port).getParent() instanceof Operation;
093: }
094:
095: public void populatePopupMenu(final DiagramApplet applet,
096: final java.awt.Point pt, final JPopupMenu menu) {
097: // Edit
098: menu.add(new AbstractAction("Edit") {
099: public void actionPerformed(ActionEvent e) {
100: Frame frame = (Frame) SwingUtilities
101: .getAncestorOfClass(Frame.class, applet
102: .getGraph());
103: OperationPermissionPropertiesDialog pd = new OperationPermissionPropertiesDialog(
104: frame, OperationPermission.this );
105: if (pd.edit()) {
106: JGraph graph = applet.getGraph();
107: GraphLayoutCache graphLayoutCache = graph
108: .getGraphLayoutCache();
109: Map map = new HashMap();
110: GraphConstants.setLineColor(map, "yes"
111: .equals(getProperty("deny")) ? Color.red
112: : Color.GREEN);
113: graphLayoutCache.editCell(OperationPermission.this,
114: map);
115: }
116: }
117: });
118: }
119:
120: }
|