org.eclipse.swt.dnd.TransferData Java Examples

The following examples show how to use org.eclipse.swt.dnd.TransferData. 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: birt   Author: eclipse   File: SimpleTextTransfer.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This implementation of <code>javaToNative</code> converts plain text
 * represented by a java <code>String</code> to a platform specific
 * representation.
 * 
 * @param object
 *            a java <code>String</code> containing text
 * @param transferData
 *            an empty <code>TransferData</code> object; this object will
 *            be filled in on return with the platform specific format of
 *            the data
 * 
 * @see Transfer#javaToNative
 */
public void javaToNative( Object object, TransferData transferData )
{
	if ( checkText( object ) && isSupportedType( transferData ) )
	{
		try
		{
			super.javaToNative( ( (String) object ).getBytes( "UTF-8" ), //$NON-NLS-1$
					transferData );
		}
		catch ( UnsupportedEncodingException e )
		{
			// do not need to log
			super.javaToNative( ( (String) object ).getBytes( ),
					transferData );
		}
	}
}
 
Example #2
Source Project: BiglyBT   Author: BiglySoftware   File: FixedURLTransfer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object nativeToJava(TransferData transferData) {
	Object result = urlTransfer.nativeToJava(transferData);
	if (DISABLED || result != null) {
		return result;
	}

	if (DEBUG) System.out.println("nativeToJava called");
	try {
		if (isSupportedType(transferData)) {
			byte [] buffer = (byte[]) super.nativeToJava(transferData);
			return bytebufferToJava(buffer);
		}
	} catch (Exception e) {
		Debug.out(e);
	}

	return null;
}
 
Example #3
Source Project: birt   Author: eclipse   File: SimpleTextTransfer.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This implementation of <code>nativeToJava</code> converts a platform
 * specific representation of plain text to a java <code>String</code>.
 * 
 * @param transferData
 *            the platform specific representation of the data to be
 *            converted
 * @return a java <code>String</code> containing text if the conversion
 *         was successful; otherwise null
 * 
 * @see Transfer#nativeToJava
 */
public Object nativeToJava( TransferData transferData )
{
	if ( !isSupportedType( transferData ) )
	{
		return null;
	}
	byte[] bytes = (byte[]) super.nativeToJava( transferData );

	try
	{
		return new String( bytes, "UTF-8" ); //$NON-NLS-1$
	}
	catch ( UnsupportedEncodingException e )
	{
		// do not need to log
	}
	return new String( bytes );
}
 
Example #4
Source Project: xtext-eclipse   Author: eclipse   File: ClipboardUtil.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Retrieves Java import information from the clipboard.
 *
 * @return {@link JavaImportData} containing imports information
 */
public static JavaImportData getJavaImportsContent() {
	return clipboardOperation(new Function<Clipboard, JavaImportData>() {

		@Override
		public JavaImportData apply(Clipboard clipboard) {
			for (int i = 0; i < clipboard.getAvailableTypeNames().length; i++) {
				final String formatName = clipboard.getAvailableTypeNames()[i];
				if (formatName.startsWith("source-with-imports-transfer-format")) {
					final TransferData transferData = clipboard.getAvailableTypes()[i];
					Object content = clipboard.getContents(new DynamicByteArrayTransfer(formatName, transferData));
					if (content instanceof JavaImportData) {
						return (JavaImportData) content;
					}
					return null;
				}
			}
			return null;
		}
	});
}
 
Example #5
Source Project: ldparteditor   Author: nilsschmidt1337   File: MyDummyTransfer2.java    License: 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 #6
Source Project: ldparteditor   Author: nilsschmidt1337   File: MyDummyTransfer2.java    License: MIT License 6 votes vote down vote up
@Override
public Object nativeToJava(TransferData transferData) {
    if (isSupportedType(transferData)) {
        byte[] buffer = (byte[]) super.nativeToJava(transferData);
        if (buffer == null)
            return null;

        MyDummyType2 datum = new MyDummyType2();
        try {
            ByteArrayInputStream in = new ByteArrayInputStream(buffer);
            DataInputStream readIn = new DataInputStream(in);
            datum.dummy = readIn.readInt();
            readIn.close();
        } catch (IOException ex) {
            return null;
        }
        return datum;
    }

    return null;
}
 
