1 4 package com.nightlabs.rcp.wizard; 5 6 import java.util.ArrayList ; 7 import java.util.Collections ; 8 import java.util.List ; 9 10 import org.eclipse.jface.wizard.IWizard; 11 import org.eclipse.jface.wizard.IWizardPage; 12 13 28 public class WizardHop implements IWizardHop 29 { 30 private IWizardHop parentHop; 31 32 private List hopPages = new ArrayList (); 33 34 private IWizardHopPage entryPage = null; 35 private IWizardHopPage exitPage = null; 36 37 43 protected WizardHop() 44 { 45 } 46 47 54 public WizardHop(IWizardHopPage entryPage) 55 { 56 setEntryPage(entryPage); 57 } 58 59 62 public IWizardHop getParentHop() 63 { 64 return parentHop; 65 } 66 69 public void setParentHop(IWizardHop parentHop) 70 { 71 this.parentHop = parentHop; 72 } 73 74 77 public IWizard getWizard() 78 { 79 if (entryPage == null) 80 return null; 81 82 return entryPage.getWizard(); 83 } 84 85 88 public void setEntryPage(IWizardHopPage entryPage) 89 { 90 entryPage.setWizardHop(this); 91 this.entryPage = entryPage; 92 } 93 94 97 public IWizardHopPage getExitPage() 98 { 99 return exitPage; 100 } 101 102 105 public void setExitPage(IWizardHopPage exitPage) 106 { 107 this.exitPage = exitPage; 108 if (exitPage != null) { 109 exitPage.setWizard(getWizard()); 110 111 if (exitPage.getWizardHop() == null) 112 throw new NullPointerException ("exitPage.getWizardHop() returns null!"); 113 114 exitPage.getWizardHop().setParentHop(this); 115 } 116 } 117 118 121 public IWizardHopPage getEntryPage() 122 { 123 return entryPage; 124 } 125 126 public void addHopPage(IWizardHopPage page) 127 { 128 page.setWizard(getWizard()); 129 page.setWizardHop(this); 130 hopPages.add(page); 131 } 132 133 public void removeAllHopPages() 134 { 135 hopPages.clear(); 136 } 137 138 public IWizardPage getNextPage(IWizardPage currentPage) 139 { 140 IWizard wizard = getWizard(); 141 if (wizard == null) 142 return null; 143 144 if (currentPage == entryPage) { 145 if (hopPages.isEmpty()) 146 return wizard.getNextPage(entryPage); 147 148 return (IWizardPage) hopPages.get(0); 149 } 150 151 int currIdx = hopPages.indexOf(currentPage); 152 int nextIdx = -1; 153 154 if (currIdx >= 0) 155 nextIdx = currIdx + 1; 156 157 if (nextIdx >= 0) { 158 if (nextIdx < hopPages.size()) 159 return (IWizardPage) hopPages.get(nextIdx); 160 161 if (exitPage != null) 162 return exitPage; 163 } 164 165 IWizardHopPage firstEntryPage = entryPage; 168 while (firstEntryPage.getWizardHop().getParentHop() != null) { 169 firstEntryPage = firstEntryPage.getWizardHop().getParentHop().getEntryPage(); 170 } 171 172 return wizard.getNextPage(firstEntryPage); 173 } 174 175 217 220 public IWizardHopPage getFirstHopPage() 221 { 222 if (hopPages.isEmpty()) 223 return null; 224 225 return (IWizardHopPage) hopPages.get(0); 226 } 227 228 231 public IWizardHopPage getLastHopPage() 232 { 233 if (hopPages.isEmpty()) 234 return null; 235 236 return (IWizardHopPage) hopPages.get(hopPages.size() - 1); 237 } 238 239 242 public boolean removeHopPage(IWizardHopPage page) 243 { 244 return hopPages.remove(page); 245 } 246 247 250 public List getHopPages() 251 { 252 return Collections.unmodifiableList(hopPages); 253 } 254 255 } 256 | Popular Tags |