Search in sources :

Example 6 with ServoyException

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

the class ValueListTypeSabloValue method filterValuelist.

/**
 * Filters the values of the valuelist for type-ahead-like usage.
 */
private void filterValuelist(JSONObject newJSONValue) {
    if (!initialized) {
        Debug.warn("Trying to send to client an uninitialized valuelist property: " + vlPD + " of " + webObjectContext);
        return;
    }
    this.valuesRequested = true;
    this.handledIDForResponse = Long.valueOf(newJSONValue.getLong(ID_KEY));
    String filterString = newJSONValue.optString(FILTER);
    if (filteredValuelist == null) {
        filteredValuelist = createFilteredValueList();
        if (filteredValuelist != null) {
            filteredValuelist.addListDataListener(new ListDataListener() {

                @Override
                public void intervalRemoved(ListDataEvent e) {
                    changeMonitor.markFullyChanged(true);
                }

                @Override
                public void intervalAdded(ListDataEvent e) {
                    changeMonitor.markFullyChanged(true);
                }

                @Override
                public void contentsChanged(ListDataEvent e) {
                    changeMonitor.markFullyChanged(true);
                }
            });
        }
    }
    if (filteredValuelist != null) {
        try {
            valueList.removeListDataListener(this);
            Object realValue = dataAdapterListToUse.getValueObject(dataAdapterListToUse.getRecord(), dataproviderID);
            // do mark it as changed but don't notify yet (false arg) because fill below will probably trigger listener above and notify anyway; that would mean that although
            // we do call notify after fill that is likely to end up in a NO_OP changesToJSON in case of foundset-linked valuelist properties
            changeMonitor.markFullyChanged(false);
            boolean useContains = Utils.getAsBoolean(dataAdapterListToUse.getApplication().getClientProperty(IApplication.VALUELIST_CONTAINS_SEARCH));
            if (!useContains && webObjectContext != null && webObjectContext.getUnderlyingWebObject() instanceof WebFormComponent) {
                WebFormComponent webObject = (WebFormComponent) webObjectContext.getUnderlyingWebObject();
                RuntimeWebComponent webComponentElement = dataAdapterListToUse.getForm().getWebComponentElement(webObject.getFormElement().getRawName());
                if (webComponentElement != null && webComponentElement.getPrototype() instanceof RuntimeLegacyComponent) {
                    RuntimeLegacyComponent legacy = (RuntimeLegacyComponent) webComponentElement.getPrototype();
                    useContains = Utils.getAsBoolean(legacy.getClientProperty(IApplication.VALUELIST_CONTAINS_SEARCH, legacy));
                }
            }
            if (useContains && filterString != null)
                filterString = '%' + filterString;
            filteredValuelist.fill(dataAdapterListToUse.getRecord(), dataproviderID, filterString, realValue, false);
            // in case fill really somehow did not result in the filteredValuelist listener doing a notify
            changeMonitor.notifyOfChange();
            valueList.addListDataListener(this);
        } catch (ServoyException e) {
            Debug.error(e);
        }
    }
}
Also used : ListDataEvent(javax.swing.event.ListDataEvent) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) JSONObject(org.json.JSONObject) RuntimeLegacyComponent(com.servoy.j2db.server.ngclient.component.RuntimeLegacyComponent) ListDataListener(javax.swing.event.ListDataListener) RuntimeWebComponent(com.servoy.j2db.server.ngclient.component.RuntimeWebComponent) ServoyException(com.servoy.j2db.util.ServoyException)

Example 7 with ServoyException

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

the class BasicFormController method setModel.

