Search in sources :

Example 16 with WebForm

use of com.servoy.j2db.server.headlessclient.WebForm in project servoy-client by Servoy.

the class WebAccordionPanel method getTagResolver.

private ITagResolver getTagResolver(IRecordInternal parentState) {
    ITagResolver resolver;
    WebForm webForm = findParent(WebForm.class);
    if (webForm != null) {
        resolver = webForm.getController().getTagResolver();
    } else {
        resolver = TagResolver.createResolver(parentState);
    }
    return resolver;
}
Also used : ITagResolver(com.servoy.base.util.ITagResolver) WebForm(com.servoy.j2db.server.headlessclient.WebForm)

Example 17 with WebForm

use of com.servoy.j2db.server.headlessclient.WebForm in project servoy-client by Servoy.

the class WebAccordionPanel method setCurrentForm.

private void setCurrentForm(WebTabFormLookup fl, int previousIndex, List<Runnable> invokeLaterRunnables) {
    if (fl != null && !fl.isFormReady())
        return;
    getStylePropertyChanges().setChanged();
    currentForm = fl;
    if (parentData != null) {
        showFoundSet(currentForm, parentData, getDefaultSort());
    }
    // Test if current one is there
    if (currentForm.isReady()) {
        addCurrentFormComponent();
        recomputeTabSequence();
        boolean visible = true;
        WebForm webform = findParent(WebForm.class);
        if (webform != null) {
            visible = webform.getController().isFormVisible();
        }
        currentForm.notifyVisible(visible, invokeLaterRunnables);
        if (onTabChangeMethodCmd != null && previousIndex != -1) {
            scriptExecutor.executeFunction(onTabChangeMethodCmd, Utils.arrayMerge((new Object[] { Integer.valueOf(previousIndex + 1) }), onTabChangeArgs), true, this, false, StaticContentSpecLoader.PROPERTY_ONCHANGEMETHODID.getPropertyName(), false);
        }
    }
}
Also used : WebForm(com.servoy.j2db.server.headlessclient.WebForm)

Example 18 with WebForm

use of com.servoy.j2db.server.headlessclient.WebForm 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 19 with WebForm

use of com.servoy.j2db.server.headlessclient.WebForm in project servoy-client by Servoy.

the class InlineScriptExecutorBehavior method respond.

