Java Code Examples for com.google.gwt.user.client.ui.HTMLTable.CellFormatter#setHorizontalAlignment()

The following examples show how to use com.google.gwt.user.client.ui.HTMLTable.CellFormatter#setHorizontalAlignment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserNews.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a new row
 *
 * @param search The search value
 */
public void addRow(GWTQueryParams search) {
	int rows = table.getRowCount();

	data.put(dataIndexValue, search);

	if (!search.isShared()) {
		table.setHTML(rows, 0, " ");
	} else {
		table.setWidget(rows, 0, new Image(OKMBundleResources.INSTANCE.sharedQuery()));
	}

	table.setHTML(rows, 1, search.getQueryName());
	table.setHTML(rows, 2, "" + dataIndexValue++);
	table.setHTML(rows, 3, "");
	table.getFlexCellFormatter().setVisible(rows, 2, false);

	// The hidden column extends table to 100% width
	CellFormatter cellFormatter = table.getCellFormatter();
	cellFormatter.setWidth(rows, 0, "30px");
	cellFormatter.setHeight(rows, 0, "20px");
	cellFormatter.setHorizontalAlignment(rows, 0, HasAlignment.ALIGN_CENTER);
	cellFormatter.setVerticalAlignment(rows, 0, HasAlignment.ALIGN_MIDDLE);
	cellFormatter.setWidth(rows, 3, "100%");

	table.getRowFormatter().setStyleName(rows, "okm-userNews");
	setRowWordWarp(rows, 4, false);
}
 
Example 2
Source File: SearchSaved.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a new row
 *
 * @param search Search parameters to be added.
 */
private void addRow(GWTQueryParams search) {
	int rows = table.getRowCount();

	data.put(new Long(dataIndexValue), search);

	if (!search.isShared()) {
		table.setHTML(rows, 0, " ");
	} else {
		table.setWidget(rows, 0, new Image(OKMBundleResources.INSTANCE.sharedQuery()));
	}

	table.setHTML(rows, 1, search.getQueryName());
	table.setHTML(rows, 2, "" + dataIndexValue++);
	table.setHTML(rows, 3, "");
	table.getCellFormatter().setVisible(rows, 2, false);

	// The hidden column extends table to 100% width
	CellFormatter cellFormatter = table.getCellFormatter();
	cellFormatter.setWidth(rows, 0, "30px");
	cellFormatter.setHeight(rows, 0, "20px");
	cellFormatter.setHorizontalAlignment(rows, 0, HasAlignment.ALIGN_CENTER);
	cellFormatter.setVerticalAlignment(rows, 0, HasAlignment.ALIGN_MIDDLE);
	cellFormatter.setWidth(rows, 3, "100%");

	table.getRowFormatter().setStyleName(rows, "okm-SearchSaved");
	setRowWordWarp(rows, 4, false);
}
 
Example 3
Source File: ClientUtils.java    From sc2gears with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the horizontal alignment of all cells of the specified table.
 * @param table      table whose cells to be aligned
 * @param hAlignment horizontal alignment to be set
 */
public static void alignTableCells( final HTMLTable table, final HorizontalAlignmentConstant hAlignment ) {
	final CellFormatter cellFormatter = table.getCellFormatter();
	
	for ( int i = table.getRowCount() - 1; i >= 0; i-- )
		for ( int j = table.getCellCount( i ) - 1; j >= 0; j-- )
			cellFormatter.setHorizontalAlignment( i, j, hAlignment );
}
 
