KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Map JavaDoc;
26 import javax.swing.JComponent JavaDoc;
27 import javax.swing.event.ChangeEvent JavaDoc;
28 import javax.swing.event.ChangeListener JavaDoc;
29 import org.netbeans.modules.subversion.ui.browser.BrowserAction;
30 import org.netbeans.modules.subversion.ui.browser.CreateFolderAction;
31 import org.netbeans.modules.subversion.ui.wizards.importstep.ImportPreviewStep;
32 import org.netbeans.modules.subversion.ui.wizards.importstep.ImportStep;
33 import org.netbeans.modules.subversion.ui.wizards.repositorystep.RepositoryStep;
34 import org.netbeans.modules.subversion.util.Context;
35 import org.openide.DialogDisplayer;
36 import org.openide.WizardDescriptor;
37 import org.tigris.subversion.svnclientadapter.SVNUrl;
38
39 /*
40  *
41  *
42  * @author Tomas Stupka
43  */

44 public final class ImportWizard implements ChangeListener JavaDoc {
45     
46     private WizardDescriptor.Panel[] panels;
47     private RepositoryStep repositoryStep;
48     private ImportStep importStep;
49     private ImportPreviewStep importPreviewStep;
50
51     private String JavaDoc errorMessage;
52     private WizardDescriptor wizardDescriptor;
53     private PanelsIterator wizardIterator;
54     
55     private final Context context;
56     
57     public ImportWizard(Context context) {
58         this.context = context;
59     }
60     
61     public boolean show() {
62         wizardIterator = new PanelsIterator();
63         wizardDescriptor = new WizardDescriptor(wizardIterator);
64         wizardDescriptor.setTitleFormat(new MessageFormat JavaDoc("{0}")); // NOI18N
65
wizardDescriptor.setTitle(org.openide.util.NbBundle.getMessage(ImportWizard.class, "CTL_Import")); // NOI18N
66
Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
67         dialog.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportWizard.class, "CTL_Import"));
68         dialog.setVisible(true);
69         dialog.toFront();
70         Object JavaDoc value = wizardDescriptor.getValue();
71         boolean finnished = value == WizardDescriptor.FINISH_OPTION;
72         
73         if(!finnished) {
74             // wizard wasn't properly finnished ...
75
if(value == WizardDescriptor.CLOSED_OPTION ||
76                value == WizardDescriptor.CANCEL_OPTION )
77             {
78                 // wizard was closed or canceled -> reset all steps & kill all running tasks
79
repositoryStep.stop();
80                 importStep.stop();
81             }
82         } else if (value == WizardDescriptor.FINISH_OPTION) {
83             if(wizardIterator.current() == importStep) {
84                 setupImportPreviewStep();
85             } else if (wizardIterator.current() == importPreviewStep) {
86                 importPreviewStep.storeTableSorter();
87             }
88         }
89         return finnished;
90     }
91
92     private void setupImportPreviewStep() {
93         // must be initialized so we may retrieve the commitFiles for the ImportAction
94
String JavaDoc repositoryUrl = repositoryStep.getRepositoryFile().getRepositoryUrl().toString();
95         String JavaDoc repositoryFolderUrl = importStep.getRepositoryFolderUrl().toString();
96         String JavaDoc localPath = context.getRootFiles()[0].getAbsolutePath();
97         importPreviewStep.setup(repositoryFolderUrl.substring(repositoryUrl.length()), localPath);
98     }
99     
100     private void setErrorMessage(String JavaDoc msg) {
101         errorMessage = msg;
102         if (wizardDescriptor != null) {
103             wizardDescriptor.putProperty("WizardPanel_errorMessage", msg); // NOI18N
104
}
105     }
106
107     public void stateChanged(ChangeEvent JavaDoc e) {
108         if(wizardIterator==null) {
109             return;
110         }
111         AbstractStep step = (AbstractStep) wizardIterator.current();
112         if(step==null) {
113             return;
114         }
115         setErrorMessage(step.getErrorMessage());
116     }
117     
118     /**
119      * Initialize panels representing individual wizard's steps and sets
120      * various properties for them influencing wizard appearance.
121      */

122     private class PanelsIterator extends WizardDescriptor.ArrayIterator {
123
124         PanelsIterator() {
125         }
126
127         protected WizardDescriptor.Panel[] initializePanels() {
128             WizardDescriptor.Panel[] panels = new WizardDescriptor.Panel[3];
129
130             repositoryStep = new RepositoryStep();
131             repositoryStep.addChangeListener(ImportWizard.this);
132
133             File JavaDoc file = context.getRootFiles()[0];
134             importStep = new ImportStep(new BrowserAction[] { new CreateFolderAction(file.getName())}, file);
135             importStep.addChangeListener(ImportWizard.this);
136
137             importPreviewStep = new ImportPreviewStep(context);
138
139             panels = new WizardDescriptor.Panel[] {repositoryStep, importStep, importPreviewStep};
140
141             String JavaDoc[] steps = new String JavaDoc[panels.length];
142             for (int i = 0; i < panels.length; i++) {
143                 Component JavaDoc c = panels[i].getComponent();
144                 // Default step name to component name of panel. Mainly useful
145
// for getting the name of the target chooser to appear in the
146
// list of steps.
147
steps[i] = c.getName();
148                 if (c instanceof JComponent JavaDoc) { // assume Swing components
149
JComponent JavaDoc jc = (JComponent JavaDoc) c;
150                     // Sets step number of a component
151
jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(i)); // NOI18N
152
// Sets steps names for a panel
153
jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
154
// Turn on subtitle creation on each step
155
jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); // NOI18N
156
// Show steps on the left side with the image on the background
157
jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE); // NOI18N
158
// Turn on numbering of all steps
159
jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE); // NOI18N
160
}
161             }
162             return panels;
163         }
164
165         public void previousPanel() {
166             if(current() == importStep) {
167                 // just a dummy to force setting the message in
168
// through importStep.validateUserInput(); in nextPanel()
169
importStep.invalid(null);
170             }
171             super.previousPanel();
172         }
173
174         public void nextPanel() {
175             if(current() == repositoryStep) {
176                 File JavaDoc file = context.getRootFiles()[0];
177                 importStep.setup(repositoryStep.getRepositoryFile().appendPath(file.getName()));
178             } else if(current() == importStep) {
179                 setupImportPreviewStep();
180             }
181             super.nextPanel();
182             if(current() == importStep) {
183                 importStep.validateUserInput();
184             }
185         }
186
187     }
188
189     public SVNUrl getRepositoryUrl() {
190         return repositoryStep.getRepositoryFile().getRepositoryUrl();
191     }
192
193     public String JavaDoc getMessage() {
194         return importStep.getImportMessage();
195     }
196
197     public SVNUrl getRepositoryFolderUrl() {
198         return importStep.getRepositoryFolderUrl();
199     }
200
201     public Map JavaDoc getCommitFiles() {
202         return importPreviewStep.getCommitFiles();
203     }
204
205 }
206
207
Popular Tags