Search in sources :

Example 1 with PropertyListener

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

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

the class RecipeEditorPanel method initializeEditor.

private void initializeEditor(@NotNull final VirtualFile file) {
    FileType fileType = fileTypeRegistry.getFileTypeByFile(file);
    editor = getEditor();
    editor.activate();
    editor.onOpen();
    view.showEditor(editor);
    // wait when editor is initialized
    editor.addPropertyListener(new PropertyListener() {

        @Override
        public void propertyChanged(PartPresenter source, int propId) {
            switch(propId) {
                case PROP_INPUT:
                    view.showEditor(editor);
                    break;
                case PROP_DIRTY:
                    if (validateUndoOperation()) {
                        setEnableSaveAndCancelButtons(true);
                    }
                    break;
                default:
            }
        }
    });
    editor.init(new RecipeEditorInput(fileType, file), new OpenEditorCallbackImpl());
}
Also used : FileType(org.eclipse.che.ide.api.filetypes.FileType) PropertyListener(org.eclipse.che.ide.api.parts.PropertyListener) OpenEditorCallbackImpl(org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 3 with PropertyListener

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

the class FileWatcher method editorOpened.

public void editorOpened(final EditorPartPresenter editor) {
    final PropertyListener propertyListener = new PropertyListener() {

        @Override
        public void propertyChanged(PartPresenter source, int propId) {
            if (propId == EditorPartPresenter.PROP_DIRTY) {
                if (!editor.isDirty()) {
                    reparseAllOpenedFiles();
                    //remove just saved editor
                    editor2reconcile.remove(editor);
                }
            }
        }
    };
    editor.addPropertyListener(propertyListener);
}
Also used : PropertyListener(org.eclipse.che.ide.api.parts.PropertyListener) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 4 with PropertyListener

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

the class EditorAgentImpl method finalizeInit.

private void finalizeInit(final VirtualFile file, final OpenEditorCallback callback, final EditorPartPresenter editor, EditorProvider editorProvider) {
    openedEditors.add(editor);
    openedEditorsToProviders.put(editor, editorProvider.getId());
    workspaceAgent.setActivePart(editor);
    editor.addPropertyListener(new PropertyListener() {

        @Override
        public void propertyChanged(PartPresenter source, int propId) {
            if (propId == EditorPartPresenter.PROP_INPUT) {
                if (editor instanceof HasReadOnlyProperty) {
                    ((HasReadOnlyProperty) editor).setReadOnly(file.isReadOnly());
                }
                if (editor instanceof TextEditor) {
                    editorContentSynchronizerProvider.get().trackEditor(editor);
                }
                callback.onEditorOpened(editor);
                eventBus.fireEvent(new EditorOpenedEvent(file, editor));
            }
        }
    });
}
Also used : TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorOpenedEvent(org.eclipse.che.ide.api.editor.EditorOpenedEvent) PropertyListener(org.eclipse.che.ide.api.parts.PropertyListener) HasReadOnlyProperty(org.eclipse.che.ide.api.editor.texteditor.HasReadOnlyProperty) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Aggregations

EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)4 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)4 PropertyListener (org.eclipse.che.ide.api.parts.PropertyListener)4 AbstractEditorPresenter (org.eclipse.che.ide.api.editor.AbstractEditorPresenter)1 EditorOpenedEvent (org.eclipse.che.ide.api.editor.EditorOpenedEvent)1 EditorWithErrors (org.eclipse.che.ide.api.editor.EditorWithErrors)1 EditorState (org.eclipse.che.ide.api.editor.EditorWithErrors.EditorState)1 OpenEditorCallbackImpl (org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl)1 HasReadOnlyProperty (org.eclipse.che.ide.api.editor.texteditor.HasReadOnlyProperty)1 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)1 FileType (org.eclipse.che.ide.api.filetypes.FileType)1 EditorTab (org.eclipse.che.ide.api.parts.EditorTab)1 TabItem (org.eclipse.che.ide.api.parts.PartStackView.TabItem)1 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)1