Example 4
Source File: HasFileStatInfoTablePage.java    From sc2gears with Apache License 2.0 4 votes vote down vote up
private void renderInfoRow( final FileStatInfo info, final FlexTable table, final ClickHandler googleAccountClickHandler ) {
	final CellFormatter cellFormatter = table.getCellFormatter();
	final RowFormatter  rowFormatter  = table.getRowFormatter();
	
	int column = 0;
	
	table.setWidget( row, column++, new Label( userCounter + "." ) );
	cellFormatter.setHorizontalAlignment( row, column-1, HasHorizontalAlignment.ALIGN_RIGHT );
	
	final VerticalPanel userPanel = new VerticalPanel();
	if ( info.getAddressedBy() != null )
		userPanel.add( ClientUtils.styledWidget( new Label( info.getAddressedBy() + ", "
			+ ( info.getCountry() == null ? "-" : info.getCountry() ) ), "explanation" ) );
	if ( googleAccountClickHandler == null || userCounter == 0 )
		userPanel.add( new Label( info.getGoogleAccount() ) );
	else {
		final Anchor googleAccountAnchor = new Anchor( info.getGoogleAccount() );
		googleAccountAnchor.setTitle( googleAccountClickHandler.toString() );
		googleAccountAnchor.addClickHandler( googleAccountClickHandler );
		userPanel.add( googleAccountAnchor );
	}
	userPanel.add( ClientUtils.styledWidget( ClientUtils.createTimestampWidget( "Updated: ", info.getUpdated() ), "explanation" ) );
	userPanel.add( ClientUtils.styledWidget( new Label(
		( info.getAccountCreated() == null ? "" : "Created: " + ClientUtils.DATE_FORMAT.format( info.getAccountCreated() ) + ", " )
		+ "Pkg: " + info.getDbPackageName() + ";" ), "explanation" ) );
	if ( info.getComment() != null ) {
		final Label commentLabel = new Label();
		if ( info.getComment().length() <= 40 )
			commentLabel.setText( info.getComment() );
		else {
			commentLabel.setText( info.getComment().substring( 0, 40 ) + "..." );
			commentLabel.setTitle( info.getComment() );
		}
		userPanel.add( ClientUtils.styledWidget( commentLabel, "explanation" ) );
	}
	table.setWidget( row, column++, userPanel );
	
	final Widget dbPackageWidget = info.getDbPackageIcon() == null ? new Label( info.getDbPackageName() ) : new Image( info.getDbPackageIcon() );
	dbPackageWidget.setTitle( "Available storage: " + NUMBER_FORMAT.format( info.getPaidStorage() ) + " bytes" );
	table.setWidget( row, column++, dbPackageWidget );
	int rowSpan = 1;
	if ( info.getRepCount  () > 0 ) rowSpan++;
	if ( info.getSmpdCount () > 0 ) rowSpan++;
	if ( info.getOtherCount() > 0 ) rowSpan++;
	if ( rowSpan > 1 )
		for ( int i = column - 1; i >= 0; i-- )
			table.getFlexCellFormatter().setRowSpan( row, i, rowSpan );
	userCounter++;
	
	for ( int type = 0; type < 4; type++ ) {
		String fileType = null;
		int    count    = 0;
		long   storage  = 0;
		switch ( type ) {
		case 0 : count = info.getAllCount(); storage = info.getAllStorage(); fileType = "<all>"; break;
		case 1 : if ( ( count = info.getRepCount  () ) == 0 ) continue; storage = info.getRepStorage  (); fileType = "rep"  ; column = 0; break;
		case 2 : if ( ( count = info.getSmpdCount () ) == 0 ) continue; storage = info.getSmpdStorage (); fileType = "smpd" ; column = 0; break;
		case 3 : if ( ( count = info.getOtherCount() ) == 0 ) continue; storage = info.getOtherStorage(); fileType = "other"; column = 0; break;
		}
		table.setWidget( row, column++, new Label( fileType ) );
		final int firstNumberColumn = column;
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( count ) ) );
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( storage ) + " bytes" ) );
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( count == 0 ? 0 : storage / count ) + " bytes" ) );
		final int usedPercent = info.getPaidStorage() == 0 ? 0 : (int) ( storage * 100 / info.getPaidStorage() );
		table.setWidget( row, column++, new Label( usedPercent + "%" ) );
		
		for ( int i = column - 1; i >= firstNumberColumn; i-- )
			cellFormatter.setHorizontalAlignment( row, i, HasHorizontalAlignment.ALIGN_RIGHT );
		
		rowFormatter.addStyleName( row, userCounter == 1 ? "gold" : ( userCounter & 0x01 ) == 0 ? "row0" : "row1" );
		
		row++;
	}
}
 
Example 5
Source File: HasApiCallStatInfoTablePage.java    From sc2gears with Apache License 2.0 4 votes vote down vote up
/**
 * Builds the API call stat info table.
 * 
 * <p>On first call the table is initialized, on later calls its content is first removed.</p>
 * 
 * @param apiCallStatInfoList       API call stat info list to build the table from
 * @param table                     table to build
 * @param googleAccountClickHandler if provided, google accounts will be rendered as links (@link {@link Anchor}),
 * 		and clicking on them will call this handler; the tool tip of links will be <code>googleAccountClickHandler.toString()</code>
 */
