Search in sources :

Example 1 with BasicFormController

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

the class DataAdapterList method valueChanged.

@Override
public void valueChanged(ModificationEvent e) {
    if (record != null && e != null && e.getName() != null) {
        for (Entry<IWebFormController, String> relatedFormEntry : getVisibleChildFormCopy().entrySet()) {
            IWebFormController relatedForm = relatedFormEntry.getKey();
            String relatedFormRelation = relatedFormEntry.getValue();
            boolean depends = false;
            Relation[] relations = getApplication().getFlattenedSolution().getRelationSequence(relatedFormRelation);
            for (int r = 0; !depends && relations != null && r < relations.length; r++) {
                try {
                    IDataProvider[] primaryDataProviders = relations[r].getPrimaryDataProviders(getApplication().getFlattenedSolution());
                    for (int p = 0; !depends && primaryDataProviders != null && p < primaryDataProviders.length; p++) {
                        depends = e.getName().equals(primaryDataProviders[p].getDataProviderID());
                    }
                } catch (RepositoryException ex) {
                    Debug.log(ex);
                }
            }
            if (depends) {
                relatedForm.loadRecords(record.getRelatedFoundSet(relatedFormRelation, ((BasicFormController) relatedForm).getDefaultSortColumns()));
            }
        }
    }
    if (!findMode && this.record != null && e.getName() != null && (e.getRecord() == null || e.getRecord() == this.record) && this.lookupDependency.containsKey(e.getName()) && !(this.record instanceof PrototypeState)) {
        if (this.record.startEditing()) {
            List<Pair<String, String>> lookupDepencies = this.lookupDependency.get(e.getName());
            for (Pair<String, String> dependency : lookupDepencies) {
                Object obj = this.record.getValue(dependency.getRight());
                this.record.setValue(dependency.getLeft(), obj);
            }
        }
    }
    // one of the relations could be changed make sure they are recreated.
    createRelationListeners();
    if (getForm().isFormVisible()) {
        pushChangedValues(e.getName(), true);
    }
}
Also used : RepositoryException(com.servoy.j2db.persistence.RepositoryException) IDataProvider(com.servoy.j2db.persistence.IDataProvider) Relation(com.servoy.j2db.persistence.Relation) JSONObject(org.json.JSONObject) BaseWebObject(org.sablo.BaseWebObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState) BasicFormController(com.servoy.j2db.BasicFormController) Pair(com.servoy.j2db.util.Pair)

Example 2 with BasicFormController

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

the class DataAdapterList method setRecord.

public void setRecord(IRecord record, boolean fireChangeEvent) {
    // because all types should just listen to the right stuff.
    if (shouldIgnoreRecordChange(this.record, record))
        return;
    if (settingRecord) {
        if (record != this.record) {
            throw new IllegalStateException("Record " + record + " is being set on DAL when record: " + this.record + " is being processed for form " + getForm());
        }
        return;
    }
    try {
        FireCollector fireCollector = FireCollector.getFireCollector();
        try {
            settingRecord = true;
            formController.getFormUI().setChanging(true);
            if (this.record != null) {
                this.record.removeModificationListener(this);
                this.record.getParentFoundSet().removeAggregateModificationListener(this);
            }
            this.record = (IRecordInternal) record;
            if (this.record != null) {
                pushChangedValues(null, fireChangeEvent);
                this.record.addModificationListener(this);
                this.record.getParentFoundSet().addAggregateModificationListener(this);
            }
            createRelationListeners();
            if (maxRecIndexPropertyValueListener != null)
                maxRecIndexPropertyValueListener.setRecord(this.record);
        } finally {
            formController.getFormUI().setChanging(false);
            settingRecord = false;
            fireCollector.done();
        }
        // we should use the "this.record" because fireCollector.done() could result in a setRecord with a different record.
        if (this.record != null) {
            for (Entry<IWebFormController, String> entry : getVisibleChildFormCopy().entrySet()) {
                String relation = entry.getValue();
                if (relation != null) {
                    IWebFormController form = entry.getKey();
                    form.loadRecords(this.record.getRelatedFoundSet(relation, ((BasicFormController) form).getDefaultSortColumns()));
                }
            }
        }
    } catch (RuntimeException re) {
        throw new RuntimeException("Error setting record " + record + " on form " + getForm() + " on DAL " + this, re);
    }
}
Also used : FireCollector(com.servoy.j2db.dataprocessing.FireCollector) BasicFormController(com.servoy.j2db.BasicFormController)

