use of org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark in project scout.rt by eclipse.
the class AbstractPage method execDataChanged.
/**
* Called by the data change listener registered with this page (and the current desktop) through
* {@link #registerDataChangeListener(Object...)}. Use this callback method to react to data change events by
* reloading current data, or throwing away cached data etc.
* <p>
* Subclasses can override this method.<br/>
* This default implementation does the following:
* <ol>
* <li>if this page is an ancestor of the selected page (or is selected itself) and this page is in the active
* outline, a full re-load of the page is performed
* <li>else the children of this page are marked dirty and the page itself is unloaded
* </ol>
*
* @see IDesktop#dataChanged(Object...)
*/
@ConfigOperation
@Order(55)
protected void execDataChanged(Object... dataTypes) {
if (getTree() == null) {
return;
}
//
HashSet<ITreeNode> pathsToSelections = new HashSet<ITreeNode>();
for (ITreeNode node : getTree().getSelectedNodes()) {
ITreeNode tmp = node;
while (tmp != null) {
pathsToSelections.add(tmp);
tmp = tmp.getParentNode();
}
}
IDesktop desktop = ClientSessionProvider.currentSession().getDesktop();
final boolean isActiveOutline = (desktop != null ? desktop.getOutline() == this.getOutline() : false);
final boolean isRootNode = pathsToSelections.isEmpty() && getTree() != null && getTree().getRootNode() == this;
if (isActiveOutline && (pathsToSelections.contains(this) || isRootNode)) {
try {
// TODO [7.0] fko: maybe remove when bookmarks can be done on outline level? (currently only pages)
if (isRootNode) {
this.reloadPage();
} else /*
* Ticket 77332 (deleting a node in the tree) also requires a reload So
* the selected and its ancestor nodes require same processing
*/
if (desktop != null) {
// NOSONAR
Bookmark bm = desktop.createBookmark();
setChildrenDirty(true);
// activate bookmark without activating the outline, since this would hide active tabs.
desktop.activateBookmark(bm, false);
}
} catch (RuntimeException | PlatformError e) {
BEANS.get(ExceptionHandler.class).handle(e);
}
} else {
// not active outline OR not on selection path
setChildrenDirty(true);
if (isExpanded()) {
setExpanded(false);
}
try {
if (isChildrenLoaded()) {
getTree().unloadNode(this);
}
} catch (RuntimeException | PlatformError e) {
BEANS.get(ExceptionHandler.class).handle(e);
}
}
}
use of org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark in project scout.rt by eclipse.
the class BookmarkToInvisibleOutlineTest method testBookmarkToInvisibleOutline.
@Test
public void testBookmarkToInvisibleOutline() throws Exception {
IDesktop desktop = TestEnvironmentClientSession.get().getDesktop();
desktop.setAvailableOutlines(CollectionUtility.arrayList(new CockpitOutline(), new AdminOutline()));
desktop.setOutline(CockpitOutline.class);
Bookmark bm = desktop.createBookmark();
//
desktop.setOutline(AdminOutline.class);
desktop.findOutline(CockpitOutline.class).setVisible(false);
Thread.sleep(400);
Exception err = null;
try {
desktop.activateBookmark(bm);
} catch (Exception e) {
err = e;
}
assertNotNull(err);
assertEquals(desktop.findOutline(AdminOutline.class), desktop.getOutline());
}
use of org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark 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;
}
use of org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark in project scout.rt by eclipse.
the class BookmarkService method setStartBookmark.
@Override
public void setStartBookmark() {
ServiceState state = getServiceState();
Bookmark b = ClientSessionProvider.currentSession().getDesktop().createBookmark();
if (b != null) {
b.setKind(Bookmark.USER_BOOKMARK);
state.m_model.getUserBookmarks().setStartupBookmark(b);
}
}
use of org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark in project scout.rt by eclipse.
the class BookmarkService method updateBookmark.
@Override
public void updateBookmark(Bookmark bm) {
// Create a new bookmark from the current view:
Bookmark newBookmark = ClientSessionProvider.currentSession().getDesktop().createBookmark();
// We want to preserve certain aspects of the old bookmark:
int cachedKind = bm.getKind();
String cachedIconId = bm.getIconId();
String cachedTitle = bm.getTitle();
String cachedKeyStroke = bm.getKeyStroke();
double cachedOrder = bm.getOrder();
// Fill the old bookmark with the data from the new one:
bm.setSerializedData(newBookmark.getSerializedData());
// "setSerializedData" overwrites all attributes - restore them from the old bookmark:
bm.setKind(cachedKind);
bm.setIconId(cachedIconId);
bm.setTitle(cachedTitle);
bm.setKeyStroke(cachedKeyStroke);
bm.setOrder(cachedOrder);
// The bookmark's "text" should not be preserved - it is not editable by
// the user and the only way to tell what the bookmark does.
}
Aggregations