Package org.apache.myfaces.tobago.component

Examples of org.apache.myfaces.tobago.component.UIGridLayout


  }


  public int calculateLayoutWidth(
      FacesContext facesContext, UIComponent component, boolean minimum) {
    UIGridLayout layout = (UIGridLayout) UILayout.getLayout(component);
    final List<UIGridLayout.Row> rows = layout.ensureRows();
    UIGridLayout.Row row = rows.get(0);


    LayoutTokens layoutTokens = layout.getColumnLayout();

    if (layoutTokens == null && !minimum && LOG.isDebugEnabled()) {
      LOG.debug("No rowLayout found using " + (minimum ? "'minimum'" : "'fixed'")
          + " for all " + rows.size() + " rows of "
          + layout.getClientId(facesContext) + " !");
    }

    if (row.getColumns() != layoutTokens.getSize()) {
      LOG.warn("Unbalanced layout: rows.size()=" + rows.size()
          + " != layoutTokens.length=" + layoutTokens.getSize()
          + " columnLayout='" + layoutTokens + "'"
          + " (clientId='" + layout.getClientId(facesContext) + "')");
      layoutTokens.ensureSize(row.getColumns(), new FixedLayoutToken());
    }

    int size = Math.min(rows.size(), layoutTokens.getSize());

    int width = 0;
    width += getMarginAsInt(layout.getMarginLeft());
    width += getMarginAsInt(layout.getMarginRight());
    boolean first = true;
    for (int i = 0; i < size; i++) {
      if (!columnIsRendered(rows,  i)) {
        continue;
      }
View Full Code Here


  public void encodeChildrenOfComponent(FacesContext facesContext, UIComponent component)
      throws IOException {
    // encode table with component's children

    UIGridLayout layout =  (UIGridLayout) UILayout.getLayout(component);
    HtmlRendererUtil.prepareRender(facesContext, layout);

    layoutEnd(facesContext, layout);
    layoutMargins(layout);

    final Map attributes = layout.getAttributes();
    List columnWidths =  (List) attributes.get(ATTR_WIDTH_LIST);


    TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
    writer.startElement(HtmlConstants.TABLE, layout);
    writer.writeAttributeFromComponent(HtmlAttributes.BORDER, ATTR_BORDER);
    writer.writeClassAttribute();
    writer.writeStyleAttribute();
    writer.writeAttribute(HtmlAttributes.CELLSPACING, 0);
    writer.writeAttribute(HtmlAttributes.CELLPADDING, 0);
    writer.writeAttribute(HtmlAttributes.SUMMARY, "", false);

    boolean first = true;
    if (columnWidths != null) {
      writer.startElement(HtmlConstants.COLGROUP, null);
      for (int i = 0; i < columnWidths.size(); i++) {
        int cellWidth = ((Integer) columnWidths.get(i)).intValue();
        if (cellWidth != LayoutInfo.HIDE) {
          cellWidth += getCellPadding(facesContext, layout, first);
          first = false;
          writer.startElement(HtmlConstants.COL, null);
          writer.writeAttribute(HtmlAttributes.WIDTH, cellWidth);
          writer.endElement(HtmlConstants.COL);
        }
      }
      writer.endElement(HtmlConstants.COLGROUP);
    }


    List<UIGridLayout.Row> rows = layout.ensureRows();
    boolean firstRenderedRow = true;
    for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) {
      UIGridLayout.Row row = rows.get(rowIndex);
      if (!row.isHidden()) {
        writer.startElement(HtmlConstants.TR, null);

        List cells = row.getElements();
        boolean firstRenderedColum = true;
        for (int columnIndex = 0; columnIndex < cells.size(); columnIndex++) {
          boolean hide = false;

          if (columnWidths != null) {
            Integer columWidth = ((Integer) columnWidths.get(columnIndex));
            hide = columWidth.intValue() == LayoutInfo.HIDE;
          }
          if (!hide) {

            Object object = cells.get(columnIndex);
            if (object.toString().equals(UIGridLayout.USED)) {
              firstRenderedColum = false;
              continue; // ignore the markers UIGridLayout.Used
            } else if (object.equals(UIGridLayout.FREE)) {
              if (LOG.isWarnEnabled() && !layout.isIgnoreFree()) {
                LOG.warn("There are free blocks in the layout: id='"
                    + layout.getClientId(facesContext)
                    + "'");
              }
              firstRenderedColum = false;
              continue;
            }
            UIComponent cell = (UIComponent) object;


            int spanX = UIGridLayout.getSpanX(cell);
            int spanY = UIGridLayout.getSpanY(cell);
            StyleClasses classes = StyleClasses.ensureStyleClassesCopy(layout);
            if (firstRenderedRow) {
              classes.addClass("gridLayout", "first-row"); // XXX not a standard compliant name
            }
            if (firstRenderedColum) {
              classes.addClass("gridLayout", "first-column"); // XXX not a standard compliant name
            }

            int cellWidth = -1;
            if (columnWidths != null) {
              cellWidth = 0;
              for (int i = columnIndex;
                   i < columnIndex + spanX && i < columnWidths.size(); i++) {
                cellWidth += ((Integer) columnWidths.get(i)).intValue()
                    + getCellPadding(facesContext, layout, firstRenderedColum);
                if (firstRenderedColum) {
                  firstRenderedColum = false;
                }
              }
            }


            int cellHeight = -1;
            try {
              Integer layoutHeight = LayoutUtil.getLayoutHeight(cell);
              if (layoutHeight != null) {
                cellHeight = layoutHeight.intValue();
              }
            } catch (Exception e) {
              // ignore
            } // ignore, use 0

            int topPadding = getCellPadding(facesContext, layout, firstRenderedRow);
            String cellStyle =
                (cellWidth != -1 ? "width: " + cellWidth + "px;" : "")
                + (cellHeight != -1 ? " height: " + (cellHeight + topPadding) + "px;" : "");
            cellStyle += getOverflow(cell);


            writer.startElement(HtmlConstants.TD, null);
            writer.writeClassAttribute("tobago-gridLayout-cell-td");
            writer.writeAttribute(HtmlAttributes.STYLE, cellStyle, false);
            if (spanX > 1) {
              writer.writeAttribute(HtmlAttributes.COLSPAN, spanX);
            }
            if (spanY > 1) {
              writer.writeAttribute(HtmlAttributes.ROWSPAN, spanY);
            }

            writer.flush();

            if (ComponentUtil.getAttribute(layout, ATTR_CELLSPACING) != null) {
              cellStyle += " padding: " + getCellSpacing(facesContext, layout) + "px;";
            }

            writer.startElement(HtmlConstants.DIV, null);
            writer.writeClassAttribute(classes);
            writer.writeAttribute(HtmlAttributes.STYLE, cellStyle, false);
            writer.flush();
            RenderUtil.encode(facesContext, cell);

            writer.endElement(HtmlConstants.DIV);
            writer.endElement(HtmlConstants.TD);

            firstRenderedColum = false;

            HtmlRendererUtil.removeStyleClasses(cell);

          }
        }

        writer.endElement(HtmlConstants.TR);
        firstRenderedRow = false;
      }
    }
    writer.endElement(HtmlConstants.TABLE);

    if (TobagoConfig.getInstance(facesContext).isFixLayoutTransparency()) {
      for (UIComponent child : (List<UIComponent>) layout.getParent().getChildren()) {
        if (child instanceof UIHiddenInput) {
          RenderUtil.encode(facesContext, child);
        }
      }
    }
View Full Code Here

  private void layoutEnd(FacesContext facesContext, UIComponent component) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("doLayout end");
    }
    UIGridLayout layout = (UIGridLayout) component;
    final Map attributes = layout.getParent().getAttributes();


    boolean needVerticalScroolbar = false;
    Integer innerHeight =
          (Integer) attributes.get(ATTR_INNER_HEIGHT);
    if (innerHeight != null && innerHeight.intValue() > 0) {
      int value = innerHeight.intValue();
      int minimum = calculateLayoutHeight(facesContext, layout.getParent(), true);
      if (minimum > value) {
        value = minimum;
        needVerticalScroolbar = true;
      }
      layoutHeight(Integer.valueOf(value), layout, facesContext);
View Full Code Here

  }

  public int getComponentExtraWidth(FacesContext facesContext,
      UIComponent component) {
    int extra = 0;
    UIGridLayout layout = (UIGridLayout) component;

    extra += getMarginAsInt(layout.getMarginRight());
    extra += getMarginAsInt(layout.getMarginLeft());

    return extra;
  }
View Full Code Here

  }

  public int getComponentExtraHeight(FacesContext facesContext,
      UIComponent component) {
    int extra = 0;
    UIGridLayout layout = (UIGridLayout) component;

    extra += getMarginAsInt(layout.getMarginTop());
    extra += getMarginAsInt(layout.getMarginBottom());
    return extra;
  }
