Page 1 of 1

Set GRID page not editable

Posted: Thu Sep 10, 2015 6:07 pm
by sebastienlavandier
Hello,

I want to know how I must cast the editorAccess.getCurrentPage() to set grid page not editable ?

Code: Select all

if (url != null) {
final boolean isEditable = EditorTabsMap.getInstance().get(url).isEditable();
WSEditor editorAccess = pluginWorkspaceAccess.getEditorAccess(url, PluginWorkspace.MAIN_EDITING_AREA);
if (editorAccess != null) {
if (EditorPageConstants.PAGE_AUTHOR.equals(editorAccess.getCurrentPageID())) {
((WSAuthorEditorPage) editorAccess.getCurrentPage()).setEditable(isEditable);
} else if (EditorPageConstants.PAGE_TEXT.equals(editorAccess.getCurrentPageID())) {
((WSTextEditorPage) editorAccess.getCurrentPage()).setEditable(isEditable);
} else if (EditorPageConstants.PAGE_GRID.equals(editorAccess.getCurrentPageID())) {
?????
}
}
}
Thanks in advance for your help.
Sébastien.L

Re: Set GRID page not editable

Posted: Fri Sep 11, 2015 4:54 pm
by alex_jitianu
Hello,

Unfortunately the Grid page doesn't have this API. If you don't really need the Grid page, as a workaround, you could stop the author going into it by using one of the following approaches:
1. by using an WSEditorChangeListener you can listen for page change events. When the active page is the grid page you can automatically switch to another page (by calling WSEditor.changePage(String)).
2. you can look inside the components hierarchy and identify and disable the button that switches to Grid page. Is not really API but it should work. The code below does this but you will also have to handle the case when the user is in the text page (and start the search from ro.sync.exml.workspace.api.editor.page.text.WSTextEditorPage.getTextComponent()) or in the grid page (and switch to a different page)

Code: Select all


if (EditorPageConstants.PAGE_GRID.equals(editorAccess.getCurrentPageID())) {
WSEditorPage currentPage = editorAccess.getCurrentPage();
if (currentPage instanceof WSAuthorEditorPage) {
final WSAuthorEditorPage authorEditorPage = (WSAuthorEditorPage) currentPage;
JComponent comp = (JComponent) authorEditorPage.getAuthorComponent();

AbstractButton pageSwitchButton = getPageSwitchButton(comp, "Grid");
pageSwitchButton.setEnabled(false);
}
}

private AbstractButton getPageSwitchButton(Container component, String text) {
AbstractButton toReturn = null;

Container parent = component.getParent();
int componentCount = parent.getComponentCount();
for (int i = 0; i < componentCount; i++) {
Component candidate = parent.getComponent(i);
if (candidate != component) {
toReturn = goDeep(candidate, text);
if (toReturn != null) {
break;
}
}
}

if (toReturn == null) {
toReturn = getPageSwitchButton(parent, text);
}

return toReturn;
}

private AbstractButton goDeep(Component candidate, String text) {
AbstractButton toReturn = null;

if (candidate instanceof AbstractButton && text.equals(((AbstractButton) candidate).getText())) {
toReturn = (AbstractButton) candidate;
} else if (candidate instanceof JComponent) {
int componentCount = ((JComponent) candidate).getComponentCount();
for (int i = 0; i < componentCount; i++) {
toReturn = goDeep(((JComponent) candidate).getComponent(i), text);
if (toReturn != null) {
break;
}
}
}

return toReturn;
}
Best regards,
Alex

Re: Set GRID page not editable

Posted: Wed Sep 16, 2015 4:15 pm
by sebastienlavandier
It works.
It's a solution.
Thanks for you your help.

Sébastien.L