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-2006 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.j2ee.ddloaders.client;
043:
044: import java.awt.Component;
045: import java.util.List;
046: import java.util.Iterator;
047:
048: import javax.swing.*;
049: import javax.swing.border.EmptyBorder;
050: import javax.swing.event.ListSelectionListener;
051: import javax.swing.event.ListSelectionEvent;
052:
053: import org.openide.util.NbBundle;
054: import org.openide.filesystems.FileStateInvalidException;
055:
056: //import org.netbeans.modules.j2ee.ddloaders.ejb.DDChangeEvent;
057:
058: /** Panel that contains list of changes for deployment descriptor
059: * to accomodate recent servlet modification.
060: *
061: * @author Radim Kubacki
062: */
063: public class DDChangesPanel extends JPanel {
064:
065: private JPanel changesPanel;
066: private JScrollPane jScrollPane1;
067: /* pkg private */JList changesList;
068:
069: /* pkg private */DefaultListModel listModel;
070:
071: /** Initializes the Form */
072: public DDChangesPanel(String caption, final JButton processButton) {
073: setLayout(new java.awt.BorderLayout(0, 12));
074: setBorder(new EmptyBorder(12, 12, 11, 0));
075:
076: JTextArea text = new JTextArea();
077: text.setEnabled(false);
078: text.setEditable(false);
079: text.setDisabledTextColor(UIManager
080: .getColor("Label.foreground")); // NOI18N
081: text.setBackground(UIManager.getColor("Label.background")); // NOI18N
082: text.setLineWrap(true);
083: text.setWrapStyleWord(true);
084: text.setText(caption);
085: add(text, "North"); // NOI18N
086:
087: changesPanel = new JPanel();
088: changesPanel.setLayout(new java.awt.BorderLayout(5, 5));
089:
090: JLabel changesLabel = new JLabel();
091: changesLabel.setText(NbBundle.getMessage(DDChangesPanel.class,
092: "LAB_ChangesList"));
093: changesLabel.getAccessibleContext().setAccessibleDescription(
094: NbBundle.getMessage(DDChangesPanel.class,
095: "ACS_ChangesListA11yDesc")); // NOI18N
096: changesPanel.add(changesLabel, "North"); // NOI18N
097:
098: jScrollPane1 = new JScrollPane();
099:
100: listModel = new DefaultListModel();
101:
102: changesList = new JList(listModel);
103: changesList.setToolTipText(NbBundle.getMessage(
104: DDChangesPanel.class, "HINT_ChangesList"));
105: changesList.setCellRenderer(new ChangesListCellRenderer());
106: changesList
107: .addListSelectionListener(new ListSelectionListener() {
108: public void valueChanged(ListSelectionEvent e) {
109: processButton.setEnabled(!changesList
110: .isSelectionEmpty());
111: }
112: });
113: changesLabel.setLabelFor(changesList);
114: changesLabel.setDisplayedMnemonic(NbBundle.getMessage(
115: DDChangesPanel.class, "LAB_ChangesList_Mnemonic")
116: .charAt(0));
117: getAccessibleContext().setAccessibleDescription(
118: NbBundle.getMessage(DDChangesPanel.class,
119: "ACS_ChangesListA11yPanelDesc"));
120:
121: jScrollPane1.setViewportView(changesList);
122:
123: changesPanel.add(jScrollPane1, "Center"); // NOI18N
124:
125: add(changesPanel, "Center"); // NOI18N
126: }
127:
128: public java.awt.Dimension getPreferredSize() {
129: return new java.awt.Dimension(600, 400);
130: }
131:
132: synchronized void setChanges(List changes) {
133: listModel.clear();
134: if (changes != null) {
135: Iterator it = changes.iterator();
136: while (it.hasNext())
137: listModel.addElement(it.next());
138: }
139: }
140:
141: static class ChangesListCellRenderer extends
142: DefaultListCellRenderer {
143:
144: public Component getListCellRendererComponent(JList list,
145: Object value, int index, boolean isSelected,
146: boolean cellHasFocus) {
147: Component comp = super .getListCellRendererComponent(list,
148: value, index, isSelected, cellHasFocus);
149: try {
150: if ((comp instanceof JLabel)
151: && (value instanceof DDChangeEvent)) {
152: DDChangeEvent evt = (DDChangeEvent) value;
153: String label = ""; // NOI18N
154: String clz = evt.getNewValue();
155: if (evt.getType() == DDChangeEvent.EJB_ADDED) {
156: label = NbBundle.getMessage(
157: DDChangesPanel.class,
158: "LAB_addServletElement", clz);
159: } else if (evt.getType() == DDChangeEvent.EJB_CLASS_CHANGED) {
160: label = NbBundle.getMessage(
161: DDChangesPanel.class,
162: "LAB_changeEjbElement", evt
163: .getOldValue(), //NOI18N
164: evt.getNewValue());
165: } else if (evt.getType() == DDChangeEvent.EJB_CLASS_DELETED) {
166: label = NbBundle.getMessage(
167: DDChangesPanel.class,
168: "LAB_deleteEjbElement", evt
169: .getNewValue()); //NOI18N
170: } else if (evt.getType() == DDChangeEvent.EJB_HOME_CHANGED) {
171: label = NbBundle.getMessage(
172: DDChangesPanel.class,
173: "LAB_changeHomeElement", evt
174: .getOldValue(), //NOI18N
175: evt.getNewValue());
176: } else if (evt.getType() == DDChangeEvent.EJB_REMOTE_CHANGED) {
177: label = NbBundle.getMessage(
178: DDChangesPanel.class,
179: "LAB_changeRemoteElement", //NOI18N
180: evt.getOldValue(), evt.getNewValue());
181: } else if (evt.getType() == DDChangeEvent.EJB_LOCAL_HOME_CHANGED) {
182: label = NbBundle.getMessage(
183: DDChangesPanel.class,
184: "LAB_changeLocalHomeElement", //NOI18N
185: evt.getOldValue(), evt.getNewValue());
186: } else if (evt.getType() == DDChangeEvent.EJB_LOCAL_CHANGED) {
187: label = NbBundle.getMessage(
188: DDChangesPanel.class,
189: "LAB_changeLocalElement", //NOI18N
190: evt.getOldValue(), evt.getNewValue());
191: } else if (evt.getType() == DDChangeEvent.EJB_HOME_DELETED) {
192: label = NbBundle.getMessage(
193: DDChangesPanel.class,
194: "LAB_deleteHomeElement", //NOI18N
195: evt.getNewValue());
196: } else if (evt.getType() == DDChangeEvent.EJB_REMOTE_DELETED) {
197: label = NbBundle.getMessage(
198: DDChangesPanel.class,
199: "LAB_deleteRemoteElement", //NOI18N
200: evt.getNewValue());
201: } else if (evt.getType() == DDChangeEvent.EJB_LOCAL_HOME_DELETED) {
202: label = NbBundle.getMessage(
203: DDChangesPanel.class,
204: "LAB_deleteLocalHomeElement", //NOI18N
205: evt.getNewValue());
206: } else if (evt.getType() == DDChangeEvent.EJB_LOCAL_DELETED) {
207: label = NbBundle.getMessage(
208: DDChangesPanel.class,
209: "LAB_deleteLocalElement", //NOI18N
210: evt.getNewValue());
211: } else if (evt.getType() == DDChangeEvent.EJB_MOVED) {
212: String fsname;
213: try {
214: fsname = evt.getOldDD().getPrimaryFile()
215: .getFileSystem().getDisplayName();
216: } catch (FileStateInvalidException e) {
217: fsname = ""; // NOI18N
218: }
219: label = NbBundle.getMessage(
220: DDChangesPanel.class,
221: "LAB_moveServletElement", clz, fsname);
222: }
223:
224: ((JLabel) comp).setText(label);
225: }
226: } catch (Exception e) {
227: e.printStackTrace();
228: }
229: return comp;
230: }
231: }
232: }
|