protected void buildApiCallStatInfoTable( final List< ApiCallStatInfo > apiCallStatInfoList, final FlexTable table, final ClickHandler googleAccountClickHandler ) {
	// Build table
	if ( table.getRowCount() == 0 ) {
		// Init table
		table.setBorderWidth( 1 );
		table.setCellSpacing( 0 );
		table.setCellPadding( 3 );
		add( table );
	}
	else
		table.removeAllRows();
	
	final RowFormatter rowFormatter = table.getRowFormatter();
	
	int column = 0;
	table.setWidget( 0, column++, new Label( "#"               ) );
	table.setWidget( 0, column++, new Label( "User"            ) );
	table.setWidget( 0, column++, new Label( "Paid Ops"        ) );
	table.setWidget( 0, column++, new Label( "∑Calls"          ) );
	table.setWidget( 0, column++, new Label( "Used Ops"        ) );
	table.setWidget( 0, column++, new Label( "Avg Time"        ) );
	table.setWidget( 0, column++, new Label( "Denied"          ) );
	table.setWidget( 0, column++, new Label( "Errors"          ) );
	table.setWidget( 0, column++, new Label( "Info"            ) );
	table.setWidget( 0, column++, new Label( "Avg Info T"      ) );
	table.setWidget( 0, column++, new Label( "Map info"        ) );
	table.setWidget( 0, column++, new Label( "Avg Map info T"  ) );
	table.setWidget( 0, column++, new Label( "Parse rep"       ) );
	table.setWidget( 0, column++, new Label( "Avg Parse rep T" ) );
	table.setWidget( 0, column++, new Label( "Prof info"       ) );
	table.setWidget( 0, column++, new Label( "Avg Prof info T" ) );
	table.setWidget( 0, column++, new Label( "Share"           ) );
	rowFormatter.addStyleName( 0, "headerRow" );
	
	final CellFormatter cellFormatter = table.getCellFormatter();
	
	final int rowsCount = apiCallStatInfoList.size();
	int userCounter = 0;
	for ( int row = 1; row <= rowsCount; row++ ) {
		final ApiCallStatInfo info = apiCallStatInfoList.get( row - 1 );
		column = 0;
		
		table.setWidget( row, column++, new Label( userCounter + "." ) );
		cellFormatter.setHorizontalAlignment( row, column-1, HasHorizontalAlignment.ALIGN_RIGHT );
		if ( googleAccountClickHandler == null || userCounter == 0 )
			table.setWidget( row, column++, new Label( info.getGoogleAccount() ) );
		else {
			final Anchor googleAccountAnchor = new Anchor( info.getGoogleAccount() );
			googleAccountAnchor.setTitle( googleAccountClickHandler.toString() );
			googleAccountAnchor.addClickHandler( googleAccountClickHandler );
			table.setWidget( row, column++, googleAccountAnchor );
		}
		userCounter++;
		
		final int firstNumberColumn = column;
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( info.getPaidOps            () )         ) );
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( info.getCalls              () )         ) );
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( info.getUsedOps            () )         ) );
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( info.getAvgExecTime        () ) + " ms" ) );
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( info.getDeniedCalls        () )         ) );
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( info.getErrors             () )         ) );
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( info.getInfoCalls          () )         ) );
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( info.getAvgInfoExecTime    () ) + " ms" ) );
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( info.getMapInfoCalls       () )         ) );
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( info.getAvgMapInfoExecTime () ) + " ms" ) );
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( info.getParseRepCalls      () )         ) );
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( info.getAvgParseRepExecTime() ) + " ms" ) );
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( info.getProfInfoCalls      () )         ) );
		table.setWidget( row, column++, new Label( NUMBER_FORMAT.format( info.getAvgProfInfoExecTime() ) + " ms" ) );
		table.setWidget( row, column++, new Label( ( info.getPaidOps() == 0 ? 0 : 100 * info.getUsedOps() / info.getPaidOps() ) + "%" ) );
		
		for ( int i = column - 1; i >= firstNumberColumn; i-- )
			cellFormatter.setHorizontalAlignment( row, i, HasHorizontalAlignment.ALIGN_RIGHT );
		
		rowFormatter.addStyleName( row, userCounter == 1 ? "gold" : ( userCounter & 0x01 ) == 0 ? "row0" : "row1" );
	}
}
 
