1 19 20 package org.netbeans.modules.projectimport.eclipse.wizard; 21 22 import java.io.File ; 23 import java.util.ArrayList ; 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Set ; 28 import javax.swing.event.ChangeEvent ; 29 import javax.swing.event.ChangeListener ; 30 import org.netbeans.modules.projectimport.ProjectImporterException; 31 import org.netbeans.modules.projectimport.eclipse.ProjectFactory; 32 import org.openide.ErrorManager; 33 import org.openide.WizardDescriptor; 34 import org.openide.filesystems.FileUtil; 35 36 41 final class EclipseWizardIterator implements 42 WizardDescriptor.Iterator, ChangeListener { 43 44 private String errorMessage; 45 private SelectionWizardPanel workspacePanel; 46 private ProjectWizardPanel projectPanel; 47 private ImporterWizardPanel current; 48 49 private boolean hasNext; 50 private boolean hasPrevious; 51 52 53 private List changeListeners; 54 55 56 EclipseWizardIterator() { 57 workspacePanel = new SelectionWizardPanel(); 58 workspacePanel.addChangeListener(this); 59 projectPanel = new ProjectWizardPanel(); 60 projectPanel.addChangeListener(this); 61 current = workspacePanel; 62 } 63 64 65 Set getProjects() { 66 if (workspacePanel.isWorkspaceChosen()) { 67 return projectPanel.getProjects(); 68 } else { 69 Set prjs = new HashSet (); 70 try { 71 File projectDirF = FileUtil.normalizeFile(new File (workspacePanel.getProjectDir())); 72 prjs.add(ProjectFactory.getInstance().load(projectDirF)); 73 } catch (ProjectImporterException e) { 74 ErrorManager.getDefault().log(ErrorManager.ERROR, 75 "ProjectImporterException catched: " + e); e.printStackTrace(); 77 } 78 return prjs; 79 } 80 } 81 82 86 int getNumberOfImportedProject() { 87 return (workspacePanel.isWorkspaceChosen() ? 88 projectPanel.getNumberOfImportedProject() : 1); 89 } 90 91 94 String getDestination() { 95 return (workspacePanel.isWorkspaceChosen() ? 96 projectPanel.getDestination() : 97 workspacePanel.getProjectDestinationDir()); 98 } 99 100 103 boolean getRecursively() { 104 return workspacePanel.isWorkspaceChosen(); 105 } 106 107 public void addChangeListener(ChangeListener l) { 108 if (changeListeners == null) { 109 changeListeners = new ArrayList (2); 110 } 111 changeListeners.add(l); 112 } 113 114 public void removeChangeListener(ChangeListener l) { 115 if (changeListeners != null) { 116 if (changeListeners.remove(l) && changeListeners.isEmpty()) { 117 changeListeners = null; 118 } 119 } 120 } 121 122 protected void fireChange() { 123 if (changeListeners != null) { 124 ChangeEvent e = new ChangeEvent (this); 125 for (Iterator i = changeListeners.iterator(); i.hasNext(); ) { 126 ((ChangeListener ) i.next()).stateChanged(e); 127 } 128 } 129 } 130 131 public void previousPanel() { 132 if (current == projectPanel) { 133 current = workspacePanel; 134 hasPrevious = false; 135 hasNext = true; 136 updateErrorMessage(); 137 } 138 } 139 140 public void nextPanel() { 141 if (current == workspacePanel) { 142 projectPanel.loadProjects(workspacePanel.getWorkspaceDir()); 143 current = projectPanel; 144 hasPrevious = true; 145 hasNext = false; 146 updateErrorMessage(); 147 } 148 } 149 150 public String name() { 151 return (current == workspacePanel) ? 152 (workspacePanel.isWorkspaceChosen() ? 153 ImporterWizardPanel.WORKSPACE_LOCATION_STEP : 154 ImporterWizardPanel.PROJECT_SELECTION_STEP) : 155 ImporterWizardPanel.PROJECTS_SELECTION_STEP; 156 } 157 158 public boolean hasPrevious() { 159 return hasPrevious; 160 } 161 162 public boolean hasNext() { 163 return hasNext; 164 } 165 166 public WizardDescriptor.Panel current() { 167 return current; 168 } 169 170 public void stateChanged(javax.swing.event.ChangeEvent e) { 171 if (current == workspacePanel && current.isValid()) { 172 if (workspacePanel.isWorkspaceChosen()) { 173 hasNext = true; 174 } else { 175 hasNext = false; 176 } 177 } 178 updateErrorMessage(); 179 } 180 181 void updateErrorMessage() { 182 errorMessage = current.getErrorMessage(); 183 fireChange(); 184 } 185 186 String getErrorMessage() { 187 return errorMessage; 188 } 189 } 190 | Popular Tags |