View | Details | Raw Unified | Return to bug 84457
Collapse All | Expand All

(-)src/org/eclipse/ui/cheatsheets/ICheatSheetManager.java (+18 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.cheatsheets;
11
package org.eclipse.ui.cheatsheets;
12
12
13
import java.util.Set;
14
13
/**
15
/**
14
 * Manages the running of a cheat sheet.
16
 * Manages the running of a cheat sheet.
15
 * <p>
17
 * <p>
Lines 68-71 Link Here
68
	 * is <code>null</code>
70
	 * is <code>null</code>
69
	 */
71
	 */
70
	public void setData(String key, String data);
72
	public void setData(String key, String data);
73
	
74
	/**
75
	 * Get the cheat sheet manager for the enclosing composite cheat sheet.
76
	 * @return The cheat sheet manager for the composite cheat sheet which contains
77
	 * this cheat sheet as a task or <code>null</code> if this cheatsheet was not
78
	 * opened as a subtask of a composite cheat sheet.
79
	 * @since 3.2
80
	 */
81
	public ICheatSheetManager getParent();
82
	
83
	/**
84
	 * Get the keys for the data in this cheat sheet manager
85
	 * @return The set of keys.
86
	 * @since 3.2
87
	 */
88
	public Set getKeySet();
71
}
89
}
(-)src/org/eclipse/ui/cheatsheets/ICheatSheetViewer.java (+12 lines)
Lines 11-16 Link Here
11
package org.eclipse.ui.cheatsheets;
11
package org.eclipse.ui.cheatsheets;
12
12
13
import java.net.URL;
13
import java.net.URL;
14
import java.util.Map;
15
14
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Composite;
15
import org.eclipse.swt.widgets.Control;
17
import org.eclipse.swt.widgets.Control;
16
18
Lines 113-116 Link Here
113
	 * are <code>null</code>
115
	 * are <code>null</code>
114
	 */
116
	 */
115
	public void setInput(String id, String name, URL url);
117
	public void setInput(String id, String name, URL url);
118
	
119
	/**
120
	 * Sets the currently active cheat sheet to its initial state and
121
	 * initalizes the cheat sheet manager data.
122
	 * @param cheatSheetData A map whose keys and values are all of type
123
	 * <code>java.lang.String</code> or <code>null</code> to reset all data in 
124
	 * the cheat sheet manager. 
125
	 * @since 3.2
126
	 */
127
	public void reset(Map cheatSheetData);
116
}
128
}
(-)src/org/eclipse/ui/internal/cheatsheets/state/MementoStateManager.java (-1 / +5 lines)
Lines 17-22 Link Here
17
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Status;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.ui.IMemento;
19
import org.eclipse.ui.IMemento;
20
import org.eclipse.ui.cheatsheets.ICheatSheetManager;
20
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetSaveHelper;
21
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetSaveHelper;
21
import org.eclipse.ui.internal.cheatsheets.data.IParserTags;
22
import org.eclipse.ui.internal.cheatsheets.data.IParserTags;
22
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
23
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
Lines 33-45 Link Here
33
	private CheatSheetElement element;
34
	private CheatSheetElement element;
34
	private CheatSheetSaveHelper saveHelper = new CheatSheetSaveHelper();
35
	private CheatSheetSaveHelper saveHelper = new CheatSheetSaveHelper();
35
	private Properties props;
36
	private Properties props;
37
	private ICheatSheetManager parentCsm;
36
38
37
	/**
39
	/**
38
	 * @param memento The memento which will be used to initialize the state. May be
40
	 * @param memento The memento which will be used to initialize the state. May be
39
	 * null to indicate that the state should be initialized.
41
	 * null to indicate that the state should be initialized.
40
	 */
42
	 */
41
	public MementoStateManager(IMemento memento) {
43
	public MementoStateManager(IMemento memento, ICheatSheetManager parentCsm) {
42
		this.memento = memento;
44
		this.memento = memento;
45
		this.parentCsm = parentCsm;
43
	}
46
	}
