Java 类org.openide.util.datatransfer.ExTransferable 实例源码

项目:incubator-netbeans    文件:PackageViewChildren.java   
@Override
public Transferable paste() throws IOException {
    if (SwingUtilities.isEventDispatchThread()) {
        PackageRootNode.PKG_VIEW_RP.post(new java.lang.Runnable() {
            @Override
            public void run() {
                final ProgressHandle h = ProgressHandleFactory.createHandle(getName());
                h.start();
                h.switchToIndeterminate();
                try {
                    doPaste();
                } catch (java.io.IOException ioe) {
                    Exceptions.printStackTrace(ioe);
                } finally {
                    h.finish();
                }
            }
        });
    } else {
        doPaste();
    }
    return ExTransferable.EMPTY;
}
项目:incubator-netbeans    文件:NbClipboardNativeTest.java   
public void testClipboard() throws Exception {
    MockServices.setServices(Cnv.class);
    Clipboard c = Lookup.getDefault().lookup(Clipboard.class);
    ExClipboard ec = Lookup.getDefault().lookup(ExClipboard.class);
    assertEquals("Clipboard == ExClipboard", c, ec);
    assertNotNull(Lookup.getDefault().lookup(ExClipboard.Convertor.class));
    assertEquals(Cnv.class, Lookup.getDefault().lookup(ExClipboard.Convertor.class).getClass());
    c.setContents(new ExTransferable.Single(DataFlavor.stringFlavor) {
        protected Object getData() throws IOException, UnsupportedFlavorException {
            return "17";
        }
    }, null);
    Transferable t = c.getContents(null);
    assertTrue("still supports stringFlavor", t.isDataFlavorSupported(DataFlavor.stringFlavor));
    assertEquals("correct string in clipboard", "17", t.getTransferData(DataFlavor.stringFlavor));
    assertTrue("support Integer too", t.isDataFlavorSupported(MYFLAV));
    assertEquals("correct Integer", new Integer(17), t.getTransferData(MYFLAV));
}
项目:incubator-netbeans    文件:NbClipboardNativeTest.java   
public Transferable convert(Transferable t) {
    Logger.getAnonymousLogger().info("converting...");
    if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        final ExTransferable t2 = ExTransferable.create(t);
        if (t2.isDataFlavorSupported(DataFlavor.stringFlavor) && !t2.isDataFlavorSupported(MYFLAV)) {
            t2.put(new ExTransferable.Single(MYFLAV) {
                protected Object getData() throws IOException, UnsupportedFlavorException {
                    String s = (String)t2.getTransferData(DataFlavor.stringFlavor);
                    try {
                        return new Integer(s);
                    } catch (NumberFormatException nfe) {
                        throw new IOException(nfe.toString());
                    }
                }
            });
        }
        return t2;
    } else {
        return t;
    }
}
项目:incubator-netbeans    文件:NbClipboardNativeTest.java   
public void testOwnershipLostEvent() throws Exception {
    final int[] holder = new int[] { 0 };
    ExTransferable transferable = ExTransferable.create (new StringSelection("A"));

    // listen on ownershipLost
    transferable.addTransferListener (new TransferListener () {
        public void accepted (int action) {}
        public void rejected () {}
        public void ownershipLost () { holder[0]++; }
    });

    Clipboard c = Lookup.getDefault().lookup(Clipboard.class);

    c.setContents(transferable, null);

    assertTrue("Still has ownership", holder[0] == 0);

    c.setContents(new StringSelection("B"), null);

    assertTrue("Exactly one ownershipLost event have happened.", holder[0] == 1);
}
项目:incubator-netbeans    文件:VersionNode.java   
@Override
public Transferable clipboardCopy() throws IOException {
    Transferable deflt = super.clipboardCopy();
    ExTransferable enriched = ExTransferable.create(deflt);
    ExTransferable.Single ex = new ExTransferable.Single(DataFlavor.stringFlavor) {
        @Override
        protected Object getData() {
            return "<dependency>\n" + //NOI18N
                    "  <groupId>" + record.getGroupId() + "</groupId>\n" + //NOI18N
                    "  <artifactId>" + record.getArtifactId() + "</artifactId>\n" + //NOI18N
                    "  <version>" + record.getVersion() + "</version>\n" + //NOI18N
                    "</dependency>"; //NOI18N
        }
    };
    enriched.put(ex);
    return enriched;
}
项目:incubator-netbeans    文件:RestClientFlavorProvider.java   
public Transferable addDataFlavors(Transferable transferable) {
    try {
        if (transferable.isDataFlavorSupported(ConsumerFlavorProvider.WADL_METHOD_FLAVOR)) {
            Object data = transferable.getTransferData(ConsumerFlavorProvider.WADL_METHOD_FLAVOR);
            if (data instanceof WadlSaasMethod) {
                WadlSaasMethod method = (WadlSaasMethod) data;
                ExTransferable t = ExTransferable.create(transferable);
                RestClientEditorDrop editorDrop = new RestClientEditorDrop(method);
                ActiveEditorDropTransferable s = new ActiveEditorDropTransferable(editorDrop);
                t.put(s);
                return t;
            }
        }
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }

    return transferable;
}
项目:incubator-netbeans    文件:CustomClientFlavorProvider.java   
public Transferable addDataFlavors(Transferable transferable) {
    try {
        if (transferable.isDataFlavorSupported(ConsumerFlavorProvider.CUSTOM_METHOD_FLAVOR)) {
            Object data = transferable.getTransferData(ConsumerFlavorProvider.CUSTOM_METHOD_FLAVOR);
            if (data instanceof CustomSaasMethod) {
                CustomSaasMethod method = (CustomSaasMethod) data;
                ExTransferable t = ExTransferable.create(transferable);
                CustomClientEditorDrop editorDrop = new CustomClientEditorDrop(method);
                ActiveEditorDropTransferable s = new ActiveEditorDropTransferable(editorDrop);
                t.put(s);
                return t;
            }
        }
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }

    return transferable;
}
项目:incubator-netbeans    文件:CopySupport.java   
@Override
public Transferable paste() throws IOException {
    if (java.awt.EventQueue.isDispatchThread())
        return doPaste();
    else { // reinvoke synchronously in AWT thread
        try {
            return Mutex.EVENT.readAccess(this);
        }
        catch (MutexException ex) {
            Exception e = ex.getException();
            if (e instanceof IOException)
                throw (IOException) e;
            else { // should not happen, ignore
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
                return ExTransferable.EMPTY;
            }
        }
    }
}
项目:incubator-netbeans    文件:ExplorerActionsImpl.java   
/**
 * Get a transferable of a selection of node(s).
 * @param sel An array with selected nodes.
 * @param copyCut <code>true</code> for copy, <code>false</code> for cut.
 * @return The transferable or <code>null</code>
 */
