Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 317102 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse (+217 lines)
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.multieditor;
12
13
import java.io.IOException;
14
import java.net.URL;
15
import java.util.ArrayList;
16
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.IWorkspace;
20
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.FileLocator;
23
import org.eclipse.core.runtime.ILog;
24
import org.eclipse.core.runtime.ILogListener;
25
import org.eclipse.core.runtime.IStatus;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.widgets.Event;
28
import org.eclipse.ui.IEditorInput;
29
import org.eclipse.ui.IEditorPart;
30
import org.eclipse.ui.IEditorRegistry;
31
import org.eclipse.ui.IPageLayout;
32
import org.eclipse.ui.IViewPart;
33
import org.eclipse.ui.IWorkbenchPage;
34
import org.eclipse.ui.IWorkbenchPart;
35
import org.eclipse.ui.IWorkbenchWindow;
36
import org.eclipse.ui.internal.PartSite;
37
import org.eclipse.ui.internal.WorkbenchPage;
38
import org.eclipse.ui.internal.WorkbenchPlugin;
39
import org.eclipse.ui.part.FileEditorInput;
40
import org.eclipse.ui.part.MultiEditorInput;
41
import org.eclipse.ui.tests.TestPlugin;
42
import org.eclipse.ui.tests.harness.util.UITestCase;
43
44
public class AbstractMultiEditorTest extends UITestCase {
45
46
	private static final String PROJECT_NAME = "TiledEditorProject";
47
48
	private static final String TILED_EDITOR_ID = "org.eclipse.ui.tests.multieditor.ConcreteAbstractMultiEditor";
49
50
	// tiled editor test files
51
	private static final String DATA_FILES_DIR = "/data/org.eclipse.newMultiEditor/";
52
53
	private static final String TEST01_TXT = "test01.txt";
54
55
	private static final String TEST03_ETEST = "test03.etest";
56
57
	private EditorErrorListener fErrorListener;
58
59
	public AbstractMultiEditorTest(String tc) {
60
		super(tc);
61
	}
62
63
	public void testBug317102() throws Throwable {
64
		final String[] simpleFiles = { TEST01_TXT, TEST03_ETEST };
65
66
		IWorkbenchWindow window = openTestWindow();
67
		WorkbenchPage page = (WorkbenchPage) window.getActivePage();
68
69
		IProject testProject = findOrCreateProject(PROJECT_NAME);
70
71
		MultiEditorInput input = generateEditorInput(simpleFiles, testProject);
72
73
		IEditorPart editor = page.openEditor(input,
74
				AbstractMultiEditorTest.TILED_EDITOR_ID);
75
76
		// did we get a multieditor back?
77
		assertTrue(editor instanceof ConcreteAbstractMultiEditor);
78
		ConcreteAbstractMultiEditor multiEditor = (ConcreteAbstractMultiEditor) editor;
79
80
		IEditorPart[] innerEditors = multiEditor.getInnerEditors();
81
		IEditorPart activeEditor = multiEditor.getActiveEditor();
82
		assertEquals(activeEditor, innerEditors[0]);
83
		multiEditor.activateEditor(innerEditors[1]);
84
85
		// activate another view
86
		IViewPart view = page.showView(IPageLayout.ID_PROBLEM_VIEW);
87
		assertEquals(view, page.getActivePart());
88
89
		fakeActivation(innerEditors[0]);
90
	}
91
92
	private void fakeActivation(IWorkbenchPart part) {
93
		try {
94
			setupErrorListener();
95
			Event event = new Event();
96
			event.type = SWT.Activate;
97
			((PartSite) part.getSite()).getPane().handleEvent(event);
98
99
			assertTrue("Nothing should have been logged",
100
					fErrorListener.messages.isEmpty());
101
		} finally {
102
			removeErrorListener();
103
		}
104
	}
105
106
	/**
107
	 * Set up to catch any editor initialization exceptions.
108
	 * 
109
	 */
110
	private void setupErrorListener() {
111
		final ILog log = WorkbenchPlugin.getDefault().getLog();
112
		fErrorListener = new EditorErrorListener();
113
		log.addLogListener(fErrorListener);
114
	}
115
116
	/**
117
	 * Remove the editor error listener.
118
	 */
119
	private void removeErrorListener() {
120
		final ILog log = WorkbenchPlugin.getDefault().getLog();
121
		if (fErrorListener != null) {
122
			log.removeLogListener(fErrorListener);
123
			fErrorListener = null;
124
		}
125
	}
126
127
	/**
128
	 * Create the multi editor input in the given project. Creates the files in
129
	 * the project from template files in the classpath if they don't already
130
	 * exist.
131
	 * 
132
	 * @param simpleFiles
133
	 *            the array of filenames to copy over
134
	 * @param testProject
135
	 *            the project to create the files in
136
	 * @return the editor input used to open the multieditor
137
	 * @throws CoreException
138
	 * @throws IOException
139
	 */
140
	private MultiEditorInput generateEditorInput(String[] simpleFiles,
141
			IProject testProject) throws CoreException, IOException {
142
		String[] ids = new String[simpleFiles.length];
143
		IEditorInput[] inputs = new IEditorInput[simpleFiles.length];
144
		IEditorRegistry registry = fWorkbench.getEditorRegistry();
145
146
		for (int f = 0; f < simpleFiles.length; ++f) {
147
			IFile f1 = createFile(testProject, simpleFiles[f]);
148
			ids[f] = registry.getDefaultEditor(f1.getName()).getId();
149
			inputs[f] = new FileEditorInput(f1);
150
		}
151
152
		MultiEditorInput input = new MultiEditorInput(ids, inputs);
153
		return input;
154
	}
155
156
	/**
157
	 * Create the project to work in. If it already exists, just open it.
158
	 * 
159
	 * @param projectName
160
	 *            the name of the project to create
161
	 * @return the newly opened project
162
	 * @throws CoreException
163
	 */
164
	private static IProject findOrCreateProject(String projectName)
165
			throws CoreException {
166
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
167
		IProject testProject = workspace.getRoot().getProject(projectName);
168
		if (!testProject.exists()) {
169
			testProject.create(null);
170
		}
171
		testProject.open(null);
172
		return testProject;
173
	}
174
175
	private static IFile createFile(IProject testProject, String simpleFile)
176
			throws CoreException, IOException {
177
		IFile file = testProject.getFile(simpleFile);
178
		if (!file.exists()) {
179
			URL url = FileLocator.toFileURL(TestPlugin.getDefault().getBundle()
180
					.getEntry(DATA_FILES_DIR + simpleFile));
181
			file.create(url.openStream(), true, null);
182
		}
183
		return file;
184
	}
185
186
	/**
187
	 * Close any editors at the beginner of a test, so the test can be clean.
188
	 */
189
	protected void doSetUp() throws Exception {
190
		super.doSetUp();
191
		IWorkbenchPage page = fWorkbench.getActiveWorkbenchWindow()
192
				.getActivePage();
193
		page.closeAllEditors(false);
194
	}
195
196
	/**
197
	 * Listens for the standard message that indicates the MultiEditor failed
198
	 * ... usually caused by incorrect framework initialization that doesn't set
199
	 * the innerChildren.
200
	 * 
201
	 * @since 3.1
202
	 * 
203
	 */
204
	public static class EditorErrorListener implements ILogListener {
205
206
		public ArrayList messages = new ArrayList();
207
208
		public void logging(IStatus status, String plugin) {
209
			String msg = status.getMessage();
210
			Throwable ex = status.getException();
211
			if (ex != null) {
212
				msg += ": " + ex.getMessage();
213
			}
214
			messages.add(msg);
215
		}
216
	}
217
}
(-)Eclipse (+48 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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.multieditor;
12
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.custom.SashForm;
15
import org.eclipse.swt.layout.FillLayout;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.ui.IEditorReference;
18
import org.eclipse.ui.part.AbstractMultiEditor;
19
20
public class ConcreteAbstractMultiEditor extends AbstractMultiEditor {
21
22
	private Composite left;
23
	private Composite right;
24
25
	private IEditorReference leftReference;
26
27
	protected void innerEditorsCreated() {
28
		// no-op
29
	}
30
31
	public Composite getInnerEditorContainer(
32
			IEditorReference innerEditorReference) {
33
		if (leftReference == null) {
34
			leftReference = innerEditorReference;
35
			return left;
36
		}
37
		return right;
38
	}
39
40
	public void createPartControl(Composite parent) {
41
		SashForm form = new SashForm(parent, SWT.HORIZONTAL);
42
		left = new Composite(form, SWT.NONE);
43
		left.setLayout(new FillLayout());
44
		right = new Composite(form, SWT.NONE);
45
		right.setLayout(new FillLayout());
46
		form.setWeights(new int[] { 50, 50 });
47
	}
48
}
(-)Eclipse UI Tests/org/eclipse/ui/tests/multieditor/MultiEditorTestSuite.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 22-27 Link Here
22
     * Construct the test suite.
22
     * Construct the test suite.
23
     */
23
     */
24
    public MultiEditorTestSuite() {
24
    public MultiEditorTestSuite() {
25
        addTestSuite(AbstractMultiEditorTest.class);
25
        addTestSuite(MultiEditorTest.class);
26
        addTestSuite(MultiEditorTest.class);
26
    }
27
    }
27
}
28
}
(-)plugin.xml (+6 lines)
Lines 687-692 Link Here
687
            id="org.eclipse.ui.tests.multieditor.TiledEditor"
