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.properties;
043:
044: import java.lang.reflect.InvocationTargetException;
045: import org.netbeans.modules.vmd.api.properties.DesignPropertyEditor;
046: import org.netbeans.modules.vmd.api.properties.DesignPropertyDescriptor;
047: import org.netbeans.modules.vmd.api.properties.GroupValue;
048:
049: /**
050: *
051: * @author Karol Harezlak
052: */
053: public final class AdvancedPropertySupport extends
054: DefaultPropertySupport {
055:
056: private String displayName;
057: private GroupValue value;
058:
059: public AdvancedPropertySupport(
060: final DesignPropertyDescriptor designerPropertyDescriptor,
061: Class type) {
062: super (designerPropertyDescriptor, type);
063: }
064:
065: public Object getValue() throws IllegalAccessException,
066: InvocationTargetException {
067: return value;
068: }
069:
070: public void setValue(final Object value)
071: throws IllegalAccessException, IllegalArgumentException,
072: InvocationTargetException {
073: if (getPropertyEditor() instanceof DesignPropertyEditor) {
074: DesignPropertyEditor propertyEditor = (DesignPropertyEditor) getPropertyEditor();
075: if (propertyEditor.canEditAsText() != null)
076: setValue("canEditAsText", propertyEditor
077: .canEditAsText()); //NOI18N
078: }
079: if (value instanceof GroupValue) {
080: this .value = (GroupValue) value;
081: if (getPropertyEditor() instanceof DesignPropertyEditor)
082: SaveToModelSupport.saveToModel(
083: getDesignPropertyDescriptor().getComponent(),
084: this .value,
085: (DesignPropertyEditor) getPropertyEditor());
086: else
087: SaveToModelSupport.saveToModel(
088: getDesignPropertyDescriptor().getComponent(),
089: this .value, null);
090: } else
091: throw new IllegalArgumentException("Wrong type"); //NOI18N
092: }
093:
094: public String getHtmlDisplayName() {
095: if (getDesignPropertyDescriptor().getPropertyNames().isEmpty())
096: return getDesignPropertyDescriptor()
097: .getPropertyDisplayName();
098:
099: getDesignPropertyDescriptor().getComponent().getDocument()
100: .getTransactionManager().readAccess(new Runnable() {
101: public void run() {
102: boolean isDefault = false;
103:
104: for (String propertyName : getDesignPropertyDescriptor()
105: .getPropertyNames()) {
106: if (getDesignPropertyDescriptor()
107: .getComponent().isDefaultValue(
108: propertyName)) {
109: isDefault = false;
110: return;
111: }
112: }
113: if (isDefault)
114: displayName = getDesignPropertyDescriptor()
115: .getPropertyDisplayName();
116: else
117: displayName = "<b>"
118: + getDesignPropertyDescriptor()
119: .getPropertyDisplayName()
120: + "</b>"; // NOI18N
121: }
122: });
123:
124: return displayName;
125: }
126:
127: protected void update() {
128: this .value = new GroupValue(getDesignPropertyDescriptor()
129: .getPropertyNames());
130: if (getDesignPropertyDescriptor().getPropertyNames() != null
131: && !getDesignPropertyDescriptor().getPropertyNames()
132: .isEmpty()) {
133: for (String propertyName : getDesignPropertyDescriptor()
134: .getPropertyNames()) {
135: value.putValue(propertyName, readPropertyValue(
136: getDesignPropertyDescriptor().getComponent(),
137: propertyName));
138: }
139: }
140: if (getPropertyEditor() instanceof DesignPropertyEditor) {
141: DesignPropertyEditor propertyEditor = (DesignPropertyEditor) getPropertyEditor();
142: propertyEditor.resolve(getDesignPropertyDescriptor()
143: .getComponent(), getDesignPropertyDescriptor()
144: .getPropertyNames(), this .value, this ,
145: getDesignPropertyDescriptor()
146: .getPropertyDisplayName());
147: propertyEditor.resolveInplaceEditor(propertyEditor
148: .getInplaceEditor());
149: String title = propertyEditor.getCustomEditorTitle();
150: if (title != null)
151: setValue(PROPERTY_CUSTOM_EDITOR_TITLE, title);
152: }
153: }
154:
155: }
|