NEW - bug 359463: move task structure bridge to sandbox
https://bugs.eclipse.org/bugs/show_bug.cgi?id=359463
diff --git a/org.eclipse.mylyn.sandbox.ui/plugin.xml b/org.eclipse.mylyn.sandbox.ui/plugin.xml
index a4a9d34..973e40b 100644
--- a/org.eclipse.mylyn.sandbox.ui/plugin.xml
+++ b/org.eclipse.mylyn.sandbox.ui/plugin.xml
@@ -432,5 +432,17 @@
name="Eclipse.org Plugin Link"
order="2000"/>
</extension>
-
+
+ <extension
+ point="org.eclipse.mylyn.context.core.bridges">
+ <structureBridge
+ class="org.eclipse.mylyn.internal.sandbox.ui.context.TaskStructureBridge"/>
+ </extension>
+ <extension
+ point="org.eclipse.mylyn.context.ui.bridges">
+ <uiBridge
+ class="org.eclipse.mylyn.internal.sandbox.ui.context.TaskUiBridge"
+ contentType="meta/task"/>
+ </extension>
+
</plugin>
diff --git a/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/actions/FindReferencesInContextAction.java b/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/actions/FindReferencesInContextAction.java
index d68ae4b..9cf0007 100644
--- a/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/actions/FindReferencesInContextAction.java
+++ b/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/actions/FindReferencesInContextAction.java
@@ -23,7 +23,7 @@
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.mylyn.internal.context.ui.ContextWorkingSetManager;
+import org.eclipse.mylyn.internal.sandbox.ui.context.ContextWorkingSetManager;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchWindow;
diff --git a/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/context/ContextWorkingSetManager.java b/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/context/ContextWorkingSetManager.java
new file mode 100644
index 0000000..7388e23
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/context/ContextWorkingSetManager.java
@@ -0,0 +1,136 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2009 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.sandbox.ui.context;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+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.IInteractionElement;
+import org.eclipse.mylyn.internal.context.core.ContextCorePlugin;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetUpdater;
+
+/**
+ * TODO: consider removing
+ *
+ * @author Shawn Minto
+ * @author Mik Kersten
+ */
+public class ContextWorkingSetManager implements IWorkingSetUpdater {
+
+ private static ContextWorkingSetManager INSTANCE = new ContextWorkingSetManager();
+
+ private List<ContextWorkingSetManager> workingSetUpdaters = null;
+
+ private final AbstractContextListener CONTEXT_LISTENER = new AbstractContextListener() {
+
+ @Override
+ public void contextChanged(ContextChangeEvent event) {
+ switch (event.getEventKind()) {
+ case ACTIVATED:
+ case DEACTIVATED:
+ case CLEARED:
+ case INTEREST_CHANGED:
+ case ELEMENTS_DELETED:
+ case LANDMARKS_ADDED:
+ case LANDMARKS_REMOVED:
+ updateWorkingSet();
+ break;
+ }
+ }
+
+ };
+
+ public void addWorkingSetManager(ContextWorkingSetManager updater) {
+ if (workingSetUpdaters == null) {
+ workingSetUpdaters = new ArrayList<ContextWorkingSetManager>();
+ }
+ workingSetUpdaters.add(updater);
+ ContextCore.getContextManager().addListener(CONTEXT_LISTENER);
+ }
+
+ public void dispose() {
+ ContextCore.getContextManager().removeListener(CONTEXT_LISTENER);
+ }
+
+ public ContextWorkingSetManager getWorkingSetUpdater() {
+ if (workingSetUpdaters == null) {
+ return null;
+ } else {
+ return workingSetUpdaters.get(0);
+ }
+ }
+
+ /** Should only ever have 1 working set */
+ private final List<IWorkingSet> workingSets = new ArrayList<IWorkingSet>();
+
+ public void add(IWorkingSet workingSet) {
+ workingSets.add(workingSet);
+ }
+
+ public boolean remove(IWorkingSet workingSet) {
+ return workingSets.remove(workingSet);
+
+ }
+
+ public boolean contains(IWorkingSet workingSet) {
+ return workingSets.contains(workingSet);
+ }
+
+ private void updateWorkingSet() {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ if (workingSets.size() <= 0) {
+ return;
+ }
+ IWorkingSet set = workingSets.get(0);
+ set.setElements(new IAdaptable[] {});
+ List<IAdaptable> elements = new ArrayList<IAdaptable>();
+ getElementsFromContext(elements);
+ set.setElements(elements.toArray(new IAdaptable[elements.size()]));
+ }
+ });
+ }
+
+ public static void getElementsFromContext(List<IAdaptable> elements) {
+ for (IInteractionElement node : ContextCorePlugin.getContextManager().getActiveDocuments()) {
+ AbstractContextStructureBridge bridge = ContextCore.getStructureBridge(node.getContentType());
+
+ // HACK comparing extension to string
+ // No need to add bugzilla resources to the taskscape
+ // search...really slow and eclipese doesn't know about them
+ if (bridge.getContentType().equals("bugzilla")) { //$NON-NLS-1$
+ continue;
+ }
+
+ Object o = bridge.getObjectForHandle(node.getHandleIdentifier());
+ if (o instanceof IAdaptable) {
+ elements.add((IAdaptable) o);
+ }
+
+ }
+ }
+
+ public IWorkingSet getWorkingSet() {
+ return workingSets.get(0);
+ }
+
+ public static ContextWorkingSetManager getDefault() {
+ return INSTANCE;
+ }
+}
diff --git a/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/context/TaskStructureBridge.java b/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/context/TaskStructureBridge.java
new file mode 100644
index 0000000..419078a
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/context/TaskStructureBridge.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2008 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.sandbox.ui.context;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.mylyn.context.core.AbstractContextStructureBridge;
+import org.eclipse.mylyn.tasks.core.IRepositoryElement;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.ui.TasksUi;
+
+/**
+ * @author Mik Kersten
+ */
+public class TaskStructureBridge extends AbstractContextStructureBridge {
+
+ public static final String CONTENT_TYPE = "meta/task"; //$NON-NLS-1$
+
+ @Override
+ public String getContentType() {
+ return CONTENT_TYPE;
+ }
+
+ @Override
+ public String getHandleIdentifier(Object object) {
+ if (object instanceof ITask) {
+ return ((ITask) object).getHandleIdentifier();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public String getParentHandle(String handle) {
+ return null;
+ }
+
+ @Override
+ public Object getObjectForHandle(String handle) {
+ return TasksUi.getRepositoryModel().getTask(handle);
+ }
+
+ @Override
+ public List<String> getChildHandles(String handle) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public String getLabel(Object object) {
+ if (object instanceof ITask) {
+ return ((ITask) object).getSummary();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public boolean canBeLandmark(String handle) {
+ return false;
+ }
+
+ @Override
+ public boolean acceptsObject(Object object) {
+ return object instanceof IRepositoryElement;
+ }
+
+ @Override
+ public boolean canFilter(Object object) {
+ return object instanceof ITask;
+ }
+
+ @Override
+ public boolean isDocument(String handle) {
+ return getObjectForHandle(handle) instanceof ITask;
+ }
+
+ @Override
+ public String getHandleForOffsetInObject(Object resource, int offset) {
+ return null;
+ }
+
+ @Override
+ public String getContentType(String elementHandle) {
+ return getContentType();
+ }
+}
diff --git a/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/context/TaskUiBridge.java b/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/context/TaskUiBridge.java
new file mode 100644
index 0000000..9f69322
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/context/TaskUiBridge.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2008 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.sandbox.ui.context;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.mylyn.context.core.IInteractionElement;
+import org.eclipse.mylyn.context.ui.AbstractContextUiBridge;
+import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * @author Mik Kersten
+ */
+public class TaskUiBridge extends AbstractContextUiBridge {
+
+ @Override
+ public void open(IInteractionElement node) {
+ // ignore
+ }
+
+ @Override
+ public void close(IInteractionElement node) {
+ // ignore
+ }
+
+ @Override
+ public boolean acceptsEditor(IEditorPart editorPart) {
+ return editorPart instanceof TaskEditor;
+ }
+
+ @Override
+ public List<TreeViewer> getContentOutlineViewers(IEditorPart editorPart) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public Object getObjectForTextSelection(TextSelection selection, IEditorPart editor) {
+ return null;
+ }
+
+ @Override
+ public IInteractionElement getElement(IEditorInput input) {
+ return null;
+ }
+
+ @Override
+ public String getContentType() {
+ return TaskStructureBridge.CONTENT_TYPE;
+ }
+}
diff --git a/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/views/ActiveSearchView.java b/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/views/ActiveSearchView.java
index b0295ac..9b57920 100644
--- a/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/views/ActiveSearchView.java
+++ b/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/views/ActiveSearchView.java
@@ -40,7 +40,6 @@
import org.eclipse.mylyn.internal.context.core.AbstractRelationProvider;
import org.eclipse.mylyn.internal.context.core.ContextCorePlugin;
import org.eclipse.mylyn.internal.context.core.IRelationsListener;
-import org.eclipse.mylyn.internal.context.ui.ActiveViewSelectionDragAdapter;
import org.eclipse.mylyn.internal.context.ui.ContextUiPlugin;
import org.eclipse.mylyn.internal.context.ui.DoiOrderSorter;
import org.eclipse.mylyn.internal.context.ui.views.ContextNodeOpenListener;
diff --git a/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/views/ActiveViewSelectionDragAdapter.java b/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/views/ActiveViewSelectionDragAdapter.java
new file mode 100644
index 0000000..cc0d188
--- /dev/null
+++ b/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/views/ActiveViewSelectionDragAdapter.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2008 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.sandbox.ui.views;
+
+import org.eclipse.jface.util.LocalSelectionTransfer;
+import org.eclipse.jface.util.TransferDragSourceListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DragSourceAdapter;
+import org.eclipse.swt.dnd.DragSourceEvent;
+import org.eclipse.swt.dnd.Transfer;
+
+/**
+ * @author Mik Kersten
+ */
+public class ActiveViewSelectionDragAdapter extends DragSourceAdapter implements TransferDragSourceListener {
+
+ private final ISelectionProvider fProvider;
+
+ public ActiveViewSelectionDragAdapter(ISelectionProvider provider) {
+ assert provider != null;
+ fProvider = provider;
+ }
+
+ public Transfer getTransfer() {
+ return LocalSelectionTransfer.getTransfer();
+ }
+
+ @Override
+ public void dragStart(DragSourceEvent event) {
+ ISelection selection = fProvider.getSelection();
+ LocalSelectionTransfer.getTransfer().setSelection(selection);
+ LocalSelectionTransfer.getTransfer().setSelectionSetTime(event.time & 0xFFFFFFFFL);
+ event.doit = isDragable(selection);
+ }
+
+ protected boolean isDragable(ISelection selection) {
+ return true;
+ }
+
+ @Override
+ public void dragSetData(DragSourceEvent event) {
+ event.data = LocalSelectionTransfer.getTransfer().getSelection();
+ }
+
+ @Override
+ public void dragFinished(DragSourceEvent event) {
+ assert event.detail != DND.DROP_MOVE;
+ LocalSelectionTransfer.getTransfer().setSelection(null);
+ LocalSelectionTransfer.getTransfer().setSelectionSetTime(0);
+ }
+}
diff --git a/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/views/ContextHierarchyView.java b/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/views/ContextHierarchyView.java
index c75e574..9885808 100644
--- a/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/views/ContextHierarchyView.java
+++ b/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/views/ContextHierarchyView.java
@@ -46,7 +46,6 @@
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.ui.ActiveViewSelectionDragAdapter;
import org.eclipse.mylyn.internal.java.ui.JavaStructureBridge;
import org.eclipse.mylyn.internal.java.ui.JavaUiBridgePlugin;
import org.eclipse.mylyn.internal.sandbox.ui.JavaContextLabelProvider;