KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > composite > explorer > ResetTaskAction


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.cheatsheets.composite.explorer;
13
14 import org.eclipse.core.runtime.IPath;
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.ui.PlatformUI;
18 import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin;
19 import org.eclipse.ui.internal.cheatsheets.Messages;
20 import org.eclipse.ui.internal.cheatsheets.composite.model.AbstractTask;
21 import org.eclipse.ui.internal.cheatsheets.composite.model.CompositeCheatSheetModel;
22 import org.eclipse.ui.internal.cheatsheets.composite.model.TaskStateUtilities;
23 import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheetTask;
24
25 /**
26  * Action to reset a single task and its children
27  */

28
29 public class ResetTaskAction extends Action {
30     private AbstractTask task;
31
32     public ResetTaskAction(ICompositeCheatSheetTask task) {
33         this.task = (AbstractTask) task;
34         this.setText(Messages.COMPOSITE_MENU_RESET);
35         IPath path = CheatSheetPlugin.ICONS_PATH.append(CheatSheetPlugin.T_ELCL).append("return_to_start.gif");//$NON-NLS-1$
36
ImageDescriptor restartImage = CheatSheetPlugin.createImageDescriptor(CheatSheetPlugin.getPlugin().getBundle(), path);
37         this.setImageDescriptor(restartImage);
38     }
39     
40     public void run() {
41         AbstractTask[] restartTasks = TaskStateUtilities.getRestartTasks(task);
42         if (restartTasks.length == 0) return;
43         TreeLabelProvider labelProvider = new TreeLabelProvider();
44         ConfirmRestartDialog dlg = new ConfirmRestartDialog(
45                 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), restartTasks, labelProvider);
46         dlg.open();
47         labelProvider.dispose();
48         if (dlg.getReturnCode() == ConfirmRestartDialog.OK) {
49             CompositeCheatSheetModel model = (CompositeCheatSheetModel) restartTasks[0].getCompositeCheatSheet();
50             model.resetTasks(restartTasks);
51         }
52     }
53
54 }
55
Popular Tags