Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 188052 Details for
Bug 317102
[EditorMgmt] Recursive editor activation when using AbstractMultiEditor
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
AbstractMultiEditor recursive activation patch v2
bug317102-patch-v2.txt (text/plain), 17.07 KB, created by
Remy Suen
on 2011-02-01 10:28:45 EST
(
hide
)
Description:
AbstractMultiEditor recursive activation patch v2
Filename:
MIME Type:
Creator:
Remy Suen
Created:
2011-02-01 10:28:45 EST
Size:
17.07 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.tests >Index: Eclipse UI Tests/org/eclipse/ui/tests/multieditor/AbstractMultiEditorTest.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/multieditor/AbstractMultiEditorTest.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/multieditor/AbstractMultiEditorTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/multieditor/AbstractMultiEditorTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,217 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2011 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.multieditor; >+ >+import java.io.IOException; >+import java.net.URL; >+import java.util.ArrayList; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IWorkspace; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.FileLocator; >+import org.eclipse.core.runtime.ILog; >+import org.eclipse.core.runtime.ILogListener; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.ui.IEditorInput; >+import org.eclipse.ui.IEditorPart; >+import org.eclipse.ui.IEditorRegistry; >+import org.eclipse.ui.IPageLayout; >+import org.eclipse.ui.IViewPart; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchPart; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.internal.PartSite; >+import org.eclipse.ui.internal.WorkbenchPage; >+import org.eclipse.ui.internal.WorkbenchPlugin; >+import org.eclipse.ui.part.FileEditorInput; >+import org.eclipse.ui.part.MultiEditorInput; >+import org.eclipse.ui.tests.TestPlugin; >+import org.eclipse.ui.tests.harness.util.UITestCase; >+ >+public class AbstractMultiEditorTest extends UITestCase { >+ >+ private static final String PROJECT_NAME = "TiledEditorProject"; >+ >+ private static final String TILED_EDITOR_ID = "org.eclipse.ui.tests.multieditor.ConcreteAbstractMultiEditor"; >+ >+ // tiled editor test files >+ private static final String DATA_FILES_DIR = "/data/org.eclipse.newMultiEditor/"; >+ >+ private static final String TEST01_TXT = "test01.txt"; >+ >+ private static final String TEST03_ETEST = "test03.etest"; >+ >+ private EditorErrorListener fErrorListener; >+ >+ public AbstractMultiEditorTest(String tc) { >+ super(tc); >+ } >+ >+ public void testBug317102() throws Throwable { >+ final String[] simpleFiles = { TEST01_TXT, TEST03_ETEST }; >+ >+ IWorkbenchWindow window = openTestWindow(); >+ WorkbenchPage page = (WorkbenchPage) window.getActivePage(); >+ >+ IProject testProject = findOrCreateProject(PROJECT_NAME); >+ >+ MultiEditorInput input = generateEditorInput(simpleFiles, testProject); >+ >+ IEditorPart editor = page.openEditor(input, >+ AbstractMultiEditorTest.TILED_EDITOR_ID); >+ >+ // did we get a multieditor back? >+ assertTrue(editor instanceof ConcreteAbstractMultiEditor); >+ ConcreteAbstractMultiEditor multiEditor = (ConcreteAbstractMultiEditor) editor; >+ >+ IEditorPart[] innerEditors = multiEditor.getInnerEditors(); >+ IEditorPart activeEditor = multiEditor.getActiveEditor(); >+ assertEquals(activeEditor, innerEditors[0]); >+ multiEditor.activateEditor(innerEditors[1]); >+ >+ // activate another view >+ IViewPart view = page.showView(IPageLayout.ID_PROBLEM_VIEW); >+ assertEquals(view, page.getActivePart()); >+ >+ fakeActivation(innerEditors[0]); >+ } >+ >+ private void fakeActivation(IWorkbenchPart part) { >+ try { >+ setupErrorListener(); >+ Event event = new Event(); >+ event.type = SWT.Activate; >+ ((PartSite) part.getSite()).getPane().handleEvent(event); >+ >+ assertTrue("Nothing should have been logged", >+ fErrorListener.messages.isEmpty()); >+ } finally { >+ removeErrorListener(); >+ } >+ } >+ >+ /** >+ * Set up to catch any editor initialization exceptions. >+ * >+ */ >+ private void setupErrorListener() { >+ final ILog log = WorkbenchPlugin.getDefault().getLog(); >+ fErrorListener = new EditorErrorListener(); >+ log.addLogListener(fErrorListener); >+ } >+ >+ /** >+ * Remove the editor error listener. >+ */ >+ private void removeErrorListener() { >+ final ILog log = WorkbenchPlugin.getDefault().getLog(); >+ if (fErrorListener != null) { >+ log.removeLogListener(fErrorListener); >+ fErrorListener = null; >+ } >+ } >+ >+ /** >+ * Create the multi editor input in the given project. Creates the files in >+ * the project from template files in the classpath if they don't already >+ * exist. >+ * >+ * @param simpleFiles >+ * the array of filenames to copy over >+ * @param testProject >+ * the project to create the files in >+ * @return the editor input used to open the multieditor >+ * @throws CoreException >+ * @throws IOException >+ */ >+ private MultiEditorInput generateEditorInput(String[] simpleFiles, >+ IProject testProject) throws CoreException, IOException { >+ String[] ids = new String[simpleFiles.length]; >+ IEditorInput[] inputs = new IEditorInput[simpleFiles.length]; >+ IEditorRegistry registry = fWorkbench.getEditorRegistry(); >+ >+ for (int f = 0; f < simpleFiles.length; ++f) { >+ IFile f1 = createFile(testProject, simpleFiles[f]); >+ ids[f] = registry.getDefaultEditor(f1.getName()).getId(); >+ inputs[f] = new FileEditorInput(f1); >+ } >+ >+ MultiEditorInput input = new MultiEditorInput(ids, inputs); >+ return input; >+ } >+ >+ /** >+ * Create the project to work in. If it already exists, just open it. >+ * >+ * @param projectName >+ * the name of the project to create >+ * @return the newly opened project >+ * @throws CoreException >+ */ >+ private static IProject findOrCreateProject(String projectName) >+ throws CoreException { >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ IProject testProject = workspace.getRoot().getProject(projectName); >+ if (!testProject.exists()) { >+ testProject.create(null); >+ } >+ testProject.open(null); >+ return testProject; >+ } >+ >+ private static IFile createFile(IProject testProject, String simpleFile) >+ throws CoreException, IOException { >+ IFile file = testProject.getFile(simpleFile); >+ if (!file.exists()) { >+ URL url = FileLocator.toFileURL(TestPlugin.getDefault().getBundle() >+ .getEntry(DATA_FILES_DIR + simpleFile)); >+ file.create(url.openStream(), true, null); >+ } >+ return file; >+ } >+ >+ /** >+ * Close any editors at the beginner of a test, so the test can be clean. >+ */ >+ protected void doSetUp() throws Exception { >+ super.doSetUp(); >+ IWorkbenchPage page = fWorkbench.getActiveWorkbenchWindow() >+ .getActivePage(); >+ page.closeAllEditors(false); >+ } >+ >+ /** >+ * Listens for the standard message that indicates the MultiEditor failed >+ * ... usually caused by incorrect framework initialization that doesn't set >+ * the innerChildren. >+ * >+ * @since 3.1 >+ * >+ */ >+ public static class EditorErrorListener implements ILogListener { >+ >+ public ArrayList messages = new ArrayList(); >+ >+ public void logging(IStatus status, String plugin) { >+ String msg = status.getMessage(); >+ Throwable ex = status.getException(); >+ if (ex != null) { >+ msg += ": " + ex.getMessage(); >+ } >+ messages.add(msg); >+ } >+ } >+} >Index: Eclipse UI Tests/org/eclipse/ui/tests/multieditor/ConcreteAbstractMultiEditor.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/multieditor/ConcreteAbstractMultiEditor.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/multieditor/ConcreteAbstractMultiEditor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/multieditor/ConcreteAbstractMultiEditor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,48 @@ >+/******************************************************************************* >+ * Copyright (c) 2011 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.multieditor; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.SashForm; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.ui.IEditorReference; >+import org.eclipse.ui.part.AbstractMultiEditor; >+ >+public class ConcreteAbstractMultiEditor extends AbstractMultiEditor { >+ >+ private Composite left; >+ private Composite right; >+ >+ private IEditorReference leftReference; >+ >+ protected void innerEditorsCreated() { >+ // no-op >+ } >+ >+ public Composite getInnerEditorContainer( >+ IEditorReference innerEditorReference) { >+ if (leftReference == null) { >+ leftReference = innerEditorReference; >+ return left; >+ } >+ return right; >+ } >+ >+ public void createPartControl(Composite parent) { >+ SashForm form = new SashForm(parent, SWT.HORIZONTAL); >+ left = new Composite(form, SWT.NONE); >+ left.setLayout(new FillLayout()); >+ right = new Composite(form, SWT.NONE); >+ right.setLayout(new FillLayout()); >+ form.setWeights(new int[] { 50, 50 }); >+ } >+} >Index: Eclipse UI Tests/org/eclipse/ui/tests/multieditor/MultiEditorTestSuite.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/multieditor/MultiEditorTestSuite.java,v >retrieving revision 1.2 >diff -u -r1.2 MultiEditorTestSuite.java >--- Eclipse UI Tests/org/eclipse/ui/tests/multieditor/MultiEditorTestSuite.java 15 Aug 2005 19:55:48 -0000 1.2 >+++ Eclipse UI Tests/org/eclipse/ui/tests/multieditor/MultiEditorTestSuite.java 1 Feb 2011 15:27:02 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2005 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 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 >@@ -22,6 +22,7 @@ > * Construct the test suite. > */ > public MultiEditorTestSuite() { >+ addTestSuite(AbstractMultiEditorTest.class); > addTestSuite(MultiEditorTest.class); > } > } >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/plugin.xml,v >retrieving revision 1.291 >diff -u -r1.291 plugin.xml >--- plugin.xml 16 Dec 2010 06:04:20 -0000 1.291 >+++ plugin.xml 1 Feb 2011 15:27:02 -0000 >@@ -687,6 +687,12 @@ > id="org.eclipse.ui.tests.multieditor.TiledEditor" > name="%Editors.TiledEditor"/> > <editor >+ class="org.eclipse.ui.tests.multieditor.ConcreteAbstractMultiEditor" >+ default="false" >+ icon="icons/binary_co.gif" >+ id="org.eclipse.ui.tests.multieditor.ConcreteAbstractMultiEditor" >+ name="%Editors.TiledEditor"/> >+ <editor > class="org.eclipse.ui.tests.multieditor.TestEditor" > contributorClass="org.eclipse.ui.tests.multieditor.TestActionBarContributor" > default="false" >#P org.eclipse.ui.workbench >Index: Eclipse UI/org/eclipse/ui/internal/EditorManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/EditorManager.java,v >retrieving revision 1.148 >diff -u -r1.148 EditorManager.java >--- Eclipse UI/org/eclipse/ui/internal/EditorManager.java 19 Jan 2010 14:03:56 -0000 1.148 >+++ Eclipse UI/org/eclipse/ui/internal/EditorManager.java 1 Feb 2011 15:27:03 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 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 >@@ -1437,7 +1437,11 @@ > return (IPathEditorInput) Util.getAdapter(input, IPathEditorInput.class); > } > >- private class InnerEditor extends EditorReference { >+ /** >+ * An editor reference that is actually contained within another editor >+ * reference. >+ */ >+ class InnerEditor extends EditorReference { > > private IEditorReference outerEditor; > >@@ -1451,6 +1455,14 @@ > this.outerEditorPart = outerEditorPart; > } > >+ /** >+ * @return Returns the parent editor reference that this reference is a >+ * child of. >+ */ >+ public IEditorReference getOuterEditor() { >+ return outerEditor; >+ } >+ > protected void doDisposePart() { > this.outerEditorPart = null; > super.doDisposePart(); >Index: Eclipse UI/org/eclipse/ui/internal/EditorReference.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/EditorReference.java,v >retrieving revision 1.42 >diff -u -r1.42 EditorReference.java >--- Eclipse UI/org/eclipse/ui/internal/EditorReference.java 1 Jun 2010 19:22:36 -0000 1.42 >+++ Eclipse UI/org/eclipse/ui/internal/EditorReference.java 1 Feb 2011 15:27:03 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2006, 2010 IBM Corporation and others. >+ * Copyright (c) 2006, 2011 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 >@@ -746,11 +746,21 @@ > * > * @return true if it has inner editor reference or the input is > * MultiEditorInput. >+ * @see #getChildren() > */ > public boolean isMultiReference() { > return multiEditorChildren!=null || restoredInput instanceof MultiEditorInput; > } > >+ /** >+ * @return Returns the child editor references. May be <code>null</code> if >+ * this is not a multi reference. >+ * @see #isMultiReference() >+ */ >+ public IEditorReference[] getChildren() { >+ return multiEditorChildren; >+ } >+ > /** > * Creates and returns an empty editor (<code>ErrorEditorPart</code>). > * >Index: Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java,v >retrieving revision 1.332 >diff -u -r1.332 WorkbenchPage.java >--- Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java 14 Dec 2010 10:45:58 -0000 1.332 >+++ Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java 1 Feb 2011 15:27:03 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 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 >@@ -3484,6 +3484,23 @@ > > if (partBeingActivated != null) { > if (partBeingActivated.getPart(false) != newPart) { >+ // check if we're a nested editor reference >+ if (partBeingActivated instanceof EditorManager.InnerEditor) { >+ EditorReference outerEditor = (EditorReference) ((EditorManager.InnerEditor) partBeingActivated) >+ .getOuterEditor(); >+ // get all the sibling references >+ IEditorReference[] children = outerEditor.getChildren(); >+ if (children != null) { >+ for (int i = 0; i < children.length; i++) { >+ // there's a recursive activation request for a >+ // sibling reference, ignore it >+ if (children[i].getPart(false) == newPart) { >+ return; >+ } >+ } >+ } >+ } >+ > WorkbenchPlugin.log(new RuntimeException(NLS.bind( > "WARNING: Prevented recursive attempt to activate part {0} while still in the middle of activating part {1}", //$NON-NLS-1$ > getId(newPart), getId(partBeingActivated))));
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 317102
:
184885
| 188052