Search in sources :

Example 1 with TransferDropTargetListener

use of org.eclipse.jface.util.TransferDropTargetListener in project webtools.sourceediting by eclipse.

the class DTDContentOutlineConfiguration method getTransferDropTargetListeners.

/*
		 * (non-Javadoc)
		 * 
		 * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getTransferDropTargetListeners(org.eclipse.jface.viewers.TreeViewer)
		 */
public TransferDropTargetListener[] getTransferDropTargetListeners(final TreeViewer treeViewer) {
    if (fTransferDropTargetListeners == null) {
        fTransferDropTargetListeners = new TransferDropTargetListener[] { new TransferDropTargetListener() {

            public void dragEnter(DropTargetEvent event) {
            }

            public void dragLeave(DropTargetEvent event) {
            }

            public void dragOperationChanged(DropTargetEvent event) {
            }

            public void dragOver(DropTargetEvent event) {
                event.feedback = DND.FEEDBACK_SELECT;
                float feedbackFloat = getHeightInItem(event);
                if (feedbackFloat > 0.75) {
                    event.feedback = DND.FEEDBACK_INSERT_AFTER;
                } else if (feedbackFloat < 0.25) {
                    event.feedback = DND.FEEDBACK_INSERT_BEFORE;
                }
                event.feedback |= DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
            }

            public void drop(DropTargetEvent event) {
                if (event.operations != DND.DROP_NONE && LocalSelectionTransfer.getTransfer().getSelection() instanceof IStructuredSelection) {
                    IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
                    if (selection != null && !selection.isEmpty() && event.item != null && event.item.getData() != null) {
                        /*
							 * the command uses these numbers instead of the
							 * feedback constants (even though it converts in
							 * the other direction as well)
							 */
                        float feedbackFloat = getHeightInItem(event);
                        final DragAndDropCommand command = new DTDDragAndDropManager().createCommand(event.item.getData(), feedbackFloat, event.operations, event.detail, selection.toList());
                        if (command != null && command.canExecute()) {
                            SafeRunnable.run(new SafeRunnable() {

                                public void run() throws Exception {
                                    command.execute();
                                }
                            });
                        }
                    }
                }
            }

            public void dropAccept(DropTargetEvent event) {
            }

            private float getHeightInItem(DropTargetEvent event) {
                if (event.item == null)
                    return .5f;
                if (event.item instanceof TreeItem) {
                    TreeItem treeItem = (TreeItem) event.item;
                    Control control = treeItem.getParent();
                    Point point = control.toControl(new Point(event.x, event.y));
                    Rectangle bounds = treeItem.getBounds();
                    return (float) (point.y - bounds.y) / (float) bounds.height;
                } else if (event.item instanceof TableItem) {
                    TableItem tableItem = (TableItem) event.item;
                    Control control = tableItem.getParent();
                    Point point = control.toControl(new Point(event.x, event.y));
                    Rectangle bounds = tableItem.getBounds(0);
                    return (float) (point.y - bounds.y) / (float) bounds.height;
                } else {
                    return 0.0F;
                }
            }

            public Transfer getTransfer() {
                return LocalSelectionTransfer.getTransfer();
            }

            public boolean isEnabled(DropTargetEvent event) {
                return getTransfer().isSupportedType(event.currentDataType);
            }
        } };
    }
    return fTransferDropTargetListeners;
}
Also used : Control(org.eclipse.swt.widgets.Control) TreeItem(org.eclipse.swt.widgets.TreeItem) SafeRunnable(org.eclipse.jface.util.SafeRunnable) TableItem(org.eclipse.swt.widgets.TableItem) TransferDropTargetListener(org.eclipse.jface.util.TransferDropTargetListener) Rectangle(org.eclipse.swt.graphics.Rectangle) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) DTDDragAndDropManager(org.eclipse.wst.dtd.ui.internal.dnd.DTDDragAndDropManager) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Point(org.eclipse.swt.graphics.Point) DragAndDropCommand(org.eclipse.wst.common.ui.internal.dnd.DragAndDropCommand)

Example 2 with TransferDropTargetListener

use of org.eclipse.jface.util.TransferDropTargetListener in project webtools.sourceediting by eclipse.

the class ConfigurableContentOutlinePage method setConfiguration.

