Search in sources :

Example 11 with SafeRunnable

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

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

the class OutlineFilterDescriptor method createFilterDescriptors.

// ---- initialization ---------------------------------------------------
/**
 * Creates the filter descriptors.
 * @param elements the configuration elements
 * @return new filter descriptors
 */
private static OutlineFilterDescriptor[] createFilterDescriptors(IConfigurationElement[] elements) {
    List result = new ArrayList(5);
    Set descIds = new HashSet(5);
    for (int i = 0; i < elements.length; i++) {
        final IConfigurationElement element = elements[i];
        if (FILTER_TAG.equals(element.getName())) {
            final OutlineFilterDescriptor[] desc = new OutlineFilterDescriptor[1];
            SafeRunner.run(new SafeRunnable(OutlineFilterMessages.FilterDescriptor_filterDescriptionCreationError_message) {

                public void run() throws Exception {
                    desc[0] = new OutlineFilterDescriptor(element);
                }
            });
            if (desc[0] != null && !descIds.contains(desc[0].getId())) {
                result.add(desc[0]);
                descIds.add(desc[0].getId());
            }
        }
    }
    return (OutlineFilterDescriptor[]) result.toArray(new OutlineFilterDescriptor[result.size()]);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) SafeRunnable(org.eclipse.jface.util.SafeRunnable) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) HashSet(java.util.HashSet)

Example 13 with SafeRunnable

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

the class XMLTableTreeViewer method createDropTargetListener.

private DropTargetListener createDropTargetListener() {
    return new DropTargetListener() {

        public void dragEnter(DropTargetEvent event) {
        }

        public void dragLeave(DropTargetEvent event) {
        }

        public void dragOperationChanged(DropTargetEvent event) {
        }

        public void drop(DropTargetEvent event) {
            if (event.operations != DND.DROP_NONE && LocalSelectionTransfer.getTransfer().getSelection() instanceof IStructuredSelection) {
                dragOver(event);
                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(), XMLTableTreeViewer.this);
                    if (command != null && command.canExecute()) {
                        SafeRunnable.run(new SafeRunnable() {

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

        public void dropAccept(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;
            if (getLocalNodeSelection(event) == null) {
                event.detail = DND.DROP_NONE;
            }
        }

        private IStructuredSelection getLocalNodeSelection(DropTargetEvent event) {
            IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
            if (selection != null && !selection.isEmpty()) {
                for (Iterator i = selection.iterator(); i.hasNext(); ) {
                    Object node = i.next();
                    if (node instanceof Node) {
                        return selection;
                    }
                }
            }
            return null;
        }

        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;
            }
        }
    };
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) SafeRunnable(org.eclipse.jface.util.SafeRunnable) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) TableItem(org.eclipse.swt.widgets.TableItem) Rectangle(org.eclipse.swt.graphics.Rectangle) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Point(org.eclipse.swt.graphics.Point) Control(org.eclipse.swt.widgets.Control) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) DragNodeCommand(org.eclipse.wst.xml.ui.internal.dnd.DragNodeCommand) Iterator(java.util.Iterator)

Example 14 with SafeRunnable

use of org.eclipse.jface.util.SafeRunnable in project archi by archimatetool.

the class ComponentSelectionManager method fireSelectionEvent.

public void fireSelectionEvent(final Object source, final Object selection) {
    if (selection == null) {
        return;
    }
    Object[] listenersArray = listeners.toArray();
    for (int i = 0; i < listenersArray.length; i++) {
        final IComponentSelectionListener l = (IComponentSelectionListener) listenersArray[i];
        SafeRunner.run(new SafeRunnable() {

            @Override
            public void run() {
                l.componentSelectionChanged(source, selection);
            }
        });
    }
}
Also used : SafeRunnable(org.eclipse.jface.util.SafeRunnable)

Example 15 with SafeRunnable

use of org.eclipse.jface.util.SafeRunnable in project translationstudio8 by heartsome.

the class TSWizardDialog method firePageChanging.

/**
	 * Notifies any page changing listeners that the currently selected dialog
	 * page is changing. Only listeners registered at the time this method is
	 * called are notified.
	 * 
	 * @param event
	 *            a selection changing event
	 * 
	 * @see IPageChangingListener#handlePageChanging(PageChangingEvent)
	 * @since 3.3
	 */
protected void firePageChanging(final PageChangingEvent event) {
    Object[] listeners = pageChangingListeners.getListeners();
    for (int i = 0; i < listeners.length; ++i) {
        final IPageChangingListener l = (IPageChangingListener) listeners[i];
        SafeRunnable.run(new SafeRunnable() {

            public void run() {
                l.handlePageChanging(event);
            }
        });
    }
}
Also used : SafeRunnable(org.eclipse.jface.util.SafeRunnable) IPageChangingListener(org.eclipse.jface.dialogs.IPageChangingListener) 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