Java 类org.eclipse.swt.dnd.DragSourceEvent 实例源码

项目:neoscada    文件:DragHelper.java   
protected static void setItemUriData ( final DragSourceEvent event, final Collection<Item> items )
{
    final StringBuilder sb = new StringBuilder ();
    int cnt = 0;
    for ( final Item item : items )
    {
        if ( cnt > 0 )
        {
            sb.append ( "\n" ); //$NON-NLS-1$
        }

        sb.append ( item.getConnectionString () );
        sb.append ( "#" ); //$NON-NLS-1$
        sb.append ( item.getId () );

        cnt++;
    }
    event.data = sb.toString ();
}
项目:neoscada    文件:ItemDragSourceListener.java   
@Override
public void dragSetData ( final DragSourceEvent event )
{
    try
    {
        if ( ItemTransfer.getInstance ().isSupportedType ( event.dataType ) )
        {
            final IStructuredSelection selection = (IStructuredSelection)LocalSelectionTransfer.getTransfer ().getSelection ();
            final Collection<Item> items = ItemSelectionHelper.getSelection ( selection );
            event.data = items.toArray ( new Item[items.size ()] );
            event.doit = true;
        }
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to set drag data", e );
        event.doit = false;
    }

}
项目:neoscada    文件:ItemDragSourceListener.java   
@Override
public void dragStart ( final DragSourceEvent event )
{
    event.doit = false;

    if ( ! ( this.viewer.getSelection () instanceof IStructuredSelection ) )
    {
        return;
    }

    final Collection<Item> items = ItemSelectionHelper.getSelection ( this.viewer.getSelection () );
    if ( !items.isEmpty () )
    {
        LocalSelectionTransfer.getTransfer ().setSelection ( this.viewer.getSelection () );
        event.doit = true;
    }

}
项目:neoscada    文件:RealtimeListDragSourceListener.java   
protected void setItemStringData ( final DragSourceEvent event, final IStructuredSelection selection )
{
    final StringBuilder sb = new StringBuilder ();
    int cnt = 0;
    for ( final Iterator<?> i = selection.iterator (); i.hasNext (); )
    {
        final ListEntry entry = (ListEntry)i.next ();
        if ( cnt > 0 )
        {
            sb.append ( "\n" ); //$NON-NLS-1$
        }

        sb.append ( entry.getDataItem ().getItem ().getId () );
        cnt++;
    }
    event.data = sb.toString ();
}
项目:neoscada    文件:ItemDragSourceListener.java   
@Override
public void dragSetData ( final DragSourceEvent event )
{
    try
    {
        if ( ItemTransfer.getInstance ().isSupportedType ( event.dataType ) )
        {
            final IStructuredSelection selection = (IStructuredSelection)LocalSelectionTransfer.getTransfer ().getSelection ();
            final Collection<Item> items = ItemSelectionHelper.getSelection ( selection );
            event.data = items.toArray ( new Item[items.size ()] );
            event.doit = true;
        }
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to set drag data", e );
        event.doit = false;
    }

}
项目:neoscada    文件:ItemDragSourceListener.java   
@Override
public void dragStart ( final DragSourceEvent event )
{
    event.doit = false;

    if ( ! ( this.viewer.getSelection () instanceof IStructuredSelection ) )
    {
        return;
    }

    final Collection<Item> items = ItemSelectionHelper.getSelection ( this.viewer.getSelection () );
    if ( !items.isEmpty () )
    {
        LocalSelectionTransfer.getTransfer ().setSelection ( this.viewer.getSelection () );
        event.doit = true;
    }

}
项目:convertigo-eclipse    文件:SourcePickerView.java   
private void createXhtmlTree() {
    sourcePicker.createXhtmlTree(treesSashForm);

    // DND support
    int ops = DND.DROP_COPY | DND.DROP_MOVE;
    Transfer[] transfers = new Transfer[] {StepSourceTransfer.getInstance()};

    DragSource source = new DragSource(sourcePicker.getTwsDomTree().getTree(), ops);
    source.setTransfer(transfers);
    source.addDragListener(new DragSourceAdapter() {            
        @Override
        public void dragStart(DragSourceEvent event) {
            event.doit = true;
            StepSourceTransfer.getInstance().setStepSource(sourcePicker.getDragData());
        }
    });

}
项目:convertigo-eclipse    文件:TreeDragListener.java   
@Override
public void dragSetData(DragSourceEvent event) {
    ProjectExplorerView explorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
    if (explorerView != null) {
        try {
            String sXml = ClipboardAction.dnd.copy(explorerView);
            if (sXml != null) {
                event.data = sXml;
            }
        } catch (EngineException e) {
            ConvertigoPlugin.logException(e, "Cannot drag");
        } catch (ParserConfigurationException ee) {
            ConvertigoPlugin.logException(ee, "Cannot drag");
        }
    }
}
项目:Hydrograph    文件:CategoriesDialogSourceComposite.java   
private void addDragSupport(final List sourcePackageList, final Combo comboJarList) {
    DragSource dragSource = ExpressionEditorUtil.INSTANCE.getDragSource(sourcePackageList);
    dragSource.addDragListener(new DragSourceAdapter() {
        public void dragSetData(DragSourceEvent event) {
            event.data = formatDataToTransfer(sourcePackageList.getSelection());
        }

        private Object formatDataToTransfer(String[] selection) {
            StringBuffer buffer = new StringBuffer();
            for (String field : selection) {
                buffer.append(field + Constants.DOT + Constants.ASTERISK + SWT.SPACE + Constants.DASH + SWT.SPACE
                        + comboJarList.getItem(comboJarList.getSelectionIndex())
                        + Constants.FIELD_SEPRATOR_FOR_DRAG_DROP);
            }
            return buffer.toString();
        }
    });
}
项目:Hydrograph    文件:ELTSWTWidgets.java   
public void applyDragFromTableViewer(Control sourceControl, int index) {
    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    final String portLabel = "in" + index + ".";
    int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
    final Table table = (Table) sourceControl;
    DragSource source = new DragSource(table, operations);
    source.setTransfer(types);
    final String[] columnData = new String[1];
    source.addDragListener(new DragSourceAdapter() {
        public void dragSetData(DragSourceEvent event) {
            // Set the data to be the first selected item's text
            event.data = addDelimeter(portLabel, table.getSelection());
        }
    });

}
项目:javapasswordsafe    文件:TreeDragListener.java   
public void dragSetData(final DragSourceEvent event) {
    final IStructuredSelection selection = (IStructuredSelection) viewer
            .getSelection();

    if (selection.getFirstElement() instanceof PwsEntryBean) {
        final PwsEntryBean firstElement = (PwsEntryBean) selection.getFirstElement();
        if (PwsEntryBeanTransfer.getInstance().isSupportedType(event.dataType)) {
            event.data = firstElement.getStoreIndex();
        }
    } else if (selection.getFirstElement() instanceof PasswordTreeContentProvider.TreeGroup) {
        event.doit = false; // disable for now
        final PasswordTreeContentProvider.TreeGroup group =
                (PasswordTreeContentProvider.TreeGroup) selection.getFirstElement();

        if (PwsEntryBeanTransfer.getInstance().isSupportedType(event.dataType)) {
            event.data = group.getGroupPath();
        }
        if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
            event.data = group.getGroupPath();
        }
    } else {
        log.warn("Unknown type: " + selection.getFirstElement().getClass());
    }
}
项目:texlipse    文件:TexOutlineDNDAdapter.java   
/** 
    * Validate the drag start. Dragging is denied if:
    * 
    * - outline is not uptodate
    * - source is preamble
    *
    * @param event the drag event 
 * @see org.eclipse.swt.dnd.DragSourceListener#dragStart(org.eclipse.swt.dnd.DragSourceEvent)
 */
