Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1075c567e52fe5d8e58a82cab55e5a016dc610ad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*******************************************************************************
 * Copyright (c) 2013, 2017 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 ******************************************************************************/

package org.eclipse.ui.tests.commands;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;
import org.junit.Test;

/**
 * @since 3.5
 *
 */
public class Bug417762Test {

	@Test
	public void testAsReported() throws ExecutionException,
			NotDefinedException, NotEnabledException, NotHandledException {
		IWorkbench workbench = PlatformUI.getWorkbench();
		ICommandService commandService = workbench
				.getService(ICommandService.class);
		IHandlerService handlerService = workbench
				.getService(IHandlerService.class);
		Command showInCommand = commandService
				.getCommand(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN);
		Map<String, String> parameters = new HashMap<>();
		parameters.put(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_PARM_TARGET,
				"my.view.id");
		IEvaluationContext contextSnapshot = handlerService
				.createContextSnapshot(true);
		ExecutionEvent event = new ExecutionEvent(showInCommand, parameters,
				null, contextSnapshot);
		showInCommand.executeWithChecks(event);
	}

	@Test
	public void testSuggestionUseExecuteCommand() throws ExecutionException,
			NotDefinedException, NotEnabledException, NotHandledException {
		IWorkbench workbench = PlatformUI.getWorkbench();
		ICommandService commandService = workbench
				.getService(ICommandService.class);
		IHandlerService handlerService = workbench
				.getService(IHandlerService.class);
		Command showInCommand = commandService
				.getCommand(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN);
//		Map<String, String> parameters = new HashMap<String, String>();
//		parameters.put(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_PARM_TARGET,
//				"my.view.id");
//		IEvaluationContext contextSnapshot = handlerService
//				.createContextSnapshot(true);
//		ExecutionEvent event = new ExecutionEvent(showInCommand, parameters,
//				null, contextSnapshot);
//		showInCommand.executeWithChecks(event);

		handlerService
				.executeCommand(
						ParameterizedCommand.generateCommand(
								showInCommand,
								Collections
										.singletonMap(
												IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_PARM_TARGET,
												"my.view.id")), null);
	}

	@Test
	public void testSuggestionUseExecuteCommandInContext() throws ExecutionException,
			NotDefinedException, NotEnabledException, NotHandledException {
		IWorkbench workbench = PlatformUI.getWorkbench();
		ICommandService commandService = workbench
				.getService(ICommandService.class);
		IHandlerService handlerService = workbench
				.getService(IHandlerService.class);
		Command showInCommand = commandService
				.getCommand(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN);
//		Map<String, String> parameters = new HashMap<String, String>();
//		parameters.put(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_PARM_TARGET,
//				"my.view.id");
		IEvaluationContext contextSnapshot = handlerService
				.createContextSnapshot(true);
//		ExecutionEvent event = new ExecutionEvent(showInCommand, parameters,
//				null, contextSnapshot);
//		showInCommand.executeWithChecks(event);

		handlerService
				.executeCommandInContext(
						ParameterizedCommand.generateCommand(
								showInCommand,
								Collections
										.singletonMap(
												IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_PARM_TARGET,
												"my.view.id")), null, contextSnapshot);
	}

	@Test
	public void testSuggestionUseParameterizedCommandExecuteWithChecks() throws ExecutionException,
			NotDefinedException, NotEnabledException, NotHandledException {
		IWorkbench workbench = PlatformUI.getWorkbench();
		ICommandService commandService = workbench
				.getService(ICommandService.class);
		IHandlerService handlerService = workbench
				.getService(IHandlerService.class);
		Command showInCommand = commandService
				.getCommand(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN);
//		Map<String, String> parameters = new HashMap<String, String>();
//		parameters.put(IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_PARM_TARGET,
//				"my.view.id");
		IEvaluationContext contextSnapshot = handlerService
				.createContextSnapshot(true);
//		ExecutionEvent event = new ExecutionEvent(showInCommand, parameters,
//				null, contextSnapshot);
//		showInCommand.executeWithChecks(event);

		final ParameterizedCommand pc = ParameterizedCommand.generateCommand(
				showInCommand,
				Collections
						.singletonMap(
								IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_PARM_TARGET,
								"my.view.id"));
		pc.executeWithChecks(null, contextSnapshot);
//		handlerService
//				.executeCommandInContext(
//						pc, null, contextSnapshot);
	}


}

Back to the top