public static Transferable getTransferableOwner(Node[] sel, boolean copyCut) {
    Transferable trans;
    if (sel.length != 1) {
        Transferable[] arrayTrans = new Transferable[sel.length];

        for (int i = 0; i < sel.length; i++) {
            if ((arrayTrans[i] = getTransferableOwner(sel[i], copyCut)) == null) {
                return null;
            }
        }

        trans = ExternalDragAndDrop.maybeAddExternalFileDnd( new ExTransferable.Multi(arrayTrans) );
    } else {
        trans = getTransferableOwner(sel[0], copyCut);
    }

    return trans;
}
项目:incubator-netbeans    文件:ExplorerActionsImpl.java   
/** Performs the paste action.
* @return Transferable which should be inserted into the clipboard after
*         paste action. It can be null, which means that clipboard content
*         should be cleared.
*/
@Override
public Transferable paste() throws IOException {
    int size = p.length;
    Transferable[] arr = new Transferable[size];

    for (int i = 0; i < size; i++) {
        Transferable newTransferable = p[i].paste();

        if (newTransferable != null) {
            arr[i] = newTransferable;
        } else {
            // keep the orginal
            arr[i] = t[i];
        }
    }

    return new ExTransferable.Multi(arr);
}
项目:incubator-netbeans    文件:DragDropUtilitiesTest.java   
public void testMultiTransferableForCopy() throws Exception {
    N node = new N();
    N n2 = new N();
    N[] arr = { node, n2 };

    Transferable t = DragDropUtilities.getNodeTransferable(arr, NodeTransfer.DND_COPY);

    assertEquals("One call to copy", 1, node.copy);
    assertEquals("One call to copy on n2", 1, n2.copy);
    assertEquals("Also one call to drag which delegates to copy", 1, node.drag);
    assertEquals("Also one call to drag which delegates to copy on n2", 1, n2.drag);
    assertEquals("No call to cut", 0, node.cut);
    assertEquals("No call to cut", 0, n2.cut);

    assertNotNull("Call to convertor", last);
    assertTrue("multi flavor supported", last.isDataFlavorSupported(ExTransferable.multiFlavor));
    Object obj = last.getTransferData(ExTransferable.multiFlavor);
    if (!( obj instanceof MultiTransferObject)) {
        fail("It should be MultiTransferObject: " + obj);
    }
    MultiTransferObject m = (MultiTransferObject)obj;

    assertEquals("Two in multi", 2, m.getCount());
    assertTrue("Is string", m.getTransferData(0, DataFlavor.stringFlavor) instanceof String);
    assertTrue("Is string2", m.getTransferData(1, DataFlavor.stringFlavor) instanceof String);
}
项目:incubator-netbeans    文件:DragDropUtilitiesTest.java   
public void testMultiTransferableForCut() throws Exception {
    N node = new N();
    N n2 = new N();
    N[] arr = { node, n2 };

    Transferable t = DragDropUtilities.getNodeTransferable(arr, NodeTransfer.DND_MOVE);

    assertEquals("One call to cut ", 1, node.cut);
    assertEquals("One call to cut on n2", 1, n2.cut);
    assertEquals("No to drag", 0, node.drag);
    assertEquals("No to drag on n2", 0, n2.drag);
    assertEquals("No call to copy", 0, node.copy);
    assertEquals("No call to copy on n2", 0, n2.copy);

    assertNotNull("Call to convertor", last);
    assertTrue("multi flavor supported", last.isDataFlavorSupported(ExTransferable.multiFlavor));
    Object obj = last.getTransferData(ExTransferable.multiFlavor);
    if (!( obj instanceof MultiTransferObject)) {
        fail("It should be MultiTransferObject: " + obj);
    }
    MultiTransferObject m = (MultiTransferObject)obj;

    assertEquals("Two in multi", 2, m.getCount());
    assertTrue("Is string", m.getTransferData(0, DataFlavor.stringFlavor) instanceof String);
    assertTrue("Is string2", m.getTransferData(1, DataFlavor.stringFlavor) instanceof String);
}
项目:incubator-netbeans    文件:DragAndDropHandlerTest.java   
public void testCustomize() throws Exception {
    PaletteActions actions = new DummyActions();
    PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), actions );
    Model model = pc.getModel();

    Item item = model.getCategories()[0].getItems()[0];

    DragAndDropHandler handler = DragAndDropHandler.getDefault();

    ExTransferable t = ExTransferable.create( item.cut() );
    DataFlavor[] flavorsBefore = t.getTransferDataFlavors();

    handler.customize( t, item.getLookup() );

    DataFlavor[] flavorsAfter = t.getTransferDataFlavors();
    assertEquals( "Default implementation does nothing", flavorsBefore.length, flavorsAfter.length );
    for( int i=0; i<flavorsBefore.length; i++ ) {
        assertEquals( "Default implementation does nothing", flavorsBefore[i], flavorsAfter[i] );
    }
}
项目:incubator-netbeans    文件:DataNode.java   
private void addExternalFileTransferable( ExTransferable t, DataObject d ) {
    FileObject fo = d.getPrimaryFile();
    File file = FileUtil.toFile( fo );
    if( null != file ) {
        //windows & mac
        final ArrayList<File> list = new ArrayList<File>(1);
        list.add( file );
        t.put( new ExTransferable.Single( DataFlavor.javaFileListFlavor ) {
            public Object getData() {
                return list;
            }
        });
        //linux
        final String uriList = Utilities.toURI(file).toString() + "\r\n";
        t.put( new ExTransferable.Single( createUriListFlavor() ) {
            public Object getData() {
                return uriList;
            }
        });
    }
}
项目:Pogamut3    文件:ExplorerFactory.java   
@Override
public Transferable createNewTransferable() {
    return new ExTransferable.Single(Competence.dataFlavor) {

        @Override
        protected Object getData() throws IOException, UnsupportedFlavorException {
            String competenceName = PGSupport.getIdentifierFromDialog("Name of competence");
            if (competenceName == null) {
                return null;
            }

            String elementName = PGSupport.getIdentifierFromDialog("Name of competence atom");
            if (elementName == null) {
                return null;
            }
            try {
                return LapElementsFactory.createCompetence(competenceName, elementName);
            } catch (DuplicateNameException ex) {
                throw new FubarException("Creating new competence with only one name, what duplicate?", ex);
            }
        }
    };
}
项目:Pogamut3    文件:Explorers.java   
@Override
protected Transferable createNewItemTransferable() {
    return new ExTransferable.Single(ActionPattern.dataFlavor) {

        @Override
        protected Object getData() throws IOException, UnsupportedFlavorException {
            String apName = PGSupport.getIdentifierFromDialog("Name of new AP");
            if (apName == null) {
                return null;
            }

            ActionPattern ap = new ActionPattern(apName);

            // XXX: Ugly hack, remove after 3.3.1. Former constructor has inserted wrong default action
            List<PoshElement> initialChildren = new LinkedList<PoshElement>();
            if (!ap.getChildDataNodes().isEmpty()) {
                initialChildren.addAll(ap.getChildDataNodes());
            }
            ap.addTriggeredAction(new TriggeredAction(SimpleRoleActionWidget.DEFAULT_ACTION));
            for (PoshElement initialChild : initialChildren) {
                ap.neutralizeChild(initialChild);
            }
            return ap;
        }
    };
}
项目:incubator-netbeans    文件:WsdlPortNode.java   
private WsdlPortNode(WsdlSaasPort port, InstanceContent content) {
    super(new WsdlPortNodeChildren(port), new AbstractLookup(content));
    this.port = port;
    content.add(port);
    transferable = ExTransferable.create(
            new SaasTransferable(port,SaasTransferable.WSDL_PORT_FLAVORS));
}
项目:incubator-netbeans    文件:WadlMethodNode.java   
public WadlMethodNode(WadlSaasMethod method, InstanceContent content) {
    super(Children.LEAF, new AbstractLookup(content));
    this.method = method;
    content.add(method);
    transferable = ExTransferable.create(
        new SaasTransferable<WadlSaasMethod>(method, SaasTransferable.WADL_METHOD_FLAVORS));
}
项目:incubator-netbeans    文件:CustomMethodNode.java   
public CustomMethodNode(CustomSaasMethod method, InstanceContent content) {
    super(Children.LEAF, new AbstractLookup(content));
    this.method = method;
    content.add(method);
    transferable = ExTransferable.create(
        new SaasTransferable<SaasMethod>(method, SaasTransferable.CUSTOM_METHOD_FLAVORS));
}
项目:incubator-netbeans    文件:WsdlMethodNode.java   
protected WsdlMethodNode(WsdlSaasMethod method, InstanceContent content) {
    super(Children.LEAF, new AbstractLookup(content));
    this.method = method;
    content.add(method);
    transferable = ExTransferable.create(
            new SaasTransferable<WsdlSaasMethod>(method, SaasTransferable.WSDL_METHOD_FLAVORS));
}
项目:incubator-netbeans    文件:PaletteItemNode.java   
@Override
public Transferable clipboardCopy() throws IOException {

    ExTransferable t = ExTransferable.create( super.clipboardCopy() );

    Lookup lookup = getLookup();
    ActiveEditorDrop drop = (ActiveEditorDrop) lookup.lookup(ActiveEditorDrop.class);
    ActiveEditorDropTransferable s = new ActiveEditorDropTransferable(drop);
    t.put(s);

    //do not allow external DnD flavors otherwise some items may get interpreted
    //as an external file dropped into the editor window
    return new NoExternalDndTransferable( t );
}
项目:incubator-netbeans    文件:ItemNode.java   
public Transferable clipboardCut() throws java.io.IOException {
    ExTransferable t = ExTransferable.create( super.clipboardCut() );

    customizeTransferable( t );
    t.put( createTransferable() );

    return t;
}
项目:incubator-netbeans    文件:ItemNode.java   
public Transferable clipboardCopy() throws IOException {
    ExTransferable t = ExTransferable.create( super.clipboardCopy() );

    customizeTransferable( t );
    t.put( createTransferable() );

    return t;
}
项目:incubator-netbeans    文件:ItemNode.java   
public Transferable drag() throws IOException {
    ExTransferable t = ExTransferable.create( super.drag() );//NodeTransfer.transferable(this, NodeTransfer.DND_MOVE) );

    customizeTransferable( t );
    t.put( createTransferable() );

    return t;
}
项目:incubator-netbeans    文件:ItemNode.java   
private ExTransferable.Single createTransferable() {
    final Lookup lkp = getLookup();
    return new ExTransferable.Single( PaletteController.ITEM_DATA_FLAVOR ) {
       public Object getData () {
           return lkp;
       }
   };
}
项目:incubator-netbeans    文件:CategoryTest.java   
private Transferable createTransferable( final Item item ) {
    return new ExTransferable.Single( PaletteController.ITEM_DATA_FLAVOR ) {
        protected Object getData() throws IOException, UnsupportedFlavorException {
            return item.getLookup();
        }
    };
}
项目:incubator-netbeans    文件:DataShadow.java   
/** Copy this node to the clipboard.
*
* @return {@link org.openide.util.datatransfer.ExTransferable.Single} with one copy flavor
* @throws IOException if it could not copy
* @see NodeTransfer
*/
public Transferable clipboardCopy () throws IOException {
    ExTransferable t = ExTransferable.create (super.clipboardCopy ());
    t.put (LoaderTransfer.transferable (
        obj, 
        LoaderTransfer.CLIPBOARD_COPY)
    );
    return t;
}
项目:incubator-netbeans    文件:DataShadow.java   
/** Cut this node to the clipboard.
*
* @return {@link org.openide.util.datatransfer.ExTransferable.Single} with one cut flavor
* @throws IOException if it could not cut
* @see NodeTransfer
*/
public Transferable clipboardCut () throws IOException {
    ExTransferable t = ExTransferable.create (super.clipboardCut ());
    t.put (LoaderTransfer.transferable (
        obj, 
        LoaderTransfer.CLIPBOARD_CUT)
    );
    return t;
}
项目:incubator-netbeans    文件:DataNode.java   
/** Copy this node to the clipboard.
*
* @return {@link org.openide.util.datatransfer.ExTransferable.Single} with one copy flavor
* @throws IOException if it could not copy
* @see org.openide.nodes.NodeTransfer
*/
@Override
public Transferable clipboardCopy () throws IOException {
    ExTransferable t = ExTransferable.create (super.clipboardCopy ());
    t.put (LoaderTransfer.transferable (
        getDataObject (), 
        LoaderTransfer.CLIPBOARD_COPY)
    );
    //add extra data flavors to allow dragging the file outside the IDE window
    addExternalFileTransferable( t, getDataObject() );
    return t;
}
项目:incubator-netbeans    文件:DataNode.java   
/** Cut this node to the clipboard.
*
* @return {@link org.openide.util.datatransfer.ExTransferable.Single} with one cut flavor
* @throws IOException if it could not cut
* @see org.openide.nodes.NodeTransfer
*/
@Override
public Transferable clipboardCut () throws IOException {
    ExTransferable t = ExTransferable.create (super.clipboardCut ());
    t.put (LoaderTransfer.transferable (
        getDataObject (), 
        LoaderTransfer.CLIPBOARD_CUT)
    );
    //add extra data flavors to allow dragging the file outside the IDE window
    addExternalFileTransferable( t, getDataObject() );
    return t;
}
项目:incubator-netbeans    文件:ConfigureToolbarPanel.java   
@Override
public Transferable drag() throws IOException {
    return new ExTransferable.Single( nodeDataFlavor ) {
        public Object getData() {
           return ItemActionNode.this;
        }
    };
}
项目:incubator-netbeans    文件:TableNode.java   
@Override
public Transferable clipboardCopy() throws IOException {
    ExTransferable result = ExTransferable.create(super.clipboardCopy());
    result.put(new ExTransferable.Single(DatabaseMetaDataTransfer.TABLE_FLAVOR) {
        @Override
        protected Object getData() {
            return DatabaseMetaDataTransferAccessor.DEFAULT.createTableData(connection.getDatabaseConnection(),
                    connection.findJDBCDriver(), getName());
        }
    });
    return result;
}
项目:incubator-netbeans    文件:ViewNode.java   
@Override
public Transferable clipboardCopy() throws IOException {
    ExTransferable result = ExTransferable.create(super.clipboardCopy());
    result.put(new ExTransferable.Single(DatabaseMetaDataTransfer.VIEW_FLAVOR) {
        protected Object getData() {
            return DatabaseMetaDataTransferAccessor.DEFAULT.createViewData(connection.getDatabaseConnection(),
                    connection.findJDBCDriver(), getName());
        }
    });
    return result;
}
项目:incubator-netbeans    文件:ColumnNode.java   
@Override
public Transferable clipboardCopy() throws IOException {
    ExTransferable result = ExTransferable.create(super.clipboardCopy());
    result.put(new ExTransferable.Single(DatabaseMetaDataTransfer.COLUMN_FLAVOR) {

        @Override
        protected Object getData() {
            return DatabaseMetaDataTransferAccessor.DEFAULT.createColumnData(connection.getDatabaseConnection(),
                    connection.findJDBCDriver(), getParentName(), getName());
        }
    });
    return result;
}
项目:incubator-netbeans    文件:ConnectionNode.java   
@Override
public Transferable clipboardCopy() throws IOException {
    ExTransferable result = ExTransferable.create(super.clipboardCopy());
    result.put(new ExTransferable.Single(DatabaseMetaDataTransfer.CONNECTION_FLAVOR) {
        @Override
        protected Object getData() {
            return DatabaseMetaDataTransferAccessor.DEFAULT.createConnectionData(connection.getDatabaseConnection(),
                    connection.findJDBCDriver());
        }
    });
    return result;
}
项目:incubator-netbeans    文件:BaseNode.java   
@Override
public Transferable clipboardCopy() throws IOException {
    Transferable deflt = super.clipboardCopy();
    ExTransferable added = ExTransferable.create(deflt);
    added.put(new ExTransferable.Single(DataFlavor.stringFlavor) {
        @Override
        protected Object getData() {
            return getDisplayName();
        }
    });
    return added;
}
项目:incubator-netbeans    文件:NodeTransfer.java   
/** Creates transferable that represents a node operation, such as cut-to-clipboard.
* The transferable will be recognizable by {@link #node}, {@link #nodes}, and {@link #cookie}.
*
* @param n the node to create a transferable for
* @param actions the action performed on the node
* @return the transferable
*/
public static ExTransferable.Single transferable(final Node n, int actions) {
    return new ExTransferable.Single(createDndFlavor(actions)) {
            public Object getData() {
                return n;
            }
        };
}
项目:incubator-netbeans    文件:NodeTransfer.java   
/** Creates transfer object that is used to carry an intelligent
* paste source through transferable or clipboard.
* {@link #findPaste} can retrieve it.
* @param paste the intelligent source of paste types
* @return the transferable
*/
public static ExTransferable.Single createPaste(final Paste paste) {
    return new ExTransferable.Single(nodePasteFlavor) {
            public Object getData() {
                return paste;
            }
        };
}
项目:incubator-netbeans    文件:DBElementNode.java   
public Transferable clipboardCut () throws IOException {
    if (!writeable)
        throw new IOException();

    ExTransferable ex = ExTransferable.create(super.clipboardCut());
    ex.put(new ElementStringTransferable());

    return ex;
}
项目:Pogamut3    文件:ExplorerFactory.java   
@Override
public Transferable createNewTransferable() {
    return new ExTransferable.Single(ActionPattern.dataFlavor) {

        @Override
        protected Object getData() throws IOException, UnsupportedFlavorException {
            String name = PGSupport.getIdentifierFromDialog("Name of new action pattern.");
            if (name == null) {
                return null;
            }

            return LapElementsFactory.createActionPattern(name);
        }
    };
}