Removed unused ServeAction.
[nbgit.git] / src / org / netbeans / modules / git / ui / wizards / CloneWizardAction.java
blob1b26f9f2ff10c3edd7cdd7af272d220a4d4ca8c5
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.Component;
45 import java.awt.Dialog;
46 import java.io.File;
47 import java.text.MessageFormat;
48 import javax.swing.JComponent;
49 import javax.swing.event.ChangeEvent;
50 import javax.swing.event.ChangeListener;
51 import org.netbeans.modules.git.ui.clone.CloneAction;
52 import org.openide.DialogDisplayer;
53 import org.openide.WizardDescriptor;
55 import org.openide.util.HelpCtx;
56 import org.openide.util.actions.CallableSystemAction;
58 // An example action demonstrating how the wizard could be called from within
59 // your code. You can copy-paste the code below wherever you need.
60 public final class CloneWizardAction extends CallableSystemAction implements ChangeListener {
62 private WizardDescriptor.Panel<WizardDescriptor>[] panels;
64 private static CloneWizardAction instance;
65 private WizardDescriptor wizardDescriptor;
66 private CloneRepositoryWizardPanel cloneRepositoryWizardPanel;
67 private CloneDestinationDirectoryWizardPanel cloneDestinationDirectoryWizardPanel;
68 private ClonePathsWizardPanel clonePathsWizardPanel;
69 private PanelsIterator wizardIterator;
70 private String errorMessage;
73 public static synchronized CloneWizardAction getInstance() {
74 if (instance == null) {
75 instance = new CloneWizardAction();
77 return instance;
80 @SuppressWarnings("unchecked")
81 public void performAction() {
82 wizardIterator = new PanelsIterator();
83 wizardDescriptor = new WizardDescriptor(wizardIterator);
85 // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
86 wizardDescriptor.setTitleFormat(new MessageFormat("{0}")); // NOI18N
87 wizardDescriptor.setTitle(org.openide.util.NbBundle.getMessage(CloneWizardAction.class, "CTL_Clone")); // NOI18N
88 Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
89 dialog.setVisible(true);
90 dialog.toFront();
91 boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
92 if (!cancelled) {
93 final String repository = (String) wizardDescriptor.getProperty("repository"); // NOI18N
94 final String username = (String) wizardDescriptor.getProperty("username"); // NOI18N
95 final String password = (String) wizardDescriptor.getProperty("password"); // NOI18N
96 final String directory = (String) wizardDescriptor.getProperty("directory"); // NOI18N
97 final String cloneName = (String) wizardDescriptor.getProperty("cloneName"); // NOI18N
98 final String pullPath = (String) wizardDescriptor.getProperty("defaultPullPath"); // NOI18N
99 final String pushPath = (String) wizardDescriptor.getProperty("defaultPushPath"); // NOI18N
100 File cloneFile = new File(directory, cloneName);
101 CloneAction.performClone(repository, cloneFile.getAbsolutePath(), true, null, pullPath, pushPath);
105 public void stateChanged(ChangeEvent e) {
106 if(wizardIterator==null) {
107 return;
109 WizardDescriptor.Panel step = wizardIterator.current();
110 if(step == null) {
111 return;
113 if (step == cloneRepositoryWizardPanel) {
114 errorMessage = cloneRepositoryWizardPanel.getErrorMessage();
115 } else if (step == clonePathsWizardPanel) {
116 errorMessage = clonePathsWizardPanel.getErrorMessage();
117 } else if (step == cloneDestinationDirectoryWizardPanel) {
118 errorMessage = cloneDestinationDirectoryWizardPanel.getErrorMessage();
120 if (wizardDescriptor != null) {
121 wizardDescriptor.putProperty("WizardPanel_errorMessage", errorMessage); // NOI18N
125 public String getName() {
126 return "Start Sample Wizard"; // NOI18N
129 public String iconResource() {
130 return null;
133 public HelpCtx getHelpCtx() {
134 return new HelpCtx(CloneWizardAction.class);
137 protected boolean asynchronous() {
138 return false;
143 * Initialize panels representing individual wizard's steps and sets
144 * various properties for them influencing wizard appearance.
146 @SuppressWarnings("unchecked")
147 private class PanelsIterator extends WizardDescriptor.ArrayIterator {
149 PanelsIterator() {
152 @Override
153 protected WizardDescriptor.Panel[] initializePanels() {
154 WizardDescriptor.Panel[] panels = new WizardDescriptor.Panel[2];
155 cloneRepositoryWizardPanel = new CloneRepositoryWizardPanel();
156 clonePathsWizardPanel = new ClonePathsWizardPanel();
157 cloneDestinationDirectoryWizardPanel = new CloneDestinationDirectoryWizardPanel();
158 panels = new WizardDescriptor.Panel[] {
159 cloneRepositoryWizardPanel, clonePathsWizardPanel, cloneDestinationDirectoryWizardPanel
161 panels[0].addChangeListener(CloneWizardAction.this);
162 panels[1].addChangeListener(CloneWizardAction.this);
163 String[] steps = new String[panels.length];
164 for (int i = 0; i < panels.length; i++) {
165 Component c = panels[i].getComponent();
166 // Default step name to component name of panel. Mainly useful
167 // for getting the name of the target chooser to appear in the
168 // list of steps.
169 steps[i] = c.getName();
170 if (c instanceof JComponent) { // assume Swing components
171 JComponent jc = (JComponent) c;
172 // Sets step number of a component
173 jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); // NOI18N
174 // Sets steps names for a panel
175 jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
176 // Turn on subtitle creation on each step
177 jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); // NOI18N
178 // Show steps on the left side with the image on the background
179 jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE); // NOI18N
180 // Turn on numbering of all steps
181 jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE); // NOI18N
184 return panels;