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.projectimport.eclipse.wizard;
043:
044: import java.awt.Color;
045: import java.io.File;
046: import javax.swing.JFileChooser;
047: import javax.swing.JPanel;
048: import javax.swing.UIManager;
049: import javax.swing.event.DocumentEvent;
050: import javax.swing.event.DocumentListener;
051: import org.netbeans.modules.projectimport.eclipse.EclipseUtils;
052:
053: /**
054: * Represent "Selection" step(panel) in the Eclipse importer wizard.
055: *
056: * @author mkrauskopf
057: */
058: final class SelectionPanel extends JPanel {
059:
060: private String errorMessage;
061:
062: /** Creates new form ProjectSelectionPanel */
063: public SelectionPanel() {
064: super ();
065: initComponents();
066: Color lblBgr = UIManager.getColor("Label.background"); // NOI18N
067: wsDescription.setBackground(lblBgr);
068: note.setBackground(lblBgr);
069: workspaceDir.getDocument().addDocumentListener(
070: new DocumentListener() {
071: public void insertUpdate(DocumentEvent e) {
072: workspaceChanged();
073: }
074:
075: public void removeUpdate(DocumentEvent e) {
076: workspaceChanged();
077: }
078:
079: public void changedUpdate(DocumentEvent e) {
080: }
081: });
082: projectDir.getDocument().addDocumentListener(
083: new DocumentListener() {
084: public void insertUpdate(DocumentEvent e) {
085: projectChanged();
086: }
087:
088: public void removeUpdate(DocumentEvent e) {
089: projectChanged();
090: }
091:
092: public void changedUpdate(DocumentEvent e) {
093: }
094: });
095: projectDestDir.getDocument().addDocumentListener(
096: new DocumentListener() {
097: public void insertUpdate(DocumentEvent e) {
098: projectChanged();
099: }
100:
101: public void removeUpdate(DocumentEvent e) {
102: projectChanged();
103: }
104:
105: public void changedUpdate(DocumentEvent e) {
106: }
107: });
108: setWorkspaceEnabled(workspaceButton.isSelected());
109: }
110:
111: /** Returns workspace directory choosed by user. */
112: String getWorkspaceDir() {
113: return workspaceDir.getText().trim();
114: }
115:
116: private void workspaceChanged() {
117: String workspace = getWorkspaceDir().trim();
118: if ("".equals(workspace)) {
119: setErrorMessage(ProjectImporterWizard
120: .getMessage("MSG_ChooseWorkspace")); // NOI18N
121: return;
122: }
123: boolean wsValid = EclipseUtils
124: .isRegularWorkSpace(getWorkspaceDir());
125: setErrorMessage(wsValid ? null : ProjectImporterWizard
126: .getMessage("MSG_NotRegularWorkspace",
127: getWorkspaceDir())); // NOI18N
128: }
129:
130: private void projectChanged() {
131: // check Eclipse project directory
132: String project = getProjectDir();
133: if ("".equals(project)) {
134: setErrorMessage(ProjectImporterWizard
135: .getMessage("MSG_ChooseProject")); // NOI18N
136: return;
137: }
138: File projectDirFile = new File(project);
139: if (!EclipseUtils.isRegularProject(projectDirFile)) {
140: setErrorMessage(ProjectImporterWizard.getMessage(
141: "MSG_NotRegularProject", project)); // NOI18N
142: return;
143: }
144:
145: // check destination directory
146: String projectDest = getProjectDestinationDir();
147: if ("".equals(projectDest)) {
148: setErrorMessage(ProjectImporterWizard
149: .getMessage("MSG_ChooseProjectDestination")); // NOI18N
150: return;
151: }
152: File projectDestFile = new File(projectDest, projectDirFile
153: .getName());
154: if (projectDestFile.exists()) {
155: setErrorMessage(ProjectImporterWizard.getMessage(
156: "MSG_ProjectExist", projectDestFile.getName())); // NOI18N
157: return;
158: }
159:
160: // valid
161: setErrorMessage(null);
162: }
163:
164: void setErrorMessage(String newMessage) {
165: String oldMessage = this .errorMessage;
166: this .errorMessage = newMessage;
167: firePropertyChange("errorMessage", oldMessage, newMessage);
168: }
169:
170: boolean isWorkspaceChosen() {
171: return workspaceButton.isSelected();
172: }
173:
174: /** Returns project directory of single-selected project. */
175: public String getProjectDir() {
176: return projectDir.getText().trim();
177: }
178:
179: /** Returns destination directory for single-selected project. */
180: public String getProjectDestinationDir() {
181: return projectDestDir.getText().trim();
182: }
183:
184: /** This method is called from within the constructor to
185: * initialize the form.
186: * WARNING: Do NOT modify this code. The content of this method is
187: * always regenerated by the Form Editor.
188: */
189: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
190: private void initComponents() {
191: java.awt.GridBagConstraints gridBagConstraints;
192:
193: buttonGroup = new javax.swing.ButtonGroup();
194: workspaceDir = new javax.swing.JTextField();
195: worskpaceBrowse = new javax.swing.JButton();
196: workSpaceLBL = new javax.swing.JLabel();
197: projectDir = new javax.swing.JTextField();
198: projectBrowse = new javax.swing.JButton();
199: projectLBL = new javax.swing.JLabel();
200: projectButton = new javax.swing.JRadioButton();
201: workspaceButton = new javax.swing.JRadioButton();
202: projectDestLBL = new javax.swing.JLabel();
203: projectDestDir = new javax.swing.JTextField();
204: projectDestBrowse = new javax.swing.JButton();
205: wsDescription = new javax.swing.JTextArea();
206: note = new javax.swing.JTextArea();
207:
208: setLayout(new java.awt.GridBagLayout());
209:
210: gridBagConstraints = new java.awt.GridBagConstraints();
211: gridBagConstraints.gridx = 1;
212: gridBagConstraints.gridy = 2;
213: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
214: gridBagConstraints.weightx = 1.0;
215: add(workspaceDir, gridBagConstraints);
216:
217: org.openide.awt.Mnemonics.setLocalizedText(worskpaceBrowse,
218: org.openide.util.NbBundle.getMessage(
219: SelectionPanel.class, "CTL_BrowseButton_B"));
220: worskpaceBrowse
221: .addActionListener(new java.awt.event.ActionListener() {
222: public void actionPerformed(
223: java.awt.event.ActionEvent evt) {
224: worskpaceBrowseActionPerformed(evt);
225: }
226: });
227:
228: gridBagConstraints = new java.awt.GridBagConstraints();
229: gridBagConstraints.gridx = 2;
230: gridBagConstraints.gridy = 2;
231: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
232: gridBagConstraints.insets = new java.awt.Insets(0, 11, 0, 0);
233: add(worskpaceBrowse, gridBagConstraints);
234:
235: workSpaceLBL.setLabelFor(workspaceDir);
236: org.openide.awt.Mnemonics.setLocalizedText(workSpaceLBL,
237: org.openide.util.NbBundle.getMessage(
238: SelectionPanel.class, "LBL_Workspace"));
239: gridBagConstraints = new java.awt.GridBagConstraints();
240: gridBagConstraints.gridx = 0;
241: gridBagConstraints.gridy = 2;
242: gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
243: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
244: gridBagConstraints.insets = new java.awt.Insets(0, 14, 0, 12);
245: add(workSpaceLBL, gridBagConstraints);
246:
247: gridBagConstraints = new java.awt.GridBagConstraints();
248: gridBagConstraints.gridx = 1;
249: gridBagConstraints.gridy = 4;
250: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
251: gridBagConstraints.weightx = 1.0;
252: add(projectDir, gridBagConstraints);
253:
254: org.openide.awt.Mnemonics.setLocalizedText(projectBrowse,
255: org.openide.util.NbBundle.getMessage(
256: SelectionPanel.class, "CTL_BrowseButton_R"));
257: projectBrowse
258: .addActionListener(new java.awt.event.ActionListener() {
259: public void actionPerformed(
260: java.awt.event.ActionEvent evt) {
261: projectBrowseActionPerformed(evt);
262: }
263: });
264:
265: gridBagConstraints = new java.awt.GridBagConstraints();
266: gridBagConstraints.gridx = 2;
267: gridBagConstraints.gridy = 4;
268: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
269: gridBagConstraints.insets = new java.awt.Insets(0, 11, 0, 0);
270: add(projectBrowse, gridBagConstraints);
271:
272: projectLBL.setLabelFor(projectDir);
273: org.openide.awt.Mnemonics.setLocalizedText(projectLBL,
274: org.openide.util.NbBundle.getMessage(
275: SelectionPanel.class, "LBL_Project"));
276: gridBagConstraints = new java.awt.GridBagConstraints();
277: gridBagConstraints.gridx = 0;
278: gridBagConstraints.gridy = 4;
279: gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
280: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
281: gridBagConstraints.insets = new java.awt.Insets(0, 14, 0, 12);
282: add(projectLBL, gridBagConstraints);
283:
284: buttonGroup.add(projectButton);
285: org.openide.awt.Mnemonics.setLocalizedText(projectButton,
286: org.openide.util.NbBundle.getMessage(
287: SelectionPanel.class, "CTL_ProjectButton"));
288: projectButton.setBorder(javax.swing.BorderFactory
289: .createEmptyBorder(0, 0, 0, 0));
290: projectButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
291: projectButton
292: .addActionListener(new java.awt.event.ActionListener() {
293: public void actionPerformed(
294: java.awt.event.ActionEvent evt) {
295: projectButtonActionPerformed(evt);
296: }
297: });
298:
299: gridBagConstraints = new java.awt.GridBagConstraints();
300: gridBagConstraints.gridx = 0;
301: gridBagConstraints.gridy = 3;
302: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
303: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
304: gridBagConstraints.insets = new java.awt.Insets(11, 0, 6, 0);
305: add(projectButton, gridBagConstraints);
306:
307: buttonGroup.add(workspaceButton);
308: workspaceButton.setSelected(true);
309: org.openide.awt.Mnemonics.setLocalizedText(workspaceButton,
310: org.openide.util.NbBundle.getMessage(
311: SelectionPanel.class, "CTL_WorkspaceButton"));
312: workspaceButton.setBorder(javax.swing.BorderFactory
313: .createEmptyBorder(0, 0, 0, 0));
314: workspaceButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
315: workspaceButton
316: .addActionListener(new java.awt.event.ActionListener() {
317: public void actionPerformed(
318: java.awt.event.ActionEvent evt) {
319: workspaceButtonActionPerformed(evt);
320: }
321: });
322:
323: gridBagConstraints = new java.awt.GridBagConstraints();
324: gridBagConstraints.gridx = 0;
325: gridBagConstraints.gridy = 1;
326: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
327: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
328: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
329: add(workspaceButton, gridBagConstraints);
330:
331: projectDestLBL.setLabelFor(projectDestDir);
332: org.openide.awt.Mnemonics
333: .setLocalizedText(projectDestLBL,
334: org.openide.util.NbBundle.getMessage(
335: SelectionPanel.class,
336: "LBL_ProjectDestination"));
337: gridBagConstraints = new java.awt.GridBagConstraints();
338: gridBagConstraints.gridx = 0;
339: gridBagConstraints.gridy = 5;
340: gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
341: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
342: gridBagConstraints.insets = new java.awt.Insets(0, 14, 0, 12);
343: add(projectDestLBL, gridBagConstraints);
344:
345: gridBagConstraints = new java.awt.GridBagConstraints();
346: gridBagConstraints.gridx = 1;
347: gridBagConstraints.gridy = 5;
348: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
349: gridBagConstraints.weightx = 1.0;
350: add(projectDestDir, gridBagConstraints);
351:
352: org.openide.awt.Mnemonics.setLocalizedText(projectDestBrowse,
353: org.openide.util.NbBundle.getMessage(
354: SelectionPanel.class, "CTL_BrowseButton_S"));
355: projectDestBrowse
356: .addActionListener(new java.awt.event.ActionListener() {
357: public void actionPerformed(
358: java.awt.event.ActionEvent evt) {
359: projectDestBrowseActionPerformed(evt);
360: }
361: });
362:
363: gridBagConstraints = new java.awt.GridBagConstraints();
364: gridBagConstraints.gridx = 2;
365: gridBagConstraints.gridy = 5;
366: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
367: gridBagConstraints.insets = new java.awt.Insets(0, 11, 0, 0);
368: add(projectDestBrowse, gridBagConstraints);
369:
370: wsDescription.setEditable(false);
371: wsDescription.setLineWrap(true);
372: wsDescription
373: .setText(java.util.ResourceBundle
374: .getBundle(
375: "org/netbeans/modules/projectimport/eclipse/wizard/Bundle")
376: .getString("LBL_SpecifyWorkspaceDescription"));
377: wsDescription.setWrapStyleWord(true);
378: gridBagConstraints = new java.awt.GridBagConstraints();
379: gridBagConstraints.gridx = 0;
380: gridBagConstraints.gridy = 0;
381: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
382: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
383: gridBagConstraints.insets = new java.awt.Insets(0, 0, 24, 0);
384: add(wsDescription, gridBagConstraints);
385:
386: note.setEditable(false);
387: note.setLineWrap(true);
388: note
389: .setText(java.util.ResourceBundle
390: .getBundle(
391: "org/netbeans/modules/projectimport/eclipse/wizard/Bundle")
392: .getString("LBL_NoteAboutWorkspaceAdvantage"));
393: note.setWrapStyleWord(true);
394: gridBagConstraints = new java.awt.GridBagConstraints();
395: gridBagConstraints.gridx = 0;
396: gridBagConstraints.gridy = 6;
397: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
398: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
399: gridBagConstraints.weighty = 1.0;
400: gridBagConstraints.insets = new java.awt.Insets(24, 0, 0, 0);
401: add(note, gridBagConstraints);
402:
403: }// </editor-fold>//GEN-END:initComponents
404:
405: private void projectDestBrowseActionPerformed(
406: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_projectDestBrowseActionPerformed
407: JFileChooser chooser = new JFileChooser(projectDestDir
408: .getText());
409: chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
410: int ret = chooser.showOpenDialog(this );
411: if (ret == JFileChooser.APPROVE_OPTION) {
412: projectDestDir.setText(chooser.getSelectedFile()
413: .getAbsolutePath());
414: }
415: }//GEN-LAST:event_projectDestBrowseActionPerformed
416:
417: private void projectButtonActionPerformed(
418: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_projectButtonActionPerformed
419: setWorkspaceEnabled(false);
420: projectChanged();
421: projectDir.requestFocusInWindow();
422: firePropertyChange("workspaceChoosen", true, false); // NOI18N
423: }//GEN-LAST:event_projectButtonActionPerformed
424:
425: private void workspaceButtonActionPerformed(
426: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_workspaceButtonActionPerformed
427: setWorkspaceEnabled(true);
428: workspaceChanged();
429: firePropertyChange("workspaceChoosen", false, true); // NOI18N
430: }//GEN-LAST:event_workspaceButtonActionPerformed
431:
432: private void setWorkspaceEnabled(boolean enabled) {
433: workSpaceLBL.setEnabled(enabled);
434: worskpaceBrowse.setEnabled(enabled);
435: workspaceDir.setEnabled(enabled);
436: projectLBL.setEnabled(!enabled);
437: projectBrowse.setEnabled(!enabled);
438: projectDir.setEnabled(!enabled);
439: projectDestBrowse.setEnabled(!enabled);
440: projectDestDir.setEnabled(!enabled);
441: projectDestLBL.setEnabled(!enabled);
442: }
443:
444: private void projectBrowseActionPerformed(
445: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_projectBrowseActionPerformed
446: JFileChooser chooser = new JFileChooser(projectDir.getText());
447: chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
448: int ret = chooser.showOpenDialog(this );
449: if (ret == JFileChooser.APPROVE_OPTION) {
450: projectDir.setText(chooser.getSelectedFile()
451: .getAbsolutePath());
452: }
453: }//GEN-LAST:event_projectBrowseActionPerformed
454:
455: private void worskpaceBrowseActionPerformed(
456: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_worskpaceBrowseActionPerformed
457: JFileChooser chooser = new JFileChooser(getWorkspaceDir());
458: chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
459: int ret = chooser.showOpenDialog(this );
460: if (ret == JFileChooser.APPROVE_OPTION) {
461: workspaceDir.setText(chooser.getSelectedFile()
462: .getAbsolutePath());
463: }
464: }//GEN-LAST:event_worskpaceBrowseActionPerformed
465:
466: // Variables declaration - do not modify//GEN-BEGIN:variables
467: private javax.swing.ButtonGroup buttonGroup;
468: private javax.swing.JTextArea note;
469: private javax.swing.JButton projectBrowse;
470: private javax.swing.JRadioButton projectButton;
471: private javax.swing.JButton projectDestBrowse;
472: private javax.swing.JTextField projectDestDir;
473: private javax.swing.JLabel projectDestLBL;
474: private javax.swing.JTextField projectDir;
475: private javax.swing.JLabel projectLBL;
476: private javax.swing.JLabel workSpaceLBL;
477: private javax.swing.JRadioButton workspaceButton;
478: private javax.swing.JTextField workspaceDir;
479: private javax.swing.JButton worskpaceBrowse;
480: private javax.swing.JTextArea wsDescription;
481: // End of variables declaration//GEN-END:variables
482: }
|