use of org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage in project scout.rt by eclipse.
the class JsonOutlineTest method testPageDisposalOnRemoveAllNested.
@Test
public void testPageDisposalOnRemoveAllNested() throws JSONException {
NodePage nodePage = new NodePage();
nodePage.getCellForUpdate().setText("node");
// trigger table creation
nodePage.getTable(true);
NodePage childPage = new NodePage();
childPage.getCellForUpdate().setText("child");
// trigger table creation
childPage.getTable(true);
List<IPage<?>> pages = new ArrayList<IPage<?>>();
pages.add(nodePage);
IOutline outline = new Outline(pages);
outline.addChildNode(nodePage, childPage);
JsonOutline<IOutline> jsonOutline = UiSessionTestUtility.newJsonAdapter(m_uiSession, outline, null);
// Assert that pages have an id
String nodeId = JsonTreeTest.getOrCreateNodeId(jsonOutline, nodePage);
assertNotNull(nodeId);
assertNotNull(JsonTreeTest.getNode(jsonOutline, nodeId));
String childId = JsonTreeTest.getOrCreateNodeId(jsonOutline, childPage);
assertNotNull(childId);
assertNotNull(JsonTreeTest.getNode(jsonOutline, childId));
// Assert that adapters for table have been created
assertNotNull(m_uiSession.getJsonAdapter(nodePage.getTable(), m_uiSession.getRootJsonAdapter()));
assertNotNull(m_uiSession.getJsonAdapter(childPage.getTable(), m_uiSession.getRootJsonAdapter()));
outline.setTreeChanging(true);
// First remove all child nodes of the node page
outline.removeAllChildNodes(nodePage);
// Then remove all child nodes of the root page
outline.removeAllChildNodes(outline.getRootNode());
// Finally fire the events -> event buffer will remove the first event, but JsonOutline must dispose the children of nodePage anyway. That is why JsonTree keeps track of the child/parent link by itself.
outline.setTreeChanging(false);
JsonTestUtility.processBufferedEvents(m_uiSession);
// Assert that pages have been disposed
assertNull(JsonTreeTest.getNode(jsonOutline, nodeId));
assertNull(JsonTreeTest.getNode(jsonOutline, childId));
// Assert that tables have been disposed
assertNull(m_uiSession.getJsonAdapter(nodePage.getTable(), m_uiSession.getRootJsonAdapter()));
assertNull(m_uiSession.getJsonAdapter(childPage.getTable(), m_uiSession.getRootJsonAdapter()));
}
use of org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage in project scout.rt by eclipse.
the class JsonOutline method treeNodeToJson.
@Override
protected JSONObject treeNodeToJson(ITreeNode node) {
if (!(node instanceof IPage)) {
throw new IllegalArgumentException("Expected node to be a page. " + node);
}
IPage page = (IPage) node;
JSONObject json = super.treeNodeToJson(node);
putDetailFormAndTable(json, page);
putNodeType(json, node);
BEANS.get(InspectorInfo.class).put(getUiSession(), json, page);
return json;
}
use of org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage in project scout.rt by eclipse.
the class JsonOutline method handleModelPageChanged.
protected void handleModelPageChanged(OutlineEvent event) {
IPage page = (IPage) event.getNode();
if (!isNodeAccepted(page)) {
return;
}
attachNode(page, false);
String nodeId = optNodeId(page);
if (nodeId == null) {
// Ignore nodes that are not yet sent to the UI (may happen due to asynchronous event processing)
return;
}
JSONObject jsonEvent = new JSONObject();
putProperty(jsonEvent, PROP_NODE_ID, getOrCreateNodeId(page));
putDetailFormAndTable(jsonEvent, page);
addActionEvent("pageChanged", jsonEvent);
}
use of org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage in project scout.rt by eclipse.
the class BookmarkUtility method resolvePage.
public static IPage<?> resolvePage(List<? extends IPage> pages, String className, String bookmarkIdentifier) {
if (className == null) {
return null;
}
TreeMap<CompositeObject, IPage> sortMap = new TreeMap<CompositeObject, IPage>();
String simpleClassName = className.replaceAll("^.*\\.", "");
int index = 0;
for (IPage<?> p : pages) {
int classNameScore = 0;
int userPreferenceContextScore = 0;
if (p.getClass().getName().equals(className)) {
classNameScore = -2;
} else if (p.getClass().getSimpleName().equalsIgnoreCase(simpleClassName)) {
classNameScore = -1;
}
IBookmarkAdapter bookmarkAdapter = getBookmarkAdapter(p);
if (bookmarkIdentifier == null || bookmarkIdentifier.equalsIgnoreCase(bookmarkAdapter.getIdentifier())) {
userPreferenceContextScore = -1;
}
if (classNameScore != 0 && userPreferenceContextScore != 0) {
sortMap.put(new CompositeObject(classNameScore, userPreferenceContextScore, index), p);
}
index++;
}
if (sortMap.isEmpty()) {
return null;
}
CompositeObject bestMatchingKey = sortMap.firstKey();
IPage<?> bestMatchingPage = sortMap.remove(bestMatchingKey);
if (!sortMap.isEmpty()) {
// check ambiguity
CompositeObject nextKey = sortMap.firstKey();
if (ObjectUtility.equals(bestMatchingKey.getComponent(0), nextKey.getComponent(0)) && ObjectUtility.equals(bestMatchingKey.getComponent(1), nextKey.getComponent(1))) {
LOG.warn("More than one pages found for page class [{}] and bookmark Identifier [{}]", className, bookmarkIdentifier);
}
}
return bestMatchingPage;
}
use of org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage in project scout.rt by eclipse.
the class BookmarkUtility method createBookmark.
@SuppressWarnings("squid:S1643")
public static Bookmark createBookmark(IPage<?> page) {
if (page == null || page.getOutline() == null) {
return null;
}
IBookmarkAdapter bookmarkAdapter = getBookmarkAdapter(page);
IOutline outline = page.getOutline();
Bookmark b = new Bookmark();
b.setIconId(bookmarkAdapter.getIconId());
// outline
b.setOutlineClassName(bookmarkAdapter.getOutlineClassName());
ArrayList<IPage<?>> path = new ArrayList<IPage<?>>();
ArrayList<String> titleSegments = new ArrayList<String>();
while (page != null) {
IBookmarkAdapter currentBookmarkAdapter = getBookmarkAdapter(page);
path.add(0, page);
String s = currentBookmarkAdapter.getTitle();
if (s != null) {
titleSegments.add(0, s);
}
// next
page = (IPage) page.getParentNode();
}
if (bookmarkAdapter.getOutlineTitle() != null) {
titleSegments.add(0, bookmarkAdapter.getOutlineTitle());
}
// title
int len = 0;
if (titleSegments.size() > 0) {
len += titleSegments.get(0).length();
}
if (titleSegments.size() > 1) {
len += titleSegments.get(titleSegments.size() - 1).length();
}
for (int i = titleSegments.size() - 1; i > 0; i--) {
if (len > 200) {
titleSegments.remove(i);
} else if (len + titleSegments.get(i).length() <= 200) {
len += titleSegments.get(i).length();
} else {
titleSegments.set(i, "...");
len = 201;
}
}
StringBuilder buf = new StringBuilder();
for (String s : titleSegments) {
if (buf.length() > 0) {
buf.append(" - ");
}
buf.append(s);
}
b.setTitle(buf.toString());
// text
StringBuilder text = new StringBuilder();
// add constraints texts
String prefix = "";
for (int i = 0; i < path.size(); i++) {
page = path.get(i);
IBookmarkAdapter currentBookmarkAdapter = getBookmarkAdapter(page);
if (i > 0 || outline.isRootNodeVisible()) {
text.append(prefix + currentBookmarkAdapter.getText());
text.append("\n");
if (page instanceof IPageWithTable) {
IPageWithTable tablePage = (IPageWithTable) page;
SearchFilter search = tablePage.getSearchFilter();
if (search != null) {
for (String s : search.getDisplayTexts()) {
if (s != null) {
String indent = prefix + " ";
s = s.trim().replaceAll("[\\n]", "\n" + indent);
if (s.length() > 0) {
text.append(indent + s);
text.append("\n");
}
}
}
}
}
prefix += " ";
}
}
b.setText(text.toString().trim());
// path
for (int i = 0; i < path.size(); i++) {
page = path.get(i);
if (page instanceof IPageWithTable) {
IPageWithTable tablePage = (IPageWithTable) page;
IPage<?> childPage = null;
if (i + 1 < path.size()) {
childPage = path.get(i + 1);
}
b.addPathElement(bmStoreTablePage(tablePage, childPage));
} else if (page instanceof IPageWithNodes) {
IPageWithNodes nodePage = (IPageWithNodes) page;
b.addPathElement(bmStoreNodePage(nodePage));
}
}
return b;
}
Aggregations