001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 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: *******************************************************************************/package org.eclipse.ui.internal.cheatsheets.composite.views;
011:
012: import java.net.MalformedURLException;
013: import java.net.URL;
014: import java.util.Dictionary;
015:
016: import org.eclipse.osgi.util.NLS;
017: import org.eclipse.swt.widgets.Composite;
018: import org.eclipse.swt.widgets.Control;
019: import org.eclipse.ui.IMemento;
020: import org.eclipse.ui.cheatsheets.CheatSheetListener;
021: import org.eclipse.ui.cheatsheets.CheatSheetViewerFactory;
022: import org.eclipse.ui.cheatsheets.ICheatSheetEvent;
023: import org.eclipse.ui.forms.widgets.FormToolkit;
024: import org.eclipse.ui.internal.cheatsheets.Messages;
025: import org.eclipse.ui.internal.cheatsheets.composite.parser.ICompositeCheatsheetTags;
026: import org.eclipse.ui.internal.cheatsheets.state.MementoStateManager;
027: import org.eclipse.ui.internal.cheatsheets.views.CheatSheetViewer;
028: import org.eclipse.ui.internal.provisional.cheatsheets.IEditableTask;
029: import org.eclipse.ui.internal.provisional.cheatsheets.TaskEditor;
030:
031: public class CheatsheetTaskEditor extends TaskEditor {
032: private CheatSheetViewer viewer;
033: private IEditableTask task;
034:
035: public void createControl(Composite parent, FormToolkit toolkit) {
036: viewer = (CheatSheetViewer) CheatSheetViewerFactory
037: .createCheatSheetView();
038: viewer.createPartControl(parent);
039: }
040:
041: public Control getControl() {
042: return viewer.getControl();
043: }
044:
045: public void setInput(IEditableTask task, IMemento memento) {
046: this .task = task;
047: Dictionary params = task.getParameters();
048: String id = (String) params
049: .get(ICompositeCheatsheetTags.CHEATSHEET_TASK_ID);
050: String path = (String) params
051: .get(ICompositeCheatsheetTags.CHEATSHEET_TASK_PATH);
052: boolean showIntro = true;
053: String showIntroParam = (String) params
054: .get(ICompositeCheatsheetTags.CHEATSHEET_TASK_SHOW_INTRO);
055: if (showIntroParam != null) {
056: showIntro = showIntroParam.equalsIgnoreCase("true"); //$NON-NLS-1$
057: }
058:
059: MementoStateManager stateManager = new MementoStateManager(
060: memento, task.getCompositeCheatSheet()
061: .getCheatSheetManager());
062: if (path != null) {
063: URL url;
064: try {
065: url = task.getInputUrl(path);
066: if (id == null) {
067: id = task.getId();
068: }
069: viewer.setInput(id, task.getName(), url, stateManager,
070: false);
071: } catch (MalformedURLException e) {
072: String message = NLS.bind(
073: Messages.ERROR_OPENING_FILE_IN_PARSER,
074: (new Object[] { path }));
075: viewer.showError(message);
076: }
077: } else if (id != null) {
078: viewer.setInput(id, stateManager);
079: } else {
080: viewer.showError(Messages.CHEATSHEET_TASK_NO_ID);
081: }
082: if (!showIntro) {
083: viewer.advanceIntroItem();
084: }
085: viewer.addListener(new TaskListener());
086: }
087:
088: /*
089: * Listener for the cheatsheet used by this class
090: */
091: private class TaskListener extends CheatSheetListener {
092:
093: public void cheatSheetEvent(ICheatSheetEvent event) {
094: if (event.getEventType() == ICheatSheetEvent.CHEATSHEET_COMPLETED) {
095: task.complete();
096: }
097: }
098: }
099:
100: public void saveState(IMemento memento) {
101: viewer.saveState(memento);
102: }
103: }
|