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-2007 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.compapp.projects.jbi.ui;
043:
044: import java.awt.Component;
045: import javax.swing.*;
046: import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
047:
048: /** Show a warning that no server is set and allows choose it.
049: *
050: * @author Pavel Buzek
051: */
052: public class NoSelectedServerWarning extends JPanel {
053:
054: public NoSelectedServerWarning(String[] serverIDs) {
055: initComponents();
056: // add MainClassChooser
057: jList1.setModel(new ServerListModel(serverIDs));
058: jList1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
059: jList1.setCellRenderer(new ServersRenderer());
060: jList1.setSelectedIndex(0);
061: }
062:
063: /** Returns the selected server instance Id or null if no instance was selected.
064: *
065: * @return server instance ID or null if no instance is selected
066: */
067: public String getSelectedInstance() {
068: if (jList1.getSelectedIndex() == -1) {
069: return null;
070: } else {
071: return (String) jList1.getSelectedValue();
072: }
073: }
074:
075: /** This method is called from within the constructor to
076: * initialize the form.
077: * WARNING: Do NOT modify this code. The content of this method is
078: * always regenerated by the Form Editor.
079: */
080: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
081: private void initComponents() {
082:
083: jLabel1 = new javax.swing.JLabel();
084: jLabel2 = new javax.swing.JLabel();
085: jScrollPane2 = new javax.swing.JScrollPane();
086: jList1 = new javax.swing.JList();
087:
088: org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
089: org.openide.util.NbBundle.getMessage(
090: NoSelectedServerWarning.class,
091: "LBL_NoSelectedServerWarning_jLabel1")); // NOI18N
092:
093: jLabel2.setLabelFor(jList1);
094: org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
095: org.openide.util.NbBundle.getMessage(
096: NoSelectedServerWarning.class,
097: "LBL_NoSelectedServerWarning_jLabel2")); // NOI18N
098:
099: jScrollPane2.setMinimumSize(new java.awt.Dimension(100, 200));
100:
101: jList1
102: .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
103: jScrollPane2.setViewportView(jList1);
104: jList1
105: .getAccessibleContext()
106: .setAccessibleDescription(
107: org.openide.util.NbBundle
108: .getBundle(
109: NoSelectedServerWarning.class)
110: .getString(
111: "ACS_NoSelectedServerWarning_jLabel2_A11YDesc")); // NOI18N
112:
113: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
114: this );
115: this .setLayout(layout);
116: layout
117: .setHorizontalGroup(layout
118: .createParallelGroup(
119: org.jdesktop.layout.GroupLayout.LEADING)
120: .add(
121: layout
122: .createSequentialGroup()
123: .addContainerGap()
124: .add(
125: layout
126: .createParallelGroup(
127: org.jdesktop.layout.GroupLayout.LEADING)
128: .add(
129: jLabel1,
130: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
131: 376,
132: Short.MAX_VALUE)
133: .add(
134: jLabel2,
135: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
136: 376,
137: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
138: .add(
139: jScrollPane2,
140: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
141: 376,
142: Short.MAX_VALUE))
143: .addContainerGap()));
144: layout
145: .setVerticalGroup(layout
146: .createParallelGroup(
147: org.jdesktop.layout.GroupLayout.LEADING)
148: .add(
149: layout
150: .createSequentialGroup()
151: .addContainerGap()
152: .add(jLabel1)
153: .add(11, 11, 11)
154: .add(jLabel2)
155: .addPreferredGap(
156: org.jdesktop.layout.LayoutStyle.RELATED)
157: .add(
158: jScrollPane2,
159: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
160: 218,
161: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
162: .add(31, 31, 31)));
163: }// </editor-fold>//GEN-END:initComponents
164:
165: // Variables declaration - do not modify//GEN-BEGIN:variables
166: private javax.swing.JLabel jLabel1;
167: private javax.swing.JLabel jLabel2;
168: private javax.swing.JList jList1;
169: private javax.swing.JScrollPane jScrollPane2;
170:
171: // End of variables declaration//GEN-END:variables
172:
173: private static final class ServerListModel extends
174: AbstractListModel {
175:
176: private String instances[];
177:
178: public ServerListModel(String[] serverIDs) {
179: this .instances = serverIDs;
180: }
181:
182: public synchronized int getSize() {
183: return instances.length;
184: }
185:
186: public synchronized Object getElementAt(int index) {
187: if (index >= 0 && index < instances.length) {
188: return instances[index];
189: } else {
190: return null;
191: }
192: }
193:
194: }
195:
196: private static final class ServersRenderer extends JLabel implements
197: ListCellRenderer {
198: ServersRenderer() {
199: setOpaque(true);
200: }
201:
202: public Component getListCellRendererComponent(JList list,
203: Object value, int index, boolean isSelected,
204: boolean cellHasFocus) {
205: if (value instanceof String) {
206: String id = (String) value;
207: setText(Deployment.getDefault()
208: .getServerInstanceDisplayName(id));
209: // setIcon (ProjectUtils.getInformation (prj).getIcon ());
210: } else {
211: setText(value.toString());
212: setIcon(null);
213: }
214: if (isSelected) {
215: setBackground(list.getSelectionBackground());
216: setForeground(list.getSelectionForeground());
217: //setBorder (BorderFactory.createLineBorder (Color.BLACK));
218: } else {
219: setBackground(list.getBackground());
220: setForeground(list.getForeground());
221: //setBorder (null);
222: }
223: return this;
224: }
225: }
226:
227: }
|