KickJava   Java API By Example, From Geeks To Geeks.

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


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.ViewComponentCookie;
25 import org.openide.nodes.Node;
26 import org.openide.util.HelpCtx;
27 import org.openide.util.NbBundle;
28
29 /**
30  * Interface GotoType defines a place where an editor can be opened
31  * for a particular component.
32  *
33  * @author Nathan Fiedler
34  */

35 public abstract class GotoType {
36
37     /**
38      * Finds the component that the given node represents. Subclasses may
39      * wish to override this to retrieve the component in different manner.
40      *
41      * @param node the Node from which to get the component.
42      * @return the component, or null if none.
43      */

44     protected Component getComponent(Node node) {
45         return XAMUtils.getComponent(node);
46     }
47
48     /**
49      * Help context for the goto type.
50      *
51      * @return the help context
52      */

53     public HelpCtx getHelpCtx() {
54         return HelpCtx.DEFAULT_HELP;
55     }
56
57     /**
58      * Returns the name of this type, to be displayed in a menu. Ideally
59      * this should be the name of the view or editor that this type will
60      * open the component in (e.g. "Design").
61      *
62      * @return name of this type.
63      */

64     public String JavaDoc getName() {
65         return NbBundle.getMessage(GotoType.class, "LBL_GoTo");
66     }
67
68     /**
69      * Return the view in which this type will show the component.
70      *
71      * @return component view.
72      */

73     protected abstract ViewComponentCookie.View getView();
74
75     /**
76      * Show the given node in the view this type represents.
77      *
78      * @param node the Node to be shown.
79      */

80     public void show(Node node) {
81         Component comp = getComponent(node);
82         ViewComponentCookie.View view = getView();
83         ViewComponentCookie cookie = XAMUtils.getViewCookie(comp, view);
84         if (cookie != null) {
85             cookie.view(view, comp);
86         }
87     }
88 }
89
Popular Tags