/*
 * Copyright (c) 2008-2014 Haulmont. All rights reserved.
 * Use is subject to license terms, see http://www.cuba-platform.com/license for details.
 */
package com.haulmont.cuba.gui.components.filter.operationedit;

import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.gui.components.AbstractAction;
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.PopupButton;
import com.haulmont.cuba.gui.components.filter.Op;
import com.haulmont.cuba.gui.components.filter.condition.AbstractCondition;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;

/**
 * Operation editor for PropertyCondition. Displays popupButton component for selecting an operation.
 *
 * @author krivopustov
 * @version $Id$
 */
public class PropertyOperationEditor extends AbstractOperationEditor {

    protected ComponentsFactory componentsFactory;
    protected Messages messages;
    protected PopupButton popupButton;

    public PropertyOperationEditor(AbstractCondition condition) {
        super(condition);
    }

    @Override
    protected Component createComponent() {
        componentsFactory = AppBeans.get(ComponentsFactory.class);
        messages = AppBeans.get(Messages.NAME);
        popupButton = componentsFactory.createComponent(PopupButton.class);

        for (Op op : Op.availableOps(condition.getJavaClass())) {
            OperatorChangeAction operatorChangeAction = new OperatorChangeAction(op);
            popupButton.addAction(operatorChangeAction);
        }

        popupButton.setCaption(messages.getMessage(condition.getOperator()));

        return popupButton;
    }

    protected class OperatorChangeAction extends AbstractAction {
        protected Op op;

        public OperatorChangeAction(Op op) {
            super(op.toString());
            this.op = op;
        }

        @Override
        public void actionPerform(Component component) {
            (PropertyOperationEditor.this.condition).setOperator(op);
            popupButton.setCaption(getCaption());
        }

        @Override
        public String getCaption() {
            return messages.getMessage(op);
        }
    }
}
@@ -1691,16 +1691,81 @@
 or()));%0D
+%0A        popupButton.setStyleName(%22condition-operation-button%22);%0D
 %0A%0D%0A     

Add stylename for condition operation buttons in generic filter #PL-5119