Search in sources :

Example 41 with VirtualFile

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

the class EditorCurrentProjectTypeMacro method expand.

/** {@inheritDoc} */
@Override
public Promise<String> expand() {
    final EditorPartPresenter editor = getActiveEditor();
    if (editor == null) {
        return promises.resolve("");
    }
    final VirtualFile file = editor.getEditorInput().getFile();
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        if (!project.isPresent()) {
            return promises.resolve("");
        }
        return promises.resolve(project.get().getType());
    }
    return promises.resolve("");
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) Resource(org.eclipse.che.ide.api.resources.Resource) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 42 with VirtualFile

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

the class AppContextImpl method getRootProject.

@Override
public Project getRootProject() {
    if (projects == null) {
        return null;
    }
    if (currentResource == null || currentResources == null) {
        EditorAgent editorAgent = editorAgentProvider.get();
        if (editorAgent == null) {
            return null;
        }
        final EditorPartPresenter editor = editorAgent.getActiveEditor();
        if (editor == null) {
            return null;
        }
        final VirtualFile file = editor.getEditorInput().getFile();
        if (file instanceof SyntheticNode) {
            final Path projectPath = ((SyntheticNode) file).getProject();
            for (Project project : projects) {
                if (project.getLocation().equals(projectPath)) {
                    return project;
                }
            }
        }
    }
    if (currentResource == null) {
        return null;
    }
    Project root = null;
    for (Project project : projects) {
        if (project.getLocation().isPrefixOf(currentResource.getLocation())) {
            root = project;
        }
    }
    if (root == null) {
        return null;
    }
    for (int i = 1; i < currentResources.length; i++) {
        if (!root.getLocation().isPrefixOf(currentResources[i].getLocation())) {
            return null;
        }
    }
    return root;
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Path(org.eclipse.che.ide.resource.Path) Project(org.eclipse.che.ide.api.resources.Project) EditorAgent(org.eclipse.che.ide.api.editor.EditorAgent) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) SyntheticNode(org.eclipse.che.ide.project.node.SyntheticNode)

Example 43 with VirtualFile

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

the class BreakpointManagerImpl method addBreakpoint.

/**
     * Adds breakpoint to the list and JVM.
     */
private void addBreakpoint(final Breakpoint breakpoint) {
    List<Breakpoint> pathBreakpoints = breakpoints.get(breakpoint.getPath());
    if (pathBreakpoints == null) {
        pathBreakpoints = new ArrayList<>();
        breakpoints.put(breakpoint.getPath(), pathBreakpoints);
    }
    if (!pathBreakpoints.contains(breakpoint)) {
        pathBreakpoints.add(breakpoint);
    }
    preserveBreakpoints();
    final BreakpointRenderer breakpointRenderer = getBreakpointRendererForFile(breakpoint.getPath());
    if (breakpointRenderer != null) {
        breakpointRenderer.addBreakpointMark(breakpoint.getLineNumber(), new LineChangeAction() {

            @Override
            public void onLineChange(VirtualFile file, int firstLine, int linesAdded, int linesRemoved) {
                BreakpointManagerImpl.this.onLineChange(file, firstLine, linesAdded, linesRemoved);
            }
        });
        breakpointRenderer.setBreakpointActive(breakpoint.getLineNumber(), breakpoint.isActive());
    }
    for (BreakpointManagerObserver observer : observers) {
        observer.onBreakpointAdded(breakpoint);
    }
    Debugger debugger = debuggerManager.getActiveDebugger();
    if (debugger != null) {
        debugger.addBreakpoint(breakpoint.getFile(), breakpoint.getLineNumber());
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Breakpoint(org.eclipse.che.ide.api.debug.Breakpoint) BreakpointRenderer(org.eclipse.che.ide.api.debug.BreakpointRenderer) HasBreakpointRenderer(org.eclipse.che.ide.api.debug.HasBreakpointRenderer) LineChangeAction(org.eclipse.che.ide.api.debug.BreakpointRenderer.LineChangeAction) BreakpointManagerObserver(org.eclipse.che.ide.api.debug.BreakpointManagerObserver) Breakpoint(org.eclipse.che.ide.api.debug.Breakpoint)

Example 44 with VirtualFile

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

the class EditorTabWidget method onResourceChanged.

@Override
public void onResourceChanged(ResourceChangedEvent event) {
    final ResourceDelta delta = event.getDelta();
    if (delta.getKind() == ADDED) {
        if (!delta.getResource().isFile() || (delta.getFlags() & (MOVED_FROM | MOVED_TO)) == 0) {
            return;
        }
        final Resource resource = delta.getResource();
        final Path movedFrom = delta.getFromPath();
        if (file.getLocation().equals(movedFrom)) {
            file = (VirtualFile) resource;
            title.setText(file.getDisplayName());
        }
    } else if (delta.getKind() == UPDATED) {
        if (!delta.getResource().isFile()) {
            return;
        }
        final Resource resource = delta.getResource();
        if (file.getLocation().equals(resource.getLocation())) {
            file = (VirtualFile) resource;
            title.setText(file.getDisplayName());
        }
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 45 with VirtualFile

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

the class JavaRefactoringRename method performRename.

private void performRename(RenameRefactoringSession session) {
    final LinkedRenameRefactoringApply dto = createLinkedRenameRefactoringApplyDto(newName, session.getSessionId());
    Promise<RefactoringResult> applyModelPromise = refactoringServiceClient.applyLinkedModeRename(dto);
    applyModelPromise.then(new Operation<RefactoringResult>() {

        @Override
        public void apply(RefactoringResult result) throws OperationException {
            switch(result.getSeverity()) {
                case OK:
                case INFO:
                    final VirtualFile file = textEditor.getDocument().getFile();
                    if (file instanceof Resource) {
                        final Optional<Project> project = ((Resource) file).getRelatedProject();
                        refactoringServiceClient.reindexProject(project.get().getLocation().toString());
                    }
                    refactoringUpdater.updateAfterRefactoring(result.getChanges());
                    break;
                case WARNING:
                case ERROR:
                    enableAutoSave();
                    undoChanges();
                    showWarningDialog();
                    break;
                case FATAL:
                    undoChanges();
                    notificationManager.notify(locale.failedToRename(), result.getEntries().get(0).getMessage(), FAIL, FLOAT_MODE);
                    break;
                default:
                    break;
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            enableAutoSave();
            undoChanges();
            notificationManager.notify(locale.failedToRename(), arg.getMessage(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) Resource(org.eclipse.che.ide.api.resources.Resource) LinkedRenameRefactoringApply(org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)48 Project (org.eclipse.che.ide.api.resources.Project)21 Resource (org.eclipse.che.ide.api.resources.Resource)19 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)18 OperationException (org.eclipse.che.api.promises.client.OperationException)15 Operation (org.eclipse.che.api.promises.client.Operation)14 PromiseError (org.eclipse.che.api.promises.client.PromiseError)9 File (org.eclipse.che.ide.api.resources.File)8 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)6 Test (org.junit.Test)6 Optional (com.google.common.base.Optional)5 Scheduler (com.google.gwt.core.client.Scheduler)4 HashMap (java.util.HashMap)4 EditorInput (org.eclipse.che.ide.api.editor.EditorInput)4 OpenEditorCallbackImpl (org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl)4 JarEntry (org.eclipse.che.ide.ext.java.shared.JarEntry)4 ClassContent (org.eclipse.che.ide.ext.java.shared.dto.ClassContent)4 Path (org.eclipse.che.ide.resource.Path)4 Breakpoint (org.eclipse.che.ide.api.debug.Breakpoint)3 JarFileNode (org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode)3