diff options
author | Uwe Stieber | 2013-02-12 16:54:15 +0000 |
---|---|---|
committer | Uwe Stieber | 2013-02-12 16:54:15 +0000 |
commit | ea3bb832760b1e41ee836e0572113cb7bb098e35 (patch) | |
tree | 999f3c88a86ef7108d215f9de5f9d2c3981c1e1b /target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org | |
parent | 3c2b776d96c96c56b8de58ee830dce16d81213bc (diff) | |
download | org.eclipse.tcf-ea3bb832760b1e41ee836e0572113cb7bb098e35.tar.gz org.eclipse.tcf-ea3bb832760b1e41ee836e0572113cb7bb098e35.tar.xz org.eclipse.tcf-ea3bb832760b1e41ee836e0572113cb7bb098e35.zip |
Target Explorer: Rework view category handling. Category contributions can have an enablement expression now and can be filtered if the associated content contribution is not active
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org')
6 files changed, 273 insertions, 229 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/DeleteHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/DeleteHandler.java index 52a103169..11eaa6959 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/DeleteHandler.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/DeleteHandler.java @@ -40,13 +40,13 @@ import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService; import org.eclipse.tcf.te.tcf.locator.model.Model; import org.eclipse.tcf.te.tcf.ui.help.IContextHelpIds; +import org.eclipse.tcf.te.tcf.ui.interfaces.IUIConstants; import org.eclipse.tcf.te.tcf.ui.nls.Messages; import org.eclipse.tcf.te.ui.interfaces.handler.IDeleteHandlerDelegate; import org.eclipse.tcf.te.ui.views.Managers; import org.eclipse.tcf.te.ui.views.ViewsUtil; import org.eclipse.tcf.te.ui.views.editor.EditorInput; import org.eclipse.tcf.te.ui.views.interfaces.ICategory; -import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants; import org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable; import org.eclipse.tcf.te.ui.views.interfaces.categories.ICategoryManager; import org.eclipse.ui.IEditorPart; @@ -76,7 +76,7 @@ public class DeleteHandler extends AbstractHandler { @Override protected void internalDone(Object caller, IStatus status) { // Refresh the view - ViewsUtil.refresh(IUIConstants.ID_EXPLORER); + ViewsUtil.refresh(org.eclipse.tcf.te.ui.views.interfaces.IUIConstants.ID_EXPLORER); } }); } @@ -375,7 +375,7 @@ public class DeleteHandler extends AbstractHandler { } else if (category != null) { // If the parent category is "Favorites", it is always // an "unlink" operation - if (IUIConstants.ID_CAT_FAVORITES.equals(category.getId())) { + if (org.eclipse.tcf.te.ui.views.interfaces.IUIConstants.ID_CAT_FAVORITES.equals(category.getId())) { Operation op = new Operation(); op.node = node; op.type = Operation.TYPE.Unlink; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/OfflineCommandHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/OfflineCommandHandler.java index f896474f9..95ae02459 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/OfflineCommandHandler.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/OfflineCommandHandler.java @@ -38,9 +38,9 @@ import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshSe import org.eclipse.tcf.te.tcf.locator.model.Model; import org.eclipse.tcf.te.tcf.ui.activator.UIPlugin; import org.eclipse.tcf.te.tcf.ui.help.IContextHelpIds; +import org.eclipse.tcf.te.tcf.ui.interfaces.IUIConstants; import org.eclipse.tcf.te.tcf.ui.nls.Messages; import org.eclipse.tcf.te.ui.views.Managers; -import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants; import org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable; import org.eclipse.ui.handlers.HandlerUtil; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/interfaces/IUIConstants.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/interfaces/IUIConstants.java new file mode 100644 index 000000000..057fc2d36 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/interfaces/IUIConstants.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2013 Wind River Systems, Inc. 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.ui.interfaces; + +/** + * UI constants. + */ +public interface IUIConstants { + + // ***** Define the constants for the default TCF view categories ***** + + /** + * Category: "My Targets" + */ + public static final String ID_CAT_MY_TARGETS = "org.eclipse.tcf.te.tcf.ui.category.mytargets"; //$NON-NLS-1$ + + /** + * Category: Neighborhood + */ + public static final String ID_CAT_NEIGHBORHOOD = "org.eclipse.tcf.te.tcf.ui.category.neighborhood"; //$NON-NLS-1$ +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/CategorizableAdapter.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/CategorizableAdapter.java index 73874f758..828737c3a 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/CategorizableAdapter.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/adapters/CategorizableAdapter.java @@ -14,9 +14,9 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.core.runtime.Assert; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; +import org.eclipse.tcf.te.tcf.ui.interfaces.IUIConstants; import org.eclipse.tcf.te.ui.views.Managers; import org.eclipse.tcf.te.ui.views.interfaces.ICategory; -import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants; import org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable; /** @@ -87,7 +87,7 @@ public class CategorizableAdapter implements ICategorizable { } // ALL: Destination is "Neighborhood" -> not valid - if (IUIConstants.ID_CAT_FAVORITES.equals(category.getId())) { + if (org.eclipse.tcf.te.ui.views.interfaces.IUIConstants.ID_CAT_FAVORITES.equals(category.getId())) { return true; } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/ContentProviderDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/ContentProviderDelegate.java index 57d2f402b..2e2e2f06c 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/ContentProviderDelegate.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/ContentProviderDelegate.java @@ -33,6 +33,7 @@ import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupSer import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService; import org.eclipse.tcf.te.tcf.locator.model.Model; import org.eclipse.tcf.te.tcf.ui.activator.UIPlugin; +import org.eclipse.tcf.te.tcf.ui.interfaces.IUIConstants; import org.eclipse.tcf.te.tcf.ui.internal.preferences.IPreferenceKeys; import org.eclipse.tcf.te.tcf.ui.navigator.nodes.PeerRedirectorGroupNode; import org.eclipse.tcf.te.ui.swt.DisplayUtil; @@ -40,7 +41,6 @@ import org.eclipse.tcf.te.ui.views.Managers; import org.eclipse.tcf.te.ui.views.extensions.CategoriesExtensionPointManager; import org.eclipse.tcf.te.ui.views.interfaces.ICategory; import org.eclipse.tcf.te.ui.views.interfaces.IRoot; -import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants; import org.eclipse.tcf.te.ui.views.interfaces.categories.ICategorizable; import org.eclipse.ui.IMemento; import org.eclipse.ui.internal.navigator.NavigatorFilterService; @@ -153,7 +153,7 @@ public class ContentProviderDelegate implements ICommonContentProvider, ITreePat final IPeerModel[] peers = model.getPeers(); final List<IPeerModel> candidates = new ArrayList<IPeerModel>(); - if (IUIConstants.ID_CAT_FAVORITES.equals(catID)) { + if (org.eclipse.tcf.te.ui.views.interfaces.IUIConstants.ID_CAT_FAVORITES.equals(catID)) { for (IPeerModel peer : peers) { ICategorizable categorizable = (ICategorizable)peer.getAdapter(ICategorizable.class); if (categorizable == null) { @@ -184,6 +184,14 @@ public class ContentProviderDelegate implements ICommonContentProvider, ITreePat // Static peers, or if launched by current user -> add automatically to "My Targets" boolean startedByCurrentUser = System.getProperty("user.name").equals(peer.getPeer().getUserName()); //$NON-NLS-1$ + if (!startedByCurrentUser) { + // If the "Neighborhood" category is not visible, ignore the startedByCurrentUser flag + ICategory neighborhoodCat = CategoriesExtensionPointManager.getInstance().getCategory(IUIConstants.ID_CAT_NEIGHBORHOOD, false); + if (neighborhoodCat != null && !neighborhoodCat.isEnabled()) { + startedByCurrentUser = true; + } + } + boolean isMyTargets = Managers.getCategoryManager().belongsTo(catID, categorizable.getId()); if (!isMyTargets && (isStatic || startedByCurrentUser)) { // "Value-add's" are not saved to the category persistence automatically @@ -216,6 +224,14 @@ public class ContentProviderDelegate implements ICommonContentProvider, ITreePat boolean isStatic = peer.isStatic(); boolean startedByCurrentUser = System.getProperty("user.name").equals(peer.getPeer().getUserName()); //$NON-NLS-1$ + if (startedByCurrentUser) { + // If the "My Targets" category is not visible, ignore the startedByCurrentUser flag + ICategory myTargetsCat = CategoriesExtensionPointManager.getInstance().getCategory(IUIConstants.ID_CAT_MY_TARGETS, false); + if (myTargetsCat != null && !myTargetsCat.isEnabled()) { + startedByCurrentUser = false; + } + } + boolean isNeighborhood = Managers.getCategoryManager().belongsTo(catID, categorizable.getId()); if (!isNeighborhood && !isStatic && !startedByCurrentUser) { // "Neighborhood" is always transient @@ -355,9 +371,9 @@ public class ContentProviderDelegate implements ICommonContentProvider, ITreePat List<TreePath> pathes = new ArrayList<TreePath>(); if (element instanceof IPeerModel) { - if (Managers.getCategoryManager().belongsTo(IUIConstants.ID_CAT_FAVORITES, ((IPeerModel)element).getPeerId())) { + if (Managers.getCategoryManager().belongsTo(org.eclipse.tcf.te.ui.views.interfaces.IUIConstants.ID_CAT_FAVORITES, ((IPeerModel)element).getPeerId())) { // Get the "Favorites" category - ICategory favCategory = CategoriesExtensionPointManager.getInstance().getCategory(IUIConstants.ID_CAT_FAVORITES, false); + ICategory favCategory = CategoriesExtensionPointManager.getInstance().getCategory(org.eclipse.tcf.te.ui.views.interfaces.IUIConstants.ID_CAT_FAVORITES, false); if (favCategory != null) { pathes.add(new TreePath(new Object[] { favCategory })); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/dnd/CommonDnD.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/dnd/CommonDnD.java index 257d79059..b5babc0e4 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/dnd/CommonDnD.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/navigator/dnd/CommonDnD.java @@ -1,219 +1,219 @@ -/*******************************************************************************
- * Copyright (c) 2012 Wind River Systems, Inc. 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:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.tcf.ui.navigator.dnd;
-
-import java.util.Iterator;
-
-import org.eclipse.jface.util.LocalSelectionTransfer;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TreePath;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.swt.dnd.DND;
-import org.eclipse.swt.dnd.TransferData;
-import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
-import org.eclipse.tcf.te.ui.views.Managers;
-import org.eclipse.tcf.te.ui.views.ViewsUtil;
-import org.eclipse.tcf.te.ui.views.interfaces.ICategory;
-import org.eclipse.tcf.te.ui.views.interfaces.IRoot;
-import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants;
-import org.eclipse.ui.navigator.CommonDropAdapter;
-
-/**
- * Common DND operation implementations.
- */
-public class CommonDnD {
-
- /**
- * If the current selection is draggable.
- *
- * @param selection The currently selected nodes.
- * @return true if it is draggable.
- */
- public static boolean isDraggable(IStructuredSelection selection) {
- if (selection.isEmpty()) {
- return false;
- }
- Object[] objects = selection.toArray();
- for (Object object : objects) {
- if (!isDraggableObject(object)) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * If the specified object is a draggable element.
- *
- * @param object The object to be dragged.
- * @return true if it is draggable.
- */
- private static boolean isDraggableObject(Object object) {
- return object instanceof IPeerModel;
- }
-
- /**
- * Perform the drop operation over dragged selection.
- *
- * @param dropAdapter The common drop adapter.
- * @param target The target Object to be moved to.
- * @param operations The current DnD operation.
- * @param selection The local selection being dropped.
- * @return true if the dropping is successful.
- */
- public static boolean dropLocalSelection(CommonDropAdapter dropAdapter, Object target, int operations, IStructuredSelection selection) {
- if (target instanceof ICategory) {
- ICategory hovered = (ICategory) target;
- if (IUIConstants.ID_CAT_FAVORITES.equals(hovered.getId())
- || IUIConstants.ID_CAT_MY_TARGETS.equals(hovered.getId())) {
- Iterator<?> iterator = selection.iterator();
- while (iterator.hasNext()) {
- Object element = iterator.next();
- if (!isDraggableObject(element)) {
- continue;
- }
- Managers.getCategoryManager().add(hovered.getId(), ((IPeerModel)element).getPeerId());
- }
- // Fire a refresh of the view
- ViewsUtil.refresh(IUIConstants.ID_EXPLORER);
- }
- } else if (target instanceof IRoot) {
- Iterator<?> iterator = selection.iterator();
- while (iterator.hasNext()) {
- Object element = iterator.next();
- if (!isDraggableObject(element)) {
- continue;
- }
-
- // To determine the parent category, we have to look at the tree path
- TreePath[] pathes = selection instanceof TreeSelection ? ((TreeSelection)selection).getPathsFor(element) : null;
- if (pathes != null && pathes.length > 0) {
- for (TreePath path : pathes) {
- ICategory category = null;
- TreePath parentPath = path.getParentPath();
- while (parentPath != null) {
- if (parentPath.getLastSegment() instanceof ICategory) {
- category = (ICategory)parentPath.getLastSegment();
- break;
- }
- parentPath = parentPath.getParentPath();
- }
-
- if (category != null) {
- Managers.getCategoryManager().remove(category.getId(), ((IPeerModel)element).getPeerId());
- }
- }
- }
- }
-
- // Fire a refresh of the view
- ViewsUtil.refresh(IUIConstants.ID_EXPLORER);
- }
-
- return false;
- }
-
- /**
- * Validate dropping when the elements being dragged are local selection.
- *
- * @param dropAdapter The common drop adapter.
- * @param target The target object.
- * @param operation The DnD operation.
- * @param transferType The transfered data type.
- *
- * @return true if it is valid for dropping.
- */
- public static boolean validateLocalSelectionDrop(CommonDropAdapter dropAdapter, Object target, int operation, TransferData transferType) {
- int overrideOperation = -1;
- boolean valid = false;
-
- // The default operation should be always "DROP_MOVE"
- if ((operation & DND.DROP_MOVE) == 0) {
- overrideOperation = DND.DROP_MOVE;
- }
-
- LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
- IStructuredSelection selection = (IStructuredSelection) transfer.getSelection();
-
- if (target instanceof ICategory) {
- ICategory category = (ICategory) target;
-
- // Dragging to the "Neighborhood" category is not possible
- if (!IUIConstants.ID_CAT_NEIGHBORHOOD.equals(category.getId())) {
- boolean allow = true;
- Iterator<?> iterator = selection.iterator();
- while (iterator.hasNext()) {
- Object element = iterator.next();
- if (!isDraggableObject(element)) {
- allow = false;
- break;
- }
- if (Managers.getCategoryManager().belongsTo(category.getId(), ((IPeerModel)element).getPeerId())) {
- allow = false;
- break;
- }
- }
- valid = allow;
-
- // If the target is the "Favorites" or the "My Targets" category,
- // force DROP_LINK operation
- if ((IUIConstants.ID_CAT_FAVORITES.equals(category.getId()) || IUIConstants.ID_CAT_MY_TARGETS.equals(category.getId()))
- && (operation & DND.DROP_LINK) == 0) {
- overrideOperation = DND.DROP_LINK;
- }
- }
- } else if (target instanceof IRoot) {
- // Allow to drag into empty space either from "Favorites"
- // or "My Targets" category only
- boolean allow = true;
- Iterator<?> iterator = selection.iterator();
- while (iterator.hasNext()) {
- Object element = iterator.next();
- if (!isDraggableObject(element)) {
- allow = false;
- break;
- }
-
- // To determine the parent category, we have to look at the tree path
- TreePath[] pathes = selection instanceof TreeSelection ? ((TreeSelection)selection).getPathsFor(element) : null;
- if (pathes != null && pathes.length > 0) {
- for (TreePath path : pathes) {
- ICategory category = null;
- TreePath parentPath = path.getParentPath();
- while (parentPath != null) {
- if (parentPath.getLastSegment() instanceof ICategory) {
- category = (ICategory)parentPath.getLastSegment();
- break;
- }
- parentPath = parentPath.getParentPath();
- }
-
- if (category == null || IUIConstants.ID_CAT_NEIGHBORHOOD.equals(category.getId())) {
- allow = false;
- break;
- }
- }
- }
- }
- valid = allow;
- }
-
- if (dropAdapter != null) {
- if (!valid) {
- dropAdapter.overrideOperation(DND.DROP_NONE);
- }
- else if (overrideOperation != -1) {
- dropAdapter.overrideOperation(overrideOperation);
- }
- }
-
- return valid;
- }
-}
+/******************************************************************************* + * Copyright (c) 2012 Wind River Systems, Inc. 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.tcf.ui.navigator.dnd; + +import java.util.Iterator; + +import org.eclipse.jface.util.LocalSelectionTransfer; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreePath; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.TransferData; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; +import org.eclipse.tcf.te.tcf.ui.interfaces.IUIConstants; +import org.eclipse.tcf.te.ui.views.Managers; +import org.eclipse.tcf.te.ui.views.ViewsUtil; +import org.eclipse.tcf.te.ui.views.interfaces.ICategory; +import org.eclipse.tcf.te.ui.views.interfaces.IRoot; +import org.eclipse.ui.navigator.CommonDropAdapter; + +/** + * Common DND operation implementations. + */ +public class CommonDnD { + + /** + * If the current selection is draggable. + * + * @param selection The currently selected nodes. + * @return true if it is draggable. + */ + public static boolean isDraggable(IStructuredSelection selection) { + if (selection.isEmpty()) { + return false; + } + Object[] objects = selection.toArray(); + for (Object object : objects) { + if (!isDraggableObject(object)) { + return false; + } + } + return true; + } + + /** + * If the specified object is a draggable element. + * + * @param object The object to be dragged. + * @return true if it is draggable. + */ + private static boolean isDraggableObject(Object object) { + return object instanceof IPeerModel; + } + + /** + * Perform the drop operation over dragged selection. + * + * @param dropAdapter The common drop adapter. + * @param target The target Object to be moved to. + * @param operations The current DnD operation. + * @param selection The local selection being dropped. + * @return true if the dropping is successful. + */ + public static boolean dropLocalSelection(CommonDropAdapter dropAdapter, Object target, int operations, IStructuredSelection selection) { + if (target instanceof ICategory) { + ICategory hovered = (ICategory) target; + if (org.eclipse.tcf.te.ui.views.interfaces.IUIConstants.ID_CAT_FAVORITES.equals(hovered.getId()) + || IUIConstants.ID_CAT_MY_TARGETS.equals(hovered.getId())) { + Iterator<?> iterator = selection.iterator(); + while (iterator.hasNext()) { + Object element = iterator.next(); + if (!isDraggableObject(element)) { + continue; + } + Managers.getCategoryManager().add(hovered.getId(), ((IPeerModel)element).getPeerId()); + } + // Fire a refresh of the view + ViewsUtil.refresh(org.eclipse.tcf.te.ui.views.interfaces.IUIConstants.ID_EXPLORER); + } + } else if (target instanceof IRoot) { + Iterator<?> iterator = selection.iterator(); + while (iterator.hasNext()) { + Object element = iterator.next(); + if (!isDraggableObject(element)) { + continue; + } + + // To determine the parent category, we have to look at the tree path + TreePath[] pathes = selection instanceof TreeSelection ? ((TreeSelection)selection).getPathsFor(element) : null; + if (pathes != null && pathes.length > 0) { + for (TreePath path : pathes) { + ICategory category = null; + TreePath parentPath = path.getParentPath(); + while (parentPath != null) { + if (parentPath.getLastSegment() instanceof ICategory) { + category = (ICategory)parentPath.getLastSegment(); + break; + } + parentPath = parentPath.getParentPath(); + } + + if (category != null) { + Managers.getCategoryManager().remove(category.getId(), ((IPeerModel)element).getPeerId()); + } + } + } + } + + // Fire a refresh of the view + ViewsUtil.refresh(org.eclipse.tcf.te.ui.views.interfaces.IUIConstants.ID_EXPLORER); + } + + return false; + } + + /** + * Validate dropping when the elements being dragged are local selection. + * + * @param dropAdapter The common drop adapter. + * @param target The target object. + * @param operation The DnD operation. + * @param transferType The transfered data type. + * + * @return true if it is valid for dropping. + */ + public static boolean validateLocalSelectionDrop(CommonDropAdapter dropAdapter, Object target, int operation, TransferData transferType) { + int overrideOperation = -1; + boolean valid = false; + + // The default operation should be always "DROP_MOVE" + if ((operation & DND.DROP_MOVE) == 0) { + overrideOperation = DND.DROP_MOVE; + } + + LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); + IStructuredSelection selection = (IStructuredSelection) transfer.getSelection(); + + if (target instanceof ICategory) { + ICategory category = (ICategory) target; + + // Dragging to the "Neighborhood" category is not possible + if (!IUIConstants.ID_CAT_NEIGHBORHOOD.equals(category.getId())) { + boolean allow = true; + Iterator<?> iterator = selection.iterator(); + while (iterator.hasNext()) { + Object element = iterator.next(); + if (!isDraggableObject(element)) { + allow = false; + break; + } + if (Managers.getCategoryManager().belongsTo(category.getId(), ((IPeerModel)element).getPeerId())) { + allow = false; + break; + } + } + valid = allow; + + // If the target is the "Favorites" or the "My Targets" category, + // force DROP_LINK operation + if ((org.eclipse.tcf.te.ui.views.interfaces.IUIConstants.ID_CAT_FAVORITES.equals(category.getId()) || IUIConstants.ID_CAT_MY_TARGETS.equals(category.getId())) + && (operation & DND.DROP_LINK) == 0) { + overrideOperation = DND.DROP_LINK; + } + } + } else if (target instanceof IRoot) { + // Allow to drag into empty space either from "Favorites" + // or "My Targets" category only + boolean allow = true; + Iterator<?> iterator = selection.iterator(); + while (iterator.hasNext()) { + Object element = iterator.next(); + if (!isDraggableObject(element)) { + allow = false; + break; + } + + // To determine the parent category, we have to look at the tree path + TreePath[] pathes = selection instanceof TreeSelection ? ((TreeSelection)selection).getPathsFor(element) : null; + if (pathes != null && pathes.length > 0) { + for (TreePath path : pathes) { + ICategory category = null; + TreePath parentPath = path.getParentPath(); + while (parentPath != null) { + if (parentPath.getLastSegment() instanceof ICategory) { + category = (ICategory)parentPath.getLastSegment(); + break; + } + parentPath = parentPath.getParentPath(); + } + + if (category == null || IUIConstants.ID_CAT_NEIGHBORHOOD.equals(category.getId())) { + allow = false; + break; + } + } + } + } + valid = allow; + } + + if (dropAdapter != null) { + if (!valid) { + dropAdapter.overrideOperation(DND.DROP_NONE); + } + else if (overrideOperation != -1) { + dropAdapter.overrideOperation(overrideOperation); + } + } + + return valid; + } +} |