Search in sources :

Example 1 with IDelegate

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;
    }
}
Also used : Insets(java.awt.Insets) Rectangle(java.awt.Rectangle) Iterator(java.util.Iterator) JComponent(javax.swing.JComponent) PortalComponent(com.servoy.j2db.smart.dataui.PortalComponent) JTextComponent(javax.swing.text.JTextComponent) JComponent(javax.swing.JComponent) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent) PortalComponent(com.servoy.j2db.smart.dataui.PortalComponent) JTextField(javax.swing.JTextField) IDelegate(com.servoy.j2db.util.IDelegate)

Example 2 with IDelegate

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);
}
Also used : JEditorPane(javax.swing.JEditorPane) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) EventObject(java.util.EventObject) CellAdapter(com.servoy.j2db.smart.dataui.CellAdapter) Component(java.awt.Component) IDelegate(com.servoy.j2db.util.IDelegate)

Example 3 with IDelegate

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);
    }
}
Also used : Wrapper(org.mozilla.javascript.Wrapper) WrappedException(org.mozilla.javascript.WrappedException) IJSFoundSet(com.servoy.base.scripting.api.IJSFoundSet) Date(java.util.Date) ApplicationException(com.servoy.j2db.ApplicationException) IDelegate(com.servoy.j2db.util.IDelegate)

Example 4 with IDelegate

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;
}
Also used : Wrapper(org.mozilla.javascript.Wrapper) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) WrappedException(org.mozilla.javascript.WrappedException) Date(java.util.Date) ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) XMLObject(org.mozilla.javascript.xml.XMLObject) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) UUID(com.servoy.j2db.util.UUID) IDelegate(com.servoy.j2db.util.IDelegate)

Example 5 with IDelegate

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);
            }
        });
    }
}
Also used : IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) IDelegate(com.servoy.j2db.util.IDelegate) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Aggregations

IDelegate (com.servoy.j2db.util.IDelegate)6 Component (java.awt.Component)3 ApplicationException (com.servoy.j2db.ApplicationException)2 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)2 Date (java.util.Date)2 EventObject (java.util.EventObject)2 WrappedException (org.mozilla.javascript.WrappedException)2 Wrapper (org.mozilla.javascript.Wrapper)2 IJSFoundSet (com.servoy.base.scripting.api.IJSFoundSet)1 FindState (com.servoy.j2db.dataprocessing.FindState)1 IDataSet (com.servoy.j2db.dataprocessing.IDataSet)1 IDisplay (com.servoy.j2db.dataprocessing.IDisplay)1 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)1 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)1 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)1 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)1 ScriptVariable (com.servoy.j2db.persistence.ScriptVariable)1 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)1 CellAdapter (com.servoy.j2db.smart.dataui.CellAdapter)1 PortalComponent (com.servoy.j2db.smart.dataui.PortalComponent)1