public void dragStart(DragSourceEvent event) {
    event.doit = false;

    // deny if outline is dirty
    if (this.outline.isModelDirty()) {
        return;
    }

    // get the selected node
    OutlineNode node = this.getSelection();
    if (node == null) {
        return;
    }

    // deny dragging of certain elements
    if (node.getType() == OutlineNode.TYPE_PREAMBLE) {
        return;
    }

    // proceed
    this.dragSource = node;
    event.doit = true;
}
项目:texlipse    文件:TexOutlineDNDAdapter.java   
/**
    * Set the text data into TextTransfer.
    * 
    * @see org.eclipse.swt.dnd.DragSourceListener#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
 */
   public void dragSetData(DragSourceEvent event) {

    // check that requested data type is supported
    if (!TextTransfer.getInstance().isSupportedType(event.dataType)) {
        return;
    }

       // get the source text
    int sourceOffset = this.dragSource.getPosition().getOffset();
    int sourceLength = this.dragSource.getPosition().getLength();

    Position sourcePosition = dragSource.getPosition();
    String sourceText = "";
    try {
        sourceText = getDocument().get(sourcePosition.getOffset(), sourcePosition.getLength());
    } catch (BadLocationException e) {
        TexlipsePlugin.log("Could not set drag data.", e);
        return;
    }

       // set the data
       event.data = sourceText;
}
项目:texlipse    文件:TexOutlineDNDAdapter.java   
/**
    * 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();
}
项目:ermasterr    文件:ERDiagramTransferDragSourceListener.java   
private Object getTargetModel(final DragSourceEvent event) {
    final List editParts = dragSourceViewer.getSelectedEditParts();
    if (editParts.size() != 1) {
        // ドラッグアンドドロップは選択されているオブジェクトが1つのときのみ可能とする
        return null;
    }

    final EditPart editPart = (EditPart) editParts.get(0);

    final Object model = editPart.getModel();
    if (model instanceof NormalColumn || model instanceof ColumnGroup || model instanceof Word) {
        return model;
    }

    return null;
}
项目:TranskribusSwtGui    文件:StructureTreeWidget.java   
void initDragAndDrop() {
        int operations = DND.DROP_MOVE;
        Transfer[] transferTypes = new Transfer[]{ LocalSelectionTransfer.getTransfer() };

        treeViewer.addDragSupport(operations, transferTypes, new DragSourceAdapter() {          
            @Override public void dragStart(DragSourceEvent event) {
                LocalSelectionTransfer.getTransfer().setSelection(treeViewer.getSelection()); // not really needed since we can get selection from member variable
            }
//          @Override public void dragSetData(DragSourceEvent event) {
//          }
//          @Override public void dragFinished(DragSourceEvent event) {
//          }
        });

        treeViewer.addDropSupport(operations, transferTypes, new StructureTreeDropAdapter(treeViewer));
    }
项目:ermaster-k    文件:ERDiagramTransferDragSourceListener.java   
@Override
public void dragStart(DragSourceEvent dragsourceevent) {
    super.dragStart(dragsourceevent);

    Object target = this.getTargetModel(dragsourceevent);

    if (target != null
            && target == this.dragSourceViewer.findObjectAt(
                    new Point(dragsourceevent.x, dragsourceevent.y))
                    .getModel()) {
        TemplateTransfer transfer = (TemplateTransfer) this.getTransfer();
        transfer.setObject(this.createTransferData(dragsourceevent));

    } else {
        dragsourceevent.doit = false;
    }
}
项目:ermaster-k    文件:ERDiagramTransferDragSourceListener.java   
private Object getTargetModel(DragSourceEvent event) {
    List editParts = dragSourceViewer.getSelectedEditParts();
    if (editParts.size() != 1) {
        // ドラッグアンドドロップは選択されているオブジェクトが1つのときのみ可能とする
        return null;
    }

    EditPart editPart = (EditPart) editParts.get(0);

    Object model = editPart.getModel();
    if (model instanceof NormalColumn || model instanceof ColumnGroup
            || model instanceof Word) {
        return model;
    }

    return null;
}
项目:PDFReporter-Studio    文件:UnitDragSourceListener.java   
/**
 * Read the selected report unit and generate the data for the event,
 * serializing an array of string with some of the unit informations. The
 * serializing is done using the UnitTransfer class
 */
