Search in sources :

Example 6 with JSEvent

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

the class BaseEventExecutor method fireEventCommand.

public Object fireEventCommand(EventType type, String cmd, Object[] args, Object[] persistArgs, boolean saveData, Object display, boolean focusEvent, int modifiers, String formName, boolean executeWhenFieldValidationFailed, Point mouseLocation, Point absoluteMouseLocation) {
    if (actionListener == null)
        return null;
    FormController fc = actionListener.getFormController();
    // won't be able to execute - form is already destroyed
    if (fc == null)
        return null;
    // also fire when cmd is null (may trigger field validation)
    if (modifiers != MODIFIERS_UNSPECIFIED)
        actionListener.setLastKeyModifiers(modifiers);
    String name = getElementName(display);
    String fName = formName;
    if (fName == null)
        fName = getFormName(display);
    if (fName == null)
        fName = this.formName;
    if (fName == null)
        fName = getFormName();
    // TODO can't this be the only one used and formName/display args as well as formName member removed?
    if (fName == null)
        fName = fc.getName();
    if (this.formName == null && fName != null)
        setFormName(fName);
    // TODO can't an abstract Object getComponent() be created for this and display be removed as arg ? all subclasses have such a reference
    Object source = getSource(display);
    JSEvent event = new JSEvent();
    event.setType(type);
    event.setSource(source);
    event.setFormName(fName);
    event.setElementName(name);
    event.setModifiers(modifiers == MODIFIERS_UNSPECIFIED ? 0 : modifiers);
    if (mouseLocation != null)
        event.setLocation(mouseLocation);
    if (absoluteMouseLocation != null)
        event.setAbsoluteLocation(absoluteMouseLocation);
    return actionListener.executeFunction(cmd, Utils.arrayMerge(Utils.arrayJoin(args, new Object[] { event }), persistArgs), saveData, source, focusEvent, null, executeWhenFieldValidationFailed);
}
Also used : FormController(com.servoy.j2db.FormController) JSEvent(com.servoy.j2db.scripting.JSEvent)

Example 7 with JSEvent

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

the class FormController method getJSEvent.

@Override
protected JSEvent getJSEvent(Object src, String eventName) {
    JSEvent event = new JSEvent();
    event.setType(JSEvent.EventType.form);
    if (eventName != null)
        event.setName(RepositoryHelper.getDisplayName(eventName, Form.class));
    event.setFormName(getName());
    event.setSource(src);
    event.setElementName(src instanceof IComponent ? ((IComponent) src).getName() : null);
    return event;
}
Also used : JSEvent(com.servoy.j2db.scripting.JSEvent) IComponent(com.servoy.j2db.ui.IComponent)

Example 8 with JSEvent

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

the class SortableCellViewHeaderGroup method sort.

