Search in sources :

Example 11 with IDisplayData

use of com.servoy.j2db.dataprocessing.IDisplayData in project servoy-client by Servoy.

the class DataRendererFactory method placeElements.

// returns usesSliding
private Map placeElements(Iterator<IFormElement> e1, IApplication app, Form form, IScriptExecuter listner, Map emptyDataRenderers, int width, int XCorrection, int YCorrection, boolean printing, boolean cutDataProviderNames, ControllerUndoManager undoManager, boolean isPortal, TabSequenceHelper<Component> tabSequence) throws Exception {
    IDataProviderLookup dataProviderLookup = app.getFlattenedSolution().getDataproviderLookup(app.getFoundSetManager(), form);
    Map listTocomplete = new HashMap();
    Map labelForComponents = new HashMap();
    // Insets insets = new Insets(0, 0, 0, 0);
    while (e1.hasNext()) {
        Point l = null;
        IPersist obj = e1.next();
        l = ((IFormElement) obj).getLocation();
        // unkown where to add
        if (l == null)
            continue;
        if (printing && obj instanceof ISupportPrinting) {
            if (!((ISupportPrinting) obj).getPrintable())
                continue;
        }
        Iterator it = emptyDataRenderers.values().iterator();
        while (it.hasNext()) {
            DataRenderer panel = (DataRenderer) it.next();
            int start = panel.getLocation().y;
            if (l.y >= start && l.y < start + panel.getSize().height) {
                Component comp = (Component) ComponentFactory.createComponent(app, form, obj, dataProviderLookup, listner, printing);
                // Test for a visible bean, then get the real component
                if (comp instanceof VisibleBean) {
                    comp = ((VisibleBean) comp).getDelegate();
                }
                if (comp != null) {
                    if (obj instanceof Field && comp instanceof JComponent) {
                        String name = ((Field) obj).getName();
                        if (name != null && !"".equals(name)) {
                            labelForComponents.put(name, comp);
                        }
                    } else if (obj instanceof GraphicalComponent && comp instanceof JLabel) {
                        String labelFor = ((GraphicalComponent) obj).getLabelFor();
                        if (labelFor != null && !"".equals(labelFor)) {
                            labelForComponents.put(comp, labelFor);
                        }
                    }
                    if (obj instanceof ISupportTabSeq && comp instanceof JComponent && (tabSequence != null)) {
                        tabSequence.add(panel, (ISupportTabSeq) obj, comp);
                    }
                    Component newComp = comp;
                    if (newComp instanceof IDisplay) {
                        // HACK:don;t no other way to do this.........
                        if (newComp instanceof IDisplayData && cutDataProviderNames) {
                            IDisplayData da = (IDisplayData) newComp;
                            String id = da.getDataProviderID();
                            if (id != null && !ScopesUtils.isVariableScope(id)) {
                                // only cut first relation (so you can have relation chain inside portal)
                                int index = id.indexOf('.');
                                // TODO:check if part before . is same as relation name (objToRender.getRelationID() )
                                if (index > 0) {
                                    id = id.substring(index + 1);
                                }
                                da.setDataProviderID(id);
                            }
                        }
                        panel.addDisplayComponent(obj, (IDisplay) newComp);
                    }
                    comp.setLocation((l.x) + XCorrection, (l.y - start) + YCorrection);
                    int index = 0;
                    if (!printing && obj instanceof ISupportAnchors) {
                        panel.add(comp, new Integer(((ISupportAnchors) obj).getAnchors()), index);
                    } else if (printing) {
                        if (obj instanceof ISupportPrintSliding && !isPortal) {
                            int slide = ((ISupportPrintSliding) obj).getPrintSliding();
                            if (slide != ISupportPrintSliding.NO_SLIDING) {
                                listTocomplete.put(comp, new Integer(slide));
                                panel.setUsingSliding(true);
                            }
                        }
                        panel.add(comp, index);
                    } else {
                        panel.add(comp, index);
                    }
                }
            }
        }
    }
    if (!printing) {
        Iterator it = labelForComponents.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Entry) it.next();
            if (entry.getKey() instanceof JLabel) {
                JComponent component = (JComponent) labelForComponents.get(entry.getValue());
                if (component != null) {
                    ((JLabel) entry.getKey()).setLabelFor(component);
                    if (component instanceof IFieldComponent) {
                        ((IFieldComponent) component).addLabelFor((ILabel) entry.getKey());
                        if (!((IFieldComponent) component).isVisible()) {
                            ((IFieldComponent) component).setComponentVisible(((IFieldComponent) component).isVisible());
                        }
                        if (!((IFieldComponent) component).isEnabled()) {
                            ((IFieldComponent) component).setComponentEnabled(((IFieldComponent) component).isEnabled());
                        }
                    }
                }
            }
        }
    }
    Iterator it = emptyDataRenderers.values().iterator();
    while (it.hasNext()) {
        DataRenderer panel = (DataRenderer) it.next();
        panel.createDataAdapter(app, dataProviderLookup, listner, undoManager);
    }
    return listTocomplete;
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ISupportTabSeq(com.servoy.j2db.persistence.ISupportTabSeq) Field(com.servoy.j2db.persistence.Field) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(java.awt.Component) JComponent(javax.swing.JComponent) ISupportPrinting(com.servoy.j2db.persistence.ISupportPrinting) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) Point(java.awt.Point) ISupportPrintSliding(com.servoy.j2db.persistence.ISupportPrintSliding) Point(java.awt.Point) ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) IPersist(com.servoy.j2db.persistence.IPersist) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IDataProviderLookup(com.servoy.j2db.persistence.IDataProviderLookup)

Example 12 with IDisplayData

use of com.servoy.j2db.dataprocessing.IDisplayData in project servoy-client by Servoy.

