private void attachDropListener() { dropTarget = new DropTarget(targetTable, DND.DROP_MOVE); dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() }); dropTarget.addDropListener(new DropTargetAdapter() { public void drop(DropTargetEvent event) { for (String fieldName : getformatedData((String) event.data)) { if(isPropertyAlreadyExists(fieldName)){ return; }else{ ExcelConfigurationDataStructure excelConfigurationDataStructure = new ExcelConfigurationDataStructure(); excelConfigurationDataStructure.setFieldName(fieldName); listOfExcelConfiguration.add(excelConfigurationDataStructure); targetTableViewer.refresh(); draggedFields.add(fieldName); enableDeleteButton(); } } combo.setItems(convertToArray(draggedFields)); combo.select(0); top_composite.layout(); top_composite.getParent().layout(); highlightDropFields(); } }); }
protected void configureDragAndDrop(DragAndDropConfiguration dragAndDropConfiguration, TreeViewer treeViewer) { // drop Transfer[] transferTypes = new Transfer[] { LocalSelectionTransfer.getTransfer() }; int operations = dragAndDropConfiguration.getSupportedDropOperations(this); DropTarget target = new DropTarget(treeViewer.getControl(), operations); target.setTransfer(transferTypes); // Drop listeners pour le drop des elements sur l'arbre SchemaViewerDropPolicy dropPolicy = dragAndDropConfiguration.getDropPolicy(this); DnDTargetListener targetListener = new DnDTargetListener(this, nodeConverter, dropPolicy); target.addDropListener(targetListener); // Drag listener pour le drag des elements de l'arbre DragSourceListener sourceListener = new DnDSourceListener(this); operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT; transferTypes = new Transfer[] { LocalSelectionTransfer.getTransfer() }; treeViewer.addDragSupport(operations, transferTypes, sourceListener); }
/** * Returns the shell for the given widget. If the widget doesn't represent a * SWT object that manage a shell, <code>null</code> is returned. * * @param widget * the widget * * @return the shell for the given widget */ public static Shell getShell(Widget widget) { if (widget instanceof Control) return ((Control) widget).getShell(); if (widget instanceof Caret) return ((Caret) widget).getParent().getShell(); if (widget instanceof DragSource) return ((DragSource) widget).getControl().getShell(); if (widget instanceof DropTarget) return ((DropTarget) widget).getControl().getShell(); if (widget instanceof Menu) return ((Menu) widget).getParent().getShell(); if (widget instanceof ScrollBar) return ((ScrollBar) widget).getParent().getShell(); return null; }
protected void registerWithExistingTarget(DropTarget target) { Transfer[] transfers = target.getTransfer(); boolean exists = false; if (transfers != null) { for (Transfer transfer : transfers) { if (transfer instanceof URLTransfer) { exists = true; break; } } if (!exists) { Transfer[] newTransfers = new Transfer[transfers.length + 1]; System.arraycopy(transfers, 0, newTransfers, 0, transfers.length); newTransfers[transfers.length] = URLTransfer.getInstance(); target.setTransfer(newTransfers); } } }
@Override public void drop(DropTargetEvent event) { if (!URLTransfer.getInstance().isSupportedType(event.currentDataType)) { return; } final String url = getUrl(event.data); if (ExampleURLHandler.isValidExample(url)) { DropTarget source = (DropTarget) event.getSource(); Display display = source.getDisplay(); display.asyncExec(new Runnable() { public void run() { proceedInstallation(url); } }); } }
/** * Returns the shell for the given widget. If the widget doesn't represent a SWT object that manage a shell, * <code>null</code> is returned. * * @return the shell for the given widget */ public static Shell getShell(Widget widget) { if (widget instanceof Control) return ((Control) widget).getShell(); if (widget instanceof Caret) return ((Caret) widget).getParent().getShell(); if (widget instanceof DragSource) return ((DragSource) widget).getControl().getShell(); if (widget instanceof DropTarget) return ((DropTarget) widget).getControl().getShell(); if (widget instanceof Menu) return ((Menu) widget).getParent().getShell(); if (widget instanceof ScrollBar) return ((ScrollBar) widget).getParent().getShell(); return null; }
/** * Returns the shell for the given widget. If the widget doesn't represent * a SWT object that manage a shell, <code>null</code> is returned. * @param widget the widget * * @return the shell for the given widget */ public static Shell getShell(Widget widget) { if (widget instanceof Control) return ((Control)widget).getShell(); if (widget instanceof Caret) return ((Caret)widget).getParent().getShell(); if (widget instanceof DragSource) return ((DragSource)widget).getControl().getShell(); if (widget instanceof DropTarget) return ((DropTarget)widget).getControl().getShell(); if (widget instanceof Menu) return ((Menu)widget).getParent().getShell(); if (widget instanceof ScrollBar) return ((ScrollBar)widget).getParent().getShell(); return null; }
@Override public void createPartControl(Composite parent) { parent.setLayout(new FillLayout()); this.container = parent; CellEditorGlobalActionHanlder.getInstance().setIActionBars(getViewSite().getActionBars()); DropTarget target = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY); Transfer[] tfs = new Transfer[] { FileTransfer.getInstance() }; target.setTransfer(tfs); target.addDropListener(new DropTargetAdapter() { @Override public void drop(DropTargetEvent event) { Object o = event.data; if (o instanceof String[]) { String[] s = (String[]) o; if (s.length == 0 && s[0] == null || s[0].length() == 0) { return; } File f = new File(s[0]); if (f.exists() && f.isFile()) { open(f); } } } }); }
public static void setupFileDrop(Control ctrl) { DropTarget dt = new DropTarget(ctrl, DND.DROP_DEFAULT | DND.DROP_MOVE); dt.setTransfer(new Transfer[] {FileTransfer.getInstance()}); dt.addDropListener(new DropTargetAdapter() { public void drop(DropTargetEvent event) { FileTransfer ft = FileTransfer.getInstance(); if (ft.isSupportedType(event.currentDataType)) { String[] files = (String[]) event.data; for (String file : files) { if (file.toLowerCase().endsWith(".eml")) ImportExportUtilities.importFromEmailFile(file); else if (file.toLowerCase().endsWith(".mbx")) ImportExportUtilities.importFromMbox(file); } } } }); }
/** * Returns the shell for the given widget. If the widget doesn't represent * a SWT object that manage a shell, <code>null</code> is returned. * @param widget the widget * * @return the shell for the given widget */ public static Shell getShell(Widget widget) { if (widget instanceof Control) { return ((Control) widget).getShell(); } if (widget instanceof Caret) { return ((Caret) widget).getParent().getShell(); } if (widget instanceof DragSource) { return ((DragSource) widget).getControl().getShell(); } if (widget instanceof DropTarget) { return ((DropTarget) widget).getControl().getShell(); } if (widget instanceof Menu) { return ((Menu) widget).getParent().getShell(); } if (widget instanceof ScrollBar) { return ((ScrollBar) widget).getParent().getShell(); } return null; }
/** * Register the provided target as {@link DropTarget} for a {@link PersistentObject} * @param target * @param r * @param colorizeControl whether the target control should change color during selection * @since 3.1.0 */ public PersistentObjectDropTarget(String name, Control target, IReceiver r, boolean colorizeControl){ if (colorizeControl) { normalColor = target.getBackground(); highlightColor = target.getDisplay().getSystemColor(SWT.COLOR_RED); } else { normalColor = null; highlightColor = null; } this.name = name; mine = target; rc = r; DropTarget dtarget = new DropTarget(target, DND.DROP_COPY); final TextTransfer textTransfer = TextTransfer.getInstance(); Transfer[] types = new Transfer[] { textTransfer }; dtarget.setTransfer(types); dtarget.addDropListener(this); }
public static void addDropSupport(TreeViewer tree, final IModelDropHandler handler) { final Transfer transfer = ModelTransfer.getInstance(); DropTarget dropTarget = new DropTarget(tree.getTree(), DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_DEFAULT); dropTarget.setTransfer(new Transfer[] { transfer }); dropTarget.addDropListener(new DropTargetAdapter() { @Override public void drop(DropTargetEvent event) { if (!transfer.isSupportedType(event.currentDataType)) return; List<BaseDescriptor> list = ModelTransfer .getBaseDescriptors(event.data); handler.handleDrop(list); } }); }
public DropTarget createDropTarget ( final Transfer[] transfers, final DropTargetListener dropTargetListener ) { checkWidget (); final DropTarget target = new DropTarget ( this.chartArea, DND.DROP_DEFAULT | DND.DROP_COPY | DND.DROP_LINK ); target.setTransfer ( transfers ); target.addDropListener ( dropTargetListener ); return target; }
void setDropTarget(DropTarget newTarget) { if (dropTarget != null) { targets.remove(dropTarget); dropTarget.dispose(); } dropTarget = newTarget; if (dropTarget != null) { targets.add(dropTarget); } }
static void updateDropTarget() { // Update all drop targets rather than just this target // // In order for a drop target to recognise a custom format, // the format must be registered and the transfer type added // to the list of transfers that the target accepts. This // must happen before the drag and drop operations starts // or the drop target will not accept the format. Therefore, // set all transfers for all targets before any drag and drop // operation starts // for (DropTarget target : targets) { target.setTransfer(getAllTransfers()); } }
private void addDropSupport() { DropTarget dropTarget = new DropTarget(targetList, DND.DROP_MOVE); dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() }); dropTarget.addDropListener(new DropTargetAdapter() { public void drop(DropTargetEvent event) { for (String formattedPackageName : ExpressionEditorUtil.INSTANCE.getformatedData((String) event.data)) { if (isFieldAvailable(formattedPackageName)){ targetList.add(formattedPackageName); removeAddedPackageNameFromSourceList(formattedPackageName); categoriesDialogSourceComposite.enableOrDisableAddLabelsOnComboSelection(); } } } }); }
private void addDropSupport() { DropTarget dropTarget = new DropTarget(expressionEditor, DND.DROP_MOVE); dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() }); dropTarget.addDropListener(new DropTargetAdapter() { public void drop(DropTargetEvent event) { for (String fieldName :ExpressionEditorUtil.INSTANCE.getformatedData((String) event.data)){ expressionEditor.insert(SWT.SPACE+fieldName+SWT.SPACE); } } }); }
public void applyDrop(final TableViewer tableViewerOpOuter,DragDropOperation dragDropOperation) { Transfer[] types = new Transfer[] { TextTransfer.getInstance() }; int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK; DropTarget target = new DropTarget(tableViewerOpOuter.getTable(), operations); target.setTransfer(types); target.addDropListener(new DradDropUtilityListener(dragDropOperation)); }
public void configure(CommandManager commandManager, Control control, ISelectionProvider provider) { dragAdapter = new DelegatingDragAdapter(); dragSource = new DragSource(control, DND.DROP_COPY | DND.DROP_MOVE); dragAdapter.addDragSourceListener(new OutlineDragSourceListener(provider)); dragSource.addDragListener(dragAdapter); dragSource.setTransfer(dragAdapter.getTransfers()); dropAdapter = new DelegatingDropAdapter(); dropTarget = new DropTarget(control, DND.DROP_COPY | DND.DROP_MOVE); dropAdapter.addDropTargetListener(new OutlineDropTargetListener(commandManager)); dropTarget.addDropListener(dropAdapter); dropTarget.setTransfer(dropAdapter.getTransfers()); }
private void addDropSupport(Section section) { int ops = DND.DROP_COPY | DND.DROP_LINK | DND.DROP_DEFAULT; Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() }; DropTarget dropTarget = new DropTarget(section, ops); dropTarget.setTransfer(transfers); dropTarget.addDropListener(servicesDropListener); }
/** * Creates or disposes a DropTarget as needed, and sets the supported transfer types. Clients should not need to call or * override this method. */ @Override protected void refreshDropTargetAdapter() { if (getControl() == null) return; if (getDelegatingDropAdapter().isEmpty()) setDropTarget(null); else { if (getDropTarget() == null) setDropTarget(new DropTarget(getTreeControl(), DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK)); getDropTarget().setTransfer(getDelegatingDropAdapter().getTransfers()); } }
protected void hookRecursive(Control child, DropTargetListener dropListener) { DropTarget childTarget = findDropTarget(child); if (childTarget != null) { registerWithExistingTarget(childTarget); registerDropListener(childTarget, dropListener); } if (child instanceof Composite) { Composite composite = (Composite) child; Control[] children = composite.getChildren(); for (Control control : children) { hookRecursive(control, dropListener); } } }
protected DropTarget findDropTarget(Control control) { Object object = control.getData(DND.DROP_TARGET_KEY); if (object instanceof DropTarget) { return (DropTarget) object; } return null; }
public void createPartControl(Composite parent) { //viewer this.parent = parent; documentListener = new ViewDocumentListener(); tabfolder = new TabFolder(parent,0); tabfolder.addSelectionListener(new TabSelectionListener()); viewer = new LogFileViewer(tabfolder,SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); // DnD DropTarget target = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK); target.setTransfer(new Transfer[] {FileTransfer.getInstance(), TextTransfer.getInstance()}); target.addDropListener (new DropTargetAdapter() { public void dragEnter(DropTargetEvent e) { if (e.detail == DND.DROP_NONE) e.detail = DND.DROP_COPY; } public void drop(DropTargetEvent event) { if (event.data == null || ((String[])event.data).length < 1) { event.detail = DND.DROP_NONE; return; } //File file = new File(((String[])event.data)[0]); if (!checkAndOpenFile(LogFileType.LOGFILE_SYSTEM_FILE,((String[])event.data)[0], false)) event.detail = DND.DROP_NONE; } }); // fill the menues makeActions(); hookContextMenu(); contributeToActionBars(); openAllLastOpenFiles(); }
/** Initialize * @param target Control that should receive 'dropped' items */ public TextAsPVDropTarget(final Control target) { this.target = new DropTarget(target, DND.DROP_MOVE | DND.DROP_COPY); this.target.setTransfer(new Transfer[] { TextTransfer.getInstance() }); this.target.addDropListener(this); }
@Override protected void initializeDragAndDrop(ISourceViewer viewer) { super.initializeDragAndDrop(viewer); // Adds snippet drag/drop support IDragAndDropService dndService = (IDragAndDropService) getSite().getService(IDragAndDropService.class); if (dndService == null) { return; } StyledText st = viewer.getTextWidget(); DropTarget dropTarget = (DropTarget) st.getData(DND.DROP_TARGET_KEY); if (dropTarget != null) { Transfer[] transfers = dropTarget.getTransfer(); List<Transfer> allTransfers = CollectionsUtil.newList(transfers); allTransfers.add(SnippetTransfer.getInstance()); dropTarget.setTransfer(allTransfers.toArray(new Transfer[allTransfers.size()])); dropTarget.addDropListener(new SnippetDropTargetListener()); } else { dndService.addMergedDropTarget(st, DND.DROP_COPY, new Transfer[] { SnippetTransfer.getInstance() }, new SnippetDropTargetListener()); } }
private void createDropTargetIfNecessary() { if (dropTarget == null && isActive() && !EmptyCheck.isEmpty(actions) && !EmptyCheck.isEmpty(supportedTypes)) { this.dropTarget = new DropTarget(control, DragDropUtil.createOperations(actions)); dropTarget.setTransfer(DragDropUtil.createTransfers(supportedTypes)); dropTarget.addDropListener(new DropTargetListenerImpl()); } }
@Override protected void cursorMoved( DropTarget target, Item targetItem, long time, int x, int y, TransferData[] dataTypes, int operations, DropTargetEventModifier event ) { TreeTableContentProvider contentProvider = (TreeTableContentProvider) viewer.getContentProvider(); Map.Entry<Object, InsertionSemantics> map = getTargetAndSemantics(targetItem, x, y, event); Object targetElement = map.getKey(); InsertionSemantics semantics = map.getValue(); TransferData sourceType = event.getCurrentDataType(); trace.debug("cursorMoved - "+targetElement+": "+semantics); ISelection selection = new StructuredSelection(targetElement); boolean isDragSourceEditorModel = EnsembleDragAndDropOracle.isDragSourceEditorModel(planEditorModel); if ((isDragSourceEditorModel && !contentProvider.isValidDrop(viewer.getSelection(), targetElement)) || !contentProvider.acceptsDrop(sourceType, selection, semantics)) { event.setDetail(DND.DROP_NONE); event.setFeedback(DND.FEEDBACK_NONE); } else { if (!isDragSourceEditorModel && ((operations & DND.DROP_COPY) != 0)) { event.setDetail(DND.DROP_COPY); } else if (event.getDetail() == DND.DROP_NONE) { if ((operations & DND.DROP_MOVE) != 0) { event.setDetail(DND.DROP_MOVE); } else if ((operations & DND.DROP_COPY) != 0) { event.setDetail(DND.DROP_COPY); } } event.setFeedback(getFeedback(semantics)); if (targetItem == null) { doFeedbackForNullItem(event); event.setFeedback(DND.FEEDBACK_INSERT_AFTER); } } if (shouldScroll(y)) { event.setFeedback(DND.FEEDBACK_SCROLL); } }
@Override protected void cursorLeftOrDropCancelledOrDataAboutToDrop( DropTarget target, Item targetItem, long time, int x, int y, TransferData[] dataTypes, int operations, TransferData currentDataType, int detail) { // nothing interesting to do here }
@Override protected boolean executeDrop(DropTarget target, Item targetItem, long time, int x, int y, TransferData currentDataType, int detail, Object data) { Map.Entry<Object, InsertionSemantics> map = getTargetAndSemantics(targetItem, x, y, null); Object targetElement = map.getKey(); InsertionSemantics semantics = map.getValue(); TreeTableContentProvider contentProvider = (TreeTableContentProvider) viewer.getContentProvider(); IUndoableOperation operation = contentProvider.createDropOperation(targetElement, semantics, currentDataType, detail, data); IUndoContext undoContext = viewer.getModel().getUndoContext(); WidgetUtils.execute(operation, undoContext, viewer.getControl(), viewer.getSite()); return true; }
/** * Overriden to call EnsembleDragAndDropOracle.acquireDropping so that a more efficient form * of drag data can be used for a same process drag and drop. * * @see gov.nasa.ensemble.common.ui.transfers.TransferRegistry#getDragData(gov.nasa.ensemble.common.ui.transfers.ITransferable, org.eclipse.swt.dnd.TransferData) */ @Override public void dropAccept(DropTargetEvent event) { super.dropAccept(event); DropTarget target = (DropTarget)event.widget; EnsembleDragAndDropOracle.acquireDropping(target); }
private void initDragAndDrop() { addDragAdapters(fCallHierarchyViewer); addDropAdapters(fCallHierarchyViewer); addDropAdapters(fLocationViewer); //dnd on empty hierarchy DropTarget dropTarget = new DropTarget(fPagebook, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_DEFAULT); dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getInstance() }); dropTarget.addDropListener(new CallHierarchyTransferDropAdapter(this, fCallHierarchyViewer)); }
private void initDragAndDrop() { for (int i= 0; i < fAllViewers.length; i++) { addDragAdapters(fAllViewers[i]); addDropAdapters(fAllViewers[i]); } addDragAdapters(fMethodsViewer); fMethodsViewer.addDropSupport(DND.DROP_NONE, new Transfer[0], new DropTargetAdapter()); //DND on empty hierarchy DropTarget dropTarget = new DropTarget(fPagebook, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_DEFAULT); dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getInstance() }); dropTarget.addDropListener(new TypeHierarchyTransferDropAdapter(this, fAllViewers[0])); }
/** * Register DragDropAdapter */ private void registerDragDrop() { // Drag-Part ////////////////////////////////////////////////////////// DragSource source = new DragSource(tree, DND.DROP_COPY | DND.DROP_MOVE); source.setTransfer(new Transfer[] { TextTransfer.getInstance() }); source.addDragListener(new TreeDragSourceListener(tree)); // Drop-Part ////////////////////////////////////////////////////////// DropTarget dropTarget = new DropTarget(tree, DND.DROP_COPY | DND.DROP_DEFAULT); dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance(), FileTransfer.getInstance() }); dropTarget.addDropListener(new TreeDropTargetAdapter(viewer, root)); }
/** * Returns the current mouse location, as a {@link Point}. The location is * relative to the control's client area. * * @return the drop location */ protected Point getDropLocation() { org.eclipse.swt.graphics.Point swt; swt = new org.eclipse.swt.graphics.Point(getCurrentEvent().x, getCurrentEvent().y); DropTarget target = (DropTarget) getCurrentEvent().widget; swt = target.getControl().toControl(swt); return new Point(swt.x, swt.y); }
/** * Creates or disposes a DropTarget as needed, and sets the supported * transfer types. Clients should not need to call or override this method. */ protected void refreshDropTargetAdapter() { if (getControl() == null) return; if (getDelegatingDropAdapter().isEmpty()) setDropTarget(null); else { if (getDropTarget() == null) setDropTarget(new DropTarget(getControl(), DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK)); getDropTarget().setTransfer( getDelegatingDropAdapter().getTransfers()); } }
/** * Sets the drop target. Called from {@link #refreshDropTargetAdapter()}. * * @param target * dropTarget <code>null</code> or a drop target */ protected void setDropTarget(DropTarget target) { if (dropTarget != null) dropTarget.dispose(); dropTarget = target; if (dropTarget != null) hookDropTarget(); }
private void hookRecursive(Control child, DropTargetListener dropListener) { DropTarget childTarget = findDropTarget(child); if (childTarget != null) { registerWithExistingTarget(childTarget); registerDropListener(childTarget, dropListener); } if (child instanceof Composite) { Composite composite = (Composite) child; Control[] children = composite.getChildren(); for (Control control : children) { hookRecursive(control, dropListener); } } }