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.api.inspector;
042:
043: import java.awt.Image;
044: import javax.swing.Action;
045: import org.netbeans.modules.vmd.api.model.DesignComponent;
046: import org.netbeans.modules.vmd.api.model.DesignEvent;
047: import org.netbeans.modules.vmd.api.model.DesignEventFilter;
048: import org.netbeans.modules.vmd.api.model.PresenterEvent;
049: import org.netbeans.modules.vmd.api.model.TypeID;
050: import org.netbeans.modules.vmd.api.model.presenters.actions.AddAction;
051:
052: /**
053: *
054: * @author Karol Harezlak
055: */
056:
057: /**
058: * Implementation of InspectorFolderPresenter. This class attached to the
059: * DesignComponent creates category in the tree structure of Mobility Visiula Designer Navigator.
060: * Category doesn't represent particular component and could be used (for example)
061: * to keep different types of folders separated in different categories like Commands, Items etc.
062: */
063:
064: public final class InspectorFolderCategoryPresenter extends
065: InspectorFolderPresenter {
066:
067: private CategoryFolder folder;
068: private TypeID typeID;
069: private Image icon;
070: private TypeID[] filtersTypeID;
071: private InspectorOrderingController[] orderingControllers;
072: private String displayName;
073: private TypeID parentTypeID;
074:
075: /**
076: * Creates InspectorFolderCategoryPresenter object.
077: * <p>Note: It's not possible to change name of the category folder created by this presenter.</p>
078: *
079: * @param displayName category folder display name
080: * @param typeID TypeID connected with this category folder
081: * @param icon image icon, visual representation of the category folder
082: * @param filtersTypeID array of allowed TypeIDs underneath of this category
083: * @param parentTypeID parent components TypeId of the component to which this presenter is attached to
084: * @param orderingControllers array of InspectorOrderingControllers available for this presenter
085: */
086: public InspectorFolderCategoryPresenter(String displayName,
087: TypeID typeID, Image icon, TypeID[] filtersTypeID,
088: TypeID parentTypeID,
089: InspectorOrderingController... orderingControllers) {
090: this .displayName = displayName;
091: this .typeID = typeID;
092: this .icon = icon;
093: this .filtersTypeID = filtersTypeID;
094: this .orderingControllers = orderingControllers;
095: this .parentTypeID = parentTypeID;
096: }
097:
098: /**
099: * Returns category InspectorFolder.
100: * @return category folder
101: */
102: public InspectorFolder getFolder() {
103: if (folder == null) {
104: folder = new CategoryFolder(displayName, typeID, icon,
105: filtersTypeID, orderingControllers);
106: }
107: return folder;
108: }
109:
110: protected void notifyAttached(DesignComponent component) {
111: }
112:
113: protected void notifyDetached(DesignComponent component) {
114: }
115:
116: protected DesignEventFilter getEventFilter() {
117: return null;
118: }
119:
120: protected void designChanged(DesignEvent event) {
121: }
122:
123: protected void presenterChanged(PresenterEvent event) {
124: }
125:
126: private class CategoryFolder extends InspectorFolder {
127:
128: private Image icon;
129: private String displayName;
130: private InspectorOrderingController[] orderingControllers;
131: private TypeID typeID;
132: private AddAction[] addAction;
133: private TypeID[] filtersTypeID;
134:
135: public CategoryFolder(String displayName, TypeID typeID,
136: Image icon, TypeID[] filtersTypeID,
137: InspectorOrderingController[] orderingControllers) {
138:
139: if (typeID == null) {
140: throw new IllegalArgumentException(
141: "TypeID cant be null InspectorFolderPresenter: "
142: + getComponent()); //NOI18N
143: }
144: this .displayName = displayName;
145: this .icon = icon;
146: this .orderingControllers = orderingControllers;
147: this .typeID = typeID;
148: this .filtersTypeID = filtersTypeID;
149: }
150:
151: public TypeID getTypeID() {
152: return typeID;
153: }
154:
155: public Long getComponentID() {
156: return getComponent().getComponentID();
157: }
158:
159: public Image getIcon() {
160: return icon;
161: }
162:
163: public String getDisplayName() {
164: return displayName;
165: }
166:
167: public String getName() {
168: return displayName;
169: }
170:
171: public Action[] getActions() {
172: if (addAction == null) {
173: addAction = new AddAction[] { AddAction
174: .getInstance(filtersTypeID) };
175: }
176: addAction[0].setComponent(getComponent());
177: return addAction;
178: }
179:
180: public boolean canRename() {
181: return false;
182: }
183:
184: public InspectorOrderingController[] getOrderingControllers() {
185: return orderingControllers;
186: }
187:
188: public boolean isInside(InspectorFolderPath path,
189: InspectorFolder folder, DesignComponent component) {
190: if (parentTypeID != null
191: && component.getParentComponent().getType().equals(
192: parentTypeID)) {
193: return false;
194: }
195: if (getComponent().getType().equals(
196: path.getLastElement().getTypeID())
197: && path.getLastElement().getComponentID().equals(
198: getComponentID())) {
199: return true;
200: }
201: return false;
202: }
203:
204: public String getHtmlDisplayName() {
205: return displayName;
206: }
207: }
208: }
|