KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > MultiComponentActionManager


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * MultiComponentActionManager.java
22  *
23  * Created on June 9, 2006, 1:47 AM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.abe;
30
31 import java.awt.Component JavaDoc;
32 import java.awt.event.MouseEvent JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import javax.swing.JPopupMenu JavaDoc;
35 import org.openide.awt.MouseUtils;
36 import org.openide.nodes.Node;
37 import org.openide.nodes.NodeOp;
38
39 /**
40  *
41  * @author girix
42  */

43 public class MultiComponentActionManager {
44     InstanceUIContext context;
45     /** Creates a new instance of MultiComponentActionManager */
46     public MultiComponentActionManager(InstanceUIContext context) {
47         this.context = context;
48     }
49     
50     public void deleteSelectedComponents(){
51         ArrayList JavaDoc<ABEBaseDropPanel> list = context.getComponentSelectionManager().getSelectedComponentList();
52         ArrayList JavaDoc<Component JavaDoc> cloneList = (ArrayList JavaDoc<Component JavaDoc>) list.clone();
53         context.getComponentSelectionManager().clearPreviousSelectedComponents(true);
54         for(Component JavaDoc comp: cloneList){
55             //list.remove(comp);
56
if(comp instanceof TagPanel){
57                 ((TagPanel) comp).removeElement();
58             }else if(comp instanceof AttributePanel){
59                 ((AttributePanel)comp).removeAttribute();
60             }else if(comp instanceof CompositorPanel){
61                 ((CompositorPanel)comp).removeCompositor();
62             }
63         }
64     }
65     
66     public void showPopupMenu(MouseEvent JavaDoc e, ABEBaseDropPanel eventSource) {
67         ArrayList JavaDoc<ABEBaseDropPanel> list = context.getComponentSelectionManager().getSelectedComponentList();
68
69         if(!list.contains(eventSource)){
70             //right click was performed on some other place than insde already selected items
71
//so just remove previous selections and select the current component
72
context.getComponentSelectionManager().
73                     setSelectedComponent(eventSource);
74             //now use this list for right click action
75
list = context.getComponentSelectionManager().getSelectedComponentList();
76         }
77         
78         ArrayList JavaDoc<Node> nodeList = new ArrayList JavaDoc<Node>();
79         for(Component JavaDoc component: list){
80             if(component instanceof ABEBaseDropPanel &&
81                     ((ABEBaseDropPanel)component).getNBNode() != null){
82                 nodeList.add(((ABEBaseDropPanel)component).getNBNode());
83             }
84         }
85         if(nodeList.size() > 0){
86             //context.getTopComponent().setActivatedNodes(nodeList.toArray(new Node[0]));
87
//get the available action in a popup menu
88
//JPopupMenu menu = nodeList.get(0).getContextMenu();
89
JPopupMenu JavaDoc menu = NodeOp.findContextMenu(nodeList.toArray(new Node[nodeList.size()]));
90             //show the Popup
91
Component JavaDoc hostComponent = e.getComponent();
92             menu.show(hostComponent, e.getX(), e.getY());
93         }
94     }
95     
96 }
97
Popular Tags