use of com.ramussoft.eval.Util in project ramus by Vitaliy-Yakovchuk.
the class EvalQualifierSetupEditor method load.
@SuppressWarnings("unchecked")
@Override
public void load(Engine engine, Qualifier qualifier) {
this.engine = engine;
this.qualifier = qualifier;
Element element = StandardAttributesPlugin.getElement(engine, qualifier.getId());
List<FunctionPersistent> list = EvalPlugin.getFunctionAttribute(engine, element);
if (list == null)
list = new ArrayList<FunctionPersistent>(0);
Util utils = Util.getUtils(engine);
Hashtable<Attribute, ArrayList<Attribute>> attrs = new Hashtable<Attribute, ArrayList<Attribute>>();
int lentgh = 0;
for (Attribute attr : qualifier.getAttributes()) {
if (attr.getAttributeType().toString().equals("Core.Table")) {
ArrayList<Attribute> aList = new ArrayList<Attribute>();
attrs.put(attr, aList);
Qualifier q = StandardAttributesPlugin.getTableQualifierForAttribute(engine, attr);
aList.addAll(q.getAttributes());
lentgh += q.getAttributes().size();
} else {
attrs.put(attr, new ArrayList<Attribute>(0));
lentgh++;
}
}
functions = new FunctionPersistent[lentgh];
names = new String[lentgh];
attributes = new Attribute[lentgh];
tableAttributes = new Attribute[lentgh];
int i = 0;
for (Attribute attribute : attrs.keySet()) {
if (attribute.getAttributeType().toString().equals("Core.Table")) {
for (Attribute tableAttribute : attrs.get(attribute)) {
attributes[i] = attribute;
tableAttributes[i] = tableAttribute;
names[i] = Util.toCanonicalValue(attribute.getName() + "." + tableAttribute.getName());
functions[i] = getFunction(list, attribute, tableAttribute, utils);
i++;
}
} else {
attributes[i] = attribute;
names[i] = Util.toCanonicalValue(attribute.getName());
functions[i] = getFunction(list, attribute, null, utils);
i++;
}
}
if (this.qualifier != null) {
this.fireTableDataChanged();
}
}
use of com.ramussoft.eval.Util 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;
}
}
use of com.ramussoft.eval.Util in project ramus by Vitaliy-Yakovchuk.
the class EvalPlugin method calculate.
public static void calculate(Engine engine, Qualifier qualifier, List<FunctionPersistent> functions) {
Util utils = Util.getUtils(engine);
Eval[] evals = utils.sort(functions);
List<Attribute> sources = new ArrayList<Attribute>();
for (Eval eval : evals) {
utils.addAttributes(sources, eval, qualifier.getAttributes());
}
Hashtable<Element, Object[]> hash = engine.getElements(qualifier, sources);
for (Entry<Element, Object[]> entry : hash.entrySet()) {
Element element = entry.getKey();
Object[] values = entry.getValue();
int i = 0;
for (Eval eval : evals) {
utils.fillAttributes(eval, element, sources, values, true);
FunctionPersistent fp = functions.get(i);
if (fp.getQualifierTableAttributeId() == -1l) {
try {
Object object = utils.fillResult(fp.getQualifierAttributeId(), eval, element);
for (int j = 0; j < values.length; j++) {
if (sources.get(j).getId() == fp.getQualifierAttributeId())
values[j] = object;
}
} catch (Exception e) {
utils.fillResult(fp.getQualifierAttributeId(), e, element);
}
} else {
Attribute tableAttribute = engine.getAttribute(fp.getQualifierAttributeId());
Qualifier tableQualifier = StandardAttributesPlugin.getTableQualifierForAttribute(engine, tableAttribute);
List<Element> tableElements = StandardAttributesPlugin.getTableElements(engine, tableAttribute, element);
List<Attribute> tableAttributes = utils.getTableAttributes(tableQualifier, fp.getQualifierAttributeId(), eval);
for (Element tableElement : tableElements) {
for (Attribute attr : tableAttributes) {
Object value = engine.getAttribute(tableElement, attr);
eval.setValue(Util.tableAttributeToValue(fp.getQualifierAttributeId(), attr.getId()), new EObject(value, tableElement, attr, engine));
}
try {
utils.fillResult(fp.getQualifierTableAttributeId(), eval, tableElement);
} catch (Exception e) {
utils.fillResult(fp.getQualifierTableAttributeId(), e, tableElement);
}
}
}
i++;
}
}
}
Aggregations