use of com.servoy.j2db.util.IDelegate in project servoy-client by Servoy.
the class DataRendererDefinition method getPreferedBreakInternal.
private int getPreferedBreakInternal(RendererParentWrapper renderParent, int breakPosition) {
// the break position is relative to the remaining area to be used from the renderer; create the absolute breakk position for the renderer
Rectangle breakRect = new Rectangle(0, startYOrgin + breakPosition, getFullSize().width, 1);
// if we do not find a satisfactory break point, we use the first intersecting component desired break point
int firstConsideredBreak = -1;
// the last component that changed the preferred break point
Component lastComponent = null;
Iterator it = bounds.keySet().iterator();
while (it.hasNext()) {
Component component = (Component) it.next();
Rectangle cbounds = (Rectangle) bounds.get(component);
if (cbounds.intersects(breakRect) && component != lastComponent) {
Component comp = component;
int pos;
if (comp instanceof PortalComponent) {
Rectangle allocation = new Rectangle(cbounds);
PortalComponent pc = (PortalComponent) comp;
Insets ins2 = pc.getBorder().getBorderInsets(pc);
allocation.x += ins2.left;
allocation.y += ins2.top;
allocation.width -= ins2.right;
allocation.height -= ins2.bottom;
// give free space and receive preferred break relative to component
pos = pc.getPreferredBreak((startYOrgin + breakPosition - allocation.y));
if (pos != 0) {
// make preferred break relative to the renderer
pos = pos + allocation.y - startYOrgin;
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Debug.trace("PortalComponent " + cbounds + " requested break for " + breakPosition + " used break " + pos);
} else {
// no use breaking immediately after the border (no useful info)
pos = cbounds.getLocation().y - startYOrgin;
}
} else {
if (component instanceof IDelegate) {
comp = (Component) ((IDelegate) component).getDelegate();
}
if (comp instanceof JTextComponent) {
if (comp instanceof JTextField) {
// optimize, cannot break single line components, return the Y location
pos = cbounds.getLocation().y - startYOrgin;
} else {
JTextComponent tcomp = (JTextComponent) comp;
Rectangle allocation = new Rectangle(cbounds);
if (component instanceof JComponent) {
// ==scrollpane border
Insets ins2 = ((JComponent) component).getBorder().getBorderInsets(component);
if (ins2 != null) {
allocation.x += ins2.left;
allocation.y += ins2.top;
allocation.width -= ins2.right;
allocation.height -= ins2.bottom;
}
}
// ==margin
Insets ins2 = tcomp.getBorder().getBorderInsets(component);
if (ins2 != null) {
allocation.x += ins2.left;
allocation.y += ins2.top;
allocation.width -= ins2.right;
allocation.height -= ins2.bottom;
}
pos = searchDesiredBreakThroughViews((startYOrgin + breakPosition - allocation.y), 0, tcomp, 0, new Rectangle(0, 0, allocation.width, allocation.height));
if (pos != 0) {
// correct for location
pos = pos - startYOrgin + allocation.y;
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Debug.trace("JTextComponent " + cbounds + " requested break for " + breakPosition + " used break " + pos);
} else {
// no use breaking immediately after the border (no useful info)
pos = cbounds.getLocation().y - startYOrgin;
}
}
} else // for all other components
{
// optimize, better stop before comp
pos = cbounds.getLocation().y - startYOrgin;
}
}
// the current intersected component decided where it would want the page to break (pos); compare with the current break position
if (breakPosition != pos) {
// we have to modify the desired (page) break point
breakPosition = pos;
breakRect.y = startYOrgin + breakPosition;
// restart search for components that intersect the new considered break position
it = bounds.keySet().iterator();
if ((firstConsideredBreak == -1) && (breakPosition > 0)) {
firstConsideredBreak = breakPosition;
}
lastComponent = component;
}
if (breakPosition < 0) {
// the components that we would find below 0 from this part are already printed - so we did not find a convenient
break;
// break point in the given vertical space
}
}
}
if (breakPosition <= 0) {
// no satisfactory normal break position; returns the first found break position (that can be < 0 too if not found)
return firstConsideredBreak;
} else {
// found a good break position
return breakPosition;
}
}
use of com.servoy.j2db.util.IDelegate in project servoy-client by Servoy.
the class FixedJTable method isCellEditable.
/*
* @see javax.swing.JTable#isCellEditable(int, int)
*/
@Override
public boolean isCellEditable(int row, int column) {
Object o = getCellEditor(row, column);
if (o instanceof CellAdapter) {
Component comp = ((CellAdapter) o).getEditor();
boolean isReadOnlyEditor = (comp instanceof IDelegate) && (((IDelegate) comp).getDelegate() instanceof JEditorPane) && !((JEditorPane) ((IDelegate) comp).getDelegate()).isEditable();
if ((comp instanceof JButton || comp instanceof JLabel || isReadOnlyEditor) && comp.isEnabled()) {
return true;
}
}
return super.isCellEditable(row, column);
}
use of com.servoy.j2db.util.IDelegate in project servoy-client by Servoy.
the class Record method put.
public void put(String name, Scriptable start, final Object value) {
try {
// $NON-NLS-1$ //$NON-NLS-2$
if ("foundset".equals(name) || "exception".equals(name))
return;
// dont allow to set
if (jsFunctions.containsKey(name))
return;
Object realValue = value;
if (realValue instanceof IDelegate<?>) {
realValue = ((IDelegate<?>) realValue).getDelegate();
if (realValue instanceof IDataSet) {
IDataSet set = (IDataSet) realValue;
StringBuilder sb = new StringBuilder();
sb.append('\n');
for (int i = 0; i < set.getRowCount(); i++) {
sb.append(set.getRow(i)[0]);
sb.append('\n');
}
realValue = sb.toString();
}
} else if (realValue instanceof FoundSet) {
StringBuilder sb = new StringBuilder();
sb.append('\n');
FoundSet fs = (FoundSet) realValue;
for (int i = 0; i < fs.getSize(); i++) {
IRecordInternal record = fs.getRecord(i);
sb.append(record.getPKHashKey());
sb.append('\n');
}
realValue = sb.toString();
} else {
Object tmp = realValue;
while (tmp instanceof Wrapper) {
tmp = ((Wrapper) tmp).unwrap();
if (tmp == realValue) {
break;
}
}
realValue = tmp;
}
boolean dbColumn = parent.getSQLSheet().getColumnIndex(name) != -1;
if (// make sure any js change is noted
!dbColumn || startEditing()) {
if (realValue instanceof Date) {
// make copy so then when it is further used in js it won't change this one.
// make copy so changes are seen (date is mutable and whould bypass equals)
realValue = new Date(((Date) realValue).getTime());
}
Object oldVal = setValue(name, realValue);
if (// did change?
oldVal != realValue) {
fireJSModificationEvent(name, realValue);
}
} else {
((FoundSetManager) parent.getFoundSetManager()).getApplication().handleException(null, new ApplicationException(ServoyException.RECORD_LOCKED));
}
} catch (RuntimeException e) {
throw new WrappedException(e);
}
}
use of com.servoy.j2db.util.IDelegate 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.util.IDelegate in project servoy-client by Servoy.
the class AbstractRuntimeRendersupportComponent method setComponent.
@Override
public void setComponent(C component, IPersist persist) {
super.setComponent(component, persist);
if (component instanceof Component) {
Component focusComponent = (Component) component;
if (component instanceof IDelegate<?>) {
Object delegate = ((IDelegate<?>) component).getDelegate();
if (delegate instanceof Component)
focusComponent = (Component) delegate;
}
focusComponent.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent e) {
getRenderEventExecutor().setRenderStateChanged();
getRenderEventExecutor().fireOnRender(false);
}
public void focusGained(FocusEvent e) {
getRenderEventExecutor().setRenderStateChanged();
getRenderEventExecutor().fireOnRender(true);
}
});
}
}
Aggregations