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;
021:
022: import java.awt.event.MouseAdapter;
023: import java.awt.event.MouseEvent;
024: import javax.swing.JPopupMenu;
025: import org.netbeans.modules.bpel.design.model.patterns.Pattern;
026:
027: import org.netbeans.modules.bpel.design.selection.EntitySelectionModel;
028: import org.netbeans.modules.bpel.design.selection.PlaceHolderManager;
029: import org.netbeans.modules.bpel.design.DiagramView;
030:
031: public class MouseHandler extends MouseAdapter {
032:
033: private DiagramView diagramView;
034:
035: public MouseHandler(DiagramView diagramView) {
036: this .diagramView = diagramView;
037: diagramView.addMouseListener(this );
038: }
039:
040: public DiagramView getDiagramView() {
041: return diagramView;
042: }
043:
044: public void cancel() {
045: getNameEditor().cancelEdit();
046: }
047:
048: public void mousePressed(MouseEvent e) {
049: getDiagramView().requestFocus();
050: Pattern p = getDiagramView().findPattern(e.getPoint());
051:
052: getSelectionModel().setSelectedPattern(p);
053:
054: maybeShowPopup(e);
055: }
056:
057: public void mouseReleased(MouseEvent e) {
058: maybeShowPopup(e);
059: }
060:
061: public void mouseClicked(MouseEvent e) {
062: if (e.getClickCount() == 2) {
063: getNameEditor().startEdit(e.getPoint());
064: if (!getNameEditor().isActive()) {
065: Pattern selected = getSelectionModel()
066: .getSelectedPattern();
067: if (selected != null) {
068: getDiagramView().getDesignView()
069: .performDefaultAction(selected);
070: }
071: }
072: }
073: }
074:
075: public NameEditor getNameEditor() {
076: return getDiagramView().getNameEditor();
077: }
078:
079: public EntitySelectionModel getSelectionModel() {
080: return getDiagramView().getDesignView().getSelectionModel();
081: }
082:
083: public boolean maybeShowPopup(MouseEvent e) {
084: if (!e.isPopupTrigger())
085: return false;
086:
087: Pattern pattern = getSelectionModel().getSelectedPattern();
088:
089: if (pattern == null)
090: return false;
091:
092: JPopupMenu popup = pattern.createPopupMenu();
093:
094: if (popup == null)
095: return false;
096:
097: popup.show(e.getComponent(), e.getX(), e.getY());
098:
099: return true;
100: }
101:
102: }
|