Search in sources :

Example 1 with TablePageState

use of org.eclipse.scout.rt.shared.services.common.bookmark.TablePageState 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 2 with TablePageState

use of org.eclipse.scout.rt.shared.services.common.bookmark.TablePageState in project scout.rt by eclipse.

the class BookmarkUtility method bmStoreTablePage.

private static TablePageState bmStoreTablePage(IPageWithTable page, IPage<?> childPage) {
    ITable table = page.getTable();
    TablePageState state = new TablePageState();
    state.setPageClassName(page.getClass().getName());
    IBookmarkAdapter bookmarkAdapter = getBookmarkAdapter(page);
    state.setBookmarkIdentifier(bookmarkAdapter.getIdentifier());
    state.setLabel(bookmarkAdapter.getText());
    state.setExpanded(page.isExpanded());
    IForm searchForm = page.getSearchFormInternal();
    if (searchForm != null) {
        state.setSearchFormState(searchForm.storeToXmlString());
        state.setSearchFilterState(searchForm.getSearchFilter().isCompleted(), "" + createSearchFilterCRC(searchForm.getSearchFilter()));
    }
    if (page.getTable().getTableCustomizer() != null) {
        state.setTableCustomizerData(page.getTable().getTableCustomizer().getSerializedData());
    }
    if (page.getTable().getUserFilterManager() != null) {
        state.setUserFilterData(page.getTable().getUserFilterManager().getSerializedData());
    }
    List<TableColumnState> allColumns = backupTableColumns(page.getTable());
    state.setAvailableColumns(allColumns);
    // 
    ArrayList<CompositeObject> pkList = new ArrayList<CompositeObject>();
    for (ITableRow row : table.getSelectedRows()) {
        pkList.add(new CompositeObject(BookmarkUtility.makeSerializableKeys(row.getKeyValues(), false)));
    }
    state.setSelectedChildrenPrimaryKeys(pkList);
    // 
    if (childPage != null) {
        for (int j = 0; j < table.getRowCount(); j++) {
            if (page.getChildNode(j) == childPage) {
                ITableRow childRow = table.getRow(j);
                state.setExpandedChildPrimaryKey(new CompositeObject(BookmarkUtility.makeSerializableKeys(childRow.getKeyValues(), false)));
                break;
            }
        }
    }
    return state;
}
Also used : CompositeObject(org.eclipse.scout.rt.platform.util.CompositeObject) IBookmarkAdapter(org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkAdapter) ArrayList(java.util.ArrayList) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) IForm(org.eclipse.scout.rt.client.ui.form.IForm) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) TablePageState(org.eclipse.scout.rt.shared.services.common.bookmark.TablePageState) TableColumnState(org.eclipse.scout.rt.shared.services.common.bookmark.TableColumnState)

Aggregations

TablePageState (org.eclipse.scout.rt.shared.services.common.bookmark.TablePageState)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 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)1 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)1 IPageWithNodes (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithNodes)1 IPageWithTable (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithTable)1 IForm (org.eclipse.scout.rt.client.ui.form.IForm)1 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)1 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)1 CompositeObject (org.eclipse.scout.rt.platform.util.CompositeObject)1 AbstractPageState (org.eclipse.scout.rt.shared.services.common.bookmark.AbstractPageState)1 NodePageState (org.eclipse.scout.rt.shared.services.common.bookmark.NodePageState)1 TableColumnState (org.eclipse.scout.rt.shared.services.common.bookmark.TableColumnState)1