use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class DataRendererFactory method createPortalRenderer.
public IDataRenderer createPortalRenderer(IApplication app, Portal objToRender, Form dataProviderLookup, IScriptExecuter listner, boolean printing, ControllerUndoManager undoManager) throws Exception {
List<IPersist> allObjectsAsList = objToRender.getAllObjectsAsList();
List<IFormElement> formElements = new ArrayList<IFormElement>(allObjectsAsList.size());
for (IPersist persist : allObjectsAsList) {
if (persist instanceof IFormElement) {
formElements.add((IFormElement) persist);
}
}
List<IFormElement> children = new SortedList<IFormElement>(new Comparator<IFormElement>() {
public int compare(IFormElement o1, IFormElement o2) {
// reverse order, right order for tab sequence
int result = -PositionComparator.XY_PERSIST_COMPARATOR.compare(o1, o2);
if (result == 0) {
return (o1.getFormIndex() - o2.getFormIndex());
}
return result;
}
}, formElements);
Iterator<IFormElement> e1 = children.iterator();
Map emptyDataRenderers = new LinkedHashMap();
DataRenderer dr = null;
int height = objToRender.getRowHeight();
boolean calculateHeight = (height == 0);
// for safety
if (height == 0)
height = 100;
// int leftBorder = 0;
// int bottomBorder = 0;
// if (objToRender.getShowHorizontalLines())
// {
// bottomBorder = 1;
// }
// if (objToRender.getShowVerticalLines())
// {
// leftBorder = 4;
// }
boolean showSelection = objToRender.getShowVerticalLines();
dr = (DataRenderer) getEmptyDataRenderer(ComponentFactory.getWebID(dataProviderLookup, objToRender), "portal_" + objToRender.getName(), app, showSelection);
setBasicSettings(dr, objToRender.getBackground(), new Dimension(objToRender.getSize().width, height), new Point(0, 0), printing);
// first is dummy saying is portal
emptyDataRenderers.put(new Boolean(true), dr);
dr.setLocation(objToRender.getLocation());
Border b = ComponentFactoryHelper.createBorder(objToRender.getBorderType());
Insets ins = new Insets(0, 0, 0, 0);
if (b != null) {
ins = ComponentFactoryHelper.getBorderInsetsForNoComponent(b);
}
// if (b instanceof EmptyBorder)
// {
// ins = ((EmptyBorder)b).getBorderInsets();
// }
placeElements(e1, app, dataProviderLookup, listner, emptyDataRenderers, objToRender.getSize().width, -(objToRender.getLocation().x + ins.right), -ins.top, printing, true, undoManager, true, null);
int biggest_width = 10;
int biggest_height = calculateHeight ? 0 : height;
Component[] comps = dr.getComponents();
boolean hasRowBGColorCalc = objToRender.getRowBGColorCalculation() != null;
for (Component element : comps) {
int w = element.getLocation().x + element.getSize().width;
if (w > biggest_width)
biggest_width = w;
if (hasRowBGColorCalc && element instanceof JComponent)
((JComponent) element).setOpaque(false);
if (calculateHeight) {
int h = element.getLocation().y + element.getSize().height;
if (h > biggest_height)
biggest_height = h;
}
}
dr.setSize(new Dimension(biggest_width, biggest_height));
dr.setPreferredSize(new Dimension(biggest_width, biggest_height));
if (printing) {
// sliding inside a multiline portal renderer is nor supported, be we have to attach the springs for resizes
addSpringsBetweenComponents(app, dr);
}
return dr;
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method putClientProperty.
/**
* put client property for current and future components.
*/
public void putClientProperty(IPersist persist, Object key, Object value) {
Map<Object, Object> clientProperties = elementToClientProperties.get(persist);
if (clientProperties == null) {
elementToClientProperties.put(persist, clientProperties = new HashMap<Object, Object>());
}
clientProperties.put(key, value);
for (Entry<Component, IPersist> entry : cellToElement.entrySet()) {
if (entry.getValue().equals(persist)) {
Component component = entry.getKey();
if (component instanceof IScriptableProvider) {
IScriptable scriptObject = ((IScriptableProvider) component).getScriptObject();
if (scriptObject instanceof HasRuntimeClientProperty) {
((HasRuntimeClientProperty) scriptObject).putClientProperty(key, value);
}
}
}
}
}
use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method setTabSeqComponents.
public void setTabSeqComponents(List<Component> list) {
if (list == null || list.size() == 0) {
if (elementTabIndexes.size() > 0)
getStylePropertyChanges().setChanged();
elementTabIndexes.clear();
} else {
getStylePropertyChanges().setChanged();
elementTabIndexes.clear();
int columnTabIndex = 0;
for (Component rowIdComponent : list) {
for (Entry<IPersist, Component> entry : elementToColumnIdentifierComponent.entrySet()) {
if (componentIdentifiesColumn(rowIdComponent, entry.getValue())) {
elementTabIndexes.put(entry.getKey(), Integer.valueOf(columnTabIndex));
columnTabIndex++;
break;
}
}
}
}
}
use of com.servoy.j2db.persistence.IPersist 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.persistence.IPersist 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;
}
Aggregations