|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2011 IBM Corporation 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 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.ui.tests.multipageeditor; |
| 12 |
|
| 13 |
import java.io.ByteArrayInputStream; |
| 14 |
|
| 15 |
import org.eclipse.core.resources.IFile; |
| 16 |
import org.eclipse.core.resources.IProject; |
| 17 |
import org.eclipse.core.resources.IWorkspace; |
| 18 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 19 |
import org.eclipse.core.runtime.CoreException; |
| 20 |
import org.eclipse.jface.viewers.IPostSelectionProvider; |
| 21 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
| 22 |
import org.eclipse.jface.viewers.ISelectionProvider; |
| 23 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
| 24 |
import org.eclipse.swt.widgets.Tree; |
| 25 |
import org.eclipse.ui.IEditorPart; |
| 26 |
import org.eclipse.ui.IPageLayout; |
| 27 |
import org.eclipse.ui.IWorkbenchPage; |
| 28 |
import org.eclipse.ui.IWorkbenchWindow; |
| 29 |
import org.eclipse.ui.PartInitException; |
| 30 |
import org.eclipse.ui.ide.IDE; |
| 31 |
import org.eclipse.ui.tests.harness.util.UITestCase; |
| 32 |
import org.eclipse.ui.views.properties.PropertySheet; |
| 33 |
|
| 34 |
public class MultiPageEditorSelectionTest extends UITestCase { |
| 35 |
|
| 36 |
private static final String MTEST01_FILE = "mtest01.multivar"; |
| 37 |
|
| 38 |
private static final String PROJECT_NAME = "MultiPageEditorSelction"; |
| 39 |
|
| 40 |
public MultiPageEditorSelectionTest(String testName) { |
| 41 |
super(testName); |
| 42 |
} |
| 43 |
|
| 44 |
protected void doTearDown() throws Exception { |
| 45 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
| 46 |
IProject testProject = workspace.getRoot().getProject(PROJECT_NAME); |
| 47 |
if (testProject.exists()) { |
| 48 |
testProject.delete(true, true, null); |
| 49 |
} |
| 50 |
super.doTearDown(); |
| 51 |
} |
| 52 |
|
| 53 |
public void testPostSelection() throws Exception { |
| 54 |
IWorkbenchWindow window = openTestWindow(); |
| 55 |
IEditorPart part = openEditor(window, MTEST01_FILE); |
| 56 |
ISelectionProvider provider = part.getSite().getSelectionProvider(); |
| 57 |
assertTrue(provider instanceof IPostSelectionProvider); |
| 58 |
|
| 59 |
final boolean[] called = { false }; |
| 60 |
IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider) provider; |
| 61 |
postSelectionProvider |
| 62 |
.addPostSelectionChangedListener(new ISelectionChangedListener() { |
| 63 |
public void selectionChanged(SelectionChangedEvent event) { |
| 64 |
called[0] = true; |
| 65 |
} |
| 66 |
}); |
| 67 |
|
| 68 |
((MultiPageResourceEditor) part).updateSelection(); |
| 69 |
assertTrue(called[0]); |
| 70 |
} |
| 71 |
|
| 72 |
public void testPropertiesView() throws Exception { |
| 73 |
IWorkbenchWindow window = openTestWindow(); |
| 74 |
IEditorPart part = openEditor(window, MTEST01_FILE); |
| 75 |
|
| 76 |
PropertySheet propertiewView = (PropertySheet) window.getActivePage() |
| 77 |
.showView(IPageLayout.ID_PROP_SHEET); |
| 78 |
|
| 79 |
window.getActivePage().activate(part); |
| 80 |
|
| 81 |
Tree tree = (Tree) propertiewView.getCurrentPage().getControl(); |
| 82 |
assertEquals(0, tree.getItemCount()); |
| 83 |
|
| 84 |
MultiPageResourceEditor editor = (MultiPageResourceEditor) part; |
| 85 |
editor.updateSelection(); |
| 86 |
assertFalse(tree.getItemCount() == 0); |
| 87 |
} |
| 88 |
|
| 89 |
private IEditorPart openEditor(IWorkbenchWindow window, String filename) |
| 90 |
throws CoreException, PartInitException { |
| 91 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
| 92 |
|
| 93 |
IProject testProject = workspace.getRoot().getProject(PROJECT_NAME); |
| 94 |
if (!testProject.exists()) { |
| 95 |
testProject.create(null); |
| 96 |
} |
| 97 |
testProject.open(null); |
| 98 |
|
| 99 |
IFile multiFile = testProject.getFile(filename); |
| 100 |
if (!multiFile.exists()) { |
| 101 |
multiFile.create(new ByteArrayInputStream("".getBytes()), true, |
| 102 |
null); |
| 103 |
} |
| 104 |
|
| 105 |
IWorkbenchPage page = window.getActivePage(); |
| 106 |
IEditorPart part = IDE.openEditor(page, multiFile, |
| 107 |
MultiPageResourceEditor.EDITOR_ID); |
| 108 |
assertTrue(part instanceof MultiPageResourceEditor); |
| 109 |
return part; |
| 110 |
} |
| 111 |
} |