@Override
protected void respond(AjaxRequestTarget target) {
    Page page = component.getPage();
    String scriptName = RequestCycle.get().getRequest().getParameter("snenc");
    ICrypt urlCrypt = Application.get().getSecuritySettings().getCryptFactory().newCrypt();
    scriptName = urlCrypt.decryptUrlSafe(scriptName).replace("\\\"", "\"");
    String argValue;
    for (String browserArgument : getBrowserArguments(scriptName)) {
        argValue = RequestCycle.get().getRequest().getParameter(browserArgument);
        if (argValue == null)
            argValue = "";
        boolean isString = true;
        try {
            Double.parseDouble(argValue);
            isString = false;
        } catch (NumberFormatException ex) {
        }
        if (isString && ("true".equals(argValue) || "false".equals(argValue)))
            isString = false;
        String browserParamWithArgument = BROWSER_PARAM + browserArgument;
        // make sure we ignore user quoting if isString
        if (isString) {
            scriptName = scriptName.replace("\"" + browserParamWithArgument + "\"", browserParamWithArgument);
            scriptName = scriptName.replace("'" + browserParamWithArgument + "'", browserParamWithArgument);
        }
        scriptName = scriptName.replace(browserParamWithArgument, isString ? "'" + argValue + "'" : argValue);
    }
    WebForm wf = component.findParent(WebForm.class);
    if (wf != null) {
        try {
            wf.getController().eval(scriptName);
        } catch (Exception e) {
            if (!(e instanceof ExitScriptException)) {
                // $NON-NLS-1$
                Debug.error("Exception evaluating: " + scriptName, e);
            }
        }
        WebEventExecutor.generateResponse(target, page);
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    target.appendJavascript("clearDoubleClickId('" + component.getMarkupId() + "')");
}
Also used : ICrypt(org.apache.wicket.util.crypt.ICrypt) WebForm(com.servoy.j2db.server.headlessclient.WebForm) Page(org.apache.wicket.Page) ExitScriptException(com.servoy.j2db.ExitScriptException) ExitScriptException(com.servoy.j2db.ExitScriptException)

Example 20 with WebForm

use of com.servoy.j2db.server.headlessclient.WebForm in project servoy-client by Servoy.

the class RecordItemModel method setValue.

/**
 * @param obj
 * @param dataProviderID
 * @param prevValue
 */
public void setValue(Component component, String dataProviderID, Object value) {
    Object obj = value;
    String compDpid = getDataProviderID(component);
    boolean ownComponentsValue = compDpid != null && dataProviderID.endsWith(compDpid);
    Object prevValue = null;
    if (ownComponentsValue && component instanceof IResolveObject) {
        obj = ((IResolveObject) component).resolveRealValue(obj);
    }
    if (component instanceof IDisplayData) {
        obj = Utils.removeJavascripLinkFromDisplay((IDisplayData) component, new Object[] { obj });
    }
    WebForm webForm = component.findParent(WebForm.class);
    IRecordInternal record = (IRecordInternal) RecordItemModel.this.getObject();
    // use UI converter to convert from UI value to record value
    if (!(record instanceof FindState)) {
        obj = ComponentFormat.applyUIConverterFromObject(component, obj, dataProviderID, webForm.getController().getApplication().getFoundSetManager());
    }
    FormScope fs = webForm.getController().getFormScope();
    try {
        Pair<String, String> scope = ScopesUtils.getVariableScope(dataProviderID);
        if (scope.getLeft() != null) {
            if (record == null) {
                webForm.getController().getApplication().getScriptEngine().getSolutionScope().getScopesScope().getGlobalScope(scope.getLeft()).put(scope.getRight(), obj);
            } else {
                // does an additional fire in foundset!
                prevValue = record.getParentFoundSet().setDataProviderValue(dataProviderID, obj);
            }
        } else if (fs.has(dataProviderID, fs)) {
            prevValue = fs.get(dataProviderID);
            fs.put(dataProviderID, obj);
        } else {
            if (record != null && record.startEditing()) {
                try {
                    prevValue = record.getValue(dataProviderID);
                    record.setValue(dataProviderID, obj);
                } catch (IllegalArgumentException e) {
                    Debug.trace(e);
                    ((WebClientSession) Session.get()).getWebClient().handleException(null, new ApplicationException(ServoyException.INVALID_INPUT, e));
                    Object stateValue = record.getValue(dataProviderID);
                    if (!Utils.equalObjects(prevValue, stateValue)) {
                        // reset display to changed value in validator method
                        obj = stateValue;
                    }
                    if (ownComponentsValue) {
                        ((IDisplayData) component).setValueValid(false, prevValue);
                    }
                    return;
                }
                if (ownComponentsValue && record instanceof FindState && component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IFormatScriptComponent && ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat() != null) {
                    ((FindState) record).setFormat(dataProviderID, ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat().parsedFormat);
                }
            }
        }
        // then dont call notify
        if (ownComponentsValue) {
            ((IDisplayData) component).notifyLastNewValueWasChange(prevValue, obj);
        }
    } finally {
        // then touch the lastInvalidValue
        if (ownComponentsValue) {
            if (((IDisplayData) component).isValueValid()) {
                lastInvalidValue = NONE;
            } else {
                lastInvalidValue = obj;
            }
        }
    }
    return;
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) WebForm(com.servoy.j2db.server.headlessclient.WebForm) FormScope(com.servoy.j2db.scripting.FormScope) FindState(com.servoy.j2db.dataprocessing.FindState) ApplicationException(com.servoy.j2db.ApplicationException) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IFormatScriptComponent(com.servoy.j2db.ui.scripting.IFormatScriptComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Aggregations

WebForm (com.servoy.j2db.server.headlessclient.WebForm)21 FormController (com.servoy.j2db.FormController)7 Point (java.awt.Point)6 Component (org.apache.wicket.Component)5 IComponent (com.servoy.j2db.ui.IComponent)4 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)4 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)3 MarkupContainer (org.apache.wicket.MarkupContainer)3 ITagResolver (com.servoy.base.util.ITagResolver)2 FlattenedSolution (com.servoy.j2db.FlattenedSolution)2 FindState (com.servoy.j2db.dataprocessing.FindState)2 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)2 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)2 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)2 Form (com.servoy.j2db.persistence.Form)2 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 FormScope (com.servoy.j2db.scripting.FormScope)2 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)2 ArrayList (java.util.ArrayList)2 AbstractActiveSolutionHandler (com.servoy.j2db.AbstractActiveSolutionHandler)1