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

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

/*
* 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.CollapseLabel;
import com.eagerlogic.cubee.client.components.Panel;
import com.eagerlogic.cubee.client.components.VBox;
import com.eagerlogic.cubee.client.properties.AExpression;
import com.eagerlogic.cubee.client.properties.BooleanProperty;
import com.eagerlogic.cubee.client.properties.IChangeListener;
import com.eagerlogic.cubee.client.properties.IntegerProperty;
import com.eagerlogic.cubee.client.properties.Timeline;
import com.eagerlogic.cubee.client.properties.ext.CondExp;
import com.eagerlogic.cubee.client.style.styles.Color;
import com.eagerlogic.cubee.client.style.styles.ColorBackground;

/**
*
* @author dipacs
*/
final class AttributeGroupView extends AUserControl {
   
    private final BooleanProperty collapsed = new BooleanProperty(false, false, false);
   
    private final AttributeGroup attributeGroup;
   
    private CollapseLabel collapseLabel;
    private VBox root;
    private VBox vbAttributes;
    private Panel attributesPanel;
   
    private Timeline tl;

    public AttributeGroupView(AttributeGroup attributeGroup) {
        if (attributeGroup == null) {
            throw new NullPointerException("The attributeGroup parameter can not be null.");
        }
        this.attributeGroup = attributeGroup;
       
        VBox root = new VBox();
        this.getChildren().add(root);
       
        final boolean nameVisible = attributeGroup.getName() != null;
       
        if (nameVisible) {
            // TODO set styleable
            collapseLabel = new CollapseLabel();
            collapseLabel.widthProperty().bind(this.clientWidthProperty());
            collapseLabel.textProperty().set(attributeGroup.getName());
            collapseLabel.collapsedProperty().bidirectionalBind(collapsed);
            root.getChildren().add(collapseLabel);
           
            root.addEmptyCell(2);
           
            Panel pnlSep = new Panel();
            pnlSep.widthProperty().bind(clientWidthProperty());
            // TODO set styleable
            pnlSep.heightProperty().set(1);
            // TODO set styleable
            pnlSep.backgroundProperty().set(new ColorBackground(Color.BLACK));
            root.getChildren().add(pnlSep);
           
            root.addEmptyCell(2);
        }
       
        attributesPanel = new Panel();
        attributesPanel.widthProperty().bind(new AExpression<Integer>() {
           
            {
                bind(clientWidthProperty());
            }

            @Override
            public Integer calculate() {
                return clientWidthProperty().get() - 10;
            }
        });
        attributesPanel.translateXProperty().set(10);
        root.getChildren().add(attributesPanel);
       
        vbAttributes = new VBox();
        attributesPanel.getChildren().add(vbAttributes);
       
        for (AAttribute<?> attribute : attributeGroup.getAttributes()) {
            AttributePanelItem item = new AttributePanelItem(attribute);
            item.widthProperty().bind(attributesPanel.clientWidthProperty());
            vbAttributes.getChildren().add(item);
           
        }
       
        collapsed.addChangeListener(new IChangeListener() {

            @Override
            public void onChanged(Object sender) {
                if (collapsed.get()) {
                    collapsePanel();
                } else {
                    expandPanel();
                }
            }
        });
    }
   
    private void expandPanel() {
        attributesPanel.visibleProperty().set(true);
        attributesPanel.heightProperty().set(null);
    }
   
    private void collapsePanel() {
        attributesPanel.visibleProperty().set(false);
        attributesPanel.heightProperty().set(0);
    }

    public AttributeGroup getAttributeGroup() {
        return attributeGroup;
    }

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

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

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.