org.eclipse.swt.dnd.DragSourceEvent Java Examples

The following examples show how to use org.eclipse.swt.dnd.DragSourceEvent. 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 Project: neoscada   Author: eclipse   File: DragHelper.java    License: Eclipse Public License 1.0 6 votes vote down vote up
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 ();
}
 
Example #2
Source Project: neoscada   Author: eclipse   File: ItemDragSourceListener.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@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;
    }

}
 
Example #3
Source Project: neoscada   Author: eclipse   File: ItemDragSourceListener.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@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;
    }

}
 
Example #4
Source Project: neoscada   Author: eclipse   File: RealtimeListDragSourceListener.java    License: Eclipse Public License 1.0 6 votes vote down vote up
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 ();
}
 
Example #5
Source Project: neoscada   Author: eclipse   File: ItemDragSourceListener.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@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;
    }

}
 
Example #6
Source Project: neoscada   Author: eclipse   File: ItemDragSourceListener.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@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;
    }

}
 
Example #7
Source Project: texlipse   Author: eclipse   File: TexOutlineDNDAdapter.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/** 
    * 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;
}
 
Example #8
Source Project: texlipse   Author: eclipse   File: TexOutlineDNDAdapter.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
    * 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;
}
 
Example #9
Source Project: texlipse   Author: eclipse   File: TexOutlineDNDAdapter.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
    * 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();
}
 
Example #10
Source Project: ermasterr   Author: roundrop   File: ERDiagramTransferDragSourceListener.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #11
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: CallHierarchyViewPart.java    License: Eclipse Public License 1.0 6 votes vote down vote up
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);
}
 
Example #12
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();
	}
}
 
Example #13
Source Project: birt   Author: eclipse   File: ColumnNamesTableDragListener.java    License: Eclipse Public License 1.0 6 votes vote down vote up
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 );
		}
	}

}
 
Example #14
Source Project: birt   Author: eclipse   File: CubeGroupContent.java    License: Eclipse Public License 1.0 6 votes vote down vote up
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;
	}

}
 
Example #15
Source Project: nebula   Author: eclipse   File: GalleryDragSourceEffect.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @seeorg.eclipse.swt.dnd.DragSourceAdapter#dragStart(org.eclipse.swt.dnd. DragSourceEvent)
 */
public void dragStart(DragSourceEvent event) {
	GalleryItem[] selection = g.getSelection();
	if (selection != null && selection.length > 0) {
		Image img = selection[0].getImage();
		if (img != null) {
			event.image = img;
		}
	}
}
 
Example #16
Source Project: nebula   Author: eclipse   File: XViewerCustomizeDialog.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.swt.dnd.DragSourceAdapter#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
 */
@Override
public void dragSetData(DragSourceEvent event) {
   if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
      List<XViewerColumn> selCols = getHiddenTableSelection();
      Collection<String> ids = new ArrayList<>(selCols.size());

      for (XViewerColumn xCol : selCols) {
         ids.add(xCol.getId());
      }

      event.data = CollectionsUtil.toString(ids, null, ", ", null); //$NON-NLS-1$
   }
}
 
Example #17
Source Project: nebula   Author: eclipse   File: XViewerCustomizeDialog.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.swt.dnd.DragSourceAdapter#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
 */
@Override
public void dragSetData(DragSourceEvent event) {
   if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
      List<XViewerColumn> selCols = getVisibleTableSelection();
      Collection<String> ids = new ArrayList<>(selCols.size());

      for (XViewerColumn xCol : selCols) {
         ids.add(xCol.getId());
      }

      event.data = CollectionsUtil.toString(ids, null, ", ", null); //$NON-NLS-1$
   }
}
 
Example #18
Source Project: nebula   Author: eclipse   File: XViewerCustDialogDragDrop.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.swt.dnd.DragSourceAdapter#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
 */
@Override
public void dragSetData(DragSourceEvent event) {
   if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
      List<XViewerColumn> selCols = xViewerCustomizeDialog.getHiddenTableSelection();
      Collection<String> ids = new ArrayList<>(selCols.size());

      for (XViewerColumn xCol : selCols) {
         ids.add(xCol.getId());
      }

      event.data = CollectionsUtil.toString(ids, null, ", ", null); //$NON-NLS-1$
   }
}
 