44
47
45
	/**
48
	/**
Lines 60-65 Link Here
60
		if (getProperties() != null) {
63
		if (getProperties() != null) {
61
		    result.setData((Hashtable) getProperties().get(IParserTags.MANAGERDATA));
64
		    result.setData((Hashtable) getProperties().get(IParserTags.MANAGERDATA));
62
		}
65
		}
66
		result.setParent(parentCsm);
63
		return result;
67
		return result;
64
	}
68
	}
65
69
(-)src/org/eclipse/ui/internal/cheatsheets/composite/model/AbstractTask.java (-1 / +2 lines)
Lines 21-26 Link Here
21
21
22
import org.eclipse.ui.cheatsheets.ICompositeCheatSheet;
22
import org.eclipse.ui.cheatsheets.ICompositeCheatSheet;
23
import org.eclipse.ui.cheatsheets.ICompositeCheatSheetTask;
23
import org.eclipse.ui.cheatsheets.ICompositeCheatSheetTask;
24
import org.eclipse.ui.cheatsheets.ITaskGroup;
24
import org.eclipse.ui.internal.cheatsheets.composite.parser.ITaskParseStrategy;
25
import org.eclipse.ui.internal.cheatsheets.composite.parser.ITaskParseStrategy;
25
26
26
/**
27
/**
Lines 205-211 Link Here
205
		this.parent = parent;
206
		this.parent = parent;
206
	}
207
	}
207
208
208
	public TaskGroup getParent() {
209
	public ITaskGroup getParent() {
209
		return parent;
210
		return parent;
210
	}
211
	}
211
212
(-)src/org/eclipse/ui/internal/cheatsheets/composite/model/CompositeCheatSheetModel.java (-7 / +7 lines)
Lines 13-25 Link Here
13
13
14
import java.net.URL;
14
import java.net.URL;
15
import java.util.Hashtable;
15
import java.util.Hashtable;
16
import java.util.Map;
16
import java.util.Observable;
17
import java.util.Observable;
17
18
18
import org.eclipse.ui.IMemento;
19
import org.eclipse.ui.IMemento;
19
import org.eclipse.ui.cheatsheets.ICheatSheetManager;
20
import org.eclipse.ui.cheatsheets.ICheatSheetManager;
20
import org.eclipse.ui.cheatsheets.ICompositeCheatSheetTask;
21
import org.eclipse.ui.cheatsheets.ICompositeCheatSheetTask;
21
import org.eclipse.ui.cheatsheets.ICompositeCheatSheet;
22
import org.eclipse.ui.cheatsheets.ICompositeCheatSheet;
22
import org.eclipse.ui.cheatsheets.TaskEditor;
23
import org.eclipse.ui.internal.cheatsheets.data.ICheatSheet;
23
import org.eclipse.ui.internal.cheatsheets.data.ICheatSheet;
24
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
24
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
25
25
Lines 118-127 Link Here
118
		if (task instanceof EditableTask) {
118
		if (task instanceof EditableTask) {
119
		    EditableTask editable = (EditableTask)task;
119
		    EditableTask editable = (EditableTask)task;
120
			editable.setState(ICompositeCheatSheetTask.NOT_STARTED);
120
			editable.setState(ICompositeCheatSheetTask.NOT_STARTED);
121
			TaskEditor editor = editable.getEditor();
122
		    if (editor != null) {
123
		    	editor.setInput(editable, null);
124
		    }
125
		} else if (task instanceof TaskGroup) { 
121
		} else if (task instanceof TaskGroup) { 
126
			TaskGroup group = (TaskGroup)task;
122
			TaskGroup group = (TaskGroup)task;
127
		    ICompositeCheatSheetTask[] subtasks = group.getSubtasks();
123
		    ICompositeCheatSheetTask[] subtasks = group.getSubtasks();
Lines 132-140 Link Here
132
		}
128
		}
133
	}
129
	}
134
130
135
	public void resetAllTasks() {
131
	public void resetAllTasks(Map cheatSheetData) {
136
        if (manager != null) {
132
        if (manager != null) {
137
        	manager.setData(new Hashtable());
133
    		if (cheatSheetData == null) {
134
            	manager.setData(new Hashtable());
135
    		} else {
136
    			manager.setData(cheatSheetData);
137
    		}
138
        }
138
        }
139
        saveHelper.clearTaskMementos();	
139
        saveHelper.clearTaskMementos();	
140
	    resetTask(getRootTask());
140
	    resetTask(getRootTask());
(-)src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetCommand.java (-2 / +2 lines)
Lines 13-21 Link Here
13
13
14
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.osgi.util.NLS;
15
import org.eclipse.osgi.util.NLS;
16
import org.eclipse.ui.cheatsheets.ICheatSheetManager;
17
import org.eclipse.ui.internal.cheatsheets.CommandRunner;
16
import org.eclipse.ui.internal.cheatsheets.CommandRunner;
18
import org.eclipse.ui.internal.cheatsheets.Messages;
17
import org.eclipse.ui.internal.cheatsheets.Messages;
18
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
19
import org.w3c.dom.Node;
19
import org.w3c.dom.Node;
20
20
21
/**
21
/**
Lines 40-46 Link Here
40
		return true;
40
		return true;
41
	}
41
	}
42
42
43
	public IStatus execute(ICheatSheetManager csm) {
43
	public IStatus execute(CheatSheetManager csm) {
44
		return new CommandRunner().executeCommand(this, csm);
44
		return new CommandRunner().executeCommand(this, csm);
45
	}
45
	}
46
46
(-)src/org/eclipse/ui/internal/cheatsheets/data/AbstractExecutable.java (-2 / +2 lines)
Lines 12-18 Link Here
12
package org.eclipse.ui.internal.cheatsheets.data;
12
package org.eclipse.ui.internal.cheatsheets.data;
13
13
14
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.ui.cheatsheets.ICheatSheetManager;
15
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
16
import org.w3c.dom.Node;
16
import org.w3c.dom.Node;
17
17
18
/**
18
/**
Lines 107-113 Link Here
107
	 * completes with a failure result, error status if an exception was thrown
107
	 * completes with a failure result, error status if an exception was thrown
108
	 * or the executable could not be initiated.
108
	 * or the executable could not be initiated.
109
	 */
109
	 */
110
	public abstract IStatus execute(ICheatSheetManager csm);	
110
	public abstract IStatus execute(CheatSheetManager csm);	
111
111
112
	/**
112
	/**
113
	 * @return true if this executable can have parameters
113
	 * @return true if this executable can have parameters
(-)src/org/eclipse/ui/internal/cheatsheets/data/Action.java (-2 / +2 lines)
Lines 12-20 Link Here
12
12
13
import org.eclipse.core.runtime.IStatus;
13
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.osgi.util.NLS;
14
import org.eclipse.osgi.util.NLS;
15
import org.eclipse.ui.cheatsheets.ICheatSheetManager;
16
import org.eclipse.ui.internal.cheatsheets.ActionRunner;
15
import org.eclipse.ui.internal.cheatsheets.ActionRunner;
17
import org.eclipse.ui.internal.cheatsheets.Messages;
16
import org.eclipse.ui.internal.cheatsheets.Messages;
17
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
18
import org.w3c.dom.Node;
18
import org.w3c.dom.Node;
19
19
20
/**
20
/**
Lines 93-99 Link Here
93
	}
93
	}
94
94
95
95
96
	public IStatus execute(ICheatSheetManager csm) {
96
	public IStatus execute(CheatSheetManager csm) {
97
		return new ActionRunner().runAction(this, csm);
97
		return new ActionRunner().runAction(this, csm);
98
	}
98
	}
99
99
(-)src/org/eclipse/ui/internal/cheatsheets/ActionRunner.java (-3 / +3 lines)
Lines 19-33 Link Here
19
import org.eclipse.jface.util.PropertyChangeEvent;
19
import org.eclipse.jface.util.PropertyChangeEvent;
20
import org.eclipse.osgi.util.NLS;
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.ui.cheatsheets.ICheatSheetAction;
21
import org.eclipse.ui.cheatsheets.ICheatSheetAction;
22
import org.eclipse.ui.cheatsheets.ICheatSheetManager;
23
import org.eclipse.ui.internal.cheatsheets.data.Action;
22
import org.eclipse.ui.internal.cheatsheets.data.Action;
23
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
24
import org.osgi.framework.Bundle;
24
import org.osgi.framework.Bundle;
25
25
26
/**
26
/**
27
 * Class which can run actions and determine the outcome
27
 * Class which can run actions and determine the outcome
28
 */
