Search in sources :

Example 11 with GraphicalComponent

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

the class JSHeader method removeComponent.

private boolean removeComponent(MobileProperty<Boolean> property) {
    JSForm form = getJSParent();
    form.checkModification();
    Iterator<GraphicalComponent> graphicalComponents = form.getSupportChild().getGraphicalComponents();
    while (graphicalComponents.hasNext()) {
        GraphicalComponent button = graphicalComponents.next();
        if (Boolean.TRUE.equals(button.getCustomMobileProperty(property.propertyName))) {
            form.getSupportChild().removeChild(button);
            return true;
        }
    }
    return false;
}
Also used : GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent)

Example 12 with GraphicalComponent

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

the class JSPortal method newButton.

/**
 * Creates a new button on the portal with the given text, place, size and JSMethod as the onClick action.
 *
 * @sample
 * var clickMethod = form.newMethod('function clickMe() { application.output("I was clicked!"); }');
 * var childrenPortal = form.newPortal('pp', 'parent_to_child', 10, 10, 620, 460);
 * childrenPortal.newButton('Click me!', 400, 100, 20, clickMethod);
 *
 * @param text The text to be displayed on the button.
 *
 * @param x The x coordinate of the button. If the portal does not have the "multiLine" property set, then the x coordinates are used only for determining the order of the columns in the grid. If the portal has the "multiLine" property set, then the components are actually displayed at the specified coordinates.
 *
 * @param width The width of the button.
 *
 * @param height The height of the button. In a portal the height of all components is set to the height of the first component, unless the "multiLine" property is set.
 *
 * @param action The JSMethod object that should be executed when the button is clicked.
 *
 * @return A JSButton instance representing the newly created button.
 */
@JSFunction
public JSButton newButton(String text, int x, int width, int height, Object action) {
    try {
        GraphicalComponent gc = getBaseComponent(true).createNewGraphicalComponent(new Point(getX() + x, getY()));
        gc.setSize(new Dimension(width, height));
        gc.setText(text);
        if (action instanceof JSMethod) {
            JSButton button = new JSButton(this, gc, application, true);
            button.setOnAction((JSMethod) action);
            return button;
        } else {
            int id = JSForm.getMethodId(action, gc, application);
            gc.setOnActionMethodID(id);
            return new JSButton(this, gc, application, true);
        }
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Point(java.awt.Point) Dimension(java.awt.Dimension) Point(java.awt.Point) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 13 with GraphicalComponent

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

the class JSPortal method getButtons.

/**
 * Retrieves an array with all buttons in the portal.
 *
 * @sampleas getButton(String)
 *
 * @return An array with all buttons in the portal.
 */
@JSFunction
public JSButton[] getButtons() {
    ArrayList<JSButton> buttons = new ArrayList<JSButton>();
    Iterator<GraphicalComponent> graphicalComponents = getBaseComponent(false).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 : GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ArrayList(java.util.ArrayList) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 14 with GraphicalComponent

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

the class JSPortal method newLabel.

/**
 * Creates a new label on the form, with the given text, place, size and an JSMethod as the onClick action.
 *
 * @sample
 * var clickMethod = form.newMethod('function clickMe() { application.output("I was clicked!"); }');
 * var childrenPortal = form.newPortal('pp', 'parent_to_my_table', 10, 10, 1180, 780);
 * var calLabel = childrenPortal.newLabel('Date', 120, 60, 20);
 * // This will result in a button being actually created, because we specify an action.
 * var textLabel = childrenPortal.newLabel('Text', 180, 60, 20, clickMethod);
 *
 * @param text The text that will be displayed in the label.
 *
 * @param x The x coordinate of the label. If the portal does not have the "multiLine" property set, then the x coordinates are used only for determining the order of the columns in the grid. If the portal has the "multiLine" property set, then the components are actually displayed at the specified coordinates.
 *
 * @param width The width of the label.
 *
 * @param height The height of the label. In a portal the height of all components is set to the height of the first component, unless the "multiLine" property is set.
 *
 * @param action The JSMethod object that should be executed when the label is clicked.
 *
 * @return A JSLabel instance that represents the newly created label.
 */
@JSFunction
public JSLabel newLabel(String text, int x, int width, int height, Object action) {
    try {
        GraphicalComponent gc = getBaseComponent(true).createNewGraphicalComponent(new Point(getX() + x, getY()));
        gc.setSize(new Dimension(width, height));
        gc.setText(text);
        if (action instanceof JSMethod) {
            JSLabel label = new JSLabel(this, gc, application, true);
            label.setOnAction((JSMethod) action);
            return label;
        } else {
            int id = JSForm.getMethodId(action, gc, application);
            if (id != -1)
                gc.setOnActionMethodID(id);
            return new JSLabel(this, gc, application, true);
        }
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Point(java.awt.Point) Dimension(java.awt.Dimension) Point(java.awt.Point) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 15 with GraphicalComponent

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

the class JSPortal method getLabels.

/**
 * Retrieves all labels from the portal.
 *
 * @sampleas getLabel(String)
 *
 * @return An array of JSLabel instances corresponding to all labels in the portal.
 */
@JSFunction
public JSLabel[] getLabels() {
    ArrayList<JSLabel> labels = new ArrayList<JSLabel>();
    Iterator<GraphicalComponent> graphicalComponents = getBaseComponent(false).getGraphicalComponents();
    while (graphicalComponents.hasNext()) {
        GraphicalComponent label = graphicalComponents.next();
        if (!ComponentFactory.isButton(label)) {
            labels.add(new JSLabel(this, label, application, false));
        }
    }
    return labels.toArray(new JSLabel[labels.size()]);
}
Also used : GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ArrayList(java.util.ArrayList) JSFunction(org.mozilla.javascript.annotations.JSFunction)

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