001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: * Sebastian Davids <sdavids@gmx.de> - Fix for bug 93373 - [Intro]
011: * TipsAndTricksAction should not use magic numbers
012: *******************************************************************************/package org.eclipse.ui.internal.ide;
013:
014: import java.util.ArrayList;
015:
016: import org.eclipse.core.runtime.IProduct;
017: import org.eclipse.core.runtime.IStatus;
018: import org.eclipse.core.runtime.Platform;
019: import org.eclipse.core.runtime.Status;
020: import org.eclipse.jface.dialogs.ErrorDialog;
021: import org.eclipse.jface.dialogs.MessageDialog;
022: import org.eclipse.jface.window.Window;
023: import org.eclipse.swt.custom.BusyIndicator;
024: import org.eclipse.swt.widgets.Shell;
025: import org.eclipse.ui.IWorkbenchWindow;
026: import org.eclipse.ui.actions.ActionFactory;
027: import org.eclipse.ui.actions.PartEventAction;
028:
029: /**
030: * Launch the tips and tricks action.
031: */
032: public class TipsAndTricksAction extends PartEventAction implements
033: ActionFactory.IWorkbenchAction {
034:
035: /**
036: * The workbench window this action is registered with.
037: */
038: private IWorkbenchWindow workbenchWindow;
039:
040: /**
041: * Create an instance of this class.
042: *
043: * @param window the window
044: */
045: public TipsAndTricksAction(IWorkbenchWindow window) {
046: super (IDEWorkbenchMessages.TipsAndTricks_text);
047: if (window == null) {
048: throw new IllegalArgumentException();
049: }
050: this .workbenchWindow = window;
051: setToolTipText(IDEWorkbenchMessages.TipsAndTricks_toolTip);
052: window.getWorkbench().getHelpSystem().setHelp(this ,
053: IIDEHelpContextIds.TIPS_AND_TRICKS_ACTION);
054: setActionDefinitionId("org.eclipse.ui.help.tipsAndTricksAction"); //$NON-NLS-1$
055: workbenchWindow.getPartService().addPartListener(this );
056: }
057:
058: /**
059: * The user has invoked this action
060: */
061: public void run() {
062: if (workbenchWindow == null) {
063: // action has been disposed
064: return;
065: }
066: // Ask the user to select a feature
067: AboutInfo[] featureInfos = IDEWorkbenchPlugin.getDefault()
068: .getFeatureInfos();
069: ArrayList tipsAndTricksFeatures = new ArrayList(
070: featureInfos.length);
071: for (int i = 0; i < featureInfos.length; i++) {
072: if (featureInfos[i].getTipsAndTricksHref() != null) {
073: tipsAndTricksFeatures.add(featureInfos[i]);
074: }
075: }
076:
077: Shell shell = workbenchWindow.getShell();
078:
079: if (tipsAndTricksFeatures.size() == 0) {
080: MessageDialog
081: .openInformation(
082: shell,
083: IDEWorkbenchMessages.TipsAndTricksMessageDialog_title,
084: IDEWorkbenchMessages.TipsAndTricksMessageDialog_message);
085: return;
086: }
087:
088: AboutInfo[] features = new AboutInfo[tipsAndTricksFeatures
089: .size()];
090: tipsAndTricksFeatures.toArray(features);
091:
092: IProduct product = Platform.getProduct();
093: FeatureSelectionDialog d = new FeatureSelectionDialog(
094: shell,
095: features,
096: product == null ? null : product.getId(),
097: IDEWorkbenchMessages.TipsAndTricksPageSelectionDialog_title,
098: IDEWorkbenchMessages.TipsAndTricksPageSelectionDialog_message,
099: IIDEHelpContextIds.TIPS_AND_TRICKS_PAGE_SELECTION_DIALOG);
100:
101: if (d.open() != Window.OK || d.getResult().length != 1) {
102: return;
103: }
104:
105: AboutInfo feature = (AboutInfo) d.getResult()[0];
106:
107: /**
108: * Open the tips and trick help topic
109: */
110: if (feature != null) {
111: final String href = feature.getTipsAndTricksHref();
112: if (href != null) {
113: BusyIndicator.showWhile(shell.getDisplay(),
114: new Runnable() {
115: public void run() {
116: workbenchWindow.getWorkbench()
117: .getHelpSystem()
118: .displayHelpResource(href);
119: }
120: });
121: } else {
122: IStatus status = new Status(
123: IStatus.ERROR,
124: IDEWorkbenchPlugin.IDE_WORKBENCH,
125: IStatus.INFO,
126: IDEWorkbenchMessages.TipsAndTricksErrorDialog_noHref,
127: null);
128: ErrorDialog
129: .openError(
130: shell,
131: IDEWorkbenchMessages.TipsAndTricksErrorDialog_title,
132: IDEWorkbenchMessages.TipsAndTricksErrorDialog_noHref,
133: status);
134: }
135: } else {
136: IStatus status = new Status(
137: IStatus.ERROR,
138: IDEWorkbenchPlugin.IDE_WORKBENCH,
139: IStatus.INFO,
140: IDEWorkbenchMessages.TipsAndTricksErrorDialog_noHref,
141: null);
142: ErrorDialog
143: .openError(
144: shell,
145: IDEWorkbenchMessages.TipsAndTricksErrorDialog_title,
146: IDEWorkbenchMessages.TipsAndTricksErrorDialog_noFeatures,
147: status);
148: }
149: }
150:
151: /* (non-Javadoc)
152: * Method declared on ActionFactory.IWorkbenchAction.
153: */
154: public void dispose() {
155: if (workbenchWindow == null) {
156: // action has already been disposed
157: return;
158: }
159: workbenchWindow.getPartService().removePartListener(this);
160: workbenchWindow = null;
161: }
162: }
|