1 19 package org.netbeans.modules.subversion.ui.wizards; 20 21 import java.awt.Component ; 22 import java.awt.Dialog ; 23 import java.io.File ; 24 import java.text.MessageFormat ; 25 import java.util.Map ; 26 import javax.swing.JComponent ; 27 import javax.swing.event.ChangeEvent ; 28 import javax.swing.event.ChangeListener ; 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 44 public final class ImportWizard implements ChangeListener { 45 46 private WizardDescriptor.Panel[] panels; 47 private RepositoryStep repositoryStep; 48 private ImportStep importStep; 49 private ImportPreviewStep importPreviewStep; 50 51 private String 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 ("{0}")); wizardDescriptor.setTitle(org.openide.util.NbBundle.getMessage(ImportWizard.class, "CTL_Import")); Dialog 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 value = wizardDescriptor.getValue(); 71 boolean finnished = value == WizardDescriptor.FINISH_OPTION; 72 73 if(!finnished) { 74 if(value == WizardDescriptor.CLOSED_OPTION || 76 value == WizardDescriptor.CANCEL_OPTION ) 77 { 78 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 String repositoryUrl = repositoryStep.getRepositoryFile().getRepositoryUrl().toString(); 95 String repositoryFolderUrl = importStep.getRepositoryFolderUrl().toString(); 96 String localPath = context.getRootFiles()[0].getAbsolutePath(); 97 importPreviewStep.setup(repositoryFolderUrl.substring(repositoryUrl.length()), localPath); 98 } 99 100 private void setErrorMessage(String msg) { 101 errorMessage = msg; 102 if (wizardDescriptor != null) { 103 wizardDescriptor.putProperty("WizardPanel_errorMessage", msg); } 105 } 106 107 public void stateChanged(ChangeEvent 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 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 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 [] steps = new String [panels.length]; 142 for (int i = 0; i < panels.length; i++) { 143 Component c = panels[i].getComponent(); 144 steps[i] = c.getName(); 148 if (c instanceof JComponent ) { JComponent jc = (JComponent ) c; 150 jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (i)); jc.putClientProperty("WizardPanel_contentData", steps); jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE); jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE); } 161 } 162 return panels; 163 } 164 165 public void previousPanel() { 166 if(current() == importStep) { 167 importStep.invalid(null); 170 } 171 super.previousPanel(); 172 } 173 174 public void nextPanel() { 175 if(current() == repositoryStep) { 176 File 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 getMessage() { 194 return importStep.getImportMessage(); 195 } 196 197 public SVNUrl getRepositoryFolderUrl() { 198 return importStep.getRepositoryFolderUrl(); 199 } 200 201 public Map getCommitFiles() { 202 return importPreviewStep.getCommitFiles(); 203 } 204 205 } 206 207 | Popular Tags |