001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.xslt.project.ui;
021:
022: import java.awt.Component;
023: import javax.swing.*;
024: import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
025:
026: /**
027: * Show a warning that no server is set and allows choose it.
028: * @author Pavel Buzek
029: * @author Vitaly Bychkov
030: */
031: public class NoSelectedServerWarning extends JPanel {
032:
033: public NoSelectedServerWarning(String serverID) {
034: initComponents();
035: // add MainClassChooser
036: jList1.setModel(new ServerListModel(serverID));
037: jList1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
038: jList1.setCellRenderer(new ServersRenderer());
039: }
040:
041: /** Returns the selected server instance Id or null if no instance was selected.
042: *
043: * @return server instance ID or null if no instance is selected
044: */
045: public String getSelectedInstance() {
046: if (jList1.getSelectedIndex() == -1) {
047: return null;
048: } else {
049: return (String) jList1.getSelectedValue();
050: }
051: }
052:
053: /** This method is called from within the constructor to
054: * initialize the form.
055: * WARNING: Do NOT modify this code. The content of this method is
056: * always regenerated by the Form Editor.
057: */
058: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
059: private void initComponents() {
060: jLabel1 = new javax.swing.JLabel();
061: jLabel2 = new javax.swing.JLabel();
062: jScrollPane2 = new javax.swing.JScrollPane();
063: jList1 = new javax.swing.JList();
064:
065: org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
066: org.openide.util.NbBundle.getMessage(
067: NoSelectedServerWarning.class,
068: "LBL_NoSelectedServerWarning_jLabel1"));
069:
070: jLabel2.setLabelFor(jList1);
071: org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
072: org.openide.util.NbBundle.getMessage(
073: NoSelectedServerWarning.class,
074: "LBL_NoSelectedServerWarning_jLabel2"));
075:
076: jScrollPane2.setMinimumSize(new java.awt.Dimension(100, 200));
077: jList1
078: .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
079: jScrollPane2.setViewportView(jList1);
080: jList1
081: .getAccessibleContext()
082: .setAccessibleDescription(
083: org.openide.util.NbBundle
084: .getMessage(
085: NoSelectedServerWarning.class,
086: "ACS_NoSelectedServerWarning_jLabel2_A11YDesc"));
087:
088: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
089: this );
090: this .setLayout(layout);
091: layout
092: .setHorizontalGroup(layout
093: .createParallelGroup(
094: org.jdesktop.layout.GroupLayout.LEADING)
095: .add(
096: layout
097: .createSequentialGroup()
098: .addContainerGap()
099: .add(
100: layout
101: .createParallelGroup(
102: org.jdesktop.layout.GroupLayout.LEADING)
103: .add(
104: jLabel1,
105: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
106: 376,
107: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
108: .add(
109: jLabel2,
110: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
111: 376,
112: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
113: .add(
114: jScrollPane2,
115: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
116: 376,
117: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
118: .addContainerGap(14,
119: Short.MAX_VALUE)));
120: layout.setVerticalGroup(layout.createParallelGroup(
121: org.jdesktop.layout.GroupLayout.LEADING).add(
122: layout.createSequentialGroup().addContainerGap().add(
123: jLabel1).addPreferredGap(
124: org.jdesktop.layout.LayoutStyle.RELATED).add(
125: jLabel2).addPreferredGap(
126: org.jdesktop.layout.LayoutStyle.RELATED).add(
127: jScrollPane2,
128: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
129: 218,
130: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
131: .add(31, 31, 31)));
132: }// </editor-fold>//GEN-END:initComponents
133:
134: // Variables declaration - do not modify//GEN-BEGIN:variables
135: private javax.swing.JLabel jLabel1;
136: private javax.swing.JLabel jLabel2;
137: private javax.swing.JList jList1;
138: private javax.swing.JScrollPane jScrollPane2;
139:
140: // End of variables declaration//GEN-END:variables
141:
142: private static final class ServerListModel extends
143: AbstractListModel {
144:
145: private String serverID;
146: private String instances[];
147:
148: public ServerListModel(String serverID) {
149: this .serverID = serverID;
150: this .instances = Deployment.getDefault()
151: .getInstancesOfServer(serverID);
152: }
153:
154: public synchronized int getSize() {
155: return instances.length;
156: }
157:
158: public synchronized Object getElementAt(int index) {
159: if (index >= 0 && index < instances.length) {
160: return instances[index];
161: } else {
162: return null;
163: }
164: }
165:
166: }
167:
168: private static final class ServersRenderer extends JLabel implements
169: ListCellRenderer {
170: ServersRenderer() {
171: setOpaque(true);
172: }
173:
174: public Component getListCellRendererComponent(JList list,
175: Object value, int index, boolean isSelected,
176: boolean cellHasFocus) {
177: if (value instanceof String) {
178: String id = (String) value;
179: setText(Deployment.getDefault()
180: .getServerInstanceDisplayName(id));
181: // setIcon (ProjectUtils.getInformation (prj).getIcon ());
182: } else {
183: setText(value.toString());
184: setIcon(null);
185: }
186: if (isSelected) {
187: setBackground(list.getSelectionBackground());
188: setForeground(list.getSelectionForeground());
189: //setBorder (BorderFactory.createLineBorder (Color.BLACK));
190: } else {
191: setBackground(list.getBackground());
192: setForeground(list.getForeground());
193: //setBorder (null);
194: }
195: return this;
196: }
197: }
198:
199: }
|