1 11 12 package org.eclipse.ui.internal.cheatsheets.composite.views; 13 14 import java.net.MalformedURLException ; 15 import java.net.URL ; 16 import java.util.Dictionary ; 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 params = task.getParameters(); 50 String id = (String )params.get(ICompositeCheatsheetTags.CHEATSHEET_TASK_ID); 51 String path = (String )params.get(ICompositeCheatsheetTags.CHEATSHEET_TASK_PATH); 52 boolean showIntro = true; 53 String showIntroParam = (String )params.get(ICompositeCheatsheetTags.CHEATSHEET_TASK_SHOW_INTRO); 54 if (showIntroParam != null) { 55 showIntro = showIntroParam.equalsIgnoreCase("true"); } 57 58 MementoStateManager stateManager = new MementoStateManager(memento, task.getCompositeCheatSheet().getCheatSheetManager()); 59 if (path != null) { 60 URL 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 e) { 68 String message = NLS.bind(Messages.ERROR_OPENING_FILE_IN_PARSER, (new Object [] {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 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 |