@Override
public void dragSetData(DragSourceEvent event) {
    IStructuredSelection selection = (IStructuredSelection) viewer
            .getSelection();
    List<String> unitInfo = new ArrayList<String>();
    if (selection.getFirstElement() instanceof MReportUnit) {
        MReportUnit unit = (MReportUnit) selection.getFirstElement();
        ResourceDescriptor unitDescrtiptor = unit.getValue();
        unitInfo.add(unitDescrtiptor.getUriString());
        List<INode> childrens = unit.getChildren();
        for (INode children : childrens) {
            if (children instanceof MInputControl) {
                ResourceDescriptor desc = (ResourceDescriptor) children
                        .getValue();
                unitInfo.add(desc.getName());
            }
        }
    }
    String[] gadgets = unitInfo.toArray(new String[unitInfo.size()]);
    if (UnitTransfer.getInstance().isSupportedType(event.dataType)) {
        event.data = gadgets;
    }
}
项目:PDFReporter-Studio    文件:NodeDragListener.java   
/**
 * Method declared on DragSourceListener
 */
public void dragFinished(DragSourceEvent event) {
    if (!event.doit)
        return;
    // if the gadget was moved, remove it from the source viewer
    if (event.detail == DND.DROP_MOVE) {
        IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
        for (Iterator<?> it = selection.iterator(); it.hasNext();) {
            Object obj = it.next();
            if (obj instanceof ANode) {
                ANode n = (ANode) obj;
                if (n.isCut())
                    ((ANode) obj).setParent(null, -1);
            }
        }
        viewer.refresh();
    }
}
项目:PDFReporter-Studio    文件:DataAdapterDragSourceListener.java   
@Override
public void dragSetData(DragSourceEvent event) {
    if(getTransfer().isSupportedType(event.dataType)){
        List<MDataAdapter> dataAdaptersSelected = getDragSelection(event);
        List<String> locations = new ArrayList<String>(dataAdaptersSelected.size());
        for(MDataAdapter da : dataAdaptersSelected){
            locations.add(createTemDataAdapterFile(da));
        }
        dataAdapterFilesLocations = locations.toArray(new String[locations.size()]);
        event.data = dataAdapterFilesLocations;
    }
    else {
        dataAdapterFilesLocations = new String[0];
        event.data = null;
    }
}
项目:PDFReporter-Studio    文件:DataAdapterDragSourceListener.java   
private List<MDataAdapter> getDragSelection(DragSourceEvent event){
    if(event.getSource() instanceof DragSource){
        List<MDataAdapter> dataAdapters = new ArrayList<MDataAdapter>();
        Control control = ((DragSource)event.getSource()).getControl();
        if(control instanceof Tree && 
                ((Tree) control).getSelection().length>0){
            for(TreeItem tItem : ((Tree) control).getSelection()){
                Object data = tItem.getData();
                if(data instanceof MDataAdapter){
                    dataAdapters.add((MDataAdapter) data);
                }
            }
            return dataAdapters;                
        }
    }
    return new ArrayList<MDataAdapter>(0);
}
项目:IDRT-Import-and-Mapping-Tool    文件:NodeMoveDragListener.java   
@Override
public void dragSetData(DragSourceEvent event) {


    System.out.println("dragSetData");
    IStructuredSelection selection = (IStructuredSelection) viewer
            .getSelection();
    if (selection.getFirstElement() instanceof OntologyTreeNode) {
        OntologyTreeNode firstElement = (OntologyTreeNode) selection
                .getFirstElement();
        if (firstElement.isModifier()){
            event.data = null;
            System.out.println("Modifier!");
        }
        else if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
            event.data = firstElement.getTreePath();
        }
    }
    else if (selection.getFirstElement() instanceof OntologyTreeSubNode) {
        setSubNode((OntologyTreeSubNode) selection
                .getFirstElement());
        event.data = "subNode";
    }
}
项目:IDRT-Import-and-Mapping-Tool    文件:NodeDragListener.java   
@Override
public void dragStart(DragSourceEvent event) {

    IStructuredSelection selection = (IStructuredSelection) viewer
            .getSelection();
    if (selection.getFirstElement() instanceof OntologyTreeNode) {
        OntologyTreeNode firstElement = (OntologyTreeNode) selection
                .getFirstElement();
        if (firstElement.isModifier()){
            System.out.println("MODIFIERS");
            event.doit=false;
        }
        else {
            Console.info("Start Drag");
            event.doit = true;
        }

    }

}
项目:Eclipse-Postfix-Code-Completion    文件:CallHierarchyViewPart.java   
private void addDragAdapters(StructuredViewer viewer) {
    int ops= DND.DROP_COPY | DND.DROP_LINK;

    Transfer[] transfers= new Transfer[] { LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance(), FileTransfer.getInstance()};

    DelegatingDragAdapter dragAdapter= new DelegatingDragAdapter() {
        @Override
        public void dragStart(DragSourceEvent event) {
            IStructuredSelection selection= (IStructuredSelection) fSelectionProviderMediator.getSelection();
            if (selection.isEmpty()) {
                event.doit= false;
                return;
            }
            super.dragStart(event);
        }
    };
    dragAdapter.addDragSourceListener(new SelectionTransferDragAdapter(fSelectionProviderMediator));
    dragAdapter.addDragSourceListener(new EditorInputTransferDragAdapter(fSelectionProviderMediator));
    dragAdapter.addDragSourceListener(new ResourceTransferDragAdapter(fSelectionProviderMediator));
    dragAdapter.addDragSourceListener(new FileTransferDragAdapter(fSelectionProviderMediator));

    viewer.addDragSupport(ops, transfers, dragAdapter);
}
项目:ermaster-nhit    文件:ERDiagramTransferDragSourceListener.java   
@Override
public void dragStart(DragSourceEvent dragsourceevent) {
    super.dragStart(dragsourceevent);

    Object target = this.getTargetModel(dragsourceevent);

    if (target != null
            && target == this.dragSourceViewer.findObjectAt(
                    new Point(dragsourceevent.x, dragsourceevent.y))
                    .getModel()) {
        TemplateTransfer transfer = (TemplateTransfer) this.getTransfer();
        transfer.setObject(this.createTransferData(dragsourceevent));

    } else {
        dragsourceevent.doit = false;
    }
}
项目:ermaster-nhit    文件:ERDiagramTransferDragSourceListener.java   
private Object getTargetModel(DragSourceEvent event) {
    List editParts = dragSourceViewer.getSelectedEditParts();
    if (editParts.size() != 1) {
        // ドラッグアンドドロップは選択されているオブジェクトが1つのときのみ可能とする
        return null;
    }

    EditPart editPart = (EditPart) editParts.get(0);

    Object model = editPart.getModel();
    if (model instanceof NormalColumn || model instanceof ColumnGroup
            || model instanceof Word) {
        return model;
    }

    return null;
}
项目:birt    文件:CubeGroupContent.java   
public void dragStart( DragSourceEvent event )
{
    TreeItem[] selection = viewer.getTree( ).getSelection( );

    if ( selection.length > 0 )
    {
        if ( viewer == dataFieldsViewer )
        {
            dragSourceItems[0] = selection[0];
        }
        else if ( viewer == groupViewer
                && selection[0].getData( ) != null
                && selection[0].getData( ) instanceof LevelHandle )
        {
            dragSourceItems[0] = selection[0];
        }
        else
            event.doit = false;
    }
    else
    {
        event.doit = false;
    }

}
项目:gef-gwt    文件:DelegatingDragAdapter.java   
/**
 * The drop has successfully completed. This event is forwarded to the current 
 * drag listener.
 * Doesn't update the current listener, since the current listener  is already the one
 * that completed the drag operation.
 * 
 * @param event the drag source event
 * @see DragSourceListener#dragFinished(DragSourceEvent)
 */
