Search in sources :

Example 1 with NavigatorSafeRunnable

use of org.eclipse.ui.internal.navigator.NavigatorSafeRunnable in project polymap4-core by Polymap4.

the class CommonDropAdapter method validateDrop.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object,
	 *      int, org.eclipse.swt.dnd.TransferData)
	 */
public boolean validateDrop(final Object aDropTarget, final int theDropOperation, final TransferData theTransferData) {
    if (Policy.DEBUG_DND) {
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println("CommonDropAdapter.validateDrop (begin) operation: " + theDropOperation + " target: " + aDropTarget);
    // new Exception().printStackTrace(System.out);
    }
    boolean result = false;
    final IStatus[] valid = new IStatus[1];
    if (super.validateDrop(aDropTarget, theDropOperation, theTransferData)) {
        result = true;
        if (Policy.DEBUG_DND) {
            // $NON-NLS-1$
            System.out.println("CommonDropAdapter.validateDrop valid for plugin transfer");
        }
    } else {
        final Object target = aDropTarget != null ? aDropTarget : getViewer().getInput();
        if (Policy.DEBUG_DND) {
            // $NON-NLS-1$
            System.out.println("CommonDropAdapter.validateDrop target: " + target);
            System.out.println(// $NON-NLS-1$
            "CommonDropAdapter.validateDrop local selection: " + LocalSelectionTransfer.getTransfer().getSelection());
        }
        CommonDropAdapterAssistant[] assistants = dndService.findCommonDropAdapterAssistants(target, theTransferData);
        for (int i = 0; i < assistants.length; i++) {
            if (Policy.DEBUG_DND) {
                System.out.println(// $NON-NLS-1$
                "CommonDropAdapter.validateDrop checking assistant: \"" + assistants[i]);
            }
            final CommonDropAdapterAssistant assistantLocal = assistants[i];
            SafeRunner.run(new NavigatorSafeRunnable() {

                public void run() throws Exception {
                    assistantLocal.setCurrentEvent(getCurrentEvent());
                    valid[0] = assistantLocal.validateDrop(target, theDropOperation, theTransferData);
                }
            });
            if (valid[0] != null && valid[0].isOK()) {
                result = true;
                if (Policy.DEBUG_DND) {
                    // $NON-NLS-1$
                    System.out.println("CommonDropAdapter.validateDrop VALID");
                }
                break;
            }
            if (Policy.DEBUG_DND) {
                System.out.println(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "CommonDropAdapter.validateDrop NOT valid: " + (valid[0] != null ? (valid[0].getSeverity() + ": " + valid[0].getMessage()) : ""));
            }
        }
    }
    if (Policy.DEBUG_DND) {
        System.out.println(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "CommonDropAdapter.validateDrop (returning " + (valid[0] != null ? valid[0].getSeverity() + ": " + valid[0].getMessage() : "" + result) + ")");
    }
    setScrollExpandEnabled(true);
    return result;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) NavigatorSafeRunnable(org.eclipse.ui.internal.navigator.NavigatorSafeRunnable)

Example 2 with NavigatorSafeRunnable

use of org.eclipse.ui.internal.navigator.NavigatorSafeRunnable in project polymap4-core by Polymap4.

the class CommonSorterDescriptor method createSorter.

/**
 * @return An instance of the ViewerSorter defined by the extension. Callers
 *         of this method are responsible for managing the instantiated
 *         filter.
 */
public ViewerSorter createSorter() {
    final ViewerSorter[] sorter = new ViewerSorter[1];
    SafeRunner.run(new NavigatorSafeRunnable(element) {

        public void run() throws Exception {
            sorter[0] = (ViewerSorter) element.createExecutableExtension(ATT_CLASS);
        }
    });
    if (sorter[0] != null)
        return sorter[0];
    return SkeletonViewerSorter.INSTANCE;
}
Also used : NavigatorSafeRunnable(org.eclipse.ui.internal.navigator.NavigatorSafeRunnable) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter)

Example 3 with NavigatorSafeRunnable

use of org.eclipse.ui.internal.navigator.NavigatorSafeRunnable in project polymap4-core by Polymap4.

the class CommonDragAdapter method dragSetData.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.swt.dnd.DragSourceAdapter#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
	 */