28
 */
29
public class ActionRunner {
29
public class ActionRunner {
30
	public IStatus runAction(Action cheatSheetAction, ICheatSheetManager csm) {
30
	public IStatus runAction(Action cheatSheetAction, CheatSheetManager csm) {
31
31
32
		IStatus status =  Status.OK_STATUS;
32
		IStatus status =  Status.OK_STATUS;
33
		String pluginId = cheatSheetAction.getPluginID();
33
		String pluginId = cheatSheetAction.getPluginID();
Lines 78-84 Link Here
78
					String param = clonedParams[i];
78
					String param = clonedParams[i];
79
					if(param != null && param.startsWith("${") && param.endsWith("}")) { //$NON-NLS-1$ //$NON-NLS-2$
79
					if(param != null && param.startsWith("${") && param.endsWith("}")) { //$NON-NLS-1$ //$NON-NLS-2$
80
						param = param.substring(2,param.length()-1);
80
						param = param.substring(2,param.length()-1);
81
						String value = csm.getData(param);
81
						String value = csm.getDataQualified(param);
82
						clonedParams[i] = value == null ? ICheatSheetResource.EMPTY_STRING : value;
82
						clonedParams[i] = value == null ? ICheatSheetResource.EMPTY_STRING : value;
83
					}
83
					}
84
				}
84
				}
(-)src/org/eclipse/ui/internal/cheatsheets/CommandRunner.java (-6 / +4 lines)
Lines 20-26 Link Here
20
import org.eclipse.osgi.util.NLS;
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.ui.IWorkbench;
21
import org.eclipse.ui.IWorkbench;
22
import org.eclipse.ui.PlatformUI;
22
import org.eclipse.ui.PlatformUI;
23
import org.eclipse.ui.cheatsheets.ICheatSheetManager;
24
import org.eclipse.ui.commands.ICommandService;
23
import org.eclipse.ui.commands.ICommandService;
25
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetCommand;
24
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetCommand;
26
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
25
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
Lines 50-56 Link Here
50
	 * @return OK_STATUS if the command completes withour error, otherwise
49
	 * @return OK_STATUS if the command completes withour error, otherwise
51
	 * an error status
50
	 * an error status
52
	 */
51
	 */
53
	public IStatus executeCommand(CheatSheetCommand command, ICheatSheetManager csm) {
52
	public IStatus executeCommand(CheatSheetCommand command, CheatSheetManager csm) {
54
		ICommandService service = getCommandService();
53
		ICommandService service = getCommandService();
55
		if (service == null) {
54
		if (service == null) {
56
			return new Status
55
			return new Status
Lines 63-70 Link Here
63
		Object result;			
62
		Object result;			
64
		String rawSerialization = command.getSerialization();
63
		String rawSerialization = command.getSerialization();
65
		try {
64
		try {
66
			String substitutedSerialization = CheatSheetManager.performVariableSubstitution
65
			String substitutedSerialization = csm.performVariableSubstitution(rawSerialization);
67
			    (rawSerialization, csm);
68
			selectedCommand = service.deserialize(substitutedSerialization);
66
			selectedCommand = service.deserialize(substitutedSerialization);
69
			result = selectedCommand.executeWithChecks(null, null);
67
			result = selectedCommand.executeWithChecks(null, null);
70
			
68
			
Lines 73-83 Link Here
73
				ParameterType returnType = selectedCommand.getCommand().getReturnType();
71
				ParameterType returnType = selectedCommand.getCommand().getReturnType();
74
				if ((returnType != null && (returnType.getValueConverter() != null))) {
72
				if ((returnType != null && (returnType.getValueConverter() != null))) {
75
					String resultString = returnType.getValueConverter().convertToString(result);
73
					String resultString = returnType.getValueConverter().convertToString(result);
76
					csm.setData(returnsAttribute, resultString);
74
					csm.setDataQualified(returnsAttribute, resultString);
77
				}
75
				}
78
				else {
76
				else {
79
					if (result instanceof String) {
77
					if (result instanceof String) {
80
						csm.setData(returnsAttribute, (String)result);
78
						csm.setDataQualified(returnsAttribute, (String)result);
81
					}
79
					}
82
				}
80
				}
83
			}
81
			}
(-)src/org/eclipse/ui/internal/cheatsheets/composite/views/CheatsheetTaskEditor.java (-4 / +4 lines)
Lines 47-57 Link Here
47
		Dictionary params = task.getParameters();
47
		Dictionary params = task.getParameters();
48
		String id = (String)params.get(ICompositeCheatsheetTags.CHEATSHEET_TASK_ID);
48
		String id = (String)params.get(ICompositeCheatsheetTags.CHEATSHEET_TASK_ID);
49
		String path = (String)params.get(ICompositeCheatsheetTags.CHEATSHEET_TASK_PATH);
49
		String path = (String)params.get(ICompositeCheatsheetTags.CHEATSHEET_TASK_PATH);
50
		MementoStateManager stateManager = new MementoStateManager(memento);
50
		MementoStateManager stateManager = new MementoStateManager(memento, task.getCompositeCheatSheet().getCheatSheetManager());
51
		if (path != null) {
51
		if (path != null) {
52
			URL url;
52
			URL url;
53
			try {
53
			try {
54
				url = task.getInputUrl(path);
54
				url = task.getInputUrl(path);
55
				if (id == null) { 
56
					id = task.getId();
57
				}
55
				viewer.setInput(id, task.getName(), url, stateManager);				
58
				viewer.setInput(id, task.getName(), url, stateManager);				
56
			} catch (MalformedURLException e) {
59
			} catch (MalformedURLException e) {
57
				e.printStackTrace();
60
				e.printStackTrace();
Lines 61-69 Link Here
61
		    viewer.setInput(id, stateManager);
64
		    viewer.setInput(id, stateManager);
62
		}
65
		}
63
		viewer.addListener(new TaskListener());
66
		viewer.addListener(new TaskListener());
64
		if (memento == null) {
65
			viewer.restart();
66
		}
67
	}
67
	}
68
	
68
	
69
	/*
69
	/*
(-)src/org/eclipse/ui/internal/cheatsheets/composite/views/CompositeCheatSheetPage.java (-10 / +18 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.ui.internal.cheatsheets.composite.views;
12
package org.eclipse.ui.internal.cheatsheets.composite.views;
13
13
14
import java.util.Map;
14
import java.util.Observable;
15
import java.util.Observable;
15
import java.util.Observer;
16
import java.util.Observer;
16
17
Lines 279-286 Link Here
279
	}
280
	}
280
281
281
	private void showTaskEditor(EditableTask task) {
282
	private void showTaskEditor(EditableTask task) {
282
		startIfSelected(task);
283
		startIfSelected(task, false);
283
		TaskEditor editor = getTaskEditor(task);
284
		TaskEditor editor = getTaskEditor(task, false);
284
		if (editor != null) {
285
		if (editor != null) {
285
		    setCurrentEditor(editor.getControl().getParent());
286
		    setCurrentEditor(editor.getControl().getParent());
286
		}
287
		}
Lines 392-400 Link Here
392
	/*
393
	/*
393
	 * Ensure that if this task is visible and in a runnable state that it has been started
394
	 * Ensure that if this task is visible and in a runnable state that it has been started
394
	 */
395
	 */
395
	private void startIfSelected(ICompositeCheatSheetTask task) {
396
	private void startIfSelected(ICompositeCheatSheetTask task, boolean initialize) {
396
		if (task == selectedTask) {
397
		if (task == selectedTask) {
397
			TaskEditor editor = getTaskEditor(task);
398
			TaskEditor editor = getTaskEditor(task, initialize);
398
			if (editor!=null) {
399
			if (editor!=null) {
399
				setCurrentEditor(editor.getControl());
400
				setCurrentEditor(editor.getControl());
400
			}
401
			}
Lines 413-419 Link Here
413
				if (data instanceof EditableTask) {
414
				if (data instanceof EditableTask) {
414
				    EditableTask task = (EditableTask)data;
415
				    EditableTask task = (EditableTask)data;
415
				    task.setStarted();
416
				    task.setStarted();
416
				    startIfSelected(task);
417
				    startIfSelected(task, true);
417
				}
418
				}
418
			}     
419
			}     
419
            if (ref.equals(SKIP_HREF)) {
420
            if (ref.equals(SKIP_HREF)) {
Lines 520-526 Link Here
520
	/*
521
	/*
521
	 * Get the task editor for this task. If no editor exists create one
522
	 * Get the task editor for this task. If no editor exists create one
522
	 */
523
	 */
523
	private TaskEditor getTaskEditor(ICompositeCheatSheetTask task) {
524
	private TaskEditor getTaskEditor(ICompositeCheatSheetTask task, boolean initialize) {
524
		if (task instanceof EditableTask) {
525
		if (task instanceof EditableTask) {
525
			EditableTask editable = (EditableTask)task;
526
			EditableTask editable = (EditableTask)task;
526
			if (editable.getEditor() == null) {
527
			if (editable.getEditor() == null) {
Lines 530-536 Link Here
530
					editor.createControl(taskEditorContainer, mform.getToolkit());
531
					editor.createControl(taskEditorContainer, mform.getToolkit());
531
					editor.setInput(editable, model.getTaskMemento(task.getId()));
532
					editor.setInput(editable, model.getTaskMemento(task.getId()));
532
					editable.setEditor(editor);
533
					editable.setEditor(editor);
533
				}				
534
				} else if (initialize) {
535
					editor.setInput(editable, model.getTaskMemento(task.getId()));
536
				}
534
			}
537
			}
535
			return editable.getEditor();
538
			return editable.getEditor();
536
		}
539
		}
Lines 569-577 Link Here
569
							PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 
572
							PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 
570
							Messages.COMPOSITE_RESTART_DIALOG_TITLE, 
573
							Messages.COMPOSITE_RESTART_DIALOG_TITLE, 
571
							Messages.COMPOSITE_RESTART_CONFIRM_MESSAGE)) {
574
							Messages.COMPOSITE_RESTART_CONFIRM_MESSAGE)) {
572
					    model.resetAllTasks();
575
					    restart(null);	
573
					    currentExplorer.setSelection
574
					        (new StructuredSelection(model.getRootTask()), true);	
575
				    }
576
				    }
576
				}
577
				}
577
			}
578
			}
Lines 610-613 Link Here
610
		return index;
611
		return index;
611
	}
612
	}
