diff options
2 files changed, 45 insertions, 26 deletions
diff --git a/org.eclipse.mylyn.context.tasks.ui/src/org/eclipse/mylyn/internal/context/tasks/ui/editors/ContextEditorFormPage.java b/org.eclipse.mylyn.context.tasks.ui/src/org/eclipse/mylyn/internal/context/tasks/ui/editors/ContextEditorFormPage.java index da0d26d57..6bf8cac69 100644 --- a/org.eclipse.mylyn.context.tasks.ui/src/org/eclipse/mylyn/internal/context/tasks/ui/editors/ContextEditorFormPage.java +++ b/org.eclipse.mylyn.context.tasks.ui/src/org/eclipse/mylyn/internal/context/tasks/ui/editors/ContextEditorFormPage.java @@ -168,7 +168,8 @@ public class ContextEditorFormPage extends FormPage { case INTEREST_CHANGED: case LANDMARKS_ADDED: case LANDMARKS_REMOVED: - if (isActiveTask()) { + if (context.isForSameTaskAs(event.getContext())) { + context.setWrappedContext(event.getContext()); refresh(event.getElements()); } break; @@ -194,6 +195,7 @@ public class ContextEditorFormPage extends FormPage { context = new ContextWrapper(ContextCorePlugin.getContextStore().loadContext(task.getHandleIdentifier()), task); } + //form.setImage(TaskListImages.getImage(TaskListImages.TASK_ACTIVE_CENTERED)); //form.setText(LABEL); //toolkit.decorateFormHeading(form.getForm()); @@ -511,13 +513,6 @@ public class ContextEditorFormPage extends FormPage { protected void fillContextMenu(IMenuManager manager) { //manager.add(removeFromContextAction); - if (!isActiveTask()) { - manager.remove("org.eclipse.mylyn.java.ui.interest.remove.element"); //$NON-NLS-1$ - // the following ID is used for both make less interesting and mark as landmark so remove it twice - manager.remove("org.eclipse.mylyn.java.ui.interest.increase.element"); //$NON-NLS-1$ - manager.remove("org.eclipse.mylyn.java.ui.interest.increase.element");//$NON-NLS-1$ - manager.remove("org.eclipse.mylyn.resources.ui.ui.interest.remove.element"); //$NON-NLS-1$ - } manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); } diff --git a/org.eclipse.mylyn.context.ui/src/org/eclipse/mylyn/internal/context/ui/actions/AbstractInterestManipulationAction.java b/org.eclipse.mylyn.context.ui/src/org/eclipse/mylyn/internal/context/ui/actions/AbstractInterestManipulationAction.java index 61189d718..38bb9dd2c 100644 --- a/org.eclipse.mylyn.context.ui/src/org/eclipse/mylyn/internal/context/ui/actions/AbstractInterestManipulationAction.java +++ b/org.eclipse.mylyn.context.ui/src/org/eclipse/mylyn/internal/context/ui/actions/AbstractInterestManipulationAction.java @@ -7,6 +7,7 @@ * * Contributors: * Tasktop Technologies - initial API and implementation + * Sebastian Schmidt - bug 385594 *******************************************************************************/ package org.eclipse.mylyn.internal.context.ui.actions; @@ -18,21 +19,23 @@ import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.mylyn.commons.workbench.WorkbenchUtil; import org.eclipse.mylyn.context.core.AbstractContextStructureBridge; import org.eclipse.mylyn.context.core.ContextCore; import org.eclipse.mylyn.context.core.IInteractionContext; import org.eclipse.mylyn.context.core.IInteractionElement; import org.eclipse.mylyn.internal.context.core.ContextCorePlugin; import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IViewActionDelegate; import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PlatformUI; /** * @author Mik Kersten + * @author Sebastian Schmidt */ public abstract class AbstractInterestManipulationAction implements IViewActionDelegate, IWorkbenchWindowActionDelegate { @@ -61,20 +64,8 @@ public abstract class AbstractInterestManipulationAction implements IViewActionD protected abstract boolean isIncrement(); - /** - * Override to return a different context. - */ - protected IInteractionContext getContext() { - return ContextCore.getContextManager().getActiveContext(); - } - public void run(IAction action) { - if (!ContextCore.getContextManager().isContextActive()) { - MessageDialog.openInformation(WorkbenchUtil.getShell(), - Messages.AbstractInterestManipulationAction_Interest_Manipulation, - Messages.AbstractInterestManipulationAction_No_task_context_is_active); - return; - } + IInteractionContext context = getContext(); boolean increment = !isRemove(); @@ -82,7 +73,7 @@ public abstract class AbstractInterestManipulationAction implements IViewActionD StructuredSelection structuredSelection = (StructuredSelection) selection; List<IInteractionElement> nodes = new ArrayList<IInteractionElement>(); for (Object object : structuredSelection.toList()) { - IInteractionElement node = convertSelectionToInteractionElement(object); + IInteractionElement node = convertSelectionToInteractionElement(context, object); nodes.add(node); } @@ -103,7 +94,7 @@ public abstract class AbstractInterestManipulationAction implements IViewActionD } } boolean manipulated = ContextCorePlugin.getContextManager().manipulateInterestForElements(nodes, - increment, false, preserveUninteresting, SOURCE_ID, getContext(), true); + increment, false, preserveUninteresting, SOURCE_ID, context, true); if (!manipulated) { AbstractInterestManipulationAction.displayInterestManipulationFailure(); } @@ -112,7 +103,7 @@ public abstract class AbstractInterestManipulationAction implements IViewActionD IInteractionElement node = ContextCore.getContextManager().getActiveElement(); if (node != null) { boolean manipulated = ContextCorePlugin.getContextManager().manipulateInterestForElement(node, - increment, false, false, SOURCE_ID, getContext(), true); + increment, false, false, SOURCE_ID, ContextCore.getContextManager().getActiveContext(), true); if (!manipulated) { AbstractInterestManipulationAction.displayInterestManipulationFailure(); } @@ -122,19 +113,52 @@ public abstract class AbstractInterestManipulationAction implements IViewActionD Messages.AbstractInterestManipulationAction_No_task_context_is_active); } } + + ContextCorePlugin.getContextManager().saveContext(context); + } + + protected IInteractionContext getContext() { + IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + IInteractionContext context = null; + if (activeWorkbenchWindow != null && activeWorkbenchWindow.getActivePage() != null) { + IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); + IEditorPart activeEditor = activePage.getActiveEditor(); + // action is invoked from context editor + if (activeEditor != null && activePage.getActivePart().equals(activeEditor)) { + context = (IInteractionContext) activeEditor.getEditorInput().getAdapter(IInteractionContext.class); + } + } + + // action is invoked from somewhere else, trying to use the active context + if (context == null && ContextCorePlugin.getContextManager().isContextActive()) { + context = ContextCorePlugin.getContextManager().getActiveContext(); + } + + if (context == null) { + throw new IllegalStateException("error determining action context"); //$NON-NLS-1$ + } + + return context; } /** * TODO: consider moving this extensibility to the UI Bridge + * + * @deprecated use {@link #convertSelectionToInteractionElement(IInteractionContext, Object) } */ + @Deprecated protected IInteractionElement convertSelectionToInteractionElement(Object object) { + return convertSelectionToInteractionElement(ContextCore.getContextManager().getActiveContext(), object); + } + + protected IInteractionElement convertSelectionToInteractionElement(IInteractionContext context, Object object) { IInteractionElement node = null; if (object instanceof IInteractionElement) { node = (IInteractionElement) object; } else { AbstractContextStructureBridge bridge = ContextCore.getStructureBridge(object); String handle = bridge.getHandleIdentifier(object); - node = ContextCore.getContextManager().getElement(handle); + node = context.get(handle); } return node; } |