1 11 12 package org.eclipse.ui.internal.intro.impl.model; 13 14 import org.eclipse.core.runtime.IRegistryChangeEvent; 15 import org.eclipse.core.runtime.PerformanceStats; 16 import org.eclipse.jface.action.Action; 17 import org.eclipse.jface.action.IToolBarManager; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.ui.IActionBars; 20 import org.eclipse.ui.IMemento; 21 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; 22 import org.eclipse.ui.internal.intro.impl.IIntroConstants; 23 import org.eclipse.ui.internal.intro.impl.IntroPlugin; 24 import org.eclipse.ui.internal.intro.impl.Messages; 25 import org.eclipse.ui.internal.intro.impl.model.viewer.IntroModelContentProvider; 26 import org.eclipse.ui.internal.intro.impl.model.viewer.IntroModelLabelProvider; 27 import org.eclipse.ui.internal.intro.impl.util.ImageUtil; 28 import org.eclipse.ui.internal.intro.impl.util.Log; 29 import org.eclipse.ui.internal.intro.impl.util.Util; 30 import org.eclipse.ui.intro.IIntroPart; 31 import org.eclipse.ui.intro.config.CustomizableIntroPart; 32 33 40 public abstract class AbstractIntroPartImplementation { 41 42 private CustomizableIntroPart introPart = null; 44 45 private IMemento memento; 47 48 protected History history = new History(); 49 50 boolean logUIcreationTime = true; 54 55 protected Action backAction = new Action() { 57 58 { 59 setToolTipText(Messages.Browser_backwardButton_tooltip); 60 setImageDescriptor(ImageUtil 61 .createImageDescriptor("full/elcl16/backward_nav.gif")); setDisabledImageDescriptor(ImageUtil 63 .createImageDescriptor("full/dlcl16/backward_nav.gif")); } 65 66 public void run() { 67 navigateBackward(); 68 } 69 }; 70 71 protected Action forwardAction = new Action() { 72 73 { 74 setToolTipText(Messages.Browser_forwardButton_tooltip); 75 setImageDescriptor(ImageUtil 76 .createImageDescriptor("full/elcl16/forward_nav.gif")); setDisabledImageDescriptor(ImageUtil 78 .createImageDescriptor("full/dlcl16/forward_nav.gif")); } 80 81 public void run() { 82 navigateForward(); 83 } 84 }; 85 86 protected Action homeAction = new Action() { 87 88 { 89 setToolTipText(Messages.Browser_homeButton_tooltip); 90 setImageDescriptor(ImageUtil 91 .createImageDescriptor("full/elcl16/home_nav.gif")); setDisabledImageDescriptor(ImageUtil 93 .createImageDescriptor("full/dlcl16/home_nav.gif")); } 95 96 public void run() { 97 navigateHome(); 98 } 99 }; 100 101 protected Action viewIntroModelAction = new Action() { 102 103 { 104 setToolTipText(Messages.IntroPart_showContentButton_tooltip); 105 setImageDescriptor(ImageUtil 106 .createImageDescriptor("contents_view.gif")); } 108 109 public void run() { 110 ElementTreeSelectionDialog treeViewer = new ElementTreeSelectionDialog( 111 getIntroPart().getIntroSite().getShell(), 112 new IntroModelLabelProvider(), new IntroModelContentProvider()); 113 treeViewer.setInput(getModel()); 114 treeViewer.open(); 115 } 116 }; 117 118 123 public abstract void createPartControl(Composite parent); 124 125 132 public void init(IIntroPart introPart, IMemento memento) { 133 this.introPart = (CustomizableIntroPart) introPart; 135 this.memento = memento; 136 } 137 138 141 public IntroModelRoot getModel() { 142 return IntroPlugin.getDefault().getIntroModelRoot(); 143 } 144 145 148 public CustomizableIntroPart getIntroPart() { 149 return introPart; 150 } 151 152 153 158 public void updateHistory(String location) { 159 history.updateHistory(location); 160 updateNavigationActionsState(); 161 } 162 163 168 public void updateHistory(AbstractIntroPage page) { 169 history.updateHistory(page); 170 updateNavigationActionsState(); 171 } 172 173 174 179 public abstract void setFocus(); 180 181 182 187 protected abstract void updateNavigationActionsState(); 188 189 190 191 public abstract boolean navigateBackward(); 192 193 public abstract boolean navigateForward(); 194 195 public abstract boolean navigateHome(); 196 197 198 202 public void dispose() { 203 } 205 206 207 210 protected void addToolBarActions() { 211 IActionBars actionBars = getIntroPart().getIntroSite().getActionBars(); 213 IToolBarManager toolBarManager = actionBars.getToolBarManager(); 214 toolBarManager.add(viewIntroModelAction); 215 toolBarManager.update(true); 216 actionBars.updateActionBars(); 217 } 218 219 226 public void standbyStateChanged(boolean standby, boolean isStandbyPartNeeded) { 227 PerformanceStats setStandbyStateStats = null; 228 long start = 0; 229 if (Log.logPerformance) { 230 if (logUIcreationTime && PerformanceStats.ENABLED) { 231 PerformanceStats stats = PerformanceStats.getStats( 232 IIntroConstants.PERF_UI_ZOOM, IIntroConstants.INTRO); 233 stats.endRun(); 234 Util 235 .logPerformanceMessage( 236 "(perf stats) time spent in UI code before content is displayed (standbyStateChanged event is fired) ", stats.getRunningTime()); 238 stats.reset(); 239 } 240 241 setStandbyStateStats = PerformanceStats.getStats( 243 IIntroConstants.PERF_SET_STANDBY_STATE, IIntroConstants.INTRO); 244 setStandbyStateStats.startRun(); 245 start = System.currentTimeMillis(); 246 } 247 248 249 doStandbyStateChanged(standby, isStandbyPartNeeded); 250 251 if (Log.logPerformance) { 253 if (PerformanceStats.ENABLED) { 254 setStandbyStateStats.endRun(); 255 Util 256 .logPerformanceMessage( 257 "(perf stats) setting standby state (zooming, displaying content) took:", +setStandbyStateStats.getRunningTime()); 259 setStandbyStateStats.reset(); 260 } else 261 Util 262 .logPerformanceTime( 263 "setting standby state (zooming, generating content, setText() ) took:", +start); 265 266 if (logUIcreationTime) { 267 if (PerformanceStats.ENABLED) { 268 PerformanceStats stats = PerformanceStats.getStats( 269 IIntroConstants.PERF_VIEW_CREATION_TIME, 270 IIntroConstants.INTRO); 271 stats.endRun(); 272 Util 273 .logPerformanceMessage( 274 "END - (perf stats): creating CustomizableIntroPart view took:", +stats.getRunningTime()); 276 stats.reset(); 277 } else 278 Util.logPerformanceTime( 279 "END: creating CustomizableIntroPart view took:", +IntroPlugin.getDefault().gettUICreationStartTime()); 281 282 283 logUIcreationTime = false; 285 } 286 287 } 288 } 289 290 291 292 295 protected abstract void doStandbyStateChanged(boolean standby, 296 boolean isStandbyPartNeeded); 297 298 299 312 public void saveState(IMemento memento) { 313 saveCurrentPage(memento); 314 } 315 316 317 325 protected void saveCurrentPage(IMemento memento) { 326 IntroModelRoot model = getModel(); 327 328 if (memento == null || model == null) 329 return; 330 String currentPage = model.getCurrentPageId(); 331 if (currentPage != null && currentPage.length() > 0) { 332 memento.putString(IIntroConstants.MEMENTO_CURRENT_PAGE_ATT, 333 currentPage); 334 } 335 } 336 337 338 345 protected String getCachedCurrentPage() { 346 String newContentPage = ExtensionMap.getInstance().getStartPage(); 349 if (newContentPage != null) { 350 return newContentPage; 351 } 352 IMemento memento = getMemento(); 353 if (memento == null) 354 return null; 355 return memento.getString(IIntroConstants.MEMENTO_CURRENT_PAGE_ATT); 356 } 357 358 359 362 public IMemento getMemento() { 363 return memento; 364 } 365 366 372 public void registryChanged(IRegistryChangeEvent event) { 373 history.clear(); 374 handleRegistryChanged(event); 376 } 377 378 383 protected abstract void handleRegistryChanged(IRegistryChangeEvent event); 384 385 386 public History getHistory() { 387 return history; 388 } 389 390 391 } 392 | Popular Tags |