protected final void sort(final String name, final WebCellBasedView view, int modifiers) {
    direction = Utils.getAsBoolean(sorted.get(name));
    direction = !direction;
    FormController fc = null;
    try {
        Iterator<IPersist> it = cellview.getAllObjects();
        while (it.hasNext()) {
            IPersist element = it.next();
            if (element instanceof ISupportName && element instanceof ISupportDataProviderID) {
                if (name.equals(ComponentFactory.getWebID(form, element))) {
                    IFoundSetInternal fs = ((FoundSetListWrapper) listView.getList()).getFoundSet();
                    if (fs != null) {
                        WebForm wf = listView.findParent(WebForm.class);
                        if (wf != null)
                            fc = wf.getController();
                        GraphicalComponent gc = (GraphicalComponent) view.labelsFor.get(((ISupportName) element).getName());
                        int labelForOnActionMethodId = 0;
                        if (gc != null) {
                            labelForOnActionMethodId = gc.getOnActionMethodID();
                        }
                        if (fc != null && labelForOnActionMethodId > 0) {
                            // execute on action
                            JSEvent event = new JSEvent();
                            event.setType(JSEvent.EventType.action);
                            event.setName(RepositoryHelper.getDisplayName(StaticContentSpecLoader.PROPERTY_ONSORTCMDMETHODID.getPropertyName(), Form.class));
                            event.setFormName(view.getDataAdapterList().getFormController().getName());
                            event.setModifiers(modifiers);
                            event.setElementName(gc.getName());
                            fc.executeFunction(String.valueOf(labelForOnActionMethodId), // $NON-NLS-1$
                            Utils.arrayMerge((new Object[] { event }), Utils.parseJSExpressions(gc.getFlattenedMethodArguments("onActionMethodID"))), true, null, false, // $NON-NLS-1$
                            "onActionMethodID");
                        }
                        String id = ((ISupportDataProviderID) element).getDataProviderID();
                        if (id != null) {
                            if (cellview instanceof Portal && !ScopesUtils.isVariableScope(id)) {
                                int idx = id.lastIndexOf('.');
                                if (idx > 0) {
                                    id = id.substring(idx + 1);
                                }
                            }
                            IDataProvider dataProvider = null;
                            if (fc != null) {
                                dataProvider = fs.getFoundSetManager().getApplication().getFlattenedSolution().getDataproviderLookup(fs.getFoundSetManager(), fc.getForm()).getDataProvider(id);
                            }
                            if (!(fc != null && labelForOnActionMethodId > 0)) {
                                // in case there is no onAction definned
                                if (cellview instanceof Portal || fc == null || fc.getForm().getOnSortCmdMethodID() == 0) {
                                    List<String> sortingProviders = null;
                                    try {
                                        sortingProviders = DBValueList.getShowDataproviders(fs.getFoundSetManager().getApplication().getFlattenedSolution().getValueList(((ISupportDataProviderID) element).getValuelistID()), (Table) fs.getTable(), dataProvider == null ? id : dataProvider.getDataProviderID(), fs.getFoundSetManager());
                                    } catch (RepositoryException ex) {
                                        Debug.error(ex);
                                    }
                                    if (sortingProviders == null) {
                                        // no related sort, use sort on dataProviderID instead
                                        sortingProviders = Collections.singletonList(dataProvider == null ? id : dataProvider.getDataProviderID());
                                    }
                                    List<SortColumn> list = (modifiers & Event.SHIFT_MASK) != 0 ? fs.getSortColumns() : new ArrayList<SortColumn>();
                                    for (String sortingProvider : sortingProviders) {
                                        FoundSetManager fsm = (FoundSetManager) fs.getFoundSetManager();
                                        SortColumn sc = fsm.getSortColumn(fs.getTable(), sortingProvider, false);
                                        if (sc != null && sc.getColumn().getDataProviderType() != IColumnTypes.MEDIA) {
                                            for (SortColumn oldColumn : list) {
                                                if (oldColumn.equalsIgnoreSortorder(sc)) {
                                                    sc = oldColumn;
                                                    break;
                                                }
                                            }
                                            if (!list.contains(sc))
                                                list.add(sc);
                                            sc.setSortOrder(direction ? SortColumn.ASCENDING : SortColumn.DESCENDING);
                                        }
                                        fs.sort(list, false);
                                    }
                                } else if (fc != null && fc.getForm().getOnSortCmdMethodID() != -1) {
                                    JSEvent event = new JSEvent();
                                    event.setType(JSEvent.EventType.none);
                                    event.setName(RepositoryHelper.getDisplayName(StaticContentSpecLoader.PROPERTY_ONSORTCMDMETHODID.getPropertyName(), Form.class));
                                    event.setFormName(view.getDataAdapterList().getFormController().getName());
                                    event.setModifiers(modifiers);
                                    fc.executeFunction(String.valueOf(fc.getForm().getOnSortCmdMethodID()), Utils.arrayMerge((new Object[] { dataProvider == null ? id : dataProvider.getDataProviderID(), Boolean.valueOf(direction), event }), // $NON-NLS-1$
                                    Utils.parseJSExpressions(fc.getForm().getFlattenedMethodArguments("onSortCmdMethodID"))), true, null, false, // $NON-NLS-1$
                                    "onSortCmdMethodID");
                                }
                            }
                            if ((modifiers & Event.SHIFT_MASK) == 0) {
                                sorted.clear();
                            }
                            sorted.put(name, new Boolean(direction));
                            listView.setCurrentPage(0);
                        }
                    }
                    break;
                }
            }
        }
        listView.modelChanged();
    } catch (Exception e) {
        if (fc != null) {
            if (e instanceof ServoyException) {
                ((ServoyException) e).setContext(fc.toString());
            } else {
                ServoyException se = new ServoyException();
                se.initCause(e);
                se.setContext(fc.toString());
                e = se;
            }
        }
        Debug.error("error sorting foundset: " + sorted, e);
    }
}
Also used : Form(com.servoy.j2db.persistence.Form) WebForm(com.servoy.j2db.server.headlessclient.WebForm) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) WebForm(com.servoy.j2db.server.headlessclient.WebForm) ISupportName(com.servoy.j2db.persistence.ISupportName) FoundSetListWrapper(com.servoy.j2db.dataprocessing.FoundSetListWrapper) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IDataProvider(com.servoy.j2db.persistence.IDataProvider) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) ServoyException(com.servoy.j2db.util.ServoyException) Portal(com.servoy.j2db.persistence.Portal) FormController(com.servoy.j2db.FormController) FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) JSEvent(com.servoy.j2db.scripting.JSEvent) Table(com.servoy.j2db.persistence.Table) ISupportDataProviderID(com.servoy.j2db.persistence.ISupportDataProviderID) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IPersist(com.servoy.j2db.persistence.IPersist)

