KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > nodes > categorized > customizer > RedefineCreator


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.schema.ui.nodes.categorized.customizer;
21
22 import java.io.IOException JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25 import org.netbeans.modules.xml.schema.model.Redefine;
26 import org.netbeans.modules.xml.schema.model.Schema;
27 import org.netbeans.modules.xml.schema.model.SchemaModel;
28 import org.netbeans.modules.xml.xam.Model;
29 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
30 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceCreator;
31 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceDecorator;
32 import org.openide.nodes.Node;
33 import org.openide.util.HelpCtx;
34 import org.openide.util.NbBundle;
35
36 /**
37  * A redefine creator.
38  *
39  * @author Administrator
40  * @author Nathan Fiedler
41  */

42 public class RedefineCreator extends ExternalReferenceCreator<Schema> {
43     /** silence compiler warnings */
44     private static final long serialVersionUID = 1L;
45     /** The decorator for this redefine. */
46     private ExternalReferenceDecorator decorator;
47
48     /**
49      * Creates a new instance of RedefineCreator
50      *
51      * @param schema component to contain the redefine(s).
52      */

53     public RedefineCreator(Schema schema) {
54         super(schema, null);
55     }
56
57     @Override JavaDoc
58     public void applyChanges() throws IOException JavaDoc {
59         super.applyChanges();
60         Schema schema = getModelComponent();
61         SchemaModel model = schema.getModel();
62         List JavaDoc<Node> nodes = getSelectedNodes();
63         for (Node node : nodes) {
64             Redefine imp = model.getFactory().createRedefine();
65             // Save the location.
66
imp.setSchemaLocation(getLocation(node));
67             schema.addExternalReference(imp);
68         }
69     }
70
71     public HelpCtx getHelpCtx() {
72         return new HelpCtx(RedefineCreator.class);
73     }
74
75     protected String JavaDoc getTargetNamespace(Model model) {
76         return ((SchemaModel) model).getSchema().getTargetNamespace();
77     }
78
79     @SuppressWarnings JavaDoc("unchecked")
80     protected Map JavaDoc<String JavaDoc, String JavaDoc> getPrefixes(Model model) {
81         SchemaModel sm = (SchemaModel) model;
82         AbstractDocumentComponent schema =
83                 (AbstractDocumentComponent) sm.getSchema();
84         return schema.getPrefixes();
85     }
86
87     protected ExternalReferenceDecorator getNodeDecorator() {
88         if (decorator == null) {
89             decorator = new SchemaReferenceDecorator(this);
90         }
91         return decorator;
92     }
93
94     public boolean mustNamespaceDiffer() {
95         return false;
96     }
97
98     protected String JavaDoc referenceTypeName() {
99         return NbBundle.getMessage(RedefineCreator.class,
100                 "LBL_RedefineCreator_Type");
101     }
102 }
103
Popular Tags