Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2008 Versant Corp. 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 |
* Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103 |
10 |
******************************************************************************/ |
11 |
|
12 |
package org.eclipse.ui.tests.propertysheet; |
13 |
|
14 |
import java.util.HashMap; |
15 |
|
16 |
import org.eclipse.core.commands.Command; |
17 |
import org.eclipse.core.commands.ExecutionEvent; |
18 |
import org.eclipse.core.commands.ExecutionException; |
19 |
import org.eclipse.core.expressions.IEvaluationContext; |
20 |
import org.eclipse.core.runtime.IAdapterFactory; |
21 |
import org.eclipse.core.runtime.Platform; |
22 |
import org.eclipse.jface.viewers.StructuredSelection; |
23 |
import org.eclipse.ui.IPageLayout; |
24 |
import org.eclipse.ui.IViewPart; |
25 |
import org.eclipse.ui.PartInitException; |
26 |
import org.eclipse.ui.PlatformUI; |
27 |
import org.eclipse.ui.commands.ICommandService; |
28 |
import org.eclipse.ui.handlers.IHandlerService; |
29 |
import org.eclipse.ui.part.IShowInSource; |
30 |
import org.eclipse.ui.part.ShowInContext; |
31 |
import org.eclipse.ui.tests.SelectionProviderView; |
32 |
import org.eclipse.ui.views.properties.PropertySheet; |
33 |
import org.eclipse.ui.views.properties.PropertyShowInContext; |
34 |
|
35 |
/** |
36 |
* @since 3.5 |
37 |
* |
38 |
*/ |
39 |
public class NewPropertySheetHandlerTest extends AbstractPropertySheetTest { |
40 |
|
41 |
private TestNewPropertySheetHandler testNewPropertySheetHandler; |
42 |
|
43 |
public NewPropertySheetHandlerTest(String testName) { |
44 |
super(testName); |
45 |
} |
46 |
|
47 |
/* |
48 |
* (non-Javadoc) |
49 |
* |
50 |
* @see |
51 |
* org.eclipse.ui.tests.propertysheet.AbstractPropertySheetTest#doSetUp() |
52 |
*/ |
53 |
protected void doSetUp() throws Exception { |
54 |
super.doSetUp(); |
55 |
testNewPropertySheetHandler = new TestNewPropertySheetHandler(); |
56 |
} |
57 |
|
58 |
private ExecutionEvent getExecutionEvent() { |
59 |
IHandlerService handlerService = (IHandlerService) PlatformUI |
60 |
.getWorkbench().getService(IHandlerService.class); |
61 |
ICommandService commandService = (ICommandService) PlatformUI |
62 |
.getWorkbench().getService(ICommandService.class); |
63 |
IEvaluationContext evalContext = handlerService.getCurrentState(); |
64 |
Command command = commandService |
65 |
.getCommand(TestNewPropertySheetHandler.ID); |
66 |
ExecutionEvent executionEvent = new ExecutionEvent(command, |
67 |
new HashMap(), null, evalContext); |
68 |
return executionEvent; |
69 |
} |
70 |
|
71 |
/** |
72 |
* Test method for |
73 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#getShowInContext(org.eclipse.core.commands.ExecutionEvent)} |
74 |
* . |
75 |
* |
76 |
* @throws ExecutionException |
77 |
* @throws PartInitException |
78 |
* StructuredSelection.EMPTY, |
79 |
*/ |
80 |
public final void testGetShowInContextFromPropertySheet() |
81 |
throws ExecutionException, PartInitException { |
82 |
activePage.showView(IPageLayout.ID_PROP_SHEET); |
83 |
|
84 |
PropertyShowInContext context = testNewPropertySheetHandler |
85 |
.getShowInContext(getExecutionEvent()); |
86 |
assertNotNull(context); |
87 |
assertNull(context.getSelection()); |
88 |
assertNull(context.getPart()); |
89 |
assertNull(context.getInput()); |
90 |
} |
91 |
|
92 |
/** |
93 |
* Test method for |
94 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#getShowInContext(org.eclipse.core.commands.ExecutionEvent)} |
95 |
* . |
96 |
* |
97 |
* @throws ExecutionException |
98 |
* @throws PartInitException |
99 |
*/ |
100 |
public final void testGetShowInContextFromAShowInSource() |
101 |
throws ExecutionException, PartInitException { |
102 |
IAdapterFactory factory = new IAdapterFactory() { |
103 |
public Object getAdapter(Object adaptableObject, Class adapterType) { |
104 |
return new IShowInSource() { |
105 |
public ShowInContext getShowInContext() { |
106 |
return new ShowInContext(StructuredSelection.EMPTY, |
107 |
StructuredSelection.EMPTY); |
108 |
} |
109 |
}; |
110 |
} |
111 |
|
112 |
public Class[] getAdapterList() { |
113 |
return new Class[] { IShowInSource.class }; |
114 |
} |
115 |
}; |
116 |
try { |
117 |
SelectionProviderView selectionProviderView = (SelectionProviderView) activePage |
118 |
.showView(SelectionProviderView.ID); |
119 |
selectionProviderView.setSelection(StructuredSelection.EMPTY); |
120 |
Platform.getAdapterManager().registerAdapters(factory, |
121 |
SelectionProviderView.class); |
122 |
|
123 |
PropertyShowInContext context = testNewPropertySheetHandler |
124 |
.getShowInContext(getExecutionEvent()); |
125 |
assertNotNull(context); |
126 |
assertEquals(StructuredSelection.EMPTY, context.getSelection()); |
127 |
assertEquals(StructuredSelection.EMPTY, context.getInput()); |
128 |
assertEquals(selectionProviderView, context.getPart()); |
129 |
} finally { |
130 |
Platform.getAdapterManager().unregisterAdapters(factory); |
131 |
} |
132 |
} |
133 |
|
134 |
/** |
135 |
* Test method for |
136 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#getShowInContext(org.eclipse.core.commands.ExecutionEvent)} |
137 |
* . |
138 |
* |
139 |
* @throws ExecutionException |
140 |
* @throws PartInitException |
141 |
*/ |
142 |
public final void testGetShowInContextWithNoShowInSource() |
143 |
throws PartInitException, ExecutionException { |
144 |
SelectionProviderView selectionProviderView = (SelectionProviderView) activePage |
145 |
.showView(SelectionProviderView.ID); |
146 |
assertFalse(selectionProviderView instanceof IShowInSource); |
147 |
assertNull(selectionProviderView.getAdapter(IShowInSource.class)); |
148 |
|
149 |
PropertyShowInContext context = testNewPropertySheetHandler |
150 |
.getShowInContext(getExecutionEvent()); |
151 |
assertNotNull(context); |
152 |
assertNull(context.getSelection()); |
153 |
assertNull(context.getInput()); |
154 |
assertEquals(selectionProviderView, context.getPart()); |
155 |
} |
156 |
|
157 |
/** |
158 |
* Test method for |
159 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#getShowInContext(org.eclipse.core.commands.ExecutionEvent)} |
160 |
* . |
161 |
*/ |
162 |
public final void testGetShowInContextWithNoActivePart() { |
163 |
try { |
164 |
testNewPropertySheetHandler.getShowInContext(getExecutionEvent()); |
165 |
} catch (ExecutionException e) { |
166 |
return; |
167 |
} |
168 |
fail("Expected ExecutionException due to no active part"); |
169 |
} |
170 |
|
171 |
/** |
172 |
* Test method for |
173 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#findPropertySheet(org.eclipse.core.commands.ExecutionEvent, org.eclipse.ui.views.properties.PropertyShowInContext)} |
174 |
* . |
175 |
* |
176 |
* @throws ExecutionException |
177 |
* @throws PartInitException |
178 |
*/ |
179 |
public final void testFindPropertySheetWithoutActivePart() |
180 |
throws PartInitException, ExecutionException { |
181 |
assertNull(PlatformUI.getWorkbench().getActiveWorkbenchWindow() |
182 |
.getActivePage().getActivePart()); |
183 |
|
184 |
try { |
185 |
testNewPropertySheetHandler.findPropertySheet(getExecutionEvent(), |
186 |
new PropertyShowInContext(null, StructuredSelection.EMPTY)); |
187 |
} catch (ExecutionException e) { |
188 |
return; |
189 |
} |
190 |
fail("Expected ExecutionException due to no active part"); |
191 |
} |
192 |
|
193 |
/** |
194 |
* Test method for |
195 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#findPropertySheet(org.eclipse.core.commands.ExecutionEvent, org.eclipse.ui.views.properties.PropertyShowInContext)} |
196 |
* . |
197 |
* |
198 |
* @throws ExecutionException |
199 |
* @throws PartInitException |
200 |
*/ |
201 |
public final void testFindPropertySheetWithOtherSheetActive() |
202 |
throws PartInitException, ExecutionException { |
203 |
propertySheet = (PropertySheet) activePage |
204 |
.showView(IPageLayout.ID_PROP_SHEET); |
205 |
assertTrue(countPropertySheetViews() == 1); |
206 |
|
207 |
PropertySheet foundSheet = testNewPropertySheetHandler |
208 |
.findPropertySheet(getExecutionEvent(), |
209 |
new PropertyShowInContext(propertySheet, |
210 |
StructuredSelection.EMPTY)); |
211 |
assertNotNull(foundSheet); |
212 |
assertNotSame(propertySheet, foundSheet); |
213 |
assertTrue(countPropertySheetViews() == 2); |
214 |
} |
215 |
|
216 |
/** |
217 |
* Test method for |
218 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#findPropertySheet(org.eclipse.core.commands.ExecutionEvent, org.eclipse.ui.views.properties.PropertyShowInContext)} |
219 |
* . |
220 |
* |
221 |
* @throws ExecutionException |
222 |
* @throws PartInitException |
223 |
*/ |
224 |
public final void testFindPropertySheetWithSPVActive() |
225 |
throws PartInitException, ExecutionException { |
226 |
IViewPart showView = activePage.showView(IPageLayout.ID_PROP_SHEET); |
227 |
IViewPart spv = activePage.showView(SelectionProviderView.ID); |
228 |
assertTrue(countPropertySheetViews() == 1); |
229 |
|
230 |
PropertySheet foundSheet = testNewPropertySheetHandler |
231 |
.findPropertySheet(getExecutionEvent(), |
232 |
new PropertyShowInContext(spv, |
233 |
StructuredSelection.EMPTY)); |
234 |
assertNotNull(foundSheet); |
235 |
assertEquals(showView, foundSheet); |
236 |
assertTrue(countPropertySheetViews() == 1); |
237 |
} |
238 |
|
239 |
/** |
240 |
* Test method for |
241 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#findPropertySheet(org.eclipse.core.commands.ExecutionEvent, org.eclipse.ui.views.properties.PropertyShowInContext)} |
242 |
* . |
243 |
* |
244 |
* @throws ExecutionException |
245 |
* @throws PartInitException |
246 |
*/ |
247 |
public final void testFindPropertySheetWithPinnedPSandSPVActive() |
248 |
throws PartInitException, ExecutionException { |
249 |
PropertySheet sheet = (PropertySheet) activePage |
250 |
.showView(IPageLayout.ID_PROP_SHEET); |
251 |
sheet.setPinned(true); |
252 |
IViewPart spv = activePage.showView(SelectionProviderView.ID); |
253 |
assertTrue(countPropertySheetViews() == 1); |
254 |
|
255 |
PropertySheet foundSheet = testNewPropertySheetHandler |
256 |
.findPropertySheet(getExecutionEvent(), |
257 |
new PropertyShowInContext(spv, |
258 |
StructuredSelection.EMPTY)); |
259 |
assertNotNull(foundSheet); |
260 |
assertNotSame(sheet, foundSheet); |
261 |
assertTrue(countPropertySheetViews() == 2); |
262 |
} |
263 |
|
264 |
/** |
265 |
* Test method for |
266 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#findPropertySheet(org.eclipse.core.commands.ExecutionEvent, org.eclipse.ui.views.properties.PropertyShowInContext)} |
267 |
* . |
268 |
* |
269 |
* @throws ExecutionException |
270 |
* @throws PartInitException |
271 |
*/ |
272 |
public final void testFindPropertySheetWithUnpinnedPSandSPVActive() |
273 |
throws PartInitException, ExecutionException { |
274 |
PropertySheet sheet = (PropertySheet) activePage |
275 |
.showView(IPageLayout.ID_PROP_SHEET); |
276 |
IViewPart showView = activePage.showView(SelectionProviderView.ID); |
277 |
PropertyShowInContext context = new PropertyShowInContext(showView, |
278 |
StructuredSelection.EMPTY); |
279 |
assertTrue(sheet.show(context)); |
280 |
sheet.setPinned(true); |
281 |
assertTrue(countPropertySheetViews() == 1); |
282 |
|
283 |
PropertySheet foundSheet = testNewPropertySheetHandler |
284 |
.findPropertySheet(getExecutionEvent(), context); |
285 |
assertNotNull(foundSheet); |
286 |
assertEquals(sheet, foundSheet); |
287 |
assertTrue(countPropertySheetViews() == 1); |
288 |
} |
289 |
} |