|
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.PropertyContext; |
| 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#getPropertyContext(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 |
PropertyContext context = testNewPropertySheetHandler |
| 85 |
.getPropertyContext(getExecutionEvent()); |
| 86 |
assertNotNull(context); |
| 87 |
assertNull(context.getSelection()); |
| 88 |
assertNull(context.getPart()); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Test method for |
| 93 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#getPropertyContext(org.eclipse.core.commands.ExecutionEvent)} |
| 94 |
* . |
| 95 |
* |
| 96 |
* @throws ExecutionException |
| 97 |
* @throws PartInitException |
| 98 |
*/ |
| 99 |
public final void testGetShowInContextFromAShowInSource() |
| 100 |
throws ExecutionException, PartInitException { |
| 101 |
IAdapterFactory factory = new IAdapterFactory() { |
| 102 |
public Object getAdapter(Object adaptableObject, Class adapterType) { |
| 103 |
return new IShowInSource() { |
| 104 |
public ShowInContext getShowInContext() { |
| 105 |
return new ShowInContext(StructuredSelection.EMPTY, |
| 106 |
StructuredSelection.EMPTY); |
| 107 |
} |
| 108 |
}; |
| 109 |
} |
| 110 |
|
| 111 |
public Class[] getAdapterList() { |
| 112 |
return new Class[] { IShowInSource.class }; |
| 113 |
} |
| 114 |
}; |
| 115 |
try { |
| 116 |
SelectionProviderView selectionProviderView = (SelectionProviderView) activePage |
| 117 |
.showView(SelectionProviderView.ID); |
| 118 |
selectionProviderView.setSelection(StructuredSelection.EMPTY); |
| 119 |
Platform.getAdapterManager().registerAdapters(factory, |
| 120 |
SelectionProviderView.class); |
| 121 |
|
| 122 |
PropertyContext context = testNewPropertySheetHandler |
| 123 |
.getPropertyContext(getExecutionEvent()); |
| 124 |
assertNotNull(context); |
| 125 |
assertEquals(StructuredSelection.EMPTY, context.getSelection()); |
| 126 |
assertEquals(selectionProviderView, context.getPart()); |
| 127 |
} finally { |
| 128 |
Platform.getAdapterManager().unregisterAdapters(factory); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Test method for |
| 134 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#getPropertyContext(org.eclipse.core.commands.ExecutionEvent)} |
| 135 |
* . |
| 136 |
* |
| 137 |
* @throws ExecutionException |
| 138 |
* @throws PartInitException |
| 139 |
*/ |
| 140 |
public final void testGetShowInContextWithNoShowInSource() |
| 141 |
throws PartInitException, ExecutionException { |
| 142 |
SelectionProviderView selectionProviderView = (SelectionProviderView) activePage |
| 143 |
.showView(SelectionProviderView.ID); |
| 144 |
assertFalse(selectionProviderView instanceof IShowInSource); |
| 145 |
assertNull(selectionProviderView.getAdapter(IShowInSource.class)); |
| 146 |
|
| 147 |
PropertyContext context = testNewPropertySheetHandler |
| 148 |
.getPropertyContext(getExecutionEvent()); |
| 149 |
assertNotNull(context); |
| 150 |
assertNull(context.getSelection()); |
| 151 |
assertEquals(selectionProviderView, context.getPart()); |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* Test method for |
| 156 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#getPropertyContext(org.eclipse.core.commands.ExecutionEvent)} |
| 157 |
* . |
| 158 |
*/ |
| 159 |
public final void testGetShowInContextWithNoActivePart() { |
| 160 |
try { |
| 161 |
testNewPropertySheetHandler.getPropertyContext(getExecutionEvent()); |
| 162 |
} catch (ExecutionException e) { |
| 163 |
return; |
| 164 |
} |
| 165 |
fail("Expected ExecutionException due to no active part"); |
| 166 |
} |
| 167 |
|
| 168 |
/** |
| 169 |
* Test method for |
| 170 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#findPropertySheet(org.eclipse.core.commands.ExecutionEvent, org.eclipse.ui.views.properties.PropertyContext)} |
| 171 |
* . |
| 172 |
* |
| 173 |
* @throws ExecutionException |
| 174 |
* @throws PartInitException |
| 175 |
*/ |
| 176 |
public final void testFindPropertySheetWithoutActivePart() |
| 177 |
throws PartInitException, ExecutionException { |
| 178 |
assertNull(PlatformUI.getWorkbench().getActiveWorkbenchWindow() |
| 179 |
.getActivePage().getActivePart()); |
| 180 |
|
| 181 |
try { |
| 182 |
testNewPropertySheetHandler.findPropertySheet(getExecutionEvent(), |
| 183 |
new PropertyContext(null, StructuredSelection.EMPTY)); |
| 184 |
} catch (ExecutionException e) { |
| 185 |
return; |
| 186 |
} |
| 187 |
fail("Expected ExecutionException due to no active part"); |
| 188 |
} |
| 189 |
|
| 190 |
/** |
| 191 |
* Test method for |
| 192 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#findPropertySheet(org.eclipse.core.commands.ExecutionEvent, org.eclipse.ui.views.properties.PropertyContext)} |
| 193 |
* . |
| 194 |
* |
| 195 |
* @throws ExecutionException |
| 196 |
* @throws PartInitException |
| 197 |
*/ |
| 198 |
public final void testFindPropertySheetWithOtherSheetActive() |
| 199 |
throws PartInitException, ExecutionException { |
| 200 |
propertySheet = (PropertySheet) activePage |
| 201 |
.showView(IPageLayout.ID_PROP_SHEET); |
| 202 |
assertTrue(countPropertySheetViews() == 1); |
| 203 |
|
| 204 |
PropertySheet foundSheet = testNewPropertySheetHandler |
| 205 |
.findPropertySheet(getExecutionEvent(), |
| 206 |
new PropertyContext(propertySheet, |
| 207 |
StructuredSelection.EMPTY)); |
| 208 |
assertNotNull(foundSheet); |
| 209 |
assertNotSame(propertySheet, foundSheet); |
| 210 |
assertTrue(countPropertySheetViews() == 2); |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* Test method for |
| 215 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#findPropertySheet(org.eclipse.core.commands.ExecutionEvent, org.eclipse.ui.views.properties.PropertyContext)} |
| 216 |
* . |
| 217 |
* |
| 218 |
* @throws ExecutionException |
| 219 |
* @throws PartInitException |
| 220 |
*/ |
| 221 |
public final void testFindPropertySheetWithSPVActive() |
| 222 |
throws PartInitException, ExecutionException { |
| 223 |
IViewPart showView = activePage.showView(IPageLayout.ID_PROP_SHEET); |
| 224 |
IViewPart spv = activePage.showView(SelectionProviderView.ID); |
| 225 |
assertTrue(countPropertySheetViews() == 1); |
| 226 |
|
| 227 |
PropertySheet foundSheet = testNewPropertySheetHandler |
| 228 |
.findPropertySheet(getExecutionEvent(), |
| 229 |
new PropertyContext(spv, |
| 230 |
StructuredSelection.EMPTY)); |
| 231 |
assertNotNull(foundSheet); |
| 232 |
assertEquals(showView, foundSheet); |
| 233 |
assertTrue(countPropertySheetViews() == 1); |
| 234 |
} |
| 235 |
|
| 236 |
/** |
| 237 |
* Test method for |
| 238 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#findPropertySheet(org.eclipse.core.commands.ExecutionEvent, org.eclipse.ui.views.properties.PropertyContext)} |
| 239 |
* . |
| 240 |
* |
| 241 |
* @throws ExecutionException |
| 242 |
* @throws PartInitException |
| 243 |
*/ |
| 244 |
public final void testFindPropertySheetWithPinnedPSandSPVActive() |
| 245 |
throws PartInitException, ExecutionException { |
| 246 |
PropertySheet sheet = (PropertySheet) activePage |
| 247 |
.showView(IPageLayout.ID_PROP_SHEET); |
| 248 |
sheet.setPinned(true); |
| 249 |
IViewPart spv = activePage.showView(SelectionProviderView.ID); |
| 250 |
assertTrue(countPropertySheetViews() == 1); |
| 251 |
|
| 252 |
PropertySheet foundSheet = testNewPropertySheetHandler |
| 253 |
.findPropertySheet(getExecutionEvent(), |
| 254 |
new PropertyContext(spv, |
| 255 |
StructuredSelection.EMPTY)); |
| 256 |
assertNotNull(foundSheet); |
| 257 |
assertNotSame(sheet, foundSheet); |
| 258 |
assertTrue(countPropertySheetViews() == 2); |
| 259 |
} |
| 260 |
|
| 261 |
/** |
| 262 |
* Test method for |
| 263 |
* {@link org.eclipse.ui.tests.propertysheet.TestNewPropertySheetHandler#findPropertySheet(org.eclipse.core.commands.ExecutionEvent, org.eclipse.ui.views.properties.PropertyContext)} |
| 264 |
* . |
| 265 |
* |
| 266 |
* @throws ExecutionException |
| 267 |
* @throws PartInitException |
| 268 |
*/ |
| 269 |
public final void testFindPropertySheetWithUnpinnedPSandSPVActive() |
| 270 |
throws PartInitException, ExecutionException { |
| 271 |
PropertySheet sheet = (PropertySheet) activePage |
| 272 |
.showView(IPageLayout.ID_PROP_SHEET); |
| 273 |
IViewPart showView = activePage.showView(SelectionProviderView.ID); |
| 274 |
PropertyContext context = new PropertyContext(showView, |
| 275 |
StructuredSelection.EMPTY); |
| 276 |
assertTrue(sheet.show(context)); |
| 277 |
sheet.setPinned(true); |
| 278 |
assertTrue(countPropertySheetViews() == 1); |
| 279 |
|
| 280 |
PropertySheet foundSheet = testNewPropertySheetHandler |
| 281 |
.findPropertySheet(getExecutionEvent(), context); |
| 282 |
assertNotNull(foundSheet); |
| 283 |
assertEquals(sheet, foundSheet); |
| 284 |
assertTrue(countPropertySheetViews() == 1); |
| 285 |
} |
| 286 |
} |