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 152557 Details for
Bug 226618
[context] move task-specific editor memento storage out of the plug-in preference store
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]
in progress
clipboard.txt (text/plain), 18.59 KB, created by
Steffen Pingel
on 2009-11-19 01:41:57 EST
(
hide
)
Description:
in progress
Filename:
MIME Type:
Creator:
Steffen Pingel
Created:
2009-11-19 01:41:57 EST
Size:
18.59 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.mylyn.context.ui >Index: src/org/eclipse/mylyn/internal/context/ui/ContextEditorManager.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.context.ui/src/org/eclipse/mylyn/internal/context/ui/ContextEditorManager.java,v >retrieving revision 1.21 >diff -u -r1.21 ContextEditorManager.java >--- src/org/eclipse/mylyn/internal/context/ui/ContextEditorManager.java 7 Oct 2009 23:15:05 -0000 1.21 >+++ src/org/eclipse/mylyn/internal/context/ui/ContextEditorManager.java 19 Nov 2009 06:40:09 -0000 >@@ -11,29 +11,23 @@ > > package org.eclipse.mylyn.internal.context.ui; > >-import java.io.IOException; >-import java.io.StringReader; >-import java.io.StringWriter; > import java.util.ArrayList; > import java.util.Arrays; > import java.util.HashSet; > import java.util.List; > import java.util.Set; > >-import org.eclipse.core.runtime.Assert; > import org.eclipse.core.runtime.ISafeRunnable; > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.MultiStatus; > import org.eclipse.core.runtime.Status; >-import org.eclipse.core.runtime.preferences.InstanceScope; >-import org.eclipse.jface.preference.IPreferenceStore; > import org.eclipse.jface.util.SafeRunnable; > import org.eclipse.mylyn.commons.core.StatusHandler; > import org.eclipse.mylyn.context.core.AbstractContextListener; > import org.eclipse.mylyn.context.core.AbstractContextStructureBridge; > import org.eclipse.mylyn.context.core.ContextChangeEvent; > import org.eclipse.mylyn.context.core.ContextCore; >-import org.eclipse.mylyn.context.core.IInteractionContext; >+import org.eclipse.mylyn.context.core.IInteractionContextManager; > import org.eclipse.mylyn.context.core.IInteractionElement; > import org.eclipse.mylyn.context.ui.AbstractContextUiBridge; > import org.eclipse.mylyn.context.ui.ContextUi; >@@ -51,24 +45,56 @@ > import org.eclipse.ui.IWorkbenchWindow; > import org.eclipse.ui.PartInitException; > import org.eclipse.ui.PlatformUI; >-import org.eclipse.ui.XMLMemento; > import org.eclipse.ui.internal.EditorManager; > import org.eclipse.ui.internal.IPreferenceConstants; > import org.eclipse.ui.internal.IWorkbenchConstants; > import org.eclipse.ui.internal.Workbench; > import org.eclipse.ui.internal.WorkbenchPage; > import org.eclipse.ui.internal.WorkbenchWindow; >-import org.eclipse.ui.preferences.ScopedPreferenceStore; > > /** > * @author Mik Kersten > * @author Shawn Minto > */ >-public class ContextEditorManager extends AbstractContextListener { >+public class ContextEditorManager { > >- private static final String PREFS_PREFIX = "editors.task."; //$NON-NLS-1$ >+ private class MementoListener extends ContextMementoListener { > >- private static final String KEY_CONTEXT_EDITORS = "ContextOpenEditors"; //$NON-NLS-1$ >+ @Override >+ public void clearState(String contextHandle, boolean isActiveContext) { >+ ContextEditorManager.this.clearState(contextHandle, isActiveContext); >+ }; >+ >+ @Override >+ public void restoreState(ContextMemento memento) { >+ ContextEditorManager.this.restoreState(memento); >+ } >+ >+ @Override >+ public void saveState(ContextMemento memento) { >+ ContextEditorManager.this.saveState(memento); >+ } >+ >+ } >+ >+ private class ContextListener extends AbstractContextListener { >+ >+ @Override >+ public void contextChanged(ContextChangeEvent event) { >+ switch (event.getEventKind()) { >+ case INTEREST_CHANGED: >+ for (IInteractionElement element : event.getElements()) { >+ closeEditor(element, false); >+ } >+ break; >+ case ELEMENTS_DELETED: >+ for (IInteractionElement element : event.getElements()) { >+ closeEditor(element, true); >+ } >+ break; >+ } >+ } >+ } > > private static final String KEY_MONITORED_WINDOW_OPEN_EDITORS = "MonitoredWindowOpenEditors"; //$NON-NLS-1$ > >@@ -83,41 +109,29 @@ > private boolean previousCloseEditorsSetting = Workbench.getInstance().getPreferenceStore().getBoolean( > IPreferenceConstants.REUSE_EDITORS_BOOLEAN); > >- private final IPreferenceStore preferenceStore; >+ private final MementoListener mementoListener; >+ >+ private final ContextListener contextListener; >+ >+ //private final IPreferenceStore preferenceStore; > > public ContextEditorManager() { >- preferenceStore = new ScopedPreferenceStore(new InstanceScope(), "org.eclipse.mylyn.resources.ui"); //$NON-NLS-1$ >+ //preferenceStore = new ScopedPreferenceStore(new InstanceScope(), "org.eclipse.mylyn.resources.ui"); //$NON-NLS-1$ >+ this.mementoListener = new MementoListener(); >+ this.contextListener = new ContextListener(); > } > >- @Override >- public void contextChanged(ContextChangeEvent event) { >- switch (event.getEventKind()) { >- case ACTIVATED: >- openEditorsFromMemento(event.getContext()); >- break; >- case DEACTIVATED: >- closeEditorsAndSaveMemento(event.getContext()); >- break; >- case INTEREST_CHANGED: >- for (IInteractionElement element : event.getElements()) { >- closeEditor(element, false); >- } >- break; >- case ELEMENTS_DELETED: >- for (IInteractionElement element : event.getElements()) { >- closeEditor(element, true); >- } >- break; >- case CLEARED: >- // use the handle since the context is null when it is cleared >- // bug 255588 >- clearEditorMemento(event.getContextHandle(), event.isActiveContext()); >- break; >+ public void start(IInteractionContextManager contextManager, ContextMementoManager mementoManager) { >+ contextManager.addListener(contextListener); >+ mementoManager.addMementoListener(mementoListener); >+ } > >- } >+ public void stop(IInteractionContextManager contextManager, ContextMementoManager mementoManager) { >+ contextManager.removeListener(contextListener); >+ mementoManager.removeMementoListener(mementoListener); > } > >- public void openEditorsFromMemento(IInteractionContext context) { >+ public void restoreState(ContextMemento state) { > if (!Workbench.getInstance().isStarting() > && ContextUiPlugin.getDefault().getPreferenceStore().getBoolean( > IContextUiPreferenceContstants.AUTO_MANAGE_EDITORS) && !TaskMigrator.isActive()) { >@@ -131,12 +145,13 @@ > ContextCore.getContextManager().setContextCapturePaused(true); > } > String mementoString = null; >- // TODO change where memento is stored > IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); > try { >- mementoString = readEditorMemento(context.getHandleIdentifier()); >- if (mementoString != null && !mementoString.trim().equals("")) { //$NON-NLS-1$ >- IMemento memento = XMLMemento.createReadRoot(new StringReader(mementoString)); >+// mementoString = readEditorMemento(context.getHandleIdentifier()); >+// if (mementoString != null && !mementoString.trim().equals("")) { //$NON-NLS-1$ >+// IMemento memento = XMLMemento.createReadRoot(new StringReader(mementoString)); >+ IMemento memento = state.getMemento("editors"); >+ if (memento != null) { > IMemento[] children = memento.getChildren(KEY_MONITORED_WINDOW_OPEN_EDITORS); > if (children.length > 0) { > // This code supports restore from multiple windows >@@ -159,7 +174,7 @@ > "Could not restore all editors, memento: \"" + mementoString + "\"", e)); //$NON-NLS-1$ //$NON-NLS-2$ > } > activeWindow.setActivePage(activeWindow.getActivePage()); >- IInteractionElement activeNode = context.getActiveNode(); >+ IInteractionElement activeNode = state.getContext().getActiveNode(); > if (activeNode != null) { > ContextUi.getUiBridge(activeNode.getContentType()).open(activeNode); > } >@@ -173,7 +188,6 @@ > } > > private WorkbenchPage getWorkbenchPageForMemento(IMemento memento, IWorkbenchWindow activeWindow) { >- > String windowToRestoreClassName = memento.getString(ATTRIBUTE_CLASS); > if (windowToRestoreClassName == null) { > windowToRestoreClassName = ""; //$NON-NLS-1$ >@@ -226,22 +240,23 @@ > return null; > } > >- private String readEditorMemento(String handleIdentifier) { >- return preferenceStore.getString(PREFS_PREFIX + handleIdentifier); >- } >+// private String readEditorMemento(String handleIdentifier) { >+// return preferenceStore.getString(PREFS_PREFIX + handleIdentifier); >+// } > >- public void closeEditorsAndSaveMemento(IInteractionContext context) { >+ public void saveState(ContextMemento state) { > if (!PlatformUI.getWorkbench().isClosing() > && ContextUiPlugin.getDefault().getPreferenceStore().getBoolean( > IContextUiPreferenceContstants.AUTO_MANAGE_EDITORS) && !TaskMigrator.isActive()) { >- closeAllButActiveTaskEditor(context.getHandleIdentifier()); >+ closeAllButActiveTaskEditor(state.getContextHandle()); > >- XMLMemento rootMemento = XMLMemento.createWriteRoot(KEY_CONTEXT_EDITORS); >+// XMLMemento rootMemento = XMLMemento.createWriteRoot(KEY_CONTEXT_EDITORS); > > IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); > IWorkbenchWindow launchingWindow = MonitorUi.getLaunchingWorkbenchWindow(); > Set<IWorkbenchWindow> monitoredWindows = MonitorUi.getMonitoredWindows(); > >+ IMemento rootMemento = state.createMemento("editors"); > for (IWorkbenchWindow window : monitoredWindows) { > IMemento memento = rootMemento.createChild(KEY_MONITORED_WINDOW_OPEN_EDITORS); > >@@ -255,15 +270,15 @@ > memento.putBoolean(ATTRIBUTE_IS_ACTIVE, window == activeWindow); > ((WorkbenchPage) window.getActivePage()).getEditorManager().saveState(memento); > } >- // TODO: avoid storing with preferences due to bloat? >- StringWriter writer = new StringWriter(); >- try { >- rootMemento.save(writer); >- writeEditorMemento(context.getHandleIdentifier(), writer.getBuffer().toString()); >- } catch (IOException e) { >- StatusHandler.log(new Status(IStatus.ERROR, ContextUiPlugin.ID_PLUGIN, "Could not store editor state", //$NON-NLS-1$ >- e)); >- } >+// // TODO: avoid storing with preferences due to bloat? >+// StringWriter writer = new StringWriter(); >+// try { >+// rootMemento.save(writer); >+// writeEditorMemento(context, writer.getBuffer().toString()); >+// } catch (IOException e) { >+// StatusHandler.log(new Status(IStatus.ERROR, ContextUiPlugin.ID_PLUGIN, "Could not store editor state", //$NON-NLS-1$ >+// e)); >+// } > > Workbench.getInstance().getPreferenceStore().setValue(IPreferenceConstants.REUSE_EDITORS_BOOLEAN, > previousCloseEditorsSetting); >@@ -271,27 +286,16 @@ > } > } > >- public void writeEditorMemento(String contextHandle, String memento) { >- preferenceStore.setValue(PREFS_PREFIX + contextHandle, memento); >- } >+// public void writeEditorMemento(IInteractionContext context, String memento) { >+// preferenceStore.setValue(PREFS_PREFIX + context.getHandleIdentifier(), memento); >+// } > >- public void clearEditorMemento(String contextHandle, boolean closeEditors) { >+ public void clearState(String contextHandle, boolean closeEditors) { > > if (closeEditors) { > closeAllButActiveTaskEditor(contextHandle); > } > >- XMLMemento memento = XMLMemento.createWriteRoot(KEY_CONTEXT_EDITORS); >- >- // TODO: avoid storing with preferences due to bloat? >- StringWriter writer = new StringWriter(); >- try { >- memento.save(writer); >- writeEditorMemento(contextHandle, writer.getBuffer().toString()); >- } catch (IOException e) { >- StatusHandler.log(new Status(IStatus.ERROR, ContextUiPlugin.ID_PLUGIN, "Could not store editor state", e)); //$NON-NLS-1$ >- } >- > Workbench.getInstance().getPreferenceStore().setValue(IPreferenceConstants.REUSE_EDITORS_BOOLEAN, > previousCloseEditorsSetting); > if (closeEditors) { >@@ -441,13 +445,4 @@ > } > } > >- public void copyEditorMemento(String sourceHandle, String targetHandle) { >- Assert.isNotNull(sourceHandle); >- Assert.isNotNull(targetHandle); >- String memento = readEditorMemento(sourceHandle); >- if (memento != null) { >- writeEditorMemento(targetHandle, memento); >- } >- } >- > } >Index: src/org/eclipse/mylyn/internal/context/ui/commands/CopyContextHandler.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.context.ui/src/org/eclipse/mylyn/internal/context/ui/commands/CopyContextHandler.java,v >retrieving revision 1.9 >diff -u -r1.9 CopyContextHandler.java >--- src/org/eclipse/mylyn/internal/context/ui/commands/CopyContextHandler.java 7 Oct 2009 23:15:05 -0000 1.9 >+++ src/org/eclipse/mylyn/internal/context/ui/commands/CopyContextHandler.java 19 Nov 2009 06:40:09 -0000 >@@ -17,7 +17,6 @@ > import org.eclipse.jface.window.Window; > import org.eclipse.mylyn.context.core.ContextCore; > import org.eclipse.mylyn.context.core.IInteractionContext; >-import org.eclipse.mylyn.internal.context.ui.ContextUiPlugin; > import org.eclipse.mylyn.internal.tasks.ui.actions.TaskSelectionDialog; > import org.eclipse.mylyn.internal.tasks.ui.commands.AbstractTaskHandler; > import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; >@@ -66,8 +65,9 @@ > MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), > TITLE_DIALOG, Messages.CopyContextHandler_SOURCE_TASK_DOES_HAVE_A_CONTEXT); > } else { >- ContextUiPlugin.getEditorManager().copyEditorMemento(sourceTask.getHandleIdentifier(), >- targetTask.getHandleIdentifier()); >+ // FIXME 3.4 re-implemnt memenot copying >+// ContextUiPlugin.getEditorManager().copyEditorMemento(sourceTask.getHandleIdentifier(), >+// targetTask.getHandleIdentifier()); > TasksUiInternal.activateTaskThroughCommand(targetTask); > } > } >#P org.eclipse.mylyn.tasks.tests >Index: src/org/eclipse/mylyn/tasks/tests/ui/ContextPerspectiveManagerTest.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/ContextPerspectiveManagerTest.java,v >retrieving revision 1.7 >diff -u -r1.7 ContextPerspectiveManagerTest.java >--- src/org/eclipse/mylyn/tasks/tests/ui/ContextPerspectiveManagerTest.java 13 Oct 2009 00:58:06 -0000 1.7 >+++ src/org/eclipse/mylyn/tasks/tests/ui/ContextPerspectiveManagerTest.java 19 Nov 2009 06:40:10 -0000 >@@ -13,13 +13,19 @@ > > import junit.framework.TestCase; > >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.mylyn.context.core.ContextCore; > import org.eclipse.mylyn.context.tests.support.ContextTestUtil; >+import org.eclipse.mylyn.internal.context.core.InteractionContext; >+import org.eclipse.mylyn.internal.context.ui.ContextMemento; > import org.eclipse.mylyn.internal.context.ui.ContextUiPlugin; > import org.eclipse.mylyn.internal.context.ui.IContextUiPreferenceContstants; > import org.eclipse.mylyn.internal.tasks.core.TaskTask; >+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; > import org.eclipse.mylyn.monitor.ui.MonitorUi; > import org.eclipse.mylyn.tasks.tests.TaskTestUtil; > import org.eclipse.mylyn.tasks.ui.TasksUi; >+import org.eclipse.ui.IMemento; > import org.eclipse.ui.PlatformUI; > > /** >@@ -51,6 +57,18 @@ > TaskTestUtil.resetTaskListAndRepositories(); > } > >+ public void testHasPlanningAndResourcePerspective() throws Exception { >+ PlatformUI.getWorkbench().showPerspective(ID_RESOURCE_PERSPECTIVE, MonitorUi.getLaunchingWorkbenchWindow()); >+ assertEquals(ID_RESOURCE_PERSPECTIVE, getActivePerspective()); >+ PlatformUI.getWorkbench().showPerspective(ID_PLANNING_PERSPECTIVE, MonitorUi.getLaunchingWorkbenchWindow()); >+ assertEquals(ID_PLANNING_PERSPECTIVE, getActivePerspective()); >+ } >+ >+ public void testHasActiveWorkbenchWindow() throws Exception { >+ assertNotNull("No active workbench window. Following tests are likely to fail.", PlatformUI.getWorkbench() >+ .getActiveWorkbenchWindow()); >+ } >+ > public void testRestorePerspective() throws Exception { > PlatformUI.getWorkbench().showPerspective(ID_RESOURCE_PERSPECTIVE, MonitorUi.getLaunchingWorkbenchWindow()); > assertEquals(ID_RESOURCE_PERSPECTIVE, getActivePerspective()); >@@ -71,24 +89,44 @@ > assertEquals(ID_PLANNING_PERSPECTIVE, getActivePerspective()); > } > >- // FIXME 3.4 re-enable test >-// public void testRecreateTask() throws Exception { >-// PlatformUI.getWorkbench().showPerspective(ID_RESOURCE_PERSPECTIVE, MonitorUi.getLaunchingWorkbenchWindow()); >-// TaskTask task = TaskTestUtil.createMockTask("1"); >-// >-// // check that deleting task switches back to original perspective >-// TasksUi.getTaskActivityManager().activateTask(task); >-// PlatformUI.getWorkbench().showPerspective(ID_PLANNING_PERSPECTIVE, MonitorUi.getLaunchingWorkbenchWindow()); >-// TasksUiPlugin.getTaskActivityManager().deactivateActiveTask(); >-// TasksUiPlugin.getTaskList().deleteTask(task); >-// assertEquals(ID_RESOURCE_PERSPECTIVE, getActivePerspective()); >-// >-// task = TaskTestUtil.createMockTask("1"); >-// >-// // check that activating new task with the same id does not switch the perspective >-// TasksUi.getTaskActivityManager().activateTask(task); >-// assertEquals(ID_RESOURCE_PERSPECTIVE, getActivePerspective()); >-// } >+ public void testRecreateTask() throws Exception { >+ PlatformUI.getWorkbench().showPerspective(ID_RESOURCE_PERSPECTIVE, MonitorUi.getLaunchingWorkbenchWindow()); >+ TaskTask task = TaskTestUtil.createMockTask("1"); >+ >+ // check that deleting task switches back to original perspective >+ TasksUi.getTaskActivityManager().activateTask(task); >+ PlatformUI.getWorkbench().showPerspective(ID_PLANNING_PERSPECTIVE, MonitorUi.getLaunchingWorkbenchWindow()); >+ TasksUiPlugin.getTaskActivityManager().deactivateActiveTask(); >+ TasksUiPlugin.getTaskList().deleteTask(task); >+ assertEquals(ID_RESOURCE_PERSPECTIVE, getActivePerspective()); >+ >+ task = TaskTestUtil.createMockTask("1"); >+ >+ // check that activating new task with the same id does not switch the perspective >+ TasksUi.getTaskActivityManager().activateTask(task); >+ assertEquals(ID_RESOURCE_PERSPECTIVE, getActivePerspective()); >+ } >+ >+ public void testMigratePreferences() throws Exception { >+ PlatformUI.getWorkbench().showPerspective(ID_RESOURCE_PERSPECTIVE, MonitorUi.getLaunchingWorkbenchWindow()); >+ >+ TaskTask task = TaskTestUtil.createMockTask("1"); >+ ContextUiPlugin.getDefault().getPreferenceStore().setValue( >+ ContextUiPlugin.PREFIX_TASK_TO_PERSPECTIVE + task.getHandleIdentifier(), ID_PLANNING_PERSPECTIVE); >+ >+ IStatus status = ContextUiPlugin.getDefault().migrateContextMementos(); >+ assertEquals(IStatus.OK, status.getSeverity()); >+ >+ InteractionContext context = new InteractionContext(task.getHandleIdentifier(), >+ ContextCore.getCommonContextScaling()); >+ ContextMemento state = ContextUiPlugin.getDefault().getMementoManager().read(context); >+ IMemento memento = state.getMemento("perspective"); >+ assertNotNull(memento); >+ assertEquals(ID_PLANNING_PERSPECTIVE, memento.getString("activeId")); >+ >+ assertNull(ContextUiPlugin.getDefault().getPreferenceStore().getString( >+ ContextUiPlugin.PREFIX_TASK_TO_PERSPECTIVE + task.getHandleIdentifier())); >+ } > > private String getActivePerspective() { > return MonitorUi.getLaunchingWorkbenchWindow().getActivePage().getPerspective().getId();
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 226618
:
123033
|
123034
|
123040
|
123142
|
135417
|
152557
|
152558
|
153653
|
154288