Example 3 with BasicFormController

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

the class JSApplication method js_showFormInDialog.

/**
 * Show the specified form in a dialog. (NOTE: x, y, width, height are initial bounds - applied only the fist time a dialog is shown)
 *
 * NOTE:
 * In the Smart Client, no code is executed after the function showFormInDialog <em>if the dialog is modal</em>.
 *
 * NOTE:
 * x, y, width and height coordinates are only applied the first time the specified dialog is shown.
 * Use APP_UI_PROPERTY.DIALOG_FULL_SCREEN for these values when the dialog should be full-screen.
 *
 * @deprecated As of release 6.0, dialogs/windows API has been rewritten (based in JSWindow objects)
 *
 * @sample
 * //Show the specified form in a modal dialog, on default initial location and size (x,y,w,h)
 * //application.showFormInDialog(forms.contacts);
 * //Note: No code is executed after the showFormInDialog until the dialog is closed if it is created as a modal dialog.
 * //Show the specified form in a non-modal dialog with a specified name, on default initial location and size (x,y,w,h)
 * //application.showFormInDialog(forms.contacts,'contactsdialog',false);
 * //Show the specified form in a modal dialog, at a specified initial location and size with custom title, not resizable but with text toolbar
 * application.showFormInDialog(forms.contacts,100,80,500,300,'my own dialog title',false,true,'mydialog',true);
 *
 * @param form The form to be shown in the dialog.
 *
 * @param x optional The "x" coordinate of the dialog.
 *
 * @param y optional The "y" coordinate of the dialog.
 *
 * @param width optional The width of the dialog.
 *
 * @param height optional The height of the dialog.
 *
 * @param dialogTitle optional The title of the dialog.
 *
 * @param resizable optional <em>true</em> if the dialog size should be modifiable; <em>false</em> if not.
 *
 * @param showTextToolbar optional <em>true</em> to add a text toolbar; <em>false</em> to not add a text toolbar.
 *
 * @param windowName optional The name of the window; defaults to "dialog" if nothing is specified. Window and dialog names share the same namespace.
 *
 * @param modal optional <em>true</em> if the dialog should be modal; <em>false</em> if not. Defaults to <em>true</em>.
 */
