org.eclipse.swt.dnd.DND Java Examples

The following examples show how to use org.eclipse.swt.dnd.DND. 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: PaletteToolTransferDropTargetListenerWithSelection.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Overridden to select the created object.
 *
 * @see org.eclipse.gef.dnd.AbstractTransferDropTargetListener#handleDrop()
 *      /!\ don't call super, this method is copied from AbstractTransferDropTargetListener,
 *      and added a method to select added object (method copied from CreationTool)
 *      Please note that intermediate class are also trying to
 */
@Override
protected void handleDrop() {
    final CreateRequest request = getCreateRequest();
    final Point loc = super.getDropLocation().getCopy();
    request.setLocation(loc);
    updateTargetEditPart();

    if (getTargetEditPart() != null) {
        final Command command = getCommand();
        if (command != null && command.canExecute()) {
            getViewer().getEditDomain().getCommandStack().execute(command);
            insertOnSequenceFlow(command, getTargetEditPart(), getViewer(), true);
            selectAddedObject(getViewer(), DiagramCommandStack.getReturnValues(command));
            getViewer().getEditDomain().loadDefaultTool();
        } else {
            getCurrentEvent().detail = DND.DROP_NONE;
        }
    } else {
        getCurrentEvent().detail = DND.DROP_NONE;
    }

}
 
Example #2
Source File: SinkView.java    From lapse-plus with GNU General Public License v3.0 6 votes vote down vote up
public void run() {
    StringBuffer buf = new StringBuffer();
    addCalls(viewer.getTable().getSelection(), buf);
    TextTransfer plainTextTransfer = TextTransfer.getInstance();
    try {
        fClipboard.setContents(new String[]{convertLineTerminators(buf.toString())},
            new Transfer[]{plainTextTransfer});
    } catch (SWTError e) {
        if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) throw e;
        if (MessageDialog
            .openQuestion(fView.getViewSite().getShell(),
                ("CopyCallHierarchyAction.problem"),
                ("CopyCallHierarchyAction.clipboard_busy"))) {
            run();
        }
    }
}
 
Example #3
Source File: ReportTemplateTransferDropTargetListener.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Validates drag source from palette, layout, or data view
 * 
 * @param dragObj
 * @return validate result
 */
private boolean handleValidateDrag( Object dragObj )
{
	if ( DNDService.getInstance( )
			.validDrop( TemplateTransfer.getInstance( ).getTemplate( ),
					getTargetEditPart( ),
					DND.DROP_DEFAULT,
					new DNDLocation( getDropLocation( ) ) ) )
	{
		return true;
	}
	return dragObj != null
			&& ( handleValidatePalette( dragObj )
					|| handleValidateOutline( dragObj )
					|| handleValidateInsert( dragObj ) || handleValidateLibrary( dragObj ) );
}
 
Example #4
Source File: LibraryTemplateTransferDropTargetListener.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void dragOver( DropTargetEvent event )
	{
		super.dragOver( event );
		if ( getTargetEditPart( ) == null )
		{
			event.detail = DND.DROP_NONE;
			return;
		}

//		if ( getTargetEditPart( ).getModel( ) instanceof LibraryHandle )
//		{
//			List list = getTargetEditPart( ).getChildren( );
//			if ( list.size( ) > 0 && !( list.get( 0 ) instanceof EmptyEditPart ) )
//			{
//				event.detail = DND.DROP_NONE;
//			}
//		}

	}
 
Example #5
Source File: CopyAction.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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(IResource[] resources, String[] fileNames, 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 (SWTError e) {
        if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
            throw e;
        }
        if (MessageDialog.openQuestion(shell, "Problem with copy title", // TODO ResourceNavigatorMessages.CopyToClipboardProblemDialog_title,  //$NON-NLS-1$
                "Problem with copy.")) { //$NON-NLS-1$
            setClipboard(resources, fileNames, names);
        }
    }
}
 
Example #6
Source File: SourceView.java    From lapse-plus with GNU General Public License v3.0 6 votes vote down vote up
public void run() {
       StringBuffer buf = new StringBuffer();
       addCalls(viewer.getTable().getSelection(), buf);

	TextTransfer plainTextTransfer = TextTransfer.getInstance();
	try{
		fClipboard.setContents(
			new String[]{ convertLineTerminators(buf.toString()) }, 
			new Transfer[]{ plainTextTransfer });
	}  catch (SWTError e){
		if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) 
			throw e;
		if (MessageDialog.openQuestion(fView.getViewSite().getShell(), 
				("CopyCallHierarchyAction.problem"), ("CopyCallHierarchyAction.clipboard_busy"))
		) 
		{
			run();
		}
	}
}
 