public void dragFinished(final DragSourceEvent event) {
    //      if (Policy.DEBUG_DRAG_DROP)
    //          System.out.println("Drag Finished: " + toString()); //$NON-NLS-1$
    SafeRunnable.run(new SafeRunnable() {
        public void run() throws Exception {
            if (currentListener != null) {
                // there is a listener that can handle the drop, delegate the event
                currentListener.dragFinished(event);
            } else {
                // The drag was canceled and currentListener was never set, so send the
                // dragFinished event to all the active listeners. 
                Iterator iterator = activeListeners.iterator();
                while (iterator.hasNext()) {
        ((TransferDragSourceListener) iterator.next())
                            .dragFinished(event);
    }
            }
        }
    });
    currentListener = null;
    activeListeners.clear();
}
项目:gef-gwt    文件:DelegatingDragAdapter.java   
/**
   * Updates the current listener to one that can handle the drag. There can 
   * be many listeners and each listener may be able to handle many <code>TransferData</code> 
   * types.  The first listener found that supports one of the <code>TransferData</ode> 
   * types specified in the <code>DragSourceEvent</code> will be selected.
   * 
   * @param event the drag source event
   */
  private void updateCurrentListener(DragSourceEvent event) {
      currentListener = null;
      if (event.dataType == null) {
    return;
}
      Iterator iterator = activeListeners.iterator();
      while (iterator.hasNext()) {
          TransferDragSourceListener listener = (TransferDragSourceListener) iterator
                  .next();

          if (listener.getTransfer().isSupportedType(event.dataType)) {
              //                if (Policy.DEBUG_DRAG_DROP)
              //                    System.out.println("Current drag listener: " + listener); //$NON-NLS-1$         
              currentListener = listener;
              return;
          }
      }
  }
