KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > wizards > CheckoutWizard


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.subversion.ui.wizards;
20
21 import java.awt.Component JavaDoc;
22 import java.awt.Dialog JavaDoc;
23 import java.io.File JavaDoc;
24 import java.text.MessageFormat JavaDoc;
25 import javax.swing.JComponent JavaDoc;
26 import javax.swing.event.ChangeEvent JavaDoc;
27 import javax.swing.event.ChangeListener JavaDoc;
28 import org.netbeans.modules.subversion.RepositoryFile;
29 import org.netbeans.modules.subversion.SvnModuleConfig;
30 import org.netbeans.modules.subversion.ui.repository.Repository;
31 import org.netbeans.modules.subversion.ui.wizards.repositorystep.RepositoryStep;
32 import org.netbeans.modules.subversion.ui.wizards.checkoutstep.CheckoutStep;
33 import org.openide.DialogDisplayer;
34 import org.openide.WizardDescriptor;
35 import org.tigris.subversion.svnclientadapter.SVNUrl;
36
37 /*
38  *
39  *
40  * @author Tomas Stupka
41  */

42 public final class CheckoutWizard implements ChangeListener JavaDoc {
43     
44     private WizardDescriptor.Panel[] panels;
45     private RepositoryStep repositoryStep;
46     private CheckoutStep checkoutStep;
47     
48     private String JavaDoc errorMessage;
49     private WizardDescriptor wizardDescriptor;
50     private PanelsIterator wizardIterator;
51         
52     public boolean show() {
53         wizardIterator = new PanelsIterator();
54         wizardDescriptor = new WizardDescriptor(wizardIterator);
55         wizardDescriptor.setTitleFormat(new MessageFormat JavaDoc("{0}")); // NOI18N
56
wizardDescriptor.setTitle(org.openide.util.NbBundle.getMessage(CheckoutWizard.class, "CTL_Checkout")); // NOI18N
57
Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
58         dialog.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CheckoutWizard.class, "CTL_Checkout"));
59         dialog.setVisible(true);
60         dialog.toFront();
61         Object JavaDoc value = wizardDescriptor.getValue();
62         boolean finnished = value == WizardDescriptor.FINISH_OPTION;
63         
64         if(finnished) {
65             onFinished();
66         } else {
67             // wizard wasn't properly finnished ...
68
if(value == WizardDescriptor.CLOSED_OPTION ||
69                value == WizardDescriptor.CANCEL_OPTION )
70             {
71                 // wizard was closed or canceled -> reset all steps & kill all running tasks
72
repositoryStep.stop();
73             }
74         }
75         return finnished;
76     }
77     
78     /** Called on sucessfull finish. */
79     private void onFinished() {
80         String JavaDoc checkout = checkoutStep.getWorkdir().getPath();
81         SvnModuleConfig.getDefault().getPreferences().put(CheckoutStep.CHECKOUT_DIRECTORY, checkout);
82     }
83
84     private void setErrorMessage(String JavaDoc msg) {
85         errorMessage = msg;
86         if (wizardDescriptor != null) {
87             wizardDescriptor.putProperty("WizardPanel_errorMessage", msg); // NOI18N
88
}
89     }
90
91     public void stateChanged(ChangeEvent JavaDoc e) {
92         if(wizardIterator==null) {
93             return;
94         }
95         AbstractStep step = (AbstractStep) wizardIterator.current();
96         if(step==null) {
97             return;
98         }
99         setErrorMessage(step.getErrorMessage());
100     }
101     
102     /**
103      * Initialize panels representing individual wizard's steps and sets
104      * various properties for them influencing wizard appearance.
105      */

106     private class PanelsIterator extends WizardDescriptor.ArrayIterator {
107         PanelsIterator() {
108         }
109
110         protected WizardDescriptor.Panel[] initializePanels() {
111             WizardDescriptor.Panel[] panels = new WizardDescriptor.Panel[3];
112             repositoryStep = new RepositoryStep(Repository.FLAG_ACCEPT_REVISION);
113             repositoryStep.addChangeListener(CheckoutWizard.this);
114             checkoutStep = new CheckoutStep();
115             checkoutStep.addChangeListener(CheckoutWizard.this);
116             
117             panels = new WizardDescriptor.Panel[] {repositoryStep, checkoutStep};
118
119             String JavaDoc[] steps = new String JavaDoc[panels.length];
120             for (int i = 0; i < panels.length; i++) {
121                 Component JavaDoc c = panels[i].getComponent();
122                 // Default step name to component name of panel. Mainly useful
123
// for getting the name of the target chooser to appear in the
124
// list of steps.
125
steps[i] = c.getName();
126                 if (c instanceof JComponent JavaDoc) { // assume Swing components
127
JComponent JavaDoc jc = (JComponent JavaDoc) c;
128                     // Sets step number of a component
129
jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(i)); // NOI18N
130
// Sets steps names for a panel
131
jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
132
// Turn on subtitle creation on each step
133
jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); // NOI18N
134
// Show steps on the left side with the image on the background
135
jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE); // NOI18N
136
// Turn on numbering of all steps
137
jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE); // NOI18N
138
}
139             }
140             return panels;
141         }
142
143         public void nextPanel() {
144             if(current() == repositoryStep) {
145                 checkoutStep.setup(repositoryStep.getRepositoryFile());
146             }
147             super.nextPanel();
148         }
149     }
150     
151     public RepositoryFile[] getRepositoryFiles() {
152         return checkoutStep.getRepositoryFiles();
153     }
154     
155     public File JavaDoc getWorkdir() {
156         return checkoutStep.getWorkdir();
157     }
158
159     public SVNUrl getRepositoryRoot() {
160         return repositoryStep.getRepositoryFile().getRepositoryUrl();
161     }
162
163     public boolean isAtWorkingDirLevel() {
164         return checkoutStep.isAtWorkingDirLevel();
165     }
166 }
167
168
Popular Tags