Search in sources :

Example 36 with FormController

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

the class SwingFormManager method showPreview.

@Override
public void showPreview(final FormController afp, final IFoundSetInternal foundset, int zoomFactor, final PrinterJob printJob) {
    removePreview();
    final FormController fc = currentContainer.getController();
    if (fc != null) {
        List invokeLaterRunnables = new ArrayList();
        boolean ok = fc.notifyVisible(false, invokeLaterRunnables);
        Utils.invokeLater(getApplication(), invokeLaterRunnables);
        if (!ok) {
            // cannot hide...so skip preview
            return;
        }
    }
    showFormInMainPanel(afp.getName(), currentContainer, null, true, null);
    getApplication().getModeManager().setMode(IModeManager.PREVIEW_MODE);
    boolean isNewUser = checkAndUpdateFormUser(afp, currentContainer);
    if (isNewUser) {
        IFormUIInternal ui = afp.getFormUI();
        currentContainer.add(ui, afp.getName());
    }
    try {
        final PrintPreview printPreview = new PrintPreview((ISmartClientApplication) getApplication(), afp, foundset, zoomFactor, printJob);
        Runnable r = new Runnable() {

            public void run() {
                printPreviews.put(currentContainer, new PrintPreviewHolder(printPreview, fc));
                // $NON-NLS-1$
                currentContainer.add(printPreview, "@preview");
                // $NON-NLS-1$
                currentContainer.show("@preview");
                // handle navigator propertly
                List invokeLaterRunnables = new ArrayList();
                afp.showNavigator(invokeLaterRunnables);
                Utils.invokeLater(getApplication(), invokeLaterRunnables);
                printPreview.showPages();
            }
        };
        getApplication().invokeLater(r);
    } catch (Exception ex) {
        // $NON-NLS-1$
        getApplication().reportError(Messages.getString("servoy.formManager.error.PrintPreview"), ex);
    }
}
Also used : FormController(com.servoy.j2db.FormController) BasicFormController(com.servoy.j2db.BasicFormController) PrintPreview(com.servoy.j2db.printing.PrintPreview) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IFormUIInternal(com.servoy.j2db.IFormUIInternal)

Example 37 with FormController

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

the class SwingRuntimeWindow method doOldShowInWindow.

private void doOldShowInWindow(String formName) {
    FormManager fm = ((FormManager) getApplication().getFormManager());
    boolean toFront = createFrameIfNeeded(fm);
    FormFrame frame = (FormFrame) wrappedWindow;
    if (frame.isVisible()) {
        frame.storeBounds();
    }
    IMainContainer container = frame.getMainContainer();
    final FormController fp = fm.showFormInMainPanel(formName, container, title, true, windowName);
    finalizeShowWindow(fp, formName, container, true, false, toFront);
}
Also used : FormController(com.servoy.j2db.FormController) FormManager(com.servoy.j2db.FormManager) IMainContainer(com.servoy.j2db.IMainContainer)

Example 38 with FormController

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

the class SortModel method setValue.

void setValue(IApplication app, String notused) {
    application = app;
    try {
        FormManager fm = (FormManager) application.getFormManager();
        FormController fc = fm.getCurrentMainShowingFormController();
        if (fc != null) {
            Form form = fc.getForm();
            ITable t = application.getFoundSetManager().getTable(form.getDataSource());
            if (t != null) {
                List<SortColumn> list = application.getFoundSetManager().getSortColumns(t, form.getInitialSort());
                init(app, t, list);
            }
        }
    } catch (RepositoryException e) {
        Debug.error(e);
    }
}
Also used : FormController(com.servoy.j2db.FormController) FormManager(com.servoy.j2db.FormManager) Form(com.servoy.j2db.persistence.Form) ITable(com.servoy.j2db.persistence.ITable) RepositoryException(com.servoy.j2db.persistence.RepositoryException) SortColumn(com.servoy.j2db.dataprocessing.SortColumn)

Example 39 with FormController

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

the class CmdPrevRecord method doIt.

@Override
public UndoableEdit doIt(java.util.EventObject ae) {
    IFormManager fm = application.getFormManager();
    final FormController fp = (FormController) fm.getCurrentForm();
    fp.selectPrevRecord();
    return null;
}
Also used : FormController(com.servoy.j2db.FormController) IFormManager(com.servoy.j2db.IFormManager)

Example 40 with FormController

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

the class ServoyWrapFactory method wrap.

/**
 * @see org.mozilla.javascript.WrapFactory#wrap(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable, java.lang.Object, java.lang.Class)
 */
