001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.bpel.design.decoration.providers;
021:
022: import java.awt.Component;
023: import java.awt.Point;
024: import java.awt.dnd.DnDConstants;
025: import java.awt.dnd.DragSource;
026: import java.util.ArrayList;
027: import java.util.Collection;
028: import javax.swing.Icon;
029: import javax.swing.ImageIcon;
030: import org.netbeans.modules.bpel.design.DesignView;
031: import org.netbeans.modules.bpel.design.DiagramView;
032: import org.netbeans.modules.bpel.design.decoration.ComponentsDescriptor;
033: import org.netbeans.modules.bpel.design.decoration.Decoration;
034: import org.netbeans.modules.bpel.design.decoration.DecorationProvider;
035: import org.netbeans.modules.bpel.design.decoration.Descriptor;
036: import org.netbeans.modules.bpel.design.decoration.Positioner;
037: import org.netbeans.modules.bpel.design.decoration.components.LinkToolButton;
038: import org.netbeans.modules.bpel.design.geometry.FBounds;
039: import org.netbeans.modules.bpel.design.geometry.FPoint;
040: import org.netbeans.modules.bpel.design.model.patterns.Pattern;
041: import org.netbeans.modules.bpel.design.selection.DiagramSelectionListener;
042: import org.netbeans.modules.bpel.design.selection.FlowlinkTool;
043: import org.netbeans.modules.bpel.model.api.BpelEntity;
044: import org.netbeans.modules.bpel.model.api.PartnerLinkReference;
045: import org.netbeans.modules.bpel.model.api.support.UniqueId;
046:
047: /**
048: *
049: * @author aa160298
050: */
051: public class LinkToolDecorationProvider extends DecorationProvider
052: implements DiagramSelectionListener {
053:
054: private ArrayList<UniqueId> linkedEntities = new ArrayList<UniqueId>();
055: private Decoration linkBtnDecoration;
056: private DragSource dragSource = new DragSource();
057:
058: private static final Icon ICON = new ImageIcon(Decoration.class
059: .getResource("resources/enabled_breakpoint.png"));
060:
061: public LinkToolDecorationProvider(DesignView designView) {
062: super (designView);
063:
064: getDesignView().getSelectionModel().addSelectionListener(this );
065: }
066:
067: public Decoration getDecoration(BpelEntity entity) {
068:
069: UniqueId entityID = entity.getUID();
070: UniqueId selectedEntityID = getDesignView().getSelectionModel()
071: .getSelectedID();
072:
073: if (entityID != null && entityID.equals(selectedEntityID)
074: && entity instanceof PartnerLinkReference
075: && linkBtnDecoration != null) {
076:
077: return (getDesignView().getFlowLinkTool().isActive()) ? null
078: : linkBtnDecoration;
079: }
080:
081: return null;
082: }
083:
084: public void selectionChanged(BpelEntity oldSelection,
085: BpelEntity newSelection) {
086:
087: if (newSelection instanceof PartnerLinkReference) {
088: Pattern p = getDesignView().getModel().getPattern(
089: newSelection);
090: LinkToolButton button = new LinkToolButton(p);
091:
092: dragSource.createDefaultDragGestureRecognizer(button,
093: DnDConstants.ACTION_MOVE, getDesignView()
094: .getDndHandler());
095:
096: ComponentsDescriptor cd = new ComponentsDescriptor();
097: cd.add(button, linkToolPositioner);
098: linkBtnDecoration = new Decoration(new Descriptor[] { cd });
099:
100: } else {
101: linkBtnDecoration = null;
102: }
103:
104: fireDecorationChanged();
105:
106: }
107:
108: private Positioner linkToolPositioner = new Positioner() {
109: private static final int HSPACING = 0;
110: private static final int VSPACING = 3;
111:
112: public void position(Pattern pattern,
113: Collection<Component> components, double zoom) {
114: assert (components.size() == 1) : "Only one LinkToolButton per element allowed";
115:
116: LinkToolButton btn = ((LinkToolButton) components.toArray()[0]);
117:
118: FlowlinkTool flt = getDesignView().getFlowLinkTool();
119:
120: if (flt.isActive()) {
121: btn.setPosition(flt.getPosition());
122: } else {
123: FBounds bounds = pattern.getFirstElement().getBounds();
124:
125: DiagramView view = pattern.getView();
126: Point p = view.convertDiagramToScreen(new FPoint(bounds
127: .getX(), bounds.getCenterY()));
128:
129: btn.setPosition(p);
130: }
131:
132: }
133:
134: };
135:
136: }
|