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.common;
043:
044: import org.netbeans.modules.vmd.api.model.Debug;
045: import org.netbeans.modules.vmd.api.model.DesignComponent;
046: import org.netbeans.modules.vmd.api.properties.DesignPropertyEditor;
047: import org.openide.DialogDescriptor;
048: import org.openide.DialogDisplayer;
049: import org.openide.explorer.propertysheet.ExPropertyEditor;
050: import org.openide.explorer.propertysheet.PropertyPanel;
051: import org.openide.nodes.Node.Property;
052: import org.openide.nodes.Node.PropertySet;
053: import org.openide.nodes.Sheet;
054: import org.openide.util.Exceptions;
055: import org.openide.util.HelpCtx;
056:
057: import java.lang.reflect.InvocationTargetException;
058: import org.netbeans.modules.vmd.api.io.ActiveViewSupport;
059: import org.netbeans.modules.vmd.api.io.DataEditorView;
060: import org.netbeans.modules.vmd.properties.PropertiesNodesManager;
061: import org.openide.util.lookup.InstanceContent;
062:
063: /**
064: *
065: * @author Karol Harezlak
066: */
067: /**
068: * This class contains satic support methods to help maintaince Visual Designer properties shown
069: * in the Properties Window.
070: */
071: public final class PropertiesSupport {
072: /**
073: * DataEditorView Tag. This tag hides Netbeans Property Window
074: */
075: public static final String DO_NOT_OPEN_PROPERTIES_WINDOW_TAG = "DO_NOT_OPEN_PROPERTIES_WINDOW"; //NOI18N
076:
077: private PropertiesSupport() {
078: }
079:
080: /**
081: * Returns propertie's Sheet object for given view and DesignComponent.
082: * @param view DataEditor view for searching properties Sheet
083: * @param component given DesignComponent
084: * @return instance of properties Sheet
085: */
086: public static Sheet getSheet(DataEditorView view,
087: DesignComponent component) {
088: return PropertiesNodesManager.getInstance(view).getSheet(
089: component);
090: }
091:
092: /**
093: * This method connects DataEditorView with InstnceContect. It means that Instance contect with
094: * the set of Nodes (PropertiesNode) can be share throug DataEditorViews (TopComponents).
095: * This way developer can share the same InstanteContent (set of Nodes) through more that one DataEditorView.
096: * @param view instance of DataEditorView to connect with given InstanceContent
097: * @param ic InstanceContent to connect with given DataEditorView
098: */
099: public static void addInstanceContent(DataEditorView view,
100: InstanceContent ic) {
101: PropertiesNodesManager.getInstance(view).add(ic);
102: }
103:
104: /**
105: * It shows custom property editor window for given DesignComponent and the name of the property.
106: * NOTE: Multi selection is not supported.
107: * WARNING: Do NOT invoke this method from inside of the read transaction.
108: * @param component instance of DesignComponent
109: * @param propertyName property name of the property which contains custom porperty editor to show
110: */
111: public synchronized static void showCustomPropertyEditor(
112: DesignComponent component, String propertyName) {
113: boolean propertyEditorExists = false;
114: if (component.getDocument().getTransactionManager()
115: .isWriteAccess())
116: Debug
117: .warning("Calling PropertiesSupport.showPropertyEditorForCurrentComponent form write transaction may generate problems"); //NOI18N
118: DataEditorView view = ActiveViewSupport.getDefault()
119: .getActiveView();
120: assert (view != null);
121: Sheet sheet = PropertiesNodesManager.getInstance(view)
122: .getSheet(component);
123: for (PropertySet propertySet : sheet.toArray()) {
124: for (Property property : propertySet.getProperties()) {
125: if (propertyName.equals(property.getName())) {
126: PropertyPanel propertyPanel = new PropertyPanel(
127: property, PropertyPanel.PREF_CUSTOM_EDITOR);
128: propertyEditorExists = true;
129: propertyPanel.setChangeImmediate(false);
130: DialogDescriptor dd = new DialogDescriptor(
131: propertyPanel, property.getDisplayName(),
132: true, null); // NOI18N
133: Object helpID = property
134: .getValue(ExPropertyEditor.PROPERTY_HELP_ID);
135: if (helpID != null) {
136: assert helpID instanceof String;
137: HelpCtx helpCtx = new HelpCtx((String) helpID);
138: dd.setHelpCtx(helpCtx);
139: }
140: property.getPropertyEditor().getCustomEditor(); // initialization of CustomEditor, issue #113195
141: Object res = DialogDisplayer.getDefault()
142: .notify(dd);
143:
144: if (res == DialogDescriptor.OK_OPTION) {
145: ((DesignPropertyEditor) property
146: .getPropertyEditor())
147: .customEditorOKButtonPressed();
148: try {
149: property.setValue(property
150: .getPropertyEditor().getValue());
151: } catch (IllegalAccessException ex) {
152: Exceptions.printStackTrace(ex);
153: } catch (IllegalArgumentException ex) {
154: Exceptions.printStackTrace(ex);
155: } catch (InvocationTargetException ex) {
156: Exceptions.printStackTrace(ex);
157: }
158: }
159: return;
160: }
161: }
162: }
163: if (!propertyEditorExists) {
164: throw new IllegalArgumentException("PropertyEditor for "
165: + propertyName + " not found in the component "
166: + component); //NOI18N
167: }
168: }
169:
170: }
|