Search in sources :

Example 6 with GraphicalComponent

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

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

the class JSForm method getButtons.

/**
 * Returns all JSButtons of this form, including the ones without a name.
 *
 * @sample
 * var buttons = myForm.getButtons();
 * for (var b in buttons)
 * {
 * 	if (buttons[b].name != null)
 * 		application.output(buttons[b].name);
 * 	else
 * 		application.output(buttons[b].text + " has no name ");
 * }
 *
 * @param returnInheritedElements boolean true to also return the elements from parent form
 * @return the list of all JSButtons on this forms
 */
@JSFunction
public JSButton[] getButtons(boolean returnInheritedElements) {
    List<JSButton> buttons = new ArrayList<JSButton>();
    AbstractContainer form2use = returnInheritedElements ? getFlattenedContainer() : getContainer();
    Iterator<GraphicalComponent> graphicalComponents = form2use.getGraphicalComponents();
    while (graphicalComponents.hasNext()) {
        GraphicalComponent button = graphicalComponents.next();
        if (ComponentFactory.isButton(button)) {
            buttons.add(new JSButton(this, button, application, false));
        }
    }
    return buttons.toArray(new JSButton[buttons.size()]);
}
Also used : AbstractContainer(com.servoy.j2db.persistence.AbstractContainer) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ArrayList(java.util.ArrayList) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 8 with GraphicalComponent

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

the class JSForm method getLabels.

/**
 * Returns all JSLabels of this form (optionally including it super forms labels), including the ones without a name.
 *
 * @sample
 * var frm = solutionModel.getForm("myForm");
 * var labels = frm.getLabels();
 * for (var i in labels)
 * {
 * 	var lname = labels[i].name;
 * 	if (lname != null)
 * 		application.output(lname);
 * }
 *
 * @param returnInheritedElements boolean true to also return the elements from parent form
 * @return all JSLabels on this form
 */
@JSFunction
public JSLabel[] getLabels(boolean returnInheritedElements) {
    List<JSLabel> labels = new ArrayList<JSLabel>();
    AbstractContainer form2use = returnInheritedElements ? getFlattenedContainer() : getContainer();
    Iterator<GraphicalComponent> graphicalComponents = form2use.getGraphicalComponents();
    while (graphicalComponents.hasNext()) {
        GraphicalComponent gc = graphicalComponents.next();
        if (!ComponentFactory.isButton(gc)) {
            labels.add(new JSLabel(this, gc, application, false));
        }
    }
    return labels.toArray(new JSLabel[labels.size()]);
}
Also used : AbstractContainer(com.servoy.j2db.persistence.AbstractContainer) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ArrayList(java.util.ArrayList) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 9 with GraphicalComponent

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

the class JSForm method removeButton.

/**
 * Removes a JSButton that has the specified name. Returns true if removal was successful, false otherwise.
 *
 * @sample
 * var form = solutionModel.newForm('newFormX',myDatasource,null,true,800,600);
 * var b1 = form.newButton('This is button1',100,100,200,50,null);
 * b1.name = 'b1';
 * var jsmethod = form.newMethod("function removeMe(event) { var form = solutionModel.getForm('newFormX'); if (form.removeButton('b1') == true) application.output('Button has been removed ok'); else application.output('Button could not be deleted'); forms['newFormX'].controller.recreateUI();}");
 * var b2 = form.newButton('Click here to remove button1',100,230,200,50,jsmethod);
 * b2.name = 'b2';
 * forms['newFormX'].controller.show();
 *
 * @param name the specified name of the JSButton to be removed
 *
 * @return true if the JSButton has been removed; false otherwise
 */
@ServoyClientSupport(mc = true, ng = true, wc = true, sc = true)
@JSFunction
public boolean removeButton(String name) {
    if (name == null)
        return false;
    checkModification();
    Iterator<GraphicalComponent> graphicalComponents = getContainer().getGraphicalComponents();
    while (graphicalComponents.hasNext()) {
        GraphicalComponent button = graphicalComponents.next();
        if (name.equals(button.getName()) && ComponentFactory.isButton(button)) {
            getContainer().removeChild(button);
            return true;
        }
    }
    return false;
}
Also used : GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) JSFunction(org.mozilla.javascript.annotations.JSFunction) ServoyClientSupport(com.servoy.base.scripting.annotations.ServoyClientSupport)

Example 10 with GraphicalComponent

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

the class JSForm method removeLabel.

/**
 * Removes a JSLabel that has the given name. Returns true if removal successful, false otherwise
 *
 * @sample
 * var form = solutionModel.newForm('newFormX',myDatasource,null,true,1000,750);
 * var jslabel = form.newLabel('JSLabel to delete',100,200,200,50,null);
 * jslabel.name = 'jsl';
 * jslabel.transparent = false;
 * jslabel.background = 'green';
 * var jsmethod = form.newMethod("function removeMe(event) { var form = solutionModel.getForm('newFormX'); if (form.removeComponent('jsl') == true) application.output('Label has been removed'); else application.output('Label could not be deleted'); forms['newFormX'].controller.recreateUI();}");
 * var removerButton = form.newButton('Click here to remove the green label',450,500,250,50,jsmethod);
 * removerButton.name = 'remover';
 * forms['newFormX'].controller.show();
 *
 * @param name the specified name of the JSLabel to be removed
 *
 * @return true if the JSLabel with the given name has successfully been removed; false otherwise
 */
@ServoyClientSupport(mc = true, ng = true, wc = true, sc = true)
@JSFunction
public boolean removeLabel(String name) {
    if (name == null)
        return false;
    checkModification();
    Iterator<GraphicalComponent> graphicalComponents = getContainer().getGraphicalComponents();
    while (graphicalComponents.hasNext()) {
        GraphicalComponent label = graphicalComponents.next();
        if (name.equals(label.getName()) && !ComponentFactory.isButton(label)) {
            getContainer().removeChild(label);
            return true;
        }
    }
    return false;
}
Also used : GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) JSFunction(org.mozilla.javascript.annotations.JSFunction) ServoyClientSupport(com.servoy.base.scripting.annotations.ServoyClientSupport)

Aggregations

GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)27 Point (java.awt.Point)14 IPersist (com.servoy.j2db.persistence.IPersist)10 JSFunction (org.mozilla.javascript.annotations.JSFunction)10 Field (com.servoy.j2db.persistence.Field)7 IFormElement (com.servoy.j2db.persistence.IFormElement)6 Part (com.servoy.j2db.persistence.Part)6 RepositoryException (com.servoy.j2db.persistence.RepositoryException)6 Dimension (java.awt.Dimension)6 ArrayList (java.util.ArrayList)6 Bean (com.servoy.j2db.persistence.Bean)5 Form (com.servoy.j2db.persistence.Form)4 ISupportName (com.servoy.j2db.persistence.ISupportName)4 Portal (com.servoy.j2db.persistence.Portal)4 HashMap (java.util.HashMap)4 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)3 BaseComponent (com.servoy.j2db.persistence.BaseComponent)3 IComponent (com.servoy.j2db.ui.IComponent)3 ServoyClientSupport (com.servoy.base.scripting.annotations.ServoyClientSupport)2 IDisplay (com.servoy.j2db.dataprocessing.IDisplay)2