Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.uberfire.ext.widgets.common.client.common;
 
 
 import  com.google.gwt.resources.client.ImageResource;
 import  com.google.gwt.user.client.ui.Composite;
 import  com.google.gwt.user.client.ui.FlexTable;
 import  com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
 import  com.google.gwt.user.client.ui.HTML;
 import  com.google.gwt.user.client.ui.HasHorizontalAlignment;
 import  com.google.gwt.user.client.ui.HasVerticalAlignment;
 import  com.google.gwt.user.client.ui.HasWidgets;
 import  com.google.gwt.user.client.ui.HorizontalPanel;
 import  com.google.gwt.user.client.ui.Image;
 import  com.google.gwt.user.client.ui.IsWidget;
 import  com.google.gwt.user.client.ui.Widget;

This form style class is to be extended to provide "form style" dialogs (eg in a popup).
 
 public class FormStyleLayout extends Composite implements HasWidgets {
 
     private FlexTable layout = new FlexTable();
     private FlexCellFormatter formatter = .getFlexCellFormatter();
     private int numInLayout = 0;

    
Create a new layout with a header and and icon.
 
     public FormStyleLayout( ImageResource image,
                             String title ) {
         addHeaderimage,
                    title );
 
         initWidget(  );
     }

    
Create a new layout with a header and and icon.
 
     public FormStyleLayout( Image image,
                             String title ) {
         addHeaderimage,
                    title );
 
         initWidget(  );
     }

    
This has no header
 
     public FormStyleLayout() {
         initWidget(  );
     }

    
Clears the layout table.
 
     public void clear() {
          = 0;
         this..clear();
     }

    
Add a widget to the "form"

Parameters:
lbl The label displayed in column 0
editor The Widget displayed in column 1
Returns:
Index of row created
 
     public int addAttributeString lbl,
                              IsWidget editor ) {
         int row = ;
         HTML label = new HTML( "<div class='form-field'>" + lbl + "</div>" );
         .setWidget( ,
                           0,
                           label );
         .setAlignment( ,
                                 0,
                                 HasHorizontalAlignment.ALIGN_RIGHT,
                                 HasVerticalAlignment.ALIGN_MIDDLE );
         .setWidget( ,
                           1,
                          editor );
        .setAlignment( ,
                                1,
                                HasHorizontalAlignment.ALIGN_LEFT,
                                HasVerticalAlignment.ALIGN_MIDDLE );
        ++;
        return row;
    }

    
Add a widget to the "form"

Parameters:
lbl The label displayed in column 0
editor The Widget displayed in column 1
isVisible Is the new row visible
Returns:
Index of row created
    public int addAttributeString lbl,
                             Widget editor,
                             boolean isVisible ) {
        int rowIndex = addAttributelbl,
                                     editor );
        setAttributeVisibilityrowIndex,
                                isVisible );
        return rowIndex;
    }

    
Add a widget to the "form" across an entire row

Parameters:
w The Widget displayed in column 1
Returns:
Index of row created
    public int addRow( Widget w ) {
        int row = ;
        .setWidget( ,
                          0,
                          w );
        .setColSpan( ,
                              0,
                              2 );
        ++;
        return row;
    }

    
Set the visibility of an Attribute

Parameters:
row
isVisible
    public void setAttributeVisibilityint row,
                                        boolean isVisible ) {
        .getWidget( row,
                          0 ).setVisible( isVisible );
        .getWidget( row,
                          1 ).setVisible( isVisible );
    }

    
Adds a header at the top.
    protected void addHeader( ImageResource image,
                              String title ) {
        HTML name = new HTML( "<div class='form-field'><b>" + title + "</b></div>" );
        name.setStyleName( "resource-name-Label" );
        doHeaderimage,
                  name );
    }

    
Adds a header at the top.
    protected void addHeader( Image image,
                              String title ) {
        HTML name = new HTML( "<div class='form-field'><b>" + title + "</b></div>" );
        name.setStyleName( "resource-name-Label" );
        doHeaderimage,
                  name );
    }
    private void doHeader( ImageResource imageResource,
                           Widget title ) {
        Image image;
        if ( imageResource == null ) {
            image = new Image();
        } else {
            image = new Image( imageResource );
        }
        .setWidget( 0,
                          0,
                          image );
        .setAlignment( 0,
                                0,
                                HasHorizontalAlignment.ALIGN_LEFT,
                                HasVerticalAlignment.ALIGN_MIDDLE );
        .setWidget( 0,
                          1,
                          title );
        ++;
    }
    private void doHeader( Image image,
                           Widget title ) {
        if ( image.getAltText() == null ) {
            image.setAltText( "" );
        }
        .setWidget( 0,
                          0,
                          image );
        .setAlignment( 0,
                                0,
                                HasHorizontalAlignment.ALIGN_LEFT,
                                HasVerticalAlignment.ALIGN_MIDDLE );
        .setWidget( 0,
                          1,
                          title );
        ++;
    }
    protected void addHeader( ImageResource image,
                              String title,
                              Widget titleIcon ) {
        HTML name = new HTML( "<div class='form-field'><b>" + title + "</b></div>" );
        name.setStyleName( "resource-name-Label" );
        HorizontalPanel horiz = new HorizontalPanel();
        horiz.add( name );
        horiz.add( titleIcon );
        doHeaderimage,
                  horiz );
    }
    public void setFlexTableWidgetint row,
                                    int col,
                                    Widget widget ) {
        .setWidget( row,
                          col,
                          widget );
    }
    public int getNumAttributes() {
        return ;
    }
    @Override
    public void add( Widget w ) {
        throw new UnsupportedOperationException"Use one of the addHeader(), addAttribute() or addRow() methods." );
    }
    @Override
    public Iterator<Widget> iterator() {
        return .iterator();
    }
    @Override
    public boolean remove( Widget w ) {
        throw new UnsupportedOperationException();
    }
New to GrepCode? Check out our FAQ X