612
613
614
	public void restart(Map cheatSheetData) {
615
		model.resetAllTasks(cheatSheetData);
616
		currentExplorer.setSelection
617
		    (new StructuredSelection(model.getRootTask()), true);
618
		
619
	}
620
613
}
621
}
(-)src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java (-5 / +12 lines)
Lines 17-22 Link Here
17
import java.util.Hashtable;
17
import java.util.Hashtable;
18
import java.util.Iterator;
18
import java.util.Iterator;
19
import java.util.ListIterator;
19
import java.util.ListIterator;
20
import java.util.Map;
20
import java.util.Properties;
21
import java.util.Properties;
21
import java.util.StringTokenizer;
22
import java.util.StringTokenizer;
22
23
Lines 332-337 Link Here
332
	private boolean loadState() {
333
	private boolean loadState() {
333
		try {
334
		try {
334
			Properties props = stateManager.getProperties();
335
			Properties props = stateManager.getProperties();
336
337
			manager = stateManager.getCheatSheetManager();
335
	
338
	
336
			// There is a bug which causes the background of the buttons to
339
			// There is a bug which causes the background of the buttons to
337
			// remain white, even though the color is set. So instead of calling
340
			// remain white, even though the color is set. So instead of calling
Lines 368-375 Link Here
368
	
371
	
369
			if (cid != null)
372
			if (cid != null)
370
				currentID = cid;
373
				currentID = cid;
371
372
			manager = stateManager.getCheatSheetManager();
373
	
374
	
374
			if (itemNum >= 0) {
375
			if (itemNum >= 0) {
375
				currentItemNum = itemNum;
376
				currentItemNum = itemNum;
Lines 999-1007 Link Here
999
1000
1000
	/*package*/ void setContent(CheatSheetElement element, ICheatSheetStateManager inputStateManager) {
1001
	/*package*/ void setContent(CheatSheetElement element, ICheatSheetStateManager inputStateManager) {
1001
		CheatSheetStopWatch.startStopWatch("CheatSheetViewer.setContent(CheatSheetElement element)"); //$NON-NLS-1$
1002
		CheatSheetStopWatch.startStopWatch("CheatSheetViewer.setContent(CheatSheetElement element)"); //$NON-NLS-1$
1002
1003
		if (element != null && element.equals(contentElement))
1004
			return;
1005
		
1003
		
1006
		// Cleanup previous contents
1004
		// Cleanup previous contents
1007
		internalDispose();
1005
		internalDispose();
Lines 1170-1173 Link Here
1170
		}
1168
		}
1171
	}
1169
	}
1172
1170
1171
	public void reset(Map cheatSheetData) {
1172
		if (currentPage instanceof CheatSheetPage) {
1173
			restart();
1174
			getManager().setData(cheatSheetData);
1175
		} else if (currentPage instanceof CompositeCheatSheetPage) {
1176
			((CompositeCheatSheetPage)currentPage).restart(cheatSheetData);
1177
		}		
1178
	}
1179
1173
}
1180
}
(-)src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetManager.java (-5 / +52 lines)
Lines 20-30 Link Here
20
 */
20
 */
21
public class CheatSheetManager implements ICheatSheetManager {
21
public class CheatSheetManager implements ICheatSheetManager {
22
22
23
	private static final String PARENT_PREFIX = "parent."; //$NON-NLS-1$
23
	private static final String VARIABLE_END = "}"; //$NON-NLS-1$
24
	private static final String VARIABLE_END = "}"; //$NON-NLS-1$
24
	private static final String VARIABLE_BEGIN = "${"; //$NON-NLS-1$
25
	private static final String VARIABLE_BEGIN = "${"; //$NON-NLS-1$
25
	private String cheatsheetID;
26
	private String cheatsheetID;
26
	private List listeners;
27
	private List listeners;
27
	private Map dataTable = null;
28
	private Map dataTable = null;
29
	private ICheatSheetManager parent;
28
	
30
	
29
	public CheatSheetManager(CheatSheetElement element) {
31
	public CheatSheetManager(CheatSheetElement element) {
30
		cheatsheetID = element.getID();
32
		cheatsheetID = element.getID();
Lines 71-96 Link Here
71
			return null;
73
			return null;
72
		return (String) dataTable.get(key);
74
		return (String) dataTable.get(key);
73
	}
75
	}
76
	
77
	/**
78
	 * Similar to get data except that if the key is prefixed with "parent."
79
	 * get the data from the parent
80
	 * @param qualifiedKey
81
	 * @return The data for this key
82
	 */
83
	public String getDataQualified(String qualifiedKey) {
84
		if (qualifiedKey.startsWith(PARENT_PREFIX) && parent != null) {
85
			return parent.getData(qualifiedKey.substring(PARENT_PREFIX.length()));
86
		} else {
87
			return getData(qualifiedKey);
88
		}
89
	}
74
90
75
	public String getVariableData(String variable) {
91
	public String getVariableData(String variable) {
76
		String result = variable;
92
		String result = variable;
77
		if(variable != null && variable.startsWith(VARIABLE_BEGIN) && variable.endsWith(VARIABLE_END)) {
93
		if(variable != null && variable.startsWith(VARIABLE_BEGIN) && variable.endsWith(VARIABLE_END)) {
78
			result = variable.substring(2,variable.length()-1);
94
			result = variable.substring(2,variable.length()-1);
79
			result = getData(result);
95
			result = getDataQualified(result);
80
		}
96
		}
81
		return result;
97
		return result;
82
	}
98
	}
83
	
99
	
84
    /**
100
    /**
85
     * Substitute occurences of ${data} with values from the cheatsheetmanager.
101
     * Substitute occurences of ${data} with values from the cheatsheetmanager.
86
     * This function is static to allow for JUnit testing
87
     * @param input The input string
102
     * @param input The input string
88
     * @param csm The cheatsheet manager
103
     * @param csm The cheatsheet manager
89
     * @return The input string with substitutions made for any cheatsheet 
104
     * @return The input string with substitutions made for any cheatsheet 
90
     * variables encountered.
105
     * variables encountered.
91
     */
106
     */
92
	public static String performVariableSubstitution(String input,
107
	public String performVariableSubstitution(String input)
93
			             ICheatSheetManager csm)
94
	{
108
	{
95
		String remaining = input;
109
		String remaining = input;
96
		String output = ""; //$NON-NLS-1$
110
		String output = ""; //$NON-NLS-1$
Lines 103-109 Link Here
103
			} else {
117
			} else {
104
                String varName = remaining.substring(varIndex + VARIABLE_BEGIN.length(),
118
                String varName = remaining.substring(varIndex + VARIABLE_BEGIN.length(),
105
                		                         endIndex);
119
                		                         endIndex);
106
                String value = csm.getData(varName);
120
                String value = getDataQualified(varName);
107
                output += remaining.substring(0, varIndex);
121
                output += remaining.substring(0, varIndex);
108
                if (value != null) {
122
                if (value != null) {
109
                	output += value;
123
                	output += value;
Lines 137-142 Link Here
137
151
138
		dataTable.put(key, data);
152
		dataTable.put(key, data);
139
	}
153
	}
154
	
155
	/**
156
	 * Similar to setData except that if the key is prefixed by "parent." 
157
	 * set the data in the parent.
158
	 * @param qualifiedKey A key which may be prefixed by parent.
159
	 * @param data The value to set
160
	 */
161
	public void setDataQualified(String qualifiedKey, String data) {
162
		if (qualifiedKey == null) {
163
			throw new IllegalArgumentException();
164
		}
165
		if (qualifiedKey.startsWith(PARENT_PREFIX) && parent != null) {
166
			parent.setData(qualifiedKey.substring(PARENT_PREFIX.length()), data);
167
		} else {
168
			setData(qualifiedKey, data);
169
		}
170
	}
140
171
141
	/**
172
	/**
142
	 * Add a listener for cheatsheet events
173
	 * Add a listener for cheatsheet events
Lines 147-150 Link Here
147
		    listeners.add(listener);
178
		    listeners.add(listener);
148
		}
179
		}
149
	}
180
	}
181
182
	public ICheatSheetManager getParent() {
183
		return parent;
184
	}
185
	
186
	public void setParent(ICheatSheetManager parent) {
187
		this.parent = parent;
188
	}
189
190
	public Set getKeySet() {
191
		if (dataTable == null) {
192
			return new HashSet();
193
		} else {
194
		    return dataTable.keySet();
195
		}
196
	}
150
}
197
}
(-)src/org/eclipse/ui/internal/cheatsheets/views/CoreItem.java (-5 / +4 lines)
Lines 26-32 Link Here
26
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Control;
27
import org.eclipse.swt.widgets.Label;
27
import org.eclipse.swt.widgets.Label;
28
import org.eclipse.ui.PlatformUI;
28
import org.eclipse.ui.PlatformUI;
29
import org.eclipse.ui.cheatsheets.ICheatSheetManager;
30
import org.eclipse.ui.forms.events.HyperlinkAdapter;
29
import org.eclipse.ui.forms.events.HyperlinkAdapter;
31
import org.eclipse.ui.forms.events.HyperlinkEvent;
30
import org.eclipse.ui.forms.events.HyperlinkEvent;
32
import org.eclipse.ui.forms.widgets.ImageHyperlink;
31
import org.eclipse.ui.forms.widgets.ImageHyperlink;
Lines 447-457 Link Here
447
	}
446
	}
448
	
447
	
449
	/*package*/
448
	/*package*/
450
	IStatus runExecutable(ICheatSheetManager csm) {
449
	IStatus runExecutable(CheatSheetManager csm) {
451
		return runExecutable(this.getItem().getExecutable(), csm);	
450
		return runExecutable(this.getItem().getExecutable(), csm);	
452
	}
451
	}
453
	
452
	
454
	IStatus runExecutable(AbstractExecutable executable, ICheatSheetManager csm) {
453
	IStatus runExecutable(AbstractExecutable executable, CheatSheetManager csm) {
455
		if(executable != null) {
454
		if(executable != null) {
456
			return executable.execute(csm);
455
			return executable.execute(csm);
457
		} 
456
		} 
Lines 540-547 Link Here
540
	 * this is the last step.
539
	 * this is the last step.
541
	 */
540
	 */
542
	void createCompletionComposite(boolean isFinalItem) {
541
	void createCompletionComposite(boolean isFinalItem) {
543
		String completionMessage = CheatSheetManager.performVariableSubstitution
542
		String completionMessage = viewer.getManager().performVariableSubstitution
544
		    (item.getCompletionMessage(), viewer.getManager());
543
		    (item.getCompletionMessage());
545
		if (completionMessage != null) {
544
		if (completionMessage != null) {
546
			Color backgroundColor = bodyWrapperComposite.getBackground();
545
			Color backgroundColor = bodyWrapperComposite.getBackground();
547
			completionComposite = page.getToolkit().createComposite(
546
			completionComposite = page.getToolkit().createComposite(
(-)cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/MockCheatSheetManager.java (-38 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ua.tests.cheatsheet.execution;
13
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import org.eclipse.ui.cheatsheets.ICheatSheetManager;
18
19
/**
20
 * Mock object used in JUnit tests for command execution
21
 */
22
23
public class MockCheatSheetManager implements ICheatSheetManager {
24
25
	private Map dataStore = new HashMap();
26
	public String getCheatSheetID() {
27
		return "Mock";
28
	}
29
30
	public String getData(String key) {
31
		return (String)dataStore.get(key);
32
	}
33
34
	public void setData(String key, String data) {
35
		dataStore.put(key, data);
36
	}
37
38
}
(-)cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestCommandExecution.java (-7 / +33 lines)
Lines 24-33 Link Here
24
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
25
import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
26
import org.eclipse.ui.IWorkbench;
26
import org.eclipse.ui.IWorkbench;
27
import org.eclipse.ui.cheatsheets.ICheatSheetManager;
28
import org.eclipse.ui.commands.ICommandService;
27
import org.eclipse.ui.commands.ICommandService;
29
import org.eclipse.ui.internal.cheatsheets.CommandRunner;
28
import org.eclipse.ui.internal.cheatsheets.CommandRunner;
30
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetCommand;
29
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetCommand;
30
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
31
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
31
32
32
/**
33
/**
33
 * Tests which exercise the CommandRunner class
34
 * Tests which exercise the CommandRunner class
Lines 46-55 Link Here
46
	    + PARAM1_ID + '=' + PARAM1_VALUE + ',' 
47
	    + PARAM1_ID + '=' + PARAM1_VALUE + ',' 
47
	    + PARAM2_ID + '=' + PARAM2_VALUE + ')';	
48
	    + PARAM2_ID + '=' + PARAM2_VALUE + ')';	
48
	private static final String RETURN_STORE = "retData";
49
	private static final String RETURN_STORE = "retData";
50
	private static final String PARENT_RETURN_STORE = "parent.retData";
49
51
50
	protected void setUp() throws Exception {
52
	protected void setUp() throws Exception {
51
		CommandHandler.reset();
53
		CommandHandler.reset();
52
	}
54
	}
55
56
	public CheatSheetManager createManager() {
57
		CheatSheetElement element = new CheatSheetElement("Name");
58
		element.setID("TestCommandExecutionId");
59
		return new CheatSheetManager(element);
60
	}
53
	
61
	
54
	private ICommandService getService() {
62
	private ICommandService getService() {
55
		IWorkbench wb =UserAssistanceTestPlugin.getDefault().getWorkbench(); //.getCommandSupport();
63
		IWorkbench wb =UserAssistanceTestPlugin.getDefault().getWorkbench(); //.getCommandSupport();
Lines 96-102 Link Here
96
	
104
	
97
	public void testCommandRunner() {
105
	public void testCommandRunner() {
98
		CheatSheetCommand command = new CheatSheetCommand();
106
		CheatSheetCommand command = new CheatSheetCommand();
99
		ICheatSheetManager csm = new MockCheatSheetManager();
107
		CheatSheetManager csm = createManager();
100
		command.setSerialization(SERIALIZED_COMMAND);
108
		command.setSerialization(SERIALIZED_COMMAND);
101
		
109
		
102
		IStatus status = new CommandRunner().executeCommand(command, csm);
110
		IStatus status = new CommandRunner().executeCommand(command, csm);
Lines 104-113 Link Here
104
		
112
		
105
		checkCommandExecution();
113
		checkCommandExecution();
106
	}
114
	}
107
	
115
108
	public void testCommandWithResult() {
116
	public void testCommandWithResult() {
109
		CheatSheetCommand command = new CheatSheetCommand();
117
		CheatSheetCommand command = new CheatSheetCommand();
110
		ICheatSheetManager csm = new MockCheatSheetManager();
118
		CheatSheetManager csm = createManager();
111
		command.setSerialization(SERIALIZED_COMMAND);
119
		command.setSerialization(SERIALIZED_COMMAND);
112
		command.setReturns(RETURN_STORE);
120
		command.setReturns(RETURN_STORE);
113
		
121
		
Lines 119-127 Link Here
119
		checkCommandExecution();
127
		checkCommandExecution();
120
	}
128
	}
121
	
129
	
130
	/**
131
	 * Test that if the return is set to parent.retData the
132
	 * return value is written to the parent cheat sheet manager.
133
	 */
134
	public void testCommandWithQualifiedResult() {
135
		CheatSheetCommand command = new CheatSheetCommand();
136
		CheatSheetManager csm = createManager();
137
		CheatSheetManager parentManager = createManager();
138
		csm.setParent(parentManager);
139
		command.setSerialization(SERIALIZED_COMMAND);
140
		command.setReturns(PARENT_RETURN_STORE);
141
		
142
		IStatus status = new CommandRunner().executeCommand(command, csm);
143
		assertTrue(status.isOK());
144
		assertNull(csm.getData(RETURN_STORE));
145
		assertNotNull(parentManager.getData(RETURN_STORE));
146
	}
147
	
122
	public void testInvalidCommandId() {
148
	public void testInvalidCommandId() {
123
		CheatSheetCommand command = new CheatSheetCommand();
149
		CheatSheetCommand command = new CheatSheetCommand();
124
		ICheatSheetManager csm = new MockCheatSheetManager();
150
		CheatSheetManager csm = createManager();
125
		command.setSerialization(COMMAND_ID + ".invalid");	 //$NON-NLS-1$
151
		command.setSerialization(COMMAND_ID + ".invalid");	 //$NON-NLS-1$
126
		IStatus status = new CommandRunner().executeCommand(command, csm);
152
		IStatus status = new CommandRunner().executeCommand(command, csm);
127
		assertFalse(status.isOK());		
153
		assertFalse(status.isOK());		
Lines 129-135 Link Here
129
	
155
	
130
	public void testCommandException() {
156
	public void testCommandException() {
131
		CheatSheetCommand command = new CheatSheetCommand();
157
		CheatSheetCommand command = new CheatSheetCommand();
132
		ICheatSheetManager csm = new MockCheatSheetManager();
158
		CheatSheetManager csm = createManager();
133
		command.setSerialization(SERIALIZED_COMMAND);
159
		command.setSerialization(SERIALIZED_COMMAND);
134
		CommandHandler.setThrowException(true);
160
		CommandHandler.setThrowException(true);
135
		
161
		
Lines 142-148 Link Here
142
	
168
	
143
	public void testCommandWithIntegerValues() {
169
	public void testCommandWithIntegerValues() {
144
		CheatSheetCommand command = new CheatSheetCommand();
170
		CheatSheetCommand command = new CheatSheetCommand();
145
		ICheatSheetManager csm = new MockCheatSheetManager();
171
		CheatSheetManager csm = createManager();
146
		command.setSerialization(NEGATE_INTEGER_COMMAND_ID);
172
		command.setSerialization(NEGATE_INTEGER_COMMAND_ID);
147
		command.setReturns(INT_RETURN_STORE);
173
		command.setReturns(INT_RETURN_STORE);
148
		
174
		
(-)cheatsheet/org/eclipse/ua/tests/cheatsheet/execution/TestVariableSubstitution.java (-4 / +4 lines)
Lines 16-37 Link Here
16
 * command execution
16
 * command execution
17
 */
17
 */
18
18
19
import org.eclipse.ui.cheatsheets.ICheatSheetManager;
19
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
20
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
20
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
21
21
22
import junit.framework.TestCase;
22
import junit.framework.TestCase;
23
23
24
public class TestVariableSubstitution extends TestCase {
24
public class TestVariableSubstitution extends TestCase {
25
	private ICheatSheetManager manager;
25
	private CheatSheetManager manager;
26
	
26
	
27
	protected void setUp() throws Exception {
27
	protected void setUp() throws Exception {
28
		manager = new MockCheatSheetManager();
28
		manager = new CheatSheetManager(new CheatSheetElement("name"));
29
		manager.setData("p1", "one");
29
		manager.setData("p1", "one");
30
		manager.setData("p2", "two");
30
		manager.setData("p2", "two");
31
	}
31
	}
32
	
32
	
33
	private String substitute(String input) {
33
	private String substitute(String input) {
34
		return CheatSheetManager.performVariableSubstitution(input, manager);
34
		return manager.performVariableSubstitution(input);
35
	}
35
	}
36
36
37
	public void testNoSubstitution() {
37
	public void testNoSubstitution() {
(-)cheatsheet/org/eclipse/ua/tests/cheatsheet/other/AllOtherCheatSheetTests.java (+1 lines)
Lines 23-28 Link Here
23
		TestSuite suite = new TestSuite(
23
		TestSuite suite = new TestSuite(
24
				"org.eclipse.ua.tests.cheatsheet.AllOtherCheatSheetTests");
24
				"org.eclipse.ua.tests.cheatsheet.AllOtherCheatSheetTests");
25
		//$JUnit-BEGIN$
25
		//$JUnit-BEGIN$
26
		suite.addTestSuite(TestCheatSheetManager.class);
26
		suite.addTestSuite(TestStatePersistence.class);
27
		suite.addTestSuite(TestStatePersistence.class);
27
		//$JUnit-END$
28
		//$JUnit-END$
28
		return suite;
29
		return suite;
(-)cheatsheet/org/eclipse/ua/tests/cheatsheet/other/TestCheatSheetManager.java (+126 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ua.tests.cheatsheet.other;
13
14
import java.util.Set;
15
16
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
17
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
18
19
import junit.framework.TestCase;
20
21
public class TestCheatSheetManager extends TestCase {
22
23
	private static final String CHEATSHEET_ID = "RandomId0234"; 
24
	private static final String CHEATSHEET_NAME = "Name"; 
25
	private static final String KEY1 = "key1";
26
	private static final String PARENT_KEY1 = "parent.key1";
27
	private static final String PARENT_KEY2 = "parent.key2";
28
	private static final String VALUE_A = "A";
29
	private static final String VALUE_B = "B";
30
	private static final String VALUE_C = "C";
31
	
32
	public CheatSheetManager createManager() {
33
		CheatSheetElement element = new CheatSheetElement(CHEATSHEET_NAME);
34
		element.setID(CHEATSHEET_ID);
35
		return new CheatSheetManager(element);
36
	}
37
	
38
	/**
39
	 * Test for correct initialization 
40
	 */
41
	public void testNewManager() {
42
		CheatSheetManager manager = createManager();
43
		assertNotNull(manager.getKeySet());
44
		assertTrue(manager.getKeySet().isEmpty());
45
		assertEquals(CHEATSHEET_ID, manager.getCheatSheetID());
46
	}
47
	
48
	/**
49
	 * Test that if there is no parent all references are local.
50
	 */
51
	public void testNoParent() {
52
		CheatSheetManager manager = createManager();
53
		manager.setDataQualified(KEY1, VALUE_A);
54
		manager.setDataQualified(PARENT_KEY1, VALUE_B);
55
		assertEquals(VALUE_A, manager.getData(KEY1));
56
		assertEquals(VALUE_A, manager.getDataQualified(KEY1));
57
		assertEquals(VALUE_B, manager.getData(PARENT_KEY1));
58
		assertEquals(VALUE_B, manager.getDataQualified(PARENT_KEY1));
59
		Set keys = manager.getKeySet();
60
		assertEquals(keys.size(), 2);
61
		assertTrue(keys.contains(KEY1));
62
		assertTrue(keys.contains(PARENT_KEY1));
63
	}
64
	
65
	/**
66
	 * Test that if there is a parent getDataQualified and setDataQualified
67
	 * can reference the parent but getData is always local
68
	 */
69
	public void testParentAccess() {
70
		CheatSheetManager manager = createManager();
71
		CheatSheetManager parentManager = createManager();
72
		manager.setParent(parentManager);
73
		manager.setDataQualified(KEY1, VALUE_A);
74
		manager.setDataQualified(PARENT_KEY1, VALUE_B);
75
		assertEquals(VALUE_A, manager.getData(KEY1));
76
		assertEquals(VALUE_A, manager.getDataQualified(KEY1));
77
		assertNull(manager.getData(PARENT_KEY1));
78
		assertEquals(VALUE_B, manager.getDataQualified(PARENT_KEY1));
79
		Set keys = manager.getKeySet();
80
		assertEquals(keys.size(), 1);
81
		assertTrue(keys.contains(KEY1));
82
		assertFalse(keys.contains(PARENT_KEY1));
83
84
		Set parentKeys = parentManager.getKeySet();
85
		assertEquals(parentKeys.size(), 1);
86
		assertTrue(parentKeys.contains(KEY1));
87
		assertFalse(parentKeys.contains(PARENT_KEY1));
88
	}
89
	
90
	/**
91
	 * Test that setData always writes locally
92
	 */
93
	public void testSetDataWithParent() {
94
		CheatSheetManager manager = createManager();
95
		CheatSheetManager parentManager = createManager();
96
		manager.setParent(parentManager);
97
		manager.setData(KEY1, VALUE_A);
98
		manager.setData(PARENT_KEY1, VALUE_B);
99
		assertEquals(VALUE_A, manager.getData(KEY1));
100
		assertEquals(VALUE_A, manager.getDataQualified(KEY1));
101
		assertNull(manager.getDataQualified(PARENT_KEY1));
102
		assertEquals(VALUE_B, manager.getData(PARENT_KEY1));
103
		Set keys = manager.getKeySet();
104
		assertEquals(keys.size(), 2);
105
		assertTrue(keys.contains(KEY1));
106
		assertTrue(keys.contains(PARENT_KEY1));
107
108
		Set parentKeys = parentManager.getKeySet();
109
		assertEquals(parentKeys.size(), 0);
110
	}
111
	
112
	public void testSubstitution() {
113
		CheatSheetManager manager = createManager();
114
		CheatSheetManager parentManager = createManager();
115
		manager.setParent(parentManager);
116
		manager.setDataQualified(KEY1, VALUE_A);
117
		manager.setDataQualified(PARENT_KEY1, VALUE_B);
118
		manager.setDataQualified(PARENT_KEY2, VALUE_C);
119
		assertEquals(VALUE_A, manager.getVariableData("${key1}"));
120
		assertEquals(VALUE_B, manager.getVariableData("${parent.key1}"));
121
		assertEquals(VALUE_C, manager.getVariableData("${parent.key2}"));
122
		assertEquals("Values are A B C", manager.performVariableSubstitution
123
				("Values are ${key1} ${parent.key1} ${parent.key2}"));
124
	}
125
126
}

Return to bug 84457