001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.xslt.tmap.nodes.properties;
020:
021: import java.beans.FeatureDescriptor;
022: import java.beans.PropertyChangeEvent;
023: import java.beans.PropertyChangeListener;
024: import java.beans.PropertyEditor;
025: import javax.swing.JPanel;
026: import org.netbeans.modules.soa.ui.form.ReusablePropertyCustomizer;
027: import org.openide.explorer.propertysheet.PropertyEnv;
028: import org.openide.nodes.Node;
029:
030: /**
031: *
032: * @author Vitaly Bychkov
033: * @author nk160297
034: */
035: public class StringPropertyCustomizer extends JPanel implements
036: PropertyChangeListener, ReusablePropertyCustomizer {
037:
038: private PropertyEditor myPropertyEditor;
039: private PropertyEnv myPropertyEnv;
040:
041: /** Creates new form StringPropertyCustomizer */
042: public StringPropertyCustomizer() {
043: super ();
044: //
045: initComponents();
046: }
047:
048: public synchronized void init(PropertyEnv propertyEnv,
049: PropertyEditor propertyEditor) {
050: assert propertyEnv != null && propertyEditor != null : "Wrong params"; // NOI18N
051: //
052: if (myPropertyEnv == propertyEnv) {
053: return; // Prevent repeated initialization
054: }
055: //
056: if (myPropertyEnv != null) {
057: myPropertyEnv.removePropertyChangeListener(this );
058: }
059: //
060: myPropertyEnv = propertyEnv;
061: myPropertyEditor = propertyEditor;
062: //
063: myPropertyEnv.addPropertyChangeListener(this );
064: //
065: // The Ok button will not work without the following line!!!
066: myPropertyEnv.setState(PropertyEnv.STATE_NEEDS_VALIDATION);
067: //
068: String value = propertyEditor.getAsText();
069: if (value == null) {
070: fldText.setText("");
071: } else {
072: fldText.setText(value);
073: }
074: //
075: FeatureDescriptor desc = myPropertyEnv.getFeatureDescriptor();
076: if (desc instanceof Node.Property) {
077: Node.Property prop = (Node.Property) desc;
078: boolean editable = prop.canWrite();
079: //
080: if (editable) {
081: Boolean canEditAsText = (Boolean) prop
082: .getValue("canEditAsText");
083: if (canEditAsText != null) {
084: editable = canEditAsText.booleanValue();
085: }
086: }
087: //
088: fldText.setEditable(editable);
089: }
090: }
091:
092: public void propertyChange(PropertyChangeEvent event) {
093: if (PropertyEnv.PROP_STATE.equals(event.getPropertyName())
094: && event.getNewValue() == PropertyEnv.STATE_VALID) {
095: try {
096: String currText = fldText.getText();
097: myPropertyEditor.setAsText(currText);
098: } catch (PropertyVetoError ex) {
099: myPropertyEnv
100: .setState(PropertyEnv.STATE_NEEDS_VALIDATION);
101: PropertyVetoError.defaultProcessing(ex);
102: }
103: }
104: }
105:
106: /** This method is called from within the constructor to
107: * initialize the form.
108: * WARNING: Do NOT modify this code. The content of this method is
109: * always regenerated by the Form Editor.
110: */
111: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
112: private void initComponents() {
113: jScrollPane1 = new javax.swing.JScrollPane();
114: fldText = new javax.swing.JTextArea();
115:
116: fldText.setColumns(20);
117: fldText.setRows(5);
118: jScrollPane1.setViewportView(fldText);
119:
120: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
121: this );
122: this .setLayout(layout);
123: layout.setHorizontalGroup(layout.createParallelGroup(
124: org.jdesktop.layout.GroupLayout.LEADING).add(
125: layout.createSequentialGroup().addContainerGap().add(
126: jScrollPane1,
127: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
128: 484, Short.MAX_VALUE).addContainerGap()));
129: layout.setVerticalGroup(layout.createParallelGroup(
130: org.jdesktop.layout.GroupLayout.LEADING).add(
131: layout.createSequentialGroup().addContainerGap().add(
132: jScrollPane1,
133: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
134: 160, Short.MAX_VALUE)));
135: }// </editor-fold>//GEN-END:initComponents
136:
137: // Variables declaration - do not modify//GEN-BEGIN:variables
138: private javax.swing.JTextArea fldText;
139: private javax.swing.JScrollPane jScrollPane1;
140: // End of variables declaration//GEN-END:variables
141:
142: }
|