Add missing NetBeans *.form files.
[nbgit.git] / src / org / netbeans / modules / git / ui / wizards / CloneDestinationDirectoryPanel.java
blob5f9ba90811f5c77468bc5ff27590bbb97778ca33
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
24 * Contributor(s):
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28 * Microsystems, Inc. All Rights Reserved.
29 * Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
31 * If you wish your version of this file to be governed by only the CDDL
32 * or only the GPL Version 2, indicate your decision by adding
33 * "[Contributor] elects to include this software in this distribution
34 * under the [CDDL or GPL Version 2] license." If you do not indicate a
35 * single choice of license, a recipient has the option to distribute
36 * your version of this file under either the CDDL, the GPL Version 2 or
37 * to extend the choice of license to its licensees as provided above.
38 * However, if you add GPL Version 2 code and therefore, elected the GPL
39 * Version 2 license, then the option applies only if the new code is
40 * made subject to such option by the copyright holder.
42 package org.netbeans.modules.git.ui.wizards;
44 import java.awt.event.ActionEvent;
45 import java.awt.event.ActionListener;
46 import java.io.File;
47 import javax.swing.JFileChooser;
48 import javax.swing.JPanel;
49 import javax.swing.filechooser.FileFilter;
50 import org.netbeans.modules.git.GitModuleConfig;
51 import org.netbeans.modules.versioning.util.AccessibleJFileChooser;
52 import org.netbeans.spi.project.ui.support.ProjectChooser;
53 import org.openide.util.NbBundle;
56 public final class CloneDestinationDirectoryPanel extends JPanel implements ActionListener {
57 private String message;
59 /** Creates new form CloneVisualPanel2 */
60 public CloneDestinationDirectoryPanel() {
61 initComponents();
62 directoryBrowseButton.addActionListener(this);
63 scanForProjectsCheckBox.addActionListener(this);
64 directoryField.setText(defaultWorkingDirectory().getPath());
65 scanForProjectsCheckBox.setSelected(GitModuleConfig.getDefault().getShowCloneCompleted());
68 @Override
69 public String getName() {
70 if (destinationDirectoryPanel == null) {
71 return null;
73 return destinationDirectoryPanel.getName();
76 public String getDirectory() {
77 return directoryField.getText();
80 public String getCloneName() {
81 return nameField.getText();
84 public String getMessage() {
85 return message;
88 public boolean isValid() {
89 String dir = directoryField.getText();
90 String name = nameField.getText();
91 File file = new File (dir, name);
92 if (file.exists()) {
93 message = NbBundle.getMessage(CloneRepositoryPanel.class, "MSG_TARGET_EXISTS"); // NOI18N
94 return false;
95 } else {
96 message = "";
97 return true;
101 /** This method is called from within the constructor to
102 * initialize the form.
103 * WARNING: Do NOT modify this code. The content of this method is
104 * always regenerated by the Form Editor.
106 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
107 private void initComponents() {
109 destinationDirectoryPanel = new javax.swing.JPanel();
110 directoryLabel = new javax.swing.JLabel();
111 directoryBrowseButton = new javax.swing.JButton();
112 nameLabel = new javax.swing.JLabel();
113 jLabel1 = new javax.swing.JLabel();
115 destinationDirectoryPanel.setName(org.openide.util.NbBundle.getMessage(CloneDestinationDirectoryPanel.class, "destinationDirectoryPanel.Name")); // NOI18N
117 directoryLabel.setLabelFor(directoryField);
118 org.openide.awt.Mnemonics.setLocalizedText(directoryLabel, org.openide.util.NbBundle.getMessage(CloneDestinationDirectoryPanel.class, "directoryLabel.Name")); // NOI18N
120 directoryField.addActionListener(new java.awt.event.ActionListener() {
121 public void actionPerformed(java.awt.event.ActionEvent evt) {
122 directoryFieldActionPerformed(evt);
126 org.openide.awt.Mnemonics.setLocalizedText(directoryBrowseButton, org.openide.util.NbBundle.getMessage(CloneDestinationDirectoryPanel.class, "directoryBrowseButton.Name")); // NOI18N
128 nameLabel.setLabelFor(nameField);
129 org.openide.awt.Mnemonics.setLocalizedText(nameLabel, org.openide.util.NbBundle.getMessage(CloneDestinationDirectoryPanel.class, "nameLabel.Name")); // NOI18N
131 scanForProjectsCheckBox.setSelected(true);
132 org.openide.awt.Mnemonics.setLocalizedText(scanForProjectsCheckBox, org.openide.util.NbBundle.getMessage(CloneDestinationDirectoryPanel.class, "CTL_Scan_After_Clone")); // NOI18N
134 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(CloneDestinationDirectoryPanel.class, "directoryTitleLabel.Name")); // NOI18N
136 org.jdesktop.layout.GroupLayout destinationDirectoryPanelLayout = new org.jdesktop.layout.GroupLayout(destinationDirectoryPanel);
137 destinationDirectoryPanel.setLayout(destinationDirectoryPanelLayout);
138 destinationDirectoryPanelLayout.setHorizontalGroup(
139 destinationDirectoryPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
140 .add(destinationDirectoryPanelLayout.createSequentialGroup()
141 .add(destinationDirectoryPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
142 .add(destinationDirectoryPanelLayout.createSequentialGroup()
143 .add(destinationDirectoryPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
144 .add(nameLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
145 .add(directoryLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
146 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
147 .add(destinationDirectoryPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
148 .add(nameField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE)
149 .add(directoryField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE))
150 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
151 .add(directoryBrowseButton))
152 .add(scanForProjectsCheckBox)
153 .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 597, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
154 .addContainerGap())
156 destinationDirectoryPanelLayout.setVerticalGroup(
157 destinationDirectoryPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
158 .add(destinationDirectoryPanelLayout.createSequentialGroup()
159 .add(jLabel1)
160 .add(20, 20, 20)
161 .add(destinationDirectoryPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
162 .add(directoryLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
163 .add(directoryBrowseButton)
164 .add(directoryField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
165 .add(28, 28, 28)
166 .add(destinationDirectoryPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
167 .add(nameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
168 .add(nameLabel))
169 .add(18, 18, 18)
170 .add(scanForProjectsCheckBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 32, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
171 .add(75, 75, 75))
174 scanForProjectsCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CloneDestinationDirectoryPanel.class, "ACSD_Scan_After_Clone")); // NOI18N
176 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
177 this.setLayout(layout);
178 layout.setHorizontalGroup(
179 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
180 .add(destinationDirectoryPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
182 layout.setVerticalGroup(
183 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
184 .add(layout.createSequentialGroup()
185 .add(destinationDirectoryPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
186 .addContainerGap(62, Short.MAX_VALUE))
188 }// </editor-fold>//GEN-END:initComponents
190 private void directoryFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_directoryFieldActionPerformed
191 // TODO add your handling code here:
192 }//GEN-LAST:event_directoryFieldActionPerformed
194 public void actionPerformed(ActionEvent evt) {
195 if (evt.getSource() == directoryBrowseButton) {
196 onBrowseClick();
197 } else if (evt.getSource() == scanForProjectsCheckBox) {
198 GitModuleConfig.getDefault().setShowCloneCompleted(scanForProjectsCheckBox.isSelected());
202 private void onBrowseClick() {
203 File oldFile = defaultWorkingDirectory();
204 JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(CloneDestinationDirectoryPanel.class, "ACSD_BrowseFolder"), oldFile); // NO I18N
205 fileChooser.setDialogTitle(NbBundle.getMessage(CloneDestinationDirectoryPanel.class, "Browse_title")); // NO I18N
206 fileChooser.setMultiSelectionEnabled(false);
207 FileFilter[] old = fileChooser.getChoosableFileFilters();
208 for (int i = 0; i < old.length; i++) {
209 FileFilter fileFilter = old[i];
210 fileChooser.removeChoosableFileFilter(fileFilter);
212 fileChooser.addChoosableFileFilter(new FileFilter() {
213 public boolean accept(File f) {
214 return f.isDirectory();
216 public String getDescription() {
217 return NbBundle.getMessage(CloneDestinationDirectoryPanel.class, "Folders"); // NOI18N
220 fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
221 fileChooser.showDialog(this, NbBundle.getMessage(CloneDestinationDirectoryPanel.class, "OK_Button")); // NO I18N
222 File f = fileChooser.getSelectedFile();
223 if (f != null) {
224 directoryField.setText(f.getAbsolutePath());
229 * Returns file to be initally used.
230 * <ul>
231 * <li>first is takes text in workTextField
232 * <li>then recent project folder
233 * <li>finally <tt>user.home</tt>
234 * <ul>
236 private File defaultWorkingDirectory() {
237 File defaultDir = null;
238 String current = directoryField.getText();
239 if (current != null && !(current.trim().equals(""))) { // NOI18N
240 File currentFile = new File(current);
241 while (currentFile != null && currentFile.exists() == false) {
242 currentFile = currentFile.getParentFile();
244 if (currentFile != null) {
245 if (currentFile.isFile()) {
246 defaultDir = currentFile.getParentFile();
247 } else {
248 defaultDir = currentFile;
253 if (defaultDir == null) {
254 File projectFolder = ProjectChooser.getProjectsFolder();
255 if (projectFolder.exists() && projectFolder.isDirectory()) {
256 defaultDir = projectFolder;
261 if (defaultDir == null) {
262 defaultDir = new File(System.getProperty("user.home")); // NOI18N
265 return defaultDir;
268 // Variables declaration - do not modify//GEN-BEGIN:variables
269 private javax.swing.JPanel destinationDirectoryPanel;
270 private javax.swing.JButton directoryBrowseButton;
271 final javax.swing.JTextField directoryField = new javax.swing.JTextField();
272 private javax.swing.JLabel directoryLabel;
273 private javax.swing.JLabel jLabel1;
274 final javax.swing.JTextField nameField = new javax.swing.JTextField();
275 private javax.swing.JLabel nameLabel;
276 final javax.swing.JCheckBox scanForProjectsCheckBox = new javax.swing.JCheckBox();
277 // End of variables declaration//GEN-END:variables