0001: /*
0002: * The contents of this file are subject to the terms of the Common Development
0003: * and Distribution License (the License). You may not use this file except in
0004: * compliance with the License.
0005: *
0006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
0007: * or http://www.netbeans.org/cddl.txt.
0008: *
0009: * When distributing Covered Code, include this CDDL Header Notice in each file
0010: * and include the License file at http://www.netbeans.org/cddl.txt.
0011: * If applicable, add the following below the CDDL Header, with the fields
0012: * enclosed by brackets [] replaced by your own identifying information:
0013: * "Portions Copyrighted [year] [name of copyright owner]"
0014: *
0015: * The Original Software is NetBeans. The Initial Developer of the Original
0016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0017: * Microsystems, Inc. All Rights Reserved.
0018: */
0019: package org.netbeans.modules.bpel.design;
0020:
0021: import java.awt.Font;
0022: import java.awt.Graphics;
0023: import java.awt.Point;
0024:
0025: import java.awt.Color;
0026: import java.awt.Component;
0027: import java.awt.Dimension;
0028: import java.awt.dnd.DropTarget;
0029: import java.awt.event.ActionEvent;
0030: import java.awt.event.KeyEvent;
0031: import java.util.logging.Level;
0032: import java.util.logging.LogRecord;
0033: import java.util.logging.Logger;
0034: import javax.accessibility.AccessibleContext;
0035: import javax.swing.Action;
0036: import javax.swing.ActionMap;
0037: import javax.swing.InputMap;
0038: import javax.swing.JComponent;
0039: import javax.swing.JPanel;
0040: import javax.swing.KeyStroke;
0041: import javax.swing.SwingUtilities;
0042: import javax.swing.ToolTipManager;
0043: import org.netbeans.modules.bpel.design.decoration.DecorationManager;
0044: import org.netbeans.modules.bpel.design.decoration.components.DiagramButton;
0045: import org.netbeans.modules.bpel.design.decoration.providers.CollapseExpandDecorationProvider;
0046: import org.netbeans.modules.bpel.design.decoration.providers.DebuggerDecorationProvider;
0047: import org.netbeans.modules.bpel.design.decoration.providers.LinkToolDecorationProvider;
0048:
0049: import org.netbeans.modules.bpel.design.decoration.providers.ToolbarDecorationProvider;
0050: import org.netbeans.modules.bpel.design.model.patterns.ProcessPattern;
0051: import org.netbeans.modules.bpel.design.model.patterns.SequencePattern;
0052: import org.netbeans.modules.bpel.editors.api.nodes.NodeType;
0053: import org.netbeans.modules.bpel.editors.api.utils.Util;
0054: import org.netbeans.modules.bpel.editors.multiview.DesignerMultiViewElement;
0055: import org.netbeans.modules.bpel.design.DiagramView;
0056: import org.netbeans.modules.bpel.model.api.BpelEntity;
0057: import org.netbeans.modules.bpel.model.api.BpelModel;
0058: import org.netbeans.modules.bpel.model.api.Process;
0059:
0060: import org.netbeans.modules.bpel.design.model.DiagramModel;
0061: import org.netbeans.modules.bpel.design.model.connections.ConnectionManager;
0062: import org.netbeans.modules.bpel.design.model.patterns.CompositePattern;
0063: import org.netbeans.modules.bpel.design.model.patterns.Pattern;
0064: import org.netbeans.modules.bpel.design.selection.FlowlinkTool;
0065: import org.netbeans.modules.bpel.design.selection.GhostSelection;
0066: import org.netbeans.modules.bpel.design.selection.EntitySelectionModel;
0067:
0068: import org.netbeans.modules.bpel.design.layout.LayoutManager;
0069: import org.netbeans.modules.bpel.properties.PropertyNodeFactory;
0070: import org.netbeans.modules.xml.xam.Model;
0071: import org.openide.util.HelpCtx;
0072: import org.openide.util.Lookup;
0073:
0074: import org.openide.nodes.Node;
0075: import org.netbeans.modules.bpel.core.helper.api.BusinessProcessHelper;
0076: import org.netbeans.modules.bpel.core.util.BPELValidationController;
0077: import org.netbeans.modules.bpel.design.decoration.Decoration;
0078: import org.netbeans.modules.bpel.design.decoration.DecorationProviderFactory;
0079: import org.netbeans.modules.bpel.design.decoration.components.GlassPane;
0080: import org.netbeans.modules.bpel.design.decoration.providers.SelectionDecorationProvider;
0081: import org.netbeans.modules.bpel.design.decoration.providers.ValidationDecorationProvider;
0082: import org.netbeans.modules.bpel.design.geometry.FDimension;
0083: import org.netbeans.modules.bpel.design.geometry.FPoint;
0084: import org.netbeans.modules.bpel.design.phmode.PlaceHolderSelectionModel;
0085: import org.netbeans.modules.soa.ui.nodes.NodeFactory;
0086: import org.netbeans.modules.bpel.design.PartnerlinksView;
0087: import org.netbeans.modules.bpel.design.ProcessView;
0088: import org.netbeans.modules.bpel.design.actions.CollapseCurrentPatternAction;
0089: import org.netbeans.modules.bpel.design.actions.DeleteAction;
0090: import org.netbeans.modules.bpel.design.actions.ExpandAllPatternsAction;
0091: import org.netbeans.modules.bpel.design.actions.ExpandCurrentPatternAction;
0092: import org.netbeans.modules.bpel.design.actions.FindUsagesAction;
0093: import org.netbeans.modules.bpel.design.actions.GoToLoggingAction;
0094: import org.netbeans.modules.bpel.design.actions.GoToMapperAction;
0095: import org.netbeans.modules.bpel.design.actions.GoToSourceAction;
0096: import org.netbeans.modules.bpel.design.actions.ShowContextMenuAction;
0097: import org.netbeans.modules.bpel.design.actions.TabToNextComponentAction;
0098: import org.netbeans.modules.bpel.design.model.PartnerRole;
0099: import org.netbeans.modules.bpel.nodes.actions.GoToAction;
0100: import org.netbeans.modules.bpel.nodes.actions.ShowBpelMapperAction;
0101: import org.netbeans.modules.bpel.properties.NodeUtils;
0102: import org.netbeans.modules.soa.ui.form.CustomNodeEditor;
0103: import org.openide.ErrorManager;
0104: import org.openide.util.NbBundle;
0105: import org.openide.windows.TopComponent;
0106:
0107: public class DesignView extends JPanel implements HelpCtx.Provider/*, ThumbScrollPane.Thumbnailable */{
0108:
0109: public static double CORNER45 = Math.PI / 4.0;
0110: private static final long serialVersionUID = 1;
0111:
0112: private double zoom = 1;
0113: private Lookup lookup;
0114: private DropTarget dTarget;
0115: private DiagramModel diagramModel;
0116: private EntitySelectionModel selectionModel;
0117: private LayoutManager layoutManager;
0118: private ConnectionManager connectionManager;
0119:
0120: private DnDHandler dndHandler;
0121: private GhostSelection ghost;
0122:
0123: private PlaceHolderSelectionModel phSelectionModel;
0124: private CopyPasteHandler copyPasteHandler;
0125: private FlowlinkTool flowLinkTool;
0126:
0127: private ErrorPanel errorPanel;
0128:
0129: private ZoomManager zoomManager;
0130: private DecorationManager decorationManager;
0131:
0132: private SelectionDecorationProvider selectionDecorationProvider;
0133: private ValidationDecorationProvider validationDecorationProvider;
0134: private DebuggerDecorationProvider debuggerDecorationProvider;
0135:
0136: private ToolbarDecorationProvider toolbarDecorationProvider;
0137: private LinkToolDecorationProvider linkToolDecorationProvider;
0138: private CollapseExpandDecorationProvider collapseExpandDectorationProvider;
0139:
0140: private SelectionBridge selectionBridge;
0141:
0142: private NavigationTools navigationTools;
0143: private RightStripe rightStripe;
0144: private DesignViewMode designViewMode = DesignViewMode.DESIGN;
0145:
0146: private PartnerlinksView consumersView;
0147: private PartnerlinksView providersView;
0148: private ProcessView processView;
0149: private OverlayPanel overlayView;
0150:
0151: private TriScrollPane scrollPane;
0152:
0153: // Memory leak probing
0154: private static final Logger TIMERS = Logger.getLogger("TIMER.bpel"); // NOI18N
0155:
0156: public DesignView(Lookup lookup) {
0157: super ();
0158:
0159: if (TIMERS.isLoggable(Level.FINE)) {
0160: LogRecord rec = new LogRecord(Level.FINE, "BPEL DesignView"); // NOI18N
0161: rec.setParameters(new Object[] { this });
0162: TIMERS.log(rec);
0163: }
0164:
0165: zoomManager = new ZoomManager(this );
0166: rightStripe = new RightStripe(this );
0167:
0168: setBackground(new Color(0xFCFAF5));
0169:
0170: this .lookup = lookup;
0171: diagramModel = new DiagramModel(this );
0172: selectionModel = new EntitySelectionModel(diagramModel);
0173:
0174: overlayView = new OverlayPanel(this );
0175:
0176: consumersView = new PartnerlinksView(this , PartnerRole.CONSUMER);
0177: consumersView.getAccessibleContext().setAccessibleName(
0178: NbBundle.getMessage(DesignView.class,
0179: "ACSN_ConsumersPLPanel"));
0180: consumersView.getAccessibleContext().setAccessibleDescription(
0181: NbBundle.getMessage(DesignView.class,
0182: "ACSD_ConsumersPLPanel"));
0183:
0184: providersView = new PartnerlinksView(this , PartnerRole.PROVIDER);
0185: providersView.getAccessibleContext().setAccessibleName(
0186: NbBundle.getMessage(DesignView.class,
0187: "ACSN_ProvidersPLPanel"));
0188: providersView.getAccessibleContext().setAccessibleDescription(
0189: NbBundle.getMessage(DesignView.class,
0190: "ACSD_ProvidersPLPanel"));
0191:
0192: processView = new ProcessView(this );
0193: processView.getAccessibleContext().setAccessibleName(
0194: NbBundle.getMessage(DesignView.class,
0195: "ACSN_ProcessPanel"));
0196: processView.getAccessibleContext().setAccessibleDescription(
0197: NbBundle.getMessage(DesignView.class,
0198: "ACSD_ProcessPanel"));
0199:
0200: navigationTools = new NavigationTools(this );
0201:
0202: scrollPane = new TriScrollPane(processView, consumersView,
0203: providersView, navigationTools, overlayView);
0204: this .add(scrollPane, 0);
0205:
0206: dndHandler = new DnDHandler(this );
0207:
0208: ghost = new GhostSelection(this );
0209: flowLinkTool = new FlowlinkTool(this );
0210: copyPasteHandler = new CopyPasteHandler(this );
0211: //FIXME phSelectionModel = new PlaceHolderSelectionModel(placeHolderManager);
0212:
0213: layoutManager = new LayoutManager();
0214: connectionManager = new ConnectionManager();
0215: selectionBridge = new SelectionBridge(this );
0216: setFocusable(true);
0217:
0218: // register before to get esc action first (117432)
0219: ToolTipManager.sharedInstance().registerComponent(this );
0220: registerActions();
0221: errorPanel = new ErrorPanel(this );
0222: decorationManager = new DecorationManager(this );
0223: loadDecorationProviders();
0224:
0225: setFocusCycleRoot(true);
0226: setFocusTraversalKeysEnabled(false);
0227:
0228: reloadModel();
0229: diagramChanged();
0230: }
0231:
0232: @Override
0233: public AccessibleContext getAccessibleContext() {
0234: EntitySelectionModel selModel = getSelectionModel();
0235: Pattern selPattern = null;
0236: if (selModel != null) {
0237: selPattern = selModel.getSelectedPattern();
0238: }
0239:
0240: DiagramView dView = null;
0241: if (selPattern != null) {
0242: dView = selPattern.getView();
0243: }
0244: return dView != null ? dView.getAccessibleContext() : super
0245: .getAccessibleContext();
0246: }
0247:
0248: public DiagramView getConsumersView() {
0249: return consumersView;
0250: }
0251:
0252: public Object getMouseHandler() {
0253: throw new UnsupportedOperationException("Not yet implemented");
0254: }
0255:
0256: public DiagramView getProcessView() {
0257: return processView;
0258: }
0259:
0260: public DiagramView getProvidersView() {
0261: return providersView;
0262: }
0263:
0264: public OverlayPanel getOverlayView() {
0265: return this .overlayView;
0266: }
0267:
0268: public NavigationTools getNavigationTools() {
0269: return navigationTools;
0270: }
0271:
0272: public RightStripe getRightStripe() {
0273: return rightStripe;
0274: }
0275:
0276: @Override
0277: public void doLayout() {
0278: int w = getWidth();
0279: int h = getHeight();
0280: for (Component c : getComponents()) {
0281: c.setBounds(0, 0, w, h);
0282:
0283: }
0284: }
0285:
0286: @Override
0287: public boolean isOptimizedDrawingEnabled() {
0288: return false;
0289: }
0290:
0291: public void reloadModel() {
0292:
0293: if (getBPELModel().getState().equals(BpelModel.State.VALID)) {
0294: BpelEntity selected = selectionModel.getSelected();
0295:
0296: Process process = getProcessModel();
0297:
0298: try {
0299: diagramModel
0300: .setRootPattern((process != null) ? diagramModel
0301: .createPattern(process)
0302: : null);
0303: } catch (Exception ex) {
0304: ErrorManager.getDefault().notify(
0305: ErrorManager.EXCEPTION, ex);
0306: }
0307:
0308: selectionModel.setSelected(selected);
0309:
0310: } else {
0311: diagramModel.setRootPattern(null);
0312: selectionModel.clear();
0313: }
0314: }
0315:
0316: public void closeView() {
0317: if (diagramModel != null) {
0318: diagramModel.release();
0319: diagramModel = null;
0320: }
0321: getDecorationManager().release();
0322: selectionBridge.release();
0323: }
0324:
0325: public BPELValidationController getValidationController() {
0326: return getLookup().lookup(BPELValidationController.class);
0327: }
0328:
0329: public EntitySelectionModel getSelectionModel() {
0330: return selectionModel;
0331: }
0332:
0333: public PlaceHolderSelectionModel getPhSelectionModel() {
0334: return phSelectionModel;
0335: }
0336:
0337: public GhostSelection getGhost() {
0338: return ghost;
0339: }
0340:
0341: public FlowlinkTool getFlowLinkTool() {
0342: return flowLinkTool;
0343: }
0344:
0345: public CopyPasteHandler getCopyPasteHandler() {
0346: return copyPasteHandler;
0347: }
0348:
0349: public DecorationManager getDecorationManager() {
0350: return decorationManager;
0351: }
0352:
0353: public ZoomManager getZoomManager() {
0354: return zoomManager;
0355: }
0356:
0357: public BpelModel getBPELModel() {
0358: return getLookup().lookup(BpelModel.class);
0359: }
0360:
0361: /**
0362: * Helper to access root element of BPEL OM tree
0363: * NB! Do not cache object returned
0364: * @return Process element
0365: **/
0366: public Process getProcessModel() {
0367: try {
0368: BpelModel model = getBPELModel();
0369: return model.getProcess();
0370: } catch (Exception ex) {
0371:
0372: ErrorManager.getDefault()
0373: .notify(ErrorManager.EXCEPTION, ex);
0374: }
0375: return null;
0376: }
0377:
0378: public NodeFactory getNodeFactory() {
0379: return PropertyNodeFactory.getInstance();
0380: }
0381:
0382: public BusinessProcessHelper getProcessHelper() {
0383: return lookup.lookup(BusinessProcessHelper.class);
0384: }
0385:
0386: public Node getNodeForPattern(Pattern pattern) {
0387: if (pattern == null) {
0388: return null;
0389: }
0390:
0391: NodeType nodeType = Util.getBasicNodeType(pattern
0392: .getOMReference());
0393:
0394: NodeFactory factory = getNodeFactory();
0395:
0396: if (factory != null) {
0397: return factory.createNode(nodeType, pattern
0398: .getOMReference(), DesignView.this .getLookup());
0399: }
0400: return null;
0401: }
0402:
0403: public DiagramView getView(Point pt) {
0404: return (DiagramView) scrollPane.getComponent(pt);
0405: }
0406:
0407: public Pattern findPattern(Point pt) {
0408: DiagramView view = getView(pt);
0409: if (view != null) {
0410: FPoint fp = view.convertPointFromParent(pt);
0411: return view.findPattern(fp.x, fp.y);
0412: }
0413: return null;
0414: }
0415:
0416: public void performDefaultAction(Pattern pattern) {
0417: Node node = getNodeForPattern(pattern);
0418:
0419: if (node == null) {
0420: return;
0421: }
0422:
0423: Action action = node.getPreferredAction();
0424:
0425: if (action != null) {
0426: action.actionPerformed(new ActionEvent(this , 0, "DBC"));
0427: }
0428: }
0429:
0430: public boolean showCustomEditor(Pattern pattern,
0431: CustomNodeEditor.EditingMode editingMode) {
0432: Node node = getNodeForPattern(pattern);
0433:
0434: if (node == null) {
0435: return false;
0436: }
0437:
0438: if (getModel().isReadOnly()) {
0439: return false;
0440: }
0441:
0442: return NodeUtils.showNodeCustomEditor(node, editingMode);
0443: }
0444:
0445: public Lookup getLookup() {
0446: return lookup;
0447: }
0448:
0449: private void registerActions() {
0450: InputMap im1 = getInputMap(WHEN_FOCUSED);
0451: InputMap im2 = getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
0452: ActionMap am = getActionMap();
0453:
0454: im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0),
0455: "rename-something"); // NOI18N
0456: im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),
0457: "delete-something"); // NOI18N
0458: im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
0459: "cancel-something"); // NOI18N
0460:
0461: KeyStroke gotoSourceKey = GoToAction
0462: .getKeyStroke(org.netbeans.modules.bpel.nodes.actions.GoToSourceAction.class);
0463: KeyStroke gotoMapperKey = GoToAction
0464: .getKeyStroke(ShowBpelMapperAction.class);
0465: KeyStroke gotoLoggingKey = GoToAction
0466: .getKeyStroke(org.netbeans.modules.bpel.nodes.actions.GoToLoggingAction.class);
0467:
0468: if (gotoSourceKey != null) {
0469: // im1.put(org.netbeans.modules.bpel.nodes.actions.GoToSourceAction.GOTOSOURCE_KEYSTROKE, "gotosource-something"); // NOI18N
0470: im1.put(gotoSourceKey, "gotosource-something"); // NOI18N
0471: im2.put(gotoSourceKey, "gotosource-something"); // NOI18N
0472: }
0473: if (gotoMapperKey != null) {
0474: // im1.put(ShowBpelMapperAction.GOTOMAPPER_KEYSTROKE, "gotomapper-something"); // NOI18N
0475: im1.put(gotoMapperKey, "gotomapper-something"); // NOI18N
0476: im2.put(gotoMapperKey, "gotomapper-something"); // NOI18N
0477: }
0478: if (gotoLoggingKey != null) {
0479: // im1.put(org.netbeans.modules.bpel.nodes.actions.GoToLoggingAction.GOTOLOGGING_KEYSTROKE, "gotologging-something"); // NOI18N
0480: im1.put(gotoLoggingKey, "gotologging-something"); // NOI18N
0481: im2.put(gotoLoggingKey, "gotologging-something"); // NOI18N
0482: }
0483: // im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.ALT_DOWN_MASK), "gotosource-something"); // NOI18N
0484: // im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.ALT_DOWN_MASK), "gotomapper-something"); // NOI18N
0485: // im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.ALT_DOWN_MASK), "gotologging-something"); // NOI18N
0486: // im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_F7, KeyEvent.ALT_DOWN_MASK), "findusages-something"); // NOI18N
0487: im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_M,
0488: KeyEvent.CTRL_DOWN_MASK), "find_next_mex_peer"); // NOI18N
0489: im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTEXT_MENU, 0),
0490: "show_context_menu"); // NOI18N
0491: im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_F10,
0492: KeyEvent.SHIFT_DOWN_MASK), "show_context_menu"); // NOI18N
0493: im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0),
0494: "go_next_hierarchy_component"); // NOI18N
0495: im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
0496: KeyEvent.SHIFT_DOWN_MASK),
0497: "go_previous_hierarchy_component"); // NOI18N
0498: im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
0499: KeyEvent.SHIFT_DOWN_MASK), "collapse-current-pattern"); // NOI18N
0500: im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
0501: "expand-current-pattern"); // NOI18N
0502: im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
0503: KeyEvent.ALT_DOWN_MASK), "expand-all-patterns"); // NOI18N
0504:
0505: im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_C,
0506: KeyEvent.CTRL_DOWN_MASK), "copy-pattern"); // NOI18N
0507: im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_V,
0508: KeyEvent.CTRL_DOWN_MASK), "paste-pattern"); // NOI18N
0509: im1.put(KeyStroke.getKeyStroke(KeyEvent.VK_X,
0510: KeyEvent.CTRL_DOWN_MASK), "cut-pattern"); // NOI18N
0511:
0512: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0),
0513: "rename-something"); // NOI18N
0514: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),
0515: "delete-something"); // NOI18N
0516: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
0517: "cancel-something"); // NOI18N
0518: // im2.put(org.netbeans.modules.bpel.nodes.actions.GoToSourceAction.GOTOSOURCE_KEYSTROKE, "gotosource-something"); // NOI18N
0519: // im2.put(ShowBpelMapperAction.GOTOMAPPER_KEYSTROKE, "gotomapper-something"); // NOI18N
0520: // im2.put(org.netbeans.modules.bpel.nodes.actions.GoToLoggingAction.GOTOLOGGING_KEYSTROKE, "gotologging-something"); // NOI18N
0521: // im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.ALT_DOWN_MASK), "gotosource-something"); // NOI18N
0522: // im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_F7, KeyEvent.ALT_DOWN_MASK), "findusages-something"); // NOI18N
0523: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_M,
0524: KeyEvent.CTRL_DOWN_MASK), "find_next_mex_peer"); // NOI18N
0525: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTEXT_MENU, 0),
0526: "show_context_menu"); // NOI18N
0527: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_F10,
0528: KeyEvent.SHIFT_DOWN_MASK), "show_context_menu"); // NOI18N
0529:
0530: im2
0531: .put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,
0532: KeyEvent.SHIFT_DOWN_MASK),
0533: "go_nearest_right_component"); // NOI18N
0534: // im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_RIGHT, KeyEvent.SHIFT_DOWN_MASK), "go_nearest_right_component"); // NOI18N
0535:
0536: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,
0537: KeyEvent.SHIFT_DOWN_MASK), "go_nearest_left_component"); // NOI18N
0538: // im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_LEFT, KeyEvent.SHIFT_DOWN_MASK), "go_nearest_left_component"); // NOI18N
0539:
0540: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,
0541: KeyEvent.SHIFT_DOWN_MASK), "go_nearest_down_component"); // NOI18N
0542: // im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_DOWN, KeyEvent.SHIFT_DOWN_MASK), "go_nearest_down_component"); // NOI18N
0543:
0544: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP,
0545: KeyEvent.SHIFT_DOWN_MASK), "go_nearest_up_component"); // NOI18N
0546: // im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_KP_UP, KeyEvent.SHIFT_DOWN_MASK), "go_nearest_up_component"); // NOI18N
0547:
0548: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0),
0549: "go_next_hierarchy_component"); // NOI18N
0550: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
0551: KeyEvent.SHIFT_DOWN_MASK),
0552: "go_previous_hierarchy_component"); // NOI18N
0553: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
0554: KeyEvent.SHIFT_DOWN_MASK), "collapse-current-pattern"); // NOI18N
0555: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
0556: "expand-current-pattern"); // NOI18N
0557: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
0558: KeyEvent.ALT_DOWN_MASK), "expand-all-patterns"); // NOI18N
0559:
0560: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_C,
0561: KeyEvent.CTRL_DOWN_MASK), "copy-pattern"); // NOI18N
0562: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_V,
0563: KeyEvent.CTRL_DOWN_MASK), "paste-pattern"); // NOI18N
0564: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_X,
0565: KeyEvent.CTRL_DOWN_MASK), "cut-pattern"); // NOI18N
0566:
0567: // am.put("rename-something", new RenameAction()); // NOI18N
0568: am.put("delete-something", new DeleteAction(this )); // NOI18N
0569: // am.put("cancel-something", new CancelAction()); // NOI18N
0570: am.put("gotosource-something", new GoToSourceAction(this )); // NOI18N
0571: am.put("gotomapper-something", new GoToMapperAction(this )); // NOI18N
0572: am.put("gotologging-something", new GoToLoggingAction(this )); // NOI18N
0573: am.put("findusages-something", new FindUsagesAction(this )); // NOI18N
0574: // am.put("find_next_mex_peer", new CycleMexAction()); // NOI18N
0575: am.put("show_context_menu", new ShowContextMenuAction(this )); // NOI18N
0576: am.put("go_next_hierarchy_component",
0577: new TabToNextComponentAction(this , true)); // NOI18N
0578: am.put("go_previous_hierarchy_component",
0579: new TabToNextComponentAction(this , false)); // NOI18N
0580: //
0581: // am.put("go_nearest_right_component", new GoRightNearestComponentAction()); // NOI18N
0582: // am.put("go_nearest_left_component", new GoLeftNearestComponentAction()); // NOI18N
0583: // am.put("go_nearest_up_component", new GoUpNearestComponentAction()); // NOI18N
0584: // am.put("go_nearest_down_component", new GoDownNearestComponentAction()); // NOI18N
0585: //
0586: am.put("expand-current-pattern",
0587: new ExpandCurrentPatternAction(this )); // NOI18N
0588: am.put("collapse-current-pattern",
0589: new CollapseCurrentPatternAction(this )); // NOI18N
0590: am
0591: .put("expand-all-patterns",
0592: new ExpandAllPatternsAction(this ));
0593: //
0594: // am.put("copy-pattern", new CopyAction()); // NOI18N
0595: // am.put("cut-pattern", new CutAction()); // NOI18N
0596: // am.put("paste-pattern", new PasteAction()); // NOI18N
0597:
0598: /**
0599: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK), "copy-pattern"); // NOI18N
0600: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK), "paste-pattern"); // NOI18N
0601: im2.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_DOWN_MASK), "cut-pattern"); // NOI18N
0602: */
0603: }
0604:
0605: public CollapseExpandDecorationProvider getCollapseExpandDecorationProvider() {
0606: return collapseExpandDectorationProvider;
0607: }
0608:
0609: public DiagramModel getModel() {
0610: return diagramModel;
0611: }
0612:
0613: public FDimension getDiagramSize() {
0614: FDimension dim = getModel().getRootPattern().getBounds()
0615: .getSize();
0616: return dim;
0617: // new FDimension(dim.width + LayoutManager.HSPACING * 2,
0618: // dim.height + LayoutManager.VSPACING * 2);
0619: }
0620:
0621: public void updateAccordingToViewFiltersStatus() {
0622: if (getRootPattern() != null) {
0623: updateAccordingToViewFiltersStatus(getRootPattern());
0624: diagramChanged();
0625: }
0626: }
0627:
0628: private void updateAccordingToViewFiltersStatus(Pattern pattern) {
0629: if (pattern instanceof SequencePattern) {
0630: ((SequencePattern) pattern)
0631: .updateAccordingToViewFiltersStatus();
0632: } else if (pattern instanceof ProcessPattern) {
0633: ((ProcessPattern) pattern)
0634: .updateAccordingToViewFiltersStatus();
0635: }
0636:
0637: if (pattern instanceof CompositePattern) {
0638: for (Pattern p : ((CompositePattern) pattern)
0639: .getNestedPatterns()) {
0640: updateAccordingToViewFiltersStatus(p);
0641: }
0642: }
0643: }
0644:
0645: public void diagramChanged() {
0646: if (getProcessModel() != null
0647: && getBPELModel().getState() == Model.State.VALID
0648: && getModel().getRootPattern() != null) {
0649:
0650: double zoom = getCorrectedZoom();
0651: setToolBarEnabled(true);
0652:
0653: layoutManager.layout(getModel().getRootPattern());
0654:
0655: connectionManager.reconnectAll(getModel().getRootPattern());
0656:
0657: connectionManager.layoutConnections(getModel()
0658: .getRootPattern());
0659:
0660: FDimension dim = getModel().getRootPattern().getBounds()
0661: .getSize();
0662:
0663: int printWidth = (int) Math.round(dim.width + 2
0664: * LayoutManager.HMARGIN);
0665:
0666: int printHeight = (int) Math.round(dim.height + 2
0667: * LayoutManager.VMARGIN);
0668:
0669: putClientProperty(Dimension.class, new Dimension(
0670: printWidth, printHeight));
0671:
0672: processView.revalidate();
0673: consumersView.revalidate();
0674: providersView.revalidate();
0675:
0676: repaint();
0677:
0678: errorPanel.uninstall();
0679:
0680: rightStripe.repaint();
0681: } else {
0682: setToolBarEnabled(false);
0683: errorPanel.install();
0684: }
0685: }
0686:
0687: private void setToolBarEnabled(final boolean enabled) {
0688: zoomManager.setEnabled(enabled);
0689: navigationTools.setEnabled(enabled);
0690:
0691: JComponent toolBar = findToolBar();
0692:
0693: if (toolBar != null) {
0694: setToolBarEnabled(toolBar, enabled);
0695: } else {
0696: SwingUtilities.invokeLater(new Runnable() {
0697: public void run() {
0698: setToolBarEnabled(findToolBar(), enabled);
0699: }
0700: });
0701: }
0702: }
0703:
0704: private void setToolBarEnabled(JComponent toolBar, boolean enabled) {
0705: if (toolBar == null) {
0706: return;
0707: }
0708:
0709: for (Component component : toolBar.getComponents()) {
0710: component.setEnabled(enabled);
0711: }
0712: }
0713:
0714: private JComponent findToolBar() {
0715: for (Component c = getView().getParent(); c != null; c = c
0716: .getParent()) {
0717: if (c instanceof DesignerMultiViewElement) {
0718: return ((DesignerMultiViewElement) c)
0719: .getToolbarRepresentation();
0720: }
0721: }
0722: return null;
0723: }
0724:
0725: public JComponent getView() {
0726: return (errorPanel.isInstalled()) ? errorPanel : this ;
0727: }
0728:
0729: public TopComponent getTopComponent() {
0730: return (TopComponent) SwingUtilities.getAncestorOfClass(
0731: TopComponent.class, this );
0732: }
0733:
0734: public Font getZoomedDiagramFont() {
0735: Font font = DiagramFontUtil.getFont();
0736: return font.deriveFont(font.getSize2D()
0737: * (float) getCorrectedZoom());
0738: }
0739:
0740: public double getZoom() {
0741: return zoomManager.getScale();
0742: }
0743:
0744: public double getCorrectedZoom() {
0745: return zoomManager.getScale()
0746: * DiagramFontUtil.getZoomCorrection();
0747: }
0748:
0749: public Pattern getRootPattern() {
0750: return diagramModel.getRootPattern();
0751: }
0752:
0753: /*
0754: public void paintThumbnail(Graphics g) {
0755: Pattern rootPattern = getRootPattern();
0756:
0757: if (rootPattern == null) return;
0758:
0759: Graphics2D g2 = GUtils.createGraphics(g);
0760:
0761: double zoom = getCorrectedZoom();
0762:
0763: Point p = convertDiagramToScreen(new FPoint(0, 0));
0764: g2.translate(p.x, p.y);
0765: g2.scale(zoom, zoom);
0766:
0767:
0768: Graphics2D g2bw = new BWGraphics2D(g2);
0769:
0770: Rectangle clipBounds = g2.getClipBounds();
0771:
0772: double exWidth = layoutManager.HSPACING * zoom;
0773: double exHeight = layoutManager.VSPACING * zoom;
0774:
0775: FBounds exClipBounds = new FBounds(
0776: clipBounds.x - exWidth,
0777: clipBounds.y - exHeight,
0778: clipBounds.width + 2 * exWidth,
0779: clipBounds.height + 2 * exHeight);
0780:
0781: paintPatternThumbnail(g2, g2bw, exClipBounds, rootPattern);
0782: paintPatternThumbnailConnections(g2, g2bw, rootPattern);
0783: g2.dispose();
0784:
0785: Graphics componentGraphics = g.create();
0786: for (int i = getComponentCount() - 1; i >= 0; i--) {
0787: Component c = getComponent(i);
0788: if (c instanceof GlassPane) {
0789: int tx = c.getX();
0790: int ty = c.getY();
0791: componentGraphics.translate(tx, ty);
0792: ((GlassPane) c).paintThumbnail(componentGraphics);
0793: componentGraphics.translate(-tx, -ty);
0794: }
0795: }
0796: componentGraphics.dispose();
0797: }
0798:
0799: private void paintPatternThumbnail(Graphics2D g2, Graphics2D g2bw,
0800: FBounds clipBounds, Pattern pattern) {
0801: if (!pattern.getBounds().isIntersects(clipBounds)) {
0802: return;
0803: }
0804:
0805: Decoration decoration = getDecoration(pattern);
0806:
0807: if (pattern instanceof CompositePattern) {
0808: CompositePattern composite = (CompositePattern) pattern;
0809:
0810: BorderElement border = composite.getBorder();
0811:
0812: Graphics2D g = (decoration.hasDimmed()) ? g2bw : g2;
0813:
0814: if (border != null) {
0815: border.paintThumbnail(g);
0816: }
0817:
0818: for (VisualElement e : composite.getElements()) {
0819: e.paintThumbnail(g);
0820: }
0821:
0822: for (Pattern p : composite.getNestedPatterns()) {
0823: paintPatternThumbnail(g2, g2bw, clipBounds, p);
0824: }
0825:
0826: if (decoration.hasStroke()) {
0827: decoration.getStroke().paint(g2, composite.createSelection());
0828: }
0829: } else {
0830: Graphics2D g = (decoration.hasDimmed()) ? g2bw : g2;
0831:
0832: for (VisualElement e : pattern.getElements()) {
0833: e.paintThumbnail(g);
0834: }
0835:
0836: if (decoration.hasStroke()) {
0837: decoration.getStroke().paint(g2, pattern.createSelection());
0838: }
0839: }
0840: }
0841:
0842:
0843: private void paintPatternThumbnailConnections(Graphics2D g2,
0844: Graphics2D g2bw, Pattern pattern)
0845: {
0846: if (pattern == null) return;
0847:
0848: if (pattern instanceof CompositePattern) {
0849: CompositePattern composite = (CompositePattern) pattern;
0850: for (Pattern p : composite.getNestedPatterns()) {
0851: paintPatternThumbnailConnections(g2, g2bw, p);
0852: }
0853: }
0854:
0855: Graphics2D g = (getDecoration(pattern).hasDimmed()) ? g2bw : g2;
0856:
0857: for (Connection c : pattern.getConnections()) {
0858: c.paintThumbnail(g);
0859: }
0860: }
0861: */
0862:
0863: // FIXME
0864: // protected void paintChildren(Graphics g) {
0865: // if (!ghost.isEmpty()) return;
0866: // super.paintChildren(g);
0867: // }
0868: //
0869: // protected void printComponent(Graphics g) {
0870: // Dimension s = (Dimension) getClientProperty(Dimension.class);
0871: // if (s == null) return;
0872: //
0873: // Color oldColor = g.getColor();
0874: // g.setColor(getBackground());
0875: // Rectangle clip = g.getClipBounds();
0876: // if (clip != null) {
0877: // g.fillRect(clip.x, clip.y, clip.width, clip.height);
0878: // } else {
0879: // g.fillRect(0, 0, s.width, s.height);
0880: // }
0881: //
0882: // g.setColor(oldColor);
0883: // paintContent(g, 1, true);
0884: // }
0885: protected void printChildren(Graphics g) {
0886: }
0887:
0888: public void goPlaceHolderMode(Pattern clipboard,
0889: boolean isCopyAction) {
0890: if (clipboard == null) {
0891: return;
0892: }
0893: CopyPasteHandler cpHandler = getCopyPasteHandler();
0894: cpHandler.initPlaceHolderMode(clipboard);
0895: setDesignViewMode(isCopyAction ? DesignViewMode.COPY_PLACE_HOLDER
0896: : DesignViewMode.CUT_PLACE_HOLDER);
0897: }
0898:
0899: private void exitPlaceHolderMode() {
0900:
0901: CopyPasteHandler cpHandler = getCopyPasteHandler();
0902: cpHandler.exitPlaceHolderMode();
0903: setDesignViewMode(DesignViewMode.DESIGN);
0904: }
0905:
0906: //FIXME
0907: public FPoint convertScreenToDiagram(Point point) {
0908: return new FPoint(0, 0);
0909: //return convertScreenToDiagram(point, designView.getCorrectedZoom());
0910: }
0911:
0912: //FIXME
0913: public Point convertDiagramToScreen(FPoint point) {
0914: return new Point(0, 0);
0915: //return convertDiagramToScreen(point, designView.getCorrectedZoom());
0916: }
0917:
0918: //FIXME
0919: public static Point convertDiagramToScreen(FPoint topRight,
0920: double zoom) {
0921: return new Point(0, 0);
0922: }
0923:
0924: public Decoration getDecoration(Pattern p) {
0925: return decorationManager.getDecoration(p);
0926: }
0927:
0928: public HelpCtx getHelpCtx() {
0929: HelpCtx helpCtx = new HelpCtx(DesignView.class);
0930: Pattern selected = getSelectionModel().getSelectedPattern();
0931: if (selected == null) {
0932: return helpCtx;
0933: }
0934:
0935: Node node = getNodeForPattern(selected);
0936: if (node == null) {
0937: return helpCtx;
0938: }
0939:
0940: HelpCtx nodeHelpCtx = node.getHelpCtx();
0941:
0942: return nodeHelpCtx == null ? helpCtx : nodeHelpCtx;
0943: }
0944:
0945: public void scrollPatternToView(Pattern pattern) {
0946: consumersView.scrollPatternToView(pattern);
0947: processView.scrollPatternToView(pattern);
0948: providersView.scrollPatternToView(pattern);
0949:
0950: }
0951:
0952: /**
0953: * ensures that components are added to container in correct order.
0954: * GlassPanes should go before Buttons
0955: **/
0956: protected void addImpl(Component comp, Object constraints, int index) {
0957:
0958: int count = getComponentCount();
0959:
0960: if (comp instanceof GlassPane) {
0961: index = 0;
0962: for (int i = 0; i < count; i++) {
0963: Component c = getComponent(i);
0964: if ((c instanceof GlassPane)
0965: || (c instanceof DiagramButton)) {
0966: index = i;
0967: break;
0968:
0969: }
0970: }
0971:
0972: } else if (comp instanceof DiagramButton) {
0973: index = -1;
0974: for (int i = 0; i < count; i++) {
0975: Component c = getComponent(i);
0976: if (c instanceof DiagramButton) {
0977: index = i;
0978: break;
0979:
0980: }
0981: }
0982: }
0983: super .addImpl(comp, constraints, index);
0984: }
0985:
0986: // public void scrollPlaceHolderToView(PlaceHolder ph) {
0987: // if (ph == null){
0988: // return;
0989: // }
0990: // /**
0991: // * Get the position of selected node and scroll view to make
0992: // * the corresponding pattern visible
0993: // **/
0994: //
0995: // FShape shape = ph.getShape();
0996: //
0997: // Point screenTL = convertDiagramToScreen(shape.getTopLeft());
0998: // Point screenBR = convertDiagramToScreen(shape.getBottomRight());
0999: //
1000: // int x1 = Math.max(0, screenTL.x - 8);
1001: // int y1 = Math.max(0, screenTL.y - 32);
1002: //
1003: // int x2 = Math.min(getWidth(), screenBR.x + 8);
1004: // int y2 = Math.min(getHeight(), screenBR.y + 8);
1005: //
1006: // int w = Math.max(1, x2 - x1);
1007: // int h = Math.max(1, y2 - y1);
1008: //
1009: // scrollRectToVisible(new Rectangle(x1, y1, w, h));
1010: // }
1011:
1012: public void scrollSelectedToView() {
1013: SwingUtilities.invokeLater(new Runnable() {
1014: public void run() {
1015: scrollPatternToView(getSelectionModel()
1016: .getSelectedPattern());
1017: }
1018: });
1019: }
1020:
1021: // public void scrollSelectedPlaceHolderToView(){
1022: // SwingUtilities.invokeLater( new Runnable() {
1023: // public void run() {
1024: // getPhSelectionModel().getSelectedPlaceHolder();
1025: // scrollPatternToView(getSelectionModel()
1026: // .getSelectedPattern());
1027: // }
1028: // });
1029: // }
1030:
1031: public ValidationDecorationProvider getValidationDecorationProvider() {
1032: return validationDecorationProvider;
1033: }
1034:
1035: private void loadDecorationProviders() {
1036: selectionDecorationProvider = new SelectionDecorationProvider(
1037: this );
1038: validationDecorationProvider = new ValidationDecorationProvider(
1039: this );
1040:
1041: debuggerDecorationProvider = new DebuggerDecorationProvider(
1042: this );
1043:
1044: toolbarDecorationProvider = new ToolbarDecorationProvider(this );
1045: linkToolDecorationProvider = new LinkToolDecorationProvider(
1046: this );
1047: collapseExpandDectorationProvider = new CollapseExpandDecorationProvider(
1048: this );
1049:
1050: Lookup.Result result = Lookup.getDefault().lookup(
1051: new Lookup.Template(DecorationProviderFactory.class));
1052:
1053: for (Object inst : result.allInstances()) {
1054: if (inst instanceof DecorationProviderFactory) {
1055: ((DecorationProviderFactory) inst).createInstance(this );
1056: }
1057: ;
1058:
1059: if (inst instanceof DebuggerDecorationProvider) {
1060: debuggerDecorationProvider = (DebuggerDecorationProvider) inst;
1061: }
1062:
1063: }
1064: }
1065:
1066: public DnDHandler getDndHandler() {
1067: return dndHandler;
1068: }
1069:
1070: private DesignViewMode getDesignViewMode() {
1071: return designViewMode;
1072: }
1073:
1074: private void setDesignViewMode(DesignViewMode mode) {
1075: if (mode == null) {
1076: return;
1077: }
1078: designViewMode = mode;
1079: }
1080:
1081: public boolean isDesignMode() {
1082: return DesignViewMode.DESIGN.equals(designViewMode);
1083: }
1084: }
|