Search in sources :

Example 16 with TransferData

use of org.eclipse.swt.dnd.TransferData in project erlide_eclipse by erlang.

the class MoveFunctionDropHandler method handleDrop.

@Override
public IStatus handleDrop(final CommonDropAdapter dropAdapter, final DropTargetEvent dropTargetEvent, final Object target) {
    // get the source data
    final TransferData td = dropAdapter.getCurrentTransfer();
    final ISelection sel = (ISelection) LocalSelectionTransfer.getTransfer().nativeToJava(td);
    final TreeSelection s = (TreeSelection) sel;
    try {
        GlobalParameters.setSelection(s);
    } catch (final WranglerException e1) {
        e1.printStackTrace();
    }
    // get the target data
    String moduleName;
    IFile file;
    if (target instanceof IFile) {
        file = (IFile) target;
    } else {
        file = (IFile) ((IErlElement) target).getResource();
    }
    moduleName = file.getName();
    moduleName = moduleName.substring(0, moduleName.lastIndexOf("."));
    final MoveFunctionRefactoring refactoring = new MoveFunctionRefactoring();
    refactoring.setUserInput(moduleName);
    final RefactoringWizard wizard = new DefaultWranglerRefactoringWizard(refactoring, RefactoringWizard.DIALOG_BASED_USER_INTERFACE, new ArrayList<WranglerPage>());
    final Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
    final RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
    try {
        op.run(shell, refactoring.getName());
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
    return Status.OK_STATUS;
}
Also used : IFile(org.eclipse.core.resources.IFile) MoveFunctionRefactoring(org.erlide.wrangler.refactoring.core.internal.MoveFunctionRefactoring) WranglerException(org.erlide.wrangler.refactoring.exception.WranglerException) WranglerException(org.erlide.wrangler.refactoring.exception.WranglerException) IErlElement(org.erlide.engine.model.IErlElement) Shell(org.eclipse.swt.widgets.Shell) RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) TransferData(org.eclipse.swt.dnd.TransferData) DefaultWranglerRefactoringWizard(org.erlide.wrangler.refactoring.ui.wizard.DefaultWranglerRefactoringWizard) RefactoringWizard(org.eclipse.ltk.ui.refactoring.RefactoringWizard) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ISelection(org.eclipse.jface.viewers.ISelection) DefaultWranglerRefactoringWizard(org.erlide.wrangler.refactoring.ui.wizard.DefaultWranglerRefactoringWizard) WranglerPage(org.erlide.wrangler.refactoring.ui.wizardpages.WranglerPage)

Example 17 with TransferData

use of org.eclipse.swt.dnd.TransferData in project netxms by netxms.

the class ScriptEditorView method canPaste.

/**
 * Check if paste action can work
 *
 * @return
 */
private boolean canPaste() {
    Clipboard cb = new Clipboard(Display.getCurrent());
    TransferData[] available = cb.getAvailableTypes();
    boolean enabled = false;
    for (int i = 0; i < available.length; i++) {
        if (TextTransfer.getInstance().isSupportedType(available[i])) {
            enabled = true;
            break;
        }
    }
    cb.dispose();
    return enabled;
}
Also used : TransferData(org.eclipse.swt.dnd.TransferData) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 18 with TransferData

use of org.eclipse.swt.dnd.TransferData in project netxms by netxms.

the class PredefinedMap method addDropSupport.

/**
 * Add drop support
 */
private void addDropSupport() {
    final Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new ViewerDropAdapter(viewer) {

        private int x;

        private int y;

        @SuppressWarnings("rawtypes")
        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            if (!LocalSelectionTransfer.getTransfer().isSupportedType(transferType))
                return false;
            IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
            Iterator it = selection.iterator();
            while (it.hasNext()) {
                Object object = it.next();
                if (!((object instanceof AbstractObject) && ((AbstractObject) object).isAllowedOnMap()))
                    return false;
            }
            return true;
        }

        @SuppressWarnings("unchecked")
        @Override
        public boolean performDrop(Object data) {
            IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
            addObjectsFromList(selection.toList(), viewer.getControl().toControl(x, y));
            return true;
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.ViewerDropAdapter#dropAccept(org.eclipse
			 * .swt.dnd.DropTargetEvent)
			 */
        @Override
        public void dropAccept(DropTargetEvent event) {
            x = event.x;
            y = event.y;
            super.dropAccept(event);
        }
    });
}
Also used : TransferData(org.eclipse.swt.dnd.TransferData) AbstractObject(org.netxms.client.objects.AbstractObject) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Iterator(java.util.Iterator) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) AbstractObject(org.netxms.client.objects.AbstractObject) NetworkMapObject(org.netxms.client.maps.elements.NetworkMapObject) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Point(org.eclipse.swt.graphics.Point)

Example 19 with TransferData

use of org.eclipse.swt.dnd.TransferData in project netxms by netxms.

the class ObjectTree method enableDropSupport.

/**
 * Enable drop support in object tree
 */