687
            id="org.eclipse.ui.tests.multieditor.TiledEditor"
688
            name="%Editors.TiledEditor"/>
688
            name="%Editors.TiledEditor"/>
689
      <editor
689
      <editor
690
            class="org.eclipse.ui.tests.multieditor.ConcreteAbstractMultiEditor"
691
            default="false"
692
            icon="icons/binary_co.gif"
693
            id="org.eclipse.ui.tests.multieditor.ConcreteAbstractMultiEditor"
694
            name="%Editors.TiledEditor"/>
695
      <editor
690
            class="org.eclipse.ui.tests.multieditor.TestEditor"
696
            class="org.eclipse.ui.tests.multieditor.TestEditor"
691
            contributorClass="org.eclipse.ui.tests.multieditor.TestActionBarContributor"
697
            contributorClass="org.eclipse.ui.tests.multieditor.TestActionBarContributor"
692
            default="false"
698
            default="false"
(-)Eclipse UI/org/eclipse/ui/internal/EditorManager.java (-2 / +14 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 1437-1443 Link Here
1437
		return (IPathEditorInput) Util.getAdapter(input, IPathEditorInput.class);
1437
		return (IPathEditorInput) Util.getAdapter(input, IPathEditorInput.class);
1438
	}
1438
	}
1439
1439
1440
	private class InnerEditor extends EditorReference {
1440
	/**
1441
	 * An editor reference that is actually contained within another editor
1442
	 * reference.
1443
	 */
1444
	class InnerEditor extends EditorReference {
1441
1445
1442
		private IEditorReference outerEditor;
1446
		private IEditorReference outerEditor;
1443
1447
Lines 1451-1456 Link Here
1451
			this.outerEditorPart = outerEditorPart;
1455
			this.outerEditorPart = outerEditorPart;
1452
		}
1456
		}
