Search in sources :

Example 6 with CalculateInfo

use of com.ramussoft.common.CalculateInfo in project ramus by Vitaliy-Yakovchuk.

the class FormulaCommand method undo.

@Override
public void undo(IEngine engine) {
    CalculateInfo oldInfo = this.oldInfo;
    if (oldInfo == null) {
        oldInfo = new CalculateInfo(newInfo.getElementId(), newInfo.getAttributeId(), null);
        engine.setCalculateInfo(oldInfo);
    } else
        engine.setCalculateInfo(oldInfo);
    FormulaEvent event = new FormulaEvent(this.engine, true, newInfo, oldInfo);
    this.engine.formulaChanged(event);
}
Also used : CalculateInfo(com.ramussoft.common.CalculateInfo) FormulaEvent(com.ramussoft.common.event.FormulaEvent)

Example 7 with CalculateInfo

use of com.ramussoft.common.CalculateInfo in project ramus by Vitaliy-Yakovchuk.

the class EvalPlugin method getElementsDeleteStatus.

@Override
public DeleteStatus getElementsDeleteStatus(long[] elementIds, IEngine engine) {
    if (elementIds.length == 0)
        return null;
    Qualifier qualifier = engine.getQualifier(engine.getQualifierIdForElement(elementIds[0]));
    StringBuffer sb = new StringBuffer();
    List<MetaValue> list = new ArrayList<MetaValue>();
    for (long elementId : elementIds) for (Attribute attr : qualifier.getAttributes()) {
        for (CalculateInfo info : engine.getDependences(elementId, attr.getId(), false)) if (info.getElementId() != elementId) {
            MetaValue value = new MetaValue(info.getElementId(), info.getAttributeId());
            if (list.indexOf(value) < 0) {
                list.add(value);
                sb.append("<tr>");
                Element element = engine.getElement(info.getElementId());
                Qualifier qualifier2 = qualifier;
                if (element.getQualifierId() != qualifier.getId()) {
                    qualifier2 = engine.getQualifier(element.getQualifierId());
                }
                Attribute attribute = engine.getAttribute(info.getAttributeId());
                sb.append("<td>");
                sb.append(qualifier2.getName());
                sb.append("</td>");
                sb.append("<td>");
                sb.append(element.getName());
                sb.append("</td>");
                sb.append("<td>");
                sb.append(attribute.getName());
                sb.append("</td>");
                sb.append("</tr>");
            }
        }
    }
    String string = sb.toString();
    if (string.equals(""))
        return null;
    sb = new StringBuffer();
    sb.append("{Eval.Function.Warning}");
    sb.append("<br>");
    sb.append("<table>");
    sb.append("<tr><td><b>{OtherElement.Qualifier}</b></td><td><b>{AttributeType.Core.OtherElement}</b></td><td><b>{OtherElement.Attribute}</b></td></tr>");
    sb.append(string);
    sb.append("</table>");
    DeleteStatus status = new DeleteStatus();
    status.setDelete(Delete.WARNING);
    status.setPluginName("Core");
    status.setPluginAnswer(sb.toString());
    return status;
}
Also used : MetaValue(com.ramussoft.eval.MetaValue) Attribute(com.ramussoft.common.Attribute) CalculateInfo(com.ramussoft.common.CalculateInfo) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) Qualifier(com.ramussoft.common.Qualifier) DeleteStatus(com.ramussoft.common.DeleteStatus)

Example 8 with CalculateInfo

use of com.ramussoft.common.CalculateInfo in project ramus by Vitaliy-Yakovchuk.

the class EvalPlugin method removeAttributeFromCalculateInfo.

private void removeAttributeFromCalculateInfo(final Engine engine, final Element element, final Attribute attribute) {
    for (CalculateInfo info : engine.getDependences(element.getId(), attribute.getId(), false)) {
        try {
            Eval eval = new Eval(info.getFormula());
            if (eval.replaceValueNames(new Replacementable() {

                private String value = Util.ELEMENT_PREFIX + element.getId() + Util.ATTRIBUTE_PREFIX + attribute.getId();

                @Override
                public String getNewName(String oldName) {
                    if (oldName.equals(value))
                        return "NULL";
                    return null;
                }
            })) {
                info.setFormula(eval.toString());
                engine.setCalculateInfo(info);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : CalculateInfo(com.ramussoft.common.CalculateInfo) Replacementable(com.ramussoft.eval.Replacementable) Eval(com.ramussoft.eval.Eval) SQLException(java.sql.SQLException)

Aggregations

CalculateInfo (com.ramussoft.common.CalculateInfo)8 Eval (com.ramussoft.eval.Eval)4 Attribute (com.ramussoft.common.Attribute)3 Element (com.ramussoft.common.Element)3 Qualifier (com.ramussoft.common.Qualifier)3 FormulaEvent (com.ramussoft.common.event.FormulaEvent)3 MetaValue (com.ramussoft.eval.MetaValue)3 Replacementable (com.ramussoft.eval.Replacementable)3 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 AttributeType (com.ramussoft.common.AttributeType)1 DeleteStatus (com.ramussoft.common.DeleteStatus)1 Engine (com.ramussoft.common.Engine)1 IEngine (com.ramussoft.common.IEngine)1 AttributeEvent (com.ramussoft.common.event.AttributeEvent)1 ElementAdapter (com.ramussoft.common.event.ElementAdapter)1 ElementAttributeListener (com.ramussoft.common.event.ElementAttributeListener)1 ElementEvent (com.ramussoft.common.event.ElementEvent)1 FormulaListener (com.ramussoft.common.event.FormulaListener)1 QualifierAdapter (com.ramussoft.common.event.QualifierAdapter)1