项目:DynamicSpotter    文件:ExtensionDragListener.java   
@Override
public void dragFinished(DragSourceEvent event) {
    viewer.setData(VIEWER_IS_DRAG_SOURCE_PROPERTY, null);
    boolean isDropTarget = isThisViewerDropTarget();
    if (!event.doit || event.detail == DND.DROP_NONE) {
        return;
    }

    if (event.detail == DND.DROP_MOVE && !isDropTarget) {
        // remove the drag source from the model
        List<?> targetChildren = extensionDragSource.getParent().getModelWrapper().getChildren();
        List<?> sourceChildren = extensionDragSourceParent.getModelWrapper().getChildren();
        // delete extension from source children
        extensionDragSource.getModelWrapper().setXMLModelContainingList(sourceChildren);
        extensionDragSourceParent.removeItem(extensionDragSource, false);
        // set target children as new containing list
        extensionDragSource.getModelWrapper().setXMLModelContainingList(targetChildren);
        if (editor != null) {
            editor.markDirty();
        }
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CallHierarchyViewPart.java   
private void addDragAdapters(StructuredViewer viewer) {
    int ops= DND.DROP_COPY | DND.DROP_LINK;

    Transfer[] transfers= new Transfer[] { LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance(), FileTransfer.getInstance()};

    DelegatingDragAdapter dragAdapter= new DelegatingDragAdapter() {
        @Override
        public void dragStart(DragSourceEvent event) {
            IStructuredSelection selection= (IStructuredSelection) fSelectionProviderMediator.getSelection();
            if (selection.isEmpty()) {
                event.doit= false;
                return;
            }
            super.dragStart(event);
        }
    };
    dragAdapter.addDragSourceListener(new SelectionTransferDragAdapter(fSelectionProviderMediator));
    dragAdapter.addDragSourceListener(new EditorInputTransferDragAdapter(fSelectionProviderMediator));
    dragAdapter.addDragSourceListener(new ResourceTransferDragAdapter(fSelectionProviderMediator));
    dragAdapter.addDragSourceListener(new FileTransferDragAdapter(fSelectionProviderMediator));

    viewer.addDragSupport(ops, transfers, dragAdapter);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ResourceTransferDragAdapter.java   
private void handleFinishedDropMove(DragSourceEvent event) {
    MultiStatus status= new MultiStatus(
        JavaPlugin.getPluginId(),
        IJavaStatusConstants.INTERNAL_ERROR,
        JavaUIMessages.ResourceTransferDragAdapter_cannot_delete_resource,
        null);
    List<IResource> resources= convertSelection();
    for (Iterator<IResource> iter= resources.iterator(); iter.hasNext();) {
        IResource resource= iter.next();
        try {
            resource.delete(true, null);
        } catch (CoreException e) {
            status.add(e.getStatus());
        }
    }
    int childrenCount= status.getChildren().length;
    if (childrenCount > 0) {
        Shell parent= SWTUtil.getShell(event.widget);
        ErrorDialog error= new ErrorDialog(parent,
                JavaUIMessages.ResourceTransferDragAdapter_moving_resource,
                childrenCount == 1 ? JavaUIMessages.ResourceTransferDragAdapter_cannot_delete_files_singular : Messages.format(
                        JavaUIMessages.ResourceTransferDragAdapter_cannot_delete_files_plural, String.valueOf(childrenCount)), status, IStatus.ERROR);
        error.open();
    }
}
项目:birt    文件:ColumnNamesTableDragListener.java   
public void dragStart( DragSourceEvent event )
{
    if ( ChartReportItemHelper.instance( )
            .getBindingCubeHandle( itemHandle ) != null )
    {
        event.doit = false;
    }
    else
    {
        int index = table.getSelectionIndex( );
        if ( index < 0 )
        {
            item = null;
            event.doit = false;
        }
        else
        {
            item = table.getItem( index );
            String strColumnName = ( (ColumnBindingInfo) item.getData( ) ).getName( );
            event.doit = ( strColumnName != null && strColumnName.length( ) > 0 );
        }
    }

}
项目:neoscada    文件:CommonDragAdapterAssistant.java   
@Override
public boolean setDragData ( final DragSourceEvent event, final IStructuredSelection selection )
{
    logger.debug ( "setDragData ( event: {}, selection: {}", event, selection );

    final Collection<Item> items = ItemSelectionHelper.getSelection ( selection );
    if ( items.isEmpty () )
    {
        logger.info ( "Empty item set for setDragData" );
        return false;
    }

    if ( ItemTransfer.getInstance ().isSupportedType ( event.dataType ) )
    {
        event.data = items.toArray ( new Item[items.size ()] );
        return true;
    }
    else if ( TextTransfer.getInstance ().isSupportedType ( event.dataType ) )
    {
        event.data = getItemUriData ( items );
        return true;
    }
    else if ( URLTransfer.getInstance ().isSupportedType ( event.dataType ) )
    {
        event.data = getItemUriData ( items );
        return true;
    }

    logger.debug ( "No possible transfer" );

    return false;
}
项目:neoscada    文件:RealtimeListDragSourceListener.java   
@Override
public void dragSetData ( final DragSourceEvent event )
{
    try
    {
        final IStructuredSelection selection = (IStructuredSelection)LocalSelectionTransfer.getTransfer ().getSelection ();
        if ( ItemTransfer.getInstance ().isSupportedType ( event.dataType ) )
        {
            final List<Item> items = new ArrayList<Item> ();
            for ( final Iterator<?> i = selection.iterator (); i.hasNext (); )
            {
                final ListEntry entry = (ListEntry)i.next ();
                items.add ( entry.getItem () );
            }
            event.data = items.toArray ( new Item[items.size ()] );
        }
        else if ( TextTransfer.getInstance ().isSupportedType ( event.dataType ) )
        {
            setItemUriData ( event, selection );
        }
        else if ( URLTransfer.getInstance ().isSupportedType ( event.dataType ) )
        {
            setItemUriData ( event, selection );
        }
    }
    catch ( final Exception e )
    {
        event.doit = false;
    }
}
项目:neoscada    文件:RealtimeListDragSourceListener.java   
protected void setItemUriData ( final DragSourceEvent event, final IStructuredSelection selection )
{
    final StringBuilder sb = new StringBuilder ();
    int cnt = 0;
    for ( final Iterator<?> i = selection.iterator (); i.hasNext (); )
    {
        final ListEntry entry = (ListEntry)i.next ();

        if ( cnt > 0 )
        {
            sb.append ( "\n" ); //$NON-NLS-1$
        }

        final Item item = entry.getItem ();

        if ( item.getType () != Type.URI )
        {
            throw new IllegalStateException ( Messages.RealtimeListDragSourceListener_TypeError );
        }

        sb.append ( item.getConnectionString () );
        sb.append ( "#" ); //$NON-NLS-1$
        try
        {
            sb.append ( URLEncoder.encode ( item.getId (), "UTF-8" ) );
        }
        catch ( final UnsupportedEncodingException e )
        {
            sb.append ( item.getId () );
        }

        cnt++;
    }
    event.data = sb.toString ();
}
项目:neoscada    文件:RealtimeListDragSourceListener.java   
@Override
public void dragStart ( final DragSourceEvent event )
{
    event.doit = false;

    if ( ! ( this.viewer.getSelection () instanceof IStructuredSelection ) )
    {
        return;
    }

    final IStructuredSelection selection = (IStructuredSelection)this.viewer.getSelection ();
    if ( selection.isEmpty () )
    {
        return;
    }

    for ( final Iterator<?> i = selection.iterator (); i.hasNext (); )
    {
        final Object o = i.next ();
        if ( ! ( o instanceof ListEntry ) )
        {
            return;
        }
    }

    LocalSelectionTransfer.getTransfer ().setSelection ( this.viewer.getSelection () );

    event.doit = true;
}
项目:neoscada    文件:CommonDragAdapterAssistant.java   
@Override
public boolean setDragData ( final DragSourceEvent event, final IStructuredSelection selection )
{
    logger.debug ( "setDragData ( event: {}, selection: {}", event, selection );

    final Collection<Item> items = ItemSelectionHelper.getSelection ( selection );
    if ( items.isEmpty () )
    {
        logger.info ( "Empty item set for setDragData" );
        return false;
    }

    if ( ItemTransfer.getInstance ().isSupportedType ( event.dataType ) )
    {
        event.data = items.toArray ( new Item[items.size ()] );
        return true;
    }
    else if ( TextTransfer.getInstance ().isSupportedType ( event.dataType ) )
    {
        event.data = getItemUriData ( items );
        return true;
    }
    else if ( URLTransfer.getInstance ().isSupportedType ( event.dataType ) )
    {
        event.data = getItemUriData ( items );
        return true;
    }

    logger.debug ( "No possible transfer" );

    return false;
}
项目:Hydrograph    文件:FunctionsComposite.java   
private void addDragSupport() {
    ExpressionEditorUtil.INSTANCE.getDragSource(methodList).addDragListener(new DragSourceAdapter() {
        public void dragSetData(DragSourceEvent event) {
            if (methodList.getItemCount() != 0
                    && !StringUtils.startsWith(methodList.getItem(0),Messages.CANNOT_SEARCH_INPUT_STRING)) {
            MethodDetails methodDetails = (MethodDetails) methodList.getData(String.valueOf(methodList
                    .getSelectionIndex()));
            event.data = methodDetails.getPlaceHolder();
        }else
            event.data=StringUtils.EMPTY+"#"+StringUtils.EMPTY;
        }
    });
}