Java Code Examples for com.google.gwt.user.client.ui.FlexTable#getCellFormatter()

The following examples show how to use com.google.gwt.user.client.ui.FlexTable#getCellFormatter() . 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: 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 2
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 3
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 4
Source File: SettingsPanel.java    From swcv with MIT License 4 votes vote down vote up
public CaptionPanel create(WCSettings setting)
{
    this.setting = setting;

    FlexTable layout = new FlexTable();

    CellFormatter cf = layout.getCellFormatter();
    // Add some standard form options
    layout.setWidget(0, 0, createLabel("Number of Words:"));
    layout.setWidget(0, 1, createNumberListBox());
    layout.setWidget(1, 0, createLabel("Layout:"));
    layout.setWidget(1, 1, createLayoutListBox());
    layout.setWidget(2, 0, createLabel("Similarity:"));
    layout.setWidget(2, 1, createSimilarityListBox());

    layout.setWidget(3, 0, createLabel("Ranking:"));
    rankingWidget = createRankingListBox();
    layout.setWidget(3, 1, rankingWidget);

    cf.setStyleName(0, 2, "adv-cell-label");
    layout.setWidget(0, 2, createLabel("Font:"));
    fontWidget = createFontListBox();
    layout.setWidget(0, 3, fontWidget);

    cf.setStyleName(1, 2, "adv-cell-label");
    layout.setWidget(1, 2, createLabel("Color:"));
    colorSchemeWidget = createColorListBox();
    layout.setWidget(1, 3, colorSchemeWidget);

    cf.setStyleName(2, 2, "adv-cell-label");
    layout.setWidget(2, 2, createLabel("Aspect Ratio:"));
    layout.setWidget(2, 3, createAspectRatioListBox());

    cf.setStyleName(3, 2, "adv-cell-label");
    layout.setWidget(3, 2, createLabel("Language:"));
    layout.setWidget(3, 3, createLanguageListBox());

    addParseOptions(layout, cf);

    addTooltips(layout);

    // Wrap the content in a DecoratorPanel
    CaptionPanel panel = new CaptionPanel();
    panel.setCaptionText("advanced options for word cloud generation");
    panel.add(layout);
    return panel;
}