use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class ComboModelListModelWrapper method setElementAt.
/**
* @param false1
* @param i
* @param b
*/
public void setElementAt(Object aValue, int rowIndex, boolean allowEmptySelection) {
// this index is the ui index (so 0 is 1 in the list model if hideFirstValue = true)
Integer i = new Integer(rowIndex);
// to be sure it present
getSelectedRows();
boolean b = ((Boolean) aValue).booleanValue();
if (b) {
if (!multiValueSelect && selectedSet.size() > 0) {
selectedSet.clear();
}
if (selectedSet.contains(i)) {
// not changed return.
return;
}
selectedSet.add(i);
} else {
if (selectedSet.size() == 1 && selectedSet.contains(i) && !allowEmptySelection) {
// not allowed.
return;
}
if (!selectedSet.contains(i)) {
// not changed return.
return;
}
selectedSet.remove(i);
}
setSelectedItem(selectedSet.size() > 0 ? getElementAt(selectedSet.iterator().next().intValue()) : null, true);
// when firing tmp remove the listener from the relatedRecord
// so that we don't get a modification change from our own fire.
IRecordInternal tmp = null;
if (relatedRecord != null) {
relatedRecord.removeModificationListener(this);
tmp = relatedRecord;
relatedRecord = null;
}
// data changed
fireContentsChanged(this, rowIndex, rowIndex);
// selection changed
fireContentsChanged(this, -1, -1);
if (tmp != null && relatedRecord == null) {
relatedRecord = tmp;
relatedRecord.addModificationListener(this);
}
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class JSUtils method js_stringReplaceTags.
/**
* Returns the text with %%tags%% replaced, based on provided record or foundset or form.
*
* @sample
* //Next line places a string in variable x, whereby the tag(%%TAG%%) is filled with the value of the database column 'company_name' of the selected record.
* var x = utils.stringReplaceTags("The companyName of the selected record is %%company_name%% ", foundset)
* //var otherExample = utils.stringReplaceTags("The amount of the related order line %%amount%% ", order_to_orderdetails);
* //var recordExample = utils.stringReplaceTags("The amount of the related order line %%amount%% ", order_to_orderdetails.getRecord(i);
* //Next line places a string in variable y, whereby the tag(%%TAG%%) is filled with the value of the form variable 'x' of the form named 'main'.
* //var y = utils.stringReplaceTags("The value of form variable is %%x%% ", forms.main);
* //The next sample shows the use of a javascript object
* //var obj = new Object();//create a javascript object
* //obj['x'] = 'test';//assign an named value
* //var y = utils.stringReplaceTags("The value of object variable is %%x%% ", obj);//use the named value in a tag
* @param text the text tags to work with
* @param scriptable the javascript object or foundset,record,form to be used to fill in the tags
* @return the text with replaced tags
*/
public String js_stringReplaceTags(String text, Object scriptable) {
if (text != null) {
ITagResolver tagResolver = null;
Properties settings = null;
if (scriptable instanceof FoundSet) {
IRecordInternal record = ((FoundSet) scriptable).getRecord(((FoundSet) scriptable).getSelectedIndex());
if (record != null) {
settings = record.getParentFoundSet().getFoundSetManager().getApplication().getSettings();
tagResolver = TagResolver.createResolver(record);
}
} else if (scriptable instanceof IRecordInternal) {
IRecordInternal record = (IRecordInternal) scriptable;
settings = record.getParentFoundSet().getFoundSetManager().getApplication().getSettings();
tagResolver = TagResolver.createResolver(record);
} else if (scriptable instanceof BasicFormController) {
final BasicFormController fc = (BasicFormController) scriptable;
IFoundSetInternal fs = fc.getFoundSet();
final ITagResolver defaultTagResolver = (fs != null) ? TagResolver.createResolver(fs.getRecord(fs.getSelectedIndex())) : null;
settings = fc.getApplication().getSettings();
tagResolver = new ITagResolver() {
public String getStringValue(String name) {
Object value = fc.getFormScope().get(name);
if (value == null || value == Scriptable.NOT_FOUND) {
value = defaultTagResolver != null ? defaultTagResolver.getStringValue(name) : null;
}
// $NON-NLS-1$
return value != null ? value.toString() : "";
}
};
} else if (scriptable instanceof Scriptable) {
Scriptable scriptObject = (Scriptable) scriptable;
settings = Settings.getInstance();
tagResolver = TagResolver.createResolver(scriptObject, application);
}
if (tagResolver != null && settings != null) {
return Text.processTags(TagResolver.formatObject(text, application), tagResolver);
}
// $NON-NLS-1$
return "";
} else {
// $NON-NLS-1$
return "";
}
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class ScriptVariableScope method put.
public Object put(String name, Object val) {
Object value = Utils.mapToNullIfUnmanageble(val);
Integer variableType = nameType.get(name);
int type = 0;
boolean xmlType = false;
if (variableType == null) {
// global doesn't exist. dynamic new one.. so MEDIA type
type = IColumnTypes.MEDIA;
nameType.put(name, new Integer(type));
// $NON-NLS-1$//$NON-NLS-2$
Debug.trace("Warning: " + name + " is not defined in the variables, a dynamic (media type) variable is created");
} else {
if (variableType.intValue() == Types.OTHER) {
type = IColumnTypes.MEDIA;
xmlType = true;
} else {
type = Column.mapToDefaultType(variableType.intValue());
}
}
if (type == IColumnTypes.TEXT) {
Object txt = value;
while (txt instanceof IDelegate<?>) {
txt = ((IDelegate<?>) txt).getDelegate();
}
if (txt instanceof IDataSet) {
IDataSet set = (IDataSet) txt;
StringBuilder sb = new StringBuilder();
sb.append('\n');
for (int i = 0; i < set.getRowCount(); i++) {
sb.append(set.getRow(i)[0]);
sb.append('\n');
}
value = sb.toString();
} else if (txt instanceof FoundSet) {
StringBuilder sb = new StringBuilder();
sb.append('\n');
FoundSet fs = (FoundSet) txt;
for (int i = 0; i < fs.getSize(); i++) {
IRecordInternal record = fs.getRecord(i);
sb.append(record.getPKHashKey());
sb.append('\n');
}
value = sb.toString();
}
}
if (value != null && variableType != null) {
Object unwrapped = value;
while (unwrapped instanceof Wrapper) {
unwrapped = ((Wrapper) unwrapped).unwrap();
if (unwrapped == value) {
break;
}
}
if (type == IColumnTypes.MEDIA) {
if (!(unwrapped instanceof UUID)) {
Object previousValue = get(name);
if (previousValue instanceof UUID || previousValue == null) {
Iterator<ScriptVariable> scriptVariablesIte = getScriptLookup().getScriptVariables(false);
ScriptVariable sv;
while (scriptVariablesIte.hasNext()) {
sv = scriptVariablesIte.next();
if (name.equals(sv.getName())) {
if (UUID.class.getSimpleName().equals(getDeclaredType(sv))) {
value = Utils.getAsUUID(unwrapped, false);
}
break;
}
}
}
}
} else {
value = unwrapped;
try {
// dont convert with timezone here, its not ui but from scripting
value = Column.getAsRightType(variableType.intValue(), IBaseColumn.NORMAL_COLUMN, value, null, Integer.MAX_VALUE, null, true, false);
} catch (Exception e) {
throw new IllegalArgumentException(// $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"servoy.conversion.error.global", new Object[] { name, Column.getDisplayTypeString(variableType.intValue()), value }));
}
}
}
if (value instanceof Date) {
// make copy so then when it is further used in js it won't change this one.
value = new Date(((Date) value).getTime());
} else if (xmlType && value instanceof String) {
// $NON-NLS-1$
value = evalValue(name, (String) value, "internal_anon", -1);
}
Object oldVar = allVars.get(name);
allVars.put(name, value);
if (variableType != null && !Utils.equalObjects(oldVar, value)) {
fireModificationEvent(name, value);
}
return oldVar;
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class ComboModelListModelWrapper method setElements.
private void setElements(Object[] values, boolean allowEmptySelection) {
// to be sure it present
getSelectedRows();
for (int i = 0; i < values.length; i++) {
boolean b = ((Boolean) values[i]).booleanValue();
if (b) {
if (selectedSet.contains(i)) {
// not changed continue.
continue;
}
if (!multiValueSelect && selectedSet.size() > 0) {
selectedSet.clear();
}
selectedSet.add(i);
} else {
if (selectedSet.size() == 1 && selectedSet.contains(i) && !allowEmptySelection) {
// not allowed.
return;
}
if (!selectedSet.contains(i)) {
// not changed continue.
continue;
}
selectedSet.remove(i);
}
setSelectedItem(selectedSet.size() > 0 ? getElementAt(selectedSet.iterator().next().intValue()) : null, true);
}
// when firing tmp remove the listener from the relatedRecord
// so that we don't get a modification change from our own fire.
IRecordInternal tmp = null;
if (relatedRecord != null) {
relatedRecord.removeModificationListener(this);
tmp = relatedRecord;
relatedRecord = null;
}
// data changed
fireContentsChanged(this, 0, values.length - 1);
// selection changed
fireContentsChanged(this, -1, -1);
if (tmp != null && relatedRecord == null) {
relatedRecord = tmp;
relatedRecord.addModificationListener(this);
}
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class PageDefinition method render.
private void render(RendererParentWrapper c, Graphics2D graphics2D) {
Rectangle clip = graphics2D.getClipBounds();
boolean didClip = false;
graphics2D.setColor(Color.black);
Iterator<DataRendererDefinition> it = panels.iterator();
while (it.hasNext()) {
DataRendererDefinition drd = it.next();
DataRenderer partpane = drd.getDataRenderer();
// is empty body
if (partpane == null)
continue;
int Y = drd.getYlocation() - drd.getStartYOrgin();
int X = drd.getXlocation();
try {
if (drd.getPart() != null && drd.getPart().getPartType() != Part.LEADING_GRAND_SUMMARY && // setting the state in grand summary clears the grand sum
drd.getPart().getPartType() != Part.TRAILING_GRAND_SUMMARY) {
IRecordInternal state = drd.getState();
if (state instanceof PageNumberState) {
((PageNumberState) state).initPagePositionAndSize(this);
}
}
if (drd.getFullSize().height != drd.getSize().height || drd.getStartYOrgin() != 0) {
// clone
Rectangle newClip = new Rectangle(clip);
// System.out.println("Y "+Y+" ,Ylocation "+drd.getYlocation());
newClip.y = Math.max(Y, drd.getYlocation());
// Math.min(drd.getSize().height,clip.height);//only allow smaller
newClip.height = drd.getSize().height;
graphics2D.setClip(newClip.intersection(clip));
didClip = true;
} else {
didClip = false;
}
// System.out.println("drd "+drd+" didClip "+didClip);
// translate and scale does effect clipping !!!!!!!!
// set the right position (the component paint ALWAY fom its 0,0 position, becouse of the absulut positioning inside it)
graphics2D.translate(X, Y);
// only needed to get it painted (position is irrelevant)
partpane.setBounds(0, 0, drd.getSize().width, drd.getFullSize().height);
// needed for correct drawing
// this does also fill the renderer again with record data, must do also to make the summaries work
drd.tempAddToParent(c, true, false, false);
// draw the pane
drd.printAll(graphics2D);
} finally {
// needed for correct drawing
// remove imm.
drd.tempRemoveFromParent(c);
// correct translate back
graphics2D.translate(-X, -Y);
// restore
if (didClip)
graphics2D.setClip(clip);
}
}
}
Aggregations