@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 ); } }
@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 ); } }
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(); } }); }
@Override public void drop(DropTargetEvent event) { IStructuredSelection structuredSelection = (IStructuredSelection) LocalSelectionTransfer .getTransfer().getSelection(); if (structuredSelection.size() == 1) { AvroNode sourceNode = (AvroNode) structuredSelection.getFirstElement(); TreeItem item = (TreeItem) event.item; if (item != null) { AvroNode targetNode = nodeConverter.convertToAvroNode(item.getData()); dropPolicy.drop(sourceNode, targetNode, position); } } }
@Test @Ignore public void testDropOn() { // Given BookmarkFolder bookmarkFolderToMoved = getBookmarkFolder(bookmarkDatabase.getBookmarksTree(), 1, 1, 1); IStructuredSelection data = new StructuredSelection(bookmarkFolderToMoved); BookmarkFolder currentTarget = getBookmarkFolder(bookmarkDatabase.getBookmarksTree(), 1, 1); BookmarksViewerDropListener listener = getBookmarksViewerDropListener(ViewerDropAdapter.LOCATION_ON, currentTarget); // When DropTargetEvent dropTargetEvent = mock(DropTargetEvent.class); listener.dragEnter(dropTargetEvent); listener.dragOver(dropTargetEvent); listener.dropAccept(dropTargetEvent); listener.drop(dropTargetEvent); // assertTrue(listener.validateDrop(currentTarget, ViewerDropAdapter.LOCATION_ON, /* transferType */ null)); // boolean result = listener.performDrop(data); // Then // assertTrue(result); assertEquals(1, bookmarksListener.getModifications().size()); assertIsBookmarksMovedModification(bookmarksListener.getModifications().get(0), currentTarget.getId(), Lists.newArrayList(bookmarkFolderToMoved.getId())); }
@Override public void drop(DropTargetEvent event) { int location = this.determineLocation(event); source = getSelectedObject(); target = determineTarget(event); String translatedLocation = ""; switch (location) { case ViewerDropAdapter.LOCATION_BEFORE: translatedLocation = "Dropped before the target "; break; case ViewerDropAdapter.LOCATION_AFTER: translatedLocation = "Dropped after the target "; break; case ViewerDropAdapter.LOCATION_ON: translatedLocation = "Dropped on the target "; break; case ViewerDropAdapter.LOCATION_NONE: translatedLocation = "Dropped into nothing "; break; } System.out.println(translatedLocation); System.out.println("The drop was done on the element: " + target); super.drop(event); }
/** * get the outline items being dropped, or null if there are none or if the event does not * qualify for a drop. */ @SuppressWarnings("unchecked") private List<PagePart> getDropItems(DropTargetEvent event) { if (event.operations == DND.DROP_NONE || event.item == null) { return null; } Object targetData = event.item.getData(); if (!(targetData instanceof PagePart)) { return null; } ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); if (selection instanceof IStructuredSelection && !selection.isEmpty()) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; List<?> list = structuredSelection.toList(); if (!list.isEmpty()) { for (Object i : list) { if (!(i instanceof PagePart)) return null; } return (List<PagePart>) list; } } return null; }
/** * @see org.eclipse.swt.dnd.DropTargetListener#drop(org.eclipse.swt.dnd.DropTargetEvent) */ @Override public void drop(DropTargetEvent event) { Object data = event.data; if (data instanceof String[]) { final String[] strings = (String[]) data; BusyIndicator.showWhile(null, new Runnable() { @Override public void run() { for (int i = 0; i < strings.length; i++) { processString(strings[i]); } } }); } }
/** * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.ui.navigator.CommonDropAdapter, * org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object) */ @Override public IStatus handleDrop(CommonDropAdapter dropAdapter, DropTargetEvent event, Object target) { switch (event.detail) { case DND.DROP_DEFAULT: case DND.DROP_MOVE: return handleDropMove(target, event); case DND.DROP_COPY: return handleDropCopy(target, event); default: break; } return Status.CANCEL_STATUS; }
/** * @see nexcore.tool.uml.ui.core.diagram.editor.DiagramDropTargetListener#dropCommandForNode(org.eclipse.swt.dnd.DropTargetEvent, * org.eclipse.gef.commands.CompoundCommand, * nexcore.tool.uml.ui.core.project.ITreeNode, int) */ @Override protected void dropCommandForNode(DropTargetEvent event, CompoundCommand commpoundCommand, ITreeNode next, int count) { Element treeElement = (Element) next.getEObject(); int horizontalScrollPoint = 0; int verticalScrollPoint = 0; Point eventPoint = null; Command command = null; org.eclipse.draw2d.geometry.Point where = null; horizontalScrollPoint = ((FigureCanvas) diagramEditor.getDiagramGraphicalViewer().getControl()).getHorizontalBar() .getSelection(); verticalScrollPoint = ((FigureCanvas) diagramEditor.getDiagramGraphicalViewer().getControl()).getVerticalBar() .getSelection(); eventPoint = diagramEditor.getDiagramGraphicalViewer().getControl().toControl(event.x + horizontalScrollPoint, event.y + verticalScrollPoint); // y좌표에 +100은 여러개를 Dorp했을때 대각선 아래로 위치하도록 한다. where = new org.eclipse.draw2d.geometry.Point(eventPoint.x + (count * 160), eventPoint.y);//20); command = new DropLifeLineNotationCommand(UMLMessage.LABEL_ADD_DROP, diagramEditor, treeElement, where); ((DropLifeLineNotationCommand) command).setDiagram(this.diagramEditor.getDiagram()); commpoundCommand.add(command); }
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; }
@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); } }); } }
private TreeItem getSelected(DropTargetEvent event) { try { TreeItem selected = (TreeItem)event.item; if (! OSTool.isSystemWindows()) { // There is a bug in SWT under Linux : // If the Tree has been configured to display column headers ("setHeaderVisible(true)"), // the "item" attribute of the DropTargetEvent references the TreeItem UNDER the actually selected item ! // That's why we must "play" with the item's coordinates :( int x = selected.getBounds().x + 2; int y = selected.getBounds().y - selected.getBounds().height + 2; selected = treFilters.getItem(new Point(x, y)); } return selected; } catch (RuntimeException e) { return null; } }
public void drop(DropTargetEvent event) { if (!transfer.isSupportedType(event.currentDataType)){ return; } IProject currProj = getProject(); if (currProj == null){ return; } IResource[] resa = (IResource[])event.data; StringBuilder sb = new StringBuilder(256); sb.append(_getText()); int len = sb.length(); if (len > 0 && sb.charAt(len-1) == '\n') { sb.setLength(len-1); } for (int i = 0; i < resa.length; i++) { IResource res = resa[i]; if (res.getProject().equals(currProj)) { sb.append("\n").append(res.getProjectRelativePath()); } } _setText(sb.toString()); }
@Override public void dragOver(DropTargetEvent event) { boolean match = false; for (CoreDropTargetListener listener : listeners) { if(listener.appliesTo(event)) { match = true; listener.dragOver(event); } else { listener.reset(); } } if(!match) { event.detail = DND.DROP_NONE; } }
@Override public void drop(DropTargetEvent event) { for (CoreDropTargetListener listener : listeners) { if (listener.appliesTo(event)) { listener.drop(event); } else { listener.reset(); } } }
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(); } } }
@Override public void drop(DropTargetEvent event) { if (event.data == null) { // case of DND drop with stepSource on Linux, see #4473 for (TransferData transferData : event.dataTypes) { if (StepSourceTransfer.getInstance().isSupportedType(transferData)) { event.data = StepSourceTransfer.getInstance().getStepSource(); break; } if (PaletteSourceTransfer.getInstance().isSupportedType(transferData)) { event.data = PaletteSourceTransfer.getInstance().getPaletteSource(); break; } if (MobileSourceTransfer.getInstance().isSupportedType(transferData)) { event.data = MobileSourceTransfer.getInstance().getMobileSource(); break; } } if (event.data == null) { return; } } if ("gtk".equalsIgnoreCase(SWT.getPlatform()) && event.detail == 0) { event.detail = DND.DROP_MOVE; } detail = event.detail; ConvertigoPlugin.clipboardManagerDND.isCopy = (event.detail == DND.DROP_COPY); ConvertigoPlugin.clipboardManagerDND.isCut = (event.detail == DND.DROP_MOVE); super.drop(event); }
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 drop(DropTargetEvent event) { if (event.data == null) { event.detail = DND.DROP_NONE; return; } String[] dropData = ((String) event.data).split(Pattern.quote("#")); for(String result:dropData) { dragDropOperation.saveResult(result); } }
@Override public void dropAction(DropTargetEvent event) { if(i==0){ super.dropAction(event); i++; } if(i>1){ return; } }
public void dragOver(DropTargetEvent event) { event.feedback = DND.FEEDBACK_SELECT; float location = computeRelativeLocation(event); if (location > THRESHOLD) { event.feedback = DND.FEEDBACK_INSERT_AFTER; } else { event.feedback = DND.FEEDBACK_INSERT_BEFORE; } // always provide expand/scroll capability when dragging event.feedback |= DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL; }
public void drop(DropTargetEvent event) { List<PagePart> dropItems = getDropItems(event); if (dropItems != null) { Insert location = computeInsertLocation(event); Object targetData = event.item.getData(); final AbstractDocumentCommand command = computeCommand(targetData, dropItems, location); if (command != null) { if (command.isEnabled()) { SafeRunnable.run(new ISafeRunnable() { public void run() throws Exception { commandManager.perform(command); } public void handleException(Throwable exception) { Log.error(exception); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.OutlineDropTargetListener_0, NLS.bind(Messages.OutlineDropTargetListener_1, new Object[] { exception.getMessage() })); } }); } else { MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.OutlineDropTargetListener_2, NLS.bind(Messages.OutlineDropTargetListener_3, new Object[] { command.getProblemText() })); } } } }
private float computeRelativeLocation(DropTargetEvent event) { if (event.item == null) return 0.0f; if (event.item instanceof TreeItem) { TreeItem treeItem = (TreeItem) event.item; Control control = treeItem.getParent(); Point eventAt = control.toControl(new Point(event.x, event.y)); Rectangle bounds = treeItem.getBounds(); return (float) (eventAt.y - bounds.y) / (float) bounds.height; } return 0.0f; }
@Override public void dragEnter(DropTargetEvent event) { if (event.detail == DND.DROP_DEFAULT || event.detail == DND.DROP_NONE) { event.detail = DND.DROP_COPY; } super.dragEnter(event); }
/** * @see org.eclipse.jface.util.TransferDropTargetListener#isEnabled(org.eclipse.swt.dnd.DropTargetEvent) */ public boolean isEnabled(DropTargetEvent event) { ISelection transferObject = (TreeSelection) this.transfer.getSelection(); if (!(transferObject instanceof TreeSelection)) { return false; } return checkTreeSectionSource((TreeSelection) transferObject); }
/** * @see org.eclipse.swt.dnd.DropTargetListener#drop(org.eclipse.swt.dnd.DropTargetEvent) */ @SuppressWarnings("unchecked") public void drop(DropTargetEvent event) { if (event.data instanceof TreeSelection) { TreeSelection selection = (TreeSelection) event.data; if (!checkTreeSectionSource(selection)) { return; } viewModelListInDiagram.clear(); viewModelListInDiagram.addAll(this.diagramEditor.getDiagram().getNodeList()); CompoundCommand commpoundCommand = new CompoundCommand(); int count = 0; Object object = null; for (Iterator<Object> i = selection.iterator(); i.hasNext();) { object = i.next(); if (object instanceof ITreeNode) { // UML 요소일 경우 dropCommandForNode(event, commpoundCommand, (ITreeNode) object, count); count++; } } diagramEditor.getDiagramCommandStack().execute(commpoundCommand); } }
/** * UmlElement drop 처리 * * @param next * @param count * void */ protected void dropCommandForNode(DropTargetEvent event, CompoundCommand commpoundCommand, ITreeNode next, int count) { Element treeElement = (Element) next.getEObject(); int horizontalScrollPoint = 0; int verticalScrollPoint = 0; Point eventPoint = null; Command command = null; org.eclipse.draw2d.geometry.Point where = null; NotationNode node = null; horizontalScrollPoint = ((FigureCanvas) diagramEditor.getDiagramGraphicalViewer().getControl()).getHorizontalBar() .getSelection(); verticalScrollPoint = ((FigureCanvas) diagramEditor.getDiagramGraphicalViewer().getControl()).getVerticalBar() .getSelection(); eventPoint = diagramEditor.getDiagramGraphicalViewer().getControl().toControl(event.x + horizontalScrollPoint, event.y + verticalScrollPoint); // y좌표에 +100은 여러개를 Dorp했을때 대각선 아래로 위치하도록 한다. where = new org.eclipse.draw2d.geometry.Point(eventPoint.x + (count * 100), eventPoint.y + (count * 100)); node = createNotationNode(treeElement); node.setX(where.x); node.setY(where.y); command = new DropNotationCommand("Add drop"); ((DropNotationCommand) command).setDiagram(this.diagramEditor.getDiagram()); ((DropNotationCommand) command).setChild(node); commpoundCommand.add(command); if (!viewModelListInDiagram.contains(node)) { viewModelListInDiagram.add(node); } getNotationNodeWithRelation(commpoundCommand, node); // this.getNotationNodeAsAssociation(commpoundCommand, node); // this.getNotationNodeAsSource(commpoundCommand, node); // this.getNotationNodeAsTarget(commpoundCommand, node); }
private void handleDropAction(final DropAction dropAction, final boolean rejected, final DropTargetEvent event) { if (rejected && dropAction == null) { event.detail = DND.DROP_NONE; } else if (dropAction != null) { event.detail = DragDropUtil.createOperations(Collections.singleton(dropAction)); } }
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; }
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; }
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(); }
public void dragOperationChanged(DropTargetEvent event) { if (event.detail == DND.DROP_DEFAULT) { if ((event.operations & DND.DROP_COPY) != 0) { event.detail = DND.DROP_COPY; } else { event.detail = DND.DROP_NONE; } } }
@Override public void dragEnter(final DropTargetEvent event) { if ((event.operations & DND.DROP_COPY) != 0) event.detail = DND.DROP_COPY; else event.detail = DND.DROP_NONE; }
@Override public void drop(DropTargetEvent event) { // Drop only the allowed items String[] items = (String[])event.data; for(String item : items){ String fileExt = Misc.nvl(FilenameUtils.getExtension(item).toLowerCase()); if(RepositoryDNDHelper.isDropOperationAllowed(fileExt) && event.item!=null && event.item.getData() instanceof MResource && event.data instanceof String[]){ MResource targetParentResource = (MResource) event.item.getData(); RepositoryDNDHelper.performDropOperation(targetParentResource, item); } } }
@Override public void dropAccept(final DropTargetEvent event) { handleDropTargetEvent(event, new IEventPublisher() { @Override public void fireEvent(final IDropEventSpi dropEvent, final IDropResponseSpi dropResponse) { fireDropAccept(dropEvent, dropResponse); } }); }
@Override public boolean isEnabled(DropTargetEvent event) { if(event.data!=null){ // check if it can be an image return isDroppedDataAnImage(event); } return super.isEnabled(event); }