@Deprecated
public void js_showFormInDialog(Object[] args) throws ServoyException {
    if (args != null && args.length >= 1) {
        Object form = args[0];
        int x = -1;
        int y = -1;
        int w = 0;
        int h = 0;
        String title = null;
        boolean resizeble = true;
        boolean showTextToolbar = false;
        Boolean closeAll = Boolean.FALSE;
        boolean legacyBehaviour = false;
        boolean modal = true;
        String dialogName = null;
        // special short cut, args: 'form,name [, modal]'
        if (args.length >= 2 && args[1] instanceof String) {
            dialogName = (String) args[1];
            if (args.length >= 3 && args[2] instanceof Boolean)
                modal = ((Boolean) args[2]).booleanValue();
            else
                modal = true;
        } else {
            if (args.length >= 2 && args[1] instanceof Number)
                x = ((Number) args[1]).intValue();
            if (args.length >= 3 && args[2] instanceof Number)
                y = ((Number) args[2]).intValue();
            if (args.length >= 4 && args[3] instanceof Number)
                w = ((Number) args[3]).intValue();
            if (args.length >= 5 && args[4] instanceof Number)
                h = ((Number) args[4]).intValue();
            if (args.length >= 6 && args[5] instanceof String)
                title = args[5].toString();
            if (args.length >= 7 && args[6] instanceof Boolean)
                resizeble = ((Boolean) args[6]).booleanValue();
            if (args.length >= 8 && args[7] instanceof Boolean)
                showTextToolbar = ((Boolean) args[7]).booleanValue();
            if (args.length >= 9 && args[8] instanceof Boolean)
                closeAll = (Boolean) args[8];
            if (args.length >= 9 && args[8] instanceof String)
                dialogName = (String) args[8];
            else
                legacyBehaviour = true;
            if (args.length >= 10 && args[9] instanceof Boolean)
                modal = ((Boolean) args[9]).booleanValue();
            else if (dialogName != null)
                modal = true;
        }
        dialogName = replaceFailingCharacters(dialogName);
        String f = null;
        if (form instanceof BasicFormController) {
            f = ((BasicFormController) form).getName();
        } else if (form instanceof FormScope) {
            f = ((FormScope) form).getFormController().getName();
        } else if (form instanceof BasicFormController.JSForm) {
            f = ((BasicFormController.JSForm) form).getFormPanel().getName();
        } else if (form instanceof String) {
            f = (String) form;
        }
        if (f != null) {
            Form frm = application.getFlattenedSolution().getForm(f);
            IBasicFormManager fm = application.getFormManager();
            if (frm == null && fm.isPossibleForm(f))
                frm = fm.getPossibleForm(f);
            if (!application.getFlattenedSolution().formCanBeInstantiated(frm)) {
                // abstract form
                throw new ApplicationException(ServoyException.ABSTRACT_FORM);
            }
            Rectangle rect = new Rectangle(x, y, w, h);
            fm.showFormInDialog(f, rect, title, resizeble, showTextToolbar, closeAll.booleanValue() || !legacyBehaviour, modal, dialogName);
        }
    }
}
Also used : Form(com.servoy.j2db.persistence.Form) Rectangle(java.awt.Rectangle) ApplicationException(com.servoy.j2db.ApplicationException) IBasicFormManager(com.servoy.j2db.IBasicFormManager) ScriptableObject(org.mozilla.javascript.ScriptableObject) BasicFormController(com.servoy.j2db.BasicFormController)

Example 4 with BasicFormController

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

the class JSApplication method js_showFormInWindow.

/**
 * Show the specified form in a window. (NOTE: x, y, width, height are initial bounds - applied only the fist time a window is shown)
 *
 * NOTE:
 * Forms in windows cannot be modal. They are more independent then dialogs, even non-modal ones. For example in SC, a non-modal dialog will always
 * be shown on top of the parent window and it will not have a separate entry in the OS window manager (for example Windows taskbar).
 *
 * NOTE:
 * x, y, width and height coordinates are only applied the first time the specified window is shown.
 * Use APP_UI_PROPERTY.FULL_SCREEN for these values when the window should be full-screen.
 *
 * @deprecated As of release 6.0, dialogs/windows API has been rewritten (based in JSWindow objects)
 *
 * @sample
 * //Show the specified form in a window, on default initial location and size
 * //application.showFormInWindow(forms.contacts);
 * //Show the specified form in a window with a specified name, on default initial location and size
 * //application.showFormInWindow(forms.contacts,'contactsWindow');
 * //Show the specified form in a window, at a specified initial location and size with custom title, not resizable but with text toolbar
 * application.showFormInWindow(forms.contacts,100,80,500,300,'my own window title',false,true,'mywindow');
 *
 * @param form The form to be shown in the dialog.
 * @param x optional The "x" coordinate of the dialog.
 * @param y optional The "y" coordinate of the dialog.
 * @param width optional The width of the dialog.
 * @param height optional The height of the dialog.
 * @param dialogTitle optional The title of the dialog.
 * @param resizable optional <em>true</em> if the dialog size should be modifiable; <em>false</em> if not.
 * @param showTextToolbar optional <em>true</em> to add a text toolbar; <em>false</em> to not add a text toolbar.
 * @param windowName optional The name of the window; defaults to "dialog" if nothing is specified. Window and dialog names share the same namespace.
 */
