use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method getStyleAttributeForListItem.
private String getStyleAttributeForListItem(ListItem<IRecordInternal> listItem, boolean isSelected, ISupportRowStyling.ATTRIBUTE rowStyleAttribute, boolean asInlineCSSString) {
String listItemAttrValue = null;
final IRecordInternal rec = listItem.getModelObject();
if (rec != null && rec.getRawData() != null) {
IStyleRule style = isSelected ? getRowSelectedStyle() : null;
if (style != null && style.getAttributeCount() == 0)
style = null;
if (style == null) {
// because index = 0 means record = 1
style = (listItem.getIndex() % 2 == 0) ? getRowOddStyle() : getRowEvenStyle();
}
if (asInlineCSSString) {
listItemAttrValue = getStyleAttributeString(style, rowStyleAttribute);
} else {
listItemAttrValue = getStyleAttributeValue(style, rowStyleAttribute);
}
}
return listItemAttrValue;
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method tableChanged.
/**
* @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
*/
public void tableChanged(TableModelEvent e) {
// as changed, as it will be faster on the client the component replace
if ((e.getType() == TableModelEvent.UPDATE) && (e.getFirstRow() == e.getLastRow()) && (nrUpdatedListItems < 20)) {
Component component = table.get(Integer.toString(e.getFirstRow()));
if (component instanceof ListItem) {
((ListItem) component).visitChildren(IProviderStylePropertyChanges.class, new IVisitor<Component>() {
public Object component(Component comp) {
if ((comp instanceof IDisplayData) || !(comp instanceof ILabel)) {
if (comp instanceof ISupportsNeedEntireState && ((ISupportsNeedEntireState) comp).needEntireState()) {
// it if has tags - mark as changed; it could be enhanced further by also know what was last-rendered on tags, not just simple dataproviders
((IProviderStylePropertyChanges) comp).getStylePropertyChanges().setChanged();
} else {
// try to mark cells as changed only if there was a real value change; otherwise there is no use to replace the whole row...
checkForValueChanges(comp);
}
}
// else labels/buttons that don't display data are not changed
return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
}
});
nrUpdatedListItems++;
IModel<IRecordInternal> newModel = table.getListItemModel(table.getModel(), e.getFirstRow());
IModel oldModel = ((ListItem) component).getModel();
if (newModel != null && oldModel != null && newModel.getObject() != null && !newModel.getObject().equals(oldModel.getObject())) {
// refresh model if it changed
((ListItem) component).setModel(newModel);
}
}
} else {
if (!isRendering && (!isScrollMode() || !(scrollBehavior != null && scrollBehavior.isGettingRows()))) {
if (isScrollMode())
resetScrollParams();
getStylePropertyChanges().setValueChanged();
}
}
// This is just an heuristic for filtering out the sort event from all table changed events that are raised.
if (currentData != null && e.getColumn() == TableModelEvent.ALL_COLUMNS && e.getFirstRow() == 0 && elementToColumnHeader.size() > 0) {
List<SortColumn> sortCols = currentData.getSortColumns();
if (sortCols != null && sortCols.size() > 0) {
Map<String, Boolean> sortMap = new HashMap<String, Boolean>();
for (IPersist persist : elementToColumnHeader.keySet()) {
SortableCellViewHeader sortableCellViewHeader = (SortableCellViewHeader) elementToColumnHeader.get(persist);
sortableCellViewHeader.setResizeImage(R_ARROW_OFF);
}
for (SortColumn sc : sortCols) {
for (IPersist persist : elementToColumnHeader.keySet()) {
Component comp = elementToColumnIdentifierComponent.get(persist);
SortableCellViewHeader sortableCellViewHeader = (SortableCellViewHeader) elementToColumnHeader.get(persist);
if (comp instanceof IDisplayData && ((IDisplayData) comp).getDataProviderID() != null) {
IDisplayData dispComp = (IDisplayData) comp;
List<String> sortingProviders = null;
if (dispComp instanceof ISupportValueList && ((ISupportValueList) dispComp).getValueList() != null) {
try {
sortingProviders = DBValueList.getShowDataproviders(((ISupportValueList) dispComp).getValueList().getValueList(), (Table) currentData.getTable(), dispComp.getDataProviderID(), currentData.getFoundSetManager());
} catch (RepositoryException ex) {
Debug.error(ex);
}
}
if (sortingProviders == null) {
// no related sort, use sort on dataProviderID instead
sortingProviders = Collections.singletonList(dispComp.getDataProviderID());
}
for (String sortingProvider : sortingProviders) {
SortColumn existingSc;
try {
FoundSetManager fsm = (FoundSetManager) currentData.getFoundSetManager();
existingSc = fsm.getSortColumn(currentData.getTable(), sortingProvider, false);
} catch (RepositoryException ex) {
Debug.error(ex);
continue;
}
if (sc.equalsIgnoreSortorder(existingSc)) {
boolean descending = sc.getSortOrder() == SortColumn.DESCENDING;
sortableCellViewHeader.setResizeImage(descending ? R_ARROW_UP : R_ARROW_DOWN);
sortMap.put(sortableCellViewHeader.getId(), Boolean.valueOf(!descending));
}
}
}
}
}
headers.recordSort(sortMap);
}
}
MainPage mp = table.findParent(MainPage.class);
if (mp != null)
mp.triggerBrowserRequestIfNeeded();
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method getRowSelectionScript.
public String getRowSelectionScript(List<Integer> indexToUpdate) {
if (currentData == null)
return null;
if (!hasOnRender() && (bgColorScript != null || hasOddEvenSelected()) && indexToUpdate != null) {
int firstRow = table.isPageableMode() ? table.getCurrentPage() * table.getRowsPerPage() : table.getStartIndex();
int lastRow = firstRow + table.getViewSize() - 1;
int[] newSelectedIndexes = getSelectedIndexes();
AppendingStringBuffer sab = new AppendingStringBuffer();
for (int rowIdx : indexToUpdate) {
ArrayList<String> bgRuntimeColorjsArray = new ArrayList<String>();
ArrayList<String> fgRuntimeColorjsArray = new ArrayList<String>();
ArrayList<String> fstyleJsAray = new ArrayList<String>();
ArrayList<String> fweightJsAray = new ArrayList<String>();
ArrayList<String> fsizeJsAray = new ArrayList<String>();
ArrayList<String> ffamilyJsAray = new ArrayList<String>();
ArrayList<String> bstyleJsAray = new ArrayList<String>();
ArrayList<String> bwidthJsAray = new ArrayList<String>();
ArrayList<String> bcolorJsAray = new ArrayList<String>();
if (rowIdx >= firstRow && rowIdx <= lastRow) {
ListItem<IRecordInternal> selectedListItem = (ListItem<IRecordInternal>) table.get(Integer.toString(rowIdx));
if (selectedListItem != null) {
String selectedId = selectedListItem.getMarkupId();
boolean isSelected = Arrays.binarySearch(newSelectedIndexes, rowIdx) >= 0;
// IF ONLY SELCTED STYLE RULE is defined then apply runtimeComonent style properties
if (bgColorScript == null && !isSelected && (getRowOddStyle().getAttributeCount() == 0) && (getRowEvenStyle().getAttributeCount() == 0)) {
Iterable<? extends Component> it = Utils.iterate(selectedListItem.iterator());
Component cellContents;
for (Component c : it) {
if (c instanceof CellContainer) {
CellContainer cell = (CellContainer) c;
cellContents = cell.iterator().next();
} else {
cellContents = c;
}
if (cellContents instanceof IScriptableProvider) {
IScriptable scriptableComponent = ((IScriptableProvider) cellContents).getScriptObject();
if (scriptableComponent instanceof IRuntimeComponent) {
IRuntimeComponent runtimeComponent = (IRuntimeComponent) scriptableComponent;
// bgcolor
bgRuntimeColorjsArray.add(runtimeComponent.getBgcolor());
// fgcolor
fgRuntimeColorjsArray.add(runtimeComponent.getFgcolor());
// font style
String fontStyle = runtimeComponent.getFont();
StringBuilder // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
fstyle = new StringBuilder(""), // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
fweight = new StringBuilder(""), // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
fsize = new StringBuilder(""), // $NON-NLS-1$
ffamily = new StringBuilder("");
splitFontStyle(fontStyle, fstyle, fweight, fsize, ffamily);
fstyleJsAray.add(fstyle.toString());
fweightJsAray.add(fweight.toString());
fsizeJsAray.add(fsize.toString());
ffamilyJsAray.add(ffamily.toString());
// border style
String borderStyle = runtimeComponent.getBorder();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
StringBuilder bstyle = new StringBuilder(""), bwidth = new StringBuilder(""), bcolor = new StringBuilder("");
splitBorderStyle(borderStyle, bstyle, bwidth, bcolor);
bstyleJsAray.add(bstyle.toString());
bwidthJsAray.add(bwidth.toString());
bcolorJsAray.add(bcolor.toString());
}
}
}
}
String selectedColor = null, selectedFgColor = null, selectedFont = null, selectedBorder = null;
selectedColor = getListItemBgColor(selectedListItem, isSelected, true);
if (!isListViewMode()) {
selectedFgColor = getListItemFgColor(selectedListItem, isSelected, true);
selectedFont = getListItemFont(selectedListItem, isSelected);
selectedBorder = getListItemBorder(selectedListItem, isSelected);
}
// $NON-NLS-1$
selectedColor = (selectedColor == null ? "" : selectedColor.toString());
// $NON-NLS-1$
selectedFgColor = (selectedFgColor == null) ? "" : selectedFgColor.toString();
// font styles
StringBuilder // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
fstyle = new StringBuilder(""), // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
fweight = new StringBuilder(""), // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
fsize = new StringBuilder(""), // $NON-NLS-1$
ffamily = new StringBuilder("");
splitFontStyle(selectedFont, fstyle, fweight, fsize, ffamily);
// border styles
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
StringBuilder bstyle = new StringBuilder(""), bwidth = new StringBuilder(""), bcolor = new StringBuilder("");
splitBorderStyle(selectedBorder, bstyle, bwidth, bcolor);
if (bgColorScript == null && !isSelected && (getRowOddStyle().getAttributeCount() == 0) && (getRowEvenStyle().getAttributeCount() == 0) && !isListViewMode()) {
// backgroundcolor and color are sent as final inline string
// $NON-NLS-1$
sab.append("Servoy.TableView.setRowStyle('").append(selectedId).append(// $NON-NLS-1$
"', ").append(toJsArrayString(bgRuntimeColorjsArray, "background-color:")).append(// $NON-NLS-1$
",").append(toJsArrayString(fgRuntimeColorjsArray, "color:")).append(// $NON-NLS-1$
",").append(toJsArrayString(fstyleJsAray, "")).append(// $NON-NLS-1$
", ").append(toJsArrayString(fweightJsAray, "")).append(// $NON-NLS-1$
", ").append(toJsArrayString(fsizeJsAray, "")).append(// $NON-NLS-1$
", ").append(toJsArrayString(ffamilyJsAray, "")).append(// $NON-NLS-1$
", ").append(toJsArrayString(bstyleJsAray, "")).append(// $NON-NLS-1$
", ").append(toJsArrayString(bwidthJsAray, "")).append(// $NON-NLS-1$
",").append(toJsArrayString(bcolorJsAray, "")).append(// $NON-NLS-1$
",").append(isListViewMode()).append(// $NON-NLS-1$
");\n");
} else {
// $NON-NLS-1$
sab.append("Servoy.TableView.setRowStyle('").append(selectedId).append(// $NON-NLS-1$
"', '").append(selectedColor).append(// $NON-NLS-1$
"', '").append(selectedFgColor).append(// $NON-NLS-1$
"', '").append(fstyle).append(// $NON-NLS-1$
"', '").append(fweight).append(// $NON-NLS-1$
"', '").append(fsize).append(// $NON-NLS-1$
"', '").append(ffamily).append(// $NON-NLS-1$
"', '").append(bstyle).append(// $NON-NLS-1$
"', '").append(bwidth).append(// $NON-NLS-1$
"', '").append(bcolor).append(// $NON-NLS-1$
"', ").append(isListViewMode()).append(// $NON-NLS-1$
");\n");
}
}
}
}
String rowSelectionScript = sab.toString();
if (rowSelectionScript.length() > 0)
return rowSelectionScript;
}
return null;
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method getCellToFocus.
/**
* @param columnIdentifierComponent
* @return
*/
private Component getCellToFocus(final Component columnIdentifierComponent) {
Component cell = null;
// this means that the given column of the cell view wants to be focused =>
// we must focus the cell component that is part of the currently selected record
int selectedIndex = currentData.getSelectedIndex();
if (selectedIndex < 0 && currentData.getSize() > 0) {
selectedIndex = 0;
}
if (selectedIndex >= 0) {
// we found a record to use - now we must locate the cell component inside this record
ListItem<IRecordInternal> li = (ListItem<IRecordInternal>) table.get(Integer.toString(selectedIndex));
if (li != null) {
Iterator<? extends Component> cells = li.iterator();
while (cells.hasNext()) {
Component someCell = cells.next();
if (isListViewMode()) {
if (someCell instanceof WebCellBasedViewListItem) {
someCell = ((WebCellBasedViewListItem) someCell).getListContainer();
}
if (someCell instanceof MarkupContainer) {
for (int i = 0; i < ((MarkupContainer) someCell).size(); i++) {
Component currentComponent = ((MarkupContainer) someCell).get(i);
if (currentComponent instanceof WrapperContainer)
currentComponent = ((WrapperContainer) currentComponent).getDelegate();
IPersist element = cellToElement.get(currentComponent);
if (element != null && elementToColumnIdentifierComponent.get(element) == columnIdentifierComponent) {
return currentComponent;
}
}
}
} else {
someCell = CellContainer.getContentsForCell(someCell);
IPersist element = cellToElement.get(someCell);
if (element != null && elementToColumnIdentifierComponent.get(element) == columnIdentifierComponent) {
cell = someCell;
break;
}
}
}
}
}
return cell;
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class WebDataLookupField method dependencyChanged.
/*
* (non-Javadoc)
*
* @see com.servoy.j2db.dataprocessing.IDisplayDependencyData#dependencyChanged(com.servoy.j2db.dataprocessing.IRecordInternal)
*/
@Override
public void dependencyChanged(IRecordInternal record) {
this.parentState = record;
if (list != null) {
int index = -1;
if (!ScopesUtils.isVariableScope(getDataProviderID()) && (getDataProviderID() != null)) {
index = getDataProviderID().lastIndexOf('.');
}
if (index == -1 || parentState == null) {
list.fill(parentState);
} else {
IFoundSetInternal relatedFoundSet = parentState.getRelatedFoundSet(getDataProviderID().substring(0, index));
if (relatedFoundSet == null) {
this.relatedRecord = parentState.getParentFoundSet().getPrototypeState();
list.fill(relatedRecord);
} else if (relatedFoundSet.getSize() == 0) {
this.relatedRecord = relatedFoundSet.getPrototypeState();
list.fill(relatedRecord);
} else {
IRecordInternal relRecord = relatedFoundSet.getRecord(relatedFoundSet.getSelectedIndex());
if (relRecord != relatedRecord) {
this.relatedRecord = relRecord;
list.fill(relatedRecord);
}
}
}
}
}
Aggregations