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.spring.beans.wizards;
043:
044: import java.util.HashSet;
045: import java.util.List;
046: import java.util.Set;
047: import javax.swing.ListSelectionModel;
048: import javax.swing.event.TableModelListener;
049: import javax.swing.table.TableModel;
050: import org.netbeans.modules.spring.api.beans.ConfigFileGroup;
051:
052: /**
053: *
054: * @author Rohan Ranade (Rohan.Ranade@Sun.COM)
055: */
056: public class SpringXMLConfigGroupVisual extends javax.swing.JPanel {
057:
058: /** Creates new form SpringXMLConfigGroupVisual */
059: public SpringXMLConfigGroupVisual(
060: List<ConfigFileGroup> configFileGroups) {
061: initComponents();
062: groupsTable.getParent().setBackground(
063: groupsTable.getBackground());
064: groupsTable.setModel(new ConfigGroupSelectionTableModel(
065: configFileGroups));
066: groupsTable.getColumnModel().getColumn(0).setMaxWidth(0);
067: groupsTable.getSelectionModel().setSelectionMode(
068: ListSelectionModel.SINGLE_SELECTION);
069: }
070:
071: /** This method is called from within the constructor to
072: * initialize the form.
073: * WARNING: Do NOT modify this code. The content of this method is
074: * always regenerated by the Form Editor.
075: */
076: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
077: private void initComponents() {
078:
079: groupsScrollPane = new javax.swing.JScrollPane();
080: groupsTable = new javax.swing.JTable();
081: groupsLabel = new javax.swing.JLabel();
082:
083: groupsTable.setIntercellSpacing(new java.awt.Dimension(0, 0));
084: groupsTable.setShowHorizontalLines(false);
085: groupsTable.setShowVerticalLines(false);
086: groupsTable.setTableHeader(null);
087: groupsScrollPane.setViewportView(groupsTable);
088:
089: groupsLabel.setText(org.openide.util.NbBundle.getMessage(
090: SpringXMLConfigGroupVisual.class,
091: "LBL_Config_File_Selection")); // NOI18N
092:
093: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
094: this );
095: this .setLayout(layout);
096: layout.setHorizontalGroup(layout.createParallelGroup(
097: org.jdesktop.layout.GroupLayout.LEADING).add(
098: layout.createSequentialGroup().add(groupsLabel)
099: .addContainerGap(152, Short.MAX_VALUE)).add(
100: groupsScrollPane,
101: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 395,
102: Short.MAX_VALUE));
103: layout
104: .setVerticalGroup(layout
105: .createParallelGroup(
106: org.jdesktop.layout.GroupLayout.LEADING)
107: .add(
108: layout
109: .createSequentialGroup()
110: .add(groupsLabel)
111: .addPreferredGap(
112: org.jdesktop.layout.LayoutStyle.RELATED)
113: .add(
114: groupsScrollPane,
115: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
116: 193, Short.MAX_VALUE)));
117: }// </editor-fold>//GEN-END:initComponents
118:
119: // Variables declaration - do not modify//GEN-BEGIN:variables
120: private javax.swing.JLabel groupsLabel;
121: private javax.swing.JScrollPane groupsScrollPane;
122: private javax.swing.JTable groupsTable;
123:
124: // End of variables declaration//GEN-END:variables
125:
126: public Set<ConfigFileGroup> getSelectedConfigFileGroups() {
127: return ((ConfigGroupSelectionTableModel) groupsTable.getModel())
128: .getSelectedGroups();
129: }
130:
131: private static final class ConfigGroupSelectionTableModel implements
132: TableModel {
133:
134: private List<ConfigFileGroup> groups;
135: private boolean[] selected;
136:
137: public ConfigGroupSelectionTableModel(
138: List<ConfigFileGroup> groups) {
139: this .groups = groups;
140: selected = new boolean[groups.size()];
141: }
142:
143: public int getRowCount() {
144: return groups.size();
145: }
146:
147: public int getColumnCount() {
148: return 2;
149: }
150:
151: public String getColumnName(int columnIndex) {
152: return (columnIndex == 0) ? "" : "Configuration File Group"; // NOI18N
153: }
154:
155: public Class<?> getColumnClass(int columnIndex) {
156: return (columnIndex == 0) ? Boolean.class
157: : ConfigFileGroup.class;
158: }
159:
160: public boolean isCellEditable(int rowIndex, int columnIndex) {
161: return columnIndex == 0;
162: }
163:
164: public Object getValueAt(int rowIndex, int columnIndex) {
165: return (columnIndex == 0) ? selected[rowIndex] : groups
166: .get(rowIndex).getName();
167: }
168:
169: public void setValueAt(Object aValue, int rowIndex,
170: int columnIndex) {
171: selected[rowIndex] = (Boolean) aValue;
172: }
173:
174: public void addTableModelListener(TableModelListener l) {
175: }
176:
177: public void removeTableModelListener(TableModelListener l) {
178: }
179:
180: public Set<ConfigFileGroup> getSelectedGroups() {
181: Set<ConfigFileGroup> selectedGroups = new HashSet<ConfigFileGroup>(
182: groups.size());
183: for (int i = 0; i < groups.size(); i++) {
184: if (selected[i]) {
185: selectedGroups.add(groups.get(i));
186: }
187: }
188:
189: return selectedGroups;
190: }
191: }
192: }
|