use of com.servoy.j2db.ui.RenderEventExecutor in project servoy-client by Servoy.
the class RuntimeDataCalendar method setFormat.
public void setFormat(String formatString) {
if (!Utils.safeEquals(formatString, getFormat())) {
setComponentFormat(new ComponentFormat(FormatParser.parseFormatProperty(application.getI18NMessageIfPrefixed(formatString)), componentFormat == null ? IColumnTypes.TEXT : componentFormat.dpType, componentFormat == null ? IColumnTypes.TEXT : componentFormat.uiType));
getChangesRecorder().setChanged();
RenderEventExecutor renderEventExecutor = getRenderEventExecutor();
IScriptRenderMethods renderable = getRenderable();
if (renderEventExecutor != null && !renderEventExecutor.isOnRenderExecuting() && renderable instanceof RenderableWrapper) {
((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_FORMAT);
}
fireOnRender();
}
}
use of com.servoy.j2db.ui.RenderEventExecutor in project servoy-client by Servoy.
the class TableView method isCellEditable.
@Override
public boolean isCellEditable(int row, int column) {
boolean isCellEditable = super.isCellEditable(row, column);
if (isCellEditable) {
Object o = getCellEditor(row, column);
if (o instanceof CellAdapter && ((CellAdapter) o).getEditor() instanceof IScriptableProvider && ((IScriptableProvider) ((CellAdapter) o).getEditor()).getScriptObject() instanceof ISupportOnRenderCallback) {
Object value = getValueAt(row, column);
boolean isSelected = isCellSelected(row, column);
Component c = ((CellAdapter) o).getTableCellEditorComponent(this, value, isSelected, row, column);
if (c instanceof IScriptableProvider) {
IScriptable scriptable = ((IScriptableProvider) c).getScriptObject();
if (scriptable instanceof ISupportOnRenderCallback) {
RenderEventExecutor renderEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
if (renderEventExecutor != null) {
renderEventExecutor.fireOnRender(false);
isCellEditable = c.isEnabled();
}
}
}
}
}
return isCellEditable;
}
use of com.servoy.j2db.ui.RenderEventExecutor 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;
}
use of com.servoy.j2db.ui.RenderEventExecutor in project servoy-client by Servoy.
the class CellAdapter method getTableCellRendererComponent.
/*
* @see TableCellRenderer#getTableCellRendererComponent(JTable, Object, boolean, boolean, int, int)
*/
public Component getTableCellRendererComponent(JTable jtable, Object value, boolean isSelected, boolean hasFocus, final int row, final int column) {
if (renderer == null || !isVisible(renderer) || !(jtable.getModel() instanceof IFoundSetInternal)) {
return empty;
}
final ISwingFoundSet foundset = (ISwingFoundSet) jtable.getModel();
if (foundset != tableViewFoundset) {
// foundset changed
this.tableViewFoundset = foundset;
rowAndDataprovider.clear();
}
final IRecordInternal state;
try {
state = foundset.getRecord(row);
} catch (RuntimeException re) {
// $NON-NLS-1$
Debug.error("Error getting row ", re);
return empty;
}
RenderEventExecutor renderEventExecutor = null;
IScriptRenderMethods renderable = null;
if (renderer instanceof IScriptableProvider) {
IScriptable scriptable = ((IScriptableProvider) renderer).getScriptObject();
if (scriptable instanceof ISupportOnRenderCallback) {
renderEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
renderable = ((ISupportOnRenderCallback) scriptable).getRenderable();
}
}
Color bgColor = getBgColor(jtable, isSelected, row, false);
if (bgColor != null && renderer instanceof JComponent)
((JComponent) renderer).setOpaque(true);
Color fgColor = getFgColor(jtable, isSelected, row);
Font font = getFont(jtable, isSelected, row);
// so that getLocation and getWidth in scripting on tableviews do work.
if (editor != null && editor.getParent() == null) {
Rectangle cellRect = jtable.getCellRect(row, column, false);
editor.setLocation(cellRect.x, cellRect.y);
editor.setSize(cellRect.width, cellRect.height);
}
boolean isRenderWithOnRender = renderEventExecutor != null && renderEventExecutor.hasRenderCallback() && renderable instanceof RenderableWrapper;
Color renderBgColor = null;
if (isSelected) {
if (!isRenderWithOnRender || renderEventExecutor.isDifferentRenderState(state, row, isSelected)) {
Color tableSelectionColor = jtable.getSelectionForeground();
if (bgColor != null) {
tableSelectionColor = adjustColorDifference(bgColor, tableSelectionColor);
}
((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_FGCOLOR);
renderer.setForeground(fgColor != null ? fgColor : tableSelectionColor);
((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_BGCOLOR);
renderBgColor = (bgColor != null ? bgColor : jtable.getSelectionBackground());
renderer.setBackground(renderBgColor);
if (font != null) {
((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_FONT);
renderer.setFont(font);
}
} else if (isRenderWithOnRender && foundset.getSize() == 1) {
// if the foundset contains a single record, we need to force trigger onRender
// because renderEventExecutor refers already to the changed render state
renderEventExecutor.setRenderStateChanged();
}
} else {
if (isRenderWithOnRender) {
if (renderEventExecutor.isDifferentRenderState(state, row, isSelected)) {
Color newBGColor = bgColor != null ? bgColor : componentBgColor;
if (newBGColor != null) {
((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_BGCOLOR);
renderBgColor = newBGColor;
renderer.setBackground(renderBgColor);
}
Color newFGColor = fgColor != null ? fgColor : componentFgColor;
if (newFGColor != null) {
((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_FGCOLOR);
renderer.setForeground(newFGColor);
} else if (newBGColor != null) {
renderer.setForeground(adjustColorDifference(newBGColor, jtable.getForeground()));
}
Font newFont = font != null ? font : componentFont;
if (newFont != null) {
((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_FONT);
renderer.setFont(newFont);
}
}
} else {
// now get the editors background. if we don't do that then scripting doesn't show up
Color background = editor.getBackground();
if (background != null && !background.equals(lastEditorBgColor)) {
unselectedBackground = background;
lastEditorBgColor = background;
}
Font editorFont = editor.getFont();
if (editorFont != null && !editorFont.equals(lastEditorFont)) {
unselectedFont = editorFont;
}
if (editor instanceof IDisplayData && ((IDisplayData) editor).isValueValid() || !(editor instanceof IDisplayData)) {
Color foreground = editor.getForeground();
if (foreground != null && !foreground.equals(lastEditorFgColor)) {
unselectedForeground = foreground;
}
Color currentForeground = (fgColor != null ? fgColor : (unselectedForeground != null) ? unselectedForeground : jtable.getForeground());
renderer.setForeground(currentForeground);
}
Color currentColor = (bgColor != null ? bgColor : (unselectedBackground != null) ? unselectedBackground : jtable.getBackground());
renderer.setBackground(currentColor);
Font currentFont = (font != null ? font : (unselectedFont != null) ? unselectedFont : jtable.getFont());
renderer.setFont(currentFont);
}
}
if (renderer instanceof JComponent) {
applyRowBorder((JComponent) renderer, jtable, isSelected, row, hasFocus);
}
// $NON-NLS-1$
boolean printing = Utils.getAsBoolean(application.getRuntimeProperties().get("isPrinting"));
if (renderEventExecutor != null && renderEventExecutor.hasRenderCallback()) {
renderEventExecutor.setRenderState(state, row, isSelected, true);
}
if (renderer instanceof IDisplayRelatedData) {
IDisplayRelatedData drd = (IDisplayRelatedData) renderer;
String relationName = drd.getSelectedRelationName();
if (state != null) {
if (relationName != null) {
if (!printing && !state.isRelatedFoundSetLoaded(relationName, null)) {
IApplication app = dal.getApplication();
((IDisplayData) renderer).setValueObject(null);
// $NON-NLS-1$ //$NON-NLS-2$
String key = row + "_" + relationName + "_" + null;
if (!rowAndDataprovider.contains(key)) {
rowAndDataprovider.add(key);
Runnable r = new ASynchonizedCellLoad(app, jtable, foundset, row, jtable.convertColumnIndexToModel(column), relationName, drd.getDefaultSort(), null);
app.getScheduledExecutor().execute(r);
}
return renderer.isVisible() ? renderer : empty;
}
}
drd.setRecord(state, true);
}
}
if (renderer instanceof IDisplayData) {
if (state != null) {
Object data = null;
if (dataProviderID != null) {
int index = -1;
if (!printing && (index = dataProviderID.indexOf('.')) > 0) {
if (!ScopesUtils.isVariableScope(dataProviderID)) {
String partName = dataProviderID.substring(0, index);
final String restName = dataProviderID.substring(index + 1);
String relationName = partName;
if (relationName != null && !state.isRelatedFoundSetLoaded(relationName, restName)) {
IApplication app = dal.getApplication();
((IDisplayData) renderer).setValueObject(null);
// $NON-NLS-1$ //$NON-NLS-2$
String key = row + "_" + relationName + "_" + restName;
if (!rowAndDataprovider.contains(key)) {
rowAndDataprovider.add(key);
List<SortColumn> defaultPKSortColumns = null;
try {
defaultPKSortColumns = app.getFoundSetManager().getDefaultPKSortColumns(app.getFlattenedSolution().getRelation(relationName).getForeignDataSource());
} catch (ServoyException e) {
Debug.error(e);
}
Runnable r = new ASynchonizedCellLoad(app, jtable, foundset, row, jtable.convertColumnIndexToModel(column), relationName, defaultPKSortColumns, restName);
app.getScheduledExecutor().execute(r);
}
return renderer.isVisible() ? renderer : empty;
}
IFoundSetInternal rfs = state.getRelatedFoundSet(relationName);
if (rfs != null) {
int selected = rfs.getSelectedIndex();
// should still go through record 0
if (selected == -1 && rfs.getSize() > 0) {
selected = 0;
}
final IRecordInternal relState = rfs.getRecord(selected);
if (testCalc(restName, relState, row, jtable.convertColumnIndexToModel(column), foundset))
return renderer;
}
}
}
if (!((IDisplayData) renderer).needEntireState() && !printing && testCalc(dataProviderID, state, row, jtable.convertColumnIndexToModel(column), foundset)) {
return renderer;
}
try {
data = dal.getValueObject(state, dataProviderID);
} catch (IllegalArgumentException iae) {
Debug.error(iae);
// $NON-NLS-1$
data = "<conversion error>";
}
}
((IDisplayData) renderer).setTagResolver(new ITagResolver() {
public String getStringValue(String nm) {
return TagResolver.formatObject(dal.getValueObject(state, nm), dal.getApplication());
}
});
if (data instanceof DbIdentValue) {
data = ((DbIdentValue) data).getPkValue();
}
convertAndSetValue(((IDisplayData) renderer), data);
}
}
if (renderer instanceof IServoyAwareBean && state != null) {
((IServoyAwareBean) renderer).setSelectedRecord(new ServoyBeanState(state, dal.getFormScope()));
}
if (!(renderer instanceof IDisplayData) && !(renderer instanceof IDisplayRelatedData) && renderEventExecutor != null && renderEventExecutor.hasRenderCallback()) {
renderEventExecutor.fireOnRender(false);
}
// if the bgcolor is not changed during onRender
if (isRenderWithOnRender && renderBgColor != null && ((RenderableWrapper) renderable).getProperty(RenderableWrapper.PROPERTY_BGCOLOR) == null) {
renderer.setBackground(renderBgColor);
}
return renderer.isVisible() ? renderer : empty;
}
use of com.servoy.j2db.ui.RenderEventExecutor in project servoy-client by Servoy.
the class ComponentFactory method createField.
private static IComponent createField(IApplication application, Form form, Field field, IDataProviderLookup dataProviderLookup, IScriptExecuter el, boolean printing) {
ValueList valuelist = application.getFlattenedSolution().getValueList(field.getValuelistID());
ComponentFormat fieldFormat = ComponentFormat.getComponentFormat(field.getFormat(), field.getDataProviderID(), dataProviderLookup, application);
IDataProvider dp = null;
if (field.getDataProviderID() != null && dataProviderLookup != null) {
try {
dp = dataProviderLookup.getDataProvider(field.getDataProviderID());
} catch (RepositoryException e) {
Debug.error(e);
}
}
// apply any style
Insets style_margin = null;
int style_halign = -1;
boolean hasBorder = false;
Pair<IStyleSheet, IStyleRule> styleInfo = getStyleForBasicComponent(application, field, form);
if (styleInfo != null) {
IStyleSheet ss = styleInfo.getLeft();
IStyleRule s = styleInfo.getRight();
if (ss != null && s != null) {
style_margin = ss.getMargin(s);
style_halign = ss.getHAlign(s);
hasBorder = ss.hasBorder(s);
}
}
IStylePropertyChangesRecorder jsChangeRecorder = application.getItemFactory().createChangesRecorder();
IFieldComponent fl;
AbstractRuntimeField<? extends IFieldComponent> scriptable;
switch(field.getDisplayType()) {
case Field.PASSWORD:
{
RuntimeDataPassword so;
scriptable = so = new RuntimeDataPassword(jsChangeRecorder, application);
fl = application.getItemFactory().createDataPassword(so, getWebID(form, field));
so.setComponent(fl, field);
}
break;
case Field.RTF_AREA:
{
RuntimeRtfArea so;
scriptable = so = new RuntimeRtfArea(jsChangeRecorder, application);
fl = application.getItemFactory().createDataTextEditor(so, getWebID(form, field), RTF_AREA, field.getEditable());
so.setComponent(fl, field);
if (fl instanceof IScrollPane) {
applyScrollBarsProperty((IScrollPane) fl, field);
}
}
break;
case Field.HTML_AREA:
{
RuntimeHTMLArea so;
scriptable = so = new RuntimeHTMLArea(jsChangeRecorder, application);
fl = application.getItemFactory().createDataTextEditor(so, getWebID(form, field), HTML_AREA, field.getEditable());
so.setComponent(fl, field);
if (fl instanceof IScrollPane) {
applyScrollBarsProperty((IScrollPane) fl, field);
}
}
break;
case Field.TEXT_AREA:
{
RuntimeTextArea so;
scriptable = so = new RuntimeTextArea(jsChangeRecorder, application);
fl = application.getItemFactory().createDataTextArea(so, getWebID(form, field));
so.setComponent(fl, field);
if (fl instanceof IScrollPane) {
applyScrollBarsProperty((IScrollPane) fl, field);
}
}
break;
case Field.CHECKS:
{
AbstractRuntimeValuelistComponent<IFieldComponent> so;
if (valuelist != null) {
IValueList list = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, field.getDataProviderID());
if (isSingleValue(valuelist)) {
scriptable = so = new RuntimeCheckbox(jsChangeRecorder, application);
fl = application.getItemFactory().createCheckBox((RuntimeCheckbox) so, getWebID(form, field), application.getI18NMessageIfPrefixed(field.getText()), list);
} else {
scriptable = so = new RuntimeCheckBoxChoice(jsChangeRecorder, application);
fl = application.getItemFactory().createDataChoice((RuntimeCheckBoxChoice) so, getWebID(form, field), list, false, fieldFormat == null || fieldFormat.dpType == IColumnTypes.TEXT);
if (fl instanceof IScrollPane) {
applyScrollBarsProperty((IScrollPane) fl, field);
}
}
} else {
scriptable = so = new RuntimeCheckbox(jsChangeRecorder, application);
fl = application.getItemFactory().createCheckBox((RuntimeCheckbox) so, getWebID(form, field), application.getI18NMessageIfPrefixed(field.getText()), null);
}
so.setComponent(fl, field);
}
break;
case Field.RADIOS:
{
AbstractRuntimeValuelistComponent<IFieldComponent> so;
IValueList list = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, field.getDataProviderID());
if (isSingleValue(valuelist)) {
scriptable = so = new RuntimeRadioButton(jsChangeRecorder, application);
fl = application.getItemFactory().createRadioButton((RuntimeRadioButton) so, getWebID(form, field), application.getI18NMessageIfPrefixed(field.getText()), list);
} else {
scriptable = so = new RuntimeRadioChoice(jsChangeRecorder, application);
fl = application.getItemFactory().createDataChoice((RuntimeRadioChoice) so, getWebID(form, field), list, true, false);
if (fl instanceof IScrollPane) {
applyScrollBarsProperty((IScrollPane) fl, field);
}
}
so.setComponent(fl, field);
}
break;
case Field.COMBOBOX:
{
RuntimeDataCombobox so;
scriptable = so = new RuntimeDataCombobox(jsChangeRecorder, application);
IValueList list = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, field.getDataProviderID());
fl = application.getItemFactory().createDataComboBox(so, getWebID(form, field), list);
so.setComponent(fl, field);
}
break;
case Field.CALENDAR:
{
RuntimeDataCalendar so;
scriptable = so = new RuntimeDataCalendar(jsChangeRecorder, application);
fl = application.getItemFactory().createDataCalendar(so, getWebID(form, field));
so.setComponent(fl, field);
}
break;
case Field.IMAGE_MEDIA:
{
RuntimeMediaField so;
scriptable = so = new RuntimeMediaField(jsChangeRecorder, application);
fl = application.getItemFactory().createDataImgMediaField(so, getWebID(form, field));
if (fl instanceof IScrollPane) {
applyScrollBarsProperty((IScrollPane) fl, field);
}
so.setComponent(fl, field);
}
break;
case Field.TYPE_AHEAD:
if (field.getValuelistID() > 0) {
fl = createTypeAheadWithValueList(application, form, field, dataProviderLookup, fieldFormat.uiType, fieldFormat.parsedFormat, jsChangeRecorder);
if (fl == null)
return null;
scriptable = (AbstractRuntimeField<? extends IFieldComponent>) fl.getScriptObject();
break;
}
if (// only allow plain columns
dp != null && dp.getColumnWrapper() != null && dp.getColumnWrapper().getRelations() == null) {
RuntimeDataLookupField so;
scriptable = so = new RuntimeDataLookupField(jsChangeRecorder, application);
fl = application.getItemFactory().createDataLookupField(so, getWebID(form, field), form.getServerName(), form.getTableName(), dp == null ? field.getDataProviderID() : dp.getDataProviderID());
so.setComponent(fl, field);
break;
} else {
RuntimeDataField so;
scriptable = so = new RuntimeDataField(jsChangeRecorder, application);
fl = application.getItemFactory().createDataField(so, getWebID(form, field));
so.setComponent(fl, field);
break;
}
// $FALL-THROUGH$
case Field.LIST_BOX:
case Field.MULTISELECT_LISTBOX:
{
boolean multiSelect = (field.getDisplayType() == Field.MULTISELECT_LISTBOX);
RuntimeListBox so;
scriptable = so = new RuntimeListBox(jsChangeRecorder, application, multiSelect);
IValueList list = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, field.getDataProviderID());
fl = application.getItemFactory().createListBox(so, getWebID(form, field), list, multiSelect);
so.setComponent(fl, field);
}
break;
case Field.SPINNER:
{
RuntimeSpinner so;
scriptable = so = new RuntimeSpinner(jsChangeRecorder, application);
IValueList list = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, field.getDataProviderID());
fl = application.getItemFactory().createSpinner(so, getWebID(form, field), list);
so.setComponent(fl, field);
break;
}
// else treat as the default case: TEXT_FIELD
default:
// Field.TEXT_FIELD
if (field.getValuelistID() > 0) {
fl = createTypeAheadWithValueList(application, form, field, dataProviderLookup, fieldFormat.uiType, fieldFormat.parsedFormat, jsChangeRecorder);
if (fl == null)
return null;
scriptable = (AbstractRuntimeField<? extends IFieldComponent>) fl.getScriptObject();
} else {
RuntimeDataField so;
scriptable = so = new RuntimeDataField(jsChangeRecorder, application);
fl = application.getItemFactory().createDataField(so, getWebID(form, field));
so.setComponent(fl, field);
}
}
if (fl instanceof ISupportAsyncLoading) {
((ISupportAsyncLoading) fl).setAsyncLoadingEnabled(!printing);
}
fl.setSelectOnEnter(field.getSelectOnEnter());
fl.setEditable(field.getEditable());
try {
int halign = field.getHorizontalAlignment();
if (halign != -1) {
fl.setHorizontalAlignment(halign);
} else if (style_halign != -1) {
fl.setHorizontalAlignment(style_halign);
}
} catch (RuntimeException e) {
// just ignore...Debug.error(e);
}
fl.setToolTipText(application.getI18NMessageIfPrefixed(field.getToolTipText()));
fl.setTitleText(application.getI18NMessageIfPrefixed(field.getText()));
fl.setDataProviderID(dp == null ? field.getDataProviderID() : dp.getDataProviderID());
if (field.getDataProviderID() != null && dataProviderLookup != null) {
if (scriptable instanceof IFormatScriptComponent) {
((IFormatScriptComponent) scriptable).setComponentFormat(fieldFormat);
}
if (dp != null) {
// if (valuelist != null && valuelist.getValueListType() != ValueList.CUSTOM_VALUES) type = valuelist.getDisplayValueType();
int l = dp.getLength();
int defaultType = Column.mapToDefaultType(fieldFormat.dpType);
boolean skipMaxLength = false;
if (valuelist != null) {
// if the display values are different than the real values, then maxlength should be skipped
IValueList vl = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, dp.getDataProviderID());
skipMaxLength = vl.hasRealValues();
}
if (l > 0 && (defaultType == IColumnTypes.TEXT || defaultType == IColumnTypes.MEDIA) && !skipMaxLength) {
fl.setMaxLength(l);
}
}
}
// fl.setOpaque(!field.getTransparent());
if (field.getDisplaysTags()) {
fl.setNeedEntireState(true);
if (field.getDataProviderID() == null && field.getText() != null && fl instanceof IDisplayTagText) {
((IDisplayTagText) fl).setTagText(field.getText());
}
}
if (// el is an ActionListener
el != null) {
fl.addScriptExecuter(el);
Object[] cmds = combineMethodsToCommands(form, form.getOnElementFocusGainedMethodID(), "onElementFocusGainedMethodID", field, field.getOnFocusGainedMethodID(), "onFocusGainedMethodID");
if (cmds != null)
fl.setEnterCmds((String[]) cmds[0], (Object[][]) cmds[1]);
cmds = combineMethodsToCommands(form, form.getOnElementFocusLostMethodID(), "onElementFocusLostMethodID", field, field.getOnFocusLostMethodID(), "onFocusLostMethodID");
if (cmds != null)
fl.setLeaveCmds((String[]) cmds[0], (Object[][]) cmds[1]);
if (field.getOnActionMethodID() > 0)
fl.setActionCmd(Integer.toString(field.getOnActionMethodID()), Utils.parseJSExpressions(field.getFlattenedMethodArguments("onActionMethodID")));
if (field.getOnDataChangeMethodID() > 0)
fl.setChangeCmd(Integer.toString(field.getOnDataChangeMethodID()), Utils.parseJSExpressions(field.getFlattenedMethodArguments("onDataChangeMethodID")));
if (field.getOnRightClickMethodID() > 0)
fl.setRightClickCommand(Integer.toString(field.getOnRightClickMethodID()), Utils.parseJSExpressions(field.getFlattenedMethodArguments("onRightClickMethodID")));
}
int onRenderMethodID = field.getOnRenderMethodID();
AbstractBase onRenderPersist = field;
if (onRenderMethodID <= 0) {
onRenderMethodID = form.getOnRenderMethodID();
onRenderPersist = form;
}
if (onRenderMethodID > 0) {
RenderEventExecutor renderEventExecutor = scriptable.getRenderEventExecutor();
renderEventExecutor.setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(onRenderPersist.getFlattenedMethodArguments("onRenderMethodID")));
IForm rendererForm = application.getFormManager().getForm(form.getName());
IScriptExecuter rendererScriptExecuter = rendererForm instanceof FormController ? ((FormController) rendererForm).getScriptExecuter() : null;
renderEventExecutor.setRenderScriptExecuter(rendererScriptExecuter);
}
applyBasicComponentProperties(application, fl, field, styleInfo);
if (fl instanceof INullableAware) {
INullableAware nullAware = (INullableAware) fl;
boolean allowNull = true;
// become 0 (because it is unchecked) so that the user does not need to check/uncheck it for save
try {
if (dataProviderLookup != null && dataProviderLookup.getTable() != null && field.getDataProviderID() != null) {
String dataproviderId = dp == null ? field.getDataProviderID() : dp.getDataProviderID();
if (dataProviderLookup.getTable().getColumn(dataproviderId) != null) {
allowNull = dataProviderLookup.getTable().getColumn(dataproviderId).getAllowNull();
}
}
} catch (RepositoryException e) {
// maybe this field is not linked to a table column... so leave it true
}
nullAware.setAllowNull(allowNull);
}
Insets m = field.getMargin();
if (m == null)
m = style_margin;
if (m != null) {
fl.setMargin(m);
if (fl instanceof IMarginAwareBorder) {
if (field.getBorderType() != null || hasBorder) {
Border b = fl.getBorder();
if (b != null) {
fl.setBorder(BorderFactory.createCompoundBorder(b, BorderFactory.createEmptyBorder(m.top, m.left, m.bottom, m.right)));
}
}
}
}
if (fl.getScriptObject() instanceof HasRuntimePlaceholder) {
((HasRuntimePlaceholder) fl.getScriptObject()).setPlaceholderText(field.getPlaceholderText());
}
return fl;
}
Aggregations