Search in sources :

Example 26 with Container

use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.

the class ResourceImpl method getParentWithMarker.

/** {@inheritDoc} */
@Override
public Optional<Resource> getParentWithMarker(String type) {
    checkArgument(!isNullOrEmpty(type), "Invalid marker type occurred");
    if (getMarker(type).isPresent()) {
        return Optional.<Resource>of(this);
    }
    Container optParent = getParent();
    while (optParent != null) {
        Container parent = optParent;
        final Optional<Marker> marker = parent.getMarker(type);
        if (marker.isPresent()) {
            return Optional.<Resource>of(parent);
        }
        optParent = parent.getParent();
    }
    return absent();
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource) Marker(org.eclipse.che.ide.api.resources.marker.Marker)

Example 27 with Container

use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.

the class ResourceImpl method getRelatedProject.

/** {@inheritDoc} */
@Override
public Optional<Project> getRelatedProject() {
    if (this instanceof Project) {
        return of((Project) this);
    }
    Container optionalParent = getParent();
    if (optionalParent == null) {
        return absent();
    }
    Container parent = optionalParent;
    while (!(parent instanceof Project)) {
        optionalParent = parent.getParent();
        if (optionalParent == null) {
            return absent();
        }
        parent = optionalParent;
    }
    return of((Project) parent);
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Container(org.eclipse.che.ide.api.resources.Container)

Example 28 with Container

use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.

the class RenamePresenter method createRenameRefactoringDto.

private CreateRenameRefactoring createRenameRefactoringDto(RefactorInfo refactorInfo) {
    CreateRenameRefactoring dto = dtoFactory.createDto(CreateRenameRefactoring.class);
    dto.setRefactorLightweight(false);
    if (refactorInfo == null) {
        final VirtualFile file = editorAgent.getActiveEditor().getEditorInput().getFile();
        dto.setType(JAVA_ELEMENT);
        dto.setPath(JavaUtil.resolveFQN(file));
        dto.setOffset(((TextEditor) editorAgent.getActiveEditor()).getCursorOffset());
        if (file instanceof Resource) {
            final Project project = ((Resource) file).getRelatedProject().get();
            dto.setProjectPath(project.getLocation().toString());
        }
    } else {
        final Resource[] resources = refactorInfo.getResources();
        checkState(resources != null && resources.length == 1);
        final Resource resource = resources[0];
        if (resource.getResourceType() == FILE) {
            dto.setPath(JavaUtil.resolveFQN(resource));
            dto.setType(COMPILATION_UNIT);
        } else if (resource instanceof Container) {
            dto.setPath(resource.getLocation().toString());
            dto.setType(PACKAGE);
        }
        final Project project = resource.getRelatedProject().get();
        dto.setProjectPath(project.getLocation().toString());
    }
    return dto;
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource) CreateRenameRefactoring(org.eclipse.che.ide.ext.java.shared.dto.refactoring.CreateRenameRefactoring)

Example 29 with Container

use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.

the class JavaReconcilerStrategyTest method setUp.

@Before
public void setUp() throws Exception {
    EditorInput editorInput = mock(EditorInput.class);
    Optional project = mock(Optional.class);
    Project projectConfig = mock(Project.class);
    Optional<Resource> srcFolder = mock(Optional.class);
    Container startPoint = mock(Container.class);
    when(editor.getEditorInput()).thenReturn(editorInput);
    when(editorInput.getFile()).thenReturn(file);
    when(file.getName()).thenReturn(FILE_NAME);
    when(file.getRelatedProject()).thenReturn(project);
    when(file.getLocation()).thenReturn(Path.valueOf("some/path/to/file"));
    when(project.get()).thenReturn(projectConfig);
    when(projectConfig.getLocation()).thenReturn(Path.valueOf("some/path/to/project"));
    when(project.isPresent()).thenReturn(true);
    when(file.getParentWithMarker(any())).thenReturn(srcFolder);
    when(srcFolder.isPresent()).thenReturn(true);
    when(srcFolder.get()).thenReturn(startPoint);
    when(startPoint.getLocation()).thenReturn(Path.valueOf("some/path"));
    when(resolvingProjectStateHolderRegistry.getResolvingProjectStateHolder(anyString())).thenReturn(resolvingProjectStateHolder);
    when(localizationConstant.codeAssistErrorMessageResolvingProject()).thenReturn("error");
    javaReconcilerStrategy.setDocument(mock(Document.class));
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Container(org.eclipse.che.ide.api.resources.Container) Optional(com.google.common.base.Optional) Resource(org.eclipse.che.ide.api.resources.Resource) Document(org.eclipse.che.ide.api.editor.document.Document) EditorInput(org.eclipse.che.ide.api.editor.EditorInput) Before(org.junit.Before)

Example 30 with Container

use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.

the class CutJavaSourceActionTest method actionShouldBeEnabledWhenFolderInContext.

@Test
public void actionShouldBeEnabledWhenFolderInContext() throws Exception {
    final Container container = mock(Container.class);
    when(updateActionEvent.getPresentation()).thenReturn(presentation);
    when(appContext.getResources()).thenReturn(new Resource[] { container });
    when(container.getRelatedProject()).thenReturn(Optional.of(project));
    when(container.getParentWithMarker(eq(SourceFolderMarker.ID))).thenReturn(Optional.of(srcFolder));
    final Map<String, List<String>> attributes = new HashMap<>();
    attributes.put(Constants.LANGUAGE, Collections.singletonList("java"));
    when(project.getAttributes()).thenReturn(attributes);
    action.update(updateActionEvent);
    verify(presentation).setEnabled(eq(true));
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) HashMap(java.util.HashMap) List(java.util.List) Test(org.junit.Test)

Aggregations

Container (org.eclipse.che.ide.api.resources.Container)38 Resource (org.eclipse.che.ide.api.resources.Resource)32 Project (org.eclipse.che.ide.api.resources.Project)13 Operation (org.eclipse.che.api.promises.client.Operation)7 OperationException (org.eclipse.che.api.promises.client.OperationException)7 Optional (com.google.common.base.Optional)5 PromiseError (org.eclipse.che.api.promises.client.PromiseError)5 File (org.eclipse.che.ide.api.resources.File)5 Path (org.eclipse.che.ide.resource.Path)5 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)4 SVGResource (org.vectomatic.dom.svg.ui.SVGResource)4 List (java.util.List)3 FunctionException (org.eclipse.che.api.promises.client.FunctionException)3 Folder (org.eclipse.che.ide.api.resources.Folder)3 JavaUtil.isJavaProject (org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject)3 RevealResourceEvent (org.eclipse.che.ide.resources.reveal.RevealResourceEvent)3 ArrayList (java.util.ArrayList)2 Collections.singletonList (java.util.Collections.singletonList)2 Promise (org.eclipse.che.api.promises.client.Promise)2 Node (org.eclipse.che.ide.api.data.tree.Node)2