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: * Portions Copyrighted 2008 Craig MacKay.
042: */
043:
044: package org.netbeans.modules.spring.beans.wizards;
045:
046: import java.util.ArrayList;
047: import java.util.List;
048: import javax.swing.ImageIcon;
049: import javax.swing.JPanel;
050: import javax.swing.ListSelectionModel;
051: import javax.swing.table.DefaultTableModel;
052: import javax.swing.table.TableColumn;
053: import javax.swing.table.TableModel;
054: import org.netbeans.api.java.classpath.ClassPath;
055: import org.netbeans.api.project.libraries.Library;
056: import org.netbeans.modules.spring.api.SpringUtilities;
057: import org.openide.util.NbBundle;
058: import org.openide.util.Utilities;
059:
060: public final class SpringXMLConfigNamespacesVisual extends JPanel {
061:
062: private Library springLibrary;
063: private ClassPath classPath;
064: private boolean addSpringToClassPath;
065:
066: public SpringXMLConfigNamespacesVisual() {
067: initComponents();
068: // set the color of the table's JViewport
069: includesTable.getParent().setBackground(
070: includesTable.getBackground());
071: ((DefaultTableModel) includesTable.getModel())
072: .setColumnIdentifiers(new String[] { "Include",
073: "Namespace" }); // NOI18N
074: TableColumn col1 = includesTable.getColumnModel().getColumn(0);
075: col1.setMaxWidth(0);
076: includesTable.getSelectionModel().setSelectionMode(
077: ListSelectionModel.SINGLE_SELECTION);
078: includesTable.revalidate();
079: springLibrary = SpringUtilities.findSpringLibrary();
080: }
081:
082: @Override
083: public String getName() {
084: return NbBundle.getMessage(
085: SpringXMLConfigNamespacesVisual.class,
086: "LBL_Namespaces_Include_Step");
087: }
088:
089: public void setClassPath(ClassPath classPath) {
090: this .classPath = classPath;
091: updateClassPathWarning();
092: }
093:
094: private void updateClassPathWarning() {
095: boolean alreadyAdded = classPath != null
096: && SpringUtilities.containsSpring(classPath);
097: boolean needToAdd = !(alreadyAdded || addSpringToClassPath || springLibrary == null);
098: springNotOnClassPathLabel.setVisible(needToAdd);
099: addSpringButton.setVisible(needToAdd);
100: }
101:
102: /** This method is called from within the constructor to
103: * initialize the form.
104: * WARNING: Do NOT modify this code. The content of this method is
105: * always regenerated by the Form Editor.
106: */
107: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
108: private void initComponents() {
109:
110: includesScrollPane = new javax.swing.JScrollPane();
111: includesTable = new javax.swing.JTable();
112:
113: addSpringButton = new javax.swing.JButton();
114: springNotOnClassPathLabel = new javax.swing.JLabel();
115:
116: includesTable
117: .setModel(new javax.swing.table.DefaultTableModel(
118: new Object[][] {
119: { null,
120: "aop - http://www.springframework.org/schema/aop/spring-aop-2.5.xsd" },
121: {
122: null,
123: "context - http://www.springframework.org/schema/context/spring-context-2.5.xsd" },
124: {
125: null,
126: "flow - http://www.springframework.org/schema/webflow-config/spring-webflow-config-1.0.xsd" },
127: { null,
128: "jms - http://www.springframework.org/schema/jms/spring-jms-2.5.xsd" },
129: { null,
130: "jee - http://www.springframework.org/schema/jee/spring-jee-2.5.xsd" },
131: { null,
132: "lang - http://www.springframework.org/schema/lang/spring-lang-2.5.xsd" },
133: { null,
134: "osgi - http://www.springframework.org/schema/osgi/spring-osgi.xsd" },
135: { null,
136: "tx - http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" },
137: { null,
138: "util - http://www.springframework.org/schema/util/spring-util-2.5.xsd" },
139: { null,
140: "p - http://www.springframework.org/schema/p" } },
141: new String[] { "", "" }) {
142: Class[] types = new Class[] {
143: java.lang.Boolean.class,
144: java.lang.String.class };
145: boolean[] canEdit = new boolean[] { true, false };
146:
147: public Class getColumnClass(int columnIndex) {
148: return types[columnIndex];
149: }
150:
151: public boolean isCellEditable(int rowIndex,
152: int columnIndex) {
153: return canEdit[columnIndex];
154: }
155: });
156: includesTable.setShowHorizontalLines(false);
157: includesTable.setShowVerticalLines(false);
158: includesTable.setTableHeader(null);
159: includesTable.setShowGrid(false);
160: includesTable.setDragEnabled(false);
161: includesTable.setIntercellSpacing(new java.awt.Dimension(0, 0));
162: includesScrollPane.setViewportView(includesTable);
163:
164: org.openide.awt.Mnemonics.setLocalizedText(addSpringButton,
165: org.openide.util.NbBundle.getMessage(
166: SpringXMLConfigNamespacesVisual.class,
167: "LBL_AddSpringFramework")); // NOI18N
168: addSpringButton
169: .addActionListener(new java.awt.event.ActionListener() {
170: public void actionPerformed(
171: java.awt.event.ActionEvent evt) {
172: addSpringButtonActionPerformed(evt);
173: }
174: });
175:
176: springNotOnClassPathLabel
177: .setIcon(new ImageIcon(
178: Utilities
179: .loadImage("org/netbeans/modules/spring/beans/resources/warning.gif")));
180: org.openide.awt.Mnemonics.setLocalizedText(
181: springNotOnClassPathLabel, org.openide.util.NbBundle
182: .getMessage(
183: SpringXMLConfigNamespacesVisual.class,
184: "LBL_SpringNotOnClassPath")); // NOI18N
185:
186: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
187: this );
188: this .setLayout(layout);
189: layout.setHorizontalGroup(layout.createParallelGroup(
190: org.jdesktop.layout.GroupLayout.LEADING).add(
191: includesScrollPane,
192: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 447,
193: Short.MAX_VALUE).add(
194: layout.createSequentialGroup().add(addSpringButton)
195: .addContainerGap()).add(
196: layout.createSequentialGroup().add(
197: springNotOnClassPathLabel).addContainerGap()));
198: layout
199: .setVerticalGroup(layout
200: .createParallelGroup(
201: org.jdesktop.layout.GroupLayout.LEADING)
202: .add(
203: layout
204: .createSequentialGroup()
205: .add(
206: includesScrollPane,
207: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
208: 196,
209: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
210: .addPreferredGap(
211: org.jdesktop.layout.LayoutStyle.RELATED,
212: 36, Short.MAX_VALUE)
213: .add(springNotOnClassPathLabel)
214: .addPreferredGap(
215: org.jdesktop.layout.LayoutStyle.RELATED)
216: .add(addSpringButton)));
217: }// </editor-fold>//GEN-END:initComponents
218:
219: private void addSpringButtonActionPerformed(
220: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addSpringButtonActionPerformed
221: addSpringToClassPath = true;
222: updateClassPathWarning();
223: }//GEN-LAST:event_addSpringButtonActionPerformed
224:
225: // Variables declaration - do not modify//GEN-BEGIN:variables
226: private javax.swing.JButton addSpringButton;
227: private javax.swing.JScrollPane includesScrollPane;
228: private javax.swing.JTable includesTable;
229: private javax.swing.JLabel springNotOnClassPathLabel;
230:
231: // End of variables declaration//GEN-END:variables
232:
233: public String[] getIncludedNamespaces() {
234: List<String> incs = new ArrayList<String>();
235: TableModel model = includesTable.getModel();
236:
237: for (int i = 0; i < model.getRowCount(); i++) {
238: Boolean selected = (Boolean) model.getValueAt(i, 0);
239: if (selected != null && selected == Boolean.TRUE) {
240: String namespace = (String) model.getValueAt(i, 1);
241: incs.add(namespace);
242: }
243: }
244: return incs.toArray(new String[0]);
245: }
246:
247: public boolean getAddSpringToClassPath() {
248: return addSpringToClassPath;
249: }
250:
251: public Library getSpringLibrary() {
252: return springLibrary;
253: }
254: }
|