Package com.eagerlogic.cubee.client.components.attributepanel

Source Code of com.eagerlogic.cubee.client.components.attributepanel.AttributePanelItem

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.eagerlogic.cubee.client.components.attributepanel;

import com.eagerlogic.cubee.client.components.AUserControl;
import com.eagerlogic.cubee.client.components.HBox;
import com.eagerlogic.cubee.client.components.Label;
import com.eagerlogic.cubee.client.components.Panel;
import com.eagerlogic.cubee.client.events.ClickEventArgs;
import com.eagerlogic.cubee.client.events.EventArgs;
import com.eagerlogic.cubee.client.events.IEventListener;
import com.eagerlogic.cubee.client.properties.AExpression;
import com.eagerlogic.cubee.client.properties.IntegerProperty;
import com.eagerlogic.cubee.client.properties.ext.AlignMiddleExp;
import com.eagerlogic.cubee.client.style.styles.ECursor;
import com.eagerlogic.cubee.client.style.styles.ETextOverflow;

/**
*
* @author dipacs
*/
final class AttributePanelItem extends AUserControl {
   
    private final AAttribute<?> attribute;
   
    private final Panel pnlName;
    private final Panel pnlValue;

    public AttributePanelItem(AAttribute<?> attribute) {
        this.attribute = attribute;
        this.heightProperty().set(25);
       
        HBox root = new HBox();
        this.getChildren().add(root);
       
        pnlName = new Panel();
        pnlName.widthProperty().bind(new AExpression<Integer>() {
           
            {
                bind(clientWidthProperty());
            }

            @Override
            public Integer calculate() {
                return (clientWidthProperty().get() - 10) / 2;
            }
        });
        pnlName.heightProperty().bind(heightProperty());
        root.getChildren().add(pnlName);
       
        // TODO make styleable
        Label lblName = new Label();
        lblName.textProperty().set(attribute.getName());
        lblName.widthProperty().bind(pnlName.clientWidthProperty());
        lblName.maxWidthProperty().bind(pnlName.clientWidthProperty());
        lblName.translateYProperty().bind(new AlignMiddleExp(pnlName, lblName));
        lblName.textOverflowProperty().set(ETextOverflow.ELLIPSIS);
        pnlName.getChildren().add(lblName);
       
        root.addEmptyCell(10);
       
        pnlValue = new Panel();
        pnlValue.widthProperty().bind(pnlName.widthProperty());
        pnlValue.heightProperty().bind(heightProperty());
        if (!attribute.isReadonly()) {
            pnlValue.cursorProperty().set(ECursor.POINTER);
            pnlValue.onClickEvent().addListener(new IEventListener<ClickEventArgs>() {

                @Override
                public void onFired(ClickEventArgs args) {
                    showEditor();
                }
            });
        }
        root.getChildren().add(pnlValue);
       
        showValue();
       
       
    }
   
    private void showValue() {
        pnlValue.getChildren().clear();
       
        // TODO make styleable
        Label lblValue = new Label();
        lblValue.textProperty().set(attribute.getStringValue());
        lblValue.widthProperty().bind(pnlName.clientWidthProperty());
        lblValue.maxWidthProperty().bind(pnlName.clientWidthProperty());
        lblValue.translateYProperty().bind(new AlignMiddleExp(pnlValue, lblValue));
        lblValue.textOverflowProperty().set(ETextOverflow.ELLIPSIS);
        lblValue.handlePointerProperty().set(false);
        pnlValue.getChildren().add(lblValue);
    }
   
    private void showEditor() {
        pnlValue.getChildren().clear();
       
        AAttributeEditor<?> editor = attribute.createEditor();
        editor.widthPropertyInner().bind(pnlName.clientWidthProperty());
        editor.heightPropertyInner().bind(pnlName.clientHeightProperty());
        editor.onClosedEvent().addListener(new IEventListener<EventArgs>() {

            @Override
            public void onFired(EventArgs args) {
                showValue();
            }
        });
        pnlValue.getChildren().add(editor);
    }

    @Override
    public IntegerProperty widthProperty() {
        return super.widthProperty();
    }

    @Override
    public IntegerProperty heightProperty() {
        return super.heightProperty();
    }
   
}
TOP

Related Classes of com.eagerlogic.cubee.client.components.attributepanel.AttributePanelItem

TOP
Copyright © 2018 www.massapi.com. 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.