Skip to main content
summaryrefslogtreecommitdiffstats
blob: ed40ef3f044c308dbdf8db7f5b8c98722c660484 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*******************************************************************************
 * Copyright (c) 2006, 2015 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.ui.internal.cheatsheets.composite.explorer;

import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin;
import org.eclipse.ui.internal.cheatsheets.Messages;
import org.eclipse.ui.internal.cheatsheets.composite.model.AbstractTask;
import org.eclipse.ui.internal.cheatsheets.composite.model.CompositeCheatSheetModel;
import org.eclipse.ui.internal.cheatsheets.composite.model.TaskStateUtilities;
import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheetTask;

/**
 * Action to reset a single task and its children
 */

public class ResetTaskAction extends Action {
	private AbstractTask task;

	public ResetTaskAction(ICompositeCheatSheetTask task) {
        this.task = (AbstractTask) task;
		this.setText(Messages.COMPOSITE_MENU_RESET);
		IPath path = CheatSheetPlugin.ICONS_PATH.append(CheatSheetPlugin.T_ELCL).append("return_to_start.gif");//$NON-NLS-1$
		ImageDescriptor restartImage = CheatSheetPlugin.createImageDescriptor(CheatSheetPlugin.getPlugin().getBundle(), path);
		this.setImageDescriptor(restartImage);
	}

	@Override
	public void run() {
		AbstractTask[] restartTasks = TaskStateUtilities.getRestartTasks(task);
		if (restartTasks.length == 0) return;
		TreeLabelProvider labelProvider = new TreeLabelProvider();
		ConfirmRestartDialog dlg = new ConfirmRestartDialog(
				PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), restartTasks, labelProvider);
		dlg.open();
		labelProvider.dispose();
		if (dlg.getReturnCode() == ConfirmRestartDialog.OK) {
			CompositeCheatSheetModel model = (CompositeCheatSheetModel) restartTasks[0].getCompositeCheatSheet();
			model.resetTasks(restartTasks);
		}
	}

}

Back to the top