Search in sources :

Example 31 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class EditorPartStackPresenterTest method tabShouldBeReturnedByPath.

@Test
public void tabShouldBeReturnedByPath() throws Exception {
    Path path = new Path(SOME_TEXT);
    when(editorTab1.getFile()).thenReturn(file1);
    when(file1.getLocation()).thenReturn(path);
    presenter.addPart(partPresenter1);
    assertEquals(editorTab1, presenter.getTabByPath(path));
}
Also used : Path(org.eclipse.che.ide.resource.Path) Test(org.junit.Test)

Example 32 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class ChangedListViewImpl method getTransitFolderName.

private String getTransitFolderName(List<String> allPaths, String comparedPath) {
    Path path = Path.valueOf(comparedPath);
    int segmentCount = path.segmentCount();
    for (int i = segmentCount; i > 0; i--) {
        if (allPaths.contains(path.removeLastSegments(segmentCount - i + 1).toString())) {
            return path.removeFirstSegments(i - 1).toString();
        }
    }
    return comparedPath;
}
Also used : Path(org.eclipse.che.ide.resource.Path)

Example 33 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class ChangedListViewImpl method getGroupedNodes.

private List<Node> getGroupedNodes(Map<String, Status> items) {
    List<String> allFiles = new ArrayList<>(items.keySet());
    List<String> allPaths = new ArrayList<>();
    for (String file : allFiles) {
        String path = file.substring(0, file.lastIndexOf("/"));
        if (!allPaths.contains(path)) {
            allPaths.add(path);
        }
    }
    List<String> commonPaths = getCommonPaths(allPaths);
    for (String commonPath : commonPaths) {
        if (!allPaths.contains(commonPath)) {
            allPaths.add(commonPath);
        }
    }
    Map<String, Node> preparedNodes = new HashMap<>();
    for (int i = getMaxNestedLevel(allFiles); i > 0; i--) {
        //Collect child files of all folders of current nesting level
        Map<String, List<Node>> currentChildNodes = new HashMap<>();
        for (String file : allFiles) {
            Path pathName = Path.valueOf(file);
            if (pathName.segmentCount() != i) {
                continue;
            }
            Node fileNode = new ChangedFileNode(file, items.get(file), nodesResources, delegate, true);
            String filePath = pathName.removeLastSegments(1).toString();
            if (currentChildNodes.keySet().contains(filePath)) {
                currentChildNodes.get(filePath).add(fileNode);
            } else {
                List<Node> listFiles = new ArrayList<>();
                listFiles.add(fileNode);
                currentChildNodes.put(filePath, listFiles);
            }
        }
        //Map child files to related folders of current nesting level or just create a common folder
        for (String path : allPaths) {
            if (!(Path.valueOf(path).segmentCount() == i - 1)) {
                continue;
            }
            Node folder = new ChangedFolderNode(getTransitFolderName(allPaths, path), nodesResources);
            if (currentChildNodes.keySet().contains(path)) {
                folder.setChildren(currentChildNodes.get(path));
            }
            preparedNodes.put(path, folder);
        }
        //Take all child folders and nest them to related parent folders of current nesting level
        List<String> currentPaths = new ArrayList<>(preparedNodes.keySet());
        for (String parentPath : currentPaths) {
            List<Node> nodesToNest = new ArrayList<>();
            for (String nestedItem : currentPaths) {
                if (!parentPath.equals(nestedItem) && (nestedItem.startsWith(parentPath + "/") || parentPath.isEmpty())) {
                    nodesToNest.add(preparedNodes.remove(nestedItem));
                }
            }
            if (nodesToNest.isEmpty()) {
                continue;
            }
            Collections.sort(nodesToNest, new NameComparator());
            if (currentChildNodes.keySet().contains(parentPath)) {
                nodesToNest.addAll(currentChildNodes.get(parentPath));
            }
            if (parentPath.isEmpty()) {
                return nodesToNest;
            } else {
                preparedNodes.get(parentPath).setChildren(nodesToNest);
            }
        }
    }
    ArrayList<Node> nodes = new ArrayList<>(preparedNodes.values());
    Collections.sort(nodes, new NameComparator());
    return new ArrayList<>(nodes);
}
Also used : Path(org.eclipse.che.ide.resource.Path) HashMap(java.util.HashMap) Node(org.eclipse.che.ide.api.data.tree.Node) ArrayList(java.util.ArrayList) NameComparator(org.eclipse.che.ide.ui.smartTree.compare.NameComparator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 34 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class AddToIndexPresenter method onAddClicked.

/** {@inheritDoc} */
@Override
public void onAddClicked() {
    DevMachine devMachine = appContext.getDevMachine();
    Resource[] resources = appContext.getResources();
    Path projectLocation = appContext.getRootProject().getLocation();
    Path[] paths = new Path[resources.length];
    for (int i = 0; i < resources.length; i++) {
        Path path = resources[i].getLocation().removeFirstSegments(projectLocation.segmentCount());
        paths[i] = path.segmentCount() == 0 ? Path.EMPTY : path;
    }
    final GitOutputConsole console = gitOutputConsoleFactory.create(constant.addToIndexCommandName());
    consolesPanelPresenter.addCommandOutput(devMachine.getId(), console);
    service.add(devMachine, projectLocation, view.isUpdated(), paths).then(new Operation<Void>() {

        @Override
        public void apply(Void arg) throws OperationException {
            console.print(constant.addSuccess());
            notificationManager.notify(constant.addSuccess());
            view.close();
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            console.printError(constant.addFailed());
            notificationManager.notify(constant.addFailed(), FAIL, FLOAT_MODE);
            view.close();
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) PromiseError(org.eclipse.che.api.promises.client.PromiseError) GitOutputConsole(org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 35 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class ComparePresenter method showCompareBetweenRevisions.

/**
     *
     * @param file
     *         path of the file
     * @param status
     *         status of the file
     * @param revisionA
     *         hash of the first revision or branch.
     *         If it is set to {@code null}, compare with empty repository state will be performed
     * @param revisionB
     *         hash of the second revision or branch.
     *         If it is set to {@code null}, compare with latest repository state will be performed
     */
public void showCompareBetweenRevisions(final Path file, final Status status, @Nullable final String revisionA, @Nullable final String revisionB) {
    this.compareWithLatest = false;
    final DevMachine devMachine = appContext.getDevMachine();
    final Path projectLocation = appContext.getRootProject().getLocation();
    view.setTitle(file.toString());
    if (status == Status.ADDED) {
        service.showFileContent(devMachine, projectLocation, file, revisionB).then(new Operation<ShowFileContentResponse>() {

            @Override
            public void apply(ShowFileContentResponse response) throws OperationException {
                view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA == null ? "" : revisionA + locale.compareReadOnlyTitle());
                view.show("", response.getContent(), file.toString(), true);
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
            }
        });
    } else if (status == Status.DELETED) {
        service.showFileContent(devMachine, projectLocation, file, revisionA).then(new Operation<ShowFileContentResponse>() {

            @Override
            public void apply(ShowFileContentResponse response) throws OperationException {
                view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA + locale.compareReadOnlyTitle());
                view.show(response.getContent(), "", file.toString(), true);
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
            }
        });
    } else {
        service.showFileContent(devMachine, projectLocation, file, revisionA).then(new Operation<ShowFileContentResponse>() {

            @Override
            public void apply(final ShowFileContentResponse contentAResponse) throws OperationException {
                service.showFileContent(devMachine, projectLocation, file, revisionB).then(new Operation<ShowFileContentResponse>() {

                    @Override
                    public void apply(ShowFileContentResponse contentBResponse) throws OperationException {
                        view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA + locale.compareReadOnlyTitle());
                        view.show(contentAResponse.getContent(), contentBResponse.getContent(), file.toString(), true);
                    }
                }).catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError error) throws OperationException {
                        notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
                    }
                });
            }
        });
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) PromiseError(org.eclipse.che.api.promises.client.PromiseError) ShowFileContentResponse(org.eclipse.che.api.git.shared.ShowFileContentResponse) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

Path (org.eclipse.che.ide.resource.Path)72 Resource (org.eclipse.che.ide.api.resources.Resource)27 Operation (org.eclipse.che.api.promises.client.Operation)15 OperationException (org.eclipse.che.api.promises.client.OperationException)15 PromiseError (org.eclipse.che.api.promises.client.PromiseError)13 ArrayList (java.util.ArrayList)11 Project (org.eclipse.che.ide.api.resources.Project)11 Promise (org.eclipse.che.api.promises.client.Promise)10 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)10 List (java.util.List)8 Test (org.junit.Test)7 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)6 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)6 Optional (com.google.common.base.Optional)5 Function (org.eclipse.che.api.promises.client.Function)5 FunctionException (org.eclipse.che.api.promises.client.FunctionException)5 Container (org.eclipse.che.ide.api.resources.Container)5 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)5 HashMap (java.util.HashMap)4 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)4