KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > ejb > DDChangesPanel


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.ddloaders.ejb;
21
22 import java.awt.Component JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Iterator JavaDoc;
25
26 import javax.swing.*;
27 import javax.swing.border.EmptyBorder JavaDoc;
28 import javax.swing.event.ListSelectionListener JavaDoc;
29 import javax.swing.event.ListSelectionEvent JavaDoc;
30
31 import org.openide.util.NbBundle;
32 import org.openide.filesystems.FileStateInvalidException;
33
34 /** Panel that contains list of changes for deployment descriptor
35  * to accomodate recent servlet modification.
36  *
37  * @author Radim Kubacki
38  */

39 public class DDChangesPanel extends JPanel {
40     
41     private JPanel changesPanel;
42     private JScrollPane jScrollPane1;
43     /* pkg private */ JList changesList;
44     
45     /* pkg private */ DefaultListModel listModel;
46     
47     /** Initializes the Form */
48     public DDChangesPanel (String JavaDoc caption, final JButton processButton) {
49         setLayout (new java.awt.BorderLayout JavaDoc (0, 12));
50         setBorder (new EmptyBorder JavaDoc (12, 12, 11, 0));
51         
52         JTextArea text = new JTextArea ();
53         text.setEnabled (false);
54         text.setEditable (false);
55         text.setDisabledTextColor (UIManager.getColor ("Label.foreground")); // NOI18N
56
text.setBackground (UIManager.getColor ("Label.background")); // NOI18N
57
text.setLineWrap (true);
58         text.setWrapStyleWord (true);
59         text.setText (caption);
60         add (text, "North"); // NOI18N
61

62         changesPanel = new JPanel ();
63         changesPanel.setLayout (new java.awt.BorderLayout JavaDoc (5, 5));
64         
65         JLabel changesLabel = new JLabel ();
66         changesLabel.setText (NbBundle.getMessage (DDChangesPanel.class, "LAB_ChangesList"));
67         changesLabel.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage (DDChangesPanel.class, "ACS_ChangesListA11yDesc")); // NOI18N
68
changesPanel.add (changesLabel, "North"); // NOI18N
69

70         jScrollPane1 = new JScrollPane ();
71         
72         listModel = new DefaultListModel ();
73         
74         changesList = new JList (listModel);
75         changesList.setToolTipText (NbBundle.getMessage (DDChangesPanel.class, "HINT_ChangesList"));
76         changesList.setCellRenderer (new ChangesListCellRenderer ());
77         changesList.addListSelectionListener (new ListSelectionListener JavaDoc () {
78             public void valueChanged (ListSelectionEvent JavaDoc e) {
79                 processButton.setEnabled (!changesList.isSelectionEmpty ());
80             }
81         });
82         changesLabel.setLabelFor (changesList);
83         changesLabel.setDisplayedMnemonic (NbBundle.getMessage (DDChangesPanel.class, "LAB_ChangesList_Mnemonic").charAt (0));
84         getAccessibleContext().setAccessibleDescription(NbBundle.getMessage (DDChangesPanel.class, "ACS_ChangesListA11yPanelDesc"));
85         
86         jScrollPane1.setViewportView (changesList);
87         
88         changesPanel.add (jScrollPane1, "Center"); // NOI18N
89

90         add (changesPanel, "Center"); // NOI18N
91
}
92     
93     public java.awt.Dimension JavaDoc getPreferredSize () {
94         return new java.awt.Dimension JavaDoc(600, 400);
95     }
96     
97     public synchronized void setChanges (List JavaDoc changes) {
98         listModel.clear ();
99         if (changes != null) {
100             Iterator JavaDoc it = changes.iterator ();
101             while (it.hasNext ())
102                 listModel.addElement (it.next ());
103         }
104     }
105
106     public DefaultListModel getListModel() {
107         return listModel;
108     }
109
110     public JList getChangesList() {
111         return changesList;
112     }
113
114     static class ChangesListCellRenderer extends DefaultListCellRenderer {
115
116         public Component JavaDoc getListCellRendererComponent(JList list, Object JavaDoc value,
117                 int index, boolean isSelected,
118                 boolean cellHasFocus) {
119             Component JavaDoc comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
120             try {
121                 if ((comp instanceof JLabel) && (value instanceof DDChangeEvent)) {
122                     DDChangeEvent evt = (DDChangeEvent)value;
123                     String JavaDoc label = ""; // NOI18N
124
String JavaDoc clz = evt.getNewValue ();
125                     if (evt.getType () == DDChangeEvent.EJB_ADDED) {
126                         label = NbBundle.getMessage (DDChangesPanel.class, "LAB_addServletElement", clz);
127                     }
128                     else if (evt.getType() == DDChangeEvent.EJB_CLASS_CHANGED){
129                         label = NbBundle.getMessage(DDChangesPanel.class,
130                             "LAB_changeEjbElement", evt.getOldValue (), //NOI18N
131
evt.getNewValue());
132                     }
133                     else if (evt.getType() == DDChangeEvent.EJB_CLASS_DELETED){
134                         label = NbBundle.getMessage(DDChangesPanel.class,
135                             "LAB_deleteEjbElement", evt.getNewValue()); //NOI18N
136
}
137                     else if (evt.getType() == DDChangeEvent.EJB_HOME_CHANGED){
138                         label = NbBundle.getMessage(DDChangesPanel.class,
139                             "LAB_changeHomeElement", evt.getOldValue(), //NOI18N
140
evt.getNewValue());
141                     }
142                     else if (evt.getType() == DDChangeEvent.EJB_REMOTE_CHANGED){
143                         label = NbBundle.getMessage(DDChangesPanel.class,
144                             "LAB_changeRemoteElement", //NOI18N
145
evt.getOldValue(), evt.getNewValue());
146                     }
147                     else if (evt.getType() ==
148                         DDChangeEvent.EJB_LOCAL_HOME_CHANGED){
149                         label = NbBundle.getMessage(DDChangesPanel.class,
150                             "LAB_changeLocalHomeElement", //NOI18N
151
evt.getOldValue(), evt.getNewValue());
152                     }
153                     else if (evt.getType() == DDChangeEvent.EJB_LOCAL_CHANGED){
154                         label = NbBundle.getMessage(DDChangesPanel.class,
155                             "LAB_changeLocalElement", //NOI18N
156
evt.getOldValue(), evt.getNewValue());
157                     }
158                     else if (evt.getType() == DDChangeEvent.EJB_HOME_DELETED){
159                         label = NbBundle.getMessage(DDChangesPanel.class,
160                             "LAB_deleteHomeElement", //NOI18N
161
evt.getNewValue ());
162                     }
163                     else if (evt.getType() == DDChangeEvent.EJB_REMOTE_DELETED){
164                         label = NbBundle.getMessage(DDChangesPanel.class,
165                             "LAB_deleteRemoteElement", //NOI18N
166
evt.getNewValue ());
167                     }
168                     else if (evt.getType() ==
169                         DDChangeEvent.EJB_LOCAL_HOME_DELETED){
170                         label = NbBundle.getMessage(DDChangesPanel.class,
171                             "LAB_deleteLocalHomeElement", //NOI18N
172
evt.getNewValue());
173                     }
174                     else if (evt.getType() == DDChangeEvent.EJB_LOCAL_DELETED){
175                         label = NbBundle.getMessage(DDChangesPanel.class,
176                             "LAB_deleteLocalElement", //NOI18N
177
evt.getNewValue ());
178                     }
179                     else if (evt.getType () == DDChangeEvent.EJB_MOVED) {
180                         String JavaDoc fsname;
181                         try {
182                             fsname = evt.getOldDD ().getPrimaryFile ().getFileSystem ().getDisplayName ();
183                         }
184                         catch (FileStateInvalidException e) {
185                             fsname = ""; // NOI18N
186
}
187                         label = NbBundle.getMessage (DDChangesPanel.class, "LAB_moveServletElement", clz, fsname);
188                     }
189                    
190                     ((JLabel)comp).setText (label);
191                 }
192             }
193             catch (Exception JavaDoc e) {
194                 e.printStackTrace ();
195             }
196             return comp;
197         }
198     }
199 }
200
Popular Tags