| /******************************************************************************* |
| * Copyright (c) 2003, 2006 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.ui.tests.navigator; |
| |
| import java.util.HashSet; |
| import java.util.Set; |
| |
| import junit.framework.TestCase; |
| |
| import org.eclipse.core.commands.operations.IUndoableOperation; |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.resources.IWorkspaceRoot; |
| import org.eclipse.core.resources.ResourcesPlugin; |
| import org.eclipse.jface.viewers.StructuredSelection; |
| import org.eclipse.swt.widgets.TreeItem; |
| import org.eclipse.ui.IViewPart; |
| import org.eclipse.ui.IWorkbenchPage; |
| import org.eclipse.ui.IWorkbenchWindow; |
| import org.eclipse.ui.PlatformUI; |
| import org.eclipse.ui.internal.navigator.filters.UpdateActiveFiltersOperation; |
| import org.eclipse.ui.navigator.CommonViewer; |
| import org.eclipse.ui.navigator.INavigatorContentService; |
| import org.eclipse.ui.tests.navigator.util.TestWorkspace; |
| |
| public class ProgrammaticOpenTest extends TestCase { |
| |
| public static final String COMMON_NAVIGATOR_INSTANCE_ID = "org.eclipse.ui.tests.navigator.ProgrammaticTestView"; //$NON-NLS-1$ |
| |
| public static final String COMMON_NAVIGATOR_RESOURCE_EXT = "org.eclipse.ui.navigator.resourceContent"; //$NON-NLS-1$ |
| |
| private Set expectedChildren = new HashSet(); |
| |
| private IProject project; |
| |
| private CommonViewer viewer; |
| |
| private INavigatorContentService contentService; |
| |
| protected void setUp() throws Exception { |
| |
| TestWorkspace.init(); |
| |
| IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); |
| project = root.getProject("Test"); //$NON-NLS-1$ |
| |
| expectedChildren.add(project.getFolder("src")); //$NON-NLS-1$ |
| expectedChildren.add(project.getFolder("bin")); //$NON-NLS-1$ |
| expectedChildren.add(project.getFile(".project")); //$NON-NLS-1$ |
| expectedChildren.add(project.getFile(".classpath")); //$NON-NLS-1$ |
| expectedChildren.add(project.getFile("model.properties")); //$NON-NLS-1$ |
| |
| EditorTestHelper.showView(COMMON_NAVIGATOR_INSTANCE_ID, true); |
| |
| IWorkbenchWindow activeWindow = PlatformUI.getWorkbench() |
| .getActiveWorkbenchWindow(); |
| IWorkbenchPage activePage = activeWindow.getActivePage(); |
| |
| IViewPart commonNavigator = activePage |
| .findView(COMMON_NAVIGATOR_INSTANCE_ID); |
| commonNavigator.setFocus(); |
| viewer = (CommonViewer) commonNavigator.getAdapter(CommonViewer.class); |
| |
| contentService = viewer.getNavigatorContentService(); |
| |
| IUndoableOperation updateFilters = new UpdateActiveFiltersOperation( |
| viewer, new String[0], true); |
| updateFilters.execute(null, null); |
| |
| } |
| |
| public void testNavigatorRootContents() throws Exception { |
| |
| assertEquals( |
| "There should be no visible extensions for the programmatic viewer.", 0, |
| contentService.getVisibleExtensionIds().length); |
| |
| contentService.bindExtensions( |
| new String[] { COMMON_NAVIGATOR_RESOURCE_EXT }, false); |
| |
| assertEquals( |
| "There should be one visible extension for the programmatic viewer.", 1, |
| contentService.getVisibleExtensionIds().length); |
| |
| contentService.getActivationService().activateExtensions( |
| new String[] { COMMON_NAVIGATOR_RESOURCE_EXT }, true); |
| |
| viewer.refresh(); |
| viewer.expandAll(); |
| |
| TreeItem[] items = viewer.getTree().getItems(); |
| |
| assertTrue("There should be some items.", items.length > 0); //$NON-NLS-1$ |
| |
| assertEquals(project, items[0].getData()); |
| |
| // we do this to force the rendering of the children of items[0] |
| viewer |
| .setSelection(new StructuredSelection(project |
| .getFile(".project"))); //$NON-NLS-1$ |
| |
| TreeItem[] children = items[0].getItems(); |
| |
| assertEquals(expectedChildren.size(), children.length); |
| for (int i = 0; i < children.length; i++) { |
| assertTrue(expectedChildren.contains(children[i].getData())); |
| } |
| |
| } |
| |
| public void testNavigatorExtensionEnablement() throws Exception { |
| |
| contentService.getActivationService().activateExtensions( |
| new String[] {}, true); |
| |
| viewer.refresh(); |
| viewer.expandAll(); |
| |
| TreeItem[] items = viewer.getTree().getItems(); |
| |
| assertTrue("There should be NO items.", items.length == 0); //$NON-NLS-1$ |
| |
| contentService.getActivationService().deactivateExtensions( |
| new String[] {}, true); |
| |
| viewer.expandToLevel(2); |
| |
| items = viewer.getTree().getItems(); |
| |
| assertTrue("There should be some items.", items.length > 0); //$NON-NLS-1$ |
| |
| } |
| |
| } |