protected boolean setModel(IFoundSetInternal newModel) throws ServoyException {
    if (newModel == formModel || adjustingModel) {
        // same or adjusting do nothing
        return true;
    }
    ITable formTable = application.getFoundSetManager().getTable(form.getDataSource());
    if (newModel != null && ((formTable == null && newModel.getTable() != null) || (formTable != null && !formTable.equals(newModel.getTable())))) {
        throw new IllegalArgumentException(application.getI18NMessage("servoy.formPanel.error.wrongFoundsetTable", new Object[] { // $NON-NLS-1$
        newModel.getTable() == null ? "NONE" : newModel.getTable().getName(), // $NON-NLS-1$
        form.getTableName() }));
    }
    try {
        IView view = getViewComponent();
        if (view != null && view.isEditing()) {
            // TODO if save fails don't set the newModel??
            int stopped = application.getFoundSetManager().getEditRecordList().stopEditing(false);
            if (stopped != ISaveConstants.STOPPED && stopped != ISaveConstants.AUTO_SAVE_BLOCKED) {
                return false;
            }
        }
        adjustingModel = true;
        if (formModel != null) {
            try {
                ((ISwingFoundSet) formModel).getSelectionModel().removeListSelectionListener(this);
                ((ISwingFoundSet) formModel).getSelectionModel().removeFormController(this);
                ((ISwingFoundSet) formModel).removeTableModelListener(this);
                // to make sure all data is gc'ed
                if (formModel instanceof FoundSet)
                    ((FoundSet) formModel).flushAllCachedItems();
            } catch (Exception ex) {
                Debug.error(ex);
            }
        }
        setFormModelInternal(newModel == null ? ((FoundSetManager) application.getFoundSetManager()).getEmptyFoundSet(this) : newModel);
        if (formScope != null) {
            // $NON-NLS-1$
            formScope.putWithoutFireChange("foundset", formModel);
            if (formScope.getPrototype() == null) {
                formScope.setPrototype(new SelectedRecordScope(this, formTable == null ? null : application.getScriptEngine().getTableScope(formTable)));
            }
        }
        if (isFormVisible) {
            ((ISwingFoundSet) formModel).getSelectionModel().addListSelectionListener(this);
            ((ISwingFoundSet) formModel).getSelectionModel().addFormController(this);
            ((ISwingFoundSet) formModel).addTableModelListener(this);
            if (// it may not yet exist
            view != null) {
                view.setModel(formModel);
            }
            // this was former a call to aggregateChange, but now does now unwanted parent traverse...
            int[] idx = null;
            if (getView() == RECORD_VIEW || getView() == LOCKED_RECORD_VIEW) {
                int selIdx = formModel.getSelectedIndex();
                if (selIdx != -1)
                    idx = new int[] { selIdx };
            } else {
                idx = formModel.getSelectedIndexes();
            }
            if (idx == null || idx.length == 0) {
                refreshAllPartRenderers(new IRecordInternal[] { formModel.getPrototypeState() });
            } else {
                IRecordInternal[] row = new IRecordInternal[idx.length];
                for (int i = 0; i < idx.length; i++) row[i] = formModel.getRecord(idx[i]);
                refreshAllPartRenderers(row);
            }
        }
    } finally {
        adjustingModel = false;
    }
    return true;
}
Also used : FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IJSFoundSet(com.servoy.base.scripting.api.IJSFoundSet) IFoundSet(com.servoy.j2db.dataprocessing.IFoundSet) RelatedFoundSet(com.servoy.j2db.dataprocessing.RelatedFoundSet) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) ViewFoundSet(com.servoy.j2db.dataprocessing.ViewFoundSet) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) SelectedRecordScope(com.servoy.j2db.scripting.SelectedRecordScope) ITable(com.servoy.j2db.persistence.ITable) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ITwoNativeJavaObject(com.servoy.j2db.scripting.ITwoNativeJavaObject)

Example 8 with ServoyException

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

the class ClientState method getScriptException.

