Example usage for org.eclipse.jface.viewers ViewerDropAdapter LOCATION_NONE

List of usage examples for org.eclipse.jface.viewers ViewerDropAdapter LOCATION_NONE

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ViewerDropAdapter LOCATION_NONE.

Prototype

int LOCATION_NONE

To view the source code for org.eclipse.jface.viewers ViewerDropAdapter LOCATION_NONE.

Click Source Link

Document

Constant describing the position of the cursor relative to the target object.

Usage

From source file:net.yatomiya.nicherry.services.explorer.MTreeUtils.java

License:Open Source License

public static LocationInfo getDropLocation(MExplorerTreeNode target, int loc) {
    MExplorerTreeNode parent = null;//ww  w  .j  a v  a2s.c  om
    int childIndex = 0;

    if (target.isRoot()) {
        return new LocationInfo(target, 0);
    }

    parent = target.getParent();
    switch (loc) {
    case ViewerDropAdapter.LOCATION_BEFORE:
        childIndex = parent.getChildren().indexOf(target);
        break;
    case ViewerDropAdapter.LOCATION_ON:
        if (isLeaf(target)) {
            childIndex = parent.getChildren().indexOf(target);
        } else {
            parent = target;
            childIndex = parent.getChildren().size();
        }
        break;
    case ViewerDropAdapter.LOCATION_AFTER:
    case ViewerDropAdapter.LOCATION_NONE:
        childIndex = parent.getChildren().indexOf(target) + 1;
        break;
    }

    return new LocationInfo(parent, childIndex);
}

From source file:org.eclipse.egit.ui.internal.rebase.RebaseInteractiveDropTargetListener.java

License:Open Source License

@Override
public boolean performDrop(Object data) {
    if (!this.rebaseInteractiveView.isDragAndDropEnabled())
        return false;

    if (!(data instanceof IStructuredSelection))
        return false;

    final IStructuredSelection structuredSelection = (IStructuredSelection) data;
    List selectionList = structuredSelection.toList();

    if (selectionList.contains(getCurrentTarget()))
        return false;

    List<RebaseInteractivePlan.PlanElement> sourceElements = new ArrayList<>();
    for (Object obj : selectionList) {
        if (obj instanceof RebaseInteractivePlan.PlanElement)
            sourceElements.add((RebaseInteractivePlan.PlanElement) obj);
    }//from  ww w.j a v  a  2s.  c o m

    if (sourceElements.isEmpty())
        return false;

    Object targetObj = getCurrentTarget();
    if (!(targetObj instanceof RebaseInteractivePlan.PlanElement))
        return false;
    RebaseInteractivePlan.PlanElement targetElement = (RebaseInteractivePlan.PlanElement) targetObj;

    boolean before = false;
    switch (getCurrentLocation()) {
    case ViewerDropAdapter.LOCATION_BEFORE:
        before = true;
        break;
    case ViewerDropAdapter.LOCATION_NONE:
        return false;
    }

    if (!before)
        Collections.reverse(sourceElements);

    if (RebaseInteractivePreferences.isOrderReversed())
        before = !before;

    for (RebaseInteractivePlan.PlanElement element : sourceElements)
        rebaseInteractiveView.getCurrentPlan().moveTodoEntry(element, targetElement, before);

    return true;
}

From source file:org.eclipse.egit.ui.internal.rebase.RebaseInteractiveDropTargetListener.java

License:Open Source License

@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
    if (!this.rebaseInteractiveView.isDragAndDropEnabled())
        return false;
    if (getCurrentTarget() instanceof RebaseInteractivePlan.PlanElement) {
        switch (getCurrentLocation()) {
        case ViewerDropAdapter.LOCATION_AFTER:
            return true;
        case ViewerDropAdapter.LOCATION_ON:
            return false;
        case ViewerDropAdapter.LOCATION_BEFORE:
            return true;
        case ViewerDropAdapter.LOCATION_NONE:
            return false;
        }//from   w  w  w .j a  va  2 s . com
    }
    return false;
}

From source file:org.eclipse.papyrus.modelexplorer.dnd.CommonDropAdapterAssistant.java

License:Open Source License

/**
 * get the list of good command by taking in account if this is a change order or a drop into
 * @param target the target object of the drop
 * @return the list of command//from   www  .  j  av  a  2  s.c om
 */
