001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * MultiComponentActionManager.java
044: *
045: * Created on June 9, 2006, 1:47 AM
046: *
047: * To change this template, choose Tools | Template Manager
048: * and open the template in the editor.
049: */
050:
051: package org.netbeans.modules.xml.schema.abe;
052:
053: import java.awt.Component;
054: import java.awt.event.KeyEvent;
055: import java.awt.event.MouseEvent;
056: import java.util.ArrayList;
057: import javax.swing.JPopupMenu;
058: import org.openide.awt.MouseUtils;
059: import org.openide.nodes.Node;
060: import org.openide.nodes.NodeOp;
061:
062: /**
063: *
064: * @author girix
065: */
066: public class MultiComponentActionManager {
067: InstanceUIContext context;
068:
069: /** Creates a new instance of MultiComponentActionManager */
070: public MultiComponentActionManager(InstanceUIContext context) {
071: this .context = context;
072: }
073:
074: public void deleteSelectedComponents() {
075: ArrayList<ABEBaseDropPanel> list = context
076: .getComponentSelectionManager()
077: .getSelectedComponentList();
078: ArrayList<Component> cloneList = (ArrayList<Component>) list
079: .clone();
080: context.getComponentSelectionManager()
081: .clearPreviousSelectedComponents(true);
082: for (Component comp : cloneList) {
083: //list.remove(comp);
084: if (comp instanceof TagPanel) {
085: ((TagPanel) comp).removeElement();
086: } else if (comp instanceof AttributePanel) {
087: ((AttributePanel) comp).removeAttribute();
088: } else if (comp instanceof CompositorPanel) {
089: ((CompositorPanel) comp).removeCompositor();
090: }
091: }
092: }
093:
094: public void showPopupMenu(MouseEvent e, ABEBaseDropPanel eventSource) {
095: ArrayList<ABEBaseDropPanel> list = context
096: .getComponentSelectionManager()
097: .getSelectedComponentList();
098:
099: if (!list.contains(eventSource)) {
100: //right click was performed on some other place than insde already selected items
101: //so just remove previous selections and select the current component
102: context.getComponentSelectionManager()
103: .setSelectedComponent(eventSource);
104: //now use this list for right click action
105: list = context.getComponentSelectionManager()
106: .getSelectedComponentList();
107: }
108:
109: ArrayList<Node> nodeList = new ArrayList<Node>();
110: for (Component component : list) {
111: if (component instanceof ABEBaseDropPanel
112: && ((ABEBaseDropPanel) component).getNBNode() != null) {
113: nodeList
114: .add(((ABEBaseDropPanel) component).getNBNode());
115: }
116: }
117: if (nodeList.size() > 0) {
118: //context.getTopComponent().setActivatedNodes(nodeList.toArray(new Node[0]));
119: //get the available action in a popup menu
120: //JPopupMenu menu = nodeList.get(0).getContextMenu();
121: JPopupMenu menu = NodeOp.findContextMenu(nodeList
122: .toArray(new Node[nodeList.size()]));
123: //show the Popup
124: Component hostComponent = e.getComponent();
125: menu.show(hostComponent, e.getX(), e.getY());
126: }
127: }
128:
129: public void showPopupMenu(KeyEvent e, ABEBaseDropPanel eventSource) {
130: ArrayList<ABEBaseDropPanel> list = context
131: .getComponentSelectionManager()
132: .getSelectedComponentList();
133:
134: if (!list.contains(eventSource)) {
135: //right click was performed on some other place than insde already selected items
136: //so just remove previous selections and select the current component
137: context.getComponentSelectionManager()
138: .setSelectedComponent(eventSource);
139: //now use this list for right click action
140: list = context.getComponentSelectionManager()
141: .getSelectedComponentList();
142: }
143:
144: ArrayList<Node> nodeList = new ArrayList<Node>();
145: for (Component component : list) {
146: if (component instanceof ABEBaseDropPanel
147: && ((ABEBaseDropPanel) component).getNBNode() != null) {
148: nodeList
149: .add(((ABEBaseDropPanel) component).getNBNode());
150: }
151: }
152: if (nodeList.size() > 0) {
153: //context.getTopComponent().setActivatedNodes(nodeList.toArray(new Node[0]));
154: //get the available action in a popup menu
155: //JPopupMenu menu = nodeList.get(0).getContextMenu();
156: JPopupMenu menu = NodeOp.findContextMenu(nodeList
157: .toArray(new Node[nodeList.size()]));
158: //show the Popup
159: Component hostComponent = e.getComponent();
160: menu.show(hostComponent, hostComponent.getWidth() / 3,
161: hostComponent.getHeight() / 2);
162: }
163: }
164:
165: }
|