/**
 * Configures (or reconfigures) the page according to the given
 * configuration.
 *
 * @param configuration
 */
public void setConfiguration(ContentOutlineConfiguration configuration) {
    // intentionally do not check to see if the new configuration != old
    // configuration
    unconfigure();
    fConfiguration = configuration;
    if (getTreeViewer() != null && getControl() != null && !getControl().isDisposed()) {
        // (re)set the providers
        ILabelProvider labelProvider = getConfiguration().getLabelProvider(getTreeViewer());
        if (labelProvider instanceof IStyledLabelProvider) {
            getTreeViewer().setLabelProvider(new DelegatingStyledCellLabelProvider((IStyledLabelProvider) labelProvider));
        } else {
            getTreeViewer().setLabelProvider(labelProvider);
        }
        getTreeViewer().setContentProvider(getConfiguration().getContentProvider(getTreeViewer()));
        // view toolbar
        IContributionManager toolbar = getSite().getActionBars().getToolBarManager();
        if (toolbar != null) {
            IContributionItem[] toolbarItems = getConfiguration().getToolbarContributions(getTreeViewer());
            if (toolbarItems != null) {
                for (int i = 0; i < toolbarItems.length; i++) {
                    toolbar.add(toolbarItems[i]);
                }
                toolbar.update(true);
            }
        }
        // view menu
        IContributionManager menu = getSite().getActionBars().getMenuManager();
        if (menu != null) {
            IContributionItem[] menuItems = getConfiguration().getMenuContributions(getTreeViewer());
            if (menuItems != null) {
                for (int i = 0; i < menuItems.length; i++) {
                    menuItems[i].setVisible(true);
                    menu.add(menuItems[i]);
                    menuItems[i].update();
                }
                menu.update(true);
            }
        }
        // add the allowed DnD listeners and types
        TransferDragSourceListener[] dragListeners = getConfiguration().getTransferDragSourceListeners(getTreeViewer());
        if (fDragAdapter != null && dragListeners.length > 0) {
            for (int i = 0; i < dragListeners.length; i++) {
                fDragAdapter.addDragSourceListener(dragListeners[i]);
            }
            fActiveDragListeners = dragListeners;
            fDragSource.addDragListener(fDragAdapter);
            fDragSource.setTransfer(fDragAdapter.getTransfers());
        }
        TransferDropTargetListener[] dropListeners = getConfiguration().getTransferDropTargetListeners(getTreeViewer());
        if (fDropAdapter != null && dropListeners.length > 0) {
            for (int i = 0; i < dropListeners.length; i++) {
                fDropAdapter.addDropTargetListener(dropListeners[i]);
            }
            fActiveDropListeners = dropListeners;
            fDropTarget.addDropListener(fDropAdapter);
            fDropTarget.setTransfer(fDropAdapter.getTransfers());
        }
        // add the key listeners
        KeyListener[] listeners = getConfiguration().getKeyListeners(getTreeViewer());
        if (listeners != null) {
            for (int i = 0; i < listeners.length; i++) {
                getControl().addKeyListener(listeners[i]);
            }
        }
    }
    if (fInput != null) {
        setInput(fInput);
    }
}
Also used : IContributionItem(org.eclipse.jface.action.IContributionItem) TransferDragSourceListener(org.eclipse.jface.util.TransferDragSourceListener) TransferDropTargetListener(org.eclipse.jface.util.TransferDropTargetListener) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) IStyledLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider) KeyListener(org.eclipse.swt.events.KeyListener) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider) IContributionManager(org.eclipse.jface.action.IContributionManager)

Example 3 with TransferDropTargetListener

use of org.eclipse.jface.util.TransferDropTargetListener in project webtools.sourceediting by eclipse.

the class AbstractXMLContentOutlineConfiguration method getTransferDropTargetListeners.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getTransferDropTargetListeners(org.eclipse.jface.viewers.TreeViewer)
	 */
