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-2007 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.uml.core.requirementsframework;
043:
044: import java.awt.Component;
045: import java.awt.event.ItemEvent;
046: import java.awt.event.ItemListener;
047: import javax.swing.DefaultComboBoxModel;
048: import javax.swing.JLabel;
049: import javax.swing.JList;
050: import javax.swing.ListCellRenderer;
051: import org.netbeans.modules.uml.core.support.umlmessagingcore.UMLMessagingHelper;
052: import org.openide.util.NbBundle;
053:
054: /**
055: *
056: * @author Sheryl
057: */
058: public class RequirementProviderPanel extends javax.swing.JPanel {
059:
060: private IRequirementsManager m_Manager = null;
061:
062: /** Creates new form RequirementProviderPanel */
063: public RequirementProviderPanel(IRequirementsManager manager) {
064: initComponents();
065: m_Manager = manager;
066: IRequirementsProvider[] descriptors = manager.getAddIns();
067: DefaultComboBoxModel model = new DefaultComboBoxModel(
068: descriptors);
069: jComboBox1.setModel(model);
070: ProviderCellRenderer renderer = new ProviderCellRenderer();
071: jComboBox1.setRenderer(renderer);
072: updateState();
073: }
074:
075: public void process() {
076: IRequirementsProvider provider = (IRequirementsProvider) jComboBox1
077: .getSelectedItem();
078:
079: try {
080: IRequirementSource source = provider.displaySources();
081: if (source != null) {
082: if (m_Manager instanceof IRequirementsManager) {
083: IRequirementsManager reqManager = (IRequirementsManager) m_Manager;
084: reqManager.processSource(source);
085: }
086: }
087: } catch (RequirementsException ev) {
088: UMLMessagingHelper helper = new UMLMessagingHelper();
089: helper.sendExceptionMessage(ev);
090: }
091: }
092:
093: private IRequirementsManager getManager() {
094: return m_Manager;
095: }
096:
097: private void updateState() {
098: IRequirementsProvider provider = (IRequirementsProvider) jComboBox1
099: .getSelectedItem();
100: jTextArea1.setText(provider.getDescription());
101: }
102:
103: private static class ProviderCellRenderer extends JLabel implements
104: ListCellRenderer {
105:
106: public ProviderCellRenderer() {
107: setOpaque(true);
108: }
109:
110: public Component getListCellRendererComponent(JList list,
111: Object value, int index, boolean isSelected,
112: boolean cellHasFocus) {
113:
114: if (value instanceof IRequirementsProvider) {
115: setText(((IRequirementsProvider) value)
116: .getDisplayName());
117: } else {
118: setText(value == null ? " " : value.toString()); // NOI18N
119: }
120: if (isSelected) {
121: setBackground(list.getSelectionBackground());
122: setForeground(list.getSelectionForeground());
123: } else {
124: setBackground(list.getBackground());
125: setForeground(list.getForeground());
126:
127: }
128: return this ;
129: }
130:
131: }
132:
133: /** This method is called from within the constructor to
134: * initialize the form.
135: * WARNING: Do NOT modify this code. The content of this method is
136: * always regenerated by the Form Editor.
137: */
138: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
139: private void initComponents() {
140: jComboBox1 = new javax.swing.JComboBox();
141: jScrollPane1 = new javax.swing.JScrollPane();
142: jTextArea1 = new javax.swing.JTextArea();
143: jLabel1 = new javax.swing.JLabel();
144: jLabel2 = new javax.swing.JLabel();
145:
146: jComboBox1
147: .setModel(new javax.swing.DefaultComboBoxModel(
148: new String[] { "Item 1", "Item 2", "Item 3",
149: "Item 4" }));
150: jComboBox1.addItemListener(new java.awt.event.ItemListener() {
151: public void itemStateChanged(java.awt.event.ItemEvent evt) {
152: jComboBox1ItemStateChanged(evt);
153: }
154: });
155:
156: jComboBox1
157: .getAccessibleContext()
158: .setAccessibleName(
159: java.util.ResourceBundle
160: .getBundle(
161: "org/netbeans/modules/uml/core/requirementsframework/Bundle")
162: .getString(
163: "ACSN_Requirement_Provider_Name"));
164: jComboBox1.getAccessibleContext().setAccessibleDescription(
165: org.openide.util.NbBundle.getMessage(
166: RequirementProviderPanel.class,
167: "ACSD_Requirement_Provider_Name"));
168: jComboBox1.getAccessibleContext().setAccessibleParent(this );
169:
170: jTextArea1.setColumns(20);
171: jTextArea1.setEditable(false);
172: jTextArea1.setRows(5);
173: jScrollPane1.setViewportView(jTextArea1);
174: jTextArea1.getAccessibleContext().setAccessibleName(
175: org.openide.util.NbBundle.getMessage(
176: RequirementProviderPanel.class,
177: "ACSN_Requirement_Provider_Description"));
178: jTextArea1.getAccessibleContext().setAccessibleDescription(
179: org.openide.util.NbBundle.getMessage(
180: RequirementProviderPanel.class,
181: "ACSD_Requirement_Provider_Description"));
182:
183: jLabel1.setLabelFor(jComboBox1);
184: org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
185: org.openide.util.NbBundle.getMessage(
186: RequirementProviderPanel.class,
187: "LBL_RequirementProviderPanel_Providers"));
188: jLabel1.getAccessibleContext().setAccessibleName(
189: org.openide.util.NbBundle.getMessage(
190: RequirementProviderPanel.class,
191: "ACSN_Requirement_Provider_Name"));
192: jLabel1
193: .getAccessibleContext()
194: .setAccessibleDescription(
195: java.util.ResourceBundle
196: .getBundle(
197: "org/netbeans/modules/uml/core/requirementsframework/Bundle")
198: .getString(
199: "ACSD_Requirement_Provider_Name"));
200: jLabel1.getAccessibleContext().setAccessibleParent(this );
201:
202: jLabel2.setLabelFor(jTextArea1);
203: org.openide.awt.Mnemonics
204: .setLocalizedText(
205: jLabel2,
206: org.openide.util.NbBundle
207: .getMessage(
208: RequirementProviderPanel.class,
209: "LBL_RequirementProviderPanel_ProviderDescritpion"));
210: jLabel2.getAccessibleContext().setAccessibleName(
211: org.openide.util.NbBundle.getMessage(
212: RequirementProviderPanel.class,
213: "ACSN_Requirement_Provider_Description"));
214: jLabel2.getAccessibleContext().setAccessibleDescription(
215: org.openide.util.NbBundle.getMessage(
216: RequirementProviderPanel.class,
217: "ACSD_Requirement_Provider_Description"));
218:
219: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
220: this );
221: this .setLayout(layout);
222: layout
223: .setHorizontalGroup(layout
224: .createParallelGroup(
225: org.jdesktop.layout.GroupLayout.LEADING)
226: .add(
227: layout
228: .createSequentialGroup()
229: .addContainerGap()
230: .add(
231: layout
232: .createParallelGroup(
233: org.jdesktop.layout.GroupLayout.LEADING)
234: .add(
235: jScrollPane1,
236: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
237: 349,
238: Short.MAX_VALUE)
239: .add(
240: jComboBox1,
241: 0,
242: 349,
243: Short.MAX_VALUE)
244: .add(jLabel1)
245: .add(jLabel2))
246: .addContainerGap()));
247: layout
248: .setVerticalGroup(layout
249: .createParallelGroup(
250: org.jdesktop.layout.GroupLayout.LEADING)
251: .add(
252: layout
253: .createSequentialGroup()
254: .addContainerGap()
255: .add(jLabel1)
256: .addPreferredGap(
257: org.jdesktop.layout.LayoutStyle.RELATED)
258: .add(
259: jComboBox1,
260: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
261: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
262: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
263: .addPreferredGap(
264: org.jdesktop.layout.LayoutStyle.RELATED,
265: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
266: Short.MAX_VALUE)
267: .add(jLabel2)
268: .addPreferredGap(
269: org.jdesktop.layout.LayoutStyle.RELATED)
270: .add(
271: jScrollPane1,
272: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
273: 170,
274: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
275: .addContainerGap()));
276: }// </editor-fold>//GEN-END:initComponents
277:
278: private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox1ItemStateChanged
279: updateState();
280: }//GEN-LAST:event_jComboBox1ItemStateChanged
281:
282: // Variables declaration - do not modify//GEN-BEGIN:variables
283: private javax.swing.JComboBox jComboBox1;
284: private javax.swing.JLabel jLabel1;
285: private javax.swing.JLabel jLabel2;
286: private javax.swing.JScrollPane jScrollPane1;
287: private javax.swing.JTextArea jTextArea1;
288: // End of variables declaration//GEN-END:variables
289:
290: }
|