use of com.ramussoft.eval.EObject in project ramus by Vitaliy-Yakovchuk.
the class EvalPlugin method recalculateQualifierAttribute.
private void recalculateQualifierAttribute(final Engine engine, Qualifier q, Util utils, FunctionPersistent fp) {
Eval eval = new Eval(fp.getFunction());
if (fp.getQualifierTableAttributeId() == -1l) {
List<Attribute> attributes = utils.getAttributes(q, eval);
Hashtable<Element, Object[]> data = engine.getElements(q, attributes);
for (Entry<Element, Object[]> entry : data.entrySet()) {
Object[] objects = entry.getValue();
Element element = entry.getKey();
for (int i = 0; i < objects.length; i++) {
eval.setValue(utils.toValue(attributes.get(i).getId()), new EObject(objects[i], element, attributes.get(i), engine));
}
utils.fillMetaValues(eval);
try {
utils.fillResult(fp.getQualifierAttributeId(), eval, element);
} catch (Exception e) {
utils.fillResult(fp.getQualifierAttributeId(), e, element);
}
}
} else {
List<Attribute> attributes = utils.getAttributes(q, eval);
Hashtable<Element, Object[]> data = engine.getElements(q, attributes);
for (Entry<Element, Object[]> entry : data.entrySet()) {
Object[] objects = entry.getValue();
Element element = entry.getKey();
for (int i = 0; i < objects.length; i++) {
eval.setValue(utils.toValue(attributes.get(i).getId()), new EObject(objects[i], element, attributes.get(i), engine));
}
utils.fillMetaValues(eval);
Qualifier tableQualifier = StandardAttributesPlugin.getTableQualifierForAttribute(engine, fp.getQualifierAttributeId());
List<Element> table = StandardAttributesPlugin.getTableElements(engine, engine.getAttribute(fp.getQualifierAttributeId()), element);
List<Attribute> tableAttributes = utils.getTableAttributes(tableQualifier, fp.getQualifierAttributeId(), eval);
for (Element tableElement : table) try {
for (Attribute tableAttribute : tableAttributes) {
Object value = engine.getAttribute(tableElement, tableAttribute);
eval.setValue(Util.tableAttributeToValue(fp.getQualifierAttributeId(), tableAttribute.getId()), new EObject(value, tableElement, tableAttribute, engine));
}
utils.fillResult(fp.getQualifierTableAttributeId(), eval, tableElement);
} catch (Exception e) {
utils.fillResult(fp.getQualifierTableAttributeId(), e, tableElement);
}
}
}
}
use of com.ramussoft.eval.EObject in project ramus by Vitaliy-Yakovchuk.
the class BarChartDataPlugin method createChart.
@Override
public JFreeChart createChart(Element element, ChartSource source) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
Attribute key = source.getAttributeProperty(BAR_ATTRIBUTE_KEY);
List<Attribute> attributes = source.getPropertyAttributes(BAR_ATTRIBUTE_VALUE_PREFIX);
for (Element e : source.getElements()) {
Object keyValue = engine.getAttribute(e, key);
if (keyValue != null) {
for (Attribute attribute : attributes) {
Object value = engine.getAttribute(e, attribute);
if (value != null) {
double v = new EObject(value).doubleValue();
dataset.addValue(v, attribute.getName(), new EObject(keyValue).stringValue());
}
}
}
}
JFreeChart chart = ChartFactory.createBarChart3D(element.getName(), source.getProperty(BAR_CATEGORY_AXIS_LABEL), source.getProperty(BAR_VALUE_AXIS_LABEL), dataset, (BAR_ORIENTATION_HORIZONTAL.equals(source.getProperty(BAR_ORIENTATION))) ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL, true, true, true);
GradientPaint gradientpaint0 = new GradientPaint(0.0F, 0.0F, new Color(0, 0, 250), 0.0F, 0.0F, new Color(136, 136, 255));
BarRenderer3D r = (BarRenderer3D) chart.getCategoryPlot().getRenderer();
r.setSeriesPaint(0, gradientpaint0);
return chart;
}
use of com.ramussoft.eval.EObject 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++;
}
}
}
use of com.ramussoft.eval.EObject in project ramus by Vitaliy-Yakovchuk.
the class ComplexImport method fill.
private void fill(Element element, Cell cell, Attribute attribute, ImportRule rule) {
Engine engine = rowSet.getEngine();
String type = attribute.getAttributeType().toString();
if (cell == null) {
try {
engine.setAttribute(element, attribute, sheetName);
} catch (Exception e) {
}
} else {
try {
EObject object = null;
if (cell.getCellType() == Cell.CELL_TYPE_STRING)
object = new EObject(cell.getStringCellValue());
else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC)
object = new EObject(cell.getNumericCellValue());
else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC)
object = new EObject(cell.getDateCellValue());
else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC)
object = new EObject(cell.getDateCellValue());
if (object == null)
try {
object = new EObject(cell.getStringCellValue());
} catch (Exception e) {
}
if (object == null)
try {
object = new EObject(cell.getNumericCellValue());
} catch (Exception e) {
}
if (object == null)
try {
object = new EObject(cell.getDateCellValue());
} catch (Exception e) {
}
if (object == null)
return;
if (("".equals(object.getValue())) && (engine.getAttribute(element, attribute) != null)) {
setAttribute(engine, element, attribute, null, rule);
return;
}
if ((object.getValue() == null) && (engine.getAttribute(element, attribute) != null)) {
setAttribute(engine, element, attribute, null, rule);
return;
}
if (("Core.Double".equals(type)) || ("Core.Currency".equals(type))) {
setAttribute(engine, element, attribute, object.doubleValue(), rule);
} else if (("Core.Text".equals(type)) || ("Core.Variant".equals(type))) {
setAttribute(engine, element, attribute, object.stringValue(), rule);
} else if ("Core.Date".equals(type)) {
setAttribute(engine, element, attribute, object.dateValue(), rule);
} else if ("Core.Long".equals(type)) {
setAttribute(engine, element, attribute, object.longValue(), rule);
} else if ("Core.OtherElement".equals(type)) {
long qId = getOtherElemetQualifierId(attribute);
String s = object.stringValue();
if ((s != null) && (s.length() > 0)) {
Element element2 = engine.getElement(s.trim(), qId);
if (element2 == null) {
Qualifier qualifier = engine.getQualifier(qId);
Attribute name = engine.getAttribute(qualifier.getAttributeForName());
if (name == null)
return;
element2 = engine.createElement(qId);
setAttribute(engine, element2, name, s, rule);
}
setAttribute(engine, element, attribute, element2.getId(), rule);
}
} else {
setAttribute(engine, element, attribute, object.getValue(), rule);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations