use of org.eclipse.scout.rt.platform.util.CompositeObject 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;
}
use of org.eclipse.scout.rt.platform.util.CompositeObject 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;
}
use of org.eclipse.scout.rt.platform.util.CompositeObject in project scout.rt by eclipse.
the class AbstractTable method resetColumnsInternal.
private void resetColumnsInternal(Set<String> options) {
if (options.contains(IResetColumnsOption.SORTING)) {
setSortValid(false);
}
if (options.contains(IResetColumnsOption.ORDER)) {
TreeMap<CompositeObject, IColumn<?>> orderMap = new TreeMap<CompositeObject, IColumn<?>>();
int index = 0;
for (IColumn<?> col : getColumns()) {
if (col.isDisplayable()) {
orderMap.put(new CompositeObject(col.getOrder(), index), col);
index++;
}
}
getColumnSet().setVisibleColumns(orderMap.values());
}
if (options.contains(IResetColumnsOption.VISIBILITY)) {
ArrayList<IColumn<?>> list = new ArrayList<IColumn<?>>();
for (IColumn<?> col : getColumnSet().getAllColumnsInUserOrder()) {
if (col.isDisplayable()) {
boolean configuredVisible = ((AbstractColumn<?>) col).isInitialVisible();
if (configuredVisible) {
list.add(col);
}
}
}
getColumnSet().setVisibleColumns(list);
}
if (options.contains(IResetColumnsOption.SORTING)) {
getColumnSet().resetSortingAndGrouping();
}
if (options.contains(IResetColumnsOption.WIDTHS)) {
for (IColumn<?> col : getColumns()) {
if (col.isDisplayable()) {
col.setWidth(col.getInitialWidth());
}
}
}
if (options.contains(IResetColumnsOption.BACKGROUND_EFFECTS)) {
for (IColumn<?> col : getColumns()) {
if (col instanceof INumberColumn) {
((INumberColumn) col).setBackgroundEffect(((INumberColumn) col).getInitialBackgroundEffect());
}
}
}
if (options.contains(IResetColumnsOption.FILTERS)) {
removeUserRowFilters();
}
}
use of org.eclipse.scout.rt.platform.util.CompositeObject in project scout.rt by eclipse.
the class AbstractTable method handleKeyStroke.
protected boolean handleKeyStroke(String keyName, char keyChar) {
if (keyName == null) {
return false;
}
keyName = keyName.toLowerCase();
// check if there is no menu keystroke with that name
for (IMenu m : getMenus()) {
if (m.getKeyStroke() != null && m.getKeyStroke().equalsIgnoreCase(keyName)) {
return false;
}
}
// check if there is no keystroke with that name (ticket 78234)
for (IKeyStroke k : getKeyStrokes()) {
if (k.getKeyStroke() != null && k.getKeyStroke().equalsIgnoreCase(keyName)) {
return false;
}
}
if (keyChar > ' ' && (!keyName.contains("control")) && (!keyName.contains("ctrl")) && (!keyName.contains("alt"))) {
// select first/next line with corresponding character
String newText = "" + Character.toLowerCase(keyChar);
m_keyStrokeBuffer.append(newText);
String prefix = m_keyStrokeBuffer.getText();
IColumn<?> col = getContextColumn();
if (col == null) {
List<IColumn<?>> sortCols = getColumnSet().getSortColumns();
if (sortCols.size() > 0) {
col = CollectionUtility.lastElement(sortCols);
} else {
TreeMap<CompositeObject, IColumn<?>> sortMap = new TreeMap<CompositeObject, IColumn<?>>();
int index = 0;
for (IColumn<?> c : getColumnSet().getVisibleColumns()) {
if (c.getDataType() == String.class) {
sortMap.put(new CompositeObject(1, index), c);
} else if (c.getDataType() == Boolean.class) {
sortMap.put(new CompositeObject(3, index), c);
} else {
sortMap.put(new CompositeObject(2, index), c);
}
index++;
}
if (sortMap.size() > 0) {
col = sortMap.get(sortMap.firstKey());
}
}
}
if (col != null) {
int colIndex = col.getColumnIndex();
String pattern = StringUtility.toRegExPattern(prefix.toLowerCase());
pattern = pattern + ".*";
if (LOG.isInfoEnabled()) {
LOG.info("finding regex: '{}' in column '{}'", pattern, getColumnSet().getColumn(colIndex).getHeaderCell().getText());
}
// loop over values and find matching one
int rowCount = getRowCount();
ITableRow selRow = getSelectedRow();
int startIndex = 0;
if (selRow != null) {
if (prefix.length() <= 1) {
startIndex = selRow.getRowIndex() + 1;
} else {
startIndex = selRow.getRowIndex();
}
}
for (int i = 0; i < rowCount; i++) {
ITableRow row = m_rows.get((startIndex + i) % rowCount);
String text = row.getCell(colIndex).getText();
if (text != null && text.toLowerCase().matches(pattern)) {
// handled
selectRow(row, false);
return true;
}
}
}
}
return false;
}
use of org.eclipse.scout.rt.platform.util.CompositeObject in project scout.rt by eclipse.
the class AbstractTable method replaceRowsCase2.
/**
* Replace rows by applying insert/update/delete on existing rows by primary key match
*/
private void replaceRowsCase2(List<? extends ITableRow> newRows) {
try {
setTableChanging(true);
//
int[] oldToNew = new int[getRowCount()];
int[] newToOld = new int[newRows.size()];
Arrays.fill(oldToNew, -1);
Arrays.fill(newToOld, -1);
HashMap<CompositeObject, Integer> newRowIndexMap = new HashMap<CompositeObject, Integer>();
for (int i = newRows.size() - 1; i >= 0; i--) {
newRowIndexMap.put(new CompositeObject(getRowKeys(newRows.get(i))), Integer.valueOf(i));
}
int mappedCount = 0;
for (int i = 0, ni = getRowCount(); i < ni; i++) {
ITableRow existingRow = m_rows.get(i);
Integer newIndex = newRowIndexMap.remove(new CompositeObject(getRowKeys(existingRow)));
if (newIndex != null) {
oldToNew[i] = newIndex.intValue();
newToOld[newIndex.intValue()] = i;
mappedCount++;
}
}
List<ITableRow> updatedRows = new ArrayList<ITableRow>(mappedCount);
for (int i = 0; i < oldToNew.length; i++) {
if (oldToNew[i] >= 0) {
ITableRow existingRow = getRow(i);
ITableRow newRow = newRows.get(oldToNew[i]);
replaceRowValues(existingRow, newRow);
updatedRows.add(existingRow);
}
}
List<ITableRow> deletedRows = new ArrayList<ITableRow>(getRowCount() - mappedCount);
for (int i = 0; i < oldToNew.length; i++) {
if (oldToNew[i] < 0) {
deletedRows.add(m_rows.get(i));
}
}
List<ITableRow> insertedRows = new ArrayList<ITableRow>(newRows.size() - mappedCount);
int[] insertedRowIndexes = new int[newRows.size() - mappedCount];
int index = 0;
for (int i = 0; i < newToOld.length; i++) {
if (newToOld[i] < 0) {
insertedRows.add(newRows.get(i));
insertedRowIndexes[index] = i;
index++;
}
}
//
updateRows(updatedRows);
deleteRows(deletedRows);
addRows(insertedRows, false, insertedRowIndexes);
} finally {
setTableChanging(false);
}
}
Aggregations