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 File: TexOutlineDNDAdapter.java    From texlipse with 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 #2
Source File: ItemDragSourceListener.java    From neoscada with 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 File: ERDiagramTransferDragSourceListener.java    From ermasterr with 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 #4
Source File: ItemDragSourceListener.java    From neoscada with 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 #5
Source File: DragHelper.java    From neoscada with 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 #6
Source File: TexOutlineDNDAdapter.java    From texlipse with 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 #7
Source File: RealtimeListDragSourceListener.java    From neoscada with 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 #8
Source File: ResourceTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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 #9
Source File: CubeGroupContent.java    From birt with 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 #10
Source File: ColumnNamesTableDragListener.java    From birt with 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 #11
Source File: TexOutlineDNDAdapter.java    From texlipse with 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 #12
Source File: CallHierarchyViewPart.java    From Eclipse-Postfix-Code-Completion with 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 #13
Source File: ItemDragSourceListener.java    From neoscada with 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 #14
Source File: ItemDragSourceListener.java    From neoscada with 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 #15
Source File: JdtViewerDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void dragStart(DragSourceEvent event) {
	IStructuredSelection selection= (IStructuredSelection)fViewer.getSelection();
	if (selection.isEmpty()) {
		event.doit= false;
		return;
	}
	super.dragStart(event);
}
 
Example #16
Source File: View.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
private void addDragListener(Control control) {
	LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();

	DragSourceAdapter dragAdapter = new DragSourceAdapter() {
		@Override
		public void dragSetData(DragSourceEvent event) {
			transfer.setSelection(new StructuredSelection(control));
		}
	};

	DragSource dragSource = new DragSource(control, DND.DROP_MOVE | DND.DROP_COPY);
	dragSource.setTransfer(new Transfer[] { transfer });
	dragSource.addDragListener(dragAdapter);
}
 
Example #17
Source File: ERDiagramTransferDragSourceListener.java    From ermasterr with 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 #18
Source File: LibraryDragListener.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void dragStart( DragSourceEvent event )
{
	boolean doit = !getViewer( ).getSelection( ).isEmpty( );
	if ( doit )
	{
		IStructuredSelection selection = (IStructuredSelection) getViewer( ).getSelection( );
		List objectList = selection.toList( );
		selectionList.clear( );
		for ( int i = 0; i < objectList.size( ); i++ )
		{
			if ( objectList.get( i ) instanceof ReportResourceEntry )
				selectionList.add( ( (ReportResourceEntry) objectList.get( i ) ).getReportElement( ) );
			else
				selectionList.add( objectList.get( i ) );
		}
		Object[] objects = selectionList.toArray( );
		if ( validateType( objects ) )
		{
			for ( int i = 0; i < objects.length; i++ )
				if ( !validateTransfer( objects[i] ) )
				{
					doit = false;
					break;
				}
		}
		else
			doit = false;
		if ( doit )
			TemplateTransfer.getInstance( ).setTemplate( objects );
	}
	event.doit = doit;
	if ( Policy.TRACING_DND_DRAG && doit )
	{
		System.out.println( "DND >> Drag starts." ); //$NON-NLS-1$
	}
}
 
Example #19
Source File: PhotoShuffler.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * The method computes the position / index of the source control
 * (label) in the children array of the parent composite. This index is
 * passed to the drop target using the data field of the drag source
 * event.
 */
public void dragSetData(DragSourceEvent event) {
	for (int i = 0; i < parentComposite.getChildren().length; i++) {
		if (parentComposite.getChildren()[i].equals(source.getControl())) {
			event.data = new Integer(i).toString();
			break;
		}
	}
}
 
Example #20
Source File: ParameterDragListener.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see DragSourceAdapter#dragSetData(DragSourceEvent)
 */
public void dragSetData( DragSourceEvent event )
{
	IStructuredSelection selection = (IStructuredSelection) getViewer( )
			.getSelection( );
	Object[] objects = selection.toList( ).toArray( );

	if ( TemplateTransfer.getInstance( ).isSupportedType( event.dataType ) )
	{
		event.data = objects;
	}
}
 
Example #21
Source File: FilterDragSourceAdapter.java    From tracecompass with 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 #22
Source File: GalleryDragSourceEffect.java    From nebula with 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 #23
Source File: RepositoriesView.java    From APICloud-Studio with 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 #24
Source File: ERDiagramTransferDragSourceListener.java    From erflute with 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 #25
Source File: EditorInputTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void dragStart(DragSourceEvent event) {
	fEditorInputDatas= new ArrayList<EditorInputData>();

	ISelection selection= fProvider.getSelection();
	if (selection instanceof IStructuredSelection) {
		IStructuredSelection structuredSelection= (IStructuredSelection) selection;
		for (Iterator<?> iter= structuredSelection.iterator(); iter.hasNext();) {
			Object element= iter.next();
			IEditorInput editorInput= EditorUtility.getEditorInput(element);
			if (editorInput != null && editorInput.getPersistable() != null) {
				try {
					String editorId= EditorUtility.getEditorID(editorInput);
					// see org.eclipse.ui.internal.ide.EditorAreaDropAdapter.openNonExternalEditor(..):
					IEditorRegistry editorReg= PlatformUI.getWorkbench().getEditorRegistry();
					IEditorDescriptor editorDesc= editorReg.findEditor(editorId);
					if (editorDesc != null && !editorDesc.isOpenExternal()) {
						fEditorInputDatas.add(EditorInputTransfer.createEditorInputData(editorId, editorInput));
					}
				} catch (PartInitException e) {
					JavaPlugin.log(e);
				}
			}
		}
	}

	event.doit= fEditorInputDatas.size() > 0;
}
 
Example #26
Source File: FileTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with 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);
}
 
Example #27
Source File: FileTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void dragFinished(DragSourceEvent event) {
	if (!event.doit)
		return;

	if (event.detail == DND.DROP_MOVE) {
		// http://bugs.eclipse.org/bugs/show_bug.cgi?id=30543
		// handleDropMove(event);
	} else if (event.detail == DND.DROP_TARGET_MOVE) {
		handleRefresh();
	}
}
 
Example #28
Source File: BasicSelectionTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void dragStart(DragSourceEvent event) {
	ISelection selection= fProvider.getSelection();
	LocalSelectionTransfer.getInstance().setSelection(selection);
	LocalSelectionTransfer.getInstance().setSelectionSetTime(event.time & 0xFFFFFFFFL);
	event.doit= isDragable(selection);
}
 
Example #29
Source File: BasicSelectionTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void dragSetData(DragSourceEvent event) {
	// For consistency set the data to the selection even though
	// the selection is provided by the LocalSelectionTransfer
	// to the drop target adapter.
	event.data= LocalSelectionTransfer.getInstance().getSelection();
}
 
Example #30
Source File: ResourceTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void dragFinished(DragSourceEvent event) {
	if (!event.doit)
		return;

	if (event.detail == DND.DROP_MOVE) {
		handleFinishedDropMove(event);
	}
}