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:
042: package org.netbeans.modules.vmd.api.properties;
043:
044: import org.netbeans.modules.vmd.api.model.DesignComponent;
045: import org.netbeans.modules.vmd.api.model.DesignEvent;
046: import org.netbeans.modules.vmd.api.model.DesignEventFilter;
047: import org.netbeans.modules.vmd.api.model.PresenterEvent;
048: import java.util.ArrayList;
049: import java.util.List;
050:
051: /**
052: *
053: * @author Karol Harezlak
054: */
055: /**
056: * This class is a default implmentation of PropertiesPresenter. It helps in easy way to compose
057: * and provide infomrmations neccessary to create DesignComponent properties visiable in
058: * the Properties Window.
059: */
060: public class DefaultPropertiesPresenter extends PropertiesPresenter {
061:
062: private static final String NULL_DEFAULT = "Null DefaultPropertyEditorSupport"; //NOI18N
063: private List<DesignPropertyDescriptor> descriptors;
064: private List<String> categories;
065: private String category;
066: private DesignEventFilterResolver designEventFilterResolver;
067:
068: /**
069: * Creates instances of the PropertiesPresenter.
070: */
071: public DefaultPropertiesPresenter() {
072: descriptors = new ArrayList<DesignPropertyDescriptor>();
073: categories = new ArrayList<String>();
074: }
075:
076: /**
077: * Creates instances of the PropertiesPresenter. Use this constructor if you'd like to
078: * provide DesignEventFilterResolver to controll execution of designChange method of this
079: * presenter.
080: * @param designEventFilterResolver
081: */
082: public DefaultPropertiesPresenter(
083: DesignEventFilterResolver designEventFilterResolver) {
084: this ();
085: this .designEventFilterResolver = designEventFilterResolver;
086: }
087:
088: /**
089: * Based on this methods DesignPropertyEditor is created and automatically added to the list of DesignPropertyDesicriptors
090: * available for this presenter.
091: * @param displayName display name of this property created based on this DesignPropertyDescriptor.
092: * This String represent display name of the property shown in the Properties Window.
093: * @param toolTip tool tip shown for this property in the Properties Window.
094: * @param propertyEditor custom property editor
095: * @param propertyNames names of the PropertyDescriptors connected with this DesignPropertyDescriptor
096: * @return instance of DefaultPropertiesPresenter
097: */
098: public DefaultPropertiesPresenter addProperty(String displayName,
099: String toolTip, DesignPropertyEditor propertyEditor,
100: String... propertyNames) {
101: if (propertyNames.length < 1) {
102: throw new IllegalArgumentException(); //NOI18N
103: }
104: if (propertyEditor == null) {
105: throw new IllegalArgumentException(NULL_DEFAULT);
106: }
107: descriptors.add(DesignPropertyDescriptor.create(displayName,
108: toolTip, category, propertyEditor, propertyEditor
109: .getClass(), propertyNames));
110: return this ;
111: }
112:
113: /**
114: * Based on this methods DesignPropertyEditor is created and automatically added to the list of DesignPropertyDesicriptors
115: * available for this presenter.
116: * @param displayName display name of this property created based on this DesignPropertyDescriptor.
117: * This String represent display name of the property shown in the Properties Window.
118: * @param propertyEditor custom property editor
119: * @param propertyNames names of the PropertyDescriptors connected with this DesignPropertyDescriptor
120: * @return instance of DefaultPropertiesPresenter
121: */
122: public DefaultPropertiesPresenter addProperty(String displayName,
123: DesignPropertyEditor propertyEditor,
124: String... propertyNames) {
125: if (propertyNames.length < 1) {
126: throw new IllegalArgumentException(); //NOI18N
127: }
128: if (propertyEditor == null) {
129: throw new IllegalArgumentException(NULL_DEFAULT);
130: }
131: descriptors.add(DesignPropertyDescriptor.create(displayName,
132: displayName, category, propertyEditor, propertyEditor
133: .getClass(), propertyNames));
134: return this ;
135: }
136:
137: /** Based on this methods DesignPropertyEditor is created and automatically added to the list of DesignPropertyDesicriptors
138: * available for this presenter.
139: * @param propertyCategory property's category as a String
140: * @return instance of DefaultPropertiesPresenter
141: */
142: public DefaultPropertiesPresenter addPropertiesCategory(
143: String propertyCategory) {
144: assert propertyCategory != null : " Group category cant be null"; // NOI18N
145: this .category = propertyCategory;
146: if (!categories.contains(propertyCategory)) {
147: categories.add(propertyCategory);
148: }
149: return this ;
150: }
151:
152: /**
153: * Returns list of DesignPropertyEditors.
154: * @return list od DesignPropertyDescriptors
155: */
156: public List<DesignPropertyDescriptor> getDesignPropertyDescriptors() {
157: return descriptors;
158: }
159:
160: /**
161: * Returns custom property editor for the property .
162: * @return category
163: */
164: public List<String> getPropertiesCategories() {
165: return categories;
166: }
167:
168: protected void notifyAttached(DesignComponent component) {
169: for (DesignPropertyDescriptor designerPropertyDescriptor : getDesignPropertyDescriptors()) {
170: if (designerPropertyDescriptor.getPropertyEditor() != null) {
171: designerPropertyDescriptor.getPropertyEditor().init(
172: component);
173: }
174: designerPropertyDescriptor.init(component);
175: }
176: }
177:
178: protected void notifyDetached(DesignComponent component) {
179: descriptors = null;
180: categories = null;
181: category = null;
182: designEventFilterResolver = null;
183: }
184:
185: protected DesignEventFilter getEventFilter() {
186: if (designEventFilterResolver != null) {
187: return designEventFilterResolver
188: .getEventFilter(getComponent());
189: }
190: return null;
191: }
192:
193: protected void designChanged(DesignEvent event) {
194: for (DesignPropertyDescriptor designerPropertyDescriptor : getDesignPropertyDescriptors()) {
195: DesignPropertyEditor propertyEditor = designerPropertyDescriptor
196: .getPropertyEditor();
197: if (designerPropertyDescriptor.getPropertyEditor() != null) {
198: propertyEditor.notifyDesignChanged(event);
199: }
200: }
201: }
202:
203: protected void presenterChanged(PresenterEvent event) {
204: }
205: }
|