Example #19
Source Project: nebula   Author: eclipse   File: XViewerCustDialogDragDrop.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.swt.dnd.DragSourceAdapter#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
 */
@Override
public void dragSetData(DragSourceEvent event) {
   if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
      List<XViewerColumn> selCols = xViewerCustomizeDialog.getVisibleTableSelection();
      Collection<String> ids = new ArrayList<>(selCols.size());

      for (XViewerColumn xCol : selCols) {
         ids.add(xCol.getId());
      }

      event.data = CollectionsUtil.toString(ids, null, ", ", null); //$NON-NLS-1$
   }
}
 
Example #20
Source Project: ADT_Frontend   Author: abapGit   File: StagingDragListener.java    License: MIT License 5 votes vote down vote up
public void dragSetData(DragSourceEvent event) {
	IStructuredSelection selection = (IStructuredSelection) this.provider.getSelection();
	if (selection.isEmpty()) {
		return;
	}
	if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
		LocalSelectionTransfer.getTransfer().setSelection(new StagingDragSelection(selection, this.unstaged));
		return;
	}
}
 
Example #21
Source Project: neoscada   Author: eclipse   File: CommonDragAdapterAssistant.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example #22
Source Project: neoscada   Author: eclipse   File: RealtimeListDragSourceListener.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@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;
    }
}
 
Example #23
Source Project: neoscada   Author: eclipse   File: RealtimeListDragSourceListener.java    License: Eclipse Public License 1.0 5 votes vote down vote up
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 ();
}
 
Example #24
Source Project: neoscada   Author: eclipse   File: RealtimeListDragSourceListener.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example #25
Source Project: neoscada   Author: eclipse   File: CommonDragAdapterAssistant.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example #26
Source Project: ermasterr   Author: roundrop   File: ERDiagramTransferDragSourceListener.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void dragStart(final DragSourceEvent dragsourceevent) {
    super.dragStart(dragsourceevent);

    final Object target = getTargetModel(dragsourceevent);

    if (target != null && target == dragSourceViewer.findObjectAt(new Point(dragsourceevent.x, dragsourceevent.y)).getModel()) {
        final TemplateTransfer transfer = (TemplateTransfer) getTransfer();
        transfer.setObject(createTransferData(dragsourceevent));

    } else {
        dragsourceevent.doit = false;
    }
}
 
Example #27
Source Project: tracecompass   Author: tracecompass   File: FilterDragSourceAdapter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void dragFinished(DragSourceEvent event) {
    if (event.detail == DND.DROP_MOVE) {
        IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
        for (Object data : selection.toList()) {
            if (data instanceof ITmfFilterTreeNode) {
                ITmfFilterTreeNode e = (ITmfFilterTreeNode) data;
                e.remove();
                fViewer.refresh();
            }
        }
    }
    LocalSelectionTransfer.getTransfer().setSelection(null);
    LocalSelectionTransfer.getTransfer().setSelectionSetTime(0);
}
 
Example #28
Source Project: APICloud-Studio   Author: apicloudcom   File: RepositoriesView.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void dragStart(DragSourceEvent event) {
    if(selection!=null) {
        final Object[] array = selection.toArray();
        // event.doit = Utils.getResources(array).length > 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] instanceof ISVNRemoteResource) {
                event.doit = true;
                return;
            }
        }
        event.doit = false;
    }
}
 
Example #29
Source Project: erflute   Author: dbflute-session   File: ERDiagramTransferDragSourceListener.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void dragStart(DragSourceEvent dragsourceevent) {
    super.dragStart(dragsourceevent);

    final Object target = getTargetModel(dragsourceevent);
    if (target != null) {
        final TemplateTransfer transfer = (TemplateTransfer) getTransfer();
        transfer.setObject(target);
    } else {
        dragsourceevent.doit = false;
    }
}
 
Example #30
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: FileTransferDragAdapter.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void dragSetData(DragSourceEvent event){
	List<IResource> elements= getResources();
	if (elements == null || elements.size() == 0) {
		event.data= null;
		return;
	}

	event.data= getResourceLocations(elements);
}