View Full Code Here

    // create popup
    final String popupId = linkId != null ? linkId + "popup" : facesContext.getViewRoot().createUniqueId();
    final UIPopup popup = (UIPopup) CreateComponentUtils.createComponent(
        facesContext, UIPopup.COMPONENT_TYPE, RendererTypes.POPUP, popupId);
    final UIGridLayout layoutOfPopup = (UIGridLayout) CreateComponentUtils.createComponent(
        facesContext, UIGridLayout.COMPONENT_TYPE, RendererTypes.GRID_LAYOUT, "layoutPopup");
    layoutOfPopup.setColumns("auto");
    layoutOfPopup.setRows("auto");
    popup.getFacets().put(Facets.LAYOUT, layoutOfPopup);
    popup.getAttributes().put(Attributes.Z_INDEX, 10);
    picker.getFacets().put(Facets.POPUP, popup);
    picker.onComponentPopulated(facesContext, parent);
    popup.setRendered(false);
    popup.onComponentPopulated(facesContext, picker);

    final ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
    final ELContext elContext = facesContext.getELContext();
    popup.setValueExpression(Attributes.LEFT, expressionFactory.createValueExpression(
        elContext, "#{tobagoContext.actionPosition.right.pixel + 5}", Object.class));
    popup.setValueExpression(Attributes.TOP, expressionFactory.createValueExpression(
        elContext, "#{tobagoContext.actionPosition.top.pixel}", Object.class));

    final UIBox box = (UIBox) CreateComponentUtils.createComponent(
        facesContext, UIBox.COMPONENT_TYPE, RendererTypes.BOX, "box");
    popup.getChildren().add(box);
    box.setValueExpression(Attributes.LABEL, expressionFactory.createValueExpression(
        elContext, "#{tobagoContext.resourceBundle.datePickerTitle}", String.class));
    final UIGridLayout layoutOfBox = (UIGridLayout) CreateComponentUtils.createComponent(
        facesContext, UIGridLayout.COMPONENT_TYPE, RendererTypes.GRID_LAYOUT, "layout");
    box.getFacets().put(Facets.LAYOUT, layoutOfBox);
    layoutOfBox.setRows("*;auto;auto");

    final UICalendar calendar = (UICalendar) CreateComponentUtils.createComponent(
        facesContext, UICalendar.COMPONENT_TYPE, RendererTypes.CALENDAR, "calendar");
    box.getChildren().add(calendar);

     // fixme: should work automatically from the layout manager
    final Measure width = getResourceManager().getThemeMeasure(facesContext, calendar, "minimumWidth");
    layoutOfBox.setColumns(width.serialize());

    // add time input
    final UIPanel timePanel = (UIPanel) CreateComponentUtils.createComponent(
        facesContext, UIPanel.COMPONENT_TYPE, RendererTypes.PANEL, "timePanel");
    box.getChildren().add(timePanel);
    final UIGridLayout layoutOfTime = (UIGridLayout) CreateComponentUtils.createComponent(
        facesContext, UIGridLayout.COMPONENT_TYPE, RendererTypes.GRID_LAYOUT, "timePanelLayout");
    timePanel.getFacets().put(Facets.LAYOUT, layoutOfTime);
    layoutOfTime.setColumns("1*;auto;1*");
    final UIPanel cell1 = (UIPanel) CreateComponentUtils.createComponent(
        facesContext, UIPanel.COMPONENT_TYPE, RendererTypes.PANEL, "cell1");
    cell1.onComponentPopulated(facesContext, parent);
    timePanel.getChildren().add(cell1);

    final UITime time = (UITime) CreateComponentUtils.createComponent(
        facesContext, UITime.COMPONENT_TYPE, RendererTypes.TIME, "time");
    timePanel.getChildren().add(time);

    final UIPanel cell2 = (UIPanel) CreateComponentUtils.createComponent(
        facesContext, UIPanel.COMPONENT_TYPE, RendererTypes.PANEL, "cell2");
    cell2.onComponentPopulated(facesContext, parent);
    timePanel.getChildren().add(cell2);

    timePanel.onComponentPopulated(facesContext, parent);


    final UIPanel buttonPanel = (UIPanel) CreateComponentUtils.createComponent(
        facesContext, UIPanel.COMPONENT_TYPE, RendererTypes.PANEL, "buttonPanel");
    final UIGridLayout layoutOfButtons = (UIGridLayout) CreateComponentUtils.createComponent(
        facesContext, UIGridLayout.COMPONENT_TYPE, RendererTypes.GRID_LAYOUT, "buttonPanelLayout");
    buttonPanel.setLayoutManager(layoutOfButtons);
    layoutOfButtons.setColumns("*;*");
    layoutOfButtons.setRows("auto");

    box.getChildren().add(buttonPanel);
    box.onComponentPopulated(facesContext, parent);

    final UIButton okButton = (UIButton) CreateComponentUtils.createComponent(
View Full Code Here

    }
  }

  private void addGridLayout(
      final FaceletContext faceletContext, final UIComponent panel, final Application application) {
    final UIGridLayout gridLayout = (UIGridLayout) application.createComponent(UIGridLayout.COMPONENT_TYPE);
    gridLayout.setRendererType(RendererTypes.GRID_LAYOUT);
    if (labelWidthAttribute != null) {
      String columns = getColumns(labelWidthAttribute.getValue(faceletContext));
      if (!LayoutUtils.checkTokens(columns)) {
        LOG.warn("Illegal value for columns = \"" + columns + "\" replacing with default: \"" + DEFAULT_COLUMNS + "\"");
        columns = DEFAULT_COLUMNS;
      }
      gridLayout.setColumns(columns);
    } else {
      gridLayout.setColumns(getColumns("auto"));
    }
    gridLayout.setRows(getRows());
    gridLayout.setId(panel.getId() + "_tx_layout");
    if (gridLayout instanceof OnComponentCreated) {
      ((OnComponentCreated) gridLayout).onComponentCreated(faceletContext.getFacesContext(), panel);
    }
    panel.getFacets().put(Facets.LAYOUT, gridLayout);
    if (gridLayout instanceof OnComponentPopulated) {
View Full Code Here

    // create popup
    final String popupId = linkId != null ? linkId + "popup" : facesContext.getViewRoot().createUniqueId();
    final UIPopup popup = (UIPopup) CreateComponentUtils.createComponent(
        facesContext, UIPopup.COMPONENT_TYPE, RendererTypes.POPUP, popupId);
    final UIGridLayout layoutOfPopup = (UIGridLayout) CreateComponentUtils.createComponent(
        facesContext, UIGridLayout.COMPONENT_TYPE, RendererTypes.GRID_LAYOUT, "layoutPopup");
    layoutOfPopup.setColumns("auto");
    layoutOfPopup.setRows("auto");
    popup.getFacets().put(Facets.LAYOUT, layoutOfPopup);
    popup.getAttributes().put(Attributes.Z_INDEX, 10);
    picker.getFacets().put(Facets.POPUP, popup);
    picker.onComponentPopulated(facesContext, parent);
    popup.setRendered(false);
    popup.onComponentPopulated(facesContext, picker);

    final ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
    final ELContext elContext = facesContext.getELContext();
    popup.setValueExpression(Attributes.LEFT, expressionFactory.createValueExpression(
        elContext, "#{tobagoContext.actionPosition.right.pixel + 5}", Object.class));
    popup.setValueExpression(Attributes.TOP, expressionFactory.createValueExpression(
        elContext, "#{tobagoContext.actionPosition.top.pixel}", Object.class));

    final UIBox box = (UIBox) CreateComponentUtils.createComponent(
        facesContext, UIBox.COMPONENT_TYPE, RendererTypes.BOX, "box");
    popup.getChildren().add(box);
    box.setValueExpression(Attributes.LABEL, expressionFactory.createValueExpression(
        elContext, "#{tobagoContext.resourceBundle.datePickerTitle}", String.class));
    final UIGridLayout layoutOfBox = (UIGridLayout) CreateComponentUtils.createComponent(
        facesContext, UIGridLayout.COMPONENT_TYPE, RendererTypes.GRID_LAYOUT, "layout");
    box.getFacets().put(Facets.LAYOUT, layoutOfBox);
    layoutOfBox.setRows("*;auto;auto");

    final UICalendar calendar = (UICalendar) CreateComponentUtils.createComponent(
        facesContext, UICalendar.COMPONENT_TYPE, RendererTypes.CALENDAR, "calendar");
    box.getChildren().add(calendar);

     // fixme: should work automatically from the layout manager
    final Measure width = getResourceManager().getThemeMeasure(facesContext, calendar, "minimumWidth");
    layoutOfBox.setColumns(width.serialize());

    // add time input
    final UIPanel timePanel = (UIPanel) CreateComponentUtils.createComponent(
        facesContext, UIPanel.COMPONENT_TYPE, RendererTypes.PANEL, "timePanel");
    box.getChildren().add(timePanel);
    final UIGridLayout layoutOfTime = (UIGridLayout) CreateComponentUtils.createComponent(
        facesContext, UIGridLayout.COMPONENT_TYPE, RendererTypes.GRID_LAYOUT, "timePanelLayout");
    timePanel.getFacets().put(Facets.LAYOUT, layoutOfTime);
    layoutOfTime.setColumns("1*;auto;1*");
    final UIPanel cell1 = (UIPanel) CreateComponentUtils.createComponent(
        facesContext, UIPanel.COMPONENT_TYPE, RendererTypes.PANEL, "cell1");
    cell1.onComponentPopulated(facesContext, parent);
    timePanel.getChildren().add(cell1);

    final UITime time = (UITime) CreateComponentUtils.createComponent(
        facesContext, UITime.COMPONENT_TYPE, RendererTypes.TIME, "time");
    timePanel.getChildren().add(time);

    final UIPanel cell2 = (UIPanel) CreateComponentUtils.createComponent(
        facesContext, UIPanel.COMPONENT_TYPE, RendererTypes.PANEL, "cell2");
    cell2.onComponentPopulated(facesContext, parent);
    timePanel.getChildren().add(cell2);

    timePanel.onComponentPopulated(facesContext, parent);


    final UIPanel buttonPanel = (UIPanel) CreateComponentUtils.createComponent(
        facesContext, UIPanel.COMPONENT_TYPE, RendererTypes.PANEL, "buttonPanel");
    final UIGridLayout layoutOfButtons = (UIGridLayout) CreateComponentUtils.createComponent(
        facesContext, UIGridLayout.COMPONENT_TYPE, RendererTypes.GRID_LAYOUT, "buttonPanelLayout");
    buttonPanel.setLayoutManager(layoutOfButtons);
    layoutOfButtons.setColumns("*;*");
    layoutOfButtons.setRows("auto");

    box.getChildren().add(buttonPanel);
    box.onComponentPopulated(facesContext, parent);

    final UIButton okButton = (UIButton) CreateComponentUtils.createComponent(
View Full Code Here

  }

  @Override
  protected void setProperties(final UIComponent uiComponent) {
    super.setProperties(uiComponent);
    final UIGridLayout component = (UIGridLayout) uiComponent;
    final FacesContext context = FacesContext.getCurrentInstance();
    final Application application = context.getApplication();
    if (markup != null) {
      if (!markup.isLiteralText()) {
        component.setValueExpression("markup", markup);
      } else {
        component.setMarkup(org.apache.myfaces.tobago.context.Markup.valueOf(markup.getExpressionString()));
      }
    }
    if (marginLeft != null) {
      if (!marginLeft.isLiteralText()) {
        component.setValueExpression("marginLeft", marginLeft);
      } else {
        component.setMarginLeft(org.apache.myfaces.tobago.layout.Measure.valueOf(marginLeft.getExpressionString()));
      }
    }
    if (marginTop != null) {
      if (!marginTop.isLiteralText()) {
        component.setValueExpression("marginTop", marginTop);
      } else {
        component.setMarginTop(org.apache.myfaces.tobago.layout.Measure.valueOf(marginTop.getExpressionString()));
      }
    }
    if (marginRight != null) {
      if (!marginRight.isLiteralText()) {
        component.setValueExpression("marginRight", marginRight);
      } else {
        component.setMarginRight(org.apache.myfaces.tobago.layout.Measure.valueOf(marginRight.getExpressionString()));
      }
    }
    if (columns != null) {
      component.setValueExpression("columns", columns);
    }

    if (cellspacing != null) {
      if (!cellspacing.isLiteralText()) {
        component.setValueExpression("cellspacing", cellspacing);
      } else {
        component.setCellspacing(org.apache.myfaces.tobago.layout.Measure.valueOf(cellspacing.getExpressionString()));
      }
    }
    if (rows != null) {
      component.setValueExpression("rows", rows);
    }

    if (marginBottom != null) {
      if (!marginBottom.isLiteralText()) {
        component.setValueExpression("marginBottom", marginBottom);
      } else {
        component.setMarginBottom(org.apache.myfaces.tobago.layout.Measure.valueOf(marginBottom.getExpressionString()));
      }
    }
    if (rowSpacing != null) {
      if (!rowSpacing.isLiteralText()) {
        component.setValueExpression("rowSpacing", rowSpacing);
      } else {
        component.setRowSpacing(org.apache.myfaces.tobago.layout.Measure.valueOf(rowSpacing.getExpressionString()));
      }
    }
    if (margin != null) {
      if (!margin.isLiteralText()) {
        component.setValueExpression("margin", margin);
      } else {
        component.setMargin(org.apache.myfaces.tobago.layout.Measure.valueOf(margin.getExpressionString()));
      }
    }
    if (border != null) {
      component.setValueExpression("border", border);
    }

    if (columnSpacing != null) {
      if (!columnSpacing.isLiteralText()) {
        component.setValueExpression("columnSpacing", columnSpacing);
      } else {
        component.setColumnSpacing(org.apache.myfaces.tobago.layout.Measure.valueOf(columnSpacing.getExpressionString()));
      }
    }
  }
View Full Code Here

      }
    }
  }

  private void addGridLayout(FaceletContext faceletContext, UIComponent panel, final Application application) {
    final UIGridLayout gridLayout = (UIGridLayout) application.createComponent(UIGridLayout.COMPONENT_TYPE);
    gridLayout.setRendererType(RendererTypes.GRID_LAYOUT);
    if (labelWidthAttribute != null) {
      String columns = getColumns(labelWidthAttribute.getValue(faceletContext));
      if (!LayoutUtils.checkTokens(columns)) {
        LOG.warn("Illegal value for columns = \"" + columns + "\" replacing with default: \"" + DEFAULT_COLUMNS + "\"");
        columns = DEFAULT_COLUMNS;
      }
      gridLayout.setColumns(columns);
    } else {
      gridLayout.setColumns(getColumns("auto"));
    }
    gridLayout.setRows(getRows());
    gridLayout.setId("_tx_" + faceletContext.generateUniqueId("layout"));
    if (gridLayout instanceof OnComponentCreated) {
      ((OnComponentCreated) gridLayout).onComponentCreated(faceletContext.getFacesContext(), panel);
    }
    panel.getFacets().put(Facets.LAYOUT, gridLayout);
    if (gridLayout instanceof OnComponentPopulated) {
View Full Code Here

TOP

Related Classes of org.apache.myfaces.tobago.component.UIGridLayout

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.