Example 6
Source File: ClientUtils.java    From sc2gears with Apache License 2.0 4 votes vote down vote up
/**
 * Displays a Details dialog box.<br>
 * Renders a table with 2 columns: name and value pairs.
 * @param caption title of the dialog
 * @param values  values to be displayed; each element is an array (name-value pair) which defines a row
 */
public static void displayDetailsDialog( final String caption, final Object[][] values ) {
	final DialogBox dialogBox = new DialogBox( true );
	dialogBox.setText( caption );
	dialogBox.setGlassEnabled( true );
	
	final VerticalPanel content = new VerticalPanel();
	content.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_CENTER );
	
	final FlexTable table = new FlexTable();
	table.setBorderWidth( 1 );
	table.setCellSpacing( 0 );
	table.setCellPadding( 3 );
	
	
	final CellFormatter cellFormatter = table.getCellFormatter();
	for ( int i = 0; i < values.length; i++ ) {
		// Name
		table.setWidget( i, 0, new Label( values[ i ][ 0 ].toString() ) );
		cellFormatter.addStyleName( i, 0, "headerRow" );
		
		final Object value = values[ i ] [ 1 ];
		
		if ( value == null )
			table.setWidget( i, 1, new Label() );
		else if ( value instanceof Widget ) 
			table.setWidget( i, 1, (Widget) value );
		else if ( value instanceof Date )
			table.setWidget( i, 1, createTimestampWidget( (Date) value ) );
		else {
			String stringValue;
			if ( value instanceof String )
				stringValue = (String) value;
			else if ( value instanceof Number )
				stringValue = NUMBER_FORMAT   .format( (Number) value );
			else
				stringValue = value.toString();
			table.setWidget( i, 1, new Label( stringValue ) );
		}
		cellFormatter.addStyleName( i, 1, "row" + ( i & 0x01 ) );
		cellFormatter.setHorizontalAlignment( i, 1, HasHorizontalAlignment.ALIGN_LEFT );
	}
	
	content.add( table );
	
	content.add( createVerticalEmptyWidget( 8 ) );
	content.add( ClientUtils.createDialogCloseButton( dialogBox, "Close" ) );
	content.add( createVerticalEmptyWidget( 8 ) );
	
	dialogBox.setWidget( content );
	
	dialogBox.center();
}
 
Example 7
Source File: WordCloudLatestApp.java    From swcv with MIT License 4 votes vote down vote up
private Grid createTable(List<WordCloud> clouds, boolean debug)
{
    Grid table = new Grid(clouds.size() + 1, debug ? 4 : 3);
    table.addStyleName("latest");
    CellFormatter cf = table.getCellFormatter();

    table.setHTML(0, 0, "<b>id</b>");
    table.setHTML(0, 1, "<b>creation date</b>");
    table.setHTML(0, 2, "<b>source</b>");
    cf.setWidth(0, 0, "10%");
    cf.setWidth(0, 1, "25%");
    cf.setWidth(0, 2, "65%");
    cf.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
    cf.setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
    cf.setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);

    if (debug)
    {
        table.setHTML(0, 3, "<b>ip</b>");
        cf.setWidth(0, 1, "20%");
        cf.setWidth(0, 2, "60%");
        cf.setWidth(0, 3, "10%");
        cf.setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
    }

    for (int i = 0; i < clouds.size(); i++)
    {
        WordCloud cloud = clouds.get(i);

        table.setHTML(i + 1, 0, "<a href='/cloud.html?id=" + cloud.getId() + "'>" + cloud.getId() + "</a>");
        Date dt = cloud.getCreationDateAsDate();
        table.setHTML(i + 1, 1, DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss").format(dt));
        table.setWidget(i + 1, 2, createSourceField(cloud, debug));
        cf.setHorizontalAlignment(i + 1, 2, HasHorizontalAlignment.ALIGN_LEFT);

        if (debug)
        {
            table.setHTML(i + 1, 3, cloud.getCreatorIP());
        }
    }

    return table;
}