1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.jface.action.Action; 14 import org.eclipse.jface.dialogs.MessageDialog; 15 import org.eclipse.jface.resource.ImageDescriptor; 16 import org.eclipse.swt.widgets.Event; 17 import org.eclipse.ui.IPageListener; 18 import org.eclipse.ui.IWorkbenchPage; 19 import org.eclipse.ui.IWorkbenchWindow; 20 import org.eclipse.ui.actions.ActionFactory; 21 import org.eclipse.ui.internal.intro.IntroDescriptor; 22 import org.eclipse.ui.internal.intro.IntroMessages; 23 24 29 public class IntroAction extends Action implements 30 ActionFactory.IWorkbenchAction { 31 32 private IWorkbenchWindow workbenchWindow; 33 34 private IPageListener pageListener = new IPageListener() { 35 36 public void pageActivated(IWorkbenchPage page) { 37 } 39 40 public void pageClosed(IWorkbenchPage page) { 41 setEnabled(workbenchWindow.getPages().length > 0); 42 } 43 44 public void pageOpened(IWorkbenchPage page) { 45 setEnabled(true); 46 } 47 }; 48 49 52 public IntroAction(IWorkbenchWindow window) { 53 super(IntroMessages.Intro_action_text); 54 if (window == null) { 55 throw new IllegalArgumentException (); 56 } 57 this.workbenchWindow = window; 58 IntroDescriptor introDescriptor = ((Workbench) workbenchWindow 59 .getWorkbench()).getIntroDescriptor(); 60 String labelOverride = introDescriptor.getLabelOverride(); 61 if (labelOverride != null) 62 setText(labelOverride); 63 64 setActionDefinitionId("org.eclipse.ui.help.quickStartAction"); 66 window.addPageListener(pageListener); 67 } 68 69 72 public void dispose() { 73 workbenchWindow.removePageListener(pageListener); 74 workbenchWindow = null; 75 } 76 77 80 public void runWithEvent(Event event) { 81 IntroDescriptor introDescriptor = ((Workbench) workbenchWindow 82 .getWorkbench()).getIntroDescriptor(); 83 if (introDescriptor == null) { 84 MessageDialog.openWarning(workbenchWindow.getShell(), 85 IntroMessages.Intro_missing_product_title, 86 IntroMessages.Intro_missing_product_message); 87 } else { 88 workbenchWindow.getWorkbench().getIntroManager().showIntro( 89 workbenchWindow, false); 90 } 91 } 92 93 96 public ImageDescriptor getImageDescriptor() { 97 IntroDescriptor introDescriptor = ((Workbench) workbenchWindow 98 .getWorkbench()).getIntroDescriptor(); 99 if (introDescriptor == null) { 100 return null; 101 } 102 return introDescriptor.getImageDescriptor(); 103 } 104 } 105 | Popular Tags |