public TransferDropTargetListener[] getTransferDropTargetListeners(final TreeViewer treeViewer) {
    if (fTransferDropTargetListeners == null) {
        fTransferDropTargetListeners = new TransferDropTargetListener[] { new TransferDropTargetListener() {

            public void dragEnter(DropTargetEvent event) {
            }

            public void dragLeave(DropTargetEvent event) {
            }

            public void dragOperationChanged(DropTargetEvent event) {
            }

            public void dragOver(DropTargetEvent event) {
                event.feedback = DND.FEEDBACK_SELECT;
                float feedbackFloat = getHeightInItem(event);
                if (feedbackFloat > 0.75) {
                    event.feedback = DND.FEEDBACK_INSERT_AFTER;
                } else if (feedbackFloat < 0.25) {
                    event.feedback = DND.FEEDBACK_INSERT_BEFORE;
                }
                event.feedback |= DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL;
            }

            public void drop(DropTargetEvent event) {
                if (event.operations != DND.DROP_NONE && LocalSelectionTransfer.getTransfer().getSelection() != null && !LocalSelectionTransfer.getTransfer().getSelection().isEmpty()) {
                    IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
                    if (selection != null && !selection.isEmpty() && event.item != null && event.item.getData() != null) {
                        /*
							 * the command uses these numbers instead of the
							 * feedback constants (even though it converts in
							 * the other direction as well)
							 */
                        float feedbackFloat = getHeightInItem(event);
                        final DragNodeCommand command = new DragNodeCommand(event.item.getData(), feedbackFloat, event.operations, event.detail, selection.toList(), treeViewer);
                        if (command != null && command.canExecute()) {
                            SafeRunnable.run(new SafeRunnable() {

                                public void run() throws Exception {
                                    command.execute();
                                }
                            });
                        }
                    }
                }
            }

            public void dropAccept(DropTargetEvent event) {
            }

            private float getHeightInItem(DropTargetEvent event) {
                if (event.item == null)
                    return .5f;
                if (event.item instanceof TreeItem) {
                    TreeItem treeItem = (TreeItem) event.item;
                    Control control = treeItem.getParent();
                    Point point = control.toControl(new Point(event.x, event.y));
                    Rectangle bounds = treeItem.getBounds();
                    return (float) (point.y - bounds.y) / (float) bounds.height;
                } else if (event.item instanceof TableItem) {
                    TableItem tableItem = (TableItem) event.item;
                    Control control = tableItem.getParent();
                    Point point = control.toControl(new Point(event.x, event.y));
                    Rectangle bounds = tableItem.getBounds(0);
                    return (float) (point.y - bounds.y) / (float) bounds.height;
                } else {
                    return 0.0F;
                }
            }

            public Transfer getTransfer() {
                return LocalSelectionTransfer.getTransfer();
            }

            public boolean isEnabled(DropTargetEvent event) {
                return getTransfer().isSupportedType(event.currentDataType);
            }
        } };
    }
    return fTransferDropTargetListeners;
}
Also used : Control(org.eclipse.swt.widgets.Control) TreeItem(org.eclipse.swt.widgets.TreeItem) DragNodeCommand(org.eclipse.wst.xml.ui.internal.dnd.DragNodeCommand) SafeRunnable(org.eclipse.jface.util.SafeRunnable) TableItem(org.eclipse.swt.widgets.TableItem) TransferDropTargetListener(org.eclipse.jface.util.TransferDropTargetListener) Rectangle(org.eclipse.swt.graphics.Rectangle) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Point(org.eclipse.swt.graphics.Point)

Aggregations

TransferDropTargetListener (org.eclipse.jface.util.TransferDropTargetListener)3 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)2 SafeRunnable (org.eclipse.jface.util.SafeRunnable)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)2 Transfer (org.eclipse.swt.dnd.Transfer)2 Point (org.eclipse.swt.graphics.Point)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 Control (org.eclipse.swt.widgets.Control)2 TableItem (org.eclipse.swt.widgets.TableItem)2 TreeItem (org.eclipse.swt.widgets.TreeItem)2 IContributionItem (org.eclipse.jface.action.IContributionItem)1 IContributionManager (org.eclipse.jface.action.IContributionManager)1 TransferDragSourceListener (org.eclipse.jface.util.TransferDragSourceListener)1 DelegatingStyledCellLabelProvider (org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider)1 IStyledLabelProvider (org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 KeyListener (org.eclipse.swt.events.KeyListener)1 DragAndDropCommand (org.eclipse.wst.common.ui.internal.dnd.DragAndDropCommand)1 DTDDragAndDropManager (org.eclipse.wst.dtd.ui.internal.dnd.DTDDragAndDropManager)1