use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class PageDefinition method toXML.
public void toXML(Writer w) throws IOException {
// $NON-NLS-1$
w.write("<PAGE>");
// $NON-NLS-1$ //$NON-NLS-2$
w.write("<PARTS count=\"" + panels.size() + "\" >");
for (int i = 0; i < panels.size(); i++) {
DataRendererDefinition drd = panels.get(i);
IRecordInternal state = drd.getState();
if (state instanceof PageNumberState) {
((PageNumberState) state).initPagePositionAndSize(this);
}
DataRenderer partpane = drd.getDataRenderer();
// fill with data
partpane.getDataAdapterList().setRecord(state, true);
drd.toXML(w);
}
// $NON-NLS-1$
w.write("</PARTS>");
// $NON-NLS-1$
w.write("</PAGE>");
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class PageNumberState method initPagePositionAndSize.
void initPagePositionAndSize(PageDefinition pd) {
Iterator<DataRendererDefinition> it = pd.getPanels().iterator();
while (it.hasNext()) {
DataRendererDefinition drd = it.next();
if (drd != null && drd.getPart() != null && drd.getPart().getPartType() == Part.BODY) {
IRecordInternal rec = drd.getState();
if (rec != null) {
delegate_to_record = rec.getParentFoundSet();
delegate_record_index = delegate_to_record.getRecordIndex(rec);
}
// do not break we want the last body record
}
}
currentPage = list.getPageNumber(pd);
totalPages = list.getPageSectionLength(pd);
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class DataRenderer method getListCellRendererComponent.
public Component getListCellRendererComponent(JComponent rendererParentCanBeNull, Object value, int index, boolean isSelected, boolean cellHasFocus) {
this.selected = isSelected;
// if (isSelected)
// {
// setBorder(focusBorder);
// }
// else
// {
// setBorder(noFocusBorder);
// }
boolean bgRowColorSet = false;
// if in Renderer mode for a the List then a renderer can't stop editing.
if (value instanceof IRecordInternal) {
IRecordInternal val = (IRecordInternal) value;
// if in list view, we need to set the render state for each list item here
if (rendererParentCanBeNull != null) {
DataAdapterList.setDataRendererComponentsRenderState(this, val);
}
dataAdapterList.setRecord(val, !isRenderer);
// setOpaque(true);
if (index != -1) {
boolean specialStateCase = (val instanceof PrototypeState || val instanceof FindState || val.getRawData() == null);
if (strRowBGColorProvider == null && !specialStateCase) {
if (rendererParentCanBeNull instanceof ISupportRowBGColorScript) {
strRowBGColorProvider = ((ISupportRowBGColorScript) rendererParentCanBeNull).getRowBGColorScript();
rowBGColorArgs = ((ISupportRowBGColorScript) rendererParentCanBeNull).getRowBGColorArgs();
}
// $NON-NLS-1$
if (strRowBGColorProvider == null)
strRowBGColorProvider = "servoy_row_bgcolor";
isRowBGColorCalculation = val.getRawData().containsCalculation(strRowBGColorProvider);
if (!isRowBGColorCalculation && strRowBGColorProvider.equals("servoy_row_bgcolor")) {
// $NON-NLS-1$
strRowBGColorProvider = "";
}
defaultColor = getBackground();
}
if (// $NON-NLS-1$
strRowBGColorProvider != null && !"".equals(strRowBGColorProvider)) {
IFoundSetInternal parent = val.getParentFoundSet();
if (parent != null && !specialStateCase) {
Object bg_color = null;
if (isRowBGColorCalculation) {
bg_color = parent.getCalculationValue(val, strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(index), new Boolean(isSelected), null, null, Boolean.FALSE }), Utils.parseJSExpressions(rowBGColorArgs)), null);
} else {
try {
FormController currentForm = dataAdapterList.getFormController();
bg_color = currentForm.executeFunction(strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(index), new Boolean(isSelected), null, null, currentForm.getName(), val, Boolean.FALSE }), Utils.parseJSExpressions(rowBGColorArgs)), false, null, true, null);
} catch (Exception ex) {
Debug.error(ex);
}
}
if (bg_color != null && !(bg_color.toString().trim().length() == 0) && !(bg_color instanceof Undefined)) {
bgRowColorSet = true;
setBackground(PersistHelper.createColor(bg_color.toString()));
} else {
setBackground(defaultColor);
}
} else {
setBackground(defaultColor);
}
}
if (rendererParentCanBeNull instanceof ISupportRowStyling && !specialStateCase && !bgRowColorSet) {
ISupportRowStyling oddEvenStyling = (ISupportRowStyling) rendererParentCanBeNull;
IStyleSheet ss = oddEvenStyling.getRowStyleSheet();
IStyleRule style = isSelected ? oddEvenStyling.getRowSelectedStyle() : null;
if (style != null && style.getAttributeCount() == 0)
style = null;
if (style == null) {
// because index = 0 means record = 1
style = (index % 2 == 0) ? oddEvenStyling.getRowOddStyle() : oddEvenStyling.getRowEvenStyle();
}
if (ss != null && style != null) {
Color bgColor = ss.getBackground(style);
if (bgColor != null) {
showSelection = false;
bgRowColorSet = true;
setBackground(bgColor);
}
}
}
}
}
if (rendererParentCanBeNull != null) {
if (rendererParentCanBeNull.isEnabled() != isEnabled()) {
// Debug.trace(donotusecanbenullifinrecondview.getName()+" "+donotusecanbenullifinrecondview.isEnabled());
// needed for portals
setEnabled(rendererParentCanBeNull.isEnabled());
}
if (bgRowColorSet && !isOpaque()) {
setOpaque(true);
}
dataRendererOnRenderWrapper.getRenderEventExecutor().fireOnRender(hasFocus());
}
return this;
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class CellAdapter method getBgColor.
private Color getBgColor(JTable jtable, boolean isSelected, int row, boolean isEdited) {
Color bgColor = null;
IRecordInternal state = ((IFoundSetInternal) jtable.getModel()).getRecord(row);
boolean specialStateCase = (state instanceof PrototypeState || state instanceof FindState || state == null || state.getRawData() == null);
if (/* !(renderer instanceof JButton) && */
!specialStateCase) {
ISwingFoundSet foundset = (ISwingFoundSet) jtable.getModel();
bgColor = (Color) getStyleAttributeForRow(jtable, isSelected, row, ISupportRowStyling.ATTRIBUTE.BGCOLOR);
String strRowBGColorProvider = null;
List<Object> rowBGColorArgs = null;
if (jtable instanceof IView) {
strRowBGColorProvider = ((IView) jtable).getRowBGColorScript();
rowBGColorArgs = ((IView) jtable).getRowBGColorArgs();
}
// $NON-NLS-1$
if (strRowBGColorProvider == null)
strRowBGColorProvider = "servoy_row_bgcolor";
boolean isRowBGColorCalculation = state.getRawData().containsCalculation(strRowBGColorProvider);
if (// $NON-NLS-1$
!isRowBGColorCalculation && strRowBGColorProvider.equals("servoy_row_bgcolor")) {
// $NON-NLS-1$
strRowBGColorProvider = "";
}
if (// $NON-NLS-1$
strRowBGColorProvider != null && !"".equals(strRowBGColorProvider)) {
Object bg_color = null;
// TODO this should be done better....
Record.VALIDATE_CALCS.set(Boolean.FALSE);
try {
String type = (editor instanceof IScriptableProvider && ((IScriptableProvider) editor).getScriptObject() instanceof IRuntimeComponent) ? ((IRuntimeComponent) ((IScriptableProvider) editor).getScriptObject()).getElementType() : null;
String nm = (editor instanceof IDisplayData) ? ((IDisplayData) editor).getDataProviderID() : null;
if (isRowBGColorCalculation) {
bg_color = foundset.getCalculationValue(state, strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(row), new Boolean(isSelected), type, nm, new Boolean(isEdited) }), Utils.parseJSExpressions(rowBGColorArgs)), null);
} else {
try {
FormController currentForm = dal.getFormController();
bg_color = currentForm.executeFunction(strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(row), new Boolean(isSelected), type, nm, currentForm.getName(), state, new Boolean(isEdited) }), Utils.parseJSExpressions(rowBGColorArgs)), false, null, true, null);
} catch (Exception ex) {
Debug.error(ex);
}
}
} finally {
Record.VALIDATE_CALCS.set(null);
}
if (bg_color != null && !(bg_color.toString().trim().length() == 0) && !(bg_color instanceof Undefined)) {
bgColor = PersistHelper.createColor(bg_color.toString());
}
}
}
return bgColor;
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class CellAdapter method getTableCellEditorComponent.
/*
* @see TableCellEditor#getTableCellEditorComponent(JTable, Object, boolean, int, int)
*/
public Component getTableCellEditorComponent(JTable jtable, Object value, boolean isSelected, int row, int column) {
if (editor == null || !isVisible(editor) || !(jtable.getModel() instanceof IFoundSetInternal)) {
return empty;
}
IRecordInternal newRec = ((IFoundSetInternal) jtable.getModel()).getRecord(row);
if (isSelected) {
Color bgColor = getBgColor(jtable, isSelected, row, true);
if (bgColor != null && editor instanceof JComponent)
((JComponent) editor).setOpaque(true);
if (bgColor == null) {
// unselected background is the default background color of the editor.
bgColor = unselectedBackground;
}
lastEditorBgColor = bgColor;
if (editor instanceof ISupportsDoubleBackground) {
((ISupportsDoubleBackground) editor).setBackground(bgColor, unselectedBackground);
} else {
editor.setBackground(bgColor);
}
Color fgColor = getFgColor(jtable, isSelected, row);
if (fgColor == null) {
// unselected foreground is the default foreground color of the editor.
fgColor = unselectedForeground;
}
lastEditorFgColor = fgColor;
if (editor instanceof ISupportsDoubleBackground) {
((ISupportsDoubleBackground) editor).setForeground(fgColor, unselectedForeground);
} else {
editor.setForeground(fgColor);
}
Font font = getFont(jtable, isSelected, row);
if (font == null) {
// unselected font is the default font of the editor.
font = unselectedFont;
}
lastEditorFont = font;
editor.setFont(font);
Border styleBorder = getBorder(jtable, isSelected, row);
if (styleBorder != null && editor instanceof JComponent) {
if (editor instanceof AbstractButton && !((AbstractButton) editor).isBorderPainted()) {
((AbstractButton) editor).setBorderPainted(true);
}
Border marginBorder = null;
if (noFocusBorder instanceof EmptyBorder) {
marginBorder = noFocusBorder;
} else if (noFocusBorder instanceof CompoundBorder && ((CompoundBorder) noFocusBorder).getInsideBorder() instanceof EmptyBorder) {
marginBorder = ((CompoundBorder) noFocusBorder).getInsideBorder();
}
// if we have margin set on the component, keep it along with the style border
if (marginBorder != null) {
styleBorder = new CompoundBorder(styleBorder, marginBorder);
}
((JComponent) editor).setBorder(styleBorder);
}
}
// try
// {
// if (currentEditingState != null && newRec != currentEditingState && currentEditingState.isEditing())
// {
// currentEditingState.stopEditing();
// }
// }
// catch (Exception e)
// {
// Debug.error(e);
// }
currentEditingState = newRec;
if (currentEditingState != null) {
if (editor instanceof IScriptableProvider) {
IScriptable scriptable = ((IScriptableProvider) editor).getScriptObject();
if (scriptable instanceof ISupportOnRenderCallback) {
RenderEventExecutor renderEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
if (renderEventExecutor != null && renderEventExecutor.hasRenderCallback()) {
renderEventExecutor.setRenderState(currentEditingState, row, isSelected, true);
}
}
}
// if not enabled or not editable do not start the edit
if (editor instanceof IDisplay && ((IDisplay) editor).isEnabled() && !((IDisplay) editor).isReadOnly()) {
DisplaysAdapter.startEdit(dal, (IDisplay) editor, currentEditingState);
}
if (editor instanceof IDisplayRelatedData) {
IDisplayRelatedData drd = (IDisplayRelatedData) editor;
IRecordInternal state = ((IFoundSetInternal) jtable.getModel()).getRecord(row);
if (state != null) {
drd.setRecord(state, true);
}
}
if (// && dataProviderID != null)
editor instanceof IDisplayData) {
try {
Object data = dal.getValueObject(currentEditingState, dataProviderID);
if (data instanceof DbIdentValue) {
data = ((DbIdentValue) data).getPkValue();
}
convertAndSetValue(((IDisplayData) editor), data);
} catch (IllegalArgumentException iae) {
Debug.error(iae);
}
}
if (editor instanceof IServoyAwareBean) {
((IServoyAwareBean) editor).setSelectedRecord(new ServoyBeanState(currentEditingState, dal.getFormScope()));
}
if (editor instanceof IScriptableProvider && !(editor instanceof IDisplayData) && !(editor instanceof IDisplayRelatedData)) {
IScriptable scriptable = ((IScriptableProvider) editor).getScriptObject();
if (scriptable instanceof ISupportOnRenderCallback) {
RenderEventExecutor renderEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
if (renderEventExecutor != null && renderEventExecutor.hasRenderCallback()) {
renderEventExecutor.fireOnRender(editor instanceof JTextComponent ? ((JTextComponent) editor).isEditable() : false);
}
}
}
}
return editor.isVisible() ? editor : empty;
}
Aggregations