Search in sources :

Example 1 with IBookmarkAdapter

use of org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkAdapter 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;
}
Also used : IPage(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage) CompositeObject(org.eclipse.scout.rt.platform.util.CompositeObject) IBookmarkAdapter(org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkAdapter) TreeMap(java.util.TreeMap)

Example 2 with IBookmarkAdapter

use of org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkAdapter 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)

Example 3 with IBookmarkAdapter

use of org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkAdapter in project scout.rt by eclipse.

the class BookmarkUtility method bmStoreNodePage.

private static NodePageState bmStoreNodePage(IPageWithNodes page) {
    NodePageState state = new NodePageState();
    state.setPageClassName(page.getClass().getName());
    IBookmarkAdapter bookmarkAdapter = getBookmarkAdapter(page);
    state.setBookmarkIdentifier(bookmarkAdapter.getIdentifier());
    state.setLabel(bookmarkAdapter.getText());
    state.setExpanded(page.isExpanded());
    return state;
}
Also used : IBookmarkAdapter(org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkAdapter) NodePageState(org.eclipse.scout.rt.shared.services.common.bookmark.NodePageState)

Example 4 with IBookmarkAdapter

use of org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkAdapter 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

IBookmarkAdapter (org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkAdapter)4 ArrayList (java.util.ArrayList)2 IPage (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage)2 CompositeObject (org.eclipse.scout.rt.platform.util.CompositeObject)2 TreeMap (java.util.TreeMap)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 Bookmark (org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark)1 NodePageState (org.eclipse.scout.rt.shared.services.common.bookmark.NodePageState)1 TableColumnState (org.eclipse.scout.rt.shared.services.common.bookmark.TableColumnState)1 TablePageState (org.eclipse.scout.rt.shared.services.common.bookmark.TablePageState)1 SearchFilter (org.eclipse.scout.rt.shared.services.common.jdbc.SearchFilter)1