Example #7
Source File: ScriptConsoleViewer.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void dragFinished(DragSourceEvent event) {
    try {
        if (event.detail == DND.DROP_MOVE && selectionIsEditable) {
            Point newSelection = getSelection();
            int length = selection.y - selection.x;
            int delta = 0;
            if (newSelection.x < selection.x) {
                delta = length;
            }
            replaceTextRange(selection.x + delta, length, "");
        }
    } finally {
        thisConsoleInitiatedDrag = false;
    }
}
 
Example #8
Source File: MemoryEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 ) );
}
 
Example #9
Source File: InfrastructureEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 ) );
}
 
Example #10
Source File: SecurityEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 ) );
}
 
Example #11
Source File: ComponentEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 ) );
}
 
Example #12
Source File: ConfigurationEditor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 ) );
}
 
Example #13
Source File: GenconfEditor.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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));
}
 
Example #14
Source File: JavaDropAdapterAssistant.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private int handleValidateMove(Object target) throws JavaModelException {
	if (target == null)
		return DND.DROP_NONE;

	IMovePolicy policy= ReorgPolicyFactory.createMovePolicy(ReorgUtils.getResources(fElements), ReorgUtils.getJavaElements(fElements));
	fMoveProcessor= (policy.canEnable()) ? new JavaMoveProcessor(policy) : null;

	if (!canMoveElements())
		return DND.DROP_NONE;

	if (fMoveProcessor == null)
		return DND.DROP_NONE;

	if (!fMoveProcessor.setDestination(ReorgDestinationFactory.createDestination(target)).isOK())
		return DND.DROP_NONE;

	return DND.DROP_MOVE;
}
 
Example #15
Source File: Trees.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
public static void addDropSupport(TreeViewer tree,
		Consumer<List<Descriptor>> handler) {
	Transfer transfer = ModelTransfer.getInstance();
	DropTarget dropTarget = new DropTarget(tree.getTree(), DND.DROP_COPY
			| DND.DROP_MOVE | DND.DROP_DEFAULT);
	dropTarget.setTransfer(new Transfer[] { transfer });
	dropTarget.addDropListener(new DropTargetAdapter() {
		@Override
		public void drop(DropTargetEvent event) {
			if (!transfer.isSupportedType(event.currentDataType))
				return;
			var list = ModelTransfer.getDescriptors(event.data);
			handler.accept(list);
		}
	});
}
 
Example #16
Source File: LocationCopyAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	IStructuredSelection selection= (IStructuredSelection) fLocationViewer.getSelection();
	StringBuffer buf= new StringBuffer();
	for (Iterator<?> iterator= selection.iterator(); iterator.hasNext();) {
		CallLocation location= (CallLocation) iterator.next();
		buf.append(location.getLineNumber()).append('\t').append(location.getCallText());
		buf.append('\n');
	}
	TextTransfer plainTextTransfer = TextTransfer.getInstance();
	try {
		fClipboard.setContents(
				new String[]{ CopyCallHierarchyAction.convertLineTerminators(buf.toString()) },
				new Transfer[]{ plainTextTransfer });
	} catch (SWTError e){
		if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD)
			throw e;
		if (MessageDialog.openQuestion(fViewSite.getShell(), CallHierarchyMessages.CopyCallHierarchyAction_problem, CallHierarchyMessages.CopyCallHierarchyAction_clipboard_busy))
			run();
	}
}
 
Example #17
Source File: CopyCallHierarchyAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	StringBuffer buf= new StringBuffer();
	addCalls(fViewer.getTree().getSelection()[0], 0, buf);

	TextTransfer plainTextTransfer= TextTransfer.getInstance();
	try {
		fClipboard.setContents(
				new String[] { convertLineTerminators(buf.toString()) },
				new Transfer[] { plainTextTransfer });
	} catch (SWTError e) {
		if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD)
			throw e;
		if (MessageDialog.openQuestion(fView.getViewSite().getShell(), CallHierarchyMessages.CopyCallHierarchyAction_problem, CallHierarchyMessages.CopyCallHierarchyAction_clipboard_busy))
			run();
	}
}
 
Example #18
Source File: SelectionTransferDropAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private int handleValidateCopy(Object target) throws JavaModelException{

		if (fCopyProcessor == null) {
			final ICopyPolicy policy= ReorgPolicyFactory.createCopyPolicy(ReorgUtils.getResources(fElements), ReorgUtils.getJavaElements(fElements));
			fCopyProcessor= policy.canEnable() ? new JavaCopyProcessor(policy) : null;
		}

		if (!canCopyElements())
			return DND.DROP_NONE;

		if (fCopyProcessor == null)
			return DND.DROP_NONE;

		if (!fCopyProcessor.setDestination(ReorgDestinationFactory.createDestination(target, getCurrentLocation())).isOK())
			return DND.DROP_NONE;

		return DND.DROP_COPY;
	}
 
