Search in sources :

Example 11 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class EditorPartStackPresenter method addPart.

/** {@inheritDoc} */
@Override
public void addPart(@NotNull PartPresenter part) {
    checkArgument(part instanceof AbstractEditorPresenter, "Can not add part " + part.getTitle() + " to editor part stack");
    EditorPartPresenter editorPart = (AbstractEditorPresenter) part;
    if (containsPart(editorPart)) {
        setActivePart(editorPart);
        return;
    }
    VirtualFile file = editorPart.getEditorInput().getFile();
    checkArgument(file != null, "File doesn't provided");
    addHandlers();
    updateListClosedParts(file);
    editorPart.addPropertyListener(propertyListener);
    final EditorTab editorTab = tabItemFactory.createEditorPartButton(editorPart, this);
    editorPart.addPropertyListener(new PropertyListener() {

        @Override
        public void propertyChanged(PartPresenter source, int propId) {
            if (propId == EditorPartPresenter.PROP_INPUT && source instanceof EditorPartPresenter) {
                editorTab.setReadOnlyMark(((EditorPartPresenter) source).getEditorInput().getFile().isReadOnly());
            }
        }
    });
    editorTab.setDelegate(this);
    parts.put(editorTab, editorPart);
    partsOrder.add(editorPart);
    view.addTab(editorTab, editorPart);
    TabItem tabItem = getTabByPart(editorPart);
    if (tabItem != null) {
        final EditorPaneMenuItem<TabItem> item = editorPaneMenuItemFactory.createMenuItem(tabItem);
        item.setDelegate(paneMenuTabItemHandler);
        editorPaneMenu.addItem(item);
        items.put(item, tabItem);
    }
    if (editorPart instanceof EditorWithErrors) {
        final EditorWithErrors presenter = ((EditorWithErrors) editorPart);
        editorPart.addPropertyListener(new PropertyListener() {

            @Override
            public void propertyChanged(PartPresenter source, int propId) {
                EditorState editorState = presenter.getErrorState();
                editorTab.setErrorMark(ERROR.equals(editorState));
                editorTab.setWarningMark(WARNING.equals(editorState));
            }
        });
    }
    view.selectTab(editorPart);
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) EditorTab(org.eclipse.che.ide.api.parts.EditorTab) TabItem(org.eclipse.che.ide.api.parts.PartStackView.TabItem) EditorWithErrors(org.eclipse.che.ide.api.editor.EditorWithErrors) PropertyListener(org.eclipse.che.ide.api.parts.PropertyListener) EditorState(org.eclipse.che.ide.api.editor.EditorWithErrors.EditorState) AbstractEditorPresenter(org.eclipse.che.ide.api.editor.AbstractEditorPresenter) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 12 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class EditorContentSynchronizerImplTest method shouldUpdatePathForGroupWhenFolderLocationIsChanged.

@Test
public void shouldUpdatePathForGroupWhenFolderLocationIsChanged() {
    Resource resource = mock(Resource.class);
    ResourceDelta delta = mock(ResourceDelta.class);
    ResourceChangedEvent resourceChangedEvent = new ResourceChangedEvent(delta);
    Path fromPath = new Path(FOLDER_PATH);
    Path toPath = new Path("testProject/src/main/java/org/eclipse/che/samples/");
    Path oldFilePath = new Path(FILE_PATH);
    Path newFilePath = new Path("testProject/src/main/java/org/eclipse/che/samples/" + FILE_NAME);
    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(false);
    editorContentSynchronizer.trackEditor(openedEditor1);
    editorContentSynchronizer.onResourceChanged(resourceChangedEvent);
    final EditorGroupSynchronization oldGroup = editorContentSynchronizer.editorGroups.get(oldFilePath);
    final EditorGroupSynchronization newGroup = editorContentSynchronizer.editorGroups.get(newFilePath);
    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 13 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class EditorContentSynchronizerImplTest method shouldRemoveGroup.

@Test
public void shouldRemoveGroup() {
    EditorPartPresenter openedEditor1 = mock(EditorPartPresenter.class);
    when(openedEditor1.getEditorInput()).thenReturn(editorInput);
    editorContentSynchronizer.trackEditor(openedEditor1);
    editorContentSynchronizer.trackEditor(activeEditor);
    editorContentSynchronizer.unTrackEditor(activeEditor);
    verify(editorGroupSynchronization).removeEditor(activeEditor);
    verify(editorGroupSynchronization).unInstall();
}
Also used : EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) Test(org.junit.Test)

Example 14 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class EditorContentSynchronizerImplTest method shouldRemoveEditorFromGroup.

@Test
public void shouldRemoveEditorFromGroup() {
    EditorPartPresenter openedEditor1 = mock(EditorPartPresenter.class);
    EditorPartPresenter openedEditor2 = mock(EditorPartPresenter.class);
    when(openedEditor1.getEditorInput()).thenReturn(editorInput);
    when(openedEditor2.getEditorInput()).thenReturn(editorInput);
    editorContentSynchronizer.trackEditor(openedEditor1);
    editorContentSynchronizer.trackEditor(openedEditor2);
    editorContentSynchronizer.trackEditor(activeEditor);
    editorContentSynchronizer.unTrackEditor(activeEditor);
    verify(editorGroupSynchronization).removeEditor(activeEditor);
}
Also used : EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) Test(org.junit.Test)

Example 15 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class EditorPartStackPresenterTest method shouldReturnFirstPart.

@Test
public void shouldReturnFirstPart() {
    presenter.addPart(partPresenter1);
    presenter.addPart(partPresenter2);
    presenter.addPart(partPresenter3);
    EditorPartPresenter result = presenter.getNextFor(partPresenter3);
    assertNotNull(result);
    assertEquals(partPresenter1, result);
}
Also used : EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) Test(org.junit.Test)

Aggregations

EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)79 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)21 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)19 OperationException (org.eclipse.che.api.promises.client.OperationException)13 Project (org.eclipse.che.ide.api.resources.Project)13 Resource (org.eclipse.che.ide.api.resources.Resource)11 Test (org.junit.Test)10 Operation (org.eclipse.che.api.promises.client.Operation)9 Path (org.eclipse.che.ide.resource.Path)8 File (org.eclipse.che.ide.api.resources.File)7 Scheduler (com.google.gwt.core.client.Scheduler)6 EditorPartStack (org.eclipse.che.ide.api.parts.EditorPartStack)6 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)6 Optional (com.google.common.base.Optional)5 OpenEditorCallbackImpl (org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl)5 LanguageServerEditorConfiguration (org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration)5 HandlesTextOperations (org.eclipse.che.ide.api.editor.texteditor.HandlesTextOperations)4 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)4 ClassContent (org.eclipse.che.ide.ext.java.shared.dto.ClassContent)4 JsonObject (elemental.json.JsonObject)3