2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2009 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]"
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
28 * Microsystems, Inc. All Rights Reserved.
29 * Portions Copyright 2009 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
.nbgit
.ui
.clone
;
44 import java
.awt
.event
.ActionEvent
;
45 import java
.awt
.event
.ActionListener
;
47 import javax
.swing
.JFileChooser
;
48 import javax
.swing
.JPanel
;
49 import javax
.swing
.filechooser
.FileFilter
;
50 import org
.nbgit
.GitModuleConfig
;
51 import org
.netbeans
.modules
.versioning
.util
.AccessibleJFileChooser
;
52 import org
.netbeans
.spi
.project
.ui
.support
.ProjectChooser
;
53 import org
.openide
.util
.NbBundle
;
59 class ClonePanel
extends JPanel
implements ActionListener
{
61 private File repository
;
63 ClonePanel(File respository
, File to
) {
64 this.repository
= respository
;
66 browseButton
.addActionListener(this);
67 setMainCheckBox
.addActionListener(this);
68 fromTextField
.setText(respository
.getAbsolutePath());
69 toTextField
.setText(to
.getParent());
70 toCloneField
.setText(to
.getName());
71 //setMainCheckBox.setSelected(GitModuleConfig.getDefault().getSetMainProject());
74 public File
getTargetDir() {
75 return new File(toTextField
.getText(), toCloneField
.getText());
78 /** This method is called from within the constructor to
79 * initialize the form.
80 * WARNING: Do NOT modify this code. The content of this method is
81 * always regenerated by the Form Editor.
83 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
84 private void initComponents() {
86 fromLabel
= new javax
.swing
.JLabel();
87 toLabel
= new javax
.swing
.JLabel();
88 browseButton
= new javax
.swing
.JButton();
89 fromTextField
= new javax
.swing
.JTextField();
90 toNameLabel
= new javax
.swing
.JLabel();
91 toCloneField
= new javax
.swing
.JTextField();
92 destinationLabel
= new javax
.swing
.JLabel();
93 setMainCheckBox
= new javax
.swing
.JCheckBox();
95 fromLabel
.setLabelFor(fromTextField
);
96 org
.openide
.awt
.Mnemonics
.setLocalizedText(fromLabel
, org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ClonePanel.fromLabel.text")); // NOI18N
98 toLabel
.setLabelFor(toTextField
);
99 org
.openide
.awt
.Mnemonics
.setLocalizedText(toLabel
, org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ClonePanel.toLabel.text")); // NOI18N
101 org
.openide
.awt
.Mnemonics
.setLocalizedText(browseButton
, org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ClonePanel.browseButton.text")); // NOI18N
103 fromTextField
.setEditable(false);
105 toNameLabel
.setLabelFor(toCloneField
);
106 org
.openide
.awt
.Mnemonics
.setLocalizedText(toNameLabel
, org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ClonePanel.toName.text")); // NOI18N
108 org
.openide
.awt
.Mnemonics
.setLocalizedText(destinationLabel
, org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "destinationLabel.text")); // NOI18N
110 org
.openide
.awt
.Mnemonics
.setLocalizedText(setMainCheckBox
, org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "openCheckbox.text")); // NOI18N
112 org
.jdesktop
.layout
.GroupLayout layout
= new org
.jdesktop
.layout
.GroupLayout(this);
113 this.setLayout(layout
);
114 layout
.setHorizontalGroup(
115 layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
116 .add(layout
.createSequentialGroup()
118 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
119 .add(destinationLabel
)
121 .add(layout
.createSequentialGroup()
123 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
125 .add(setMainCheckBox
)))
126 .add(layout
.createSequentialGroup()
129 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
130 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
131 .add(fromTextField
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 428, Short
.MAX_VALUE
)
132 .add(org
.jdesktop
.layout
.GroupLayout
.TRAILING
, layout
.createSequentialGroup()
133 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.TRAILING
)
134 .add(toCloneField
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 319, Short
.MAX_VALUE
)
135 .add(toTextField
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 319, Short
.MAX_VALUE
))
136 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
140 layout
.setVerticalGroup(
141 layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
142 .add(layout
.createSequentialGroup()
144 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.BASELINE
)
146 .add(fromTextField
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
))
148 .add(destinationLabel
)
149 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
150 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.BASELINE
)
152 .add(toTextField
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
)
154 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, Short
.MAX_VALUE
)
155 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.BASELINE
)
156 .add(toCloneField
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
)
158 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
159 .add(setMainCheckBox
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, 21, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
)
163 toTextField
.getAccessibleContext().setAccessibleDescription(org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ACSD_toTextField")); // NOI18N
164 browseButton
.getAccessibleContext().setAccessibleDescription(org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ACSD_Browse")); // NOI18N
165 fromTextField
.getAccessibleContext().setAccessibleDescription(org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ACSD_fromTextField")); // NOI18N
166 toCloneField
.getAccessibleContext().setAccessibleDescription(org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ACSD_toCloneField")); // NOI18N
167 setMainCheckBox
.getAccessibleContext().setAccessibleDescription(org
.openide
.util
.NbBundle
.getMessage(ClonePanel
.class, "ACSD_setMainCheckBox")); // NOI18N
168 }// </editor-fold>//GEN-END:initComponents
171 public void actionPerformed(ActionEvent evt
) {
172 if (evt
.getSource() == browseButton
) {
174 } else if (evt
.getSource() == setMainCheckBox
) {
175 //GitModuleConfig.getDefault().setSetMainProject(setMainCheckBox.isSelected());
179 private void onBrowseClick() {
180 File oldFile
= defaultWorkingDirectory();
181 JFileChooser fileChooser
= new AccessibleJFileChooser(NbBundle
.getMessage(ClonePanel
.class, "ACSD_BrowseFolder"), oldFile
); // NO I18N
182 fileChooser
.setDialogTitle(NbBundle
.getMessage(ClonePanel
.class, "Browse_title")); // NO I18N
183 fileChooser
.setMultiSelectionEnabled(false);
184 FileFilter
[] old
= fileChooser
.getChoosableFileFilters();
185 for (int i
= 0; i
< old
.length
; i
++) {
186 FileFilter fileFilter
= old
[i
];
187 fileChooser
.removeChoosableFileFilter(fileFilter
);
190 fileChooser
.addChoosableFileFilter(new FileFilter() {
191 public boolean accept(File f
) {
192 return f
.isDirectory();
194 public String
getDescription() {
195 return NbBundle
.getMessage(ClonePanel
.class, "Folders");// NOI18N
198 fileChooser
.setFileSelectionMode(JFileChooser
.DIRECTORIES_ONLY
);
199 fileChooser
.showDialog(this, NbBundle
.getMessage(ClonePanel
.class, "OK_Button")); // NO I18N
200 File f
= fileChooser
.getSelectedFile();
202 toTextField
.setText(f
.getAbsolutePath());
206 * Returns file to be initally used.
208 * <li>first is takes text in workTextField
209 * <li>then recent project folder
210 * <li>finally <tt>user.home</tt>
213 private File
defaultWorkingDirectory() {
214 File defaultDir
= null;
215 String current
= toTextField
.getText();
216 if (current
!= null && !(current
.trim().equals(""))) { // NOI18N
217 File currentFile
= new File(current
);
218 while (currentFile
!= null && currentFile
.exists() == false) {
219 currentFile
= currentFile
.getParentFile();
221 if (currentFile
!= null) {
222 if (currentFile
.isFile()) {
223 defaultDir
= currentFile
.getParentFile();
225 defaultDir
= currentFile
;
230 if (defaultDir
== null) {
231 File projectFolder
= ProjectChooser
.getProjectsFolder();
232 if (projectFolder
.exists() && projectFolder
.isDirectory()) {
233 defaultDir
= projectFolder
;
238 if (defaultDir
== null) {
239 defaultDir
= new File(System
.getProperty("user.home")); // NOI18N
245 // Variables declaration - do not modify//GEN-BEGIN:variables
246 private javax
.swing
.JButton browseButton
;
247 private javax
.swing
.JLabel destinationLabel
;
248 private javax
.swing
.JLabel fromLabel
;
249 private javax
.swing
.JTextField fromTextField
;
250 private javax
.swing
.JCheckBox setMainCheckBox
;
251 private javax
.swing
.JTextField toCloneField
;
252 private javax
.swing
.JLabel toLabel
;
253 private javax
.swing
.JLabel toNameLabel
;
254 final javax
.swing
.JTextField toTextField
= new javax
.swing
.JTextField();
255 // End of variables declaration//GEN-END:variables