KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xam > ui > customizer > AbstractReferenceCustomizer


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.customizer;
21
22 import java.util.Map JavaDoc;
23 import org.netbeans.modules.xml.xam.Component;
24 import org.netbeans.modules.xml.xam.Model;
25 import org.openide.explorer.ExplorerManager;
26 import org.openide.nodes.Node;
27
28 /**
29  * Abstract base class for external reference customizers.
30  *
31  * @author Ajit Bhate
32  * @author Nathan Fiedler
33  */

34 public abstract class AbstractReferenceCustomizer<T extends Component>
35         extends AbstractComponentCustomizer<T> {
36     /** silence compiler warnings */
37     private static final long serialVersionUID = 1L;
38     /** The explorer manager for the node view. */
39     protected ExplorerManager explorerManager;
40
41     /**
42      * Creates new form ExternalReferenceCustomizer
43      *
44      * @param component external reference to customize.
45      */

46     public AbstractReferenceCustomizer(T component) {
47         super(component);
48     }
49
50     /**
51      * Create an ExternalReferenceNode with the given delegate node.
52      *
53      * @param node delegate Node.
54      * @return new ExternalReferenceNode.
55      */

56     public abstract ExternalReferenceDataNode createExternalReferenceNode(
57             Node original);
58
59     /**
60      * Creates the root node of the file selection tree.
61      */

62     protected abstract Node createRootNode();
63
64     /**
65      * Return the target namespace of the given model.
66      *
67      * @param model the model for which to get the namespace.
68      * @return target namespace, or null if none.
69      */

70     protected abstract String JavaDoc getTargetNamespace(Model model);
71
72     /**
73      * Return the model of the component being customized.
74      *
75      * @return component model.
76      */

77     public Model getComponentModel() {
78         return getModelComponent().getModel();
79     }
80
81     /**
82      * Return the target namespace of the model that contains the
83      * component being customized.
84      *
85      * @return target namespace, or null if none.
86      */

87     public String JavaDoc getTargetNamespace() {
88         return getTargetNamespace(getModelComponent().getModel());
89     }
90
91     /**
92      * Return the existing external reference prefixes for the given model.
93      *
94      * @param model the model for which to get the namespace.
95      * @return set of prefixes; empty if none.
96      */

97     protected abstract Map JavaDoc<String JavaDoc, String JavaDoc> getPrefixes(Model model);
98
99     /**
100      * Returns the NodeDecorator for this customizer, if any.
101      *
102      * @return node decorator for files nodes, or null if none.
103      */

104     protected abstract ExternalReferenceDecorator getNodeDecorator();
105
106     /**
107      * Load the component values into the interface widgets. Do not, under
108      * any circumstances, create interface components and add them to the
109      * customizer. This instance is cached and re-used over and over again.
110      */

111     protected abstract void initializeUI();
112
113     /**
114      * Indicates if the namespace value must be different than that of
115      * the model containing the component being customized. If false,
116      * then the opposite must hold - the namespace must be the same.
117      * The one exception is if the namespace is not defined at all.
118      *
119      * @return true if namespace must differ, false if same.
120      */

121     public abstract boolean mustNamespaceDiffer();
122
123     public void reset() {
124         initializeUI();
125         // Rebuild the node tree and view to ensure we display the
126
// latest available files in the project.
127
Node root = createRootNode();
128         explorerManager.setRootContext(root);
129         setSaveEnabled(false);
130         setResetEnabled(false);
131         showMessage(null);
132     }
133
134     /**
135      * Display the given message, or reset the message label to blank.
136      *
137      * @param msg message to show, or null to hide messages.
138      */

139     protected abstract void showMessage(String JavaDoc msg);
140 }
141
Popular Tags