org.eclipse.swt.dnd.DropTargetEvent Java Examples
The following examples show how to use
org.eclipse.swt.dnd.DropTargetEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TmxEditorViewer.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
@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); } } } }); }
Example #2
Source File: XViewerCustDialogDragDrop.java From nebula with Eclipse Public License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public void performHiddenTableTextDrop(DropTargetEvent event) { String droppedIds = (String) event.data; List<XViewerColumn> droppedVisibleTableXCols = new ArrayList<>(); List<XViewerColumn> orderCols = (List<XViewerColumn>) xViewerCustomizeDialog.visibleColTable.getViewer().getInput(); for (XViewerColumn xCol : orderCols) { if (droppedIds.contains(xCol.getId())) { droppedVisibleTableXCols.add(xCol); } } xViewerCustomizeDialog.moveFromVisibleToHidden(droppedVisibleTableXCols); }
Example #3
Source File: AbstractThemeableEditor.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
public void drop(DropTargetEvent event) { if (event.data instanceof SnippetElement) { SnippetElement snippet = (SnippetElement) event.data; CommandResult commandResult = CommandExecutionUtils.executeCommand(snippet, InvocationType.MENU, AbstractThemeableEditor.this); if (commandResult == null) { BundleElement bundle = snippet.getOwningBundle(); String bundleName = (bundle == null) ? "Unknown bundle" : bundle.getDisplayName(); //$NON-NLS-1$ IdeLog.logError(CommonEditorPlugin.getDefault(), MessageFormat.format("Error executing command {0} in bundle {1}. Command returned null.", //$NON-NLS-1$ snippet.getDisplayName(), bundleName), IDebugScopes.DRAG_DROP); } else { CommandExecutionUtils.processCommandResult(snippet, commandResult, AbstractThemeableEditor.this); AbstractThemeableEditor.this.setFocus(); } } }
Example #4
Source File: AbapGitStagingView.java From ADT_Frontend with MIT License | 6 votes |
private void addDragAndDropSupport(TreeViewer viewer, final boolean unstaged) { viewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK, new Transfer[] { LocalSelectionTransfer.getTransfer(), LocalSelectionTransfer.getTransfer() }, new StagingDragListener(viewer, ArrayContentProvider.getInstance(), unstaged)); viewer.addDropSupport(DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new DropTargetAdapter() { public void drop(DropTargetEvent event) { event.detail = DND.DROP_COPY; if (event.data instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) event.data; if (selection instanceof StagingDragSelection && ((StagingDragSelection) selection).isFromUnstaged() == unstaged) { return; } if (((StagingDragSelection) selection).isFromUnstaged()) { stageSelectedObjects(selection); } else { unstageSelectedObjects(selection); } } } }); }
Example #5
Source File: DropAdapterExtension.java From neoscada with Eclipse Public License 1.0 | 6 votes |
@Override protected Collection<?> getDragSource ( final DropTargetEvent event ) { final ItemTransfer itemTransfer = ItemTransfer.getInstance (); if ( itemTransfer.isSupportedType ( event.currentDataType ) ) { if ( IS_MOTIF ) { return null; } final Object object = itemTransfer.nativeToJava ( event.currentDataType ); return object == null ? null : extractDragSource ( object ); } else { return super.getDragSource ( event ); } }
Example #6
Source File: DropAdapterExtension.java From neoscada with Eclipse Public License 1.0 | 6 votes |
@Override protected Collection<?> getDragSource ( final DropTargetEvent event ) { // Check whether the current data type can be transfered locally. // final ItemTransfer itemTransfer = ItemTransfer.getInstance (); if ( itemTransfer.isSupportedType ( event.currentDataType ) ) { // Motif kludge: we would get something random instead of null. // if ( IS_MOTIF ) { return null; } // Transfer the data and, if non-null, extract it. // final Object object = itemTransfer.nativeToJava ( event.currentDataType ); return object == null ? null : extractDragSource ( object ); } else { return super.getDragSource ( event ); } }
Example #7
Source File: JdtViewerDropAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public void dragOver(DropTargetEvent event) { //use newly revealed item as target if scrolling occurs Object target = determineTarget(event); //set the location feedback int oldLocation = currentLocation; currentLocation = determineLocation(event); setFeedback(event, currentLocation); //see if anything has really changed before doing validation. if (target != currentTarget || currentLocation != oldLocation) { currentTarget = target; doDropValidation(event); } }
Example #8
Source File: GridDropTargetEffect.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * This implementation of <code>dragLeave</code> provides a default drag under effect * for the feedback specified in <code>event.feedback</code>. * * For additional information see <code>DropTargetAdapter.dragLeave</code>. * * Subclasses that override this method should call <code>super.dragLeave(event)</code> * to get the default drag under effect implementation. * * @param event the information associated with the drag leave event * * @see DropTargetAdapter * @see DropTargetEvent */ public void dragLeave(DropTargetEvent event) { if (selectedCell != null) { deselect(selectedCell); selectedCell = null; } if (insertCell != null) { setInsertMark(null, false); insertCell = null; } expandBeginTime = 0; expandItem = null; scrollBeginTime = 0; scrollItem = null; }
Example #9
Source File: ExampleDropTargetListener.java From statecharts with Eclipse Public License 1.0 | 6 votes |
@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); } }); } }
Example #10
Source File: LibraryTemplateTransferDropTargetListener.java From birt with Eclipse Public License 1.0 | 6 votes |
public void dragOver( DropTargetEvent event ) { super.dragOver( event ); if ( getTargetEditPart( ) == null ) { event.detail = DND.DROP_NONE; return; } // if ( getTargetEditPart( ).getModel( ) instanceof LibraryHandle ) // { // List list = getTargetEditPart( ).getChildren( ); // if ( list.size( ) > 0 && !( list.get( 0 ) instanceof EmptyEditPart ) ) // { // event.detail = DND.DROP_NONE; // } // } }
Example #11
Source File: GridDropTargetEffect.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * This implementation of <code>dragLeave</code> provides a default drag under effect * for the feedback specified in <code>event.feedback</code>. * * For additional information see <code>DropTargetAdapter.dragLeave</code>. * * Subclasses that override this method should call <code>super.dragLeave(event)</code> * to get the default drag under effect implementation. * * @param event the information associated with the drag leave event * * @see DropTargetAdapter * @see DropTargetEvent */ public void dragLeave(DropTargetEvent event) { if (selectedCell != null) { deselect(selectedCell); selectedCell = null; } if (insertCell != null) { setInsertMark(null, false); insertCell = null; } expandBeginTime = 0; expandItem = null; scrollBeginTime = 0; scrollItem = null; }
Example #12
Source File: ExampleDropTargetListener.java From statecharts with Eclipse Public License 1.0 | 6 votes |
private boolean dropTargetIsValid(DropTargetEvent e, boolean isDrop) { if (URLTransfer.getInstance().isSupportedType(e.currentDataType)) { // on Windows, we get the URL already during drag operations... // FIXME find a way to check the URL early on other platforms, // too... if (isDrop || Util.isWindows()) { if (e.data == null && !extractEventData(e)) { // ... but if we don't, it's no problem, unless this is // already // the final drop event return !isDrop; } final String url = getUrl(e.data); if (!ExampleURLHandler.isValidExample(url)) { return false; } } return true; } return false; }
Example #13
Source File: GridDropTargetEffect.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * This implementation of <code>dragLeave</code> provides a default drag under effect * for the feedback specified in <code>event.feedback</code>. * * For additional information see <code>DropTargetAdapter.dragLeave</code>. * * Subclasses that override this method should call <code>super.dragLeave(event)</code> * to get the default drag under effect implementation. * * @param event the information associated with the drag leave event * * @see DropTargetAdapter * @see DropTargetEvent */ public void dragLeave(DropTargetEvent event) { if (selectedCell != null) { deselect(selectedCell); selectedCell = null; } if (insertCell != null) { setInsertMark(null, false); insertCell = null; } expandBeginTime = 0; expandItem = null; scrollBeginTime = 0; scrollItem = null; }
Example #14
Source File: FilterDropTargetAdapter.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
@Override public void drop(DropTargetEvent event) { ITmfFilterTreeNode treeNodeToDrop = FilterEditUtils.getTransferredTreeNode(); if (event.item instanceof TreeItem) { Object data = event.item.getData(); if (data instanceof ITmfFilterTreeNode) { ITmfFilterTreeNode node = (ITmfFilterTreeNode) data; if (node.getValidChildren().contains(treeNodeToDrop.getNodeName())) { treeNodeToDrop = treeNodeToDrop.clone(); node.addChild(treeNodeToDrop); fViewer.refresh(); fViewer.setSelection(treeNodeToDrop, true); return; } } } else { // accept only TmfFilterNode if (TmfFilterNode.NODE_NAME.equals(treeNodeToDrop.getNodeName())) { ITmfFilterTreeNode root = fViewer.getInput(); treeNodeToDrop = treeNodeToDrop.clone(); root.addChild(treeNodeToDrop); fViewer.refresh(); fViewer.setSelection(treeNodeToDrop, true); return; } } }
Example #15
Source File: AbstractThemeableEditor.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public void dragOver(DropTargetEvent event) { if (event.data instanceof SnippetElement) { event.feedback |= DND.FEEDBACK_SCROLL; } }
Example #16
Source File: WorkingSetDropAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ public boolean isEnabled(DropTargetEvent event) { Object target= event.item != null ? event.item.getData() : null; if (target == null) return false; ISelection selection= LocalSelectionTransfer.getInstance().getSelection(); if (!isValidSelection(selection)) { return false; } if (!isValidTarget(target)) return false; initializeState(target, selection); return true; }
Example #17
Source File: FileTransferDropAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ public boolean isEnabled(DropTargetEvent event) { Object target= event.item != null ? event.item.getData() : null; if (target == null) return false; return target instanceof IJavaElement || target instanceof IResource; }
Example #18
Source File: SelectionTransferDropAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ public boolean isEnabled(DropTargetEvent event) { Object target= event.item != null ? event.item.getData() : null; if (target == null) return false; return target instanceof IJavaElement || target instanceof IResource; }
Example #19
Source File: DesignerDropListener.java From birt with Eclipse Public License 1.0 | 5 votes |
public void dragEnter( DropTargetEvent event ) { if ( ( event.operations & DND.DROP_COPY ) != 0 && ( event.operations & DND.DROP_MOVE ) == 0 ) { event.detail = DND.DROP_COPY; } super.dragEnter( event ); }
Example #20
Source File: JdtViewerDropAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void setFeedback(DropTargetEvent event, int location) { if (feedbackEnabled) { switch (location) { case LOCATION_BEFORE: event.feedback = DND.FEEDBACK_INSERT_BEFORE; break; case LOCATION_AFTER: event.feedback = DND.FEEDBACK_INSERT_AFTER; break; case LOCATION_ON: default: event.feedback = DND.FEEDBACK_SELECT; break; } } // Explicitly inhibit SELECT feedback if desired if (!selectFeedbackEnabled) { event.feedback &= ~DND.FEEDBACK_SELECT; } if (expandEnabled) { event.feedback |= DND.FEEDBACK_EXPAND; } if (scrollEnabled) { event.feedback |= DND.FEEDBACK_SCROLL; } }
Example #21
Source File: EditorAreaDropAdapter.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public void drop(final DropTargetEvent event) { Display d = window.getShell().getDisplay(); final IWorkbenchPage page = window.getActivePage(); if (page != null) { d.asyncExec(new Runnable() { public void run() { asyncDrop(event, page); } }); } }
Example #22
Source File: EditorAreaDropAdapter.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public void drop(final DropTargetEvent event) { Display d = window.getShell().getDisplay(); final IWorkbenchPage page = window.getActivePage(); if (page != null) { d.asyncExec(new Runnable() { public void run() { asyncDrop(event, page); } }); } }
Example #23
Source File: PhotoShuffler.java From codeexamples-eclipse with Eclipse Public License 1.0 | 5 votes |
/** * This method moves the dragged picture to the new position and shifts the * old picture to the right or left. */ public void drop(DropTargetEvent event) { // retrieve the stored index int sourceIndex = Integer.valueOf(event.data.toString()); // compute the index of target control Control targetControl = target.getControl(); int targetIndex = -1; for (int i = 0; i < parentComposite.getChildren().length; i++) { if (parentComposite.getChildren()[i].equals(targetControl)) { targetIndex = i; break; } } Control sourceControl = parentComposite.getChildren()[sourceIndex]; // do not do anything if the dragged photo is dropped at the same // position if (targetIndex == sourceIndex) return; // if dragged from left to right // shift the old picture to the left if (targetIndex > sourceIndex) sourceControl.moveBelow(targetControl); // if dragged from right to left // shift the old picture to the right else sourceControl.moveAbove(targetControl); // repaint the parent composite parentComposite.requestLayout(); }
Example #24
Source File: View.java From codeexamples-eclipse with Eclipse Public License 1.0 | 5 votes |
private void addDropListener(Composite parent) { LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); DropTargetAdapter dragAdapter = new DropTargetAdapter() { @Override public void drop(DropTargetEvent event) { Control droppedObj = (Control) ((StructuredSelection) transfer.getSelection()).getFirstElement(); // Get the existing parent of the dragged control Composite oldParent = droppedObj.getParent(); if (oldParent == parent) { return; } if (droppedObj instanceof Label) { System.out.println("Dropped"); } // handle the drop if (droppedObj instanceof Label) { Label droppedLabel = (Label) droppedObj; droppedLabel.setParent(parent); // Change parent } if (droppedObj instanceof Button) { Button droppedButton = (Button) droppedObj; droppedButton.setParent(parent); // Change parent } // request a layout pass oldParent.requestLayout(); // If you change that to layout the layout will be correct parent.layout(); } }; DropTarget dropTarget = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY); dropTarget.setTransfer(new Transfer[] { transfer }); dropTarget.addDropListener(dragAdapter); }
Example #25
Source File: JdtViewerDropAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void drop(DropTargetEvent event) { currentLocation = determineLocation(event); //perform the drop behavior if (!performDrop(event.data)) { event.detail = DND.DROP_NONE; } currentOperation = event.detail; }
Example #26
Source File: ExampleDropTargetListener.java From statecharts with Eclipse Public License 1.0 | 5 votes |
private void setDropOperation(DropTargetEvent e) { int allowedOperations = e.operations; for (int op : PREFERRED_DROP_OPERATIONS) { if ((allowedOperations & op) != 0) { e.detail = op; return; } } e.detail = allowedOperations; }
Example #27
Source File: NavigatorDropAssistant.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public IStatus handleDrop(final CommonDropAdapter adapter, final DropTargetEvent event, final Object target) { if (FileTransfer.getInstance().isSupportedType(event.currentDataType)) { final String[] files = (String[]) event.data; if (files != null && files.length > 0) { PasteAction.handlePaste(files); return Status.OK_STATUS; } } else if (ResourceTransfer.getInstance().isSupportedType(event.currentDataType)) { } return Status.CANCEL_STATUS; }
Example #28
Source File: TabFolderReorder.java From hop with Apache License 2.0 | 5 votes |
private void moveTabs( CTabFolder folder, DropTargetEvent event ) { Point point = folder.toControl( folder.getDisplay().getCursorLocation() ); CTabItem item = folder.getItem( new Point( point.x, point.y ) ); if ( item != null && dragItem != null ) { Control dragControl = dragItem.getControl(); String dragText = dragItem.getText(); Image dragImage = dragItem.getImage(); String dragToolTip = dragItem.getToolTipText(); boolean dragShowClose = dragItem.getShowClose(); Object dragData = dragItem.getData(); dragItem.setText( item.getText() ); dragItem.setImage( item.getImage() ); dragItem.setToolTipText( item.getToolTipText() ); dragItem.setData( item.getData() ); dragItem.setShowClose( item.getShowClose() ); dragItem.setControl( item.getControl() ); item.setText( dragText ); item.setImage( dragImage ); item.setToolTipText( dragToolTip ); item.setData( dragData ); item.setShowClose( dragShowClose ); item.setControl( dragControl ); folder.setSelection( item ); } }
Example #29
Source File: ExampleDropTargetListener.java From statecharts with Eclipse Public License 1.0 | 5 votes |
private boolean extractEventData(DropTargetEvent e) { TransferData transferData = e.currentDataType; if (transferData != null) { Object data = URLTransfer.getInstance().nativeToJava(transferData); if (data != null && getUrl(data) != null) { e.data = data; return true; } } return false; }
Example #30
Source File: LogViewer.java From LogViewer with Eclipse Public License 2.0 | 5 votes |
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], null, false)) event.detail = DND.DROP_NONE; } }); // fill the menues makeActions(); hookContextMenu(); contributeToActionBars(); openAllLastOpenFiles(); }