Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDejan Gloszic2006-02-09 22:23:56 +0000
committerDejan Gloszic2006-02-09 22:23:56 +0000
commit58eb0b1860f4e1a18a276ffbe39120026e02cb27 (patch)
treed9bfce66835731d92c0bffa02b0b59596af7bd5f /org.eclipse.ui.cheatsheets
parent3c34d603453646985cc7695029c7f16df88bbaa0 (diff)
downloadeclipse.platform.ua-58eb0b1860f4e1a18a276ffbe39120026e02cb27.tar.gz
eclipse.platform.ua-58eb0b1860f4e1a18a276ffbe39120026e02cb27.tar.xz
eclipse.platform.ua-58eb0b1860f4e1a18a276ffbe39120026e02cb27.zip
127178 Composite Cheat Sheets should use mementos to save state
Diffstat (limited to 'org.eclipse.ui.cheatsheets')
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ICompositeCheatSheet.java8
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ICompositeCheatSheetTask.java22
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ITaskEditor.java48
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin.java134
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.java6
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.properties6
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CheatSheetTask.java34
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CompositeCheatSheetModel.java50
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CompositeCheatSheetSaveHelper.java242
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/SuccesorTaskFinder.java2
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/parser/ICompositeCheatsheetTags.java6
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CheatsheetTaskEditor.java23
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CompositeCheatSheetPage.java106
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetSaveHelper.java9
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetPage.java38
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java74
16 files changed, 466 insertions, 342 deletions
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ICompositeCheatSheet.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ICompositeCheatSheet.java
index 9e5885b66..328854be4 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ICompositeCheatSheet.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ICompositeCheatSheet.java
@@ -11,8 +11,6 @@
package org.eclipse.ui.cheatsheets;
-
-
/**
* Interface representing a composite cheatsheet.
* A composite cheat sheet has a single root task, each task may have
@@ -38,4 +36,10 @@ public interface ICompositeCheatSheet {
* @return the root task object
*/
ICompositeCheatSheetTask getRootTask();
+
+ /**
+ * Get the manager which allows data to be shared between tasks.
+ * @return the CheatSheetManager for this composite cheat cheet. May not be null.
+ */
+ ICheatSheetManager getCheatSheetManager();
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ICompositeCheatSheetTask.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ICompositeCheatSheetTask.java
index b1adf3229..09737ca96 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ICompositeCheatSheetTask.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ICompositeCheatSheetTask.java
@@ -15,8 +15,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.Dictionary;
-import org.eclipse.core.runtime.IPath;
-
/**
* A task within a composite cheat sheet.
* <p>
@@ -30,15 +28,15 @@ public interface ICompositeCheatSheetTask {
* The constant that indicates that the task has not been
* processed yet.
*/
- int NOT_STARTED = 0;
+ public static final int NOT_STARTED = 0;
/**
* The constant that indicates that the task is in progress.
*/
- int IN_PROGRESS = 1;
+ public static final int IN_PROGRESS = 1;
/**
* The constant that indicates that the task has been completed.
*/
- int COMPLETED = 2;
+ public static final int COMPLETED = 2;
/**
* @return the unique identifier of this task.
*/
@@ -128,14 +126,6 @@ public interface ICompositeCheatSheetTask {
public boolean isStartable();
/**
- * Gets a location where the state for this task can be saved.
- * @return the path of a writeable directory on file system where this
- * task can save its state. This will always be a subdirectory of the
- * directory in which the state is stored for the parent composite cheat sheet.
- */
- public IPath getStateLocation();
-
- /**
* Gets a URL which can be used to open the content file for this
* task if the content file can be specified by a path relative to
* the content file for the composite cheat sheet which contains it.
@@ -145,4 +135,10 @@ public interface ICompositeCheatSheetTask {
* location of the content file for the composite cheat sheet.
*/
public URL getInputUrl(String path) throws MalformedURLException;
+
+ /**
+ * Get the enclosing composite cheat sheet
+ * @return the composite cheat sheet which contains this task
+ */
+ public ICompositeCheatSheet getCompositeCheatSheet();
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ITaskEditor.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ITaskEditor.java
index e5a75aaba..389c735c2 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ITaskEditor.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ITaskEditor.java
@@ -13,6 +13,7 @@ package org.eclipse.ui.cheatsheets;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IMemento;
import org.eclipse.ui.forms.widgets.FormToolkit;
/**
@@ -24,23 +25,36 @@ import org.eclipse.ui.forms.widgets.FormToolkit;
*/
public interface ITaskEditor {
-/**
- * Creates the widget
- * @param parent
- * @param toolkit
- */
+
+ /**
+ * Creates the widget
+ * @param parent
+ * @param toolkit
+ */
public void createControl(Composite parent, FormToolkit toolkit);
-
-/**
- * @return the Control created by a previous call to CreateControl()
- */
+
+ /**
+ * @return the Control created by a previous call to CreateControl()
+ */
public Control getControl();
-
-/**
- * Starts editing the provided task. The editor is responsible
- * for setting the 'percentage complete' state of the task and
- * saving its state. createControl() will always be called before start().
- * @param task
- */
- public void start(ICompositeCheatSheetTask task);
+
+ /**
+ * Starts editing the provided task. The editor is responsible
+ * for setting the 'percentage complete' state of the task and
+ * saving its state. createControl() will always be called before setInput().
+ * The memento will be <b>null</b> if the task has not been previously started
+ * or if it is being restarted. If the editor is being restored from a previous
+ * session the memento will contain the last saved state.
+ * @param task The task associated with this editor
+ * @param memento The state of this task saved from a previous invocation, may be null.
+ */
+ public void setInput(ICompositeCheatSheetTask task, IMemento memento);
+
+ /**
+ * Saves the object state within a memento.
+ *
+ * @param memento a memento to receive the object state
+ */
+ public void saveState(IMemento memento);
+
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin.java
index 03b4bc60e..40007cfd7 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CheatSheetPlugin.java
@@ -54,7 +54,7 @@ public class CheatSheetPlugin extends AbstractUIPlugin {
private CheatSheetHistory history = null;
private DocumentBuilder documentBuilder = null;
- private static final String DEFAULT_CHEATSHEET_STATE_FILENAME = "cheatsheet.xml"; //$NON-NLS-1$
+ private static final String HISTORY_FILENAME = "history.xml"; //$NON-NLS-1$
private static final String MEMENTO_TAG_CHEATSHEET = "cheatsheet"; //$NON-NLS-1$
private static final String MEMENTO_TAG_VERSION = "version"; //$NON-NLS-1$
private static final String VERSION_STRING[] = { "0.0", "3.0.0" }; //$NON-NLS-1$ //$NON-NLS-2$
@@ -94,8 +94,6 @@ public class CheatSheetPlugin extends AbstractUIPlugin {
return image;
}
-
-
/**
* Returns the CheatSheetHistory
*/
@@ -108,11 +106,11 @@ public class CheatSheetPlugin extends AbstractUIPlugin {
}
/**
- * Answer the workbench state file.
+ * Get a file from the state folder.
*/
- private File getCheatSheetStateFile() {
+ private File getCheatSheetStateFile(String filename) {
IPath path = CheatSheetPlugin.getPlugin().getStateLocation();
- path = path.append(DEFAULT_CHEATSHEET_STATE_FILENAME);
+ path = path.append(filename);
return path.toFile();
}
@@ -184,36 +182,13 @@ public class CheatSheetPlugin extends AbstractUIPlugin {
private void restoreCheatSheetHistory() {
SafeRunner.run(new SafeRunnable() {
public void run() {
- InputStreamReader reader = null;
-
- try {
- // Read the cheatsheet state file.
- final File stateFile = getCheatSheetStateFile();
-
- FileInputStream input = new FileInputStream(stateFile);
- reader = new InputStreamReader(input, "utf-8"); //$NON-NLS-1$
- IMemento memento = XMLMemento.createReadRoot(reader);
-
+ IMemento memento;
+ memento = readMemento(HISTORY_FILENAME);
+ if (memento != null) {
IMemento childMem = memento.getChild(MEMENTO_TAG_CHEATSHEET_HISTORY);
if (childMem != null) {
history.restoreState(childMem);
}
- } catch (FileNotFoundException e) {
- // Do nothing, the file will not exist the first time the workbench in used.
- } catch (Exception e) {
- String message = Messages.ERROR_READING_STATE_FILE;
- IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e);
- CheatSheetPlugin.getPlugin().getLog().log(status);
- } finally {
- try {
- if (reader != null)
- reader.close();
- } catch (IOException e) {
- // Not much to do, just catch the exception and keep going.
- String message = Messages.ERROR_READING_STATE_FILE;
- IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e);
- CheatSheetPlugin.getPlugin().getLog().log(status);
- }
}
}
public void handleException(Throwable e) {
@@ -223,6 +198,46 @@ public class CheatSheetPlugin extends AbstractUIPlugin {
}
});
}
+
+ /**
+ * Read a memento from the state directory for the cheatsheets plugin
+ * @param filename A simple filename
+ * @return A memento read from the state directory or null if the memento could not be read
+ */
+ public XMLMemento readMemento(String filename) {
+ XMLMemento memento;
+ InputStreamReader reader = null;
+
+ try {
+ // Read the cheatsheet state file.
+ final File stateFile = getCheatSheetStateFile(filename);
+
+ FileInputStream input = new FileInputStream(stateFile);
+ reader = new InputStreamReader(input, "utf-8"); //$NON-NLS-1$
+ memento = XMLMemento.createReadRoot(reader);
+
+
+ } catch (FileNotFoundException e) {
+ memento = null;
+ // Do nothing, the file will not exist the first time the workbench in used.
+ } catch (Exception e) {
+ String message = Messages.ERROR_READING_STATE_FILE;
+ IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e);
+ CheatSheetPlugin.getPlugin().getLog().log(status);
+ memento = null;
+ } finally {
+ try {
+ if (reader != null)
+ reader.close();
+ } catch (IOException e) {
+ // Not much to do, just catch the exception and keep going.
+ String message = Messages.ERROR_READING_STATE_FILE;
+ IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e);
+ CheatSheetPlugin.getPlugin().getLog().log(status);
+ }
+ }
+ return memento;
+ }
/**
* Saves the current cheatsheet history so it can be restored later on
@@ -238,27 +253,9 @@ public class CheatSheetPlugin extends AbstractUIPlugin {
// Save perspective history.
getCheatSheetHistory().saveState(memento.createChild(MEMENTO_TAG_CHEATSHEET_HISTORY));
- // Save the IMemento to a file.
- File stateFile = getCheatSheetStateFile();
- OutputStreamWriter writer = null;
- try {
- FileOutputStream stream = new FileOutputStream(stateFile);
- writer = new OutputStreamWriter(stream, "utf-8"); //$NON-NLS-1$
- memento.save(writer);
- } catch (IOException e) {
- stateFile.delete();
- String message = Messages.ERROR_WRITING_STATE_FILE;
- IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e);
+ IStatus status = saveMemento(memento, HISTORY_FILENAME);
+ if (!status.isOK()) {
CheatSheetPlugin.getPlugin().getLog().log(status);
- } finally {
- try {
- if (writer != null)
- writer.close();
- } catch (IOException e) {
- String message = Messages.ERROR_WRITING_STATE_FILE;
- IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e);
- CheatSheetPlugin.getPlugin().getLog().log(status);
- }
}
}
public void handleException(Throwable e) {
@@ -268,6 +265,39 @@ public class CheatSheetPlugin extends AbstractUIPlugin {
}
});
}
+
+ /**
+ * Save the memento to a file in this plugins state area
+ * @param memento The memento to save
+ * @param filename A simple filename
+ * @return OK_Status if the memento was saved without error, otherwise an error
+ * status
+ */
+ public IStatus saveMemento(XMLMemento memento, String filename) {
+ // Save the IMemento to a file.
+ File stateFile = getCheatSheetStateFile(filename);
+ OutputStreamWriter writer = null;
+ try {
+ FileOutputStream stream = new FileOutputStream(stateFile);
+ writer = new OutputStreamWriter(stream, "utf-8"); //$NON-NLS-1$
+ memento.save(writer);
+ return Status.OK_STATUS;
+ } catch (IOException e) {
+ stateFile.delete();
+ String message = Messages.ERROR_WRITING_STATE_FILE;
+ IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e);
+ return status;
+ } finally {
+ try {
+ if (writer != null)
+ writer.close();
+ } catch (IOException e) {
+ String message = Messages.ERROR_WRITING_STATE_FILE;
+ IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e);
+ CheatSheetPlugin.getPlugin().getLog().log(status);
+ }
+ }
+ }
/* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.java
index dcba1b569..1ca5e6725 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.java
@@ -119,7 +119,11 @@ public final class Messages extends NLS {
public static String COMPOSITE_PAGE_BLOCKED;
public static String COMPOSITE_PAGE_TASK_NOT_COMPLETE;
public static String EXPLORER_PULLDOWN_MENU;
-
+ public static String COMPOSITE_RESTART_DIALOG_TITLE;
+ public static String COMPOSITE_RESTART_CONFIRM_MESSAGE;
+ public static String RESTART_ALL_MENU;
+ public static String RESTART_MENU;
+
static {
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.properties b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.properties
index 327378d50..d9323bf60 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.properties
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.properties
@@ -33,8 +33,10 @@ RESTORE_ALL_TOOLTIP = Expand To Previous Expansion States
CATEGORY_OTHER = Other
# CheatSheetMenu
-CHEAT_SHEET_OTHER_MENU = Other...
+CHEAT_SHEET_OTHER_MENU = Launch Other...
EXPLORER_PULLDOWN_MENU = Explorer
+RESTART_ALL_MENU = Restart all tasks
+RESTART_MENU = Restart
# CoreItem
PERFORM_TASK_TOOLTIP = Click to Perform
@@ -166,3 +168,5 @@ COMPOSITE_PAGE_GOTO_TASK = Go to task ''{0}''
COMPOSITE_PAGE_START_TASK = Start working on this task
COMPOSITE_PAGE_BLOCKED = This task cannot be started until all prerequisite tasks are completed.
COMPOSITE_PAGE_TASK_NOT_COMPLETE = Task ''{0}'' is not complete
+COMPOSITE_RESTART_DIALOG_TITLE = Restart Composite Cheat Sheet
+COMPOSITE_RESTART_CONFIRM_MESSAGE = This will reset the state of all tasks.
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CheatSheetTask.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CheatSheetTask.java
index 2b19907c7..de58a8bc1 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CheatSheetTask.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CheatSheetTask.java
@@ -11,18 +11,19 @@
package org.eclipse.ui.internal.cheatsheets.composite.model;
-import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Iterator;
import java.util.List;
-import org.eclipse.core.runtime.IPath;
+
+import org.eclipse.ui.cheatsheets.ICompositeCheatSheet;
import org.eclipse.ui.cheatsheets.ICompositeCheatSheetTask;
+import org.eclipse.ui.cheatsheets.ITaskEditor;
/**
- * A task that represents a single cheatsheet within a composite cheatsheet.
+ * A single task within a composite cheatsheet.
*/
public class CheatSheetTask implements ICompositeCheatSheetTask {
@@ -47,6 +48,8 @@ public class CheatSheetTask implements ICompositeCheatSheetTask {
private ArrayList successorTasks;
private int percentageComplete;
+
+ private ITaskEditor editor;
private static final ICompositeCheatSheetTask[] EMPTY = new ICompositeCheatSheetTask[0];
@@ -191,26 +194,19 @@ public class CheatSheetTask implements ICompositeCheatSheetTask {
model.notifyStateChanged(this);
}
- public IPath getStateLocation() {
- if (model != null) {
- IPath statePath = model.getStateLocation().append(getId());
- File statePathAsFile = statePath.toFile();
- // Create directory if necessary
- if (!statePathAsFile.exists()) {
- statePathAsFile.mkdirs();
- }
- if (statePathAsFile.exists()) {
- return statePath;
- }
- }
- return null;
- }
-
public URL getInputUrl(String path) throws MalformedURLException {
return new URL(model.getContentUrl(), path);
}
- public CompositeCheatSheetModel getModel() {
+ public void setEditor(ITaskEditor editor) {
+ this.editor = editor;
+ }
+
+ public ITaskEditor getEditor() {
+ return editor;
+ }
+
+ public ICompositeCheatSheet getCompositeCheatSheet() {
return model;
}
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CompositeCheatSheetModel.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CompositeCheatSheetModel.java
index 27894ff6f..1d2166ddf 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CompositeCheatSheetModel.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CompositeCheatSheetModel.java
@@ -14,10 +14,13 @@ package org.eclipse.ui.internal.cheatsheets.composite.model;
import java.net.URL;
import java.util.Observable;
-import org.eclipse.core.runtime.IPath;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.cheatsheets.ICheatSheetManager;
import org.eclipse.ui.cheatsheets.ICompositeCheatSheetTask;
import org.eclipse.ui.cheatsheets.ICompositeCheatSheet;
+import org.eclipse.ui.cheatsheets.ITaskEditor;
import org.eclipse.ui.internal.cheatsheets.data.ICheatSheet;
+import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
public class CompositeCheatSheetModel extends Observable implements ICompositeCheatSheet, ICheatSheet{
@@ -30,6 +33,7 @@ public class CompositeCheatSheetModel extends Observable implements ICompositeCh
private String id;
private CompositeCheatSheetSaveHelper saveHelper;
private URL contentURL;
+ private CheatSheetManager manager;
public void setRootTask(ICompositeCheatSheetTask task) {
rootTask = task;
@@ -40,6 +44,7 @@ public class CompositeCheatSheetModel extends Observable implements ICompositeCh
this.description = description;
this.explorerId = explorerId;
this.dependencies = new TaskDependencies();
+ // TODO initialize the CheatSheetManager
}
public String getName() {
@@ -81,10 +86,6 @@ public class CompositeCheatSheetModel extends Observable implements ICompositeCh
public String getId() {
return id;
}
-
- public IPath getStateLocation() {
- return saveHelper.getSavePath();
- }
public void setSaveHelper(CompositeCheatSheetSaveHelper saveHelper) {
this.saveHelper = saveHelper;
@@ -94,5 +95,44 @@ public class CompositeCheatSheetModel extends Observable implements ICompositeCh
setChanged();
notifyObservers(task);
}
+
+ public IMemento getTaskMemento(String id) {
+ return saveHelper.getTaskMemento(id);
+ }
+
+ public ICheatSheetManager getCheatSheetManager() {
+ return manager;
+ }
+
+ public void setCheatSheetManager(CheatSheetManager manager) {
+ this.manager = manager;
+ }
+
+ public void loadState() {
+ saveHelper.loadCompositeState(this);
+ }
+
+ /*
+ * Reset the state of a task and it's children
+ */
+ private void resetTask(ICompositeCheatSheetTask task) {
+ CheatSheetTask csTask = (CheatSheetTask)task;
+ csTask.setState(0);
+ csTask.setPercentageComplete(0);
+ ITaskEditor editor = csTask.getEditor();
+ if (editor != null) {
+ editor.setInput(task, null);
+ }
+ ICompositeCheatSheetTask[] subtasks = csTask.getSubtasks();
+ for (int i = 0; i < subtasks.length; i++) {
+ resetTask(subtasks[i]);
+ }
+ }
+
+ public void resetAllTasks() {
+ resetTask(getRootTask());
+ saveHelper.clearTaskMementos();
+
+ }
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CompositeCheatSheetSaveHelper.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CompositeCheatSheetSaveHelper.java
index 84bab7e89..32b061559 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CompositeCheatSheetSaveHelper.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CompositeCheatSheetSaveHelper.java
@@ -10,36 +10,34 @@
*******************************************************************************/
package org.eclipse.ui.internal.cheatsheets.composite.model;
-import java.net.MalformedURLException;
-import java.net.URL;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
-import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.XMLMemento;
+import org.eclipse.ui.cheatsheets.ICheatSheetManager;
import org.eclipse.ui.cheatsheets.ICompositeCheatSheetTask;
+import org.eclipse.ui.cheatsheets.ITaskEditor;
import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin;
-import org.eclipse.ui.internal.cheatsheets.ICheatSheetResource;
-import org.eclipse.ui.internal.cheatsheets.Messages;
import org.eclipse.ui.internal.cheatsheets.composite.parser.ICompositeCheatsheetTags;
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetSaveHelper;
import org.eclipse.ui.internal.cheatsheets.data.IParserTags;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
+import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
+
+/**
+ * Class to save and restore composite cheatsheet state using a memento
+ * There is a child memento for each task which contains keys for the
+ * state and percentage complete. There is also a grandchild memento for
+ * each task that has been started.
+ */
public class CompositeCheatSheetSaveHelper extends CheatSheetSaveHelper {
+ private static final String DOT_XML = ".xml"; //$NON-NLS-1$
+ private Map taskMementoMap;
+
/**
* Constructor
*/
@@ -47,135 +45,125 @@ public class CompositeCheatSheetSaveHelper extends CheatSheetSaveHelper {
super();
}
- public IStatus loadCompositeState(CompositeCheatSheetModel model, IPath savePath) {
- if (savePath != null) {
- this.savePath = savePath;
- } else {
- this.savePath = Platform
- .getStateLocation(CheatSheetPlugin.getPlugin().getBundle());
- }
-
- Path filePath = getStateFile(model.getId());
- Document doc = null;
- URL readURL = null;
+ public IStatus loadCompositeState(CompositeCheatSheetModel model) {
+ XMLMemento readMemento = CheatSheetPlugin.getPlugin().readMemento(model.getId() + DOT_XML);
+ if (readMemento == null) {
+ return Status.OK_STATUS;
+ }
+ taskMementoMap = createTaskMap(readMemento);
+ loadTaskState(taskMementoMap, (CheatSheetTask)model.getRootTask());
+ loadCheatsheetManagerData(readMemento, model.getCheatSheetManager());
+ return Status.OK_STATUS;
+ }
- try {
- readURL = filePath.toFile().toURL();
- doc = readXMLFile(readURL);
- } catch (MalformedURLException mue) {
- String message = NLS.bind(Messages.ERROR_CREATING_STATEFILE_URL,
- (new Object[] { readURL }));
- IStatus status = new Status(IStatus.ERROR,
- ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK,
- message, mue);
- return status;
+ private Map createTaskMap(XMLMemento readMemento) {
+ Map map = new HashMap();
+ IMemento[] tasks = readMemento.getChildren(ICompositeCheatsheetTags.TASK);
+ for (int i = 0; i < tasks.length; i++) {
+ String taskId = tasks[i].getString(ICompositeCheatsheetTags.TASK_ID);
+ if (taskId != null) {
+ map.put(taskId, tasks[i]);
+ }
}
+ return map;
+ }
- if (doc == null) {
- return Status.OK_STATUS;
- }
- Node rootnode = doc.getDocumentElement();
- NamedNodeMap rootatts = rootnode.getAttributes();
- if (isReference(doc)) {
- String path = getAttributeWithName(rootatts, IParserTags.PATH);
- return loadCompositeState(model, new Path(path));
+ private void loadTaskState(Map taskMap, CheatSheetTask task) {
+ ICompositeCheatSheetTask[] children = task.getSubtasks();
+ IMemento memento = (IMemento)taskMap.get(task.getId());
+ if (memento != null) {
+ String state = memento.getString(ICompositeCheatsheetTags.STATE);
+ if (state != null) {
+ task.setState(Integer.parseInt(state));
+ }
+ String percentage = memento.getString(ICompositeCheatsheetTags.PERCENTAGE_COMPLETE);
+ if (percentage != null) {
+ task.setPercentageComplete(Integer.parseInt(percentage));
+ }
}
-
- // The root node should be of type compositeCheatSheetState
-
- if (rootnode.getNodeName() != ICompositeCheatsheetTags.COMPOSITE_CHEATSHEET_STATE) {
- String message = NLS.bind(Messages.ERROR_PARSING_ROOT_NODE_TYPE,
- (new Object[] {ICompositeCheatsheetTags.COMPOSITE_CHEATSHEET_STATE}));
- IStatus status = new Status(IStatus.ERROR,
- ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK,
- message, null);
- return status;
+ for (int i = 0; i < children.length; i++) {
+ loadTaskState(taskMap, (CheatSheetTask) children[i]);
}
-
- NodeList children = rootnode.getChildNodes();
- for (int i = 0; i < children.getLength(); i++) {
- String nodeName = children.item(i).getNodeName();
- if (ICompositeCheatsheetTags.TASK.equals(nodeName)) {
- return loadTaskState((CheatSheetTask)model.getRootTask(), children.item(i));
- }
- }
- return new Status(IStatus.ERROR,
- ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK,
- Messages.ERROR_PARSING_NO_ROOT, null);
}
-
- private IStatus loadTaskState(CheatSheetTask task, Node taskNode) {
- NamedNodeMap attributes = taskNode.getAttributes();
- Node state = attributes.getNamedItem(ICompositeCheatsheetTags.STATE);
- Node percentage = attributes.getNamedItem(ICompositeCheatsheetTags.PERCENTAGE_COMPLETE);
- if (state != null) {
- task.setState(Integer.parseInt(state.getNodeValue()));
- }
- if (percentage != null) {
- task.setPercentageComplete(Integer.parseInt(percentage.getNodeValue()));
+
+ private void loadCheatsheetManagerData(XMLMemento readMemento, ICheatSheetManager manager) {
+ if (manager == null) {
+ return;
}
-
- NodeList children = taskNode.getChildNodes();
- for (int i = 0; i < children.getLength(); i++) {
- if (i < task.getSubtasks().length) {
- loadTaskState((CheatSheetTask)task.getSubtasks()[i], children.item(i));
- }
+ IMemento[] children = readMemento.getChildren(ICompositeCheatsheetTags.CHEAT_SHEET_MANAGER);
+ for (int i = 0; i < children.length; i++) {
+ IMemento childMemento = children[i];
+ String key = childMemento.getString(ICompositeCheatsheetTags.KEY);
+ String value = childMemento.getString(ICompositeCheatsheetTags.VALUE);
+ manager.setData(key, value);
}
- // TODO detect bad state
- return Status.OK_STATUS;
}
-
+
/**
* Save the state of a composite cheat sheet model
* @param model
* @return
*/
public IStatus saveCompositeState(CompositeCheatSheetModel model) {
+ XMLMemento writeMemento = XMLMemento.createWriteRoot(ICompositeCheatsheetTags.COMPOSITE_CHEATSHEET_STATE);
+ writeMemento.putString(IParserTags.ID, model.getId());
+ saveTaskState(writeMemento, (CheatSheetTask)model.getRootTask());
+ saveCheatSheetManagerData(writeMemento, model.getCheatSheetManager());
+ taskMementoMap = createTaskMap(writeMemento);
+ return CheatSheetPlugin.getPlugin().saveMemento(writeMemento, model.getId() + DOT_XML);
+ }
- try {
- DocumentBuilder documentBuilder = DocumentBuilderFactory
- .newInstance().newDocumentBuilder();
-
- Document doc = documentBuilder.newDocument();
- Element root = doc.createElement(ICompositeCheatsheetTags.COMPOSITE_CHEATSHEET_STATE);
-
- Path filePath = getStateFile(model.getId());
-
- root.setAttribute(IParserTags.ID, model.getId());
- doc.appendChild(root);
-
- saveTaskState(doc, root, (CheatSheetTask)model.getRootTask());
-
- StreamResult streamResult = new StreamResult(filePath.toFile());
-
- DOMSource domSource = new DOMSource(doc);
- Transformer transformer = TransformerFactory.newInstance()
- .newTransformer();
- transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
- transformer.transform(domSource, streamResult);
- } catch (Exception e) {
- String message = NLS.bind(Messages.ERROR_SAVING_STATEFILE_URL,
- (new Object[] { model.getId() }));
- IStatus status = new Status(IStatus.ERROR,
- ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK,
- message, e);
- return status;
+ private void saveCheatSheetManagerData(XMLMemento writeMemento, ICheatSheetManager manager) {
+ if (!(manager instanceof CheatSheetManager)) {
+ return;
+ }
+ Map data = ((CheatSheetManager)manager).getData();
+ for (Iterator iter = data.keySet().iterator(); iter.hasNext();) {
+ String key = (String)iter.next();
+ String value = manager.getData(key);
+ IMemento childMemento = writeMemento.createChild(ICompositeCheatsheetTags.CHEAT_SHEET_MANAGER);
+ childMemento.putString(ICompositeCheatsheetTags.KEY, key);
+ childMemento.putString(ICompositeCheatsheetTags.VALUE, value);
}
- return Status.OK_STATUS;
}
- private void saveTaskState(Document doc, Element parent, CheatSheetTask task) {
- Element taskElement = doc.createElement(ICompositeCheatsheetTags.TASK);
- taskElement.setAttribute(ICompositeCheatsheetTags.STATE, Integer.toString(task.getState()));
- taskElement.setAttribute(ICompositeCheatsheetTags.PERCENTAGE_COMPLETE, Integer.toString(task.getPercentageComplete()));
- if (task.getId() != null) {
- taskElement.setAttribute(IParserTags.ID, task.getId());
- }
+ private void saveTaskState(IMemento writeMemento, CheatSheetTask task) {
+ IMemento childMemento = writeMemento.createChild(ICompositeCheatsheetTags.TASK);
+ childMemento.putString(ICompositeCheatsheetTags.TASK_ID, task.getId());
+ childMemento.putString(ICompositeCheatsheetTags.STATE, Integer.toString(task.getState()));
+ childMemento.putString(ICompositeCheatsheetTags.PERCENTAGE_COMPLETE, Integer.toString(task.getPercentageComplete()));
+
ICompositeCheatSheetTask[] subtasks = task.getSubtasks();
- parent.appendChild(taskElement);
+ ITaskEditor editor = task.getEditor();
+ if (editor != null) {
+ IMemento taskDataMemento = childMemento.createChild(ICompositeCheatsheetTags.TASK_DATA);
+ editor.saveState(taskDataMemento);
+ } else {
+ // The task has not been started so save its previous state
+ IMemento taskData = getTaskMemento(task.getId());
+ if (taskData != null) {
+ IMemento previousDataMemento = childMemento.createChild(ICompositeCheatsheetTags.TASK_DATA);
+ previousDataMemento.putMemento(taskData);
+ }
+ }
for (int i = 0; i < subtasks.length; i++) {
- saveTaskState(doc, taskElement, (CheatSheetTask)subtasks[i]);
+ saveTaskState(writeMemento, (CheatSheetTask)subtasks[i]);
+ }
+ }
+
+ public IMemento getTaskMemento(String id) {
+ if (taskMementoMap == null) {
+ return null;
}
+ IMemento childMemento = (IMemento)taskMementoMap.get(id);
+ if (childMemento == null) {
+ return null;
+ }
+ return childMemento.getChild(ICompositeCheatsheetTags.TASK_DATA);
+ }
+
+ public void clearTaskMementos() {
+ taskMementoMap = null;
}
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/SuccesorTaskFinder.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/SuccesorTaskFinder.java
index b74efb6dc..e9687511e 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/SuccesorTaskFinder.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/SuccesorTaskFinder.java
@@ -41,7 +41,7 @@ public class SuccesorTaskFinder {
bestSuccessor = null;
bestPredecessor = null;
seenThisTask = false;
- searchRunnableChildren(csTask.getModel().getRootTask());
+ searchRunnableChildren(csTask.getCompositeCheatSheet().getRootTask());
// If there is a task which is found later in the tree return
// that, otherwise an earlier task.
if (bestSuccessor != null) {
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/parser/ICompositeCheatsheetTags.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/parser/ICompositeCheatsheetTags.java
index 20c7bc856..ba1928c5a 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/parser/ICompositeCheatsheetTags.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/parser/ICompositeCheatsheetTags.java
@@ -37,4 +37,10 @@ public interface ICompositeCheatsheetTags {
public static final String CHEATSHEET_TASK_ID = "id"; //$NON-NLS-1$
public static final String CHEATSHEET_TASK_PATH = "path"; //$NON-NLS-1$
+ // Tags used in Memento
+ public static final String TASK_DATA = "taskData"; //$NON-NLS-1$
+ public static final String CHEAT_SHEET_MANAGER = "cheatSheetManager"; //$NON-NLS-1$
+ public static final String KEY = "key"; //$NON-NLS-1$
+ public static final String TASK_ID = "id"; //$NON-NLS-1$
+
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CheatsheetTaskEditor.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CheatsheetTaskEditor.java
index 9c26d05bf..6415b08e8 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CheatsheetTaskEditor.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CheatsheetTaskEditor.java
@@ -17,6 +17,7 @@ import java.util.Dictionary;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IMemento;
import org.eclipse.ui.cheatsheets.CheatSheetListener;
import org.eclipse.ui.cheatsheets.CheatSheetViewerFactory;
import org.eclipse.ui.cheatsheets.ICheatSheetEvent;
@@ -40,12 +41,12 @@ public class CheatsheetTaskEditor implements ITaskEditor {
return viewer.getControl();
}
- public void start(ICompositeCheatSheetTask task) {
- this.task = task;
+
+ public void setInput(ICompositeCheatSheetTask task, IMemento memento) {
+ this.task = task;
Dictionary params = task.getParameters();
String id = (String)params.get(ICompositeCheatsheetTags.CHEATSHEET_TASK_ID);
String path = (String)params.get(ICompositeCheatsheetTags.CHEATSHEET_TASK_PATH);
- ((CheatSheetViewer)viewer).setNextSavePath(task.getStateLocation());
if (path != null) {
URL url;
try {
@@ -56,8 +57,12 @@ public class CheatsheetTaskEditor implements ITaskEditor {
}
} else {
viewer.setInput(id);
+ CheatSheetViewer cheatSheetViewer = (CheatSheetViewer)viewer;
+ cheatSheetViewer.addListener(new TaskListener());
+ if (memento == null) {
+ cheatSheetViewer.restart();
+ }
}
- ((CheatSheetViewer)viewer).addListener(new TaskListener());
}
/*
@@ -68,9 +73,11 @@ public class CheatsheetTaskEditor implements ITaskEditor {
public void cheatSheetEvent(ICheatSheetEvent event) {
if (event.getEventType() == ICheatSheetEvent.CHEATSHEET_COMPLETED) {
task.advanceState();
- }
-
- }
-
+ }
+ }
+ }
+
+ public void saveState(IMemento memento) {
+ // TODO Implement state save
}
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CompositeCheatSheetPage.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CompositeCheatSheetPage.java
index 3f1a7b99f..526cfb43e 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CompositeCheatSheetPage.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CompositeCheatSheetPage.java
@@ -14,6 +14,7 @@ package org.eclipse.ui.internal.cheatsheets.composite.views;
import java.util.Observable;
import java.util.Observer;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -35,6 +36,7 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.cheatsheets.ICompositeCheatSheetTask;
import org.eclipse.ui.cheatsheets.ITaskEditor;
import org.eclipse.ui.cheatsheets.ITaskExplorer;
@@ -64,11 +66,6 @@ import org.eclipse.ui.part.PageBook;
public class CompositeCheatSheetPage extends Page implements ISelectionChangedListener, IMenuContributor {
-
- private static final String TASK = "task"; //$NON-NLS-1$
- private static final String EDITOR = "editor"; //$NON-NLS-1$
- private static final String STARTED = "started"; //$NON-NLS-1$
- private static final String TRUE = "true"; //$NON-NLS-1$
private static final String REVIEW_TAG = "Review:"; //$NON-NLS-1$
private static final String NEXT_TASK_TAG = "Next:"; //$NON-NLS-1$
private ManagedForm mform;
@@ -90,9 +87,7 @@ public class CompositeCheatSheetPage extends Page implements ISelectionChangedLi
}
public void createPart(Composite parent) {
- //////
init(parent.getDisplay());
- //////
form = toolkit.createScrolledForm(parent);
form.setLayoutData(new GridData(GridData.FILL_BOTH));
FormColors colors = toolkit.getColors();
@@ -123,7 +118,7 @@ public class CompositeCheatSheetPage extends Page implements ISelectionChangedLi
}
});
sash.setBackground(colors.getColor(FormColors.TB_GBG));
- //toolkit.adapt(sash, false, false);
+
Composite explorerPanel = new Composite(sash, SWT.NULL);
explorerPanel.setBackground(colors.getColor(FormColors.TB_BORDER));
GridLayout playout = new GridLayout();
@@ -273,7 +268,6 @@ public class CompositeCheatSheetPage extends Page implements ISelectionChangedLi
showComplete(task);
break;
}
- saveGuideState();
}
private void showTaskEditor(ICompositeCheatSheetTask task) {
@@ -282,7 +276,7 @@ public class CompositeCheatSheetPage extends Page implements ISelectionChangedLi
setCurrentEditor(editor.getControl().getParent());
}
- private void saveGuideState() {
+ public void saveState() {
saveHelper.saveCompositeState(model);
}
@@ -372,10 +366,6 @@ public class CompositeCheatSheetPage extends Page implements ISelectionChangedLi
if (task == selectedTask) {
ITaskEditor editor = getTaskEditor(task);
if (editor!=null) {
- if (!TRUE.equals(editor.getControl().getData(STARTED))) {
- editor.start(task);
- editor.getControl().setData(STARTED, TRUE);
- }
setCurrentEditor(editor.getControl());
}
}
@@ -463,51 +453,26 @@ public class CompositeCheatSheetPage extends Page implements ISelectionChangedLi
buf.append("</a></p>"); //$NON-NLS-1$
}
- private ITaskEditor getTaskEditor(ICompositeCheatSheetTask task) {
- Control [] controls = taskEditorContainer.getChildren();
- for (int i=0; i<controls.length; i++) {
- Control control = controls[i];
- if (control==descriptionPanel || control==completePanel)
- continue;
- ICompositeCheatSheetTask ctask = (ICompositeCheatSheetTask)control.getData(ICompositeCheatsheetTags.TASK);
- if (task==ctask)
- return (ITaskEditor)control.getData(EDITOR);
- }
- // Create a new editor using the extension point data
- ITaskEditor editor = TaskEditorManager.getInstance().getEditor(task.getKind());
- if (editor != null) {
- editor.createControl(taskEditorContainer, mform.getToolkit());
- editor.getControl().setData(TASK, task);
- editor.getControl().setData(EDITOR, editor);
- }
- return editor;
- }
-
- // TODO enable a reset mechanism
/*
- *
- private class ResetAction extends Action {
- public ResetAction() {
- setText("Reset Guide State");
- }
-
- public void run() {
- if (model instanceof CompositeCheatSheetModel) {
- resetTask(((CompositeCheatSheetModel)model).getRootTask());
- }
- }
-
- private void resetTask(IGuideTask task) {
- GuideTask gTask = (GuideTask)task;
- gTask.setState(0);
- gTask.setPercentageComplete(0);
- IGuideTask[] subtasks = gTask.getSubtasks();
- for (int i = 0; i < subtasks.length; i++) {
- resetTask(subtasks[i]);
+ * Get the task editor for this task. If no editor exists create one
+ */
+ private ITaskEditor getTaskEditor(ICompositeCheatSheetTask task) {
+ if (task instanceof CheatSheetTask) {
+ CheatSheetTask csTask = (CheatSheetTask)task;
+ if (csTask.getEditor() == null) {
+ // Create a new editor using the extension point data
+ ITaskEditor editor = TaskEditorManager.getInstance().getEditor(task.getKind());
+ if (editor != null) {
+ editor.createControl(taskEditorContainer, mform.getToolkit());
+ editor.setInput(task, model.getTaskMemento(task.getId()));
+ csTask.setEditor(editor);
+ }
}
+ return csTask.getEditor();
}
+
+ return null;
}
- */
public Control getControl() {
return form;
@@ -519,13 +484,36 @@ public class CompositeCheatSheetPage extends Page implements ISelectionChangedLi
public void initialized() {
// Open the model
- saveHelper.loadCompositeState(model, null);
+ model.setSaveHelper(saveHelper);
+ model.loadState();
setInputModel(model);
- model.setSaveHelper(saveHelper);
}
- public int contributeToViewMenu(Menu menu, int index) {
-
+ public int contributeToViewMenu(Menu menu, int index) {
+ index = contributeExplorerItem(menu, index);
+ return contributeRestartItem(menu, index);
+ }
+
+ private int contributeRestartItem(Menu menu, int index) {
+ MenuItem item = new MenuItem(menu, SWT.PUSH, index++);
+ item.setText(Messages.RESTART_ALL_MENU);
+ // TODO set the image
+ item.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if (model != null) {
+ if (MessageDialog.openConfirm(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ Messages.COMPOSITE_RESTART_DIALOG_TITLE,
+ Messages.COMPOSITE_RESTART_CONFIRM_MESSAGE)) {
+ model.resetAllTasks();
+ }
+ }
+ }
+ });
+ return index;
+ }
+
+ private int contributeExplorerItem(Menu menu, int index) {
String[] explorerIds = CheatSheetRegistryReader.getInstance().getExplorerIds();
if (explorerIds.length == 1) {
return index; // no other explorer to chosse from
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetSaveHelper.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetSaveHelper.java
index 90dee9e09..3cfade3de 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetSaveHelper.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetSaveHelper.java
@@ -39,8 +39,7 @@ public class CheatSheetSaveHelper {
*/
public CheatSheetSaveHelper() {
super();
- savePath = Platform
- .getStateLocation(CheatSheetPlugin.getPlugin().getBundle());
+ savePath = CheatSheetPlugin.getPlugin().getStateLocation();
}
private Properties createProperties(int currentItemNum, ArrayList items,
@@ -155,8 +154,7 @@ public class CheatSheetSaveHelper {
if (savePath != null) {
this.savePath = savePath;
} else {
- this.savePath = Platform
- .getStateLocation(CheatSheetPlugin.getPlugin().getBundle());
+ this.savePath = CheatSheetPlugin.getPlugin().getStateLocation();
}
Properties returnProps = null;
Hashtable subskipped = null;
@@ -466,8 +464,7 @@ public class CheatSheetSaveHelper {
Document doc = documentBuilder.newDocument();
- IPath filePath = getStateFile(csID, Platform
- .getStateLocation(CheatSheetPlugin.getPlugin().getBundle()));
+ IPath filePath = getStateFile(csID, CheatSheetPlugin.getPlugin().getStateLocation());
// Create the root element for the document now:
Element root = doc.createElement(IParserTags.CHEATSHEET_STATE_REFERENCE);
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetPage.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetPage.java
index c7141f0d3..18005c79f 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetPage.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetPage.java
@@ -10,18 +10,28 @@
*******************************************************************************/
package org.eclipse.ui.internal.cheatsheets.views;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Iterator;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.ui.forms.FormColors;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
-import org.eclipse.ui.internal.cheatsheets.*;
-import org.eclipse.ui.internal.cheatsheets.data.*;
+import org.eclipse.ui.internal.cheatsheets.CheatSheetStopWatch;
+import org.eclipse.ui.internal.cheatsheets.ICheatSheetResource;
+import org.eclipse.ui.internal.cheatsheets.Messages;
+import org.eclipse.ui.internal.cheatsheets.actions.IMenuContributor;
+import org.eclipse.ui.internal.cheatsheets.data.CheatSheet;
-public class CheatSheetPage extends Page {
+public class CheatSheetPage extends Page implements IMenuContributor {
// Colors
private Color introColor;
private Color activeColor;
@@ -220,4 +230,20 @@ public class CheatSheetPage extends Page {
public FormToolkit getToolkit() {
return toolkit;
}
+
+ private int contributeRestartItem(Menu menu, int index) {
+ MenuItem item = new MenuItem(menu, SWT.PUSH, index++);
+ item.setText(Messages.RESTART_MENU);
+ // TODO set the image
+ item.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ viewer.restart();
+ }
+ });
+ return index;
+ }
+
+ public int contributeToViewMenu(Menu menu, int index) {
+ return contributeRestartItem(menu, index);
+ }
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java
index 767c67b2d..c379614e3 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java
@@ -123,6 +123,27 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
}
/*package*/ void advanceIntroItem() {
+ resetItemState();
+ /* LP-item event */
+ // fireManagerItemEvent(ICheatSheetItemEvent.ITEM_DEACTIVATED, introItem);
+
+ currentItemNum = 1;
+ ViewItem nextItem = getViewItemAtIndex(currentItemNum);
+ if (nextItem.item.isDynamic()) {
+ nextItem.handleButtons();
+ }
+ nextItem.setAsCurrentActiveItem();
+ /* LP-item event */
+ // fireManagerItemEvent(ICheatSheetItemEvent.ITEM_ACTIVATED, nextItem);
+ collapseAllButCurrent(false);
+
+ saveCurrentSheet();
+ }
+
+ /**
+ * Reset the state of all the items in this cheatsheet
+ */
+ private void resetItemState() {
IntroItem introItem = (IntroItem) getViewItemAtIndex(0);
boolean isStarted = introItem.isCompleted();
@@ -136,8 +157,6 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
if(isStarted)
initManager();
- currentItemNum = 1;
-
for (Iterator iter = viewItemList.iterator(); iter.hasNext();) {
ViewItem item = (ViewItem) iter.next();
if (item instanceof CoreItem) {
@@ -160,19 +179,6 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
introItem.setAsNormalCollapsed();
introItem.setComplete();
introItem.setRestartImage();
- /* LP-item event */
- // fireManagerItemEvent(ICheatSheetItemEvent.ITEM_DEACTIVATED, introItem);
-
- ViewItem nextItem = getViewItemAtIndex(1);
- if (nextItem.item.isDynamic()) {
- nextItem.handleButtons();
- }
- nextItem.setAsCurrentActiveItem();
- /* LP-item event */
- // fireManagerItemEvent(ICheatSheetItemEvent.ITEM_ACTIVATED, nextItem);
- collapseAllButCurrent(false);
-
- saveCurrentSheet();
}
/*package*/
@@ -237,10 +243,7 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
FormToolkit.ensureVisible(currentItem.getMainItemComposite());
} else if (indexNextItem == viewItemList.size()) {
saveCurrentSheet();
- ViewItem item = getViewItemAtIndex(0);
- item.setExpanded();
- item.setBold(true);
- item.getMainItemComposite().setFocus();
+ showIntroItem();
if (!currentItem.isCompletionMessageExpanded()) { // The event will already have been fired
getManager().fireEvent(ICheatSheetEvent.CHEATSHEET_COMPLETED);
}
@@ -249,6 +252,13 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
saveCurrentSheet();
}
+ private void showIntroItem() {
+ ViewItem item = getViewItemAtIndex(0);
+ item.setExpanded();
+ item.setBold(true);
+ item.getMainItemComposite().setFocus();
+ }
+
/*package*/ void advanceSubItem(ImageHyperlink link, boolean markAsCompleted, int subItemIndex) {
Label l = null;
ArrayList list = null;
@@ -795,7 +805,10 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
if (model instanceof CheatSheet) {
currentPage = new CheatSheetPage((CheatSheet)model, viewItemList, this);
} else if (model instanceof CompositeCheatSheetModel) {
- currentPage = new CompositeCheatSheetPage((CompositeCheatSheetModel)model);
+ CompositeCheatSheetModel compositeCheatSheetModel = ((CompositeCheatSheetModel)model);
+ compositeCheatSheetModel.setId(currentID);
+ currentPage = new CompositeCheatSheetPage(compositeCheatSheetModel);
+ compositeCheatSheetModel.setCheatSheetManager(initManager());
}
CheatSheetStopWatch.printLapTime("CheatSheetViewer.initCheatSheetView()", "Time in CheatSheetViewer.initCheatSheetView() after CheatSheetPage() call: "); //$NON-NLS-1$ //$NON-NLS-2$
currentPage.createPart(control);
@@ -827,7 +840,7 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
private void internalDispose() {
if(manager != null)
manager.fireEvent(ICheatSheetEvent.CHEATSHEET_CLOSED);
-
+
saveCurrentSheet();
for (Iterator iter = viewItemList.iterator(); iter.hasNext();) {
@@ -948,10 +961,14 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
/*package*/ void saveCurrentSheet() {
if(currentID != null) {
- boolean expandRestoreActionState = false;
- if(expandRestoreAction != null)
- expandRestoreActionState = expandRestoreAction.isCollapsed();
- saveHelper.saveState(currentItemNum, viewItemList, expandRestoreActionState, expandRestoreList, currentID, restorePath, getManager());
+ if (currentPage instanceof CheatSheetPage) {
+ boolean expandRestoreActionState = false;
+ if(expandRestoreAction != null)
+ expandRestoreActionState = expandRestoreAction.isCollapsed();
+ saveHelper.saveState(currentItemNum, viewItemList, expandRestoreActionState, expandRestoreList, currentID, restorePath, getManager());
+ } else if (currentPage instanceof CompositeCheatSheetPage) {
+ ((CompositeCheatSheetPage)currentPage).saveState();
+ }
}
}
@@ -1129,5 +1146,12 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
}
return index;
}
+
+ public void restart() {
+ resetItemState();
+ currentItemNum = 0;
+ collapseAllButCurrent(false);
+ showIntroItem();
+ }
} \ No newline at end of file

Back to the top