Example #7
Source Project: ldparteditor   Author: nilsschmidt1337   File: MyDummyTransfer.java    License: 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 #8
Source Project: ldparteditor   Author: nilsschmidt1337   File: MyDummyTransfer.java    License: MIT License 6 votes vote down vote up
@Override
public Object nativeToJava(TransferData transferData) {
    if (isSupportedType(transferData)) {
        byte[] buffer = (byte[]) super.nativeToJava(transferData);
        if (buffer == null)
            return null;

        MyDummyType datum = new MyDummyType();
        try {
            ByteArrayInputStream in = new ByteArrayInputStream(buffer);
            DataInputStream readIn = new DataInputStream(in);
            datum.dummy = readIn.readInt();
            readIn.close();
        } catch (IOException ex) {
            return null;
        }
        return datum;
    }

    return null;
}
 
Example #9
Source Project: APICloud-Studio   Author: apicloudcom   File: SnippetTransfer.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void javaToNative(Object object, TransferData transferData)
{
	if (object instanceof SnippetElement)
	{
		SnippetElement snippetElement = (SnippetElement) object;
		byte[] bytes = getBytes(snippetElement);
		if (bytes != null)
		{
			super.javaToNative(bytes, transferData);
		}
	}
	else
	{
		super.javaToNative(object, transferData);
	}
}
 
Example #10
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: JavaElementTransfer.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Object nativeToJava(TransferData transferData) {
	/*
	 * The element serialization format is:
	 *  (int) number of element
	 * Then, the following for each element:
	 *  (String) handle identifier
	 */

	byte[] bytes= (byte[]) super.nativeToJava(transferData);
	if (bytes == null)
		return null;
	DataInputStream in= new DataInputStream(new ByteArrayInputStream(bytes));
	try {
		int count= in.readInt();
		IJavaElement[] results= new IJavaElement[count];
		for (int i= 0; i < count; i++) {
			results[i]= readJavaElement(in);
		}
		return results;
	} catch (IOException e) {
		return null;
	}
}
 
Example #11
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: TypedSourceTransfer.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Object nativeToJava(TransferData transferData) {

	byte[] bytes = (byte[]) super.nativeToJava(transferData);
	if (bytes == null)
		return null;
	DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
	try {
		int count = in.readInt();
		TypedSource[] results = new TypedSource[count];
		for (int i = 0; i < count; i++) {
			results[i] = readJavaElement(in);
			Assert.isNotNull(results[i]);
		}
		in.close();
		return results;
	} catch (IOException e) {
		return null;
	}
}
 
Example #12
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: FileTransferDropAdapter.java    License: 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 #13
@Override
protected int determineOperation(Object target, int operation, TransferData transferType, int operations) {
	setSelectionFeedbackEnabled(false);
	setExpandEnabled(false);

	initializeSelection();

	if (target != null) {
		return super.determineOperation(target, operation, transferType, operations);
	} else if (getInputElement(getSelection()) != null) {
		setSelectionFeedbackEnabled(false);
		setExpandEnabled(false);
		return operation == DND.DROP_DEFAULT || operation == DND.DROP_MOVE ? DND.DROP_LINK : operation;
	} else {
		return DND.DROP_NONE;
	}
}
 
Example #14
Source Project: hop   Author: project-hop   File: TabFolderReorder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object nativeToJava( TransferData transferData ) {
  byte bytes[] = (byte[]) super.nativeToJava( transferData );
  if ( bytes == null ) {
    return null;
  }
  long startTime = Long.parseLong( new String( bytes ) );
  return ( this.startTime == startTime ) ? item : null;
}
 
Example #15
Source Project: neoscada   Author: eclipse   File: ItemTransfer.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void javaToNative ( final Object object, final TransferData transferData )
{
    final byte[] bytes = toByteArray ( (Item[])object );
    if ( bytes != null )
    {
        super.javaToNative ( bytes, transferData );
    }
}
 
Example #16
Source Project: neoscada   Author: eclipse   File: ItemTransfer.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object nativeToJava ( final TransferData transferData )
{
    final byte[] bytes = (byte[])super.nativeToJava ( transferData );
    if ( bytes == null )
    {
        return null;
    }
    return fromByteArray ( bytes );
}
 
Example #17
Source Project: neoscada   Author: eclipse   File: ItemTransfer.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void javaToNative ( final Object object, final TransferData transferData )
{
    final byte[] bytes = toByteArray ( (Item[])object );
    if ( bytes != null )
    {
        super.javaToNative ( bytes, transferData );
    }
}
 
