@Override public PasteType getDropType(Transferable t, int action, int index) { // #139713: drop into empty area creates new link, otherwise disabled if (index != -1) return null; // any kind of drop just creates link in Favorites DataObject[] dos = LoaderTransfer.getDataObjects(t, LoaderTransfer.DND_COPY_OR_MOVE | LoaderTransfer.CLIPBOARD_CUT); if (dos == null) { List<File> files = getDraggedFilesList(t); if (!files.isEmpty()) { return new FavoritesExternalPasteType(files); } return null; } for (DataObject dataObject : dos) { if (! Actions.Add.isAllowed(dataObject)) return null; } return new FavoritesPasteType(dos); }
@Override public void actionPerformed(ActionEvent e) { PasteType[] arr; synchronized (this) { arr = this.pasteTypes; } if (arr != null && arr.length > 0) { try { arr[0].paste(); return; } catch (IOException ex) { Exceptions.printStackTrace(ex); } } Utilities.disabledActionBeep(); }
public void actionPerformed(ActionEvent event) { PasteType type = getPasteType(); if (type != null) { try { Transferable trans = type.paste(); if (trans != null) { ClipboardOwner owner = trans instanceof ClipboardOwner ? (ClipboardOwner)trans : new StringSelection(""); // NOI18N Clipboard clipboard = (Clipboard)Lookup.getDefault().lookup(ExClipboard.class); clipboard.setContents(trans, owner); } } catch (java.io.IOException e) { ERR.log( Level.INFO, e.getLocalizedMessage(), e ); } } }
public static PasteType getPaste(Lookup look) { ExplorerContext drop = look.lookup(ExplorerContext.class); if (drop==null) { return null; } Transferable orig = drop.getTransferable(); if (orig==null) { return null; } Node n = drop.getTargetNode(); if (n==null) { return null; } PasteType[] pt = n.getPasteTypes(orig); if (pt.length==1) { return null; } return pt[1]; }
public void performActionAt(int index, ActionEvent ev) { Action[] action = new Action[1]; Object[] arr = getPasteTypesOrActions(action); if (arr.length <= index) { return; } if (arr[index] instanceof PasteType) { PasteType t = (PasteType) arr[index]; // posts the action is RP thread new ActionPT(t, (ev == null) ? null : ev.getActionCommand()); return; } else { // is action Action a = (Action) arr[index]; a.actionPerformed(new ActionEvent(a, ActionEvent.ACTION_PERFORMED, a.NAME)); return; } }
public void testJavaFileListPasteTypes() throws ClassNotFoundException, IOException { FileObject testFO = FileUtil.createData( testFileSystem.getRoot(), "testFile.txt" ); File testFile = FileUtil.toFile( testFO ); ArrayList fileList = new ArrayList(1); fileList.add( testFile ); Transferable t = new MockTransferable( new DataFlavor[] {DataFlavor.javaFileListFlavor}, fileList ); DataFolder.FolderNode node = (DataFolder.FolderNode)folderNode; ArrayList list = new ArrayList(); node.createPasteTypes( t, list ); assertFalse( list.isEmpty() ); PasteType paste = (PasteType)list.get( 0 ); paste.paste(); FileObject[] children = testFileSystem.getRoot().getFileObject( "testDir" ).getChildren(); assertEquals( 1, children.length ); assertEquals( children[0].getNameExt(), "testFile.txt" ); }
public void testUriFileListPasteTypes() throws ClassNotFoundException, IOException { DataFlavor flavor = new DataFlavor( "unsupported/flavor;class=java.lang.Object" ); FileObject testFO = FileUtil.createData( testFileSystem.getRoot(), "testFile.txt" ); File testFile = FileUtil.toFile( testFO ); String uriList = Utilities.toURI(testFile) + "\r\n"; Transferable t = new MockTransferable( new DataFlavor[] {new DataFlavor("text/uri-list;class=java.lang.String")}, uriList ); DataFolder.FolderNode node = (DataFolder.FolderNode)folderNode; ArrayList list = new ArrayList(); node.createPasteTypes( t, list ); assertFalse( list.isEmpty() ); PasteType paste = (PasteType)list.get( 0 ); paste.paste(); FileObject[] children = testFileSystem.getRoot().getFileObject( "testDir" ).getChildren(); assertEquals( 1, children.length ); assertEquals( children[0].getNameExt(), "testFile.txt" ); }
/** * Test for bug 233673. * * @throws java.io.IOException */ public void testJavaFileListWithRelativePaths() throws IOException { FileObject testFO = FileUtil.createData(testFileSystem.getRoot(), "absoluteTestFile.txt"); File absoluteTestFile = FileUtil.toFile(testFO); File relativeTestFile = new File("relativeFile.txt"); ArrayList fileList = new ArrayList(2); fileList.add(relativeTestFile); fileList.add(absoluteTestFile); Transferable t = new MockTransferable( new DataFlavor[]{DataFlavor.javaFileListFlavor}, fileList); DataFolder.FolderNode node = (DataFolder.FolderNode) folderNode; ArrayList<PasteType> list = new ArrayList<PasteType>(); node.createPasteTypes(t, list); assertEquals("Relative path should be skipped", 1, list.size()); PasteType paste = (PasteType) list.get(0); paste.paste(); FileObject[] children = testFileSystem.getRoot().getFileObject( "testDir").getChildren(); assertEquals(1, children.length); assertEquals(children[0].getNameExt(), "absoluteTestFile.txt"); }
/** * */ static PasteType getPasteType(final DataFolder targetFolder, final Transferable transfer) { final FileObject folder = targetFolder.getPrimaryFile(); PasteType retVal = null; try { /*Copy/Cut/Paste is allowed just on SystemFileSystem*/ if (folder.getFileSystem().isDefault()) { final int[] pasteOperations = new int[]{LoaderTransfer.CLIPBOARD_COPY, LoaderTransfer.CLIPBOARD_CUT}; for (int i = 0; i < pasteOperations.length; i++) { final DataObject[] dataObjects = LoaderTransfer.getDataObjects(transfer, pasteOperations[i]); if (dataObjects != null) { if (canBePasted(dataObjects, targetFolder, pasteOperations[i])) { retVal = new PasteTypeImpl(Arrays.asList(dataObjects), targetFolder, pasteOperations[i]); break; } } } } } catch (FileStateInvalidException e) {/*just null is returned if folder.getFileSystem fires ISE*/} return retVal; }
@Override public void createPasteTypes(Transferable transferable, List<PasteType> types) { super.createPasteTypes(transferable, types); Element.ItemElem item; Node node = NodeTransfer.node(transferable, NodeTransfer.MOVE); if (node != null && node.canDestroy()) { item = node.getCookie(Element.ItemElem.class); if (item == null) { return; } Node itemNode = getChildren().findChild(item.getKey()); if (node.equals(itemNode)) { return; } types.add(new EntryPasteType(item, node)); } else { item = NodeTransfer.cookie(transferable, NodeTransfer.COPY, Element.ItemElem.class); if (item != null) { types.add(new EntryPasteType(item, null)); } } }
@Override public void doMove(final Lookup lookup) { if(canMove(lookup)) { Runnable task = new NodeToFileObjectTask(lookup.lookupAll(Node.class)) { @Override protected RefactoringUI createRefactoringUI(FileObject[] fileObjects) { // are other parameters specified e.g. due to drag and drop or copy paste PasteType pasteType = getPaste(lookup); FileObject targetFolder = getTarget(lookup); if (fileObjects.length == 1) { return new MoveMappingFilesRefactoringUI(fileObjects, targetFolder, pasteType); } else { return new MoveMappingFilesRefactoringUI(fileObjects, targetFolder, pasteType); } } }; task.run(); } }
private PasteType getPaste(Lookup look) { ExplorerContext drop = look.lookup(ExplorerContext.class); if (drop == null) { return null; } Transferable orig = drop.getTransferable(); if (orig == null) { return null; } Node n = drop.getTargetNode(); if (n == null) { return null; } PasteType[] pt = n.getPasteTypes(orig); if (pt.length == 1) { return null; } return pt[1]; }
@Override public PasteType getDropType(Transferable t, int action, int index) { PasteType pasteType = super.getDropType(t, action, index); //The pasteType can be: // 1) PackagePasteType - the t.flavor is package flavor // 2) null or DataPasteType - the t.flavor in not package flavor if (pasteType instanceof PackageViewChildren.PackagePasteType) { ((PackageViewChildren.PackagePasteType)pasteType).setOperation (action); } return pasteType; }
@Override public PasteType[] getPasteTypes(ExtendedNodeModel original, Object node, Transferable t) throws UnknownTypeException { VariablesFilter vf = getFilter (node, true, null); if (!(vf instanceof ExtendedNodeModelFilter)) { return original.getPasteTypes(node, t); } else { return ((ExtendedNodeModelFilter) vf).getPasteTypes(original, node, t); } }
@Override public PasteType[] types(Node target) { RefactoringPasteType refactoringPaste = new RefactoringPasteType(delegate, target); if (refactoringPaste.canHandle()) return new PasteType[] {refactoringPaste}; return new PasteType[0]; }
public void setPasteTypes(PasteType[] arr) { synchronized (this) { this.pasteTypes = arr; } LOG.log(Level.FINER, "setPasteTypes for {0}", Arrays.toString(arr)); toEnabled(arr != null); }
/** Can node recieve given drop action? */ // XXX canditate for more general support private boolean canDrop(Node n, int dropAction) { if (n == null) { return false; } if (ExplorerDnDManager.getDefault().getNodeAllowedActions() == DnDConstants.ACTION_NONE) { return false; } // test if a parent of the dragged nodes isn't the node over // only for MOVE action if ((DnDConstants.ACTION_MOVE & dropAction) != 0) { Node[] nodes = ExplorerDnDManager.getDefault().getDraggedNodes(); if (nodes != null) { for (int i = 0; i < nodes.length; i++) { if (n.equals(nodes[i].getParentNode())) { return false; } } } } Transferable trans = ExplorerDnDManager.getDefault().getDraggedTransferable( (DnDConstants.ACTION_MOVE & dropAction) != 0 ); if (trans == null) { return false; } // get paste types for given transferred transferable PasteType pt = null; //TODO DragDropUtilities.getDropType(n, trans, dropAction); return (pt != null); }
public void testIllegalStateException() throws Exception { N root = new N(); final N ch1 = new N(); final N ch2 = new N(); final N ch3 = new N(); PT mockPaste = new PT(); ch3.pasteTypes = Collections.<PasteType>singletonList(mockPaste); root.getChildren().add(new Node[] { ch1, ch2, ch3 }); final ExplorerManager em = new ExplorerManager(); em.setRootContext(root); em.setSelectedNodes(new Node[] { root }); Action action = ExplorerUtils.actionPaste(em); Action cut = ExplorerUtils.actionCut(em); em.waitActionsFinished(); assertFalse("Not enabled", action.isEnabled()); action.addPropertyChangeListener(this); cut.addPropertyChangeListener(this); em.setSelectedNodes(new Node[] { ch3 }); em.waitActionsFinished(); assertFalse("Cut is not enabled", cut.isEnabled()); assertTrue("Now enabled", action.isEnabled()); action.actionPerformed(new ActionEvent(this, 0, "")); assertEquals("The paste type is going to be called", 1, mockPaste.cnt); if (err != null) { throw err; } if (cnt == 0) { fail("There should be some change in actions: " + cnt); } }
@RandomlyFails // NB-Core-Build #9619, #9847, #9998, #10014 public void testPasteActionGetDelegatesBlocks() throws Exception { N root = new N(); final N ch1 = new N(); final N ch2 = new N(); final N ch3 = new N(); PT mockPaste = new PT(); ch3.pasteTypes = Collections.<PasteType>singletonList(mockPaste); root.getChildren().add(new Node[] { ch1, ch2, ch3 }); final ExplorerManager em = new ExplorerManager(); em.setRootContext(root); em.setSelectedNodes(new Node[] { root }); Action action = ExplorerUtils.actionPaste(em); em.waitActionsFinished(); assertFalse("Not enabled", action.isEnabled()); action.addPropertyChangeListener(this); assertNull("No delegates yet", action.getValue("delegates")); em.setSelectedNodes(new Node[] { ch3 }); Object ret = action.getValue("delegates"); assertNotNull("Delegates are updated", ret); Object[] arr = (Object[])ret; assertEquals("One item in there", 1, arr.length); if (err != null) { throw err; } }
public ActionPT(PasteType t, String command) { this.t = t; ExplorerManager em = findExplorerManager(); if (em != null) { this.sel = new NodeSelector(em, null); } if ("waitFinished".equals(command)) { // NOI18N run(); } else { RP.post(this); } }
private PasteType getPasteType() { Clipboard clipboard = (Clipboard) Lookup.getDefault().lookup(ExClipboard.class); Transferable trans = clipboard.getContents(this); if (trans != null) { PasteType[] pasteTypes = categoryNode.getPasteTypes(trans); if (pasteTypes != null && pasteTypes.length != 0) return pasteTypes[0]; } return null; }
public MoveClassUI(DataObject javaObject, FileObject targetFolder, PasteType pasteType, boolean needsByPass) { this.needsByPass = needsByPass; this.disable = targetFolder != null; this.targetFolder = targetFolder; this.javaObject = javaObject; this.sourceName = javaObject.getName(); this.pasteType = pasteType; this.refactoring = new MoveRefactoring(Lookups.fixed(javaObject.getPrimaryFile())); this.refactoring.getContext().add(JavaRefactoringUtils.getClasspathInfoFor(javaObject.getPrimaryFile())); }
public MoveClassUI(TreePathHandle javaClass, FileObject targetFolder, PasteType pasteType, String sourceName) { this.needsByPass = false; this.disable = targetFolder != null; this.javaClass = javaClass; this.sourceName = sourceName; this.targetFolder = targetFolder; this.pasteType = pasteType; this.refactoring = new MoveRefactoring(Lookups.fixed(javaClass)); this.refactoring.getContext().add(JavaRefactoringUtils.getClasspathInfoFor(javaClass.getFileObject())); }
public MoveClassesUI(Set<FileObject> javaObjects, FileObject targetFolder, PasteType paste) { this.disable = targetFolder != null; this.targetFolder = targetFolder; this.javaObjects=javaObjects; this.pasteType = paste; if (!disable) { resources = new ArrayList<FileObject>(javaObjects); } }
public CopyClassesUI(Set<FileObject> javaObjects, FileObject targetFolder, PasteType paste) { this.disable = targetFolder != null; this.targetFolder = targetFolder; this.javaObjects = javaObjects; this.pasteType = paste; if (!disable) { resources = new ArrayList<FileObject>(javaObjects); } }
@Override public PasteType[] getPasteTypes(Transferable t) { PasteType[] pasteTypes = super.getPasteTypes(t); if (pasteTypes.length > 1) { pasteTypes = new PasteType[] { pasteTypes[0] }; // COPY only } return pasteTypes; }
@Override protected void createPasteTypes(Transferable t, List<PasteType> s) { super.createPasteTypes(t, s); if (!(this instanceof DataFolder.FolderNode)) { s.addAll(getPasteTypesFromParent(t)); // #250134 } }
@NbBundle.Messages({ "# Text appended to action name so that it is clear that the action", "# will be invoked on parent node. For example:", "# Paste -> Copy (to parent); Paste -> Refactory Copy... (to parent)", "# Please note the leading space.", "LBL_PasteToParent= (to parent)" }) private PasteType[] updateParentPasteTypes(PasteType[] parentTypes) { PasteType[] ret = new PasteType[parentTypes.length]; for (int i = 0; i < parentTypes.length; i++) { final PasteType parentType = parentTypes[i]; ret[i] = new PasteType() { @Override public Transferable paste() throws IOException { return parentType.paste(); } @Override public String getName() { return parentType.getName() + Bundle.LBL_PasteToParent(); } @Override public HelpCtx getHelpCtx() { return parentType.getHelpCtx(); } }; } return ret; }
@Override public void createPasteTypes(Transferable t, List<PasteType> l) { PasteType[] p; try { p = model.getPasteTypes(object, t); } catch (UnknownTypeException e) { Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, e); p = null; } if (p == null) { super.createPasteTypes(t, l); } else { l.addAll(Arrays.asList(p)); } }
@Override public PasteType[] getPasteTypes(Object node, Transferable t) throws UnknownTypeException { if (filter instanceof ExtendedNodeModelFilter) { return ((ExtendedNodeModelFilter) filter).getPasteTypes(model, node, t); } else { return model.getPasteTypes(node, t); } }
@Override public PasteType getDropType(Object node, Transferable t, int action, int index) throws UnknownTypeException { if (dndfilter != null) { return dndfilter.getDropType(model, node, t, action, index); } else { return model.getDropType(node, t, action, index); } }
@Override public PasteType getDropType(Object node, Transferable t, int action, int index) throws UnknownTypeException { if (dndNodeModel != null) { return dndNodeModel.getDropType(node, t, action, index); } else { return null; } }
/** Creates paste types for this node. Overrides superclass method. */ @Override protected void createPasteTypes(Transferable t, List<PasteType> s) { super.createPasteTypes(t, s); Element.ItemElem item; Node n = NodeTransfer.node(t, NodeTransfer.MOVE); // cut if (n != null && n.canDestroy ()) { item = n.getCookie(Element.ItemElem.class); if (item != null) { // are we pasting into the same node Node n2 = getChildren().findChild(item.getKey()); if (n == n2) { return; } s.add(new KeyPasteType(item, n, KeyPasteType.MODE_PASTE_WITH_VALUE)); s.add(new KeyPasteType(item, n, KeyPasteType.MODE_PASTE_WITHOUT_VALUE)); return; } } // copy else { item = NodeTransfer.cookie(t, NodeTransfer.COPY, Element.ItemElem.class); if (item != null) { s.add(new KeyPasteType(item, null, KeyPasteType.MODE_PASTE_WITH_VALUE)); s.add(new KeyPasteType(item, null, KeyPasteType.MODE_PASTE_WITHOUT_VALUE)); return; } } }
/** * * @param pageFileObject * @param targetFolder * @param pasteType */ public MoveMappingFilesRefactoringUI(FileObject[] mappingFileObjects, FileObject targetFolder, PasteType pasteType) { refactoring = new MoveRefactoring(Lookups.fixed((Object[]) mappingFileObjects)); this.disable = targetFolder != null; this.targetFolder = targetFolder; this.mappingFileObjects = mappingFileObjects; this.pasteType = pasteType; }
public PasteType[] getPasteTypes(final Object node, final Transferable t) throws UnknownTypeException { if (node != TreeModel.ROOT && getWatch(node) == null) { return null; } DataFlavor[] flavors = t.getTransferDataFlavors(); final DataFlavor textFlavor = DataFlavor.selectBestTextFlavor(flavors); if (textFlavor != null) { return new PasteType[] { new PasteType() { public Transferable paste() { try { java.io.Reader r = textFlavor.getReaderForText(t); java.nio.CharBuffer cb = java.nio.CharBuffer.allocate(1000); r.read(cb); cb.flip(); Watch w = getWatch(node); if (w != null) { w.setExpression(cb.toString()); //fireModelChange(new ModelEvent.NodeChanged(WatchesNodeModel.this, node)); } else { // Root => add a new watch DebuggerManager.getDebuggerManager().createWatch(cb.toString()); } } catch (Exception ex) {} return null; } } }; } else { return null; } }
/** Set possible paste types. * Automatically enables or disables the paste action according to whether there are any. * @deprecated Use <code>TopComponent.getActionMap ().put (javax.swing.text.DefaultEditorKit.pasteAction, yourPasteAction);</code> * If you want register more paste types then use an action which delegates to * an array of <code>PasteAction</code> or also can delegate to an array of * <code>org.openide.util.datatransfer.PasteType</code>. * @param types the new types to allow, or <code>null</code> */ @Deprecated public void setPasteTypes(PasteType[] types) { PasteAction.types = types; if ((types == null) || (types.length == 0)) { setEnabled(false); } else { setEnabled(true); } model().checkStateChanged(true); }
@Override protected void createPasteTypes(Transferable t, List<PasteType> s) { }
@Override public PasteType getDropType(Transferable t, int action, int index) { return null; }