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-2007 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.api.inspector.common;
042:
043: import java.awt.Image;
044: import java.util.ArrayList;
045: import java.util.Arrays;
046: import java.util.Collection;
047: import java.util.List;
048: import javax.swing.Action;
049: import org.netbeans.modules.vmd.api.inspector.InspectorFolder;
050: import org.netbeans.modules.vmd.api.inspector.InspectorFolderPath;
051: import org.netbeans.modules.vmd.api.inspector.InspectorOrderingController;
052: import org.netbeans.modules.vmd.api.inspector.InspectorOrderingPresenter;
053: import org.netbeans.modules.vmd.api.inspector.InspectorPositionController;
054: import org.netbeans.modules.vmd.api.inspector.InspectorPositionPresenter;
055: import org.netbeans.modules.vmd.api.model.Debug;
056: import org.netbeans.modules.vmd.api.model.DesignComponent;
057: import org.netbeans.modules.vmd.api.model.DesignEventFilter;
058: import org.netbeans.modules.vmd.api.model.TypeID;
059: import org.netbeans.modules.vmd.api.model.presenters.InfoPresenter;
060: import org.netbeans.modules.vmd.api.model.presenters.actions.ActionsSupport;
061:
062: /**
063: *
064: * @author Karol Harezlak
065: */
066:
067: /**
068: * This class suits as a descriptor for the Mobility Visual Designer Navigator node.
069: * InspectorFolder in this class is created based on DesignComponent passed in the class constructor.
070: * This class creates visual representation of DesignComponent in the Mobility Visual Designer Navigator.
071: */
072: public class DesignComponentInspectorFolder extends InspectorFolder {
073:
074: private String displayName;
075: private Image icon;
076: private boolean canRename;
077: private String name;
078: private List<InspectorOrderingController> ocs;
079: private DesignComponent component;
080:
081: /**
082: * Creates DesignComponentInspectorFolder
083: * @param canRename - indicates if name of the InspectorFolder can be changed
084: * @param component - InspectorFolder is created based on this parameter
085: */
086: public DesignComponentInspectorFolder(boolean canRename,
087: DesignComponent component) {
088: assert (component != null);
089: this .component = component;
090: this .canRename = canRename;
091: }
092:
093: public TypeID getTypeID() {
094: return getComponent().getType();
095: }
096:
097: public Long getComponentID() {
098: return getComponent().getComponentID();
099: }
100:
101: public Image getIcon() {
102: getComponent().getDocument().getTransactionManager()
103: .readAccess(new Runnable() {
104: public void run() {
105: InfoPresenter presenter = getComponent()
106: .getPresenter(InfoPresenter.class);
107: if (presenter == null)
108: throw new IllegalStateException(
109: "No InfoPresenter for this component"); //NOI18N
110: icon = presenter
111: .getIcon(InfoPresenter.IconType.COLOR_16x16);
112: }
113: });
114: return icon;
115: }
116:
117: public String getDisplayName() {
118: getComponent().getDocument().getTransactionManager()
119: .readAccess(new Runnable() {
120: public void run() {
121: if (getComponent().getParentComponent() != null)
122: displayName = InfoPresenter
123: .getDisplayName(getComponent());
124: else if (getComponent() == getComponent()
125: .getDocument().getRootComponent())
126: displayName = InfoPresenter
127: .getDisplayName(getComponent());
128: }
129: });
130: return displayName;
131: }
132:
133: public String getHtmlDisplayName() {
134: getComponent().getDocument().getTransactionManager()
135: .readAccess(new Runnable() {
136: public void run() {
137: if (getComponent().getParentComponent() != null)
138: displayName = InfoPresenter
139: .getHtmlDisplayName(getComponent());
140: else if (getComponent() == getComponent()
141: .getDocument().getRootComponent())
142: displayName = InfoPresenter
143: .getHtmlDisplayName(getComponent());
144: }
145: });
146: return displayName;
147: }
148:
149: public boolean isInside(final InspectorFolderPath path,
150: final InspectorFolder folder,
151: final DesignComponent component) {
152: for (InspectorPositionPresenter presenter : getComponent()
153: .getPresenters(InspectorPositionPresenter.class)) {
154: for (InspectorPositionController pc : presenter
155: .getFolderPositionControllers()) {
156: if (pc != null
157: && pc.isInside(path, folder, getComponent()))
158: return true;
159: }
160: }
161: return false;
162: }
163:
164: public Action[] getActions() {
165: return ActionsSupport.createActionsArray(getComponent());
166: }
167:
168: public boolean canRename() {
169: return canRename;
170: }
171:
172: public String getName() {
173: getComponent().getDocument().getTransactionManager()
174: .readAccess(new Runnable() {
175: public void run() {
176: InfoPresenter presenter = getComponent()
177: .getPresenter(InfoPresenter.class);
178: if (presenter != null) {
179: if (presenter.isEditable())
180: name = presenter.getEditableName();
181: } else
182: Debug
183: .warning("No info presenter for component :"
184: + getComponent()); //NOI18N
185: }
186: });
187: return name;
188: }
189:
190: public InspectorOrderingController[] getOrderingControllers() {
191: getComponent().getDocument().getTransactionManager()
192: .readAccess(new Runnable() {
193: public void run() {
194: Collection<? extends InspectorOrderingPresenter> presenters = getComponent()
195: .getPresenters(
196: InspectorOrderingPresenter.class);
197: if (presenters == null || presenters.isEmpty()) {
198: ocs = null;
199: return;
200: }
201: ocs = new ArrayList<InspectorOrderingController>();
202: for (InspectorOrderingPresenter presenter : presenters) {
203: ocs.addAll(Arrays.asList(presenter
204: .getFolderOrderingControllers()));
205: }
206: }
207: });
208: if (ocs == null)
209: return null;
210: return ocs.toArray(new InspectorOrderingController[ocs.size()]);
211: }
212:
213: protected DesignEventFilter getEventFilter() {
214: return null;
215: }
216:
217: protected DesignComponent getComponent() {
218: return component;
219: }
220:
221: }
|