Search in sources :

Example 6 with ServoyClientSupport

use of com.servoy.base.scripting.annotations.ServoyClientSupport in project servoy-client by Servoy.

the class JSApplication method js_getPrinters.

/**
 * Get all the printer names in an array.
 *
 * @sample var printersArray = application.getPrinters();
 *
 * @return All printer names
 */
@ServoyClientSupport(ng = false, wc = true, sc = true)
public String[] js_getPrinters() {
    DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE;
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    PrintService[] printServices = PrintServiceLookup.lookupPrintServices(flavor, pras);
    if (printServices == null)
        return new String[0];
    String[] retval = new String[printServices.length];
    for (int i = 0; i < printServices.length; i++) {
        retval[i] = printServices[i].getName();
    }
    return retval;
}
Also used : DocFlavor(javax.print.DocFlavor) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) PrintService(javax.print.PrintService) ServoyClientSupport(com.servoy.base.scripting.annotations.ServoyClientSupport)

Example 7 with ServoyClientSupport

use of com.servoy.base.scripting.annotations.ServoyClientSupport in project servoy-client by Servoy.

the class JSForm method removeField.

/**
 * Removes a JSField that has the given name. Returns true if removal was successful, false otherwise.
 *
 * @sample
 * var form = solutionModel.newForm('newFormX',myDatasource,null,true,800,600);
 * var jsfield = form.newField(scopes.globals.myGlobalVariable,JSField.TEXT_FIELD,100,300,200,50);
 * jsfield.name = 'jsf';
 * var jsmethod = form.newMethod("function removeMe(event) { var form = solutionModel.getForm('newFormX');\n if (form.removeComponent('jsf') == true) application.output('Field has been removed ok'); else application.output('Field could not be deleted'); forms['newFormX'].controller.recreateUI();}");
 * var removerButton = form.newButton('Click here to remove the field',450,500,250,50,jsmethod);
 * removerButton.name = 'remover';
 * forms['newFormX'].controller.show();
 *
 * @param name the specified name of the JSField to remove
 *
 * @return true is the JSField has been successfully removed; false otherwise
 */
@ServoyClientSupport(mc = true, ng = true, wc = true, sc = true)
@JSFunction
public boolean removeField(String name) {
    if (name == null)
        return false;
    checkModification();
    Iterator<Field> fields = getContainer().getFields();
    while (fields.hasNext()) {
        Field field = fields.next();
        if (name.equals(field.getName())) {
            getContainer().removeChild(field);
            return true;
        }
    }
    return false;
}
Also used : Field(com.servoy.j2db.persistence.Field) JSFunction(org.mozilla.javascript.annotations.JSFunction) ServoyClientSupport(com.servoy.base.scripting.annotations.ServoyClientSupport)

Example 8 with ServoyClientSupport

use of com.servoy.base.scripting.annotations.ServoyClientSupport in project servoy-client by Servoy.

the class JSForm method js_setOnDuplicateRecordCmdMethod.

/**
 * @deprecated  As of release 4.1, replaced by setOnDuplicateRecordCmd(JSMethod).
 */
@Deprecated
@ServoyClientSupport(ng = false, wc = true, sc = true)
public void js_setOnDuplicateRecordCmdMethod(Object functionOrInteger) {
    checkModification();
    if (functionOrInteger instanceof Function) {
        Function function = (Function) functionOrInteger;
        ScriptMethod scriptMethod = getScriptMethod(function, application.getFlattenedSolution());
        if (scriptMethod != null) {
            getForm().setOnDuplicateRecordCmdMethodID(scriptMethod.getID());
        } else {
            getForm().setOnDuplicateRecordCmdMethodID(0);
        }
    } else if (functionOrInteger instanceof Number) {
        getForm().setOnDuplicateRecordCmdMethodID(((Number) functionOrInteger).intValue());
    }
}
Also used : JSFunction(org.mozilla.javascript.annotations.JSFunction) Function(org.mozilla.javascript.Function) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) ServoyClientSupport(com.servoy.base.scripting.annotations.ServoyClientSupport)

Example 9 with ServoyClientSupport

use of com.servoy.base.scripting.annotations.ServoyClientSupport in project servoy-client by Servoy.

the class JSForm method js_setOnPrintPreviewCmdMethod.

/**
 * @deprecated As of release 4.1, replaced by setOnPrintPreviewCmd(JSMethod).
 */
