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.midpnb.propertyeditors;
043:
044: import org.netbeans.modules.vmd.api.model.DesignComponent;
045: import org.netbeans.modules.vmd.api.model.TypeID;
046: import org.netbeans.modules.vmd.midp.actions.GoToSourceSupport;
047: import org.netbeans.modules.vmd.midp.propertyeditors.api.resource.element.PropertyEditorResourceElement;
048: import org.netbeans.modules.vmd.midpnb.components.resources.SimpleCancellableTaskCD;
049:
050: import javax.swing.*;
051: import java.lang.ref.WeakReference;
052: import java.util.Arrays;
053: import java.util.List;
054:
055: /**
056: *
057: * @author Anton Chechel
058: */
059: public class TaskEditorElement extends PropertyEditorResourceElement {
060:
061: private WeakReference<DesignComponent> component;
062:
063: public TaskEditorElement() {
064: initComponents();
065: }
066:
067: public JComponent getJComponent() {
068: return this ;
069: }
070:
071: public TypeID getTypeID() {
072: return SimpleCancellableTaskCD.TYPEID;
073: }
074:
075: public List<String> getPropertyValueNames() {
076: return Arrays.asList(SimpleCancellableTaskCD.PROP_CODE);
077: }
078:
079: @Override
080: public String getResourceNameSuggestion() {
081: return "task"; // NOI18N
082: }
083:
084: public void setDesignComponentWrapper(
085: final DesignComponentWrapper wrapper) {
086: boolean enableGoTo = true;
087: if (wrapper != null) {
088: DesignComponent _component = wrapper.getComponent();
089: if (enableGoTo = _component != null) {
090: component = new WeakReference<DesignComponent>(
091: _component);
092: }
093: } else {
094: component = null;
095: }
096:
097: // UI stuff
098: taskLabel.setEnabled(wrapper != null);
099: gotoButton.setEnabled(wrapper != null && enableGoTo);
100: }
101:
102: /** This method is called from within the constructor to
103: * initialize the form.
104: * WARNING: Do NOT modify this code. The content of this method is
105: * always regenerated by the Form Editor.
106: */
107: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
108: private void initComponents() {
109:
110: taskLabel = new javax.swing.JLabel();
111: gotoButton = new javax.swing.JButton();
112: jScrollPane1 = new javax.swing.JScrollPane();
113: jTextArea1 = new javax.swing.JTextArea();
114:
115: taskLabel.setLabelFor(gotoButton);
116: org.openide.awt.Mnemonics.setLocalizedText(taskLabel,
117: org.openide.util.NbBundle.getMessage(
118: TaskEditorElement.class,
119: "TaskEditorElement.taskLabel.text")); // NOI18N
120: taskLabel.setEnabled(false);
121:
122: org.openide.awt.Mnemonics.setLocalizedText(gotoButton,
123: org.openide.util.NbBundle.getMessage(
124: TaskEditorElement.class,
125: "TaskEditorElement.gotoButton.text")); // NOI18N
126: gotoButton.setEnabled(false);
127: gotoButton
128: .addActionListener(new java.awt.event.ActionListener() {
129: public void actionPerformed(
130: java.awt.event.ActionEvent evt) {
131: gotoButtonActionPerformed(evt);
132: }
133: });
134:
135: jTextArea1.setBackground(javax.swing.UIManager.getDefaults()
136: .getColor("Panel.background"));
137: jTextArea1.setColumns(20);
138: jTextArea1.setEditable(false);
139: jTextArea1.setLineWrap(true);
140: jTextArea1.setRows(5);
141: jTextArea1.setText(org.openide.util.NbBundle.getMessage(
142: TaskEditorElement.class,
143: "TaskEditorElement.jTextArea1.text")); // NOI18N
144: jScrollPane1.setViewportView(jTextArea1);
145:
146: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
147: this );
148: this .setLayout(layout);
149: layout
150: .setHorizontalGroup(layout
151: .createParallelGroup(
152: org.jdesktop.layout.GroupLayout.LEADING)
153: .add(
154: layout
155: .createSequentialGroup()
156: .add(
157: layout
158: .createParallelGroup(
159: org.jdesktop.layout.GroupLayout.LEADING)
160: .add(taskLabel)
161: .add(gotoButton))
162: .add(43, 43, 43))
163: .add(
164: jScrollPane1,
165: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
166: 176, Short.MAX_VALUE));
167: layout
168: .setVerticalGroup(layout
169: .createParallelGroup(
170: org.jdesktop.layout.GroupLayout.LEADING)
171: .add(
172: layout
173: .createSequentialGroup()
174: .add(taskLabel)
175: .addPreferredGap(
176: org.jdesktop.layout.LayoutStyle.RELATED)
177: .add(gotoButton)
178: .addPreferredGap(
179: org.jdesktop.layout.LayoutStyle.RELATED)
180: .add(
181: jScrollPane1,
182: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
183: 122, Short.MAX_VALUE)));
184: }// </editor-fold>//GEN-END:initComponents
185:
186: private void gotoButtonActionPerformed(
187: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gotoButtonActionPerformed
188: if (component != null) {
189: DesignComponent _component = component.get();
190: if (_component != null) {
191: GoToSourceSupport.goToSourceOfComponent(_component);
192: }
193: }
194: }//GEN-LAST:event_gotoButtonActionPerformed
195:
196: // Variables declaration - do not modify
197: // Variables declaration - do not modify//GEN-BEGIN:variables
198: private javax.swing.JButton gotoButton;
199: private javax.swing.JScrollPane jScrollPane1;
200: private javax.swing.JTextArea jTextArea1;
201: private javax.swing.JLabel taskLabel;
202: // End of variables declaration//GEN-END:variables
203: }
|