use of org.eclipse.swt.dnd.Transfer in project tdi-studio-se by Talend.
the class JobHierarchyViewPart method addDropAdapters.
private void addDropAdapters(AbstractTreeViewer viewer) {
Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getInstance() };
int ops = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_DEFAULT;
DelegatingDropAdapter delegatingDropAdapter = new DelegatingDropAdapter();
delegatingDropAdapter.addDropTargetListener(new JobHierarchyTransferDropAdapter(this));
viewer.addDropSupport(ops, transfers, delegatingDropAdapter);
}
use of org.eclipse.swt.dnd.Transfer in project tdi-studio-se by Talend.
the class GEFCopyAction method run.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
List objects = GEFDeleteAction.filterSameObject(getSelectedObjects());
if (!objects.isEmpty()) {
Clipboard clipboard = Clipboard.getDefault();
org.eclipse.swt.dnd.Clipboard systemClipboard = new org.eclipse.swt.dnd.Clipboard(Display.getCurrent());
boolean noteTextActived = false;
boolean connectionTextActived = false;
boolean nodeLabelActived = false;
Text text = null;
if (objects.size() == 1) {
if (objects.get(0) instanceof NoteEditPart) {
NoteDirectEditManager directEditManager = ((NoteEditPart) objects.get(0)).getDirectEditManager();
if (directEditManager != null && directEditManager.getCellEditor() != null) {
noteTextActived = true;
}
} else if (objects.get(0) instanceof ConnLabelEditPart) {
ConnLabelEditPart connLabelEditPart = (ConnLabelEditPart) objects.get(0);
if (connLabelEditPart.getDirectEditManager() != null && connLabelEditPart.getDirectEditManager().getTextControl() != null) {
connectionTextActived = true;
}
} else if (objects.get(0) instanceof NodeLabelEditPart) {
NodeLabelEditPart nodeLabelEditPart = (NodeLabelEditPart) objects.get(0);
if (nodeLabelEditPart.getDirectEditManager() != null && nodeLabelEditPart.getDirectEditManager().getCellEditor() != null) {
nodeLabelActived = true;
}
}
}
if (noteTextActived) {
text = ((NoteEditPart) objects.get(0)).getDirectEditManager().getTextControl();
clipboard.setContents(text.getSelectionText());
} else if (connectionTextActived) {
text = ((ConnLabelEditPart) objects.get(0)).getDirectEditManager().getTextControl();
clipboard.setContents(text.getSelectionText());
} else if (nodeLabelActived) {
text = (Text) ((NodeLabelEditPart) objects.get(0)).getDirectEditManager().getCellEditor().getControl();
clipboard.setContents(text.getSelectionText());
} else {
clipboard.setContents(objects);
}
if (text != null && !("").equals(text.getSelectionText())) {
TextTransfer textTransfer = TextTransfer.getInstance();
Transfer[] transfers = new Transfer[] { textTransfer };
Object[] data = new Object[] { text.getSelectionText() };
systemClipboard.setContents(data, transfers);
}
}
// Refreshes the pasteAction's enable status.
IWorkbenchPart part = getWorkbenchPart();
if (part instanceof AbstractTalendEditor) {
AbstractTalendEditor talendEditor = (AbstractTalendEditor) part;
IAction action = talendEditor.getActionRegistry().getAction(ActionFactory.PASTE.getId());
action.setEnabled(true);
}
}
use of org.eclipse.swt.dnd.Transfer in project eclipse.platform.text by eclipse.
the class AbstractTemplatesPage method initializeDND.
/**
* Initializes drag and drop the template items
*/
private void initializeDND() {
DragSourceAdapter dragListener = new DragSourceAdapter() {
@Override
public void dragStart(DragSourceEvent event) {
if (getSelectedTemplates().length == 0) {
event.doit = false;
}
}
@Override
public void dragSetData(DragSourceEvent event) {
if (TemplatesTransfer.getInstance().isSupportedType(event.dataType)) {
event.data = getSelectedTemplates();
}
}
};
fTreeViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { TemplatesTransfer.getInstance() }, dragListener);
DropTargetAdapter dropListener = new DropTargetAdapter() {
Transfer textTransfer = TextTransfer.getInstance();
Transfer templateTransfer = TemplatesTransfer.getInstance();
@Override
public void dragEnter(DropTargetEvent event) {
if (event.detail == DND.DROP_DEFAULT)
event.detail = DND.DROP_COPY;
}
@Override
public void dragOperationChanged(DropTargetEvent event) {
if (event.detail == DND.DROP_DEFAULT)
event.detail = DND.DROP_COPY;
}
@Override
public void dragOver(DropTargetEvent event) {
event.feedback |= DND.FEEDBACK_SCROLL;
if (event.item == null) {
event.detail = DND.DROP_NONE;
return;
}
int index = 0;
boolean isTemplateTransfer = false;
while (index < event.dataTypes.length) {
if (textTransfer.isSupportedType(event.dataTypes[index])) {
break;
}
if (templateTransfer.isSupportedType(event.dataTypes[index])) {
isTemplateTransfer = true;
break;
}
index++;
}
if (index < event.dataTypes.length) {
event.currentDataType = event.dataTypes[index];
if (event.detail == DND.DROP_DEFAULT || !isTemplateTransfer)
event.detail = DND.DROP_COPY;
return;
}
}
@Override
public void drop(DropTargetEvent event) {
if (event.item == null)
return;
Object object = ((TreeItem) event.item).getData();
final String contextId;
if (object instanceof TemplateContextType)
contextId = ((TemplateContextType) object).getId();
else
contextId = ((TemplatePersistenceData) object).getTemplate().getContextTypeId();
if (textTransfer.isSupportedType(event.currentDataType)) {
// $NON-NLS-1$ //$NON-NLS-2$
String text = ((String) event.data).replaceAll("\\$", "\\$\\$");
final Template template = new Template(createTemplateName(), TemplatesMessages.TemplatesPage_paste_description, contextId, text, true);
getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
addTemplate(template);
}
});
return;
}
if (templateTransfer.isSupportedType(event.currentDataType)) {
final TemplatePersistenceData[] templates = (TemplatePersistenceData[]) event.data;
final int dropType = event.detail;
getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (dropType == DND.DROP_COPY)
copyTemplates(templates, contextId);
else
moveTemplates(templates, contextId);
}
});
}
}
};
Transfer[] transfers = new Transfer[] { TextTransfer.getInstance(), TemplatesTransfer.getInstance() };
fTreeViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, dropListener);
}
use of org.eclipse.swt.dnd.Transfer in project knime-core by knime.
the class AbstractRepositoryView method createPartControl.
/**
* This callback creates the content of the view. The TreeViewer is initialized.
*
* @see org.eclipse.ui.IWorkbenchPart #createPartControl(org.eclipse.swt.widgets.Composite)
* @param parent the parent composite
*/
@Override
public void createPartControl(final Composite parent) {
parent.setCursor(new Cursor(Display.getDefault(), SWT.CURSOR_WAIT));
m_viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
m_viewer.getControl().setToolTipText("Loading node repository...");
m_viewer.setContentProvider(new RepositoryContentProvider());
m_viewer.setLabelProvider(new RepositoryStyledLabelProvider(new RepositoryLabelProvider(), false));
m_viewer.setInput("Loading node repository...");
contributeToActionBars();
hookContextMenu();
hookDoubleClickAction();
// The viewer provides the selection to the workbench.
this.getSite().setSelectionProvider(m_viewer);
// The viewer supports drag&drop
// (well, actually only drag - objects are dropped into the editor ;-)
Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
m_viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new NodeTemplateDragListener(m_viewer));
PlatformUI.getWorkbench().getHelpSystem().setHelp(m_viewer.getControl(), "org.knime.workbench.help.repository_view_context");
final Job treeUpdater = new KNIMEJob("Node Repository Loader", FrameworkUtil.getBundle(getClass())) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
readRepository(parent, monitor);
return Status.OK_STATUS;
}
};
treeUpdater.setSystem(true);
treeUpdater.schedule();
}
use of org.eclipse.swt.dnd.Transfer in project knime-core by knime.
the class FavoritesView method createPartControl.
/**
* {@inheritDoc}
*/
@Override
public void createPartControl(final Composite parent) {
m_viewer = new TreeViewer(parent, SWT.SINGLE | SWT.V_SCROLL);
this.getSite().setSelectionProvider(m_viewer);
Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
m_viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new FavoriteNodesDragSource(this));
m_viewer.addDropSupport(DND.DROP_COPY, transfers, new FavoriteNodesDropTarget(this));
m_viewer.setLabelProvider(new RepositoryLabelProvider());
m_viewer.setContentProvider(new RepositoryContentProvider());
// no sorting
m_viewer.setComparator(null);
m_viewer.setInput("Loading favorite nodes...");
Job treeUpdater = new KNIMEJob("Favorite Nodes Loader", FrameworkUtil.getBundle(getClass())) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
final Root root = FavoriteNodesManager.getInstance().getRoot();
final Object category = root.getChildByID(FavoriteNodesManager.FAV_CAT_ID, false);
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
} else {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (!parent.isDisposed()) {
m_viewer.setInput(root);
m_viewer.expandToLevel(category, 1);
}
}
});
}
return Status.OK_STATUS;
}
};
treeUpdater.setSystem(true);
treeUpdater.schedule();
NodeUsageRegistry.addNodeUsageListener(FavoritesView.this);
hookDoubleClickAction();
}
Aggregations