public List<Command> getDrop(Object target) {
    CommonDropAdapter dropAdapter = getCommonDropAdapter();
    List<Command> commandList = new ArrayList<Command>();
    switch (dropAdapter.getCurrentOperation()) {
    case DND.DROP_MOVE:
        if (dropAdapter.getCurrentLocation() == ViewerDropAdapter.LOCATION_BEFORE) {
            if (target instanceof ModelElementItem) {
                commandList = getOrderChangeCommand(target, true);
            }
        } else if (dropAdapter.getCurrentLocation() == ViewerDropAdapter.LOCATION_AFTER) {
            if (target instanceof ModelElementItem) {
                commandList = getOrderChangeCommand(target, false);
            }
        } else if (dropAdapter.getCurrentLocation() == ViewerDropAdapter.LOCATION_ON) {
            if (target instanceof ModelElementItem) {
                commandList = getDropIntoCommand(target, null);
            }
            if (target instanceof LinkItem) {
                commandList = getDropIntoCommand(((LinkItem) target).getParent(),
                        ((LinkItem) target).getReference());
            }
        }

        else if (dropAdapter.getCurrentLocation() == ViewerDropAdapter.LOCATION_NONE) {
        }
        break;
    }
    return commandList;
}

From source file:org.eclipse.papyrus.views.modelexplorer.dnd.CommonDropAdapterAssistant.java

License:Open Source License

/**
 * get the list of good command by taking in account if this is a change order or a drop into
 * @param target the target object of the drop
 * @return the list of command//  w  w w.  j av  a  2s  . c o  m
 */
public CompoundCommand getDrop(Object target) {
    CommonDropAdapter dropAdapter = getCommonDropAdapter();
    List<Command> commandList = new ArrayList<Command>();
    switch (dropAdapter.getCurrentOperation()) {
    case DND.DROP_MOVE:
        if (dropAdapter.getCurrentLocation() == ViewerDropAdapter.LOCATION_BEFORE) {
            if (target instanceof ModelElementItem) {
                commandList = getOrderChangeCommand(target, true);
            }
        } else if (dropAdapter.getCurrentLocation() == ViewerDropAdapter.LOCATION_AFTER) {
            if (target instanceof ModelElementItem) {
                commandList = getOrderChangeCommand(target, false);
            }
        } else if (dropAdapter.getCurrentLocation() == ViewerDropAdapter.LOCATION_ON) {
            if (target instanceof ModelElementItem) {
                commandList = getDropIntoCommand(target, null);
            }
            if (target instanceof LinkItem) {
                commandList = getDropIntoCommand(((LinkItem) target).getParent(),
                        ((LinkItem) target).getReference());
            }
        }

        else if (dropAdapter.getCurrentLocation() == ViewerDropAdapter.LOCATION_NONE) {
        }
        break;
    }
    return new CompoundCommand(commandList);
}

From source file:org.eclipse.rcptt.ctx.capability.ui.views.CapabiltyContextTable.java

License:Open Source License

@Override
protected boolean doPerformDrop(Object data, Object currentTarget, int currentLocation) {
    if (data instanceof IResource[]) {
        IResource[] resources = (IResource[]) data;
        EList<Object> content = getContents();
        int targetPosition = content.size() - 1;
        if (currentTarget != null) {
            targetPosition = content.indexOf(currentTarget);
        }/*  w ww  .ja  v a  2  s  . c o m*/
        if (currentLocation == ViewerDropAdapter.LOCATION_AFTER
                || currentLocation == ViewerDropAdapter.LOCATION_NONE) {
            targetPosition++;
        }
        EList<Object> contents = getContents();
        List<String> newContents = new ArrayList<String>();
        for (IResource resource : resources) {
            IQ7NamedElement element = ResourceUtils.getNamedElementByResource(resource);
            if (filter.isValidToAdd(element, getNamedElement())) {
                try {
                    newContents.add(element.getID());
                } catch (ModelException e) {
                    Q7UIPlugin.log(e);
                }
            }
        }
        if (targetPosition != -1) {
            contents.addAll(targetPosition, newContents);
        } else {
            contents.addAll(newContents);
        }
        refresh();

        return true;
    } else {
        return super.doPerformDrop(data, currentTarget, currentLocation);
    }
}

From source file:org.eclipse.rcptt.ui.commons.EObjectTable.java

License:Open Source License

protected boolean doPerformDrop(Object data, Object currentTarget, int currentLocation) {
    Object[] toDrop = (Object[]) data;
    for (Object toDropObject : toDrop) {
        if (toDropObject.equals(currentTarget)) {
            return false;
        }//from   w w w .jav a2  s .  c  o  m
    }

    EList<Object> content = getContents();
    int targetPosition = content.size() - 1;
    if (currentTarget != null) {
        targetPosition = content.indexOf(currentTarget);
    }

    for (int i = 0; i < toDrop.length; i++) {
        Object toDropObject = toDrop[i];
        int oldPosition = content.indexOf(toDropObject);

        if (oldPosition == -1) {
            if (currentLocation == ViewerDropAdapter.LOCATION_AFTER
                    || currentLocation == ViewerDropAdapter.LOCATION_NONE) {
                targetPosition++;
            }
            if (targetPosition != -1) {
                content.add(targetPosition, toDropObject);
            } else {
                content.add(toDropObject);
            }
        } else if (oldPosition < targetPosition && currentLocation == ViewerDropAdapter.LOCATION_BEFORE) {
            content.move(targetPosition - 1, oldPosition);
        } else if (oldPosition > targetPosition && currentLocation == ViewerDropAdapter.LOCATION_AFTER) {
            content.move(targetPosition + 1, oldPosition);
        } else {
            if (targetPosition < 0) {
                return false;
            }
            content.move(targetPosition, oldPosition);
        }
    }
    refresh();
    return true;
}

