Java Code Examples for javafx.scene.input.Clipboard#getFiles()

The following examples show how to use javafx.scene.input.Clipboard#getFiles() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroupResource.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void paste(int index, Clipboard clipboard, Operation operation) {
    if (!clipboard.hasFiles() || !type.droppable(clipboard.getFiles(), getFilePath())) {
        return;
    }
    List<File> files = clipboard.getFiles();
    ObservableList<TreeItem<Resource>> cs = getChildren();
    for (File file : files) {
        GroupEntry ge = null;
        try {
            if (Constants.isSuiteFile(file)) {
                ge = new GroupGroupEntry(GroupEntryType.SUITE, file.toPath().toString());
            } else if (Constants.isFeatureFile(file)) {
                ge = new GroupGroupEntry(GroupEntryType.FEATURE, file.toPath().toString());
            } else if (Constants.isStoryFile(file)) {
                ge = new GroupGroupEntry(GroupEntryType.STORY, file.toPath().toString());
            } else if (Constants.isIssueFile(file)) {
                ge = new GroupGroupEntry(GroupEntryType.ISSUE, file.toPath().toString());
            } else if (Constants.isTestFile(file)) {
                ge = getTestEntry(file);
            }
        } catch (IOException e) {
            e.printStackTrace();
            continue;
        }
        cs.add(index, new GroupEntryResource(ge));
        group.getEntries().add(index, ge);
        index++;
    }
    try {
        Group.updateFile(group);
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    Event.fireEvent(this, new ResourceModificationEvent(ResourceModificationEvent.UPDATE, this));
    return;
}
 
Example 2
Source File: FolderResource.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@Override
public void pasteInto(Clipboard clipboard, Operation operation) {
    if (clipboard.hasFiles()) {
        List<File> files = clipboard.getFiles();
        List<Path> paths = new ArrayList<>();
        for (File file : files) {
            paths.add(file.toPath().toAbsolutePath());
        }
        Collections.sort(paths);
        Path lastCopiedPath = null;
        for (Path path : paths) {
            try {
                if (lastCopiedPath == null || !path.startsWith(lastCopiedPath)) {
                    Path newPath = Copy.copy(path, this.path, operation);
                    if (newPath == null) {
                        continue;
                    }
                    Resource to;
                    if (Files.isDirectory(newPath)) {
                        to = new FolderResource(newPath.toFile(), watcher);
                    } else {
                        to = new FileResource(newPath.toFile());
                    }
                    lastCopiedPath = path;
                    Resource from;
                    if (path.toFile().isDirectory()) {
                        from = new FolderResource(path.toFile(), watcher);
                    } else {
                        from = new FileResource(path.toFile());
                    }
                    Event.fireEvent(this, new ResourceView.ResourceModificationEvent(
                            operation == Operation.CUT ? ResourceModificationEvent.MOVED : ResourceModificationEvent.COPIED,
                            from, to));
                }
            } catch (IOException e) {
                FXUIUtils.showMessageDialog(null, "Error in copying files.", e.getMessage(), AlertType.ERROR);
            }
        }
    }
    Platform.runLater(() -> refresh());
}