Search in sources :

Example 1 with IPageWithNodes

use of org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithNodes in project scout.rt by eclipse.

the class DefaultPageChangeStrategy method pageChanged.

@Override
public void pageChanged(final IOutline outline, final IPage<?> deselectedPage, final IPage<?> selectedPage) {
    if (outline == null) {
        return;
    }
    outline.clearContextPage();
    IForm detailForm = null;
    ITable detailTable = null;
    ISearchForm searchForm = null;
    // new active page
    outline.makeActivePageToContextPage();
    IPage<?> activePage = outline.getActivePage();
    if (activePage != null) {
        try {
            activePage.ensureChildrenLoaded();
        } catch (RuntimeException | PlatformError e1) {
            BEANS.get(ExceptionHandler.class).handle(e1);
        }
        if (activePage instanceof IPageWithTable) {
            IPageWithTable tablePage = (IPageWithTable) activePage;
            detailForm = activePage.getDetailForm();
            if (activePage.isTableVisible()) {
                detailTable = tablePage.getTable(false);
            }
            if (tablePage.isSearchActive()) {
                searchForm = tablePage.getSearchFormInternal();
            }
        } else if (activePage instanceof IPageWithNodes) {
            IPageWithNodes nodePage = (IPageWithNodes) activePage;
            if (activePage.isDetailFormVisible()) {
                detailForm = activePage.getDetailForm();
            }
            if (activePage.isTableVisible()) {
                detailTable = nodePage.getTable(false);
            }
        }
    }
    // remove first
    if (detailForm == null) {
        outline.setDetailForm(null);
    }
    if (detailTable == null) {
        outline.setDetailTable(null);
    }
    if (searchForm == null) {
        outline.setSearchForm(null);
    }
    // add new
    if (detailForm != null) {
        outline.setDetailForm(detailForm);
    }
    if (detailTable != null) {
        outline.setDetailTable(detailTable);
    }
    if (searchForm != null) {
        outline.setSearchForm(searchForm);
    }
}
Also used : IPageWithTable(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithTable) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IPageWithNodes(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithNodes) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) IForm(org.eclipse.scout.rt.client.ui.form.IForm) ISearchForm(org.eclipse.scout.rt.client.ui.desktop.outline.pages.ISearchForm)

Example 2 with IPageWithNodes

use of org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithNodes in project scout.rt by eclipse.

the class BookmarkUtility method activateBookmark.

/**
 * Load a {@link Bookmark} on the specified {@link IDesktop} model.
 * <p>
 * First the specific {@link Bookmark#getOutlineClassName()} is evaluated and, if activateOutline is true, activated.
 * Afterwards every page from the {@link Bookmark#getPath()} will be selected (respecting the
 * {@link AbstractPageState}).
 * </p>
 * Finally the path will be expanded. Possible exceptions might occur if no outline is set in the {@link Bookmark} or
 * the outline is not available.
 */
public static void activateBookmark(IDesktop desktop, Bookmark bm, boolean activateOutline) {
    if (bm.getOutlineClassName() == null) {
        return;
    }
    IOutline outline = BookmarkUtility.resolveOutline(desktop.getAvailableOutlines(), bm.getOutlineClassName());
    if (outline == null) {
        throw new ProcessingException("outline '" + bm.getOutlineClassName() + "' was not found");
    }
    if (!(outline.isVisible() && outline.isEnabled())) {
        throw new VetoException(TEXTS.get("BookmarkActivationFailedOutlineNotAvailable", outline.getTitle()));
    }
    if (activateOutline) {
        desktop.activateOutline(outline);
    }
    try {
        outline.setTreeChanging(true);
        // 
        IPage<?> parentPage = outline.getRootPage();
        boolean pathFullyRestored = true;
        List<AbstractPageState> path = bm.getPath();
        AbstractPageState parentPageState = path.get(0);
        boolean resetViewAndWarnOnFail = bm.getId() != 0;
        for (int i = 1; i < path.size(); i++) {
            // try to find correct child page (next parentPage)
            IPage<?> childPage = null;
            AbstractPageState childState = path.get(i);
            if (parentPageState instanceof TablePageState) {
                TablePageState tablePageState = (TablePageState) parentPageState;
                if (parentPage instanceof IPageWithTable) {
                    IPageWithTable tablePage = (IPageWithTable) parentPage;
                    childPage = bmLoadTablePage(tablePage, tablePageState, false, resetViewAndWarnOnFail);
                }
            } else if (parentPageState instanceof NodePageState) {
                NodePageState nodePageState = (NodePageState) parentPageState;
                if (parentPage instanceof IPageWithNodes) {
                    IPageWithNodes nodePage = (IPageWithNodes) parentPage;
                    childPage = bmLoadNodePage(nodePage, nodePageState, childState, resetViewAndWarnOnFail);
                }
            }
            // next
            if (childPage != null) {
                parentPage = childPage;
                parentPageState = childState;
            } else if (i < path.size()) {
                pathFullyRestored = false;
                break;
            }
        }
        if (pathFullyRestored) {
            if (parentPageState instanceof TablePageState && parentPage instanceof IPageWithTable) {
                bmLoadTablePage((IPageWithTable) parentPage, (TablePageState) parentPageState, true, resetViewAndWarnOnFail);
            } else if (parentPage instanceof IPageWithNodes) {
                bmLoadNodePage((IPageWithNodes) parentPage, (NodePageState) parentPageState, null, resetViewAndWarnOnFail);
            }
        }
        /*
       * Expansions of the restored tree path
       */
        IPage<?> p = parentPage;
        // last element
        if (pathFullyRestored && parentPageState.isExpanded() != null) {
            p.setExpanded(parentPageState.isExpanded());
        } else {
            if (!(p instanceof IPageWithTable)) {
                p.setExpanded(true);
            }
        }
        // ancestor elements
        p = p.getParentPage();
        while (p != null) {
            p.setExpanded(true);
            p = p.getParentPage();
        }
        outline.selectNode(parentPage, false);
    } finally {
        outline.setTreeChanging(false);
    }
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) AbstractPageState(org.eclipse.scout.rt.shared.services.common.bookmark.AbstractPageState) IPageWithTable(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithTable) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) IPageWithNodes(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithNodes) NodePageState(org.eclipse.scout.rt.shared.services.common.bookmark.NodePageState) TablePageState(org.eclipse.scout.rt.shared.services.common.bookmark.TablePageState) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 3 with IPageWithNodes

use of org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithNodes 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)

Aggregations

IPageWithNodes (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithNodes)3 IPageWithTable (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithTable)3 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)2 ArrayList (java.util.ArrayList)1 IBookmarkAdapter (org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkAdapter)1 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)1 IPage (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage)1 ISearchForm (org.eclipse.scout.rt.client.ui.desktop.outline.pages.ISearchForm)1 IForm (org.eclipse.scout.rt.client.ui.form.IForm)1 PlatformError (org.eclipse.scout.rt.platform.exception.PlatformError)1 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)1 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)1 AbstractPageState (org.eclipse.scout.rt.shared.services.common.bookmark.AbstractPageState)1 Bookmark (org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark)1 NodePageState (org.eclipse.scout.rt.shared.services.common.bookmark.NodePageState)1 TablePageState (org.eclipse.scout.rt.shared.services.common.bookmark.TablePageState)1 SearchFilter (org.eclipse.scout.rt.shared.services.common.jdbc.SearchFilter)1