public void dragSetData(final DragSourceEvent event) {
    final ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
    if (Policy.DEBUG_DND) {
        System.out.println(// $NON-NLS-1$ //$NON-NLS-2$
        "CommonDragAdapter.dragSetData: event" + event + " selection=" + selection);
    }
    if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
        event.data = selection;
        if (Policy.DEBUG_DND) {
            System.out.println(// $NON-NLS-1$
            "CommonDragAdapter.dragSetData set LocalSelectionTransfer: " + event.data);
        }
    } else if (PluginTransfer.getInstance().isSupportedType(event.dataType)) {
        event.data = NavigatorPluginDropAction.createTransferData(contentService);
        if (Policy.DEBUG_DND) {
            System.out.println(// $NON-NLS-1$
            "CommonDragAdapter.dragSetData set PluginTransfer: " + event.data);
        }
    } else if (selection instanceof IStructuredSelection) {
        if (Policy.DEBUG_DND) {
            System.out.println(// $NON-NLS-1$
            "CommonDragAdapter.dragSetData looking for assistants");
        }
        for (int i = 0, len = assistantsToUse.size(); i < len; i++) {
            final CommonDragAdapterAssistant assistant = (CommonDragAdapterAssistant) assistantsToUse.get(i);
            if (Policy.DEBUG_DND) {
                System.out.println(// $NON-NLS-1$
                "CommonDragAdapter.dragSetData assistant: " + assistant);
            }
            Transfer[] supportedTransferTypes = assistant.getSupportedTransferTypes();
            final boolean[] getOut = new boolean[1];
            for (int j = 0; j < supportedTransferTypes.length; j++) {
                if (supportedTransferTypes[j].isSupportedType(event.dataType)) {
                    SafeRunner.run(new NavigatorSafeRunnable() {

                        public void run() throws Exception {
                            if (Policy.DEBUG_DND) {
                                System.out.println(// $NON-NLS-1$
                                "CommonDragAdapter.dragSetData supported xfer type");
                            }
                            if (assistant.setDragData(event, (IStructuredSelection) selection)) {
                                if (Policy.DEBUG_DND) {
                                    System.out.println(// $NON-NLS-1$
                                    "CommonDragAdapter.dragSetData set data " + event.data);
                                }
                                setDataAssistant = assistant;
                                getOut[0] = true;
                            }
                        }
                    });
                    if (getOut[0])
                        return;
                }
            }
        }
        if (Policy.DEBUG_DND) {
            System.out.println(// $NON-NLS-1$
            "CommonDragAdapter.dragSetData FAILED no assistant handled it");
        }
        event.doit = false;
    } else {
        if (Policy.DEBUG_DND) {
            System.out.println(// $NON-NLS-1$
            "CommonDragAdapter.dragSetData FAILED can't identify transfer type");
        }
        event.doit = false;
    }
}
Also used : NavigatorSafeRunnable(org.eclipse.ui.internal.navigator.NavigatorSafeRunnable) ISelection(org.eclipse.jface.viewers.ISelection) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) PluginTransfer(org.eclipse.ui.part.PluginTransfer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 4 with NavigatorSafeRunnable

use of org.eclipse.ui.internal.navigator.NavigatorSafeRunnable in project polymap4-core by Polymap4.

the class StructuredViewerManager method safeRefresh.

/**
 */
public void safeRefresh() {
    final Viewer localViewer = viewer;
    if (localViewer == null || localViewer.getControl().isDisposed())
        return;
    Display display = localViewer.getControl().getDisplay();
    if (display.isDisposed())
        return;
    display.syncExec(new Runnable() {

        public void run() {
            if (localViewer.getControl().isDisposed())
                return;
            SafeRunner.run(new NavigatorSafeRunnable() {

                public void run() throws Exception {
                    localViewer.getControl().setRedraw(false);
                    localViewer.refresh();
                }
            });
            localViewer.getControl().setRedraw(true);
        }
    });
}
Also used : NavigatorSafeRunnable(org.eclipse.ui.internal.navigator.NavigatorSafeRunnable) NavigatorSafeRunnable(org.eclipse.ui.internal.navigator.NavigatorSafeRunnable) Viewer(org.eclipse.jface.viewers.Viewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Display(org.eclipse.swt.widgets.Display)

Example 5 with NavigatorSafeRunnable

use of org.eclipse.ui.internal.navigator.NavigatorSafeRunnable in project polymap4-core by Polymap4.

the class CommonDragAssistantDescriptor method createDragAssistant.

/**
 * Create an instance of the {@link CommonDragAdapterAssistant} defined by
 * this descriptor.
 *
 * @return an instance of the {@link CommonDragAdapterAssistant} or
 *         {@link SkeletonCommonDragAssistant} if a problem occurs with the
 *         instantiation.
 */
public CommonDragAdapterAssistant createDragAssistant() {
    final CommonDragAdapterAssistant[] da = new CommonDragAdapterAssistant[1];
    SafeRunner.run(new NavigatorSafeRunnable(element) {

        public void run() throws Exception {
            da[0] = (CommonDragAdapterAssistant) element.createExecutableExtension(ATT_CLASS);
        }
    });
    if (da[0] != null)
        return da[0];
    return SkeletonCommonDragAssistant.INSTANCE;
}
Also used : CommonDragAdapterAssistant(org.eclipse.ui.navigator.CommonDragAdapterAssistant) NavigatorSafeRunnable(org.eclipse.ui.internal.navigator.NavigatorSafeRunnable)

Aggregations

NavigatorSafeRunnable (org.eclipse.ui.internal.navigator.NavigatorSafeRunnable)17 IStatus (org.eclipse.core.runtime.IStatus)2 CommonActionProviderDescriptor (org.eclipse.ui.internal.navigator.actions.CommonActionProviderDescriptor)2 Iterator (java.util.Iterator)1 CoreException (org.eclipse.core.runtime.CoreException)1 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)1 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 ViewerSorter (org.eclipse.jface.viewers.ViewerSorter)1 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)1 Transfer (org.eclipse.swt.dnd.Transfer)1 Display (org.eclipse.swt.widgets.Display)1 ActionContext (org.eclipse.ui.actions.ActionContext)1 CommonActionProvider (org.eclipse.ui.navigator.CommonActionProvider)1 CommonDragAdapterAssistant (org.eclipse.ui.navigator.CommonDragAdapterAssistant)1 CommonDropAdapterAssistant (org.eclipse.ui.navigator.CommonDropAdapterAssistant)1