Example 9 with JSEvent

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

the class JSEventType method fromJSON.

@Override
public JSEvent fromJSON(Object newJSONValue, JSEvent previousSabloValue, PropertyDescription pd, IBrowserConverterContext dataConverterContext, ValueReference<Boolean> returnValueAdjustedIncommingValue) {
    JSEvent event = null;
    if (newJSONValue instanceof JSONObject) {
        JSONObject jsonObject = (JSONObject) newJSONValue;
        // $NON-NLS-1$
        event = getReference(jsonObject.optString("jseventhash"));
        if (event == null) {
            BaseWebObject webObject = dataConverterContext.getWebObject();
            event = new JSEvent();
            fillJSEvent(event, jsonObject, webObject, null);
        }
    } else if (newJSONValue instanceof JSEvent) {
        event = (JSEvent) newJSONValue;
    }
    return event;
}
Also used : JSEvent(com.servoy.j2db.scripting.JSEvent) JSONObject(org.json.JSONObject) BaseWebObject(org.sablo.BaseWebObject)

Example 10 with JSEvent

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

the class ClientDesignService method executeMethod.

@Override
public Object executeMethod(String methodName, JSONObject args) throws Exception {
    Object retValue = null;
    String formname = args.optString("formname");
    IWebFormController form = application.getFormManager().getForm(formname);
    if (form != null && form.getDesignModeCallbacks() != null) {
        String layoutWrapperName = args.optString("element");
        JSEvent event = new JSEvent();
        event.setFormName(formname);
        JSONObject jsevent = args.optJSONObject("event");
        if (jsevent != null) {
            if (jsevent.has("timestamp"))
                event.setTimestamp(new Timestamp(jsevent.getLong("timestamp")));
            else
                event.setTimestamp(new Date());
            if (jsevent.has("x"))
                event.setLocation(new Point(jsevent.getInt("x"), jsevent.getInt("y")));
            if (jsevent.has("modifiers"))
                event.setModifiers(jsevent.getInt("modifiers"));
        }
        List<RuntimeWebComponent> selection = new ArrayList<>();
        String name = layoutWrapperName;
        if (layoutWrapperName != null && layoutWrapperName.startsWith("layout.")) {
            name = name.substring(7);
        }
        if (name != null && !"".equals(name)) {
            RuntimeWebComponent[] webComponentElements = form.getWebComponentElements();
            for (RuntimeWebComponent component : webComponentElements) {
                if (component.getComponent().getName().equals(name)) {
                    JSONObject location = args.optJSONObject("location");
                    if (location != null) {
                        component.getComponent().setProperty(StaticContentSpecLoader.PROPERTY_LOCATION.getPropertyName(), new Point(location.optInt("x"), location.optInt("y")));
                    }
                    JSONObject size = args.optJSONObject("size");
                    if (size != null) {
                        component.getComponent().setProperty(StaticContentSpecLoader.PROPERTY_SIZE.getPropertyName(), new Dimension(size.optInt("width"), size.optInt("height")));
                    }
                    selection.add(component);
                    break;
                }
            }
        }
        event.setData(selection.toArray());
        event.setName(methodName);
        switch(methodName) {
            case // $NON-NLS-1$
            "onselect":
                event.setType(IJSEvent.ACTION);
                retValue = form.getDesignModeCallbacks().executeOnSelect(event);
                // selection is allowed, only disallow it when retValue is false directly
                if (retValue == null || Undefined.isUndefined(retValue))
                    retValue = Boolean.TRUE;
                break;
            case // $NON-NLS-1$
            "ondrag":
                event.setType(IJSEvent.EventType.onDrag);
                retValue = form.getDesignModeCallbacks().executeOnDrag(event);
                break;
            case // $NON-NLS-1$
            "ondrop":
                event.setType(IJSEvent.EventType.onDrop);
                retValue = form.getDesignModeCallbacks().executeOnDrop(event);
                break;
            case // $NON-NLS-1$
            "onresize":
                event.setType(IJSEvent.EventType.onDrop);
                retValue = form.getDesignModeCallbacks().executeOnResize(event);
                break;
            case // $NON-NLS-1$
            "onrightclick":
                event.setType(IJSEvent.EventType.rightClick);
                retValue = form.getDesignModeCallbacks().executeOnRightClick(event);
                break;
            case // $NON-NLS-1$
            "ondoubleclick":
                event.setType(IJSEvent.EventType.doubleClick);
                retValue = form.getDesignModeCallbacks().executeOnDblClick(event);
                break;
            default:
                break;
        }
    }
    return Undefined.isUndefined(retValue) ? null : retValue;
}
Also used : JSEvent(com.servoy.j2db.scripting.JSEvent) IJSEvent(com.servoy.base.scripting.api.IJSEvent) ArrayList(java.util.ArrayList) Point(java.awt.Point) Dimension(java.awt.Dimension) Timestamp(java.sql.Timestamp) RuntimeWebComponent(com.servoy.j2db.server.ngclient.component.RuntimeWebComponent) Date(java.util.Date) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject)

Aggregations

JSEvent (com.servoy.j2db.scripting.JSEvent)11 JSONObject (org.json.JSONObject)4 IComponent (com.servoy.j2db.ui.IComponent)3 IJSEvent (com.servoy.base.scripting.api.IJSEvent)2 FormController (com.servoy.j2db.FormController)2 Form (com.servoy.j2db.persistence.Form)2 IPersist (com.servoy.j2db.persistence.IPersist)2 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)2 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)2 ServoyException (com.servoy.j2db.util.ServoyException)2 ArrayList (java.util.ArrayList)2 JSONException (org.json.JSONException)2 Scriptable (org.mozilla.javascript.Scriptable)2 PropertyDescription (org.sablo.specification.PropertyDescription)2 FoundSetListWrapper (com.servoy.j2db.dataprocessing.FoundSetListWrapper)1 FoundSetManager (com.servoy.j2db.dataprocessing.FoundSetManager)1 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)1 IRecord (com.servoy.j2db.dataprocessing.IRecord)1 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)1 SortColumn (com.servoy.j2db.dataprocessing.SortColumn)1