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 Project: lapse-plus   Author: OWASP   File: SinkView.java    License: 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 #2
Source Project: olca-app   Author: GreenDelta   File: Trees.java    License: 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 #3
Source Project: lapse-plus   Author: OWASP   File: SourceView.java    License: 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 #4
Source Project: birt   Author: eclipse   File: ReportTemplateTransferDropTargetListener.java    License: 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 #5
Source Project: birt   Author: eclipse   File: LibraryTemplateTransferDropTargetListener.java    License: 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 #6
Source Project: Pydev   Author: fabioz   File: CopyAction.java    License: 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 #7
Source Project: Pydev   Author: fabioz   File: ScriptConsoleViewer.java    License: 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 Project: neoscada   Author: eclipse   File: MemoryEditor.java    License: 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 Project: neoscada   Author: eclipse   File: InfrastructureEditor.java    License: 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 Project: neoscada   Author: eclipse   File: SecurityEditor.java    License: 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 Project: neoscada   Author: eclipse   File: ComponentEditor.java    License: 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 Project: neoscada   Author: eclipse   File: ConfigurationEditor.java    License: 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 Project: M2Doc   Author: ObeoNetwork   File: GenconfEditor.java    License: 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 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 #15
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: JavaDropAdapterAssistant.java    License: 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 #16
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 #17
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 #18
Source Project: gama   Author: gama-platform   File: GamlEditorDragAndDropHandler.java    License: 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 #19
Source Project: tmxeditor8   Author: heartsome   File: TmxEditorViewer.java    License: 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 #20
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 #21
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: WorkingSetDropAdapter.java    License: 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 #22
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 #23
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 #24
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: CopyCallHierarchyAction.java    License: 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 #25
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: LocationCopyAction.java    License: 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 #26
/**
 * 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 #27
Source Project: nebula   Author: eclipse   File: XViewerCustDialogDragDrop.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public XViewerCustDialogDragDrop(XViewerCustomizeDialog xViewerCustomizeDialog) {
   this.xViewerCustomizeDialog = xViewerCustomizeDialog;

   xViewerCustomizeDialog.visibleColTable.getViewer().addDragSupport(DND.DROP_MOVE,
      new Transfer[] {TextTransfer.getInstance()}, visibleTableDragListener);
   xViewerCustomizeDialog.visibleColTable.getViewer().addDropSupport(DND.DROP_MOVE,
      new Transfer[] {TextTransfer.getInstance()}, visibleTableDropListener);
   xViewerCustomizeDialog.hiddenColTable.getViewer().addDragSupport(DND.DROP_MOVE,
      new Transfer[] {TextTransfer.getInstance()}, hiddenTableDragListener);
   xViewerCustomizeDialog.hiddenColTable.getViewer().addDropSupport(DND.DROP_MOVE,
      new Transfer[] {TextTransfer.getInstance()}, hiddenTableDropListener);

}
 
Example #28
Source Project: e4macs   Author: MulgaSoft   File: KillRing.java    License: 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;
}
 
Example #29
Source Project: translationstudio8   Author: heartsome   File: CopyAction.java    License: GNU General Public License v2.0 5 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,
                         WorkbenchNavigatorMessages.actions_CopyAction_msgTitle, // TODO ResourceNavigatorMessages.CopyToClipboardProblemDialog_title,  //$NON-NLS-1$
                         WorkbenchNavigatorMessages.actions_CopyAction_msg)) { //$NON-NLS-1$
	setClipboard(resources, fileNames, names);
}
     }
 }
 
Example #30
Source Project: birt   Author: eclipse   File: DesignerDropListener.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void dragEnter( DropTargetEvent event )
{
	if ( ( event.operations & DND.DROP_COPY ) != 0
			&& ( event.operations & DND.DROP_MOVE ) == 0 )
	{
		event.detail = DND.DROP_COPY;
	}
	super.dragEnter( event );
}