@Deprecated
public void js_showFormInWindow(Object[] args) throws ServoyException {
    if (args != null && args.length >= 1) {
        Object form = args[0];
        int x = -1;
        int y = -1;
        int w = 0;
        int h = 0;
        String title = null;
        boolean resizeble = true;
        boolean showTextToolbar = false;
        String windowName = null;
        // special short cut, args: 'form,name'
        if (args.length >= 2 && args[1] instanceof String) {
            windowName = (String) args[1];
        } else {
            if (args.length >= 2 && args[1] instanceof Number)
                x = ((Number) args[1]).intValue();
            if (args.length >= 3 && args[2] instanceof Number)
                y = ((Number) args[2]).intValue();
            if (args.length >= 4 && args[3] instanceof Number)
                w = ((Number) args[3]).intValue();
            if (args.length >= 5 && args[4] instanceof Number)
                h = ((Number) args[4]).intValue();
            if (args.length >= 6 && args[5] instanceof String)
                title = args[5].toString();
            if (args.length >= 7 && args[6] instanceof Boolean)
                resizeble = ((Boolean) args[6]).booleanValue();
            if (args.length >= 8 && args[7] instanceof Boolean)
                showTextToolbar = ((Boolean) args[7]).booleanValue();
            if (args.length >= 9 && args[8] instanceof String)
                windowName = (String) args[8];
        }
        windowName = replaceFailingCharacters(windowName);
        String formName = null;
        if (form instanceof BasicFormController) {
            formName = ((BasicFormController) form).getName();
        } else if (form instanceof FormScope) {
            formName = ((FormScope) form).getFormController().getName();
        } else if (form instanceof BasicFormController.JSForm) {
            formName = ((FormController.JSForm) form).getFormPanel().getName();
        } else if (form instanceof String) {
            formName = (String) form;
        }
        if (formName != null) {
            Form frm = application.getFlattenedSolution().getForm(formName);
            IBasicFormManager fm = application.getFormManager();
            if (frm == null && fm.isPossibleForm(formName))
                frm = fm.getPossibleForm(formName);
            if (!application.getFlattenedSolution().formCanBeInstantiated(frm)) {
                // abstract form
                throw new ApplicationException(ServoyException.ABSTRACT_FORM);
            }
            Rectangle bounds = new Rectangle(x, y, w, h);
            fm.showFormInFrame(formName, bounds, title, resizeble, showTextToolbar, windowName);
        }
    }
}
Also used : Form(com.servoy.j2db.persistence.Form) Rectangle(java.awt.Rectangle) ApplicationException(com.servoy.j2db.ApplicationException) IBasicFormManager(com.servoy.j2db.IBasicFormManager) ScriptableObject(org.mozilla.javascript.ScriptableObject) BasicFormController(com.servoy.j2db.BasicFormController)

Example 5 with BasicFormController

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

the class JSUtils method js_stringReplaceTags.

/**
 * Returns the text with %%tags%% replaced, based on provided record or foundset or form.
 *
 * @sample
 * //Next line places a string in variable x, whereby the tag(%%TAG%%) is filled with the value of the database column 'company_name' of the selected record.
 * var x = utils.stringReplaceTags("The companyName of the selected record is %%company_name%% ", foundset)
 * //var otherExample = utils.stringReplaceTags("The amount of the related order line %%amount%% ", order_to_orderdetails);
 * //var recordExample = utils.stringReplaceTags("The amount of the related order line %%amount%% ", order_to_orderdetails.getRecord(i);
 * //Next line places a string in variable y, whereby the tag(%%TAG%%) is filled with the value of the form variable 'x' of the form named 'main'.
 * //var y = utils.stringReplaceTags("The value of form variable is %%x%% ", forms.main);
 * //The next sample shows the use of a javascript object
 * //var obj = new Object();//create a javascript object
 * //obj['x'] = 'test';//assign an named value
 * //var y = utils.stringReplaceTags("The value of object variable is %%x%% ", obj);//use the named value in a tag
 * @param text the text tags to work with
 * @param scriptable the javascript object or foundset,record,form to be used to fill in the tags
 * @return the text with replaced tags
 */
