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