Example #19
Source File: SelectionTransferDropAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private int handleValidateMove(Object target) throws JavaModelException{
	if (fMoveProcessor == null) {
		IMovePolicy policy= ReorgPolicyFactory.createMovePolicy(ReorgUtils.getResources(fElements), ReorgUtils.getJavaElements(fElements));
		if (policy.canEnable())
			fMoveProcessor= new JavaMoveProcessor(policy);
	}

	if (!canMoveElements())
		return DND.DROP_NONE;

	if (fMoveProcessor == null)
		return DND.DROP_NONE;

	RefactoringStatus moveStatus= fMoveProcessor.setDestination(ReorgDestinationFactory.createDestination(target, getCurrentLocation()));
	if (moveStatus.hasError())
		return DND.DROP_NONE;

	return DND.DROP_MOVE;
}
 
Example #20
Source File: WorkingSetDropAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void performElementRearrange(int eventDetail) {
	// only move if target isn't the other working set. If this is the case
	// the move will happenn automatically by refreshing the other working set
	if (!isOthersWorkingSet(fWorkingSet)) {
		List<Object> elements= new ArrayList<Object>(Arrays.asList(fWorkingSet.getElements()));
		elements.addAll(Arrays.asList(fElementsToAdds));
		fWorkingSet.setElements(elements.toArray(new IAdaptable[elements.size()]));
	}
	if (eventDetail == DND.DROP_MOVE) {
		ITreeSelection treeSelection= (ITreeSelection)fSelection;
		Map<IWorkingSet, List<Object>> workingSets= groupByWorkingSets(treeSelection.getPaths());
		for (Iterator<IWorkingSet> iter= workingSets.keySet().iterator(); iter.hasNext();) {
			IWorkingSet ws= iter.next();
			List<Object> toRemove= workingSets.get(ws);
			List<IAdaptable> currentElements= new ArrayList<IAdaptable>(Arrays.asList(ws.getElements()));
			currentElements.removeAll(toRemove);
			ws.setElements(currentElements.toArray(new IAdaptable[currentElements.size()]));
		}
	}
}
 
Example #21
Source File: FileTransferDropAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected int determineOperation(Object target, int operation, TransferData transferType, int operations) {

	boolean isPackageFragment= target instanceof IPackageFragment;
	boolean isJavaProject= target instanceof IJavaProject;
	boolean isPackageFragmentRoot= target instanceof IPackageFragmentRoot;
	boolean isContainer= target instanceof IContainer;

	if (!(isPackageFragment || isJavaProject || isPackageFragmentRoot || isContainer))
		return DND.DROP_NONE;

	if (isContainer) {
		IContainer container= (IContainer)target;
		if (container.isAccessible() && !Resources.isReadOnly(container))
			return DND.DROP_COPY;
	} else {
		IJavaElement element= (IJavaElement)target;
		if (!element.isReadOnly())
			return DND.DROP_COPY;
	}

	return DND.DROP_NONE;
}
 
Example #22
Source File: TmxEditorViewer.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void createPartControl(Composite parent) {
	parent.setLayout(new FillLayout());
	this.container = parent;
	CellEditorGlobalActionHanlder.getInstance().setIActionBars(getViewSite().getActionBars());
	DropTarget target = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY);
	Transfer[] tfs = new Transfer[] { FileTransfer.getInstance() };
	target.setTransfer(tfs);
	target.addDropListener(new DropTargetAdapter() {
		@Override
		public void drop(DropTargetEvent event) {
			Object o = event.data;
			if (o instanceof String[]) {
				String[] s = (String[]) o;
				if (s.length == 0 && s[0] == null || s[0].length() == 0) {
					return;
				}
				File f = new File(s[0]);
				if (f.exists() && f.isFile()) {
					open(f);
				}
			}
		}
	});
}
 
Example #23
Source File: GamlEditorDragAndDropHandler.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
protected void uninstall() {
	if (getViewer() == null || !fIsTextDragAndDropInstalled) { return; }

	final IDragAndDropService dndService = editor.getSite().getService(IDragAndDropService.class);
	if (dndService == null) { return; }

	final StyledText st = getStyledText();
	dndService.removeMergedDropTarget(st);

	final DragSource dragSource = (DragSource) st.getData(DND.DRAG_SOURCE_KEY);
	if (dragSource != null) {
		dragSource.dispose();
		st.setData(DND.DRAG_SOURCE_KEY, null);
	}

	fIsTextDragAndDropInstalled = false;
}
 
