use of com.servoy.j2db.dataprocessing.PrototypeState in project servoy-client by Servoy.
the class SwingForm method initView.
public IView initView(IApplication application, FormController fp, int viewType) {
view = null;
IDataRenderer[] dataRenderers = fp.getDataRenderers();
setTitleHeader((JComponent) dataRenderers[Part.TITLE_HEADER]);
setHeader((JComponent) dataRenderers[Part.HEADER]);
setLeadingGrandSummary((JComponent) dataRenderers[Part.LEADING_GRAND_SUMMARY]);
setTrailingGrandSummary((JComponent) dataRenderers[Part.TRAILING_GRAND_SUMMARY]);
setFooter((JComponent) dataRenderers[Part.FOOTER]);
// remove any left slider
setWest(null);
switch(viewType) {
case FormController.LOCKED_LIST_VIEW:
case IForm.LIST_VIEW:
view = new ListView();
PrototypeState proto = null;
if (fp.getFoundSet() != null) {
proto = fp.getFoundSet().getPrototypeState();
} else {
proto = new PrototypeState(null);
}
// this call is extreemly inportant, it prevent all rows retrieval
((ListView) view).setPrototypeCellValue(proto);
FormBodyEditor editor = null;
if (dataRenderers[FormController.FORM_RENDERER] != null) {
Component[] rendererComponents = ((Container) dataRenderers[FormController.FORM_RENDERER]).getComponents();
for (Component rendererComponent : rendererComponents) {
if (rendererComponent instanceof ISupportAsyncLoading) {
// in listview it is impossible to get lazy loaded images displaying correctly, due to needed repaintfire, which we cannot initiate
((ISupportAsyncLoading) rendererComponent).setAsyncLoadingEnabled(false);
}
rendererComponent.setFocusable(false);
}
((Component) dataRenderers[FormController.FORM_RENDERER]).setFocusable(false);
}
editor = new FormBodyEditor((DataRenderer) dataRenderers[FormController.FORM_EDITOR]);
if (dataRenderers[FormController.FORM_RENDERER] != null) {
DataRenderer dr = (DataRenderer) dataRenderers[FormController.FORM_RENDERER];
dr.setRenderer(true);
String bgcolorCalc = fp.getForm().getRowBGColorCalculation();
if (bgcolorCalc != null) {
// dr.setRowBGColorProvider(bgcolorCalc);
dr.setShowSelection(false);
// $NON-NLS-1$
((ListView) view).setRowBGColorScript(bgcolorCalc, fp.getForm().getFlattenedMethodArguments("rowBGColorCalculation"));
((DataRenderer) dataRenderers[FormController.FORM_EDITOR]).setShowSelection(false);
}
((ListView) view).setCellRenderer(dr);
} else {
// form with no body part - used only for printing probably
((ListView) view).setCellRenderer(new ListCellRenderer() {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
// $NON-NLS-1$
return new JLabel("");
}
});
}
((ListView) view).setCellEditor(editor);
((ListView) view).setRendererSameAsEditor(false);
((ListView) view).setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
break;
case FormController.LOCKED_TABLE_VIEW:
case FormController.TABLE_VIEW:
view = new TableView(application, fp, fp.getForm(), fp.getForm(), fp.getScriptExecuter(), dataRenderers[Part.HEADER], dataRenderers[Part.LEADING_GRAND_SUMMARY], false);
if (dataRenderers[FormController.FORM_EDITOR] != null)
dataRenderers[FormController.FORM_EDITOR].destroy();
dataRenderers[FormController.FORM_EDITOR] = (IDataRenderer) view;
if (formController.getBodyStyle() != null) {
Pair<IStyleSheet, IStyleRule> pairStyle = ComponentFactory.getCSSPairStyleForForm(application, fp.getForm());
if (pairStyle != null && pairStyle.getLeft() != null) {
Border border = pairStyle.getLeft().getBorder(formController.getBodyStyle());
if (border != null) {
innerPanel.setBorder(border);
}
}
}
break;
case IForm.LOCKED_RECORD_VIEW:
case IForm.RECORD_VIEW:
default:
view = new RecordView(formController);
if (dataRenderers[FormController.FORM_EDITOR] != null) {
((DataRenderer) dataRenderers[FormController.FORM_EDITOR]).setShowSelection(false);
((RecordView) view).setCellRenderer((DataRenderer) dataRenderers[FormController.FORM_EDITOR]);
}
int form_id = fp.getForm().getNavigatorID();
if (form_id == 0) {
StyledEnablePanel slider = ((RecordView) view).getSliderComponent();
if (bgColor != null)
slider.setBackground(bgColor);
setWest(slider);
}
}
getVerticalScrollBar().setValue(1);
getVerticalScrollBar().setValue(0);
setViewportView((JComponent) view);
if (view instanceof TableView) {
// the table view needs it's orientation set correctly
OrientationApplier.setOrientationToAWTComponent(this, application.getLocale(), application.getSolution().getTextOrientation());
}
if (view instanceof ListView) {
view.requestFocus();
}
OrientationApplier.setOrientationToAWTComponent(this, application.getLocale(), application.getSolution().getTextOrientation());
if ((bgColor != null) && (view instanceof ListView))
((ListView) view).setBackground(bgColor);
// except if it's a table view, that is always transparent
if (!(view instanceof TableView)) {
setOpaque(isOpaque());
} else {
for (int i = FormController.FORM_RENDERER + 1; i < dataRenderers.length; i++) {
if (dataRenderers[i] != null && !(dataRenderers[i] instanceof TableView)) {
dataRenderers[i].setOpaque(isOpaque());
}
}
}
return view;
}
use of com.servoy.j2db.dataprocessing.PrototypeState in project servoy-client by Servoy.
the class RecordView method syncSliderAndRefresh.
private void syncSliderAndRefresh() {
// check if the model wasn't already cleared.
if (model == null)
return;
isAdjusting = true;
int index = model.getSelectedIndex();
if (slider.getValue() - 1 != index) {
slider.setValue(index + 1);
}
// if the same refresh to be sure!!
if (renderer != null) {
if (index != -1) {
// minus 1 for the slider
Object value = model.getElementAt(index);
if (renderer.getDataAdapterList() != null) {
renderer.getListCellRendererComponent(this, value, index, false, true);
} else {
Debug.error("Illegalstate calling getListCellRendererComponent on a Render Component that has no dataadapterlist for form: " + controller, new RuntimeException("Illegalstate calling getListCellRendererComponent on a Render Component that has no dataadapterlist for form: " + controller));
}
} else {
PrototypeState state = null;
if (model != null) {
state = ((IFoundSetInternal) model).getPrototypeState();
} else {
state = new PrototypeState(null);
}
if (renderer.getDataAdapterList() != null) {
renderer.getListCellRendererComponent(this, state, -1, false, true);
} else {
Debug.error("Illegalstate calling getListCellRendererComponent on a Render Component that has no dataadapterlist for form: " + controller, new RuntimeException("Illegalstate calling getListCellRendererComponent on a Render Component that has no dataadapterlist for form: " + controller));
}
}
}
isAdjusting = false;
}
use of com.servoy.j2db.dataprocessing.PrototypeState 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.PrototypeState 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.PrototypeState in project servoy-client by Servoy.
the class CellAdapter method testCalc.
private boolean testCalc(final String possibleCalcDataprovider, final IRecordInternal state, final int row, final int column, final ISwingFoundSet foundset) {
if (state != null && state.getRawData() != null && !(state instanceof PrototypeState || state instanceof FindState) && state.getRawData().containsCalculation(possibleCalcDataprovider) && state.getRawData().mustRecalculate(possibleCalcDataprovider, true)) {
IApplication app = dal.getApplication();
convertAndSetValue(((IDisplayData) renderer), state.getRawData().getValue(possibleCalcDataprovider));
// $NON-NLS-1$
final String key = row + "_" + possibleCalcDataprovider;
if (!rowAndDataprovider.contains(key)) {
rowAndDataprovider.add(key);
app.getScheduledExecutor().execute(new Runnable() {
public void run() {
state.getValue(possibleCalcDataprovider);
application.invokeLater(new Runnable() {
public void run() {
rowAndDataprovider.remove(key);
foundset.fireTableModelEvent(row, row, column, TableModelEvent.UPDATE);
Container parent = table.getParent();
while (parent != null && !(parent instanceof ListView)) {
parent = parent.getParent();
}
if (parent instanceof ListView) {
((ListView) parent).repaint();
}
}
});
}
});
}
return true;
}
return false;
}
Aggregations