1 11 package org.eclipse.ui.internal.ide; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.IProduct; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.Platform; 18 import org.eclipse.core.runtime.Status; 19 import org.eclipse.jface.dialogs.ErrorDialog; 20 import org.eclipse.jface.dialogs.MessageDialog; 21 import org.eclipse.jface.window.Window; 22 import org.eclipse.swt.custom.BusyIndicator; 23 import org.eclipse.swt.widgets.Shell; 24 import org.eclipse.ui.IWorkbenchWindow; 25 import org.eclipse.ui.actions.ActionFactory; 26 import org.eclipse.ui.actions.PartEventAction; 27 28 31 public class TipsAndTricksAction extends PartEventAction implements 32 ActionFactory.IWorkbenchAction { 33 34 37 private IWorkbenchWindow workbenchWindow; 38 39 44 public TipsAndTricksAction(IWorkbenchWindow window) { 45 super(IDEWorkbenchMessages.TipsAndTricks_text); 46 if (window == null) { 47 throw new IllegalArgumentException (); 48 } 49 this.workbenchWindow = window; 50 setToolTipText(IDEWorkbenchMessages.TipsAndTricks_toolTip); 51 window.getWorkbench().getHelpSystem().setHelp(this, 52 IIDEHelpContextIds.TIPS_AND_TRICKS_ACTION); 53 setActionDefinitionId("org.eclipse.ui.help.tipsAndTricksAction"); workbenchWindow.getPartService().addPartListener(this); 55 } 56 57 60 public void run() { 61 if (workbenchWindow == null) { 62 return; 64 } 65 AboutInfo[] featureInfos = IDEWorkbenchPlugin.getDefault() 67 .getFeatureInfos(); 68 ArrayList tipsAndTricksFeatures = new ArrayList (featureInfos.length); 69 for (int i = 0; i < featureInfos.length; i++) { 70 if (featureInfos[i].getTipsAndTricksHref() != null) { 71 tipsAndTricksFeatures.add(featureInfos[i]); 72 } 73 } 74 75 Shell shell = workbenchWindow.getShell(); 76 77 if (tipsAndTricksFeatures.size() == 0) { 78 MessageDialog.openInformation(shell, IDEWorkbenchMessages.TipsAndTricksMessageDialog_title, 79 IDEWorkbenchMessages.TipsAndTricksMessageDialog_message); 80 return; 81 } 82 83 AboutInfo[] features = new AboutInfo[tipsAndTricksFeatures.size()]; 84 tipsAndTricksFeatures.toArray(features); 85 86 IProduct product = Platform.getProduct(); 87 FeatureSelectionDialog d = new FeatureSelectionDialog(shell, features, 88 product == null ? null : product.getId(), IDEWorkbenchMessages.TipsAndTricksPageSelectionDialog_title, 89 IDEWorkbenchMessages.TipsAndTricksPageSelectionDialog_message, 90 IIDEHelpContextIds.TIPS_AND_TRICKS_PAGE_SELECTION_DIALOG); 91 92 if (d.open() != Window.OK || d.getResult().length != 1) { 93 return; 94 } 95 96 AboutInfo feature = (AboutInfo) d.getResult()[0]; 97 98 101 if (feature != null) { 102 final String href = feature.getTipsAndTricksHref(); 103 if (href != null) { 104 BusyIndicator.showWhile(shell.getDisplay(), new Runnable () { 105 public void run() { 106 workbenchWindow.getWorkbench().getHelpSystem() 107 .displayHelpResource(href); 108 } 109 }); 110 } else { 111 IStatus status = new Status( 112 IStatus.ERROR, 113 IDEWorkbenchPlugin.IDE_WORKBENCH, 114 1, 115 IDEWorkbenchMessages.TipsAndTricksErrorDialog_noHref, null); 116 ErrorDialog.openError(shell, IDEWorkbenchMessages.TipsAndTricksErrorDialog_title, 117 IDEWorkbenchMessages.TipsAndTricksErrorDialog_noHref, 118 status); 119 } 120 } else { 121 IStatus status = new Status(IStatus.ERROR, 122 IDEWorkbenchPlugin.IDE_WORKBENCH, 1, IDEWorkbenchMessages.TipsAndTricksErrorDialog_noHref, null); 123 ErrorDialog.openError(shell, IDEWorkbenchMessages.TipsAndTricksErrorDialog_title, 124 IDEWorkbenchMessages.TipsAndTricksErrorDialog_noFeatures, 125 status); 126 } 127 } 128 129 132 public void dispose() { 133 if (workbenchWindow == null) { 134 return; 136 } 137 workbenchWindow.getPartService().removePartListener(this); 138 workbenchWindow = null; 139 } 140 } 141 | Popular Tags |