Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 35860 Details for
Bug 84457
[CheatSheet] No API to restart the cheat sheet
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch including API, implementation and JUnits
patch084457.txt (text/plain), 40.10 KB, created by
Chris Goldthorpe
on 2006-03-07 16:43:41 EST
(
hide
)
Description:
Patch including API, implementation and JUnits
Filename:
MIME Type:
Creator:
Chris Goldthorpe
Created:
2006-03-07 16:43:41 EST
Size:
40.10 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.cheatsheets >Index: src/org/eclipse/ui/cheatsheets/ICheatSheetManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ICheatSheetManager.java,v >retrieving revision 1.6 >diff -u -r1.6 ICheatSheetManager.java >--- src/org/eclipse/ui/cheatsheets/ICheatSheetManager.java 1 Mar 2005 20:45:46 -0000 1.6 >+++ src/org/eclipse/ui/cheatsheets/ICheatSheetManager.java 7 Mar 2006 21:44:49 -0000 >@@ -10,6 +10,8 @@ > *******************************************************************************/ > package org.eclipse.ui.cheatsheets; > >+import java.util.Set; >+ > /** > * Manages the running of a cheat sheet. > * <p> >@@ -68,4 +70,20 @@ > * is <code>null</code> > */ > public void setData(String key, String data); >+ >+ /** >+ * Get the cheat sheet manager for the enclosing composite cheat sheet. >+ * @return The cheat sheet manager for the composite cheat sheet which contains >+ * this cheat sheet as a task or <code>null</code> if this cheatsheet was not >+ * opened as a subtask of a composite cheat sheet. >+ * @since 3.2 >+ */ >+ public ICheatSheetManager getParent(); >+ >+ /** >+ * Get the keys for the data in this cheat sheet manager >+ * @return The set of keys. >+ * @since 3.2 >+ */ >+ public Set getKeySet(); > } >Index: src/org/eclipse/ui/cheatsheets/ICheatSheetViewer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/ICheatSheetViewer.java,v >retrieving revision 1.6 >diff -u -r1.6 ICheatSheetViewer.java >--- src/org/eclipse/ui/cheatsheets/ICheatSheetViewer.java 1 Mar 2005 20:45:46 -0000 1.6 >+++ src/org/eclipse/ui/cheatsheets/ICheatSheetViewer.java 7 Mar 2006 21:44:49 -0000 >@@ -11,6 +11,8 @@ > package org.eclipse.ui.cheatsheets; > > import java.net.URL; >+import java.util.Map; >+ > import org.eclipse.swt.widgets.Composite; > import org.eclipse.swt.widgets.Control; > >@@ -113,4 +115,14 @@ > * are <code>null</code> > */ > public void setInput(String id, String name, URL url); >+ >+ /** >+ * Sets the currently active cheat sheet to its initial state and >+ * initalizes the cheat sheet manager data. >+ * @param cheatSheetData A map whose keys and values are all of type >+ * <code>java.lang.String</code> or <code>null</code> to reset all data in >+ * the cheat sheet manager. >+ * @since 3.2 >+ */ >+ public void reset(Map cheatSheetData); > } >Index: src/org/eclipse/ui/internal/cheatsheets/state/MementoStateManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/state/MementoStateManager.java,v >retrieving revision 1.1 >diff -u -r1.1 MementoStateManager.java >--- src/org/eclipse/ui/internal/cheatsheets/state/MementoStateManager.java 2 Mar 2006 17:30:40 -0000 1.1 >+++ src/org/eclipse/ui/internal/cheatsheets/state/MementoStateManager.java 7 Mar 2006 21:44:49 -0000 >@@ -17,6 +17,7 @@ > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Status; > import org.eclipse.ui.IMemento; >+import org.eclipse.ui.cheatsheets.ICheatSheetManager; > import org.eclipse.ui.internal.cheatsheets.data.CheatSheetSaveHelper; > import org.eclipse.ui.internal.cheatsheets.data.IParserTags; > import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement; >@@ -33,13 +34,15 @@ > private CheatSheetElement element; > private CheatSheetSaveHelper saveHelper = new CheatSheetSaveHelper(); > private Properties props; >+ private ICheatSheetManager parentCsm; > > /** > * @param memento The memento which will be used to initialize the state. May be > * null to indicate that the state should be initialized. > */ >- public MementoStateManager(IMemento memento) { >+ public MementoStateManager(IMemento memento, ICheatSheetManager parentCsm) { > this.memento = memento; >+ this.parentCsm = parentCsm; > } > > /** >@@ -60,6 +63,7 @@ > if (getProperties() != null) { > result.setData((Hashtable) getProperties().get(IParserTags.MANAGERDATA)); > } >+ result.setParent(parentCsm); > return result; > } > >Index: src/org/eclipse/ui/internal/cheatsheets/composite/model/AbstractTask.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/AbstractTask.java,v >retrieving revision 1.4 >diff -u -r1.4 AbstractTask.java >--- src/org/eclipse/ui/internal/cheatsheets/composite/model/AbstractTask.java 24 Feb 2006 23:28:12 -0000 1.4 >+++ src/org/eclipse/ui/internal/cheatsheets/composite/model/AbstractTask.java 7 Mar 2006 21:44:49 -0000 >@@ -21,6 +21,7 @@ > > import org.eclipse.ui.cheatsheets.ICompositeCheatSheet; > import org.eclipse.ui.cheatsheets.ICompositeCheatSheetTask; >+import org.eclipse.ui.cheatsheets.ITaskGroup; > import org.eclipse.ui.internal.cheatsheets.composite.parser.ITaskParseStrategy; > > /** >@@ -205,7 +206,7 @@ > this.parent = parent; > } > >- public TaskGroup getParent() { >+ public ITaskGroup getParent() { > return parent; > } > >Index: src/org/eclipse/ui/internal/cheatsheets/composite/model/CompositeCheatSheetModel.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/model/CompositeCheatSheetModel.java,v >retrieving revision 1.4 >diff -u -r1.4 CompositeCheatSheetModel.java >--- src/org/eclipse/ui/internal/cheatsheets/composite/model/CompositeCheatSheetModel.java 23 Feb 2006 21:20:34 -0000 1.4 >+++ src/org/eclipse/ui/internal/cheatsheets/composite/model/CompositeCheatSheetModel.java 7 Mar 2006 21:44:49 -0000 >@@ -13,13 +13,13 @@ > > import java.net.URL; > import java.util.Hashtable; >+import java.util.Map; > import java.util.Observable; > > 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.TaskEditor; > import org.eclipse.ui.internal.cheatsheets.data.ICheatSheet; > import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager; > >@@ -118,10 +118,6 @@ > if (task instanceof EditableTask) { > EditableTask editable = (EditableTask)task; > editable.setState(ICompositeCheatSheetTask.NOT_STARTED); >- TaskEditor editor = editable.getEditor(); >- if (editor != null) { >- editor.setInput(editable, null); >- } > } else if (task instanceof TaskGroup) { > TaskGroup group = (TaskGroup)task; > ICompositeCheatSheetTask[] subtasks = group.getSubtasks(); >@@ -132,9 +128,13 @@ > } > } > >- public void resetAllTasks() { >+ public void resetAllTasks(Map cheatSheetData) { > if (manager != null) { >- manager.setData(new Hashtable()); >+ if (cheatSheetData == null) { >+ manager.setData(new Hashtable()); >+ } else { >+ manager.setData(cheatSheetData); >+ } > } > saveHelper.clearTaskMementos(); > resetTask(getRootTask()); >Index: src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetCommand.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetCommand.java,v >retrieving revision 1.2 >diff -u -r1.2 CheatSheetCommand.java >--- src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetCommand.java 30 Jan 2006 23:13:49 -0000 1.2 >+++ src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetCommand.java 7 Mar 2006 21:44:49 -0000 >@@ -13,9 +13,9 @@ > > import org.eclipse.core.runtime.IStatus; > import org.eclipse.osgi.util.NLS; >-import org.eclipse.ui.cheatsheets.ICheatSheetManager; > import org.eclipse.ui.internal.cheatsheets.CommandRunner; > import org.eclipse.ui.internal.cheatsheets.Messages; >+import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager; > import org.w3c.dom.Node; > > /** >@@ -40,7 +40,7 @@ > return true; > } > >- public IStatus execute(ICheatSheetManager csm) { >+ public IStatus execute(CheatSheetManager csm) { > return new CommandRunner().executeCommand(this, csm); > } > >Index: src/org/eclipse/ui/internal/cheatsheets/data/AbstractExecutable.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/AbstractExecutable.java,v >retrieving revision 1.1 >diff -u -r1.1 AbstractExecutable.java >--- src/org/eclipse/ui/internal/cheatsheets/data/AbstractExecutable.java 5 Jan 2006 22:10:26 -0000 1.1 >+++ src/org/eclipse/ui/internal/cheatsheets/data/AbstractExecutable.java 7 Mar 2006 21:44:49 -0000 >@@ -12,7 +12,7 @@ > package org.eclipse.ui.internal.cheatsheets.data; > > import org.eclipse.core.runtime.IStatus; >-import org.eclipse.ui.cheatsheets.ICheatSheetManager; >+import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager; > import org.w3c.dom.Node; > > /** >@@ -107,7 +107,7 @@ > * completes with a failure result, error status if an exception was thrown > * or the executable could not be initiated. > */ >- public abstract IStatus execute(ICheatSheetManager csm); >+ public abstract IStatus execute(CheatSheetManager csm); > > /** > * @return true if this executable can have parameters >Index: src/org/eclipse/ui/internal/cheatsheets/data/Action.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/Action.java,v >retrieving revision 1.3 >diff -u -r1.3 Action.java >--- src/org/eclipse/ui/internal/cheatsheets/data/Action.java 5 Jan 2006 22:10:26 -0000 1.3 >+++ src/org/eclipse/ui/internal/cheatsheets/data/Action.java 7 Mar 2006 21:44:49 -0000 >@@ -12,9 +12,9 @@ > > import org.eclipse.core.runtime.IStatus; > import org.eclipse.osgi.util.NLS; >-import org.eclipse.ui.cheatsheets.ICheatSheetManager; > import org.eclipse.ui.internal.cheatsheets.ActionRunner; > import org.eclipse.ui.internal.cheatsheets.Messages; >+import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager; > import org.w3c.dom.Node; > > /** >@@ -93,7 +93,7 @@ > } > > >- public IStatus execute(ICheatSheetManager csm) { >+ public IStatus execute(CheatSheetManager csm) { > return new ActionRunner().runAction(this, csm); > } > >Index: src/org/eclipse/ui/internal/cheatsheets/ActionRunner.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/ActionRunner.java,v >retrieving revision 1.2 >diff -u -r1.2 ActionRunner.java >--- src/org/eclipse/ui/internal/cheatsheets/ActionRunner.java 27 Jan 2006 19:49:14 -0000 1.2 >+++ src/org/eclipse/ui/internal/cheatsheets/ActionRunner.java 7 Mar 2006 21:44:49 -0000 >@@ -19,15 +19,15 @@ > import org.eclipse.jface.util.PropertyChangeEvent; > import org.eclipse.osgi.util.NLS; > import org.eclipse.ui.cheatsheets.ICheatSheetAction; >-import org.eclipse.ui.cheatsheets.ICheatSheetManager; > import org.eclipse.ui.internal.cheatsheets.data.Action; >+import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager; > import org.osgi.framework.Bundle; > > /** > * Class which can run actions and determine the outcome > */ > public class ActionRunner { >- public IStatus runAction(Action cheatSheetAction, ICheatSheetManager csm) { >+ public IStatus runAction(Action cheatSheetAction, CheatSheetManager csm) { > > IStatus status = Status.OK_STATUS; > String pluginId = cheatSheetAction.getPluginID(); >@@ -78,7 +78,7 @@ > String param = clonedParams[i]; > if(param != null && param.startsWith("${") && param.endsWith("}")) { //$NON-NLS-1$ //$NON-NLS-2$ > param = param.substring(2,param.length()-1); >- String value = csm.getData(param); >+ String value = csm.getDataQualified(param); > clonedParams[i] = value == null ? ICheatSheetResource.EMPTY_STRING : value; > } > } >Index: src/org/eclipse/ui/internal/cheatsheets/CommandRunner.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CommandRunner.java,v >retrieving revision 1.3 >diff -u -r1.3 CommandRunner.java >--- src/org/eclipse/ui/internal/cheatsheets/CommandRunner.java 9 Feb 2006 20:18:20 -0000 1.3 >+++ src/org/eclipse/ui/internal/cheatsheets/CommandRunner.java 7 Mar 2006 21:44:49 -0000 >@@ -20,7 +20,6 @@ > import org.eclipse.osgi.util.NLS; > import org.eclipse.ui.IWorkbench; > import org.eclipse.ui.PlatformUI; >-import org.eclipse.ui.cheatsheets.ICheatSheetManager; > import org.eclipse.ui.commands.ICommandService; > import org.eclipse.ui.internal.cheatsheets.data.CheatSheetCommand; > import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager; >@@ -50,7 +49,7 @@ > * @return OK_STATUS if the command completes withour error, otherwise > * an error status > */ >- public IStatus executeCommand(CheatSheetCommand command, ICheatSheetManager csm) { >+ public IStatus executeCommand(CheatSheetCommand command, CheatSheetManager csm) { > ICommandService service = getCommandService(); > if (service == null) { > return new Status >@@ -63,8 +62,7 @@ > Object result; > String rawSerialization = command.getSerialization(); > try { >- String substitutedSerialization = CheatSheetManager.performVariableSubstitution >- (rawSerialization, csm); >+ String substitutedSerialization = csm.performVariableSubstitution(rawSerialization); > selectedCommand = service.deserialize(substitutedSerialization); > result = selectedCommand.executeWithChecks(null, null); > >@@ -73,11 +71,11 @@ > ParameterType returnType = selectedCommand.getCommand().getReturnType(); > if ((returnType != null && (returnType.getValueConverter() != null))) { > String resultString = returnType.getValueConverter().convertToString(result); >- csm.setData(returnsAttribute, resultString); >+ csm.setDataQualified(returnsAttribute, resultString); > } > else { > if (result instanceof String) { >- csm.setData(returnsAttribute, (String)result); >+ csm.setDataQualified(returnsAttribute, (String)result); > } > } > } >Index: src/org/eclipse/ui/internal/cheatsheets/composite/views/CheatsheetTaskEditor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CheatsheetTaskEditor.java,v >retrieving revision 1.4 >diff -u -r1.4 CheatsheetTaskEditor.java >--- src/org/eclipse/ui/internal/cheatsheets/composite/views/CheatsheetTaskEditor.java 2 Mar 2006 17:30:40 -0000 1.4 >+++ src/org/eclipse/ui/internal/cheatsheets/composite/views/CheatsheetTaskEditor.java 7 Mar 2006 21:44:49 -0000 >@@ -47,11 +47,14 @@ > Dictionary params = task.getParameters(); > String id = (String)params.get(ICompositeCheatsheetTags.CHEATSHEET_TASK_ID); > String path = (String)params.get(ICompositeCheatsheetTags.CHEATSHEET_TASK_PATH); >- MementoStateManager stateManager = new MementoStateManager(memento); >+ MementoStateManager stateManager = new MementoStateManager(memento, task.getCompositeCheatSheet().getCheatSheetManager()); > if (path != null) { > URL url; > try { > url = task.getInputUrl(path); >+ if (id == null) { >+ id = task.getId(); >+ } > viewer.setInput(id, task.getName(), url, stateManager); > } catch (MalformedURLException e) { > e.printStackTrace(); >@@ -61,9 +64,6 @@ > viewer.setInput(id, stateManager); > } > viewer.addListener(new TaskListener()); >- if (memento == null) { >- viewer.restart(); >- } > } > > /* >Index: src/org/eclipse/ui/internal/cheatsheets/composite/views/CompositeCheatSheetPage.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CompositeCheatSheetPage.java,v >retrieving revision 1.11 >diff -u -r1.11 CompositeCheatSheetPage.java >--- src/org/eclipse/ui/internal/cheatsheets/composite/views/CompositeCheatSheetPage.java 24 Feb 2006 20:01:49 -0000 1.11 >+++ src/org/eclipse/ui/internal/cheatsheets/composite/views/CompositeCheatSheetPage.java 7 Mar 2006 21:44:49 -0000 >@@ -11,6 +11,7 @@ > > package org.eclipse.ui.internal.cheatsheets.composite.views; > >+import java.util.Map; > import java.util.Observable; > import java.util.Observer; > >@@ -279,8 +280,8 @@ > } > > private void showTaskEditor(EditableTask task) { >- startIfSelected(task); >- TaskEditor editor = getTaskEditor(task); >+ startIfSelected(task, false); >+ TaskEditor editor = getTaskEditor(task, false); > if (editor != null) { > setCurrentEditor(editor.getControl().getParent()); > } >@@ -392,9 +393,9 @@ > /* > * Ensure that if this task is visible and in a runnable state that it has been started > */ >- private void startIfSelected(ICompositeCheatSheetTask task) { >+ private void startIfSelected(ICompositeCheatSheetTask task, boolean initialize) { > if (task == selectedTask) { >- TaskEditor editor = getTaskEditor(task); >+ TaskEditor editor = getTaskEditor(task, initialize); > if (editor!=null) { > setCurrentEditor(editor.getControl()); > } >@@ -413,7 +414,7 @@ > if (data instanceof EditableTask) { > EditableTask task = (EditableTask)data; > task.setStarted(); >- startIfSelected(task); >+ startIfSelected(task, true); > } > } > if (ref.equals(SKIP_HREF)) { >@@ -520,7 +521,7 @@ > /* > * Get the task editor for this task. If no editor exists create one > */ >- private TaskEditor getTaskEditor(ICompositeCheatSheetTask task) { >+ private TaskEditor getTaskEditor(ICompositeCheatSheetTask task, boolean initialize) { > if (task instanceof EditableTask) { > EditableTask editable = (EditableTask)task; > if (editable.getEditor() == null) { >@@ -530,7 +531,9 @@ > editor.createControl(taskEditorContainer, mform.getToolkit()); > editor.setInput(editable, model.getTaskMemento(task.getId())); > editable.setEditor(editor); >- } >+ } else if (initialize) { >+ editor.setInput(editable, model.getTaskMemento(task.getId())); >+ } > } > return editable.getEditor(); > } >@@ -569,9 +572,7 @@ > PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), > Messages.COMPOSITE_RESTART_DIALOG_TITLE, > Messages.COMPOSITE_RESTART_CONFIRM_MESSAGE)) { >- model.resetAllTasks(); >- currentExplorer.setSelection >- (new StructuredSelection(model.getRootTask()), true); >+ restart(null); > } > } > } >@@ -610,4 +611,11 @@ > return index; > } > >+ public void restart(Map cheatSheetData) { >+ model.resetAllTasks(cheatSheetData); >+ currentExplorer.setSelection >+ (new StructuredSelection(model.getRootTask()), true); >+ >+ } >+ > } >Index: src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java,v >retrieving revision 1.48 >diff -u -r1.48 CheatSheetViewer.java >--- src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java 2 Mar 2006 17:30:40 -0000 1.48 >+++ src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java 7 Mar 2006 21:44:50 -0000 >@@ -17,6 +17,7 @@ > import java.util.Hashtable; > import java.util.Iterator; > import java.util.ListIterator; >+import java.util.Map; > import java.util.Properties; > import java.util.StringTokenizer; > >@@ -332,6 +333,8 @@ > private boolean loadState() { > try { > Properties props = stateManager.getProperties(); >+ >+ manager = stateManager.getCheatSheetManager(); > > // There is a bug which causes the background of the buttons to > // remain white, even though the color is set. So instead of calling >@@ -368,8 +371,6 @@ > > if (cid != null) > currentID = cid; >- >- manager = stateManager.getCheatSheetManager(); > > if (itemNum >= 0) { > currentItemNum = itemNum; >@@ -999,9 +1000,6 @@ > > /*package*/ void setContent(CheatSheetElement element, ICheatSheetStateManager inputStateManager) { > CheatSheetStopWatch.startStopWatch("CheatSheetViewer.setContent(CheatSheetElement element)"); //$NON-NLS-1$ >- >- if (element != null && element.equals(contentElement)) >- return; > > // Cleanup previous contents > internalDispose(); >@@ -1170,4 +1168,13 @@ > } > } > >+ public void reset(Map cheatSheetData) { >+ if (currentPage instanceof CheatSheetPage) { >+ restart(); >+ getManager().setData(cheatSheetData); >+ } else if (currentPage instanceof CompositeCheatSheetPage) { >+ ((CompositeCheatSheetPage)currentPage).restart(cheatSheetData); >+ } >+ } >+ > } >\ No newline at end of file >Index: src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetManager.java,v >retrieving revision 1.19 >diff -u -r1.19 CheatSheetManager.java >--- src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetManager.java 23 Feb 2006 21:20:34 -0000 1.19 >+++ src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetManager.java 7 Mar 2006 21:44:49 -0000 >@@ -20,11 +20,13 @@ > */ > public class CheatSheetManager implements ICheatSheetManager { > >+ private static final String PARENT_PREFIX = "parent."; //$NON-NLS-1$ > private static final String VARIABLE_END = "}"; //$NON-NLS-1$ > private static final String VARIABLE_BEGIN = "${"; //$NON-NLS-1$ > private String cheatsheetID; > private List listeners; > private Map dataTable = null; >+ private ICheatSheetManager parent; > > public CheatSheetManager(CheatSheetElement element) { > cheatsheetID = element.getID(); >@@ -71,26 +73,38 @@ > return null; > return (String) dataTable.get(key); > } >+ >+ /** >+ * Similar to get data except that if the key is prefixed with "parent." >+ * get the data from the parent >+ * @param qualifiedKey >+ * @return The data for this key >+ */ >+ public String getDataQualified(String qualifiedKey) { >+ if (qualifiedKey.startsWith(PARENT_PREFIX) && parent != null) { >+ return parent.getData(qualifiedKey.substring(PARENT_PREFIX.length())); >+ } else { >+ return getData(qualifiedKey); >+ } >+ } > > public String getVariableData(String variable) { > String result = variable; > if(variable != null && variable.startsWith(VARIABLE_BEGIN) && variable.endsWith(VARIABLE_END)) { > result = variable.substring(2,variable.length()-1); >- result = getData(result); >+ result = getDataQualified(result); > } > return result; > } > > /** > * Substitute occurences of ${data} with values from the cheatsheetmanager. >- * This function is static to allow for JUnit testing > * @param input The input string > * @param csm The cheatsheet manager > * @return The input string with substitutions made for any cheatsheet > * variables encountered. > */ >- public static String performVariableSubstitution(String input, >- ICheatSheetManager csm) >+ public String performVariableSubstitution(String input) > { > String remaining = input; > String output = ""; //$NON-NLS-1$ >@@ -103,7 +117,7 @@ > } else { > String varName = remaining.substring(varIndex + VARIABLE_BEGIN.length(), > endIndex); >- String value = csm.getData(varName); >+ String value = getDataQualified(varName); > output += remaining.substring(0, varIndex); > if (value != null) { > output += value; >@@ -137,6 +151,23 @@ > > dataTable.put(key, data); > } >+ >+ /** >+ * Similar to setData except that if the key is prefixed by "parent." >+ * set the data in the parent. >+ * @param qualifiedKey A key which may be prefixed by parent. >+ * @param data The value to set >+ */ >+ public void setDataQualified(String qualifiedKey, String data) { >+ if (qualifiedKey == null) { >+ throw new IllegalArgumentException(); >+ } >+ if (qualifiedKey.startsWith(PARENT_PREFIX) && parent != null) { >+ parent.setData(qualifiedKey.substring(PARENT_PREFIX.length()), data); >+ } else { >+ setData(qualifiedKey, data); >+ } >+ } > > /** > * Add a listener for cheatsheet events >@@ -147,4 +178,20 @@ > listeners.add(listener); > } > } >+ >+ public ICheatSheetManager getParent() { >+ return parent; >+ } >+ >+ public void setParent(ICheatSheetManager parent) { >+ this.parent = parent; >+ } >+ >+ public Set getKeySet() { >+ if (dataTable == null) { >+ return new HashSet(); >+ } else { >+ return dataTable.keySet(); >+ } >+ } > } >Index: src/org/eclipse/ui/internal/cheatsheets/views/CoreItem.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CoreItem.java,v >retrieving revision 1.35 >diff -u -r1.35 CoreItem.java >--- src/org/eclipse/ui/internal/cheatsheets/views/CoreItem.java 30 Jan 2006 23:13:49 -0000 1.35 >+++ src/org/eclipse/ui/internal/cheatsheets/views/CoreItem.java 7 Mar 2006 21:44:50 -0000 >@@ -26,7 +26,6 @@ > import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Label; > import org.eclipse.ui.PlatformUI; >-import org.eclipse.ui.cheatsheets.ICheatSheetManager; > import org.eclipse.ui.forms.events.HyperlinkAdapter; > import org.eclipse.ui.forms.events.HyperlinkEvent; > import org.eclipse.ui.forms.widgets.ImageHyperlink; >@@ -447,11 +446,11 @@ > } > > /*package*/ >- IStatus runExecutable(ICheatSheetManager csm) { >+ IStatus runExecutable(CheatSheetManager csm) { > return runExecutable(this.getItem().getExecutable(), csm); > } > >- IStatus runExecutable(AbstractExecutable executable, ICheatSheetManager csm) { >+ IStatus runExecutable(AbstractExecutable executable, CheatSheetManager csm) { > if(executable != null) { > return executable.execute(csm); > } >@@ -540,8 +539,8 @@ > * this is the last step. > */ > void createCompletionComposite(boolean isFinalItem) { >- String completionMessage = CheatSheetManager.performVariableSubstitution >- (item.getCompletionMessage(), viewer.getManager()); >+ String completionMessage = viewer.getManager().performVariableSubstitution >+ (item.getCompletionMessage()); > if (completionMessage != null) { > Color backgroundColor = bodyWrapperComposite.getBackground(); > completionComposite = page.getToolkit().createComposite( >#P org.eclipse.ua.tests >Index: cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/MockCheatSheetManager.java >=================================================================== >RCS file: cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/MockCheatSheetManager.java >diff -N cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/MockCheatSheetManager.java >--- cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/MockCheatSheetManager.java 30 Jan 2006 23:12:57 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,38 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >- >-package org.eclipse.ua.tests.cheatsheet.execution; >- >-import java.util.HashMap; >-import java.util.Map; >- >-import org.eclipse.ui.cheatsheets.ICheatSheetManager; >- >-/** >- * Mock object used in JUnit tests for command execution >- */ >- >-public class MockCheatSheetManager implements ICheatSheetManager { >- >- private Map dataStore = new HashMap(); >- public String getCheatSheetID() { >- return "Mock"; >- } >- >- public String getData(String key) { >- return (String)dataStore.get(key); >- } >- >- public void setData(String key, String data) { >- dataStore.put(key, data); >- } >- >-} >Index: cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestCommandExecution.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestCommandExecution.java,v >retrieving revision 1.3 >diff -u -r1.3 TestCommandExecution.java >--- cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestCommandExecution.java 9 Feb 2006 20:21:52 -0000 1.3 >+++ cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestCommandExecution.java 7 Mar 2006 21:44:51 -0000 >@@ -24,10 +24,11 @@ > import org.eclipse.core.runtime.IStatus; > import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin; > import org.eclipse.ui.IWorkbench; >-import org.eclipse.ui.cheatsheets.ICheatSheetManager; > import org.eclipse.ui.commands.ICommandService; > import org.eclipse.ui.internal.cheatsheets.CommandRunner; > import org.eclipse.ui.internal.cheatsheets.data.CheatSheetCommand; >+import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement; >+import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager; > > /** > * Tests which exercise the CommandRunner class >@@ -46,10 +47,17 @@ > + PARAM1_ID + '=' + PARAM1_VALUE + ',' > + PARAM2_ID + '=' + PARAM2_VALUE + ')'; > private static final String RETURN_STORE = "retData"; >+ private static final String PARENT_RETURN_STORE = "parent.retData"; > > protected void setUp() throws Exception { > CommandHandler.reset(); > } >+ >+ public CheatSheetManager createManager() { >+ CheatSheetElement element = new CheatSheetElement("Name"); >+ element.setID("TestCommandExecutionId"); >+ return new CheatSheetManager(element); >+ } > > private ICommandService getService() { > IWorkbench wb =UserAssistanceTestPlugin.getDefault().getWorkbench(); //.getCommandSupport(); >@@ -96,7 +104,7 @@ > > public void testCommandRunner() { > CheatSheetCommand command = new CheatSheetCommand(); >- ICheatSheetManager csm = new MockCheatSheetManager(); >+ CheatSheetManager csm = createManager(); > command.setSerialization(SERIALIZED_COMMAND); > > IStatus status = new CommandRunner().executeCommand(command, csm); >@@ -104,10 +112,10 @@ > > checkCommandExecution(); > } >- >+ > public void testCommandWithResult() { > CheatSheetCommand command = new CheatSheetCommand(); >- ICheatSheetManager csm = new MockCheatSheetManager(); >+ CheatSheetManager csm = createManager(); > command.setSerialization(SERIALIZED_COMMAND); > command.setReturns(RETURN_STORE); > >@@ -119,9 +127,27 @@ > checkCommandExecution(); > } > >+ /** >+ * Test that if the return is set to parent.retData the >+ * return value is written to the parent cheat sheet manager. >+ */ >+ public void testCommandWithQualifiedResult() { >+ CheatSheetCommand command = new CheatSheetCommand(); >+ CheatSheetManager csm = createManager(); >+ CheatSheetManager parentManager = createManager(); >+ csm.setParent(parentManager); >+ command.setSerialization(SERIALIZED_COMMAND); >+ command.setReturns(PARENT_RETURN_STORE); >+ >+ IStatus status = new CommandRunner().executeCommand(command, csm); >+ assertTrue(status.isOK()); >+ assertNull(csm.getData(RETURN_STORE)); >+ assertNotNull(parentManager.getData(RETURN_STORE)); >+ } >+ > public void testInvalidCommandId() { > CheatSheetCommand command = new CheatSheetCommand(); >- ICheatSheetManager csm = new MockCheatSheetManager(); >+ CheatSheetManager csm = createManager(); > command.setSerialization(COMMAND_ID + ".invalid"); //$NON-NLS-1$ > IStatus status = new CommandRunner().executeCommand(command, csm); > assertFalse(status.isOK()); >@@ -129,7 +155,7 @@ > > public void testCommandException() { > CheatSheetCommand command = new CheatSheetCommand(); >- ICheatSheetManager csm = new MockCheatSheetManager(); >+ CheatSheetManager csm = createManager(); > command.setSerialization(SERIALIZED_COMMAND); > CommandHandler.setThrowException(true); > >@@ -142,7 +168,7 @@ > > public void testCommandWithIntegerValues() { > CheatSheetCommand command = new CheatSheetCommand(); >- ICheatSheetManager csm = new MockCheatSheetManager(); >+ CheatSheetManager csm = createManager(); > command.setSerialization(NEGATE_INTEGER_COMMAND_ID); > command.setReturns(INT_RETURN_STORE); > >Index: cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestVariableSubstitution.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestVariableSubstitution.java,v >retrieving revision 1.1 >diff -u -r1.1 TestVariableSubstitution.java >--- cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestVariableSubstitution.java 30 Jan 2006 23:12:57 -0000 1.1 >+++ cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestVariableSubstitution.java 7 Mar 2006 21:44:51 -0000 >@@ -16,22 +16,22 @@ > * command execution > */ > >-import org.eclipse.ui.cheatsheets.ICheatSheetManager; >+import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement; > import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager; > > import junit.framework.TestCase; > > public class TestVariableSubstitution extends TestCase { >- private ICheatSheetManager manager; >+ private CheatSheetManager manager; > > protected void setUp() throws Exception { >- manager = new MockCheatSheetManager(); >+ manager = new CheatSheetManager(new CheatSheetElement("name")); > manager.setData("p1", "one"); > manager.setData("p2", "two"); > } > > private String substitute(String input) { >- return CheatSheetManager.performVariableSubstitution(input, manager); >+ return manager.performVariableSubstitution(input); > } > > public void testNoSubstitution() { >Index: cheatsheet/org/eclipse/ua/tests/cheatsheet/other/AllOtherCheatSheetTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/other/AllOtherCheatSheetTests.java,v >retrieving revision 1.1 >diff -u -r1.1 AllOtherCheatSheetTests.java >--- cheatsheet/org/eclipse/ua/tests/cheatsheet/other/AllOtherCheatSheetTests.java 2 Mar 2006 17:30:51 -0000 1.1 >+++ cheatsheet/org/eclipse/ua/tests/cheatsheet/other/AllOtherCheatSheetTests.java 7 Mar 2006 21:44:51 -0000 >@@ -23,6 +23,7 @@ > TestSuite suite = new TestSuite( > "org.eclipse.ua.tests.cheatsheet.AllOtherCheatSheetTests"); > //$JUnit-BEGIN$ >+ suite.addTestSuite(TestCheatSheetManager.class); > suite.addTestSuite(TestStatePersistence.class); > //$JUnit-END$ > return suite; >Index: cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetManager.java >=================================================================== >RCS file: cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetManager.java >diff -N cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetManager.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetManager.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,126 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.ua.tests.cheatsheet.other; >+ >+import java.util.Set; >+ >+import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement; >+import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager; >+ >+import junit.framework.TestCase; >+ >+public class TestCheatSheetManager extends TestCase { >+ >+ private static final String CHEATSHEET_ID = "RandomId0234"; >+ private static final String CHEATSHEET_NAME = "Name"; >+ private static final String KEY1 = "key1"; >+ private static final String PARENT_KEY1 = "parent.key1"; >+ private static final String PARENT_KEY2 = "parent.key2"; >+ private static final String VALUE_A = "A"; >+ private static final String VALUE_B = "B"; >+ private static final String VALUE_C = "C"; >+ >+ public CheatSheetManager createManager() { >+ CheatSheetElement element = new CheatSheetElement(CHEATSHEET_NAME); >+ element.setID(CHEATSHEET_ID); >+ return new CheatSheetManager(element); >+ } >+ >+ /** >+ * Test for correct initialization >+ */ >+ public void testNewManager() { >+ CheatSheetManager manager = createManager(); >+ assertNotNull(manager.getKeySet()); >+ assertTrue(manager.getKeySet().isEmpty()); >+ assertEquals(CHEATSHEET_ID, manager.getCheatSheetID()); >+ } >+ >+ /** >+ * Test that if there is no parent all references are local. >+ */ >+ public void testNoParent() { >+ CheatSheetManager manager = createManager(); >+ manager.setDataQualified(KEY1, VALUE_A); >+ manager.setDataQualified(PARENT_KEY1, VALUE_B); >+ assertEquals(VALUE_A, manager.getData(KEY1)); >+ assertEquals(VALUE_A, manager.getDataQualified(KEY1)); >+ assertEquals(VALUE_B, manager.getData(PARENT_KEY1)); >+ assertEquals(VALUE_B, manager.getDataQualified(PARENT_KEY1)); >+ Set keys = manager.getKeySet(); >+ assertEquals(keys.size(), 2); >+ assertTrue(keys.contains(KEY1)); >+ assertTrue(keys.contains(PARENT_KEY1)); >+ } >+ >+ /** >+ * Test that if there is a parent getDataQualified and setDataQualified >+ * can reference the parent but getData is always local >+ */ >+ public void testParentAccess() { >+ CheatSheetManager manager = createManager(); >+ CheatSheetManager parentManager = createManager(); >+ manager.setParent(parentManager); >+ manager.setDataQualified(KEY1, VALUE_A); >+ manager.setDataQualified(PARENT_KEY1, VALUE_B); >+ assertEquals(VALUE_A, manager.getData(KEY1)); >+ assertEquals(VALUE_A, manager.getDataQualified(KEY1)); >+ assertNull(manager.getData(PARENT_KEY1)); >+ assertEquals(VALUE_B, manager.getDataQualified(PARENT_KEY1)); >+ Set keys = manager.getKeySet(); >+ assertEquals(keys.size(), 1); >+ assertTrue(keys.contains(KEY1)); >+ assertFalse(keys.contains(PARENT_KEY1)); >+ >+ Set parentKeys = parentManager.getKeySet(); >+ assertEquals(parentKeys.size(), 1); >+ assertTrue(parentKeys.contains(KEY1)); >+ assertFalse(parentKeys.contains(PARENT_KEY1)); >+ } >+ >+ /** >+ * Test that setData always writes locally >+ */ >+ public void testSetDataWithParent() { >+ CheatSheetManager manager = createManager(); >+ CheatSheetManager parentManager = createManager(); >+ manager.setParent(parentManager); >+ manager.setData(KEY1, VALUE_A); >+ manager.setData(PARENT_KEY1, VALUE_B); >+ assertEquals(VALUE_A, manager.getData(KEY1)); >+ assertEquals(VALUE_A, manager.getDataQualified(KEY1)); >+ assertNull(manager.getDataQualified(PARENT_KEY1)); >+ assertEquals(VALUE_B, manager.getData(PARENT_KEY1)); >+ Set keys = manager.getKeySet(); >+ assertEquals(keys.size(), 2); >+ assertTrue(keys.contains(KEY1)); >+ assertTrue(keys.contains(PARENT_KEY1)); >+ >+ Set parentKeys = parentManager.getKeySet(); >+ assertEquals(parentKeys.size(), 0); >+ } >+ >+ public void testSubstitution() { >+ CheatSheetManager manager = createManager(); >+ CheatSheetManager parentManager = createManager(); >+ manager.setParent(parentManager); >+ manager.setDataQualified(KEY1, VALUE_A); >+ manager.setDataQualified(PARENT_KEY1, VALUE_B); >+ manager.setDataQualified(PARENT_KEY2, VALUE_C); >+ assertEquals(VALUE_A, manager.getVariableData("${key1}")); >+ assertEquals(VALUE_B, manager.getVariableData("${parent.key1}")); >+ assertEquals(VALUE_C, manager.getVariableData("${parent.key2}")); >+ assertEquals("Values are A B C", manager.performVariableSubstitution >+ ("Values are ${key1} ${parent.key1} ${parent.key2}")); >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 84457
: 35860