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);
}
});
}
}
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];
}
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();
}
}
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);
}
});
}
}
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;
}
Aggregations