001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.vmd.structure.registry;
042:
043: import org.netbeans.api.visual.widget.Widget;
044: import org.netbeans.modules.vmd.api.io.DataEditorView;
045: import org.netbeans.modules.vmd.api.io.DataObjectContext;
046: import org.netbeans.modules.vmd.api.model.*;
047: import org.openide.awt.UndoRedo;
048: import org.openide.util.HelpCtx;
049: import org.openide.util.Utilities;
050: import org.openide.util.NbBundle;
051:
052: import javax.swing.*;
053: import java.awt.*;
054: import java.io.IOException;
055: import java.util.Collection;
056: import java.util.Collections;
057:
058: /**
059: * @author David Kaspar
060: */
061: public class RegistryEditorView implements DataEditorView,
062: DescriptorRegistryListener {
063:
064: private static final long serialVersionUID = 3328221238376153199L;
065:
066: static final String REGISTRY_ID = "registry"; // NOI18N
067:
068: private DataObjectContext context;
069: private transient DescriptorRegistry registry;
070:
071: private transient JToolBar toolbarRepresentation;
072: private transient JScrollPane scrollPane;
073: private transient RegistryScene scene;
074: private transient JComponent view;
075:
076: public RegistryEditorView() {
077: }
078:
079: public RegistryEditorView(DataObjectContext context) {
080: this .context = context;
081: init();
082: }
083:
084: private void init() {
085: registry = DescriptorRegistry.getDescriptorRegistry(context
086: .getProjectType(), context.getProjectID());
087: scene = new RegistryScene();
088: view = scene.createView();
089: scrollPane = new JScrollPane(view);
090: toolbarRepresentation = new JToolBar();
091: toolbarRepresentation.setFloatable(false);
092: }
093:
094: public DataObjectContext getContext() {
095: return context;
096: }
097:
098: public Kind getKind() {
099: return Kind.MODEL;
100: }
101:
102: public boolean canShowSideWindows() {
103: return true;
104: }
105:
106: public Collection<String> getTags() {
107: return Collections.emptySet();
108: }
109:
110: public String preferredID() {
111: return REGISTRY_ID;
112: }
113:
114: public String getDisplayName() {
115: return NbBundle.getMessage(RegistryEditorView.class,
116: "TITLE_RegistryView"); // NOI18N
117: }
118:
119: public HelpCtx getHelpCtx() {
120: return new HelpCtx(RegistryEditorView.class);
121: }
122:
123: public JComponent getVisualRepresentation() {
124: return scrollPane;
125: }
126:
127: public JComponent getToolbarRepresentation() {
128: return toolbarRepresentation;
129: }
130:
131: public UndoRedo getUndoRedo() {
132: return null;
133: }
134:
135: public void componentOpened() {
136: registry.addRegistryListener(this );
137: }
138:
139: public void componentClosed() {
140: registry.removeRegistryListener(this );
141: }
142:
143: public void componentShowing() {
144: }
145:
146: public void componentHidden() {
147: }
148:
149: public void componentActivated() {
150: }
151:
152: public void componentDeactivated() {
153: }
154:
155: public int getOpenPriority() {
156: return getOrder();
157: }
158:
159: public int getEditPriority() {
160: return -getOrder();
161: }
162:
163: public int getOrder() {
164: return 12;
165: }
166:
167: public void descriptorRegistryUpdated() {
168: SwingUtilities.invokeLater(new Runnable() {
169: public void run() {
170: update();
171: }
172: });
173: }
174:
175: private void update() {
176: registry.readAccess(new Runnable() {
177: public void run() {
178: RegistryWidget widget = new RegistryWidget(scene,
179: false, null, NbBundle.getMessage(
180: RegistryEditorView.class,
181: "DISP_Descriptors")); // NOI18N
182: Collection<ComponentDescriptor> descriptors = registry
183: .getComponentDescriptors();
184: scene.clear();
185: scene.addRootNode("descriptors", widget); // NOI18N
186: updateForSuper(descriptors, null, widget);
187:
188: widget = new RegistryWidget(scene, false, null,
189: NbBundle.getMessage(RegistryEditorView.class,
190: "DISP_Producers")); // NOI18N
191: scene.addRootNode("producers", widget); // NOI18N
192: for (ComponentProducer producer : registry
193: .getComponentProducers()) {
194: PaletteDescriptor paletteDescriptor = producer
195: .getPaletteDescriptor();
196: Widget sub;
197: if (paletteDescriptor != null) {
198: String smallIcon = paletteDescriptor
199: .getSmallIcon();
200: Image image = smallIcon != null ? Utilities
201: .loadImage(smallIcon) : null;
202: sub = new RegistryWidget(scene, true, image,
203: paletteDescriptor.getDisplayName());
204: } else
205: sub = new RegistryWidget(scene, false, null,
206: producer.getMainComponentTypeID()
207: .toString());
208: widget.addSub("producer:"
209: + producer.getProducerID(), sub); // NOI18N
210: }
211:
212: scene.validate();
213: }
214: });
215: }
216:
217: private void updateForSuper(
218: Collection<ComponentDescriptor> descriptors,
219: ComponentDescriptor super Descriptor, RegistryWidget widget) {
220: for (ComponentDescriptor componentDescriptor : descriptors) {
221: if (componentDescriptor.getSuperDescriptor() == super Descriptor) {
222: PaletteDescriptor paletteDescriptor = componentDescriptor
223: .getPaletteDescriptor();
224: RegistryWidget sub;
225: if (paletteDescriptor != null) {
226: String smallIcon = paletteDescriptor.getSmallIcon();
227: Image image = smallIcon != null ? Utilities
228: .loadImage(smallIcon) : null;
229: sub = new RegistryWidget(scene, true, image,
230: paletteDescriptor.getDisplayName());
231: } else
232: sub = new RegistryWidget(scene, false, null,
233: componentDescriptor.getTypeDescriptor()
234: .getThisType().toString());
235: widget.addSub("descriptor:"
236: + componentDescriptor.getTypeDescriptor()
237: .getThisType(), sub);
238:
239: updateForSuper(descriptors, componentDescriptor, sub);
240: }
241: }
242: }
243:
244: private void writeObject(java.io.ObjectOutputStream out)
245: throws IOException {
246: out.writeObject(context);
247: }
248:
249: private void readObject(java.io.ObjectInputStream in)
250: throws IOException, ClassNotFoundException {
251: Object object = in.readObject();
252: if (!(object instanceof DataObjectContext))
253: throw new ClassNotFoundException(
254: "DataObjectContext expected but not found"); // NOI18N
255: context = (DataObjectContext) object;
256: init();
257: }
258:
259: }
|