public // SubtreeType infrastructure
void enableDropSupport(// SubtreeType infrastructure
final ObjectBrowser obj) {
    final Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
    objectTree.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new ViewerDropAdapter(objectTree) {

        int operation = 0;

        @Override
        public boolean performDrop(Object data) {
            TreeSelection selection = (TreeSelection) data;
            List<?> movableSelection = selection.toList();
            for (int i = 0; i < movableSelection.size(); i++) {
                AbstractObject movableObject = (AbstractObject) movableSelection.get(i);
                TreePath path = selection.getPaths()[0];
                AbstractObject parent = (AbstractObject) path.getSegment(path.getSegmentCount() - 2);
                obj.performObjectMove((AbstractObject) getCurrentTarget(), parent, movableObject, operation == DND.DROP_MOVE ? true : false);
            }
            return true;
        }

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            this.operation = operation;
            if ((target == null) || !LocalSelectionTransfer.getTransfer().isSupportedType(transferType))
                return false;
            IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
            if (selection.isEmpty())
                return false;
            for (final Object object : selection.toList()) {
                SubtreeType subtree = null;
                if ((object instanceof AbstractObject)) {
                    if (obj.isValidSelectionForMove(SubtreeType.INFRASTRUCTURE))
                        subtree = SubtreeType.INFRASTRUCTURE;
                    else if (obj.isValidSelectionForMove(SubtreeType.TEMPLATES))
                        subtree = SubtreeType.TEMPLATES;
                    else if (obj.isValidSelectionForMove(SubtreeType.BUSINESS_SERVICES))
                        subtree = SubtreeType.BUSINESS_SERVICES;
                    else if (obj.isValidSelectionForMove(SubtreeType.DASHBOARDS))
                        subtree = SubtreeType.DASHBOARDS;
                    else if (obj.isValidSelectionForMove(SubtreeType.MAPS))
                        subtree = SubtreeType.MAPS;
                }
                if (subtree == null)
                    return false;
                Set<Integer> filter;
                switch(subtree) {
                    case INFRASTRUCTURE:
                        filter = ObjectSelectionDialog.createContainerSelectionFilter();
                        break;
                    case TEMPLATES:
                        filter = ObjectSelectionDialog.createTemplateGroupSelectionFilter();
                        break;
                    case BUSINESS_SERVICES:
                        filter = ObjectSelectionDialog.createBusinessServiceSelectionFilter();
                        break;
                    case DASHBOARDS:
                        if (object instanceof DashboardGroup)
                            filter = ObjectSelectionDialog.createDashboardGroupSelectionFilter();
                        else
                            filter = ObjectSelectionDialog.createDashboardSelectionFilter();
                        break;
                    case MAPS:
                        filter = ObjectSelectionDialog.createNetworkMapGroupsSelectionFilter();
                        break;
                    default:
                        filter = null;
                        break;
                }
                if ((filter == null) || !filter.contains(((AbstractObject) target).getObjectClass()) || target.equals(object))
                    return false;
            }
            return true;
        }
    });
}
Also used : DashboardGroup(org.netxms.client.objects.DashboardGroup) Set(java.util.Set) HashSet(java.util.HashSet) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SubtreeType(org.netxms.ui.eclipse.objectbrowser.api.SubtreeType) TreePath(org.eclipse.jface.viewers.TreePath) TransferData(org.eclipse.swt.dnd.TransferData) TreeSelection(org.eclipse.jface.viewers.TreeSelection) AbstractObject(org.netxms.client.objects.AbstractObject) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) AbstractObject(org.netxms.client.objects.AbstractObject) List(java.util.List)

Example 20 with TransferData

use of org.eclipse.swt.dnd.TransferData in project portfolio by buchen.

the class EditReportingPeriodsDialog method setupDnD.

private void setupDnD() {
    Transfer[] types = new Transfer[] { LocalSelectionTransfer.getTransfer() };
    tableViewer.addDragSupport(DND.DROP_MOVE, types, new DragSourceAdapter() {

        @Override
        public void dragSetData(DragSourceEvent event) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            event.doit = (selection.size() < tableViewer.getTable().getItemCount());
            if (event.doit) {
                LocalSelectionTransfer.getTransfer().setSelection(selection);
                LocalSelectionTransfer.getTransfer().setSelectionSetTime(event.time & 0xFFFFFFFFL);
            }
        }
    });
    tableViewer.addDropSupport(DND.DROP_MOVE, types, new ViewerDropAdapter(tableViewer) {

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            return true;
        }

        @Override
        public boolean performDrop(Object data) {
            IStructuredSelection selection = (IStructuredSelection) data;
            List<ReportingPeriod> movedItems = new ArrayList<>();
            for (Object o : selection.toList()) movedItems.add((ReportingPeriod) o);
            periods.removeAll(movedItems);
            Object destination = getCurrentTarget();
            int index = periods.indexOf(destination);
            if (index >= 0) {
                int location = getCurrentLocation();
                if (location == ViewerDropAdapter.LOCATION_ON || location == ViewerDropAdapter.LOCATION_AFTER)
                    index++;
                periods.addAll(index, movedItems);
            }
            tableViewer.refresh();
            return true;
        }
    });
}
Also used : DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) TransferData(org.eclipse.swt.dnd.TransferData) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

TransferData (org.eclipse.swt.dnd.TransferData)29 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 ViewerDropAdapter (org.eclipse.jface.viewers.ViewerDropAdapter)12 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)11 Transfer (org.eclipse.swt.dnd.Transfer)10 List (java.util.List)9 ArrayList (java.util.ArrayList)7 IResource (org.eclipse.core.resources.IResource)7 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)6 IFile (org.eclipse.core.resources.IFile)5 ISelection (org.eclipse.jface.viewers.ISelection)5 CoreException (org.eclipse.core.runtime.CoreException)4 IStatus (org.eclipse.core.runtime.IStatus)4 TreeSelection (org.eclipse.jface.viewers.TreeSelection)4 AbstractObject (org.netxms.client.objects.AbstractObject)4 URI (java.net.URI)3 IContainer (org.eclipse.core.resources.IContainer)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 Point (org.eclipse.swt.graphics.Point)3