001: /*******************************************************************************
002: * Copyright (c) 2003, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.tests.navigator;
011:
012: import java.util.HashSet;
013: import java.util.Set;
014:
015: import junit.framework.TestCase;
016:
017: import org.eclipse.core.commands.operations.IUndoableOperation;
018: import org.eclipse.core.resources.IProject;
019: import org.eclipse.core.resources.IWorkspaceRoot;
020: import org.eclipse.core.resources.ResourcesPlugin;
021: import org.eclipse.jface.viewers.StructuredSelection;
022: import org.eclipse.swt.widgets.TreeItem;
023: import org.eclipse.ui.IViewPart;
024: import org.eclipse.ui.IWorkbenchPage;
025: import org.eclipse.ui.IWorkbenchWindow;
026: import org.eclipse.ui.PlatformUI;
027: import org.eclipse.ui.internal.navigator.filters.UpdateActiveFiltersOperation;
028: import org.eclipse.ui.navigator.CommonViewer;
029: import org.eclipse.ui.navigator.INavigatorContentService;
030: import org.eclipse.ui.tests.navigator.util.TestWorkspace;
031:
032: public class OpenTest extends TestCase {
033:
034: public static final String COMMON_NAVIGATOR_INSTANCE_ID = "org.eclipse.ui.navigator.ProjectExplorer"; //$NON-NLS-1$
035: public static final String COMMON_NAVIGATOR_RESOURCE_EXT = "org.eclipse.ui.navigator.resourceContent"; //$NON-NLS-1$
036:
037: private Set expectedChildren = new HashSet();
038:
039: private IProject project;
040:
041: private CommonViewer viewer;
042:
043: private INavigatorContentService contentService;
044:
045: protected void setUp() throws Exception {
046:
047: TestWorkspace.init();
048:
049: IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
050: project = root.getProject("Test"); //$NON-NLS-1$
051:
052: expectedChildren.add(project.getFolder("src")); //$NON-NLS-1$
053: expectedChildren.add(project.getFolder("bin")); //$NON-NLS-1$
054: expectedChildren.add(project.getFile(".project")); //$NON-NLS-1$
055: expectedChildren.add(project.getFile(".classpath")); //$NON-NLS-1$
056: expectedChildren.add(project.getFile("model.properties")); //$NON-NLS-1$
057:
058: EditorTestHelper.showView(COMMON_NAVIGATOR_INSTANCE_ID, true);
059:
060: IWorkbenchWindow activeWindow = PlatformUI.getWorkbench()
061: .getActiveWorkbenchWindow();
062: IWorkbenchPage activePage = activeWindow.getActivePage();
063:
064: IViewPart commonNavigator = activePage
065: .findView(COMMON_NAVIGATOR_INSTANCE_ID);
066: commonNavigator.setFocus();
067: viewer = (CommonViewer) commonNavigator
068: .getAdapter(CommonViewer.class);
069:
070: contentService = viewer.getNavigatorContentService();
071:
072: IUndoableOperation updateFilters = new UpdateActiveFiltersOperation(
073: viewer, new String[0], true);
074: updateFilters.execute(null, null);
075:
076: }
077:
078: public void testNavigatorRootContents() throws Exception {
079:
080: contentService.getActivationService().activateExtensions(
081: new String[] { COMMON_NAVIGATOR_RESOURCE_EXT }, true);
082:
083: viewer.refresh();
084: viewer.expandAll();
085:
086: TreeItem[] items = viewer.getTree().getItems();
087:
088: assertTrue("There should be some items.", items.length > 0); //$NON-NLS-1$
089:
090: assertEquals(project, items[0].getData());
091:
092: // we do this to force the rendering of the children of items[0]
093: viewer.setSelection(new StructuredSelection(project
094: .getFile(".project"))); //$NON-NLS-1$
095:
096: TreeItem[] children = items[0].getItems();
097:
098: assertEquals(expectedChildren.size(), children.length);
099: for (int i = 0; i < children.length; i++) {
100: assertTrue(expectedChildren.contains(children[i].getData()));
101: }
102:
103: }
104:
105: public void testNavigatorExtensionEnablement() throws Exception {
106:
107: contentService.getActivationService().activateExtensions(
108: new String[] {}, true);
109:
110: viewer.refresh();
111: viewer.expandAll();
112:
113: TreeItem[] items = viewer.getTree().getItems();
114:
115: assertTrue("There should be NO items.", items.length == 0); //$NON-NLS-1$
116:
117: contentService.getActivationService().deactivateExtensions(
118: new String[] {}, true);
119:
120: viewer.expandToLevel(2);
121:
122: items = viewer.getTree().getItems();
123:
124: assertTrue("There should be some items.", items.length > 0); //$NON-NLS-1$
125:
126: }
127:
128: }
|