KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > MessageNameConfigurationPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * MessageNameConfigurationPanel.java
22  *
23  * Created on September 8, 2006, 12:53 PM
24  */

25
26 package org.netbeans.modules.xml.wsdl.ui.view;
27
28 import java.util.ArrayList JavaDoc;
29 import java.util.List JavaDoc;
30 import javax.swing.DefaultComboBoxModel JavaDoc;
31 import javax.swing.JPanel JavaDoc;
32 import javax.swing.JTextField JavaDoc;
33 import org.openide.DialogDisplayer;
34 import org.openide.NotifyDescriptor;
35
36 /**
37  *
38  * @author radval
39  */

40 public class MessageNameConfigurationPanel extends javax.swing.JPanel JavaDoc {
41     
42     private JPanel JavaDoc mPartsTablePanel;
43     
44     private List JavaDoc mExistingMessagesList = new ArrayList JavaDoc();
45     
46     private boolean mIsNewMessage = true;
47     
48     private JTextField JavaDoc messageEditor = new JTextField JavaDoc();
49     
50     /** Creates new form MessageNameConfigurationPanel */
51     public MessageNameConfigurationPanel() {
52         initComponents();
53     }
54     
55     public MessageNameConfigurationPanel(JPanel JavaDoc partsTablePanel) {
56         this.mPartsTablePanel = partsTablePanel;
57         initComponents();
58         initGUI();
59     }
60     
61     /** This method is called from within the constructor to
62      * initialize the form.
63      * WARNING: Do NOT modify this code. The content of this method is
64      * always regenerated by the Form Editor.
65      */

66     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
67
private void initComponents() {
68         messageNameComboBox = new javax.swing.JComboBox JavaDoc();
69
70         messageNameComboBox.setEditable(true);
71         messageNameComboBox.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(new String JavaDoc[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
72         messageNameComboBox.addItemListener(new java.awt.event.ItemListener JavaDoc() {
73             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
74                 messageNameComboBoxItemStateChanged(evt);
75             }
76         });
77         messageNameComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
78             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
79                 messageNameComboBoxActionPerformed(evt);
80             }
81         });
82         messageNameComboBox.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
83             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
84                 messageNameComboBoxKeyReleased(evt);
85             }
86         });
87
88         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
89         this.setLayout(layout);
90         layout.setHorizontalGroup(
91             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
92             .add(messageNameComboBox, 0, 209, Short.MAX_VALUE)
93         );
94         layout.setVerticalGroup(
95             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
96             .add(messageNameComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
97         );
98     }// </editor-fold>//GEN-END:initComponents
99

100     private void messageNameComboBoxKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_messageNameComboBoxKeyReleased
101

102     }//GEN-LAST:event_messageNameComboBoxKeyReleased
103

104     public boolean isNewMessage() {
105         return this.mIsNewMessage;
106     }
107     
108     public String JavaDoc getMessageName() {
109         return messageEditor.getText();
110     }
111     
112     public void setMessages(String JavaDoc[] existingMessages, String JavaDoc newMessageName, javax.swing.event.DocumentListener JavaDoc msgNameDocumentListener) {
113             int existingMessageCount = 0;
114             if(existingMessages != null) {
115                 existingMessageCount = existingMessages.length;
116             }
117             
118             String JavaDoc[] messages = new String JavaDoc[existingMessageCount +1];
119             messages[0] = newMessageName;
120             
121             for(int i = 0; i < existingMessageCount; i++) {
122                 messages[i+1] = existingMessages[i];
123                 mExistingMessagesList.add(existingMessages[i]);
124             }
125             
126             DefaultComboBoxModel JavaDoc messageModel = new DefaultComboBoxModel JavaDoc(messages);
127             this.messageNameComboBox.setModel(messageModel);
128             
129             if(msgNameDocumentListener != null) {
130                 messageEditor.getDocument().addDocumentListener(msgNameDocumentListener);
131             }
132     }
133     
134     private void initGUI() {
135         messageEditor = (JTextField JavaDoc)this.messageNameComboBox.getEditor().getEditorComponent();
136         
137         
138     }
139     
140     private void messageNameComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_messageNameComboBoxActionPerformed
141

142     }//GEN-LAST:event_messageNameComboBoxActionPerformed
143

144     private void messageNameComboBoxItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_messageNameComboBoxItemStateChanged
145
String JavaDoc messageName = (String JavaDoc) evt.getItem();
146         if(mExistingMessagesList.contains(messageName)) {
147             this.mPartsTablePanel.setEnabled(false);
148             mIsNewMessage = false;
149         } else {
150             this.mPartsTablePanel.setEnabled(true);
151             mIsNewMessage = true;
152         }
153         
154         this.mPartsTablePanel.revalidate();
155     }//GEN-LAST:event_messageNameComboBoxItemStateChanged
156

157     
158     // Variables declaration - do not modify//GEN-BEGIN:variables
159
private javax.swing.JComboBox JavaDoc messageNameComboBox;
160     // End of variables declaration//GEN-END:variables
161

162 }
163
Popular Tags