Search in sources :

Example 36 with Resource

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

the class OpenDeclarationFinder method openDeclaration.

public void openDeclaration() {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor == null) {
        return;
    }
    if (!(activeEditor instanceof TextEditor)) {
        Log.error(getClass(), "Open Declaration support only TextEditor as editor");
        return;
    }
    TextEditor editor = ((TextEditor) activeEditor);
    int offset = editor.getCursorOffset();
    final VirtualFile file = editor.getEditorInput().getFile();
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        final Optional<Resource> srcFolder = ((Resource) file).getParentWithMarker(SourceFolderMarker.ID);
        if (!srcFolder.isPresent()) {
            return;
        }
        final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) file);
        navigationService.findDeclaration(project.get().getLocation(), fqn, offset).then(new Operation<OpenDeclarationDescriptor>() {

            @Override
            public void apply(OpenDeclarationDescriptor result) throws OperationException {
                if (result != null) {
                    handleDescriptor(project.get().getLocation(), result);
                }
            }
        });
    } else if (file instanceof JarFileNode) {
        navigationService.findDeclaration(((JarFileNode) file).getProjectLocation(), file.getLocation().toString().replace('/', '.'), offset).then(new Operation<OpenDeclarationDescriptor>() {

            @Override
            public void apply(OpenDeclarationDescriptor result) throws OperationException {
                if (result != null) {
                    handleDescriptor(((JarFileNode) file).getProject(), result);
                }
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) OpenDeclarationDescriptor(org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) JarFileNode(org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode) Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 37 with Resource

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

the class ConvertFolderToProjectAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    Resource folder = getSelectedItem();
    if (folder == null) {
        return;
    }
    Path location = folder.getLocation();
    if (location == null) {
        return;
    }
    MutableProjectConfig mutableProjectConfig = new MutableProjectConfig();
    mutableProjectConfig.setPath(location.toString());
    mutableProjectConfig.setName(folder.getName());
    projectConfigWizard.show(mutableProjectConfig);
}
Also used : Path(org.eclipse.che.ide.resource.Path) MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 38 with Resource

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

the class DownloadProjectAction method actionPerformed.

/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
    final Resource resource = appContext.getResource();
    if (resource == null || resource.getResourceType() != PROJECT) {
        return;
    }
    final Project project = (Project) resource;
    downloadContainer.setUrl(project.getURL());
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 39 with Resource

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

the class FullTextSearchAction method actionPerformed.

/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
    final Resource[] resources = appContext.getResources();
    final Path searchPath;
    if (resources == null || resources.length == 0 || resources.length > 1) {
        searchPath = Path.ROOT;
    } else {
        if (resources[0] instanceof Container) {
            searchPath = resources[0].getLocation();
        } else {
            final Container parent = resources[0].getParent();
            searchPath = parent != null ? parent.getLocation() : Path.ROOT;
        }
    }
    presenter.showDialog(searchPath);
}
Also used : Path(org.eclipse.che.ide.resource.Path) Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 40 with Resource

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

the class ProjectConfigurationAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    final Resource[] resources = appContext.getResources();
    checkState(resources != null && resources.length == 1);
    final Resource resource = resources[0];
    checkState(resource instanceof Container);
    if (resource.getResourceType() == PROJECT) {
        final MutableProjectConfig config = new MutableProjectConfig((Project) resource);
        projectWizard.show(config);
    }
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) Resource(org.eclipse.che.ide.api.resources.Resource)

Aggregations

Resource (org.eclipse.che.ide.api.resources.Resource)146 Project (org.eclipse.che.ide.api.resources.Project)73 OperationException (org.eclipse.che.api.promises.client.OperationException)48 Operation (org.eclipse.che.api.promises.client.Operation)46 PromiseError (org.eclipse.che.api.promises.client.PromiseError)40 Container (org.eclipse.che.ide.api.resources.Container)32 Path (org.eclipse.che.ide.resource.Path)30 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)22 Optional (com.google.common.base.Optional)15 File (org.eclipse.che.ide.api.resources.File)14 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)14 List (java.util.List)13 Promise (org.eclipse.che.api.promises.client.Promise)13 FunctionException (org.eclipse.che.api.promises.client.FunctionException)12 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)12 ArrayList (java.util.ArrayList)11 Function (org.eclipse.che.api.promises.client.Function)9 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)9 JavaUtil.isJavaProject (org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject)9 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)8