1 11 12 package org.eclipse.ui.internal.cheatsheets.composite.model; 13 14 import java.net.URL ; 15 import java.util.HashSet ; 16 import java.util.Hashtable ; 17 import java.util.Iterator ; 18 import java.util.Map ; 19 import java.util.Observable ; 20 import java.util.Set ; 21 22 import org.eclipse.ui.IMemento; 23 import org.eclipse.ui.cheatsheets.ICheatSheetManager; 24 import org.eclipse.ui.internal.cheatsheets.data.ICheatSheet; 25 import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager; 26 import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheet; 27 import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheetTask; 28 29 public class CompositeCheatSheetModel extends Observable implements ICompositeCheatSheet, ICheatSheet{ 30 31 private String name; 32 private String description; 33 private String explorerId; 34 private ICompositeCheatSheetTask rootTask; 35 private TaskDependencies dependencies; 36 private String id; 37 private CompositeCheatSheetSaveHelper saveHelper; 38 private URL contentURL; 39 private CheatSheetManager manager; 40 private Set stateChangedSet = new HashSet (); 41 42 public void setRootTask(ICompositeCheatSheetTask task) { 43 rootTask = task; 44 } 45 46 public CompositeCheatSheetModel(String name, String description, String explorerId) { 47 this.name = name; 48 this.description = description; 49 this.explorerId = explorerId; 50 this.dependencies = new TaskDependencies(); 51 } 52 53 public String getName() { 54 return name; 55 } 56 57 public String getDescription() { 58 return description; 59 } 60 61 public String getTaskExplorerId() { 62 return explorerId; 63 } 64 65 public ICompositeCheatSheetTask getRootTask() { 66 return rootTask; 67 } 68 69 public void setDependencies(TaskDependencies dependencies) { 70 this.dependencies = dependencies; 71 } 72 73 public TaskDependencies getDependencies() { 74 return dependencies; 75 } 76 77 public URL getContentUrl() { 78 return contentURL; 79 } 80 81 public void setContentUrl(URL newUrl) { 82 contentURL=newUrl; 83 } 84 85 public void setId(String id) { 86 this.id = id; 87 } 88 89 public String getId() { 90 return id; 91 } 92 93 public void setSaveHelper(CompositeCheatSheetSaveHelper saveHelper) { 94 this.saveHelper = saveHelper; 95 } 96 97 102 void stateChanged(ICompositeCheatSheetTask task) { 103 if (!stateChangedSet.contains(task)) { 104 stateChangedSet.add(task); 105 } 106 } 107 108 113 public void sendTaskChangeEvents() { 114 Set blockedStateChanged = new BlockedTaskFinder().findBlockedTaskChanges(stateChangedSet); 115 for (Iterator iter = stateChangedSet.iterator(); iter.hasNext();) { 116 setChanged(); 117 notifyObservers(iter.next()); 118 } 119 for (Iterator iter = blockedStateChanged.iterator(); iter.hasNext();) { 120 setChanged(); 121 notifyObservers(iter.next()); 122 } 123 stateChangedSet.clear(); 124 } 125 126 public IMemento getTaskMemento(String id) { 127 return saveHelper.getTaskMemento(id); 128 } 129 130 public ICheatSheetManager getCheatSheetManager() { 131 return manager; 132 } 133 134 public void setCheatSheetManager(CheatSheetManager manager) { 135 this.manager = manager; 136 } 137 138 public void loadState(Map layoutData) { 139 saveHelper.loadCompositeState(this, layoutData); 140 } 141 142 145 private void resetTask(ICompositeCheatSheetTask task) { 146 if (task instanceof EditableTask) { 147 EditableTask editable = (EditableTask)task; 148 editable.reset(); 149 if (saveHelper != null) { 150 saveHelper.clearTaskMemento(task.getId()); 151 } 152 } else if (task instanceof TaskGroup) { 153 TaskGroup group = (TaskGroup)task; 154 ICompositeCheatSheetTask[] subtasks = group.getSubtasks(); 155 for (int i = 0; i < subtasks.length; i++) { 156 resetTask(subtasks[i]); 157 } 158 group.setStateNoNotify(ICompositeCheatSheetTask.NOT_STARTED); 159 } 160 } 161 162 public void resetAllTasks(Map cheatSheetData) { 163 if (manager != null) { 164 if (cheatSheetData == null) { 165 manager.setData(new Hashtable ()); 166 } else { 167 manager.setData(cheatSheetData); 168 } 169 } 170 saveHelper.clearTaskMementos(); 171 resetTask(getRootTask()); 172 sendTaskChangeEvents(); 173 } 174 175 179 public void resetTasks(ICompositeCheatSheetTask[] restartTasks) { 180 for (int i = 0; i < restartTasks.length; i++) { 181 resetTask(restartTasks[i]); 182 } 183 sendTaskChangeEvents(); 184 } 185 186 } 187 | Popular Tags |