001: /*******************************************************************************
002: * Copyright (c) 2003, 2004 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Common Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/cpl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.openwfe.gpe.parts;
011:
012: import java.beans.PropertyChangeEvent;
013: import java.beans.PropertyChangeListener;
014: import java.util.List;
015: import java.util.Map;
016:
017: import org.eclipse.draw2d.ConnectionAnchor;
018: import org.eclipse.draw2d.IFigure;
019: import org.eclipse.draw2d.Label;
020: import org.eclipse.draw2d.geometry.Rectangle;
021: import org.eclipse.draw2d.graph.CompoundDirectedGraph;
022: import org.eclipse.draw2d.graph.Node;
023: import org.eclipse.draw2d.graph.Subgraph;
024:
025: import org.eclipse.gef.ConnectionEditPart;
026: import org.eclipse.gef.EditPolicy;
027: import org.eclipse.gef.GraphicalEditPart;
028: import org.eclipse.gef.NodeEditPart;
029: import org.eclipse.gef.Request;
030: import org.eclipse.gef.RequestConstants;
031: import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
032: import org.eclipse.gef.tools.DirectEditManager;
033:
034: import org.openwfe.gpe.figures.ConcurrenceFigure;
035: import org.openwfe.gpe.figures.SubgraphFigure;
036: import org.openwfe.gpe.model.AbstractFlow;
037: import org.openwfe.gpe.model.ConcurrenceComposite;
038: import org.openwfe.gpe.model.FlowElement;
039: import org.openwfe.gpe.policies.ActivityDirectEditPolicy;
040: import org.openwfe.gpe.policies.ActivityEditPolicy;
041:
042: //import org.openwfe.gpe.policies.ActivityNodeEditPolicy;
043: //import org.openwfe.gpe.policies.ActivitySourceEditPolicy;
044:
045: /**
046: * @author hudsonr
047: * Created on Jun 30, 2003
048: */
049: public abstract class FlowElementPart extends AbstractGraphicalEditPart
050: implements PropertyChangeListener
051: //, NodeEditPart
052: {
053:
054: protected DirectEditManager manager;
055:
056: /**
057: * @see org.eclipse.gef.EditPart#activate()
058: */
059: public void activate() {
060: super .activate();
061: getActivity().addPropertyChangeListener(this );
062: }
063:
064: protected void applyGraphResults(CompoundDirectedGraph graph,
065: Map map) {
066: Node n = (Node) map.get(this );
067: getFigure().setBounds(
068: new Rectangle(n.x, n.y, n.width, n.height));
069: }
070:
071: public void contributeEdgesToGraph(CompoundDirectedGraph graph,
072: Map map) {
073: for (int i = 0; i < getChildren().size(); i++) {
074: FlowElementPart child = (FlowElementPart) children.get(i);
075: child.contributeEdgesToGraph(graph, map);
076: }
077: }
078:
079: public abstract void contributeNodesToGraph(
080: CompoundDirectedGraph graph, Subgraph s, Map map);
081:
082: /**
083: * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
084: */
085: protected void createEditPolicies() {
086: //installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new ActivityNodeEditPolicy());
087: //installEditPolicy(EditPolicy.CONTAINER_ROLE, new ActivitySourceEditPolicy());
088: installEditPolicy(EditPolicy.COMPONENT_ROLE,
089: new ActivityEditPolicy());
090: installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE,
091: new ActivityDirectEditPolicy());
092: }
093:
094: /**
095: * @see org.eclipse.gef.EditPart#deactivate()
096: */
097: public void deactivate() {
098: super .deactivate();
099: getActivity().removePropertyChangeListener(this );
100: }
101:
102: /**
103: * Returns the FlowElement model associated with this EditPart
104: * @return the FlowElement model
105: */
106: protected FlowElement getActivity() {
107: return (FlowElement) getModel();
108: }
109:
110: //abstract int getAnchorOffset();
111:
112: /**
113: * @see NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.ConnectionEditPart)
114: */
115: /*public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connection) {
116: return new BottomAnchor(getFigure(), getAnchorOffset());
117: }
118: */
119: /**
120: * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.Request)
121: */
122: /*public ConnectionAnchor getSourceConnectionAnchor(Request request) {
123: return new BottomAnchor(getFigure(), getAnchorOffset());
124: }*/
125:
126: /**
127: * @see NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.ConnectionEditPart)
128: */
129: /*public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart connection) {
130: return new TopAnchor(getFigure(), getAnchorOffset());
131: }*/
132:
133: /**
134: * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.Request)
135: */
136: /*public ConnectionAnchor getTargetConnectionAnchor(Request request) {
137: return new TopAnchor(getFigure(), getAnchorOffset());
138: }
139: */
140: protected void performDirectEdit() {
141: }
142:
143: /**
144: * @see org.eclipse.gef.EditPart#performRequest(org.eclipse.gef.Request)
145: */
146: public void performRequest(Request request) {
147: if (request.getType() == RequestConstants.REQ_DIRECT_EDIT)
148: performDirectEdit();
149: }
150:
151: /**
152: * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
153: */
154: public void propertyChange(PropertyChangeEvent evt) {
155: String prop = evt.getPropertyName();
156: if (AbstractFlow.CHILDREN.equals(prop))
157: refreshChildren();
158:
159: // Causes Graph to re-layout
160: ((GraphicalEditPart) (getViewer().getContents())).getFigure()
161: .revalidate();
162: }
163:
164: /**
165: * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#setFigure(org.eclipse.draw2d.IFigure)
166: */
167: protected void setFigure(IFigure figure) {
168: figure.getBounds().setSize(0, 0);
169: super .setFigure(figure);
170: }
171:
172: /**
173: * @see org.eclipse.gef.editparts.AbstractEditPart#toString()
174: */
175: public String toString() {
176: return getModel().toString();
177: }
178:
179: }
|