@Override
public Object wrap(Context cx, Scriptable scope, Object obj, Class staticType) {
    if (application.getSolution() == null) {
        throw new ExitScriptException("killing current script, client/solution already terminated");
    }
    if (obj == null || obj == Undefined.instance || obj instanceof Scriptable || obj instanceof String || obj instanceof CharSequence || obj instanceof Number || obj instanceof Boolean) {
        return obj;
    }
    if (obj instanceof Date) {
        return cx.newObject(scope, "Date", new Object[] { new Double(NativeDate.convertToUTCMillisFromJava(((Date) obj).getTime())) });
    }
    if (obj instanceof DbIdentValue || obj instanceof UUID) {
        return new NativeJavaObject(scope, obj, ScriptObjectRegistry.getJavaMembers(obj.getClass(), null));
    }
    if (cx != null) {
        if (obj instanceof JSConvertedMap<?, ?>) {
            Scriptable newObject = null;
            JSConvertedMap<?, ?> map = (JSConvertedMap<?, ?>) obj;
            if (map.getConstructorName() != null) {
                newObject = cx.newObject(scope, map.getConstructorName());
            } else {
                newObject = cx.newObject(scope);
            }
            Iterator<?> iterator = map.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<?, ?> next = (Entry<?, ?>) iterator.next();
                Object key = next.getKey();
                Object value = next.getValue();
                if (value != null) {
                    value = wrap(cx, newObject, value, value.getClass());
                }
                if (key instanceof Integer) {
                    newObject.put(((Integer) key).intValue(), newObject, value);
                } else if (key instanceof String) {
                    newObject.put((String) key, newObject, value);
                } else {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    Debug.error("Try to create a JSConvertedMap->NativeObject with a key that isnt a string or integer:" + key + " for value: " + value);
                }
            }
            return newObject;
        }
        if (obj.getClass() == JSONObject.class) {
            JSONObject json = (JSONObject) obj;
            Scriptable newObject = cx.newObject(scope);
            Iterator<String> iterator = json.keys();
            while (iterator.hasNext()) {
                String key = iterator.next();
                Object value = null;
                try {
                    value = ServoyJSONObject.jsonNullToNull(json.get(key));
                } catch (JSONException e) {
                    Debug.error(e);
                }
                if (value != null) {
                    value = wrap(cx, newObject, value, value.getClass());
                }
                newObject.put(key, newObject, value);
            }
            return newObject;
        }
        if (obj.getClass() == JSONArray.class) {
            JSONArray array = (JSONArray) obj;
            Scriptable newObject = cx.newObject(scope, "Array");
            for (int i = 0; i < array.length(); i++) {
                Object value = null;
                try {
                    value = array.get(i);
                } catch (JSONException e) {
                    Debug.error(e);
                }
                if (value != null) {
                    value = wrap(cx, newObject, value, value.getClass());
                }
                newObject.put(i, newObject, value);
            }
            return newObject;
        }
    }
    if (obj instanceof IDataSet) {
        return new JSDataSet(application, (IDataSet) obj);
    }
    if (obj instanceof FormController) {
        throw new IllegalArgumentException(// $NON-NLS-1$
        "Bad practice: FormController cant be wrapped to javascript (for example not usable as argument in Scheduler plugin)");
    }
    // if it is a none primitive array
    if (obj.getClass().isArray() && !obj.getClass().getComponentType().isPrimitive()) {
        // then convert the array to a NativeArray, first convert all the elements of the array itself.
        Object[] source = (Object[]) obj;
        Object[] array = new Object[source.length];
        for (int i = 0; i < source.length; i++) {
            Object src = source[i];
            array[i] = wrap(cx, scope, src, src != null ? src.getClass() : null);
        }
        NativeArray result = obj.getClass().getComponentType() != Object.class ? new ServoyNativeArray(array, obj.getClass().getComponentType()) : new NativeArray(array);
        ScriptRuntime.setBuiltinProtoAndParent(result, scope, TopLevel.Builtins.Array);
        return result;
    }
    return super.wrap(cx, scope, obj, staticType);
}
Also used : NativeArray(org.mozilla.javascript.NativeArray) JSDataSet(com.servoy.j2db.dataprocessing.JSDataSet) Entry(java.util.Map.Entry) DbIdentValue(com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue) UUID(com.servoy.j2db.util.UUID) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) FormController(com.servoy.j2db.FormController) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Scriptable(org.mozilla.javascript.Scriptable) ExitScriptException(com.servoy.j2db.ExitScriptException) Date(java.util.Date) NativeDate(org.mozilla.javascript.NativeDate) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) JSONObject(org.json.JSONObject) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) Map(java.util.Map)

Aggregations

FormController (com.servoy.j2db.FormController)70 FormManager (com.servoy.j2db.FormManager)15 Form (com.servoy.j2db.persistence.Form)13 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)12 RepositoryException (com.servoy.j2db.persistence.RepositoryException)10 Point (java.awt.Point)10 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)9 ArrayList (java.util.ArrayList)9 IFormController (com.servoy.j2db.IFormController)8 BasicFormController (com.servoy.j2db.BasicFormController)7 IForm (com.servoy.j2db.IForm)7 WebForm (com.servoy.j2db.server.headlessclient.WebForm)7 FlattenedSolution (com.servoy.j2db.FlattenedSolution)6 IFormUIInternal (com.servoy.j2db.IFormUIInternal)5 IDataProvider (com.servoy.j2db.persistence.IDataProvider)5 List (java.util.List)5 ApplicationException (com.servoy.j2db.ApplicationException)4 IMainContainer (com.servoy.j2db.IMainContainer)4 PrototypeState (com.servoy.j2db.dataprocessing.PrototypeState)4 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)4