KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xam > ui > actions > AbstractShowComponentAction


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 package org.netbeans.modules.xml.xam.ui.actions;
21
22 import org.netbeans.modules.xml.xam.Component;
23 import org.netbeans.modules.xml.xam.ui.XAMUtils;
24 import org.netbeans.modules.xml.xam.ui.cookies.GetComponentCookie;
25 import org.netbeans.modules.xml.xam.ui.cookies.ViewComponentCookie;
26 import org.openide.nodes.Node;
27 import org.openide.util.actions.CookieAction;
28
29 /**
30  * Base class for all actions which show a component in a particular view.
31  *
32  * @author Ajit Bhate
33  * @author Nathan Fiedler
34  */

35 public abstract class AbstractShowComponentAction extends CookieAction {
36     /** silence compiler warnings */
37     private static final long serialVersionUID = 1L;
38
39     /**
40      * Creates a new instance of AbstractShowComponentAction.
41      */

42     public AbstractShowComponentAction() {
43         super();
44     }
45
46     protected boolean asynchronous() {
47         return false;
48     }
49
50     protected final boolean enable(Node[] nodes) {
51         return nodes != null && super.enable(nodes) &&
52                 XAMUtils.getViewCookie(XAMUtils.getComponent(
53                 nodes[0]), getView()) != null;
54     }
55
56     protected void performAction(Node[] nodes) {
57         Component comp = XAMUtils.getComponent(nodes[0]);
58         ViewComponentCookie.View view = getView();
59         ViewComponentCookie cookie = XAMUtils.getViewCookie(comp, view);
60         if (cookie != null) {
61             cookie.view(view, comp);
62         }
63     }
64
65     /**
66      * Return the view in which this action will show the component.
67      *
68      * @return component view.
69      */

70     protected abstract ViewComponentCookie.View getView();
71
72     protected int mode() {
73         return MODE_EXACTLY_ONE;
74     }
75
76     protected Class JavaDoc[] cookieClasses() {
77         return new Class JavaDoc[]{
78             GetComponentCookie.class,
79             Component.class
80         };
81     }
82 }
83
Popular Tags