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 File: CallHierarchyTransferDropAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@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 #2
Source File: ClipboardUtil.java    From xtext-eclipse with 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 #3
Source File: JavaElementTransfer.java    From Eclipse-Postfix-Code-Completion with 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 #4
Source File: SimpleTextTransfer.java    From birt with 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 #5
Source File: SnippetTransfer.java    From APICloud-Studio with 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 #6
Source File: MyDummyTransfer.java    From ldparteditor with 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 #7
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 #8
Source File: FixedURLTransfer.java    From BiglyBT with 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 #9
Source File: MyDummyTransfer2.java    From ldparteditor with 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 #10
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 #11
Source File: SimpleTextTransfer.java    From birt with 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 #12
Source File: TypedSourceTransfer.java    From Eclipse-Postfix-Code-Completion with 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 #13
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 #14
Source File: PasteAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected final TypedSource[] getClipboardTypedSources(TransferData[] availableDataTypes) {
	Transfer transfer= TypedSourceTransfer.getInstance();
	if (isAvailable(transfer, availableDataTypes)) {
		return (TypedSource[])getContents(fClipboard2, transfer, getShell());
	}
	return null;
}
 
Example #15
Source File: PasteAction.java    From Eclipse-Postfix-Code-Completion with 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;
}
 
Example #16
Source File: PasteAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected final IJavaElement[] getClipboardJavaElements(TransferData[] availableDataTypes) {
	Transfer transfer= JavaElementTransfer.getInstance();
	if (isAvailable(transfer, availableDataTypes)) {
		return (IJavaElement[])getContents(fClipboard2, transfer, getShell());
	}
	return null;
}
 
Example #17
Source File: DropAdapterAssistant.java    From tracecompass with 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 #18
Source File: PasteAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean canEnable(TransferData[] availableDataTypes) {
	boolean resourceTransfer= isAvailable(ResourceTransfer.getInstance(), availableDataTypes);
	boolean javaElementTransfer= isAvailable(JavaElementTransfer.getInstance(), availableDataTypes);
	if (! javaElementTransfer)
		return canPasteSimpleProjects(availableDataTypes);
	if (! resourceTransfer)
		return canPasteJavaProjects(availableDataTypes);
	return canPasteJavaProjects(availableDataTypes) && canPasteSimpleProjects(availableDataTypes);
  	}
 
Example #19
Source File: HSTextTransfer.java    From tmxeditor8 with 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 File: PasteAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private String[] getClipboardFiles(TransferData[] availableDataTypes) {
	Transfer transfer= FileTransfer.getInstance();
	if (isAvailable(transfer, availableDataTypes)) {
		return (String[])getContents(getClipboard(), transfer, getShell());
	}
	return null;
}
 
Example #21
Source File: DesignElementDropAdapter.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see ViewerDropAdapter#validateDrop(Object, int, TransferData)
 */
public boolean validateDrop( Object target, int op, TransferData type )
{

	//		if(target!=null){
	//			Object adapter = ElementAdapterManager.getAdatper( target, IElementDropAdapter.class );
	//			if(adapter!=null){
	//				IElementDropAdapter dropAdapter = (IElementDropAdapter)adapter;
	//				return dropAdapter.validateDrop( target, getCurrentOperation( ), getCurrentLocation( ), null, type );
	//			}
	//		}

	return TemplateTransfer.getInstance( ).isSupportedType( type );
}
 
Example #22
Source File: TypedSourceTransfer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void javaToNative(Object data, TransferData transferData) {
	if (! (data instanceof TypedSource[]))
		return;
	TypedSource[] sources = (TypedSource[]) data;

	/*
	 * The serialization format is:
	 *  (int) number of elements
	 * Then, the following for each element:
	 *  (int) type (see <code>IJavaElement</code>)
	 *  (String) source of the element
	 */

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

		dataOut.writeInt(sources.length);

		for (int i = 0; i < sources.length; i++) {
			writeJavaElement(dataOut, sources[i]);
		}

		dataOut.close();
		out.close();

		super.javaToNative(out.toByteArray(), transferData);
	} catch (IOException e) {
		//it's best to send nothing if there were problems
	}
}
 
Example #23
Source File: WorkingSetDropAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected int determineOperation(Object target, int operation, TransferData transferType, int operations) {
	switch(operation) {
		case DND.DROP_DEFAULT:
		case DND.DROP_COPY:
		case DND.DROP_MOVE:
			return validateTarget(target, operation);
		default:
			return DND.DROP_NONE;
	}

}
 
Example #24
Source File: SelectionTransferDropAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected int determineOperation(Object target, int operation, TransferData transferType, int operations) {
	int result= internalDetermineOperation(target, operation, operations);

	if (result == DND.DROP_NONE) {
		setSelectionFeedbackEnabled(false);
	} else {
		setSelectionFeedbackEnabled(true);
	}

	return result;
}
 
Example #25
Source File: PasteAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean canPasteSimpleProjects(TransferData[] availableDataTypes) {
	IResource[] resources= getClipboardResources(availableDataTypes);
	if (resources == null || resources.length == 0) return false;
	for (int i= 0; i < resources.length; i++) {
		if (resources[i].getType() != IResource.PROJECT || ! ((IProject)resources[i]).isOpen())
			return false;
	}
	return true;
}
 
Example #26
Source File: PasteAction.java    From Eclipse-Postfix-Code-Completion with 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 #27
Source File: JavaElementTransfer.java    From Eclipse-Postfix-Code-Completion with 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 #28
Source File: RemoteResourceTransfer.java    From APICloud-Studio with 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 #29
Source File: ExampleDropTargetListener.java    From statecharts with 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 #30
Source File: TabFolderReorder.java    From hop with 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;
}