Search in sources :

Example 1 with BorderAndPadding

use of com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.BorderAndPadding in project servoy-client by Servoy.

the class SortableCellViewHeader method setWidth.

public void setWidth(int width) {
    int borderWidth = 0;
    Iterator<IPersist> it2 = cellview.getAllObjects();
    while (it2.hasNext()) {
        IPersist element = it2.next();
        if (id.equals(ComponentFactory.getWebID(form, element))) {
            GraphicalComponent gc = (GraphicalComponent) view.labelsFor.get(((ISupportName) element).getName());
            if (gc != null) {
                TextualStyle styleObj = new TextualStyle();
                BorderAndPadding ins = TemplateGenerator.applyBaseComponentProperties(gc, view.fc.getForm(), styleObj, (Insets) TemplateGenerator.DEFAULT_LABEL_PADDING.clone(), null, application);
                if (ins.border != null)
                    borderWidth = ins.border.left + ins.border.right;
            }
        }
    }
    int headerPadding = TemplateGenerator.SORTABLE_HEADER_PADDING;
    // If there is no label-for, we leave place for the default border placed at the right of headers.
    if (view.labelsFor.size() == 0) {
        int extraWidth = TemplateGenerator.NO_LABELFOR_DEFAULT_BORDER_WIDTH;
        String headerBorder = view.getHeaderBorder();
        if (headerBorder != null) {
            Properties properties = new Properties();
            Insets borderIns = ComponentFactoryHelper.createBorderCSSProperties(headerBorder, properties);
            extraWidth = borderIns.left + borderIns.right;
            headerPadding = 0;
        }
        borderWidth += extraWidth;
    }
    // we have only left padding
    int clientWidth = width - headerPadding - borderWidth;
    // if we have grid_style for the header, then don't change the header width
    this.width = (view.labelsFor.size() == 0 && view.getHeaderBorder() != null) ? width : clientWidth;
    StyleAppendingModifier widthStyleModifier = new StyleAppendingModifier(new Model<String>() {

        @Override
        public String getObject() {
            // $NON-NLS-1$//$NON-NLS-2$
            return "width: " + SortableCellViewHeader.this.width + "px";
        }
    });
    add(widthStyleModifier);
    headerColumnTable.add(widthStyleModifier);
    labelResolver.setWidth(clientWidth - SortableCellViewHeader.ARROW_WIDTH);
    getStylePropertyChanges().setChanged();
}
Also used : Insets(java.awt.Insets) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ISupportName(com.servoy.j2db.persistence.ISupportName) BorderAndPadding(com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.BorderAndPadding) Properties(java.util.Properties) TextualStyle(com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle) IPersist(com.servoy.j2db.persistence.IPersist)

Aggregations

GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)1 IPersist (com.servoy.j2db.persistence.IPersist)1 ISupportName (com.servoy.j2db.persistence.ISupportName)1 BorderAndPadding (com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.BorderAndPadding)1 TextualStyle (com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle)1 Insets (java.awt.Insets)1 Properties (java.util.Properties)1