Search in sources :

Example 36 with VirtualFile

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

the class BreakpointManagerImpl method setCurrentBreakpoint.

private void setCurrentBreakpoint(String filePath, int lineNumber) {
    deleteCurrentBreakpoint();
    EditorPartPresenter editor = getEditorForFile(filePath);
    if (editor != null) {
        VirtualFile activeFile = editor.getEditorInput().getFile();
        doSetCurrentBreakpoint(activeFile, lineNumber);
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 37 with VirtualFile

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

the class EditorGroupSynchronizationImpl method updateContent.

private void updateContent(String newContent, String oldStamp, VirtualFile virtualFile) {
    final DocumentHandle documentHandle = getDocumentHandleFor(groupLeaderEditor);
    if (documentHandle == null) {
        return;
    }
    final Document document = documentHandle.getDocument();
    final String oldContent = document.getContents();
    final TextPosition cursorPosition = document.getCursorPosition();
    if (!(virtualFile instanceof File)) {
        replaceContent(document, newContent, oldContent, cursorPosition);
        return;
    }
    final File file = (File) virtualFile;
    final String newStamp = file.getModificationStamp();
    if (oldStamp == null && !Objects.equals(newContent, oldContent)) {
        replaceContent(document, newContent, oldContent, cursorPosition);
        return;
    }
    if (!Objects.equals(oldStamp, newStamp)) {
        replaceContent(document, newContent, oldContent, cursorPosition);
        notificationManager.notify("External operation", "File '" + file.getName() + "' is updated", SUCCESS, EMERGE_MODE);
    }
}
Also used : DocumentHandle(org.eclipse.che.ide.api.editor.document.DocumentHandle) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Document(org.eclipse.che.ide.api.editor.document.Document) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile)

Example 38 with VirtualFile

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

the class EditorGroupSynchronizationImpl method onFileContentUpdate.

@Override
public void onFileContentUpdate(final FileContentUpdateEvent event) {
    if (synchronizedEditors.keySet().isEmpty()) {
        return;
    }
    if (groupLeaderEditor == null) {
        groupLeaderEditor = synchronizedEditors.keySet().iterator().next();
        resolveAutoSave();
    }
    final VirtualFile virtualFile = groupLeaderEditor.getEditorInput().getFile();
    if (!event.getFilePath().equals(virtualFile.getLocation().toString())) {
        return;
    }
    documentStorage.getDocument(virtualFile, new DocumentStorage.DocumentCallback() {

        @Override
        public void onDocumentReceived(final String content) {
            updateContent(content, event.getModificationStamp(), virtualFile);
        }

        @Override
        public void onDocumentLoadFailure(final Throwable caught) {
            notificationManager.notify("", "Can not to update content for the file " + virtualFile.getDisplayName(), FAIL, EMERGE_MODE);
        }
    });
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) DocumentStorage(org.eclipse.che.ide.api.editor.document.DocumentStorage)

Example 39 with VirtualFile

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

the class EditorAgentImpl method onActivePartChanged.

@Override
public void onActivePartChanged(ActivePartChangedEvent event) {
    activePart = event.getActivePart();
    if (!(event.getActivePart() instanceof EditorPartPresenter)) {
        return;
    }
    activeEditor = (EditorPartPresenter) event.getActivePart();
    activeEditor.activate();
    final String isLinkedWithEditor = preferencesManager.getValue(LinkWithEditorAction.LINK_WITH_EDITOR);
    if (parseBoolean(isLinkedWithEditor)) {
        final VirtualFile file = activeEditor.getEditorInput().getFile();
        eventBus.fireEvent(new RevealResourceEvent(file.getLocation()));
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent)

Example 40 with VirtualFile

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

the class EditorCurrentProjectNameMacro 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().getName());
    }
    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)

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