KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > web > 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.web;
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.web.event.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.SERVLET_ADDED) {
121                         label = NbBundle.getMessage (DDChangesPanel.class, "LAB_addServletElement", clz);
122                     }
123                     else if (evt.getType () == DDChangeEvent.SERVLET_CHANGED) {
124                         label = NbBundle.getMessage (DDChangesPanel.class, "LAB_changeServletElement", evt.getOldValue (), evt.getNewValue ());
125                     }
126                     else if (evt.getType () == DDChangeEvent.SERVLET_DELETED) {
127                         label = NbBundle.getMessage (DDChangesPanel.class, "LAB_deleteServletElement", evt.getNewValue ());
128                     }
129                     else if (evt.getType () == DDChangeEvent.SERVLET_MOVED) {
130                         String JavaDoc fsname;
131                         try {
132                             fsname = evt.getOldDD ().getPrimaryFile ().getFileSystem ().getDisplayName ();
133                         }
134                         catch (FileStateInvalidException e) {
135                             fsname = ""; // NOI18N
136
}
137                         label = NbBundle.getMessage (DDChangesPanel.class, "LAB_moveServletElement", clz, fsname);
138                     }
139                     else if (evt.getType () == DDChangeEvent.FILTER_CHANGED) {
140                         label = NbBundle.getMessage (DDChangesPanel.class, "LAB_changeFilterElement", evt.getOldValue (), evt.getNewValue ());
141                     }
142                     else if (evt.getType () == DDChangeEvent.FILTER_DELETED) {
143                         label = NbBundle.getMessage (DDChangesPanel.class, "LAB_deleteFilterElement", evt.getNewValue ());
144                     }
145                     else if (evt.getType () == DDChangeEvent.LISTENER_CHANGED) {
146                         label = NbBundle.getMessage (DDChangesPanel.class, "LAB_changeListenerElement", evt.getOldValue (), evt.getNewValue ());
147                     }
148                     else if (evt.getType () == DDChangeEvent.LISTENER_DELETED) {
149                         label = NbBundle.getMessage (DDChangesPanel.class, "LAB_deleteListenerElement", evt.getNewValue ());
150                     }
151                     else if (evt.getType () == DDChangeEvent.JSP_CHANGED) {
152                         label = NbBundle.getMessage (DDChangesPanel.class, "LAB_changeJspElement", evt.getOldValue (), evt.getNewValue ());
153                     }
154                     else if (evt.getType () == DDChangeEvent.JSP_DELETED) {
155                         label = NbBundle.getMessage (DDChangesPanel.class, "LAB_deleteJspElement", evt.getNewValue ());
156                     }
157                     ((JLabel)comp).setText (label);
158                 }
159             }
160             catch (Exception JavaDoc e) {
161                 e.printStackTrace ();
162             }
163             return comp;
164         }
165     }
166 }
167
Popular Tags