public static Object getScriptException(final Exception e) {
    Exception scriptException = e;
    // first check for a javascript exception with its value
    if (scriptException instanceof JavaScriptException) {
        if (((JavaScriptException) scriptException).getValue() instanceof Exception) {
            scriptException = (Exception) ((JavaScriptException) scriptException).getValue();
        } else if (((JavaScriptException) scriptException).getValue() != null) {
            // just return the object thrown in scripting
            return ((JavaScriptException) scriptException).getValue();
        }
    } else // then check if it is RhinoException and skip that one by default.
    if (scriptException instanceof RhinoException && scriptException.getCause() instanceof Exception) {
        scriptException = (Exception) scriptException.getCause();
    }
    // Now search for a ServoyException in the chain.
    Throwable cause = scriptException;
    while (cause != null && !(cause instanceof ServoyException)) {
        cause = cause.getCause();
        if (cause instanceof ServoyException) {
            scriptException = (ServoyException) cause;
        }
    }
    return scriptException;
}
Also used : RhinoException(org.mozilla.javascript.RhinoException) UnmarshalException(java.rmi.UnmarshalException) RhinoException(org.mozilla.javascript.RhinoException) RemoteException(java.rmi.RemoteException) ServoyException(com.servoy.j2db.util.ServoyException) JavaScriptException(org.mozilla.javascript.JavaScriptException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ServoyException(com.servoy.j2db.util.ServoyException) JavaScriptException(org.mozilla.javascript.JavaScriptException)

Example 9 with ServoyException

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

the class DisplaysAdapter method startEdit.

public static void startEdit(DataAdapterList dal, IDisplay display, IRecordInternal state) {
    final IApplication application = dal.getApplication();
    dal.setCurrentDisplay(display);
    boolean isGlobal = false;
    boolean isColumn = true;
    if (display instanceof IDisplayData) {
        String dataProviderID = ((IDisplayData) display).getDataProviderID();
        isGlobal = dataProviderID != null && ScopesUtils.isVariableScope(dataProviderID);
        if (!isGlobal && dataProviderID != null) {
            // $NON-NLS-1$
            String[] parts = dataProviderID.split("\\.");
            IRecordInternal currState = state;
            for (int i = 0; i < parts.length - 1; i++) {
                IFoundSetInternal foundset = currState.getRelatedFoundSet(parts[i]);
                if (foundset == null) {
                    break;
                }
                Relation r = application.getFoundSetManager().getApplication().getFlattenedSolution().getRelation(parts[i]);
                currState = foundset.getRecord(foundset.getSelectedIndex());
                if (currState == null) {
                    if (r != null && r.getAllowCreationRelatedRecords()) {
                        try {
                            currState = foundset.getRecord(foundset.newRecord(0, true));
                        } catch (ServoyException se) {
                            application.reportError(se.getLocalizedMessage(), se);
                        }
                    } else {
                        final ApplicationException ae = new ApplicationException(ServoyException.NO_RELATED_CREATE_ACCESS, new Object[] { parts[i] });
                        ae.setContext(dal.getFormController().toString());
                        // unfocus the current field, otherwise when the dialog is closed focus is set back to this field and the same error recurs ad infinitum.
                        application.looseFocus();
                        application.invokeLater(new Runnable() {

                            public void run() {
                                // ApplicationException knows how to translate this null into an i18n message
                                application.handleException(null, ae);
                            }
                        });
                    }
                }
                if (currState == null)
                    return;
            }
            isColumn = currState.getParentFoundSet().getColumnIndex(parts[parts.length - 1]) != -1 || currState.getParentFoundSet().containsCalculation(dataProviderID);
        }
    }
    if (// globals are always allowed to set in datarenderers
    isGlobal || !isColumn || state.startEditing()) {
        // bit ugly should use property event here
        if (application instanceof ISmartClientApplication)
            ((ISmartClientApplication) application).updateInsertModeIcon(display);
    } else {
        // loose focus first
        // don't transfer focus to menu bar.. (macosx)
        // application.getMainApplicationFrame().getJMenuBar().requestFocus();
        application.looseFocus();
        application.reportWarningInStatus(// $NON-NLS-1$
        application.getI18NMessage("servoy.foundSet.error.noModifyAccess", new Object[] { state.getParentFoundSet().getDataSource() }));
    }
}
Also used : ISmartClientApplication(com.servoy.j2db.ISmartClientApplication) ServoyException(com.servoy.j2db.util.ServoyException) IApplication(com.servoy.j2db.IApplication) Relation(com.servoy.j2db.persistence.Relation) ApplicationException(com.servoy.j2db.ApplicationException)

Example 10 with ServoyException

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

the class FindState method getRelatedFoundSet.

/*
	 * _____________________________________________________________ Related states implementation
	 */
/**
 * Get related foundset, relationName may be multiple-levels deep
 */
public IFoundSetInternal getRelatedFoundSet(String relationName, List<SortColumn> defaultSortColumns) {
    if (relationName == null || parent == null)
        return null;
    String partName = relationName;
    String restName = null;
    int index = relationName.indexOf('.');
    if (index > 0) {
        partName = relationName.substring(0, index);
        restName = relationName.substring(index + 1);
    }
    IFoundSetInternal rfs = relatedStates.get(partName);
    if (rfs == null) {
        FlattenedSolution fs = parent.getFoundSetManager().getApplication().getFlattenedSolution();
        Relation r = fs.getRelation(partName);
        // safety
        if (r == null)
            return null;
        try {
            if (r.isGlobal() || r.isParentRef()) {
                rfs = parent.getRelatedFoundSet(this, partName, defaultSortColumns);
            // do not store in relatedStates because it is not a relatedfindfoundset
            } else {
                if (!getValidSearchRelations().contains(r)) {
                    if (relatedFoundsetErrorReported == null)
                        relatedFoundsetErrorReported = new ArrayList<>();
                    if (!relatedFoundsetErrorReported.contains(partName)) {
                        relatedFoundsetErrorReported.add(partName);
                        String reason = "";
                        if (r.isGlobal())
                            reason = "global relation";
                        else if (r.isMultiServer())
                            reason = "multi server";
                        else if (!Relation.isValid(r, fs))
                            reason = "server/table not valid/loaded";
                        else {
                            reason = "relation primary datasource: " + r.getPrimaryDataSource() + " != findstate primary datasource: " + parent.getDataSource();
                        }
                        Debug.warn("Find: skip related search for '" + partName + "', relation cannot be used in search, because: " + reason);
                        parent.getFoundSetManager().getApplication().reportJSWarning(Messages.getString("servoy.relation.find.unusable", new Object[] { partName }) + " (" + reason + ')', // $NON-NLS-2$
                        null);
                    }
                    return null;
                }
                SQLSheet sheet = parent.getSQLSheet().getRelatedSheet(((FoundSetManager) parent.getFoundSetManager()).getApplication().getFlattenedSolution().getRelation(partName), ((FoundSetManager) parent.getFoundSetManager()).getSQLGenerator());
                rfs = ((FoundSetManager) parent.getFoundSetManager()).createRelatedFindFoundSet(this, partName, sheet);
                ((FoundSet) rfs).addParent(this);
                ((FoundSet) rfs).setFindMode();
                relatedStates.put(partName, rfs);
            }
        } catch (ServoyException ex) {
            // $NON-NLS-1$
            Debug.error("Error making related findstate", ex);
            return null;
        }
    }
    if (restName != null) {
        IRecordInternal record = rfs.getRecord(rfs.getSelectedIndex());
        if (record == null)
            return null;
        return record.getRelatedFoundSet(restName);
    }
    return rfs;
}
Also used : Relation(com.servoy.j2db.persistence.Relation) IRelation(com.servoy.j2db.persistence.IRelation) ArrayList(java.util.ArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IJSFoundSet(com.servoy.base.scripting.api.IJSFoundSet) ServoyException(com.servoy.j2db.util.ServoyException)

Aggregations

ServoyException (com.servoy.j2db.util.ServoyException)58 RepositoryException (com.servoy.j2db.persistence.RepositoryException)31 ApplicationException (com.servoy.j2db.ApplicationException)25 RemoteException (java.rmi.RemoteException)25 ArrayList (java.util.ArrayList)16 ITable (com.servoy.j2db.persistence.ITable)14 QuerySelect (com.servoy.j2db.query.QuerySelect)13 BaseQueryTable (com.servoy.base.query.BaseQueryTable)11 QueryTable (com.servoy.j2db.query.QueryTable)10 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)10 IOException (java.io.IOException)9 SQLException (java.sql.SQLException)9 JavaScriptException (org.mozilla.javascript.JavaScriptException)9 Column (com.servoy.j2db.persistence.Column)8 Table (com.servoy.j2db.persistence.Table)8 IBaseColumn (com.servoy.base.persistence.IBaseColumn)7 QueryColumn (com.servoy.j2db.query.QueryColumn)7 HashMap (java.util.HashMap)7 MarshallException (org.jabsorb.serializer.MarshallException)7 NativeObject (org.mozilla.javascript.NativeObject)7