Example #18
Source Project: BiglyBT   Author: BiglySoftware   File: FixedURLTransfer.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public TransferData[] getSupportedTypes() {
	if (DISABLED) {
		return urlTransfer.getSupportedTypes();
	}
	return super.getSupportedTypes();
}
 
Example #19
Source Project: translationstudio8   Author: heartsome   File: XLiffTextTransfer.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void javaToNative(Object object, TransferData transferData) {
	if (!checkMyType(object) || !isSupportedType(transferData)) {
		DND.error(DND.ERROR_INVALID_DATA);
	}
	String string = (String) object;
	byte[] bytes = string.getBytes();
	if (bytes != null) {
		super.javaToNative(bytes, transferData);
	}
}
 
Example #20
Source Project: scava   Author: crossminer   File: CrossflowDiagramEditor.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected List getObjectsBeingDropped() {
	TransferData data = getCurrentEvent().currentDataType;
	HashSet<URI> uris = new HashSet<URI>();

	Object transferedObject = getJavaObject(data);
	if (transferedObject instanceof IStructuredSelection) {
		IStructuredSelection selection = (IStructuredSelection) transferedObject;
		for (Iterator<?> it = selection.iterator(); it.hasNext();) {
			Object nextSelectedObject = it.next();
			if (nextSelectedObject instanceof CrossflowNavigatorItem) {
				View view = ((CrossflowNavigatorItem) nextSelectedObject).getView();
				nextSelectedObject = view.getElement();
			} else if (nextSelectedObject instanceof IAdaptable) {
				IAdaptable adaptable = (IAdaptable) nextSelectedObject;
				nextSelectedObject = adaptable.getAdapter(EObject.class);
			}

			if (nextSelectedObject instanceof EObject) {
				EObject modelElement = (EObject) nextSelectedObject;
				uris.add(EcoreUtil.getURI(modelElement));
			}
		}
	}

	ArrayList<EObject> result = new ArrayList<EObject>(uris.size());
	for (URI nextURI : uris) {
		EObject modelObject = getEditingDomain().getResourceSet().getEObject(nextURI, true);
		result.add(modelObject);
	}
	return result;
}
 
Example #21
Source Project: xtext-eclipse   Author: eclipse   File: ClipboardUtil.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object nativeToJava(TransferData transferData) {
	byte[] bytes = (byte[]) super.nativeToJava(transferData);
	if (bytes != null) {
		try {
			return new JavaImportData(new ClipboardData(bytes));
		} catch (IOException e) {
		}
	}
	return null;
}
 
Example #22
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: ClipboardOperationAction.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void javaToNative(Object data, TransferData transferData) {
	if (data instanceof ClipboardData) {
		try {
			super.javaToNative(((ClipboardData) data).serialize(), transferData);
		} catch (IOException e) {
			//it's best to send nothing if there were problems
		}
	}
}
 
Example #23
Source Project: xtext-eclipse   Author: eclipse   File: ImportsAwareClipboardAction.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Object nativeToJava(TransferData transferData) {
	byte[] bytes = (byte[]) super.nativeToJava(transferData);
	if (bytes != null) {
		try {
			return new XbaseClipboardData(bytes);
		} catch (IOException e) {
		}
	}
	return null;
}
 
Example #24
Source Project: texlipse   Author: eclipse   File: TexOutlineDNDAdapter.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Validate the drop. Invalidation is caused if
    * 
    * - outline is not uptodate
    * - transfer type is other than text
    * - drop target is equal or children of source
    * - target is preamble
    * 
    * @param target
    * @param operation
    * @param transferType
    * 
    * @return true if drop is valid
    * 
    * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
 */
public boolean validateDrop(Object target, int operation,
		TransferData transferType) {

	// deny if outline is dirty
	if (this.outline.isModelDirty()) {
		return false;
	}
	
	// check transfer type, only allow text
	if (!TextTransfer.getInstance().isSupportedType(transferType)) {
		return false;
	}
			
	// get the selected node, check null and type
	OutlineNode targetNode = (OutlineNode)target;
	if (targetNode == null || targetNode.getType() == OutlineNode.TYPE_PREAMBLE) {
		return false;
	}
   
	// deny dropping over oneself or over ones children
	if (targetNode.equals(this.dragSource) ||
			isAncestor(dragSource, targetNode)) {
		return false;
	}
	
	return true;
}
 
