Package reportgen.math

Examples of reportgen.math.MathExpression


    @Override
    public Element toXML() {
        Element root = new Element(ROWTAG);
        for(Object value: values) {
            MathExpression val = null;
            if(value.getClass().equals(Long.class)) {
                 val = new MathExpressionConstValueLong((Long)value, context);

            } else if(value.getClass().equals(Double.class)) {
                val = new MathExpressionConstValueDouble((Double)value, context);

            } else if(value.getClass().equals(Date.class)) {
                val = new MathExpressionConstValueDate((Date)value, context);

            } else if(value.getClass().equals(String.class)) {
                val = new MathExpressionConstValueString((String)value, context);

            } else if(value.getClass().equals(Boolean.class)) {
                val = new MathExpressionConstValueBoolean((Boolean)value, context);
               
            } else {
                throw new RuntimeException("Сохранение значения '" + value.toString() +
                        "' как результата подзапроса не поддерживается");
            }
            root.addContent(val.toXML());
        }
        return root;
    }
View Full Code Here


     * @return
     */
    @Override
    public MathExpressionConditionUnaryExist getValue()  {
        if(operandPanel != null) {
            MathExpression value = operandPanel.getValue();
            if(value == null) {
                return null;
            }
            me.setOperand((MathExpressionOperand) value);
        }
View Full Code Here

    }

    @Override
    public MathExpressionConditionUnaryNull getValue()  {
        if(operandPanel != null) {
            MathExpression value = operandPanel.getValue();
            if(value == null) {
                return null;
            }
            me.setOperand((MathExpressionOperand) value);
        }
View Full Code Here

        MathExpressionComplex parExp = getParent(path);
        if(parExp == null) {
            Message.warning(this, "В данный элемент выражения нельзя вставить новый элемент");
            return;
        }
        MathExpression selection = getSelection(path);
        if(selection == parExp) {
            selection = null;
        }

        CreateMathExpressionDlg dlg = new CreateMathExpressionDlg(parent,
                parExp.getLocalContext(), parExp);

        dlg.setVisible(true);
        if(dlg.isOK()) {
            MathExpression expr = dlg.getValue();

            try {
                if (selection == null) {
                    parExp.getChildren().add(expr);
                } else {
View Full Code Here

        TreePath path = tree.getSelectionPath();
        if (path != null) {
            TreePath parentPath = path.getParentPath();
            if (parentPath != null) {
                MathExpressionComplex parentExp = (MathExpressionComplex) parentPath.getLastPathComponent();
                MathExpression child = (MathExpression) path.getLastPathComponent();
                parentExp.getChildren().remove(child);
                tree.setModel(new TreeExpressionModel(me));
                tree.expandPath(parentPath);
                tree.setSelectionPath(parentPath);
View Full Code Here

            if(path == null) {
                return;
            }
        }

        MathExpression selection = getSelection(path);
        MathExpressionComplex parExp = getParent(path);
        if(selection == null) {
            return;
        }
        EditMathExpressionDlg dlg = new EditMathExpressionDlg(parent, selection, parExp);
        dlg.setVisible(true);
        if(dlg.isOK())  {
            MathExpression value = dlg.getValue();
            if(value != selection) {
                try {
                    parExp.getChildren().insertBefore(selection, value);
                    parExp.getChildren().remove(selection);
                } catch (ReportException ex) {
View Full Code Here

        TreePath parentPath = path.getParentPath();
        if (parentPath == null) {
            return;
        }
        MathExpressionComplex parentExp = (MathExpressionComplex) parentPath.getLastPathComponent();
        MathExpression child = (MathExpression) path.getLastPathComponent();
        int index = parentExp.getChildren().indexOf(child);

        if (up) {
            parentExp.getChildren().moveUp(index);
        } else {
View Full Code Here

     */
    protected LinkedList<MathExpression> buildAvailiableChildren() throws ReportException {
        LinkedList<MathExpression> list = new LinkedList<MathExpression>();

        for(int i=0; i< children.size(); i++) {
            MathExpression child = children.get(i);
            if(!(child instanceof MathExpressionConditionBinary)
                    && !(child instanceof MathExpressionConditionUnaryNull)) {
                list.add(child);
            } else {
                MathExpression core = (MathExpression) child;

                //условие валидное, берем
                if(!core.containsMissingVariables()) {
                    list.add(child);

                //условие невалидное, а список еще пуст
                } else if(list.size() ==0) {
                    if(i+1 >= children.size()) {
                        //если список условий заканчивается, выходим
                        break;
                    }
                    //проверим и пропустим невалидный оператор условия
                    MathExpression operator = children.get(i+1);
                    if(!(operator instanceof MathExpressionOperatorRef)) {
                        throw new ReportException("В условии пропущен оператор.");
                    }
                    i++;

                //условие невалидное в списке уже есть оператор
                } else if(i+1<children.size()) {
                    //есть 2 опрератора, нужно выбрать один
                    MathExpression operator1 = list.getLast();
                    MathExpression operator2 = children.get(i+1);
                    list.removeLast();
                    //проверим что операторы
                    if(!(operator1 instanceof MathExpressionOperatorRef)
                            || !(operator2 instanceof MathExpressionOperatorRef)) {
                        throw new ReportException("В условии пропущен оператор.");
                    }
                    int priority1 = ((MathExpressionOperatorRef)operator1).getRef().getPriority();
                    int priority2 = ((MathExpressionOperatorRef)operator2).getRef().getPriority();

                    //вернем в список валидный (менее приоритетный)
                    list.add(priority1 >= priority2 ? operator2 : operator1);
                    i++;

                //условие невалидное, а список не пуст, проверим и удалим последний оператор в списке
                } else {
                    MathExpression operator = list.getLast();
                    if(!(operator instanceof MathExpressionOperatorRef)) {
                        throw new ReportException("В условии пропущен оператор.");
                    }
                    list.removeLast();
                }
View Full Code Here

        //get min priority operand
        int pos = -1;
        int priority = Integer.MAX_VALUE;
        MathExpressionOperatorRef operator = null;
        for(int j=end; j>=beg; j--) {
            MathExpression element = elem.get(j);
            if(element instanceof MathExpressionOperatorRef) {
                MathExpressionOperatorRef iOperator = (MathExpressionOperatorRef) element;
                int prior = iOperator.getRef().getPriority();
                if(prior < priority) {
                    priority = prior;
                    pos = j;
                    operator = iOperator;
                }
            }
        }

        if(pos == -1) {
            if(end == beg) {
                //it allways be operand
                stack.add(elem.get(0));
                return stack;
            }

            throw new ReportException("Выражение составлено неверно, пропущен оператор");
        }

        if(pos == 0) {
            throw new ReportException("Перед оператором '" + operator + "' должен быть операнд");
        } else if(pos+1 == elem.size()) {
            throw new ReportException("После оператора '" + operator + "' должен быть операнд");
        }

        int leftOperandPos = pos-1;
        int rightOperandPos = pos+1;
        MathExpression leftOperand = elem.get(leftOperandPos);
        MathExpression rightOperand = elem.get(rightOperandPos);

        if(!(leftOperand instanceof MathExpressionOperand)) {
            throw new ReportException("Перед оператором '" + operator + "' должен быть операнд");
        } else if (!(rightOperand instanceof MathExpressionOperand)) {
            throw new ReportException("После оператора '" + operator + "' должен быть операнд");
View Full Code Here

    /**
     *
     */
    protected final void tryOK() {
        MathExpression val = getValue();
        if(val == null) {
            Message.warning(this, "Выберите один из вариантов");
        } else {
            try {
                if(!(val instanceof MathExpressionFunction)
                        && !(val instanceof MathExpressionEmphases)) {
                    val.validate();
                }
                setDlgResult(true);
                setVisible(false);
            } catch (ReportException ex) {
                Message.warning(this, ex);
View Full Code Here

TOP

Related Classes of reportgen.math.MathExpression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.