/** * Set the clipboard contents. Prompt to retry if clipboard is busy. * * @param resources * the resources to copy to the clipboard * @param fileNames * file names of the resources to copy to the clipboard * @param names * string representation of all names */ private void setClipboard(final IResource[] resources, final String[] fileNames, final String names) { try { // set the clipboard contents if (fileNames.length > 0) { clipboard.setContents(new Object[] { resources, fileNames, names }, new Transfer[] { ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() }); } else { clipboard.setContents(new Object[] { resources, names }, new Transfer[] { ResourceTransfer.getInstance(), TextTransfer.getInstance() }); } } catch (final SWTError e) { if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) { throw e; } if (MessageDialog.openQuestion(shell, "Problem with copy title", // TODO //$NON-NLS-1$ // ResourceNavigatorMessages.CopyToClipboardProblemDialog_title, "Problem with copy.")) { //$NON-NLS-1$ setClipboard(resources, fileNames, names); } } }
/** * This creates a context menu for the viewer and adds a listener as well registering the menu for extension. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void createContextMenuFor ( StructuredViewer viewer ) { MenuManager contextMenu = new MenuManager ( "#PopUp" ); //$NON-NLS-1$ contextMenu.add ( new Separator ( "additions" ) ); //$NON-NLS-1$ contextMenu.setRemoveAllWhenShown ( true ); contextMenu.addMenuListener ( this ); Menu menu = contextMenu.createContextMenu ( viewer.getControl () ); viewer.getControl ().setMenu ( menu ); getSite ().registerContextMenu ( contextMenu, new UnwrappingSelectionProvider ( viewer ) ); int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance (), LocalSelectionTransfer.getTransfer (), FileTransfer.getInstance () }; viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) ); viewer.addDropSupport ( dndOperations, transfers, new EditingDomainViewerDropAdapter ( editingDomain, viewer ) ); }
/** * This creates a context menu for the viewer and adds a listener as well * registering the menu for extension. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated NOT */ protected void createContextMenuFor ( final StructuredViewer viewer ) { final MenuManager contextMenu = new MenuManager ( "#PopUp" ); //$NON-NLS-1$ contextMenu.add ( new Separator ( "additions" ) ); //$NON-NLS-1$ contextMenu.setRemoveAllWhenShown ( true ); contextMenu.addMenuListener ( this ); final Menu menu = contextMenu.createContextMenu ( viewer.getControl () ); viewer.getControl ().setMenu ( menu ); getSite ().registerContextMenu ( contextMenu, new UnwrappingSelectionProvider ( viewer ) ); final int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; final Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance (), LocalSelectionTransfer.getTransfer (), FileTransfer.getInstance (), ItemTransfer.getInstance () }; viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) ); viewer.addDropSupport ( dndOperations, transfers, new DropAdapterExtension ( this.editingDomain, viewer ) ); }
/** * This creates a context menu for the viewer and adds a listener as well * registering the menu for extension. <!-- begin-user-doc --> <!-- * end-user-doc --> */ protected void createContextMenuFor ( final StructuredViewer viewer ) { final MenuManager contextMenu = new MenuManager ( "#PopUp" ); contextMenu.add ( new Separator ( "additions" ) ); contextMenu.setRemoveAllWhenShown ( true ); contextMenu.addMenuListener ( this ); final Menu menu = contextMenu.createContextMenu ( viewer.getControl () ); viewer.getControl ().setMenu ( menu ); getSite ().registerContextMenu ( contextMenu, new UnwrappingSelectionProvider ( viewer ) ); final int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; final Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance () }; viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) ); viewer.addDropSupport ( dndOperations, transfers, new EditingDomainViewerDropAdapter ( this.editingDomain, viewer ) ); }
/** * This creates a context menu for the viewer and adds a listener as well registering the menu for extension. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void createContextMenuFor ( StructuredViewer viewer ) { MenuManager contextMenu = new MenuManager ( "#PopUp" ); contextMenu.add ( new Separator ( "additions" ) ); contextMenu.setRemoveAllWhenShown ( true ); contextMenu.addMenuListener ( this ); Menu menu = contextMenu.createContextMenu ( viewer.getControl () ); viewer.getControl ().setMenu ( menu ); getSite ().registerContextMenu ( contextMenu, new UnwrappingSelectionProvider ( viewer ) ); int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance (), LocalSelectionTransfer.getTransfer (), FileTransfer.getInstance () }; viewer.addDragSupport ( dndOperations, transfers, new ViewerDragAdapter ( viewer ) ); viewer.addDropSupport ( dndOperations, transfers, new EditingDomainViewerDropAdapter ( editingDomain, viewer ) ); }
private void createXhtmlTree() { sourcePicker.createXhtmlTree(treesSashForm); // DND support int ops = DND.DROP_COPY | DND.DROP_MOVE; Transfer[] transfers = new Transfer[] {StepSourceTransfer.getInstance()}; DragSource source = new DragSource(sourcePicker.getTwsDomTree().getTree(), ops); source.setTransfer(transfers); source.addDragListener(new DragSourceAdapter() { @Override public void dragStart(DragSourceEvent event) { event.doit = true; StepSourceTransfer.getInstance().setStepSource(sourcePicker.getDragData()); } }); }
@Override public void javaToNative (Object object, TransferData transferData) { if (!checkCustom(object) || !isSupportedType(transferData)) { DND.error(DND.ERROR_INVALID_DATA); } byte [] bytes = null; if (object instanceof ByteBuffer) { bytes = ((ByteBuffer)object).array(); } else { if (object instanceof byte []) { bytes = (byte []) object; } } if (bytes == null) { DND.error(DND.ERROR_INVALID_DATA); } super.javaToNative(bytes, transferData); }
Set<TransferMode> getTransferModes(int bits) { Set<TransferMode> set = new HashSet<>(); if ((bits & DND.DROP_COPY) != 0) { set.add(TransferMode.COPY); } if ((bits & DND.DROP_MOVE) != 0) { set.add(TransferMode.MOVE); } if ((bits & DND.DROP_TARGET_MOVE) != 0) { set.add(TransferMode.MOVE); } if ((bits & DND.DROP_LINK) != 0) { set.add(TransferMode.LINK); } return set; }
public void applyDragFromTableViewer(Control sourceControl, int index) { Transfer[] types = new Transfer[] { TextTransfer.getInstance() }; final String portLabel = "in" + index + "."; int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK; final Table table = (Table) sourceControl; DragSource source = new DragSource(table, operations); source.setTransfer(types); final String[] columnData = new String[1]; source.addDragListener(new DragSourceAdapter() { public void dragSetData(DragSourceEvent event) { // Set the data to be the first selected item's text event.data = addDelimeter(portLabel, table.getSelection()); } }); }
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 int dragOver(AvroNode draggedNode, AvroNode targetNode, TargetPosition position) { int detail = DND.DROP_NONE; AvroSchemaController schemaController = context.getService(AvroSchemaController.class); if (schemaController.canDnDElement(DragAndDropPolicy.Action.MOVE, draggedNode, targetNode, position)) { detail = DND.DROP_MOVE; } else if (schemaController.canDnDElement(DragAndDropPolicy.Action.COPY, draggedNode, targetNode, position)) { detail = DND.DROP_COPY; } else if (schemaController.canDnDElement(DragAndDropPolicy.Action.REFERENCE, draggedNode, targetNode, position)) { detail = DND.DROP_MOVE; } return detail; }
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); }
/** * This creates a context menu for the viewer and adds a listener as well registering the menu for extension. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected void createContextMenuFor(StructuredViewer viewer) { MenuManager contextMenu = new MenuManager("#PopUp"); contextMenu.add(new Separator("additions")); contextMenu.setRemoveAllWhenShown(true); contextMenu.addMenuListener(this); Menu menu = contextMenu.createContextMenu(viewer.getControl()); viewer.getControl().setMenu(menu); getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer)); int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; Transfer[] transfers = new Transfer[] {LocalTransfer.getInstance(), LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance()}; viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer)); viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(editingDomain, viewer)); }
/** * Adds a new note to the notepad. */ public void addNewNote() { String noteText = ""; if (preferences.getBoolean(PreferenceConstants.PREF_PASTE_CLIPBOARD_IN_NEW_NOTES, PreferenceConstants.PREF_PASTE_CLIPBOARD_IN_NEW_NOTES_DEFAULT)) { noteText = (String) clipboard.getContents(TextTransfer.getInstance(), DND.CLIPBOARD); } String noteTitle = preferences.get(PreferenceConstants.PREF_NAME_PREFIX, PreferenceConstants.PREF_NAME_PREFIX_DEFAULT) + " " + (tabFolder.getItemCount() + 1); // Add a new note tab with a number appended to its name (Note 1, Note 2, Note 3, etc.). addNewNoteTab(noteTitle, noteText, null, true, null); CTabItem previousSelectedTab = tabFolder.getSelection(); // Remove lock for currently selected tab. if (previousSelectedTab != null && previousSelectedTab.getText().startsWith(LOCK_PREFIX)) { previousSelectedTab.setText(previousSelectedTab.getText().substring(LOCK_PREFIX.length())); } tabFolder.setSelection(tabFolder.getItemCount() - 1); }
/** * Finish the drag by removing the source text if the operation * was MOVE. * * Trigger updating of TexlipseModel and outline when done. * * @param event the dragEvent * @see org.eclipse.swt.dnd.DragSourceListener#dragFinished(org.eclipse.swt.dnd.DragSourceEvent) */ public void dragFinished(DragSourceEvent event) { // remove MOVE source if (event.detail == DND.DROP_MOVE) { int sourceLength = this.dragSource.getPosition().getLength(); try { getDocument().replace(removeOffset, sourceLength, ""); } catch (BadLocationException e) { TexlipsePlugin.log("Could not remove drag'n'drop source.", e); } } // trigger parsing this.outline.getEditor().updateModelNow(); }
void initDragAndDrop() { int operations = DND.DROP_MOVE; Transfer[] transferTypes = new Transfer[]{ LocalSelectionTransfer.getTransfer() }; treeViewer.addDragSupport(operations, transferTypes, new DragSourceAdapter() { @Override public void dragStart(DragSourceEvent event) { LocalSelectionTransfer.getTransfer().setSelection(treeViewer.getSelection()); // not really needed since we can get selection from member variable } // @Override public void dragSetData(DragSourceEvent event) { // } // @Override public void dragFinished(DragSourceEvent event) { // } }); treeViewer.addDropSupport(operations, transferTypes, new StructureTreeDropAdapter(treeViewer)); }
/** * 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; }
@Override public boolean validateDrop(Object target, int operation, TransferData type) { overrideOperation(DND.DROP_COPY); // if (application == null) // return false; if (operation == DND.DROP_COPY || operation == DND.DROP_DEFAULT) { if (LocalSelectionTransfer.getTransfer().isSupportedType(type)) { IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer() .getSelection(); Object[] objects = selection.toArray(); for (Object obj : objects) { if (obj instanceof CFServiceInstance) { return true; } } } } return false; }
/** * @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; }
@Override protected void handleDrop() { factory.handle = (ModelHandle) getCurrentEvent().data; factory.targetTreeNode = (PaletteTreeNodeEditPart) getCurrentEvent().item.getData(); // We need to override the default logic to find the target edit part for the drop, // as this is failing with our hybrid GEF/JFace Tree implementation. // So, no call to super.handleDrop() here, but a slightly modified reimplementation. // We need the direct setTargetEditPart as the default logic is failing. updateTargetRequest(); setTargetEditPart(factory.targetTreeNode); if (getTargetEditPart() != null) { Command command = getCommand(); if (command != null && command.canExecute()) getViewer().getEditDomain().getCommandStack().execute(command); else getCurrentEvent().detail = DND.DROP_NONE; } else getCurrentEvent().detail = DND.DROP_NONE; }
/** * This creates a context menu for the viewer and adds a listener as well registering the menu for extension. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void createContextMenuFor(StructuredViewer viewer) { MenuManager contextMenu = new MenuManager("#PopUp"); contextMenu.add(new Separator("additions")); contextMenu.setRemoveAllWhenShown(true); contextMenu.addMenuListener(this); Menu menu= contextMenu.createContextMenu(viewer.getControl()); viewer.getControl().setMenu(menu); getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer)); int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance(), LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance() }; viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer)); viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(editingDomain, viewer)); }
@Override public boolean validateDrop(Object target, int operation, TransferData type) { overrideOperation(DND.DROP_COPY); // if (application == null) // return false; if (operation == DND.DROP_COPY || operation == DND.DROP_DEFAULT) { if (LocalSelectionTransfer.getTransfer().isSupportedType(type)) { IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer() .getSelection(); Object[] objects = selection.toArray(); for (Object obj : objects) { if (obj instanceof CloudService) { return true; } } } } return false; }
/** * This creates a context menu for the viewer and adds a listener as well * registering the menu for extension. <!-- begin-user-doc --> <!-- * end-user-doc --> * * @generated */ protected void createContextMenuFor(StructuredViewer viewer) { MenuManager contextMenu = new MenuManager("#PopUp"); contextMenu.add(new Separator("additions")); contextMenu.setRemoveAllWhenShown(true); contextMenu.addMenuListener(this); Menu menu = contextMenu.createContextMenu(viewer.getControl()); viewer.getControl().setMenu(menu); getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer)); int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance(), LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance() }; viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer)); viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(editingDomain, viewer)); }
@Override public void paste() { if ((getStyle() & SWT.SINGLE) != 0) { checkWidget(); String text = (String) getMyClipboardContent(DND.CLIPBOARD); if (text.contains("\n") || text.contains("\r")) { if (text != null && text.length() > 0) { text = StringUtils.replace(text, "\n", " "); text = StringUtils.replace(text, "\r", " "); text = StringUtils.replace(text, "\t", " "); // Replace multiple spaces with a single space. RaptorStringTokenizer tok = new RaptorStringTokenizer(text, " ", true); StringBuilder result = new StringBuilder(text.length()); while (tok.hasMoreTokens()) { result.append(tok.nextToken()).append(" "); } replaceTextRange(getSelection().x, 0, result.toString()); } } else { super.paste(); } } }
/** * This creates a context menu for the viewer and adds a listener as well registering the menu for extension. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void createContextMenuFor(StructuredViewer viewer) { MenuManager contextMenu = new MenuManager("#PopUp"); contextMenu.add(new Separator("additions")); contextMenu.setRemoveAllWhenShown(true); contextMenu.addMenuListener(this); Menu menu = contextMenu.createContextMenu(viewer.getControl()); viewer.getControl().setMenu(menu); getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer)); int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance() }; viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter( viewer)); viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(editingDomain, viewer)); }