Search in sources :

Example 51 with Path

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

the class ChangedListViewImpl method getCommonPath.

private String getCommonPath(String firstPath, String secondPath) {
    Path commonPath = Path.valueOf(firstPath);
    int segmentCount = commonPath.segmentCount();
    for (int i = 1; i < segmentCount; i++) {
        String path = commonPath.removeLastSegments(segmentCount - i).toString();
        if (!secondPath.startsWith(path)) {
            return Path.valueOf(path).removeLastSegments(1).toString();
        }
    }
    return commonPath.toString();
}
Also used : Path(org.eclipse.che.ide.resource.Path)

Example 52 with Path

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

the class ComparePresenter method showCompareWithLatest.

/**
     * Show compare window.
     *
     * @param file
     *         file name with its full path
     * @param status
     *         status of the file
     * @param revision
     *         hash of revision or branch
     */
public void showCompareWithLatest(final File file, final Status status, final String revision) {
    this.comparedFile = file;
    this.revision = revision;
    this.compareWithLatest = true;
    if (status.equals(ADDED)) {
        showCompare("");
        return;
    }
    final Optional<Project> project = file.getRelatedProject();
    if (!project.isPresent()) {
        return;
    }
    final Path relPath = file.getLocation().removeFirstSegments(project.get().getLocation().segmentCount());
    if (status.equals(DELETED)) {
        service.showFileContent(appContext.getDevMachine(), project.get().getLocation(), relPath, revision).then(new Operation<ShowFileContentResponse>() {

            @Override
            public void apply(ShowFileContentResponse content) throws OperationException {
                view.setTitle(file.getLocation().toString());
                view.setColumnTitles(locale.compareYourVersionTitle(), revision + locale.compareReadOnlyTitle());
                view.show(content.getContent(), "", file.getLocation().toString(), false);
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
            }
        });
    } else {
        service.showFileContent(appContext.getDevMachine(), project.get().getLocation(), relPath, revision).then(new Operation<ShowFileContentResponse>() {

            @Override
            public void apply(ShowFileContentResponse content) throws OperationException {
                showCompare(content.getContent());
            }
        }).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) Project(org.eclipse.che.ide.api.resources.Project) 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)

Example 53 with Path

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

the class EditorContentSynchronizerImplTest method init.

@Before
public void init() {
    activeEditor = mock(EditorPartPresenter.class, withSettings().extraInterfaces(EditorWithAutoSave.class));
    when(activeEditor.getEditorInput()).thenReturn(editorInput);
    when(editorInput.getFile()).thenReturn(virtualFile);
    when(virtualFile.getLocation()).thenReturn(new Path(FILE_PATH));
    when(editorGroupSyncProvider.get()).thenReturn(editorGroupSynchronization);
}
Also used : Path(org.eclipse.che.ide.resource.Path) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) Before(org.junit.Before)

Example 54 with Path

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

the class EditorContentSynchronizerImplTest method shouldUpdatePathForGroupWhenFileLocationIsChanged.

@Test
public void shouldUpdatePathForGroupWhenFileLocationIsChanged() {
    Resource resource = mock(Resource.class);
    ResourceDelta delta = mock(ResourceDelta.class);
    ResourceChangedEvent resourceChangedEvent = new ResourceChangedEvent(delta);
    Path fromPath = new Path(FILE_PATH);
    Path toPath = new Path("testProject/src/main/java/org/eclipse/che/examples/changedFile");
    EditorPartPresenter openedEditor1 = mock(EditorPartPresenter.class);
    when(openedEditor1.getEditorInput()).thenReturn(editorInput);
    when(delta.getKind()).thenReturn(ResourceDelta.ADDED);
    when(delta.getFlags()).thenReturn(5632);
    when(delta.getFromPath()).thenReturn(fromPath);
    when(delta.getToPath()).thenReturn(toPath);
    when(delta.getResource()).thenReturn(resource);
    when(resource.isFile()).thenReturn(true);
    editorContentSynchronizer.trackEditor(openedEditor1);
    editorContentSynchronizer.onResourceChanged(resourceChangedEvent);
    final EditorGroupSynchronization oldGroup = editorContentSynchronizer.editorGroups.get(fromPath);
    final EditorGroupSynchronization newGroup = editorContentSynchronizer.editorGroups.get(toPath);
    assertNull(oldGroup);
    assertNotNull(newGroup);
}
Also used : Path(org.eclipse.che.ide.resource.Path) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) Resource(org.eclipse.che.ide.api.resources.Resource) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) Test(org.junit.Test)

Example 55 with Path

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

the class FullTextSearchPresenterTest method viewShouldBeShowed.

@Test
public void viewShouldBeShowed() {
    final Path path = Path.valueOf("/search");
    fullTextSearchPresenter.showDialog(path);
    verify(view).showDialog();
    verify(view).clearInput();
    verify(view).setPathDirectory(eq(path.toString()));
}
Also used : Path(org.eclipse.che.ide.resource.Path) Test(org.junit.Test)

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