blob: 06bcde084e98cbce81657074a794eb9a329d3afb [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2003, 2008 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.Iterator;
import java.util.Map;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.navigator.INavigatorContentDescriptor;
import org.eclipse.ui.navigator.INavigatorSorterService;
import org.eclipse.ui.tests.navigator.extension.TestDataSorter;
public class ProgrammaticOpenTest extends NavigatorTestBase {
public ProgrammaticOpenTest() {
_navigatorInstanceId = "org.eclipse.ui.tests.navigator.ProgrammaticTestView"; //$NON-NLS-1$
}
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 {
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);
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$
}
public void testNavigatorSorterAccess() throws Exception {
INavigatorSorterService sorterService = contentService.getSorterService();
INavigatorContentDescriptor testDescriptor = contentService.getContentDescriptorById(COMMON_NAVIGATOR_TEST_EXT);
Map sorters = sorterService.findAvailableSorters(testDescriptor);
assertEquals(3, sorters.size());
for (Iterator iter = sorters.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
assertTrue(entry.getValue() instanceof TestDataSorter);
}
}
}