Search in sources :

Example 6 with Bookmark

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);
        }
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) Bookmark(org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) HashSet(java.util.HashSet) Order(org.eclipse.scout.rt.platform.Order) ConfigOperation(org.eclipse.scout.rt.platform.annotations.ConfigOperation)

Example 7 with Bookmark

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());
}
Also used : Bookmark(org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) Test(org.junit.Test)

Example 8 with Bookmark

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;
}
Also used : IPageWithTable(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithTable) IBookmarkAdapter(org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkAdapter) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) ArrayList(java.util.ArrayList) SearchFilter(org.eclipse.scout.rt.shared.services.common.jdbc.SearchFilter) IPage(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage) Bookmark(org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark) IPageWithNodes(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithNodes)

Example 9 with Bookmark

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);
    }
}
Also used : Bookmark(org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark)

Example 10 with Bookmark

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.
}
Also used : Bookmark(org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark)

Aggregations

Bookmark (org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark)15 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 BookmarkFolder (org.eclipse.scout.rt.shared.services.common.bookmark.BookmarkFolder)4 IBookmarkService (org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkService)3 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)2 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)2 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 IBookmarkAdapter (org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkAdapter)1 AbstractMenuSeparator (org.eclipse.scout.rt.client.ui.action.menu.AbstractMenuSeparator)1 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)1 MenuSeparator (org.eclipse.scout.rt.client.ui.action.menu.MenuSeparator)1 ITreeVisitor (org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)1 BookmarkForm (org.eclipse.scout.rt.client.ui.desktop.bookmark.BookmarkForm)1 IBookmarkForm (org.eclipse.scout.rt.client.ui.desktop.bookmark.IBookmarkForm)1 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)1