the class GlobalAutoScrollerFocusListener method propertyChange.

public void propertyChange(PropertyChangeEvent e) {
    if (// $NON-NLS-1$
    "focusOwner".equals(e.getPropertyName())) {
        Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
        if (owner != null) {
            // System.out.println("focus moved to ->" + owner.getClass().getCanonicalName() + "/" + owner + "<-");
            // if (owner instanceof Component) System.out.println("\towner name is: " + (owner).getName());
            // Container focusRoot = KeyboardFocusManager.getCurrentKeyboardFocusManager().getCurrentFocusCycleRoot();
            // System.out.println("focus cycle root is now ->" + focusRoot.getClass().getCanonicalName() + "/" + focusRoot + "<-");
            owner = getEventualParentScrollPane(owner);
            /* Auto scroll only when our specific fields receive focus. */
            if (owner instanceof IDisplayData || owner instanceof ScriptButton) {
                /* Find a scrollable parent, if any. */
                JComponent scrollableParent = findScrollableParent(owner);
                while (scrollableParent != null) {
                    /* Compute the coordinates of the owner relative to the scrollable parent. */
                    Rectangle r = owner.getBounds();
                    Component c = owner.getParent();
                    while (c != scrollableParent && c != null) {
                        Rectangle s = c.getBounds();
                        r.setLocation(r.x + s.x, r.y + s.y);
                        c = c.getParent();
                    }
                    scrollableParent.scrollRectToVisible(r);
                    // If we are inside a tab panel, then we go up one level and scroll everything again,
                    // because the tab panel itself can be out of the screen now.
                    scrollableParent = findTabPanelParent(scrollableParent);
                    if (scrollableParent != null)
                        scrollableParent = findScrollableParent(scrollableParent.getParent());
                }
            }
        }
    }
}
Also used : ScriptButton(com.servoy.j2db.smart.dataui.ScriptButton) JComponent(javax.swing.JComponent) Rectangle(java.awt.Rectangle) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Example 13 with IDisplayData

use of com.servoy.j2db.dataprocessing.IDisplayData in project servoy-client by Servoy.

the class CellAdapter method valueChanged.

/*
	 * @see JSModificationListener#valueChanged(ModificationEvent)
	 */
public void valueChanged(ModificationEvent e) {
    if (adjusting)
        return;
    try {
        adjusting = true;
        // ignore globals in a cell adapter, will be handled by the row manager
        if (!table.isEditing() && ScopesUtils.isVariableScope(e.getName())) {
            // test if it is a related
            if (dataProviderID != null && dataProviderID.indexOf('.') != -1) {
                TableModel parent = table.getModel();
                if (parent instanceof ISwingFoundSet) {
                    // it could be based on that global so fire a table event.
                    ((ISwingFoundSet) parent).fireTableModelEvent(0, parent.getRowCount() - 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE);
                }
            }
            return;
        }
        // refresh value
        IRecord s = e.getRecord();
        if (s == null) {
            TableModel tm = table.getModel();
            if (tm instanceof IFoundSetInternal) {
                IFoundSetInternal fs = (IFoundSetInternal) tm;
                int selRow = fs.getSelectedIndex();
                if (selRow != -1) {
                    s = fs.getRecord(selRow);
                }
            }
        }
        if (s != null) {
            Object obj = e.getValue();
            if (e.getName().equals(dataProviderID)) {
                // make sure the change is seen and pushed to display by jtable
                fireModificationEvent(s);
            } else {
                obj = dal.getValueObject(s, dataProviderID);
                if (obj == Scriptable.NOT_FOUND) {
                    obj = null;
                }
            }
            if (s == currentEditingState && table.getEditorComponent() == editor && editor instanceof IDisplayData) {
                convertAndSetValue(((IDisplayData) editor), obj);
            }
        }
    } finally {
        adjusting = false;
    }
}
Also used : IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) IRecord(com.servoy.j2db.dataprocessing.IRecord) EventObject(java.util.EventObject) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) TableModel(javax.swing.table.TableModel) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) Point(java.awt.Point)

Example 14 with IDisplayData

use of com.servoy.j2db.dataprocessing.IDisplayData 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;
}
Also used : FormController(com.servoy.j2db.FormController) Undefined(org.mozilla.javascript.Undefined) IView(com.servoy.j2db.IView) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Color(java.awt.Color) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) ServoyException(com.servoy.j2db.util.ServoyException) ParseException(java.text.ParseException) ApplicationException(com.servoy.j2db.ApplicationException) FindState(com.servoy.j2db.dataprocessing.FindState) EventObject(java.util.EventObject) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Example 15 with IDisplayData

use of com.servoy.j2db.dataprocessing.IDisplayData 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;
}
Also used : IApplication(com.servoy.j2db.IApplication) Container(java.awt.Container) FindState(com.servoy.j2db.dataprocessing.FindState) ListView(com.servoy.j2db.smart.ListView) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState)

Aggregations

IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)24 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)8 IDisplay (com.servoy.j2db.dataprocessing.IDisplay)7 HashMap (java.util.HashMap)7 JComponent (javax.swing.JComponent)7 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)6 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)6 Point (java.awt.Point)6 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)5 IPersist (com.servoy.j2db.persistence.IPersist)5 IScriptable (com.servoy.j2db.scripting.IScriptable)5 IComponent (com.servoy.j2db.ui.IComponent)5 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)5 Component (java.awt.Component)5 EventObject (java.util.EventObject)5 Iterator (java.util.Iterator)5 Component (org.apache.wicket.Component)5 FindState (com.servoy.j2db.dataprocessing.FindState)4 IDisplayRelatedData (com.servoy.j2db.dataprocessing.IDisplayRelatedData)4 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)4