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.util.EventObject;
013: import java.util.Map;
014:
015: import org.eclipse.draw2d.Figure;
016: import org.eclipse.draw2d.IFigure;
017: import org.eclipse.draw2d.geometry.Rectangle;
018: import org.eclipse.draw2d.graph.CompoundDirectedGraph;
019:
020: import org.eclipse.gef.EditPolicy;
021: import org.eclipse.gef.commands.CommandStackListener;
022: import org.eclipse.gef.editpolicies.RootComponentEditPolicy;
023:
024: import org.openwfe.gpe.policies.ActivityContainerEditPolicy;
025: import org.openwfe.gpe.policies.StructuredActivityLayoutEditPolicy;
026:
027: /**
028: * @author hudsonr
029: * Created on Jul 16, 2003
030: */
031: public class FlowElementDiagramPart extends CompositeOrOneChildPart {
032:
033: /**
034: * @param figure
035: */
036: IFigure figure;
037:
038: public FlowElementDiagramPart(IFigure figure) {
039: super ();
040: this .figure = figure;
041: // TODO Auto-generated constructor stub
042: }
043:
044: CommandStackListener stackListener = new CommandStackListener() {
045: public void commandStackChanged(EventObject event) {
046: if (!GraphAnimation.captureLayout(getFigure()))
047: return;
048: while (GraphAnimation.step())
049: getFigure().getUpdateManager().performUpdate();
050: GraphAnimation.end();
051: }
052: };
053:
054: protected void applyOwnResults(CompoundDirectedGraph graph, Map map) {
055: }
056:
057: /**
058: * @see org.openwfe.gpe.parts.FlowElementPart#activate()
059: */
060: public void activate() {
061: super .activate();
062: getViewer().getEditDomain().getCommandStack()
063: .addCommandStackListener(stackListener);
064: }
065:
066: /**
067: * @see org.openwfe.gpe.parts.FlowElementPart#createEditPolicies()
068: */
069: protected void createEditPolicies() {
070: installEditPolicy(EditPolicy.NODE_ROLE, null);
071: installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, null);
072: installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, null);
073: installEditPolicy(EditPolicy.COMPONENT_ROLE,
074: new RootComponentEditPolicy());
075: installEditPolicy(EditPolicy.LAYOUT_ROLE,
076: new StructuredActivityLayoutEditPolicy());
077: installEditPolicy(EditPolicy.CONTAINER_ROLE,
078: new ActivityContainerEditPolicy());
079: }
080:
081: protected IFigure createFigure() {
082: Figure f = new Figure() {
083: public void setBounds(Rectangle rect) {
084: int x = bounds.x, y = bounds.y;
085:
086: boolean resize = (rect.width != bounds.width)
087: || (rect.height != bounds.height), translate = (rect.x != x)
088: || (rect.y != y);
089:
090: if (isVisible() && (resize || translate))
091: erase();
092: if (translate) {
093: int dx = rect.x - x;
094: int dy = rect.y - y;
095: primTranslate(dx, dy);
096: }
097: bounds.width = rect.width;
098: bounds.height = rect.height;
099: if (resize || translate) {
100: fireMoved();
101: repaint();
102: }
103: }
104: };
105: f.setLayoutManager(new GraphLayoutManager(this ));
106: return f;
107: }
108:
109: /**
110: * @see org.openwfe.gpe.parts.FlowElementPart#deactivate()
111: */
112: public void deactivate() {
113: getViewer().getEditDomain().getCommandStack()
114: .removeCommandStackListener(stackListener);
115: super .deactivate();
116: }
117:
118: /**
119: * @see org.eclipse.gef.editparts.AbstractEditPart#isSelectable()
120: */
121: public boolean isSelectable() {
122: return false;
123: }
124:
125: /**
126: * @see org.openwfe.gpe.parts.CompositeOrOneChildPart#refreshVisuals()
127: */
128: protected void refreshVisuals() {
129: }
130:
131: }
|