Search in sources :

Example 46 with ITable

use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.

the class OrganizeColumnsFormTest method testNoNPEInExecDrop.

@Test
public void testNoNPEInExecDrop() {
    ITable table = mock(ITable.class);
    List<ITableRow> list = new LinkedList<ITableRow>();
    list.add(mock(ITableRow.class));
    JavaTransferObject transfer = mock(JavaTransferObject.class);
    when(transfer.getLocalObjectAsList(ITableRow.class)).thenReturn(list);
    OrganizeColumnsForm form = new OrganizeColumnsForm(table);
    try {
        form.getColumnsTableField().getTable().execDrop(null, null);
        form.getColumnsTableField().getTable().execDrop(null, transfer);
        form.getColumnsTableField().getTable().execDrop(mock(ITableRow.class), null);
    } catch (NullPointerException e) {
        fail("Null-Argument should not lead to NullPointerException " + e);
    }
}
Also used : ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) JavaTransferObject(org.eclipse.scout.rt.client.ui.dnd.JavaTransferObject) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 47 with ITable

use of org.eclipse.scout.rt.client.ui.basic.table.ITable 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 48 with ITable

use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.

the class BookmarkUtility method bmLoadTablePage.

private static IPage<?> bmLoadTablePage(IPageWithTable tablePage, TablePageState tablePageState, boolean leafState, boolean resetViewAndWarnOnFail) {
    ITable table = tablePage.getTable();
    if (tablePageState.getTableCustomizerData() != null && tablePage.getTable().getTableCustomizer() != null) {
        byte[] newData = tablePageState.getTableCustomizerData();
        ITableCustomizer tc = tablePage.getTable().getTableCustomizer();
        byte[] curData = tc.getSerializedData();
        if (ObjectUtility.notEquals(curData, newData)) {
            tc.removeAllColumns();
            tc.setSerializedData(newData);
            table.resetColumnConfiguration();
            tablePage.setChildrenLoaded(false);
        }
    }
    // starts search form
    tablePage.getSearchFilter();
    // setup table
    try {
        table.setTableChanging(true);
        restoreTableColumns(tablePage.getTable(), tablePageState.getAvailableColumns());
    } finally {
        table.setTableChanging(false);
    }
    // setup user filter
    if (tablePageState.getUserFilterData() != null && tablePage.getTable().getUserFilterManager() != null) {
        byte[] newData = tablePageState.getUserFilterData();
        TableUserFilterManager ufm = tablePage.getTable().getUserFilterManager();
        byte[] curData = ufm.getSerializedData();
        if (ObjectUtility.notEquals(curData, newData)) {
            try {
                ufm.setSerializedData(newData);
            } catch (RuntimeException e) {
                LOG.error("User filters could not be restored. ", e);
            }
        }
    }
    // setup search
    if (tablePageState.getSearchFormState() != null) {
        ISearchForm searchForm = tablePage.getSearchFormInternal();
        if (searchForm != null) {
            boolean doSearch = true;
            String newSearchFilterState = tablePageState.getSearchFilterState();
            String oldSearchFilterState = "" + createSearchFilterCRC(searchForm.getSearchFilter());
            if (ObjectUtility.equals(oldSearchFilterState, newSearchFilterState)) {
                String newSearchFormState = tablePageState.getSearchFormState();
                String oldSearchFormState = searchForm.storeToXmlString();
                if (ObjectUtility.equals(oldSearchFormState, newSearchFormState)) {
                    doSearch = false;
                }
            }
            // in case search form is in correct state, but no search has been executed, force search
            if (tablePage.getTable().getRowCount() == 0) {
                doSearch = true;
            }
            if (doSearch) {
                searchForm.loadFromXmlString(tablePageState.getSearchFormState());
                if (tablePageState.isSearchFilterComplete()) {
                    searchForm.doSaveWithoutMarkerChange();
                }
            }
        }
    }
    IPage<?> childPage = null;
    boolean loadChildren = !leafState;
    if (tablePage.isChildrenDirty() || tablePage.isChildrenVolatile()) {
        loadChildren = true;
        tablePage.setChildrenLoaded(false);
    }
    if (loadChildren) {
        tablePage.ensureChildrenLoaded();
        tablePage.setChildrenDirty(false);
        CompositeObject childPk = tablePageState.getExpandedChildPrimaryKey();
        if (childPk != null) {
            for (int r = 0; r < table.getRowCount(); r++) {
                CompositeObject testPkLegacy = new CompositeObject(BookmarkUtility.makeSerializableKeys(table.getRowKeys(r), true));
                CompositeObject testPk = new CompositeObject(BookmarkUtility.makeSerializableKeys(table.getRowKeys(r), false));
                if (testPk.equals(childPk) || testPkLegacy.equals(childPk)) {
                    if (r < tablePage.getChildNodeCount()) {
                        childPage = tablePage.getChildPage(r);
                    }
                    break;
                }
            }
        } else {
            List<ITreeNode> filteredChildNodes = tablePage.getFilteredChildNodes();
            if (filteredChildNodes.size() > 0) {
                childPage = (IPage) CollectionUtility.firstElement(filteredChildNodes);
            } else if (tablePage.getChildNodeCount() > 0) {
                childPage = tablePage.getChildPage(0);
            }
        }
    }
    // load selections
    if (leafState) {
        if (tablePageState.getSelectedChildrenPrimaryKeys().size() > 0) {
            tablePage.ensureChildrenLoaded();
            HashSet<CompositeObject> selectionSet = new HashSet<CompositeObject>(tablePageState.getSelectedChildrenPrimaryKeys());
            ArrayList<ITableRow> rowList = new ArrayList<ITableRow>();
            for (ITableRow row : table.getRows()) {
                CompositeObject testPkLegacy = new CompositeObject(BookmarkUtility.makeSerializableKeys(row.getKeyValues(), true));
                CompositeObject testPk = new CompositeObject(BookmarkUtility.makeSerializableKeys(row.getKeyValues(), false));
                if ((selectionSet.contains(testPk) || selectionSet.contains(testPkLegacy)) && row.isFilterAccepted()) {
                    rowList.add(row);
                }
            }
            if (rowList.size() > 0) {
                table.selectRows(rowList);
            }
        }
        return childPage;
    }
    // check, whether table column filter must be reset
    if (resetViewAndWarnOnFail) {
        final boolean childPageHidden = childPage == null || (!childPage.isFilterAccepted() && table.getUserFilterManager() != null);
        if (childPageHidden) {
            table.getUserFilterManager().reset();
            tablePage.setTableStatus(new Status(TEXTS.get("BookmarkResetColumnFilters"), IStatus.WARNING));
        }
    }
    // child page is not available or filtered out
    if (childPage == null || !childPage.isFilterAccepted()) {
        if (resetViewAndWarnOnFail) {
            // set appropriate warning
            if (tablePage.isSearchActive() && tablePage.getSearchFormInternal() != null) {
                tablePage.setTableStatus(new Status(TEXTS.get("BookmarkResolutionCanceledCheckSearchCriteria"), IStatus.ERROR));
            } else {
                tablePage.setTableStatus(new Status(TEXTS.get("BookmarkResolutionCanceled"), IStatus.ERROR));
            }
        }
        childPage = null;
    }
    return childPage;
}
Also used : IStatus(org.eclipse.scout.rt.platform.status.IStatus) Status(org.eclipse.scout.rt.platform.status.Status) ArrayList(java.util.ArrayList) TableUserFilterManager(org.eclipse.scout.rt.client.ui.basic.table.userfilter.TableUserFilterManager) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) CompositeObject(org.eclipse.scout.rt.platform.util.CompositeObject) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ISearchForm(org.eclipse.scout.rt.client.ui.desktop.outline.pages.ISearchForm) ITableCustomizer(org.eclipse.scout.rt.client.ui.basic.table.customizer.ITableCustomizer) HashSet(java.util.HashSet)

