Search in sources :

Example 6 with Field

use of com.servoy.j2db.persistence.Field in project servoy-client by Servoy.

the class FormTemplateGenerator method isSingleValueComponent.

/**
 * @return false if the persist has no valuelist or at most one value in the valuelist, true otherwise
 */
public static boolean isSingleValueComponent(IFormElement persist) {
    Field field = (Field) persist;
    if (field.getValuelistID() > 0) {
        try {
            IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
            FlattenedSolution fs = new FlattenedSolution((SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(((Solution) persist.getRootObject()).getName(), IRepository.SOLUTIONS), new AbstractActiveSolutionHandler(as) {

                @Override
                public IRepository getRepository() {
                    return ApplicationServerRegistry.get().getLocalRepository();
                }
            });
            ValueList valuelist = fs.getValueList(field.getValuelistID());
            return isSingleValue(valuelist);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return true;
}
Also used : Field(com.servoy.j2db.persistence.Field) AbstractActiveSolutionHandler(com.servoy.j2db.AbstractActiveSolutionHandler) ValueList(com.servoy.j2db.persistence.ValueList) IApplicationServer(com.servoy.j2db.server.shared.IApplicationServer) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IRepository(com.servoy.j2db.persistence.IRepository) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException)

Example 7 with Field

use of com.servoy.j2db.persistence.Field 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 8 with Field

use of com.servoy.j2db.persistence.Field in project servoy-client by Servoy.

the class JSForm method newField.

/**
 * Creates a new JSField object on the form - including the dataprovider/JSVariable of the JSField object, the "x" and "y" position of the JSField object in pixels, as well as the width and height of the JSField object in pixels.
 *
 * @sample
 * var form = solutionModel.newForm('newForm1', myDatasource, null, true, 800, 600);
 * var variable = form.newVariable('myVar', JSVariable.TEXT);
 * variable.defaultValue = "'This is a default value (with triple quotes)!'";
 * var field = form.newField(variable, JSField.TEXT_FIELD, 100, 100, 200, 200);
 * forms['newForm1'].controller.show();
 *
 * @param dataprovider the specified dataprovider name/JSVariable of the JSField object
 *
 * @param type the display type of the JSField object (see the Solution Model -> JSField node for display types)
 *
 * @param x the horizontal "x" position of the JSField object in pixels
 *
 * @param y the vertical "y" position of the JSField object in pixels
 *
 * @param width the width of the JSField object in pixels
 *
 * @param height the height of the JSField object in pixels
 *
 * @return a new JSField object (of the specified display type)
 */
@JSFunction
public JSField newField(Object dataprovider, int type, int x, int y, int width, int height) {
    checkModification();
    try {
        Field field = getContainer().createNewField(new Point(x, y));
        field.setDisplayType(type);
        CSSPositionUtils.setSize(field, width, height);
        if (dataprovider instanceof String) {
            field.setDataProviderID((String) dataprovider);
        } else if (dataprovider instanceof JSVariable) {
            field.setDataProviderID(((JSVariable) dataprovider).getScriptVariable().getDataProviderID());
        }
        return JSField.createField(this, field, application, true);
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : Field(com.servoy.j2db.persistence.Field) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Point(java.awt.Point) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 9 with Field

use of com.servoy.j2db.persistence.Field in project servoy-client by Servoy.

the class JSForm method getFields.

/**
 * Returns all JSField objects of this form, including the ones without a name.
 *
 * @sample
 * var frm = solutionModel.getForm("myForm");
 * var fields = frm.getFields();
 * for (var f in fields)
 * {
 * 	var fname = fields[f].name;
 * 	if (fname != null)
 * 		application.output(fname);
 * }
 *
 * @param returnInheritedElements boolean true to also return the elements from the parent form
 * @return all JSField objects of this form
 */
@JSFunction
public JSField[] getFields(boolean returnInheritedElements) {
    List<JSField> fields = new ArrayList<JSField>();
    AbstractContainer form2use = returnInheritedElements ? getFlattenedContainer() : getContainer();
    Iterator<Field> iterator = form2use.getFields();
    while (iterator.hasNext()) {
        fields.add(JSField.createField(this, iterator.next(), application, false));
    }
    return fields.toArray(new JSField[fields.size()]);
}
Also used : Field(com.servoy.j2db.persistence.Field) AbstractContainer(com.servoy.j2db.persistence.AbstractContainer) ArrayList(java.util.ArrayList) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 10 with Field

use of com.servoy.j2db.persistence.Field in project servoy-client by Servoy.

the class JSPortal method getFields.

/**
 * Retrieves an array with all fields in a portal.
 *
 * @sampleas getField(String)
 *
 * @return An array with JSField instances corresponding to all fields in the portal.
 */
@JSFunction
public JSField[] getFields() {
    ArrayList<JSField> fields = new ArrayList<JSField>();
    Iterator<Field> iterator = getBaseComponent(false).getFields();
    while (iterator.hasNext()) {
        Field field = iterator.next();
        fields.add(JSField.createField(this, field, application, false));
    }
    return fields.toArray(new JSField[fields.size()]);
}
Also used : IBaseSMField(com.servoy.base.solutionmodel.IBaseSMField) Field(com.servoy.j2db.persistence.Field) ArrayList(java.util.ArrayList) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Aggregations

Field (com.servoy.j2db.persistence.Field)17 Point (java.awt.Point)8 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)7 IPersist (com.servoy.j2db.persistence.IPersist)6 Bean (com.servoy.j2db.persistence.Bean)5 Dimension (java.awt.Dimension)5 JSFunction (org.mozilla.javascript.annotations.JSFunction)5 Portal (com.servoy.j2db.persistence.Portal)4 HashMap (java.util.HashMap)4 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)3 AbstractBase (com.servoy.j2db.persistence.AbstractBase)3 Form (com.servoy.j2db.persistence.Form)3 IFormElement (com.servoy.j2db.persistence.IFormElement)3 ValueList (com.servoy.j2db.persistence.ValueList)3 IComponent (com.servoy.j2db.ui.IComponent)3 IBaseSMField (com.servoy.base.solutionmodel.IBaseSMField)2 IDisplay (com.servoy.j2db.dataprocessing.IDisplay)2 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)2 IDataProviderLookup (com.servoy.j2db.persistence.IDataProviderLookup)2 ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)2