From source file:org.eclipse.rcptt.ui.commons.TestSuiteTableViewer.java

License:Open Source License

protected boolean doPerformDrop(Object data, Object currentTarget, int currentLocation) {
    flushAndResetTableSort();/*from   w ww.  j  a  v a 2s .  c o  m*/
    testSuite.setManuallyOrdered(true);
    if (data instanceof IResource[]) {
        IResource[] resources = (IResource[]) data;
        int targetPosition = testSuite.getItems().size() - 1;
        if (currentTarget != null) {
            targetPosition = testSuite.getItems().indexOf(currentTarget);
        }
        if (currentLocation == ViewerDropAdapter.LOCATION_AFTER
                || currentLocation == ViewerDropAdapter.LOCATION_NONE) {
            targetPosition++;
        }
        for (IResource resource : resources) {
            if (resource instanceof IFile) {
                IQ7NamedElement element = getNamedElementByResource(resource);
                if (isValidToAdd(element)) {
                    addItem(element, targetPosition);
                    targetPosition++;
                }
            } else if (resource instanceof IContainer) {
                addFolder((IContainer) resource, targetPosition);
            }
        }
        return true;
    } else {
        return doPerformInternalDrop(data, currentTarget, currentLocation);
    }
}

From source file:org.eclipse.rcptt.ui.commons.TestSuiteTableViewer.java

License:Open Source License

protected boolean doPerformInternalDrop(Object data, Object currentTarget, int currentLocation) {
    EList<TestSuiteItem> content = testSuite.getItems();

    int shiftLastPosition = 0;
    int targetPosition = content.size() - 1;

    if (currentTarget != null) {
        targetPosition = content.indexOf(currentTarget);
    }/*from  ww  w . j  a  v a2 s . c  o m*/
    if (currentLocation == ViewerDropAdapter.LOCATION_AFTER
            || currentLocation == ViewerDropAdapter.LOCATION_NONE) {
        shiftLastPosition++;
    }

    int shiftNextLandingPosition = 0;
    List<TestSuiteItem> toDrop = convertStringsToItems(data);

    for (TestSuiteItem toDropObject : toDrop) {
        int fromPosition = testSuite.getItems().indexOf(toDropObject);
        int toPosition = targetPosition + shiftNextLandingPosition;

        if (fromPosition == -1) {
            testSuite.getItems().add(toPosition + shiftLastPosition, toDropObject);
            shiftNextLandingPosition++;
        } else {
            testSuite.getItems().move(toPosition, fromPosition);
            if (fromPosition >= targetPosition) {
                shiftNextLandingPosition++;
            }
        }
    }

    updateItems();
    return true;
}

From source file:org.eclipse.rcptt.ui.controls.ContextsTable.java

License:Open Source License

@Override
protected boolean doPerformDrop(Object data, Object currentTarget, int currentLocation) {
    if (data instanceof IResource[]) {
        IResource[] resources = (IResource[]) data;
        EList<Object> content = getContents();
        int targetPosition = content.size() - 1;
        if (currentTarget != null) {
            targetPosition = content.indexOf(currentTarget);
        }//from   w  w  w  .ja  v a  2s. co m
        if (currentLocation == ViewerDropAdapter.LOCATION_AFTER
                || currentLocation == ViewerDropAdapter.LOCATION_NONE) {
            targetPosition++;
        }
        EList<Object> contents = getContents();
        List<String> newContents = new ArrayList<String>();
        for (IResource resource : resources) {
            IQ7NamedElement element = getNamedElementByResource(resource);
            if (isValidToAdd(element)) {
                try {
                    newContents.add(element.getID());
                } catch (ModelException e) {
                    Q7UIPlugin.log(e);
                }
            }
        }
        if (targetPosition != -1) {
            contents.addAll(targetPosition, newContents);
        } else {
            contents.addAll(newContents);
        }
        refresh();

        return true;
    } else {
        return super.doPerformDrop(data, currentTarget, currentLocation);
    }
}