Example #24
Source File: MyDummyTransfer.java    From ldparteditor with MIT License 6 votes vote down vote up
@Override
public void javaToNative(Object object, TransferData transferData) {
    if (!checkMyType(object) || !isSupportedType(transferData)) {
        DND.error(DND.ERROR_INVALID_DATA);
    }
    MyDummyType myTypes = (MyDummyType) object;
    try {
        // write data to a byte array and then ask super to convert to
        // pMedium
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DataOutputStream writeOut = new DataOutputStream(out);
        writeOut.writeInt(myTypes.dummy);
        byte[] buffer2 = out.toByteArray();
        writeOut.close();
        super.javaToNative(buffer2, transferData);
    } catch (IOException e) {
    }
}
 
Example #25
Source File: MyDummyTransfer2.java    From ldparteditor with MIT License 6 votes vote down vote up
@Override
public void javaToNative(Object object, TransferData transferData) {
    if (!checkMyType(object) || !isSupportedType(transferData)) {
        DND.error(DND.ERROR_INVALID_DATA);
    }
    MyDummyType2 myTypes = (MyDummyType2) object;
    try {
        // write data to a byte array and then ask super to convert to
        // pMedium
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DataOutputStream writeOut = new DataOutputStream(out);
        writeOut.writeInt(myTypes.dummy);
        byte[] buffer2 = out.toByteArray();
        writeOut.close();
        super.javaToNative(buffer2, transferData);
    } catch (IOException e) {
    }
}
 
Example #26
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 #27
Source File: TextEditor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void pasteClipboard( )
{
	Clipboard cb = new Clipboard( Display.getCurrent( ) );
	// TransferData[] types = cb.getAvailableTypes( );
	RTFTransfer rtfTransfer = RTFTransfer.getInstance( );
	Object contents = cb.getContents( rtfTransfer );
	// textEditor.paste( );
	if ( contents != null )
	{
		RTFHTMLHandler handler = new RTFHTMLHandler( );
		try
		{
			RTFParser.parse( contents.toString( ), handler );
			textEditor.insert( handler.toHTML( ) );
			return;
		}
		catch ( Exception e1 )
		{
		}
	}
	else
	{
		HTMLTransfer htmlTransfer = HTMLTransfer.getInstance( );
		contents = cb.getContents( htmlTransfer );
		if ( contents != null )
		{
			textEditor.insert( contents.toString( ) );
			return;
		}
	}

	TextTransfer plainTextTransfer = TextTransfer.getInstance( );
	String text = (String) cb.getContents( plainTextTransfer, DND.CLIPBOARD );
	textEditor.insert( text );
}
 
Example #28
Source File: CopyToClipboardAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void copyToClipboard(ITextSelection selection, int repeatCount) {
	try{
		fClipboard.setContents(new String[] { selection.getText() }, new Transfer[] { TextTransfer.getInstance() });
	} catch (SWTError e) {
		if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD || repeatCount >= MAX_REPEAT_COUNT)
			throw e;

		if (MessageDialog.openQuestion(getShell(), InfoViewMessages.CopyToClipboard_error_title, InfoViewMessages.CopyToClipboard_error_message))
			copyToClipboard(selection, repeatCount + 1);
	}
}
 
Example #29
Source File: BTEditor.java    From jbt with Apache License 2.0 5 votes vote down vote up
public void dragEnter(DropTargetEvent event) {
	for (int i = 0; i < event.dataTypes.length; i++) {
		if (BTNodeIndentifierTransfer.getInstance().isSupportedType(event.dataTypes[i])) {
			event.currentDataType = event.dataTypes[i];
			event.detail = DND.DROP_MOVE;
			break;
		}
		if (ConceptualBTNodeTransfer.getInstance().isSupportedType(event.dataTypes[i])) {
			event.currentDataType = event.dataTypes[i];
			event.detail = DND.DROP_MOVE;
			break;
		}
	}
}
 
Example #30
Source File: KillRing.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the text from the system clipboard
 * 
 * @return the system clipboard content as a String
 */
public String getClipboardText() {
	Clipboard clipboard = new Clipboard(Display.getCurrent());
	TextTransfer plainTextTransfer = TextTransfer.getInstance();
	String cliptxt = (String)clipboard.getContents(plainTextTransfer, DND.CLIPBOARD);
	clipboard.dispose();
	return cliptxt;
}