Search in sources :

Example 1 with PartPresenter

use of org.eclipse.che.ide.api.parts.PartPresenter in project che by eclipse.

the class AbstractPerspective method getPartStackState.

private JsonObject getPartStackState(PartStack partStack, WorkBenchPartController partController) {
    JsonObject state = Json.createObject();
    state.put("SIZE", partController.getSize());
    if (partStack.getParts().isEmpty()) {
        state.put("HIDDEN", true);
    } else {
        if (partStack.getActivePart() != null) {
            state.put("ACTIVE_PART", partStack.getActivePart().getClass().getName());
        }
        state.put("HIDDEN", partController.isHidden());
        JsonArray parts = Json.createArray();
        state.put("PARTS", parts);
        int i = 0;
        for (PartPresenter entry : partStack.getParts()) {
            JsonObject presenterState = Json.createObject();
            presenterState.put("CLASS", entry.getClass().getName());
            parts.set(i++, presenterState);
        }
    }
    return state;
}
Also used : JsonArray(elemental.json.JsonArray) JsonObject(elemental.json.JsonObject) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter)

Example 2 with PartPresenter

use of org.eclipse.che.ide.api.parts.PartPresenter in project che by eclipse.

the class AbstractPerspective method restorePartController.

private void restorePartController(PartStack partStack, WorkBenchPartController controller, JsonObject partStackJSON) {
    if (partStackJSON.hasKey("PARTS")) {
        JsonArray parts = partStackJSON.get("PARTS");
        for (int i = 0; i < parts.length(); i++) {
            JsonObject value = parts.get(i);
            if (value.hasKey("CLASS")) {
                String className = value.getString("CLASS");
                Provider<PartPresenter> provider = dynaProvider.getProvider(className);
                if (provider != null) {
                    PartPresenter partPresenter = provider.get();
                    if (!partStack.containsPart(partPresenter)) {
                        partStack.addPart(partPresenter);
                    }
                }
            }
        }
    }
    //hide part stack if it has no parts
    if (partStack.getParts().isEmpty()) {
        controller.setHidden(true);
        return;
    }
    if (partStackJSON.hasKey("HIDDEN") && partStackJSON.getBoolean("HIDDEN")) {
        partStack.minimize();
        return;
    }
    if (partStackJSON.hasKey("SIZE")) {
        double size = partStackJSON.getNumber("SIZE");
        // Size of the part must not be less 100 pixels.
        if (size < MIN_PART_SIZE) {
            size = DEFAULT_PART_SIZE;
        }
        controller.setSize(size);
    }
}
Also used : JsonArray(elemental.json.JsonArray) JsonObject(elemental.json.JsonObject) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter)

Example 3 with PartPresenter

use of org.eclipse.che.ide.api.parts.PartPresenter 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 4 with PartPresenter

use of org.eclipse.che.ide.api.parts.PartPresenter in project che by eclipse.

the class OrionEditorPresenter method updateTabReference.

private void updateTabReference(File file, Path oldPath) {
    final PartPresenter activePart = editorMultiPartStackPresenter.getActivePart();
    final EditorPartStack activePartStack = editorMultiPartStackPresenter.getPartStackByPart(activePart);
    if (activePartStack == null) {
        return;
    }
    final EditorTab editorTab = activePartStack.getTabByPath(oldPath);
    if (editorTab != null) {
        editorTab.setFile(file);
    }
}
Also used : EditorTab(org.eclipse.che.ide.api.parts.EditorTab) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter) EditorPartStack(org.eclipse.che.ide.api.parts.EditorPartStack)

Example 5 with PartPresenter

use of org.eclipse.che.ide.api.parts.PartPresenter in project che by eclipse.

the class AbstractPerspectivePersistenceTest method shouldRestorePartStackSize.

@Test
public void shouldRestorePartStackSize() throws Exception {
    JsonObject state = Json.createObject();
    JsonObject parts = Json.createObject();
    state.put("PART_STACKS", parts);
    JsonObject partStack = Json.createObject();
    parts.put("INFORMATION", partStack);
    JsonArray partsArray = Json.createArray();
    partStack.put("PARTS", partsArray);
    JsonObject part = Json.createObject();
    partsArray.set(0, part);
    part.put("CLASS", "foo.Bar");
    partStack.put("SIZE", 142);
    // partStackPresenter.getParts() must return non empty list
    final List<PartPresenter> partPresenters = new ArrayList<>();
    partPresenters.add(partPresenter);
    when(partStackPresenter.getParts()).thenAnswer(new Answer<List<? extends PartPresenter>>() {

        @Override
        public List<? extends PartPresenter> answer(InvocationOnMock invocationOnMock) throws Throwable {
            return partPresenters;
        }
    });
    perspective.loadState(state);
    verify(workBenchController).setSize(142d);
}
Also used : JsonArray(elemental.json.JsonArray) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) JsonObject(elemental.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter) Test(org.junit.Test)

Aggregations

PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)16 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)9 JsonObject (elemental.json.JsonObject)6 JsonArray (elemental.json.JsonArray)4 PropertyListener (org.eclipse.che.ide.api.parts.PropertyListener)4 EditorPartStack (org.eclipse.che.ide.api.parts.EditorPartStack)3 FileType (org.eclipse.che.ide.api.filetypes.FileType)2 EditorTab (org.eclipse.che.ide.api.parts.EditorTab)2 Path (org.eclipse.che.ide.resource.Path)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 HasDataObject (org.eclipse.che.ide.api.data.HasDataObject)1 AbstractEditorPresenter (org.eclipse.che.ide.api.editor.AbstractEditorPresenter)1 AsyncEditorProvider (org.eclipse.che.ide.api.editor.AsyncEditorProvider)1 EditorOpenedEvent (org.eclipse.che.ide.api.editor.EditorOpenedEvent)1 EditorProvider (org.eclipse.che.ide.api.editor.EditorProvider)1 EditorWithErrors (org.eclipse.che.ide.api.editor.EditorWithErrors)1 EditorState (org.eclipse.che.ide.api.editor.EditorWithErrors.EditorState)1