Search in sources :

Example 21 with SafeRunnable

use of org.eclipse.jface.util.SafeRunnable in project erlide_eclipse by erlang.

the class ResourceTreeAndListGroup method notifyCheckStateChangeListeners.

/**
 * Notify all checked state listeners that the passed element has had its
 * checked state changed to the passed state
 */
protected void notifyCheckStateChangeListeners(final CheckStateChangedEvent event) {
    final Object[] array = getListeners();
    for (Object anArray : array) {
        final ICheckStateListener l = (ICheckStateListener) anArray;
        SafeRunner.run(new SafeRunnable() {

            @Override
            public void run() {
                l.checkStateChanged(event);
            }
        });
    }
}
Also used : ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) SafeRunnable(org.eclipse.jface.util.SafeRunnable)

Example 22 with SafeRunnable

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

the class OutlineFilterDescriptor method createViewerFilter.

/**
 * Creates a new <code>ViewerFilter</code>.
 * This method is only valid for viewer filters.
 * @return a new <code>ViewerFilter</code>
 */
public ViewerFilter createViewerFilter() {
    if (!isCustomFilter())
        return null;
    final ViewerFilter[] result = new ViewerFilter[1];
    String message = OutlineFilterMessages.FilterDescriptor_filterCreationError_message;
    ISafeRunnable code = new SafeRunnable(message) {

        /*
			 * @see org.eclipse.core.runtime.ISafeRunnable#run()
			 */
        public void run() throws Exception {
            result[0] = (ViewerFilter) fElement.createExecutableExtension(CLASS_ATTRIBUTE);
        }
    };
    SafeRunner.run(code);
    return result[0];
}
Also used : ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) SafeRunnable(org.eclipse.jface.util.SafeRunnable) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable)

Example 23 with SafeRunnable

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

the class OpenHyperlinkAction method run.

public void run() {
    if (fHyperlinkDetectors == null)
        return;
    ISelection selection = getTextEditor().getSelectionProvider().getSelection();
    if (selection == null || !(selection instanceof ITextSelection)) {
        return;
    }
    ITextSelection textSelection = (ITextSelection) selection;
    final IRegion region = new Region(textSelection.getOffset(), textSelection.getLength());
    IHyperlink hyperlink = null;
    synchronized (fHyperlinkDetectors) {
        for (int i = 0, length = fHyperlinkDetectors.length; i < length && hyperlink == null; i++) {
            final IHyperlinkDetector detector = fHyperlinkDetectors[i];
            if (detector == null)
                continue;
            /* The array is final, but its contents aren't */
            final IHyperlink[][] hyperlinks = new IHyperlink[1][];
            /*
				 * Detect from within a SafeRunnable since the list of
				 * detectors is extensible
				 */
            SafeRunnable detectorRunnable = new SafeRunnable() {

                public void run() throws Exception {
                    hyperlinks[0] = detector.detectHyperlinks(fTextViewer, region, false);
                }
            };
            SafeRunner.run(detectorRunnable);
            if (hyperlinks[0] == null)
                continue;
            if (hyperlinks.length > 0)
                hyperlink = hyperlinks[0][0];
        }
    }
    if (hyperlink != null) {
        /**
         * Force the highlight range to change when the hyperlink is
         * opened by altering the highlighted range beforehand.
         */
        getTextEditor().setHighlightRange(Math.max(0, region.getOffset() - 1), 0, false);
        hyperlink.open();
    }
}
Also used : IHyperlinkDetector(org.eclipse.jface.text.hyperlink.IHyperlinkDetector) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) SafeRunnable(org.eclipse.jface.util.SafeRunnable) ISelection(org.eclipse.jface.viewers.ISelection) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) ITextSelection(org.eclipse.jface.text.ITextSelection) IRegion(org.eclipse.jface.text.IRegion)

Example 24 with SafeRunnable

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

the class ExtensibleContentOutlinePage method fireSelectionChanged.

protected void fireSelectionChanged(ISelection selection) {
    // create an event
    final SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
    // fire the event
    Object[] listeners = selectionChangedListeners.getListeners();
    for (int i = 0; i < listeners.length; ++i) {
        final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
        Platform.run(new SafeRunnable() {

            public void run() {
                l.selectionChanged(event);
            }
        });
    }
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SafeRunnable(org.eclipse.jface.util.SafeRunnable) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent)

Example 25 with SafeRunnable

use of org.eclipse.jface.util.SafeRunnable 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

SafeRunnable (org.eclipse.jface.util.SafeRunnable)31 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)6 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)5 Point (org.eclipse.swt.graphics.Point)5 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)4 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)3 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 Control (org.eclipse.swt.widgets.Control)3 TableItem (org.eclipse.swt.widgets.TableItem)3 TreeItem (org.eclipse.swt.widgets.TreeItem)3 IHyperlinkDetector (org.eclipse.jface.text.hyperlink.IHyperlinkDetector)2 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)2 TransferDropTargetListener (org.eclipse.jface.util.TransferDropTargetListener)2 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)2 Transfer (org.eclipse.swt.dnd.Transfer)2 DragNodeCommand (org.eclipse.wst.xml.ui.internal.dnd.DragNodeCommand)2