protected static void setItemUriData ( final DragSourceEvent event, final Collection<Item> items ) { final StringBuilder sb = new StringBuilder (); int cnt = 0; for ( final Item item : items ) { if ( cnt > 0 ) { sb.append ( "\n" ); //$NON-NLS-1$ } sb.append ( item.getConnectionString () ); sb.append ( "#" ); //$NON-NLS-1$ sb.append ( item.getId () ); cnt++; } event.data = sb.toString (); }
@Override public void dragSetData ( final DragSourceEvent event ) { try { if ( ItemTransfer.getInstance ().isSupportedType ( event.dataType ) ) { final IStructuredSelection selection = (IStructuredSelection)LocalSelectionTransfer.getTransfer ().getSelection (); final Collection<Item> items = ItemSelectionHelper.getSelection ( selection ); event.data = items.toArray ( new Item[items.size ()] ); event.doit = true; } } catch ( final Exception e ) { logger.warn ( "Failed to set drag data", e ); event.doit = false; } }
@Override public void dragStart ( final DragSourceEvent event ) { event.doit = false; if ( ! ( this.viewer.getSelection () instanceof IStructuredSelection ) ) { return; } final Collection<Item> items = ItemSelectionHelper.getSelection ( this.viewer.getSelection () ); if ( !items.isEmpty () ) { LocalSelectionTransfer.getTransfer ().setSelection ( this.viewer.getSelection () ); event.doit = true; } }
protected void setItemStringData ( final DragSourceEvent event, final IStructuredSelection selection ) { final StringBuilder sb = new StringBuilder (); int cnt = 0; for ( final Iterator<?> i = selection.iterator (); i.hasNext (); ) { final ListEntry entry = (ListEntry)i.next (); if ( cnt > 0 ) { sb.append ( "\n" ); //$NON-NLS-1$ } sb.append ( entry.getDataItem ().getItem ().getId () ); cnt++; } event.data = sb.toString (); }
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 dragSetData(DragSourceEvent event) { ProjectExplorerView explorerView = ConvertigoPlugin.getDefault().getProjectExplorerView(); if (explorerView != null) { try { String sXml = ClipboardAction.dnd.copy(explorerView); if (sXml != null) { event.data = sXml; } } catch (EngineException e) { ConvertigoPlugin.logException(e, "Cannot drag"); } catch (ParserConfigurationException ee) { ConvertigoPlugin.logException(ee, "Cannot drag"); } } }
private void addDragSupport(final List sourcePackageList, final Combo comboJarList) { DragSource dragSource = ExpressionEditorUtil.INSTANCE.getDragSource(sourcePackageList); dragSource.addDragListener(new DragSourceAdapter() { public void dragSetData(DragSourceEvent event) { event.data = formatDataToTransfer(sourcePackageList.getSelection()); } private Object formatDataToTransfer(String[] selection) { StringBuffer buffer = new StringBuffer(); for (String field : selection) { buffer.append(field + Constants.DOT + Constants.ASTERISK + SWT.SPACE + Constants.DASH + SWT.SPACE + comboJarList.getItem(comboJarList.getSelectionIndex()) + Constants.FIELD_SEPRATOR_FOR_DRAG_DROP); } return buffer.toString(); } }); }
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()); } }); }
public void dragSetData(final DragSourceEvent event) { final IStructuredSelection selection = (IStructuredSelection) viewer .getSelection(); if (selection.getFirstElement() instanceof PwsEntryBean) { final PwsEntryBean firstElement = (PwsEntryBean) selection.getFirstElement(); if (PwsEntryBeanTransfer.getInstance().isSupportedType(event.dataType)) { event.data = firstElement.getStoreIndex(); } } else if (selection.getFirstElement() instanceof PasswordTreeContentProvider.TreeGroup) { event.doit = false; // disable for now final PasswordTreeContentProvider.TreeGroup group = (PasswordTreeContentProvider.TreeGroup) selection.getFirstElement(); if (PwsEntryBeanTransfer.getInstance().isSupportedType(event.dataType)) { event.data = group.getGroupPath(); } if (TextTransfer.getInstance().isSupportedType(event.dataType)) { event.data = group.getGroupPath(); } } else { log.warn("Unknown type: " + selection.getFirstElement().getClass()); } }
/** * Validate the drag start. Dragging is denied if: * * - outline is not uptodate * - source is preamble * * @param event the drag event * @see org.eclipse.swt.dnd.DragSourceListener#dragStart(org.eclipse.swt.dnd.DragSourceEvent) */ public void dragStart(DragSourceEvent event) { event.doit = false; // deny if outline is dirty if (this.outline.isModelDirty()) { return; } // get the selected node OutlineNode node = this.getSelection(); if (node == null) { return; } // deny dragging of certain elements if (node.getType() == OutlineNode.TYPE_PREAMBLE) { return; } // proceed this.dragSource = node; event.doit = true; }
/** * Set the text data into TextTransfer. * * @see org.eclipse.swt.dnd.DragSourceListener#dragSetData(org.eclipse.swt.dnd.DragSourceEvent) */ public void dragSetData(DragSourceEvent event) { // check that requested data type is supported if (!TextTransfer.getInstance().isSupportedType(event.dataType)) { return; } // get the source text int sourceOffset = this.dragSource.getPosition().getOffset(); int sourceLength = this.dragSource.getPosition().getLength(); Position sourcePosition = dragSource.getPosition(); String sourceText = ""; try { sourceText = getDocument().get(sourcePosition.getOffset(), sourcePosition.getLength()); } catch (BadLocationException e) { TexlipsePlugin.log("Could not set drag data.", e); return; } // set the data event.data = sourceText; }
/** * 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(); }
private Object getTargetModel(final DragSourceEvent event) { final List editParts = dragSourceViewer.getSelectedEditParts(); if (editParts.size() != 1) { // ドラッグアンドドロップは選択されているオブジェクトが1つのときのみ可能とする return null; } final EditPart editPart = (EditPart) editParts.get(0); final Object model = editPart.getModel(); if (model instanceof NormalColumn || model instanceof ColumnGroup || model instanceof Word) { return model; } return null; }
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)); }
@Override public void dragStart(DragSourceEvent dragsourceevent) { super.dragStart(dragsourceevent); Object target = this.getTargetModel(dragsourceevent); if (target != null && target == this.dragSourceViewer.findObjectAt( new Point(dragsourceevent.x, dragsourceevent.y)) .getModel()) { TemplateTransfer transfer = (TemplateTransfer) this.getTransfer(); transfer.setObject(this.createTransferData(dragsourceevent)); } else { dragsourceevent.doit = false; } }
private Object getTargetModel(DragSourceEvent event) { List editParts = dragSourceViewer.getSelectedEditParts(); if (editParts.size() != 1) { // ドラッグアンドドロップは選択されているオブジェクトが1つのときのみ可能とする return null; } EditPart editPart = (EditPart) editParts.get(0); Object model = editPart.getModel(); if (model instanceof NormalColumn || model instanceof ColumnGroup || model instanceof Word) { return model; } return null; }
/** * Read the selected report unit and generate the data for the event, * serializing an array of string with some of the unit informations. The * serializing is done using the UnitTransfer class */ @Override public void dragSetData(DragSourceEvent event) { IStructuredSelection selection = (IStructuredSelection) viewer .getSelection(); List<String> unitInfo = new ArrayList<String>(); if (selection.getFirstElement() instanceof MReportUnit) { MReportUnit unit = (MReportUnit) selection.getFirstElement(); ResourceDescriptor unitDescrtiptor = unit.getValue(); unitInfo.add(unitDescrtiptor.getUriString()); List<INode> childrens = unit.getChildren(); for (INode children : childrens) { if (children instanceof MInputControl) { ResourceDescriptor desc = (ResourceDescriptor) children .getValue(); unitInfo.add(desc.getName()); } } } String[] gadgets = unitInfo.toArray(new String[unitInfo.size()]); if (UnitTransfer.getInstance().isSupportedType(event.dataType)) { event.data = gadgets; } }
/** * Method declared on DragSourceListener */ public void dragFinished(DragSourceEvent event) { if (!event.doit) return; // if the gadget was moved, remove it from the source viewer if (event.detail == DND.DROP_MOVE) { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); for (Iterator<?> it = selection.iterator(); it.hasNext();) { Object obj = it.next(); if (obj instanceof ANode) { ANode n = (ANode) obj; if (n.isCut()) ((ANode) obj).setParent(null, -1); } } viewer.refresh(); } }
@Override public void dragSetData(DragSourceEvent event) { if(getTransfer().isSupportedType(event.dataType)){ List<MDataAdapter> dataAdaptersSelected = getDragSelection(event); List<String> locations = new ArrayList<String>(dataAdaptersSelected.size()); for(MDataAdapter da : dataAdaptersSelected){ locations.add(createTemDataAdapterFile(da)); } dataAdapterFilesLocations = locations.toArray(new String[locations.size()]); event.data = dataAdapterFilesLocations; } else { dataAdapterFilesLocations = new String[0]; event.data = null; } }
private List<MDataAdapter> getDragSelection(DragSourceEvent event){ if(event.getSource() instanceof DragSource){ List<MDataAdapter> dataAdapters = new ArrayList<MDataAdapter>(); Control control = ((DragSource)event.getSource()).getControl(); if(control instanceof Tree && ((Tree) control).getSelection().length>0){ for(TreeItem tItem : ((Tree) control).getSelection()){ Object data = tItem.getData(); if(data instanceof MDataAdapter){ dataAdapters.add((MDataAdapter) data); } } return dataAdapters; } } return new ArrayList<MDataAdapter>(0); }
@Override public void dragSetData(DragSourceEvent event) { System.out.println("dragSetData"); IStructuredSelection selection = (IStructuredSelection) viewer .getSelection(); if (selection.getFirstElement() instanceof OntologyTreeNode) { OntologyTreeNode firstElement = (OntologyTreeNode) selection .getFirstElement(); if (firstElement.isModifier()){ event.data = null; System.out.println("Modifier!"); } else if (TextTransfer.getInstance().isSupportedType(event.dataType)) { event.data = firstElement.getTreePath(); } } else if (selection.getFirstElement() instanceof OntologyTreeSubNode) { setSubNode((OntologyTreeSubNode) selection .getFirstElement()); event.data = "subNode"; } }
@Override public void dragStart(DragSourceEvent event) { IStructuredSelection selection = (IStructuredSelection) viewer .getSelection(); if (selection.getFirstElement() instanceof OntologyTreeNode) { OntologyTreeNode firstElement = (OntologyTreeNode) selection .getFirstElement(); if (firstElement.isModifier()){ System.out.println("MODIFIERS"); event.doit=false; } else { Console.info("Start Drag"); event.doit = true; } } }
private void addDragAdapters(StructuredViewer viewer) { int ops= DND.DROP_COPY | DND.DROP_LINK; Transfer[] transfers= new Transfer[] { LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance(), FileTransfer.getInstance()}; DelegatingDragAdapter dragAdapter= new DelegatingDragAdapter() { @Override public void dragStart(DragSourceEvent event) { IStructuredSelection selection= (IStructuredSelection) fSelectionProviderMediator.getSelection(); if (selection.isEmpty()) { event.doit= false; return; } super.dragStart(event); } }; dragAdapter.addDragSourceListener(new SelectionTransferDragAdapter(fSelectionProviderMediator)); dragAdapter.addDragSourceListener(new EditorInputTransferDragAdapter(fSelectionProviderMediator)); dragAdapter.addDragSourceListener(new ResourceTransferDragAdapter(fSelectionProviderMediator)); dragAdapter.addDragSourceListener(new FileTransferDragAdapter(fSelectionProviderMediator)); viewer.addDragSupport(ops, transfers, dragAdapter); }
public void dragStart( DragSourceEvent event ) { TreeItem[] selection = viewer.getTree( ).getSelection( ); if ( selection.length > 0 ) { if ( viewer == dataFieldsViewer ) { dragSourceItems[0] = selection[0]; } else if ( viewer == groupViewer && selection[0].getData( ) != null && selection[0].getData( ) instanceof LevelHandle ) { dragSourceItems[0] = selection[0]; } else event.doit = false; } else { event.doit = false; } }
/** * The drop has successfully completed. This event is forwarded to the current * drag listener. * Doesn't update the current listener, since the current listener is already the one * that completed the drag operation. * * @param event the drag source event * @see DragSourceListener#dragFinished(DragSourceEvent) */ public void dragFinished(final DragSourceEvent event) { // if (Policy.DEBUG_DRAG_DROP) // System.out.println("Drag Finished: " + toString()); //$NON-NLS-1$ SafeRunnable.run(new SafeRunnable() { public void run() throws Exception { if (currentListener != null) { // there is a listener that can handle the drop, delegate the event currentListener.dragFinished(event); } else { // The drag was canceled and currentListener was never set, so send the // dragFinished event to all the active listeners. Iterator iterator = activeListeners.iterator(); while (iterator.hasNext()) { ((TransferDragSourceListener) iterator.next()) .dragFinished(event); } } } }); currentListener = null; activeListeners.clear(); }
/** * Updates the current listener to one that can handle the drag. There can * be many listeners and each listener may be able to handle many <code>TransferData</code> * types. The first listener found that supports one of the <code>TransferData</ode> * types specified in the <code>DragSourceEvent</code> will be selected. * * @param event the drag source event */ private void updateCurrentListener(DragSourceEvent event) { currentListener = null; if (event.dataType == null) { return; } Iterator iterator = activeListeners.iterator(); while (iterator.hasNext()) { TransferDragSourceListener listener = (TransferDragSourceListener) iterator .next(); if (listener.getTransfer().isSupportedType(event.dataType)) { // if (Policy.DEBUG_DRAG_DROP) // System.out.println("Current drag listener: " + listener); //$NON-NLS-1$ currentListener = listener; return; } } }
@Override public void dragFinished(DragSourceEvent event) { viewer.setData(VIEWER_IS_DRAG_SOURCE_PROPERTY, null); boolean isDropTarget = isThisViewerDropTarget(); if (!event.doit || event.detail == DND.DROP_NONE) { return; } if (event.detail == DND.DROP_MOVE && !isDropTarget) { // remove the drag source from the model List<?> targetChildren = extensionDragSource.getParent().getModelWrapper().getChildren(); List<?> sourceChildren = extensionDragSourceParent.getModelWrapper().getChildren(); // delete extension from source children extensionDragSource.getModelWrapper().setXMLModelContainingList(sourceChildren); extensionDragSourceParent.removeItem(extensionDragSource, false); // set target children as new containing list extensionDragSource.getModelWrapper().setXMLModelContainingList(targetChildren); if (editor != null) { editor.markDirty(); } } }
private void handleFinishedDropMove(DragSourceEvent event) { MultiStatus status= new MultiStatus( JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.ResourceTransferDragAdapter_cannot_delete_resource, null); List<IResource> resources= convertSelection(); for (Iterator<IResource> iter= resources.iterator(); iter.hasNext();) { IResource resource= iter.next(); try { resource.delete(true, null); } catch (CoreException e) { status.add(e.getStatus()); } } int childrenCount= status.getChildren().length; if (childrenCount > 0) { Shell parent= SWTUtil.getShell(event.widget); ErrorDialog error= new ErrorDialog(parent, JavaUIMessages.ResourceTransferDragAdapter_moving_resource, childrenCount == 1 ? JavaUIMessages.ResourceTransferDragAdapter_cannot_delete_files_singular : Messages.format( JavaUIMessages.ResourceTransferDragAdapter_cannot_delete_files_plural, String.valueOf(childrenCount)), status, IStatus.ERROR); error.open(); } }
public void dragStart( DragSourceEvent event ) { if ( ChartReportItemHelper.instance( ) .getBindingCubeHandle( itemHandle ) != null ) { event.doit = false; } else { int index = table.getSelectionIndex( ); if ( index < 0 ) { item = null; event.doit = false; } else { item = table.getItem( index ); String strColumnName = ( (ColumnBindingInfo) item.getData( ) ).getName( ); event.doit = ( strColumnName != null && strColumnName.length( ) > 0 ); } } }
@Override public boolean setDragData ( final DragSourceEvent event, final IStructuredSelection selection ) { logger.debug ( "setDragData ( event: {}, selection: {}", event, selection ); final Collection<Item> items = ItemSelectionHelper.getSelection ( selection ); if ( items.isEmpty () ) { logger.info ( "Empty item set for setDragData" ); return false; } if ( ItemTransfer.getInstance ().isSupportedType ( event.dataType ) ) { event.data = items.toArray ( new Item[items.size ()] ); return true; } else if ( TextTransfer.getInstance ().isSupportedType ( event.dataType ) ) { event.data = getItemUriData ( items ); return true; } else if ( URLTransfer.getInstance ().isSupportedType ( event.dataType ) ) { event.data = getItemUriData ( items ); return true; } logger.debug ( "No possible transfer" ); return false; }
@Override public void dragSetData ( final DragSourceEvent event ) { try { final IStructuredSelection selection = (IStructuredSelection)LocalSelectionTransfer.getTransfer ().getSelection (); if ( ItemTransfer.getInstance ().isSupportedType ( event.dataType ) ) { final List<Item> items = new ArrayList<Item> (); for ( final Iterator<?> i = selection.iterator (); i.hasNext (); ) { final ListEntry entry = (ListEntry)i.next (); items.add ( entry.getItem () ); } event.data = items.toArray ( new Item[items.size ()] ); } else if ( TextTransfer.getInstance ().isSupportedType ( event.dataType ) ) { setItemUriData ( event, selection ); } else if ( URLTransfer.getInstance ().isSupportedType ( event.dataType ) ) { setItemUriData ( event, selection ); } } catch ( final Exception e ) { event.doit = false; } }
protected void setItemUriData ( final DragSourceEvent event, final IStructuredSelection selection ) { final StringBuilder sb = new StringBuilder (); int cnt = 0; for ( final Iterator<?> i = selection.iterator (); i.hasNext (); ) { final ListEntry entry = (ListEntry)i.next (); if ( cnt > 0 ) { sb.append ( "\n" ); //$NON-NLS-1$ } final Item item = entry.getItem (); if ( item.getType () != Type.URI ) { throw new IllegalStateException ( Messages.RealtimeListDragSourceListener_TypeError ); } sb.append ( item.getConnectionString () ); sb.append ( "#" ); //$NON-NLS-1$ try { sb.append ( URLEncoder.encode ( item.getId (), "UTF-8" ) ); } catch ( final UnsupportedEncodingException e ) { sb.append ( item.getId () ); } cnt++; } event.data = sb.toString (); }
@Override public void dragStart ( final DragSourceEvent event ) { event.doit = false; if ( ! ( this.viewer.getSelection () instanceof IStructuredSelection ) ) { return; } final IStructuredSelection selection = (IStructuredSelection)this.viewer.getSelection (); if ( selection.isEmpty () ) { return; } for ( final Iterator<?> i = selection.iterator (); i.hasNext (); ) { final Object o = i.next (); if ( ! ( o instanceof ListEntry ) ) { return; } } LocalSelectionTransfer.getTransfer ().setSelection ( this.viewer.getSelection () ); event.doit = true; }
private void addDragSupport() { ExpressionEditorUtil.INSTANCE.getDragSource(methodList).addDragListener(new DragSourceAdapter() { public void dragSetData(DragSourceEvent event) { if (methodList.getItemCount() != 0 && !StringUtils.startsWith(methodList.getItem(0),Messages.CANNOT_SEARCH_INPUT_STRING)) { MethodDetails methodDetails = (MethodDetails) methodList.getData(String.valueOf(methodList .getSelectionIndex())); event.data = methodDetails.getPlaceHolder(); }else event.data=StringUtils.EMPTY+"#"+StringUtils.EMPTY; } }); }