1453
1457
1458
		/**
1459
		 * @return Returns the parent editor reference that this reference is a
1460
		 *         child of.
1461
		 */
1462
		public IEditorReference getOuterEditor() {
1463
			return outerEditor;
1464
		}
1465
1454
		protected void doDisposePart() {
1466
		protected void doDisposePart() {
1455
			this.outerEditorPart = null;
1467
			this.outerEditorPart = null;
1456
			super.doDisposePart();
1468
			super.doDisposePart();
(-)Eclipse UI/org/eclipse/ui/internal/EditorReference.java (-1 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2010 IBM Corporation and others.
2
 * Copyright (c) 2006, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 746-756 Link Here
746
     * 
746
     * 
747
     * @return true if it has inner editor reference or the input is
747
     * @return true if it has inner editor reference or the input is
748
     * MultiEditorInput.
748
     * MultiEditorInput.
749
     * @see #getChildren()
749
     */
750
     */
750
    public boolean isMultiReference() {
751
    public boolean isMultiReference() {
751
    	return multiEditorChildren!=null || restoredInput instanceof MultiEditorInput;
752
    	return multiEditorChildren!=null || restoredInput instanceof MultiEditorInput;
752
    }
753
    }
753
754
755
    /**
756
	 * @return Returns the child editor references. May be <code>null</code> if
757
	 *         this is not a multi reference.
758
	 * @see #isMultiReference()
759
     */
760
	public IEditorReference[] getChildren() {
761
		return multiEditorChildren;
762
	}
763
754
	/**
764
	/**
755
	 * Creates and returns an empty editor (<code>ErrorEditorPart</code>).
765
	 * Creates and returns an empty editor (<code>ErrorEditorPart</code>).
756
	 * 
766
	 * 
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java (-1 / +18 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 3484-3489 Link Here
3484
        
3484
        
3485
        if (partBeingActivated != null) {
3485
        if (partBeingActivated != null) {
3486
            if (partBeingActivated.getPart(false) != newPart) {
3486
            if (partBeingActivated.getPart(false) != newPart) {
3487
            	// check if we're a nested editor reference
3488
				if (partBeingActivated instanceof EditorManager.InnerEditor) {
3489
					EditorReference outerEditor = (EditorReference) ((EditorManager.InnerEditor) partBeingActivated)
3490
							.getOuterEditor();
3491
					// get all the sibling references
3492
					IEditorReference[] children = outerEditor.getChildren();
3493
					if (children != null) {
3494
						for (int i = 0; i < children.length; i++) {
3495
							// there's a recursive activation request for a
3496
							// sibling reference, ignore it
3497
							if (children[i].getPart(false) == newPart) {
3498
								return;
3499
							}
3500
						}
3501
					}
3502
				}
3503
3487
                WorkbenchPlugin.log(new RuntimeException(NLS.bind(
3504
                WorkbenchPlugin.log(new RuntimeException(NLS.bind(
3488
                        "WARNING: Prevented recursive attempt to activate part {0} while still in the middle of activating part {1}", //$NON-NLS-1$
3505
                        "WARNING: Prevented recursive attempt to activate part {0} while still in the middle of activating part {1}", //$NON-NLS-1$
3489
                        getId(newPart), getId(partBeingActivated))));
3506
                        getId(newPart), getId(partBeingActivated))));

Return to bug 317102