Example 49 with ITable

use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.

the class AbstractDesktop method setPageDetailTable.

@Override
public void setPageDetailTable(ITable t) {
    if (m_pageDetailTable != t) {
        ITable oldTable = m_pageDetailTable;
        m_pageDetailTable = t;
        // extensions
        for (IDesktopExtension ext : getDesktopExtensions()) {
            try {
                ContributionCommand cc = ext.pageDetailTableChangedDelegate(oldTable, m_pageDetailTable);
                if (cc == ContributionCommand.Stop) {
                    break;
                }
            } catch (Exception x) {
                LOG.error("extension {}", ext, x);
            }
        }
    }
}
Also used : ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) DeepLinkException(org.eclipse.scout.rt.client.deeplink.DeepLinkException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) VetoException(org.eclipse.scout.rt.platform.exception.VetoException)

Example 50 with ITable

use of org.eclipse.scout.rt.client.ui.basic.table.ITable in project scout.rt by eclipse.

the class OutlineMediator method mediateTreeNodeAction.

public void mediateTreeNodeAction(TreeEvent e, IPageWithTable<? extends ITable> pageWithTable) {
    if (e.isConsumed()) {
        return;
    }
    ITableRow row = pageWithTable.getTableRowFor(e.getNode());
    ITable table = pageWithTable.getTable();
    if (row != null) {
        e.consume();
        /*
       * ticket 78684: this line added
       */
        table.getUIFacade().setSelectedRowsFromUI(CollectionUtility.arrayList(row));
        table.getUIFacade().fireRowActionFromUI(row);
    }
}
Also used : ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow)

Aggregations

ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)89 Test (org.junit.Test)64 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)45 TableWith3Cols (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols)28 JSONObject (org.json.JSONObject)23 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)16 JSONArray (org.json.JSONArray)12 ITableRowFilter (org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter)11 Table (org.eclipse.scout.rt.ui.html.json.table.fixtures.Table)10 ArrayList (java.util.ArrayList)9 ListBoxTable (org.eclipse.scout.rt.ui.html.json.table.fixtures.ListBoxTable)8 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)6 AbstractTable (org.eclipse.scout.rt.client.ui.basic.table.AbstractTable)6 ITableField (org.eclipse.scout.rt.client.ui.form.fields.tablefield.ITableField)5 TableWithLongColumn (org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWithLongColumn)5 IColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)4 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)4 IPageWithTable (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPageWithTable)4 IProposalField (org.eclipse.scout.rt.client.ui.form.fields.smartfield.IProposalField)4 OrderedCollection (org.eclipse.scout.rt.platform.util.collection.OrderedCollection)4