public String js_stringReplaceTags(String text, Object scriptable) {
    if (text != null) {
        ITagResolver tagResolver = null;
        Properties settings = null;
        if (scriptable instanceof FoundSet) {
            IRecordInternal record = ((FoundSet) scriptable).getRecord(((FoundSet) scriptable).getSelectedIndex());
            if (record != null) {
                settings = record.getParentFoundSet().getFoundSetManager().getApplication().getSettings();
                tagResolver = TagResolver.createResolver(record);
            }
        } else if (scriptable instanceof IRecordInternal) {
            IRecordInternal record = (IRecordInternal) scriptable;
            settings = record.getParentFoundSet().getFoundSetManager().getApplication().getSettings();
            tagResolver = TagResolver.createResolver(record);
        } else if (scriptable instanceof BasicFormController) {
            final BasicFormController fc = (BasicFormController) scriptable;
            IFoundSetInternal fs = fc.getFoundSet();
            final ITagResolver defaultTagResolver = (fs != null) ? TagResolver.createResolver(fs.getRecord(fs.getSelectedIndex())) : null;
            settings = fc.getApplication().getSettings();
            tagResolver = new ITagResolver() {

                public String getStringValue(String name) {
                    Object value = fc.getFormScope().get(name);
                    if (value == null || value == Scriptable.NOT_FOUND) {
                        value = defaultTagResolver != null ? defaultTagResolver.getStringValue(name) : null;
                    }
                    // $NON-NLS-1$
                    return value != null ? value.toString() : "";
                }
            };
        } else if (scriptable instanceof Scriptable) {
            Scriptable scriptObject = (Scriptable) scriptable;
            settings = Settings.getInstance();
            tagResolver = TagResolver.createResolver(scriptObject, application);
        }
        if (tagResolver != null && settings != null) {
            return Text.processTags(TagResolver.formatObject(text, application), tagResolver);
        }
        // $NON-NLS-1$
        return "";
    } else {
        // $NON-NLS-1$
        return "";
    }
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) ITagResolver(com.servoy.base.util.ITagResolver) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) IJSFoundSet(com.servoy.base.scripting.api.IJSFoundSet) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) Properties(java.util.Properties) Scriptable(org.mozilla.javascript.Scriptable) BasicFormController(com.servoy.j2db.BasicFormController)

Aggregations

BasicFormController (com.servoy.j2db.BasicFormController)7 ApplicationException (com.servoy.j2db.ApplicationException)3 IBasicFormManager (com.servoy.j2db.IBasicFormManager)3 Form (com.servoy.j2db.persistence.Form)3 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)2 Rectangle (java.awt.Rectangle)2 JSONObject (org.json.JSONObject)2 ScriptableObject (org.mozilla.javascript.ScriptableObject)2 BaseWebObject (org.sablo.BaseWebObject)2 IJSFoundSet (com.servoy.base.scripting.api.IJSFoundSet)1 ITagResolver (com.servoy.base.util.ITagResolver)1 FireCollector (com.servoy.j2db.dataprocessing.FireCollector)1 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)1 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)1 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)1 PrototypeState (com.servoy.j2db.dataprocessing.PrototypeState)1 IDataProvider (com.servoy.j2db.persistence.IDataProvider)1 Relation (com.servoy.j2db.persistence.Relation)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 JSForm (com.servoy.j2db.scripting.solutionmodel.JSForm)1