001: package org.drools.eclipse.flow.common.editor.editpart;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import org.drools.eclipse.flow.common.editor.core.ElementConnection;
023: import org.drools.eclipse.flow.common.editor.core.ElementConnectionFactory;
024: import org.drools.eclipse.flow.common.editor.core.ModelEvent;
025: import org.drools.eclipse.flow.common.editor.core.ModelListener;
026: import org.drools.eclipse.flow.common.editor.policy.ConnectionBendpointEditPolicy;
027: import org.drools.eclipse.flow.common.editor.policy.ConnectionEditPolicy;
028: import org.eclipse.draw2d.AbsoluteBendpoint;
029: import org.eclipse.draw2d.BendpointConnectionRouter;
030: import org.eclipse.draw2d.IFigure;
031: import org.eclipse.draw2d.PolygonDecoration;
032: import org.eclipse.draw2d.PolylineConnection;
033: import org.eclipse.draw2d.geometry.Point;
034: import org.eclipse.gef.EditPart;
035: import org.eclipse.gef.EditPolicy;
036: import org.eclipse.gef.editparts.AbstractConnectionEditPart;
037: import org.eclipse.gef.editpolicies.ConnectionEndpointEditPolicy;
038:
039: /**
040: * Implementation of a connection EditPart.
041: *
042: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
043: */
044: public class ElementConnectionEditPart extends
045: AbstractConnectionEditPart implements ModelListener {
046:
047: protected void createEditPolicies() {
048: ConnectionEditPolicy connectionEditPolicy = new ConnectionEditPolicy();
049: connectionEditPolicy
050: .setDefaultElementConnectionFactory(getDefaultElementConnectionFactory());
051: installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE,
052: new ConnectionEndpointEditPolicy());
053: installEditPolicy(EditPolicy.CONNECTION_ROLE,
054: connectionEditPolicy);
055: installEditPolicy(EditPolicy.CONNECTION_BENDPOINTS_ROLE,
056: new ConnectionBendpointEditPolicy());
057: }
058:
059: protected ElementConnectionFactory getDefaultElementConnectionFactory() {
060: return new ElementConnectionFactory(0);
061: }
062:
063: protected IFigure createFigure() {
064: PolylineConnection result = new PolylineConnection();
065: result.setConnectionRouter(new BendpointConnectionRouter());
066: result.setTargetDecoration(new PolygonDecoration());
067: return result;
068: }
069:
070: public void setSelected(int value) {
071: super .setSelected(value);
072: if (value != EditPart.SELECTED_NONE) {
073: ((PolylineConnection) getFigure()).setLineWidth(2);
074: } else {
075: ((PolylineConnection) getFigure()).setLineWidth(1);
076: }
077: }
078:
079: public void modelChanged(ModelEvent event) {
080: if (event.getChange() == ElementConnection.CHANGE_BENDPOINTS) {
081: refreshBendpoints();
082: }
083: }
084:
085: public void activate() {
086: super .activate();
087: ((ElementConnection) getModel()).addListener(this );
088: }
089:
090: public void deactivate() {
091: ((ElementConnection) getModel()).removeListener(this );
092: super .deactivate();
093: }
094:
095: protected void refreshBendpoints() {
096: List bendpoints = ((ElementConnection) getModel())
097: .getBendpoints();
098: List constraint = new ArrayList();
099: for (int i = 0; i < bendpoints.size(); i++) {
100: constraint.add(new AbsoluteBendpoint((Point) bendpoints
101: .get(i)));
102: }
103: getConnectionFigure().setRoutingConstraint(constraint);
104: }
105:
106: protected void refreshVisuals() {
107: refreshBendpoints();
108: }
109: }
|