/** * Closes the tab if it is unmodified and the editor is not in Edit mode. * * @param tab The tab to close * @param target AjaxRequestTarget */ void onCloseUnmodified(Tab tab, AjaxRequestTarget target) { final IEditor editor = tab.getEditor(); try { if (editor != null && !editor.getMode().equals(IEditor.Mode.EDIT)) { editor.close(); } } catch (EditorException e) { log.warn("Unable to save the document in the editor", e); throw new RuntimeException("Unable to save the document in the editor", e); } }
private void openDocumentEditor(final String documentHandleUuid, final IEditor.Mode mode) { final IEditorManager editorManager = context.getService(editorManagerServiceId, IEditorManager.class); try { final Node documentHandle = UserSession.get().getJcrSession().getNodeByIdentifier(documentHandleUuid); final JcrNodeModel documentHandleModel = new JcrNodeModel(documentHandle); IEditor<?> editor = editorManager.getEditor(documentHandleModel); if (editor == null) { editor = editorManager.openEditor(documentHandleModel); } if (mode == IEditor.Mode.EDIT && editor.getMode() != IEditor.Mode.EDIT) { editor.setMode(mode); } editor.focus(); } catch (ItemNotFoundException e) { ChannelEditor.log.warn("Could not find document with uuid '{}'", documentHandleUuid, e); } catch (EditorException|RepositoryException|ServiceException e) { ChannelEditor.log.warn("Failed to open editor in '{}' mode for document with uuid '{}'", mode, documentHandleUuid, e); } } }