use of com.servoy.j2db.ui.ISupportRowStyling in project servoy-client by Servoy.
the class FormController method setView.
// set the view (record,list,table)
@Override
public void setView(int v) {
int viewType = v;
if (viewType == -1) {
viewType = getForm().getView();
}
if (viewType == currentViewType) {
// no change
return;
}
if (currentViewType == LOCKED_TABLE_VIEW || currentViewType == LOCKED_LIST_VIEW || currentViewType == LOCKED_RECORD_VIEW) {
// don't let user change
return;
}
currentViewType = viewType;
// always synch the view menu with this call
if (application.getFormManager() instanceof IFormManagerInternal) {
IBasicFormManager sfm = application.getFormManager();
if (sfm.getCurrentMainShowingFormController() == this) {
((IFormManagerInternal) sfm).synchViewMenu(viewType);
}
}
boolean formReadOnly = ((FormManager) application.getFormManager()).isFormReadOnly(getName());
// uninstall old view
if (view != null) {
// with the elements that are now created again.
if (formReadOnly || containerImpl.isReadOnly()) {
containerImpl.setReadOnly(false);
}
view.stop();
view = null;
deleteRenderers();
try {
createDataRenderers(viewType);
} catch (Exception e) {
// $NON-NLS-1$ //$NON-NLS-2$
application.reportError(application.getI18NMessage("servoy.formPanel.error.setupForm") + ": " + getName(), e);
}
}
if (bgColor != null) {
containerImpl.setBackground(bgColor);
}
view = containerImpl.initView(application, this, viewType);
// Do tab sequencing now.
tabSequence.fromAbstractToNamed();
view.start(application);
// make sure that the formscope is created to insert the elements in it.
getFormScope();
if (formScope != null) {
hmChildrenJavaMembers = new HashMap<String, Object[]>();
Scriptable scope = getFormUI().makeElementsScriptObject(formScope, hmChildrenJavaMembers, dataRenderers, view);
// $NON-NLS-1$
formScope.putWithoutFireChange("elements", scope);
}
if (isFormVisible) {
view.setModel(formModel);
}
// $NON-NLS-1$
view.setRowBGColorScript(form.getRowBGColorCalculation(), form.getFlattenedMethodArguments("rowBGColorCalculation"));
if (view instanceof ISupportRowStyling)
((ISupportRowStyling) view).setRowStyles(stylesheet, styleOdd, styleEven, styleSelected, styleHeader);
if (formReadOnly) {
containerImpl.setReadOnly(true);
}
}
use of com.servoy.j2db.ui.ISupportRowStyling 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.ui.ISupportRowStyling in project servoy-client by Servoy.
the class CellAdapter method getStyleAttributeForRow.
private Object getStyleAttributeForRow(JTable jtable, boolean isSelected, int row, ISupportRowStyling.ATTRIBUTE rowStyleAttribute) {
Object rowStyleAttrValue = null;
IRecordInternal state = ((IFoundSetInternal) jtable.getModel()).getRecord(row);
boolean specialStateCase = (state instanceof PrototypeState || state instanceof FindState);
if (/* !(renderer instanceof JButton) && */
!specialStateCase) {
if (jtable instanceof ISupportRowStyling) {
ISupportRowStyling oddEvenStyling = (ISupportRowStyling) jtable;
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 = (row % 2 == 0) ? oddEvenStyling.getRowOddStyle() : oddEvenStyling.getRowEvenStyle();
}
rowStyleAttrValue = getStyleAttribute(ss, style, rowStyleAttribute);
}
}
return rowStyleAttrValue;
}
use of com.servoy.j2db.ui.ISupportRowStyling in project servoy-client by Servoy.
the class WebDataRenderer method getParentViewBgColor.
private String getParentViewBgColor() {
if (parentView != null) {
String rowBGColorCalculation = parentView.getRowBGColorScript();
IRecordInternal rec = (IRecordInternal) getDefaultModelObject();
if (rec != null && rec.getRawData() != null) {
IFoundSetInternal parentFoundSet = rec.getParentFoundSet();
int recIndex = parentFoundSet.getSelectedIndex();
boolean isSelected = recIndex == parentFoundSet.getRecordIndex(rec);
if (rowBGColorCalculation != null) {
Object bg_color = null;
if (rec.getRawData().containsCalculation(rowBGColorCalculation)) {
// data renderer is always on the selected index.
bg_color = parentFoundSet.getCalculationValue(rec, rowBGColorCalculation, Utils.arrayMerge(new Object[] { new Integer(recIndex), new Boolean(isSelected), null, null, Boolean.FALSE }, Utils.parseJSExpressions(parentView.getRowBGColorArgs())), null);
} else {
try {
FormController currentForm = dataAdapterList.getFormController();
bg_color = currentForm.executeFunction(rowBGColorCalculation, Utils.arrayMerge(new Object[] { new Integer(parentFoundSet.getSelectedIndex()), new Boolean(isSelected), null, null, currentForm.getName(), rec, Boolean.FALSE }, Utils.parseJSExpressions(parentView.getRowBGColorArgs())), true, null, true, null);
} catch (Exception ex) {
Debug.error(ex);
}
}
if (bg_color != null && !(bg_color.toString().trim().length() == 0) && !(bg_color instanceof Undefined)) {
return bg_color.toString();
}
}
if (parentView instanceof ISupportRowStyling) {
ISupportRowStyling parentViewWithRowStyling = (ISupportRowStyling) parentView;
IStyleSheet ss = parentViewWithRowStyling.getRowStyleSheet();
IStyleRule style = isSelected ? parentViewWithRowStyling.getRowSelectedStyle() : null;
if (style != null && style.getAttributeCount() == 0)
style = null;
if (style == null) {
style = (recIndex % 2 == 0) ? parentViewWithRowStyling.getRowEvenStyle() : parentViewWithRowStyling.getRowOddStyle();
}
if (ss != null && style != null) {
return PersistHelper.createColorString(ss.getBackground(style));
}
}
}
}
return null;
}
Aggregations