KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > app > 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.app;
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.loaders.DataObject;
33 import org.openide.filesystems.FileStateInvalidException;
34
35 //import org.netbeans.modules.j2ee.ddloaders.ejb.DDChangeEvent;
36

37 /** Panel that contains list of changes for deployment descriptor
38  * to accomodate recent servlet modification.
39  *
40  * @author Radim Kubacki
41  */

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

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

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

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