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 javax.swing.JComponent ; 26 import javax.swing.event.ChangeEvent ; 27 import javax.swing.event.ChangeListener ; 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 42 public final class CheckoutWizard implements ChangeListener { 43 44 private WizardDescriptor.Panel[] panels; 45 private RepositoryStep repositoryStep; 46 private CheckoutStep checkoutStep; 47 48 private String 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 ("{0}")); wizardDescriptor.setTitle(org.openide.util.NbBundle.getMessage(CheckoutWizard.class, "CTL_Checkout")); Dialog 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 value = wizardDescriptor.getValue(); 62 boolean finnished = value == WizardDescriptor.FINISH_OPTION; 63 64 if(finnished) { 65 onFinished(); 66 } else { 67 if(value == WizardDescriptor.CLOSED_OPTION || 69 value == WizardDescriptor.CANCEL_OPTION ) 70 { 71 repositoryStep.stop(); 73 } 74 } 75 return finnished; 76 } 77 78 79 private void onFinished() { 80 String checkout = checkoutStep.getWorkdir().getPath(); 81 SvnModuleConfig.getDefault().getPreferences().put(CheckoutStep.CHECKOUT_DIRECTORY, checkout); 82 } 83 84 private void setErrorMessage(String msg) { 85 errorMessage = msg; 86 if (wizardDescriptor != null) { 87 wizardDescriptor.putProperty("WizardPanel_errorMessage", msg); } 89 } 90 91 public void stateChanged(ChangeEvent 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 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 [] steps = new String [panels.length]; 120 for (int i = 0; i < panels.length; i++) { 121 Component c = panels[i].getComponent(); 122 steps[i] = c.getName(); 126 if (c instanceof JComponent ) { JComponent jc = (JComponent ) c; 128 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); } 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 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 |