KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > composite > views > CheatsheetTaskEditor


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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.views;
13
14 import java.net.MalformedURLException JavaDoc;
15 import java.net.URL JavaDoc;
16 import java.util.Dictionary JavaDoc;
17
18 import org.eclipse.osgi.util.NLS;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.ui.IMemento;
22 import org.eclipse.ui.cheatsheets.CheatSheetListener;
23 import org.eclipse.ui.cheatsheets.CheatSheetViewerFactory;
24 import org.eclipse.ui.cheatsheets.ICheatSheetEvent;
25 import org.eclipse.ui.forms.widgets.FormToolkit;
26 import org.eclipse.ui.internal.cheatsheets.Messages;
27 import org.eclipse.ui.internal.cheatsheets.composite.parser.ICompositeCheatsheetTags;
28 import org.eclipse.ui.internal.cheatsheets.state.MementoStateManager;
29 import org.eclipse.ui.internal.cheatsheets.views.CheatSheetViewer;
30 import org.eclipse.ui.internal.provisional.cheatsheets.IEditableTask;
31 import org.eclipse.ui.internal.provisional.cheatsheets.TaskEditor;
32
33 public class CheatsheetTaskEditor extends TaskEditor {
34     private CheatSheetViewer viewer;
35     private IEditableTask task;
36
37     public void createControl(Composite parent, FormToolkit toolkit) {
38         viewer = (CheatSheetViewer)CheatSheetViewerFactory.createCheatSheetView();
39         viewer.createPartControl(parent);
40     }
41     
42     public Control getControl() {
43         return viewer.getControl();
44     }
45
46
47     public void setInput(IEditableTask task, IMemento memento) {
48         this.task = task;
49         Dictionary JavaDoc params = task.getParameters();
50         String JavaDoc id = (String JavaDoc)params.get(ICompositeCheatsheetTags.CHEATSHEET_TASK_ID);
51         String JavaDoc path = (String JavaDoc)params.get(ICompositeCheatsheetTags.CHEATSHEET_TASK_PATH);
52         boolean showIntro = true;
53         String JavaDoc showIntroParam = (String JavaDoc)params.get(ICompositeCheatsheetTags.CHEATSHEET_TASK_SHOW_INTRO);
54         if (showIntroParam != null) {
55             showIntro = showIntroParam.equalsIgnoreCase("true"); //$NON-NLS-1$
56
}
57         
58         MementoStateManager stateManager = new MementoStateManager(memento, task.getCompositeCheatSheet().getCheatSheetManager());
59         if (path != null) {
60             URL JavaDoc url;
61             try {
62                 url = task.getInputUrl(path);
63                 if (id == null) {
64                     id = task.getId();
65                 }
66                 viewer.setInput(id, task.getName(), url, stateManager, false);
67             } catch (MalformedURLException JavaDoc e) {
68                 String JavaDoc message = NLS.bind(Messages.ERROR_OPENING_FILE_IN_PARSER, (new Object JavaDoc[] {path}));
69                 viewer.showError(message);
70             }
71         } else if (id != null){
72             viewer.setInput(id, stateManager);
73         } else {
74             viewer.showError(Messages.CHEATSHEET_TASK_NO_ID);
75         }
76         if (!showIntro) {
77             viewer.advanceIntroItem();
78         }
79         viewer.addListener(new TaskListener());
80     }
81     
82     /*
83      * Listener for the cheatsheet used by this class
84      */

85     private class TaskListener extends CheatSheetListener {
86
87         public void cheatSheetEvent(ICheatSheetEvent event) {
88             if (event.getEventType() == ICheatSheetEvent.CHEATSHEET_COMPLETED) {
89                 task.complete();
90             }
91         }
92     }
93
94     public void saveState(IMemento memento) {
95         viewer.saveState(memento);
96     }
97 }
98
Popular Tags