@Deprecated
@ServoyClientSupport(ng = false, wc = true, sc = true)
public void js_setOnPrintPreviewCmdMethod(Object functionOrInteger) {
    checkModification();
    if (functionOrInteger instanceof Function) {
        Function function = (Function) functionOrInteger;
        ScriptMethod scriptMethod = getScriptMethod(function, application.getFlattenedSolution());
        if (scriptMethod != null) {
            getForm().setOnPrintPreviewCmdMethodID(scriptMethod.getID());
        } else {
            getForm().setOnPrintPreviewCmdMethodID(0);
        }
    } else if (functionOrInteger instanceof Number) {
        getForm().setOnPrintPreviewCmdMethodID(((Number) functionOrInteger).intValue());
    }
}
Also used : JSFunction(org.mozilla.javascript.annotations.JSFunction) Function(org.mozilla.javascript.Function) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) ServoyClientSupport(com.servoy.base.scripting.annotations.ServoyClientSupport)

Example 10 with ServoyClientSupport

use of com.servoy.base.scripting.annotations.ServoyClientSupport in project servoy-client by Servoy.

the class JSBaseContainer method newWebComponent.

/**
 * Creates a new JSWebComponent (spec based component) object on the RESPONSIVE form.
 *
 * @sample
 * var form = solutionModel.newForm('newForm1', 'db:/server1/table1', null, true, 800, 600);
 * var container = myForm.getLayoutContainer("row1")
 * var bean = container.newWebComponent('bean','mypackage-testcomponent',1);
 *
 * @param name the specified name of the JSWebComponent object
 * @param type the webcomponent name as it appears in the spec
 * @param position the position of JSWebComponent object in its parent container
 *
 * @return a JSWebComponent object
 */
@ServoyClientSupport(mc = false, ng = true, wc = false, sc = false)
@JSFunction
public JSWebComponent newWebComponent(String name, String type, int position) {
    checkModification();
    try {
        AbstractContainer container = getContainer();
        Form form = (Form) container.getAncestor(IRepository.FORMS);
        if (form.isResponsiveLayout()) {
            if (name == null) {
                String componentName = type;
                int index = componentName.indexOf("-");
                if (index != -1) {
                    componentName = componentName.substring(index + 1);
                }
                // $NON-NLS-1$//$NON-NLS-2$
                componentName = componentName.replaceAll("-", "_");
                // $NON-NLS-1$
                name = componentName + "_" + id.incrementAndGet();
                IJSParent<?> parent = this;
                while (!(parent instanceof JSForm)) {
                    parent = parent.getJSParent();
                }
                if (parent instanceof JSForm) {
                    while (findComponent((JSForm) parent, name) != null) {
                        name = componentName + "_" + id.incrementAndGet();
                    }
                }
            }
            WebComponent webComponent = container.createNewWebComponent(IdentDocumentValidator.checkName(name), type);
            webComponent.setLocation(new Point(position, position));
            return createWebComponent(this, webComponent, application, true);
        } else {
            throw new RuntimeException("Form " + form.getName() + " is not responsive. Cannot create component without specifying the location and size.");
        }
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : WebComponent(com.servoy.j2db.persistence.WebComponent) AbstractContainer(com.servoy.j2db.persistence.AbstractContainer) Form(com.servoy.j2db.persistence.Form) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Point(java.awt.Point) Point(java.awt.Point) JSFunction(org.mozilla.javascript.annotations.JSFunction) ServoyClientSupport(com.servoy.base.scripting.annotations.ServoyClientSupport)

Aggregations

ServoyClientSupport (com.servoy.base.scripting.annotations.ServoyClientSupport)12 JSFunction (org.mozilla.javascript.annotations.JSFunction)11 AbstractContainer (com.servoy.j2db.persistence.AbstractContainer)3 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)3 WebComponent (com.servoy.j2db.persistence.WebComponent)3 Function (org.mozilla.javascript.Function)3 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)2 ArrayList (java.util.ArrayList)2 Bean (com.servoy.j2db.persistence.Bean)1 Field (com.servoy.j2db.persistence.Field)1 Form (com.servoy.j2db.persistence.Form)1 LayoutContainer (com.servoy.j2db.persistence.LayoutContainer)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 Point (java.awt.Point)1 DocFlavor (javax.print.DocFlavor)1 PrintService (javax.print.PrintService)1 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)1 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)1