|
Link Here
|
| 14 |
import java.lang.reflect.Field; |
14 |
import java.lang.reflect.Field; |
| 15 |
|
15 |
|
| 16 |
import org.eclipse.jface.action.Action; |
16 |
import org.eclipse.jface.action.Action; |
|
|
17 |
import org.eclipse.jface.action.GroupMarker; |
| 17 |
import org.eclipse.jface.action.IContributionItem; |
18 |
import org.eclipse.jface.action.IContributionItem; |
| 18 |
import org.eclipse.jface.action.MenuManager; |
19 |
import org.eclipse.jface.action.MenuManager; |
| 19 |
import org.eclipse.jface.action.ToolBarManager; |
20 |
import org.eclipse.jface.action.ToolBarManager; |
| 20 |
import org.eclipse.jface.resource.ImageDescriptor; |
21 |
import org.eclipse.jface.resource.ImageDescriptor; |
| 21 |
import org.eclipse.ui.IPageLayout; |
22 |
import org.eclipse.ui.IPageLayout; |
| 22 |
import org.eclipse.ui.IViewPart; |
23 |
import org.eclipse.ui.IViewPart; |
|
|
24 |
import org.eclipse.ui.IWorkbenchCommandConstants; |
| 23 |
import org.eclipse.ui.menus.AbstractContributionFactory; |
25 |
import org.eclipse.ui.menus.AbstractContributionFactory; |
| 24 |
import org.eclipse.ui.menus.CommandContributionItem; |
26 |
import org.eclipse.ui.menus.CommandContributionItem; |
|
|
27 |
import org.eclipse.ui.menus.CommandContributionItemParameter; |
| 25 |
import org.eclipse.ui.menus.IContributionRoot; |
28 |
import org.eclipse.ui.menus.IContributionRoot; |
| 26 |
import org.eclipse.ui.menus.IMenuService; |
29 |
import org.eclipse.ui.menus.IMenuService; |
| 27 |
import org.eclipse.ui.services.IServiceLocator; |
30 |
import org.eclipse.ui.services.IServiceLocator; |
|
Link Here
|
| 41 |
public static final String ID_DEFAULT = "org.eclipse.ui.tests.menus.iconsDefault"; |
44 |
public static final String ID_DEFAULT = "org.eclipse.ui.tests.menus.iconsDefault"; |
| 42 |
public static final String ID_ALL = "org.eclipse.ui.tests.menus.iconsAll"; |
45 |
public static final String ID_ALL = "org.eclipse.ui.tests.menus.iconsAll"; |
| 43 |
public static final String ID_TOOLBAR = "org.eclipse.ui.tests.menus.iconsToolbarOnly"; |
46 |
public static final String ID_TOOLBAR = "org.eclipse.ui.tests.menus.iconsToolbarOnly"; |
|
|
47 |
private AbstractContributionFactory afterOne; |
| 48 |
private AbstractContributionFactory beforeOne; |
| 49 |
private AbstractContributionFactory endofOne; |
| 50 |
private CommandContributionItem usefulContribution; |
| 44 |
|
51 |
|
| 45 |
/** |
52 |
/** |
| 46 |
* @param testName |
53 |
* @param testName |
|
Link Here
|
| 161 |
|
168 |
|
| 162 |
public void testFactoryScopePopulation() throws Exception { |
169 |
public void testFactoryScopePopulation() throws Exception { |
| 163 |
AbstractContributionFactory factory = new AbstractContributionFactory( |
170 |
AbstractContributionFactory factory = new AbstractContributionFactory( |
| 164 |
"menu:the.population.menu?after=additions", "org.eclipse.ui.tests") { |
171 |
"menu:the.population.menu?after=additions", |
|
|
172 |
"org.eclipse.ui.tests") { |
| 165 |
|
173 |
|
| 166 |
public void createContributionItems(IServiceLocator serviceLocator, |
174 |
public void createContributionItems(IServiceLocator serviceLocator, |
| 167 |
IContributionRoot additions) { |
175 |
IContributionRoot additions) { |
|
Link Here
|
| 178 |
assertNotNull(view); |
186 |
assertNotNull(view); |
| 179 |
IMenuService service = (IMenuService) view.getSite().getService( |
187 |
IMenuService service = (IMenuService) view.getSite().getService( |
| 180 |
IMenuService.class); |
188 |
IMenuService.class); |
| 181 |
service.populateContributionManager(testManager, "menu:the.population.menu"); |
189 |
service.populateContributionManager(testManager, |
|
|
190 |
"menu:the.population.menu"); |
| 182 |
assertEquals(0, testManager.getSize()); |
191 |
assertEquals(0, testManager.getSize()); |
| 183 |
service.addContributionFactory(factory); |
192 |
service.addContributionFactory(factory); |
| 184 |
assertEquals(1, testManager.getSize()); |
193 |
assertEquals(1, testManager.getSize()); |
|
Link Here
|
| 186 |
processEvents(); |
195 |
processEvents(); |
| 187 |
assertEquals(0, testManager.getSize()); |
196 |
assertEquals(0, testManager.getSize()); |
| 188 |
} |
197 |
} |
|
|
198 |
|
| 199 |
public void testAfterQueryInvalid() throws Exception { |
| 200 |
MenuManager manager = new MenuManager(); |
| 201 |
menuService.populateContributionManager(manager, "menu:after.menu"); |
| 202 |
assertEquals(0, manager.getSize()); |
| 203 |
} |
| 204 |
|
| 205 |
public void testAfterQueryOneGroup() throws Exception { |
| 206 |
MenuManager manager = new MenuManager(); |
| 207 |
manager.add(new GroupMarker("after.one")); |
| 208 |
assertEquals(1, manager.getSize()); |
| 209 |
menuService.populateContributionManager(manager, "menu:after.menu"); |
| 210 |
assertEquals(2, manager.getSize()); |
| 211 |
assertEquals("after.insert", manager.getItems()[1].getId()); |
| 212 |
} |
| 213 |
|
| 214 |
public void testAfterQueryTwoGroups() throws Exception { |
| 215 |
MenuManager manager = new MenuManager(); |
| 216 |
manager.add(new GroupMarker("after.one")); |
| 217 |
manager.add(new GroupMarker("after.two")); |
| 218 |
assertEquals(2, manager.getSize()); |
| 219 |
menuService.populateContributionManager(manager, "menu:after.menu"); |
| 220 |
assertEquals(3, manager.getSize()); |
| 221 |
assertEquals("after.insert", manager.getItems()[1].getId()); |
| 222 |
} |
| 223 |
|
| 224 |
public void testBeforeQueryInvalid() throws Exception { |
| 225 |
MenuManager manager = new MenuManager(); |
| 226 |
menuService.populateContributionManager(manager, "menu:before.menu"); |
| 227 |
assertEquals(0, manager.getSize()); |
| 228 |
} |
| 229 |
|
| 230 |
public void testBeforeQueryOneGroup() throws Exception { |
| 231 |
MenuManager manager = new MenuManager(); |
| 232 |
manager.add(new GroupMarker("before.one")); |
| 233 |
assertEquals(1, manager.getSize()); |
| 234 |
menuService.populateContributionManager(manager, "menu:before.menu"); |
| 235 |
assertEquals(2, manager.getSize()); |
| 236 |
assertEquals("before.insert", manager.getItems()[0].getId()); |
| 237 |
} |
| 238 |
|
| 239 |
public void testBeforeQueryTwoGroups() throws Exception { |
| 240 |
MenuManager manager = new MenuManager(); |
| 241 |
manager.add(new GroupMarker("before.one")); |
| 242 |
manager.add(new GroupMarker("before.two")); |
| 243 |
assertEquals(2, manager.getSize()); |
| 244 |
menuService.populateContributionManager(manager, "menu:before.menu"); |
| 245 |
assertEquals(3, manager.getSize()); |
| 246 |
assertEquals("before.insert", manager.getItems()[0].getId()); |
| 247 |
} |
| 248 |
|
| 249 |
public void testBeforeQueryTwoGroups2() throws Exception { |
| 250 |
MenuManager manager = new MenuManager(); |
| 251 |
manager.add(new GroupMarker("before.two")); |
| 252 |
manager.add(new GroupMarker("before.one")); |
| 253 |
assertEquals(2, manager.getSize()); |
| 254 |
menuService.populateContributionManager(manager, "menu:before.menu"); |
| 255 |
assertEquals(3, manager.getSize()); |
| 256 |
assertEquals("before.insert", manager.getItems()[1].getId()); |
| 257 |
} |
| 258 |
|
| 259 |
public void testEndofQueryInvalid() throws Exception { |
| 260 |
MenuManager manager = new MenuManager(); |
| 261 |
menuService.populateContributionManager(manager, "menu:endof.menu"); |
| 262 |
assertEquals(0, manager.getSize()); |
| 263 |
} |
| 264 |
|
| 265 |
public void testEndofQueryOneGroup() throws Exception { |
| 266 |
MenuManager manager = new MenuManager(); |
| 267 |
manager.add(new GroupMarker("endof.one")); |
| 268 |
assertEquals(1, manager.getSize()); |
| 269 |
menuService.populateContributionManager(manager, "menu:endof.menu"); |
| 270 |
assertEquals(2, manager.getSize()); |
| 271 |
assertEquals("endof.insert", manager.getItems()[1].getId()); |
| 272 |
} |
| 273 |
|
| 274 |
public void testEndofQueryTwoGroups() throws Exception { |
| 275 |
MenuManager manager = new MenuManager(); |
| 276 |
manager.add(new GroupMarker("endof.one")); |
| 277 |
manager.add(new GroupMarker("endof.two")); |
| 278 |
assertEquals(2, manager.getSize()); |
| 279 |
menuService.populateContributionManager(manager, "menu:endof.menu"); |
| 280 |
assertEquals(3, manager.getSize()); |
| 281 |
assertEquals("endof.insert", manager.getItems()[1].getId()); |
| 282 |
} |
| 283 |
|
| 284 |
public void testEndofQueryTwoGroups2() throws Exception { |
| 285 |
MenuManager manager = new MenuManager(); |
| 286 |
manager.add(new GroupMarker("endof.one")); |
| 287 |
manager.add(usefulContribution); |
| 288 |
manager.add(new GroupMarker("endof.two")); |
| 289 |
assertEquals(3, manager.getSize()); |
| 290 |
menuService.populateContributionManager(manager, "menu:endof.menu"); |
| 291 |
assertEquals(4, manager.getSize()); |
| 292 |
assertEquals("endof.insert", manager.getItems()[2].getId()); |
| 293 |
} |
| 294 |
|
| 295 |
public void testEndofQueryTwoGroups3() throws Exception { |
| 296 |
MenuManager manager = new MenuManager(); |
| 297 |
manager.add(new GroupMarker("endof.two")); |
| 298 |
manager.add(new GroupMarker("endof.one")); |
| 299 |
assertEquals(2, manager.getSize()); |
| 300 |
menuService.populateContributionManager(manager, "menu:endof.menu"); |
| 301 |
assertEquals(3, manager.getSize()); |
| 302 |
assertEquals("endof.insert", manager.getItems()[2].getId()); |
| 303 |
} |
| 304 |
|
| 305 |
public void testEndofQueryTwoGroups4() throws Exception { |
| 306 |
MenuManager manager = new MenuManager(); |
| 307 |
manager.add(new GroupMarker("endof.two")); |
| 308 |
manager.add(new GroupMarker("endof.one")); |
| 309 |
manager.add(usefulContribution); |
| 310 |
assertEquals(3, manager.getSize()); |
| 311 |
menuService.populateContributionManager(manager, "menu:endof.menu"); |
| 312 |
assertEquals(4, manager.getSize()); |
| 313 |
assertEquals("endof.insert", manager.getItems()[3].getId()); |
| 314 |
} |
| 315 |
|
| 316 |
/* |
| 317 |
* (non-Javadoc) |
| 318 |
* |
| 319 |
* @see org.eclipse.ui.tests.menus.MenuTestCase#doSetUp() |
| 320 |
*/ |
| 321 |
protected void doSetUp() throws Exception { |
| 322 |
super.doSetUp(); |
| 323 |
afterOne = new AbstractContributionFactory( |
| 324 |
"menu:after.menu?after=after.one", "org.eclipse.ui.tests") { |
| 325 |
public void createContributionItems(IServiceLocator serviceLocator, |
| 326 |
IContributionRoot additions) { |
| 327 |
additions.addContributionItem(new GroupMarker("after.insert"), |
| 328 |
null); |
| 329 |
} |
| 330 |
}; |
| 331 |
menuService.addContributionFactory(afterOne); |
| 332 |
|
| 333 |
beforeOne = new AbstractContributionFactory( |
| 334 |
"menu:before.menu?before=before.one", "org.eclipse.ui.tests") { |
| 335 |
public void createContributionItems(IServiceLocator serviceLocator, |
| 336 |
IContributionRoot additions) { |
| 337 |
additions.addContributionItem(new GroupMarker("before.insert"), |
| 338 |
null); |
| 339 |
} |
| 340 |
}; |
| 341 |
menuService.addContributionFactory(beforeOne); |
| 342 |
|
| 343 |
endofOne = new AbstractContributionFactory( |
| 344 |
"menu:endof.menu?endof=endof.one", "org.eclipse.ui.tests") { |
| 345 |
public void createContributionItems(IServiceLocator serviceLocator, |
| 346 |
IContributionRoot additions) { |
| 347 |
additions.addContributionItem(new GroupMarker("endof.insert"), |
| 348 |
null); |
| 349 |
} |
| 350 |
}; |
| 351 |
menuService.addContributionFactory(endofOne); |
| 352 |
usefulContribution = new CommandContributionItem( |
| 353 |
new CommandContributionItemParameter(window, null, |
| 354 |
IWorkbenchCommandConstants.HELP_ABOUT, 0)); |
| 355 |
} |
| 356 |
|
| 357 |
/* |
| 358 |
* (non-Javadoc) |
| 359 |
* |
| 360 |
* @see org.eclipse.ui.tests.menus.MenuTestCase#doTearDown() |
| 361 |
*/ |
| 362 |
protected void doTearDown() throws Exception { |
| 363 |
menuService.removeContributionFactory(afterOne); |
| 364 |
menuService.removeContributionFactory(beforeOne); |
| 365 |
menuService.removeContributionFactory(endofOne); |
| 366 |
usefulContribution.dispose(); |
| 367 |
usefulContribution = null; |
| 368 |
super.doTearDown(); |
| 369 |
} |
| 189 |
} |
370 |
} |