Example #25
Source Project: tracecompass   Author: tracecompass   File: DropAdapterAssistant.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IStatus validateDrop(Object target, int operation, TransferData transferType) {
    if (target instanceof TmfTraceFolder) {
        return Status.OK_STATUS;
    }
    if (target instanceof TmfExperimentElement) {
        return Status.OK_STATUS;
    }
    if (target instanceof TmfTraceElement) {
        ITmfProjectModelElement parent = ((TmfTraceElement) target).getParent();
        if (parent instanceof TmfTraceFolder) {
            return Status.OK_STATUS;
        }
        if (parent instanceof TmfExperimentElement) {
            return Status.OK_STATUS;
        }
    }

    if (target instanceof TmfProjectElement) {
        return Status.OK_STATUS;
    }

    if (target instanceof IProject) {
        return Status.CANCEL_STATUS;
    }

    return Status.CANCEL_STATUS;
}
 
Example #26
Source Project: statecharts   Author: Yakindu   File: ExampleDropTargetListener.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private boolean extractEventData(DropTargetEvent e) {
	TransferData transferData = e.currentDataType;
	if (transferData != null) {
		Object data = URLTransfer.getInstance().nativeToJava(transferData);
		if (data != null && getUrl(data) != null) {
			e.data = data;
			return true;
		}
	}
	return false;
}
 
Example #27
Source Project: APICloud-Studio   Author: apicloudcom   File: RemoteResourceTransfer.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void javaToNative (Object object, TransferData transferData) {
	if (object == null || !(object instanceof ISVNRemoteResource)) return;
	
	if (isSupportedType(transferData)) {
		// write data to a byte array and then ask super to convert to pMedium
	byte[] buffer = toByteArray((ISVNRemoteResource) object);
    super.javaToNative(buffer, transferData);
	}
}
 
Example #28
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: JavaElementTransfer.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void javaToNative(Object data, TransferData transferData) {
	if (!(data instanceof IJavaElement[]))
		return;

	IJavaElement[] javaElements= (IJavaElement[]) data;
	/*
	 * The element serialization format is:
	 *  (int) number of element
	 * Then, the following for each element:
	 *  (String) handle identifier
	 */

	try {
		ByteArrayOutputStream out= new ByteArrayOutputStream();
		DataOutputStream dataOut= new DataOutputStream(out);

		//write the number of elements
		dataOut.writeInt(javaElements.length);

		//write each element
		for (int i= 0; i < javaElements.length; i++) {
			writeJavaElement(dataOut, javaElements[i]);
		}

		//cleanup
		dataOut.close();
		out.close();
		byte[] bytes= out.toByteArray();
		super.javaToNative(bytes, transferData);
	} catch (IOException e) {
		//it's best to send nothing if there were problems
	}
}
 
Example #29
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: PasteAction.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private Paster[] createEnabledPasters(TransferData[] availableDataTypes, Clipboard clipboard) {
	Paster paster;
	Shell shell = getShell();
	List<Paster> result= new ArrayList<Paster>(2);
	paster= new ProjectPaster(shell, clipboard);
	if (paster.canEnable(availableDataTypes))
		result.add(paster);

	paster= new JavaElementAndResourcePaster(shell, clipboard);
	if (paster.canEnable(availableDataTypes))
		result.add(paster);

	paster= new TypedSourcePaster(shell, clipboard);
	if (paster.canEnable(availableDataTypes))
		result.add(paster);

	paster= new FilePaster(shell, clipboard);
	if (paster.canEnable(availableDataTypes))
		result.add(paster);

	paster= new WorkingSetPaster(shell, clipboard);
	if (paster.canEnable(availableDataTypes))
		result.add(paster);

	paster= new TextPaster(shell, clipboard);
	if (paster.canEnable(availableDataTypes))
		result.add(paster);
	return result.toArray(new Paster[result.size()]);
}
 
Example #30
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: PasteAction.java    License: Eclipse Public License 1.0 5 votes vote down vote up
protected final IResource[] getClipboardResources(TransferData[] availableDataTypes) {
	Transfer transfer= ResourceTransfer.getInstance();
	if (isAvailable(transfer, availableDataTypes)) {
		return (IResource[])getContents(fClipboard2, transfer, getShell());
	}
	return null;
}