Search in sources :

Example 1 with UnknownValuesException

use of com.ramussoft.eval.UnknownValuesException in project ramus by Vitaliy-Yakovchuk.

the class SetFormulaDialog method onOk.

@Override
protected void onOk() {
    if (editor.getText().equals("")) {
        info.setFormula(null);
        ((Journaled) engine).startUserTransaction();
        engine.setCalculateInfo(info);
        ((Journaled) engine).commitUserTransaction();
        super.onOk();
        return;
    }
    Util utils = Util.getUtils(engine);
    try {
        try {
            info.setFormula(utils.compile(editor.getText(), engine.getElement(info.getElementId()), engine.getAttribute(info.getAttributeId())));
        } catch (UnknownValuesException e) {
            StringBuffer sb = new StringBuffer();
            sb.append("<html><body>");
            for (String value : e.getValues()) {
                sb.append(MessageFormat.format(GlobalResourcesManager.getString("Eval.UnknowValue"), value));
                sb.append("<br>");
            }
            sb.append("</body></html>");
            JOptionPane.showMessageDialog(null, sb.toString());
        }
        Eval eval = new Eval(info.getFormula());
        List<String> rec = new ArrayList<String>();
        for (String function : eval.getFunctions()) if (!utils.isFunctionExists(function)) {
            JOptionPane.showMessageDialog(null, MessageFormat.format(GlobalResourcesManager.getString("Eval.UnknowFunction"), function));
            return;
        }
        rec.add(utils.toValue(info.getElementId(), info.getAttributeId()));
        if (recCheck(rec, eval, utils)) {
            JOptionPane.showMessageDialog(null, GlobalResourcesManager.getString("Recursive.Link"));
        } else {
            ((Journaled) engine).startUserTransaction();
            engine.setCalculateInfo(info);
            ((Journaled) engine).commitUserTransaction();
            super.onOk();
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, MessageFormat.format(GlobalResourcesManager.getString("Eval.Error"), editor.getText()));
        return;
    }
}
Also used : Journaled(com.ramussoft.common.journal.Journaled) UnknownValuesException(com.ramussoft.eval.UnknownValuesException) ArrayList(java.util.ArrayList) Util(com.ramussoft.eval.Util) Eval(com.ramussoft.eval.Eval) UnknownValuesException(com.ramussoft.eval.UnknownValuesException)

Aggregations

Journaled (com.ramussoft.common.journal.Journaled)1 Eval (com.ramussoft.eval.Eval)1 UnknownValuesException (com.ramussoft.eval.UnknownValuesException)1 Util (com.ramussoft.eval.Util)1 ArrayList (java.util.ArrayList)1