List of usage examples for com.google.gwt.i18n.client NumberFormat getFormat
public static NumberFormat getFormat(String pattern)
NumberFormat
instance for the default locale using the specified pattern and the default currencyCode. From source file:com.smartgwt.sample.showcase.client.miniapp.ItemListGrid.java
License:Open Source License
public ItemListGrid(DataSource supplyItemDS) { setDataSource(supplyItemDS);/*from w ww.ja va2 s. com*/ setUseAllDataSourceFields(true); ListGridField itemName = new ListGridField("itemName", "Name"); itemName.setShowHover(true); ListGridField units = new ListGridField("units"); units.setWidth(100); ListGridField unitCost = new ListGridField("unitCost"); unitCost.setWidth(100); unitCost.setCellFormatter(new CellFormatter() { public String format(Object value, ListGridRecord record, int rowNum, int colNum) { if (value == null) return null; try { NumberFormat nf = NumberFormat.getFormat("##0.00"); return "$" + nf.format(((Number) value).floatValue()); } catch (Exception e) { return value.toString(); } } }); unitCost.setEditorType(SpinnerItem.class); SpinnerItem spinnerItem = new SpinnerItem(); spinnerItem.setStep(0.01); unitCost.setEditorProperties(spinnerItem); ListGridField sku = new ListGridField("SKU"); sku.setCanEdit(false); ListGridField description = new ListGridField("description"); description.setWidth(150); description.setShowHover(true); ListGridField category = new ListGridField("category"); category.setCanEdit(false); ListGridField inStock = new ListGridField("inStock"); inStock.setWidth(70); inStock.setAlign(Alignment.CENTER); ListGridField nextShipment = new ListGridField("nextShipent", 150); nextShipment.setShowIfCondition(new ListGridFieldIfFunction() { public boolean execute(ListGrid grid, ListGridField field, int fieldNum) { return false; } }); setFields(itemName, units, unitCost, sku, description, category, inStock); setCanEdit(true); setCanDragRecordsOut(true); setHoverWidth(200); setHoverHeight(20); setSelectionType(SelectionStyle.SINGLE); }
From source file:com.smartgwt.sample.showcase.client.offline.OfflinePreferencesSample.java
License:Open Source License
public Canvas getViewPanel() { VLayout layout = new VLayout(15); layout.setWidth(650);/*from w ww . jav a2 s. co m*/ layout.setAutoHeight(); final ListGrid countryGrid = new ListGrid(); countryGrid.setLeaveScrollbarGap(true); countryGrid.setCanFreezeFields(true); countryGrid.setCanGroupBy(true); countryGrid.setWidth100(); countryGrid.setHeight(224); countryGrid.setDataSource(CountryXmlDS.getInstance()); countryGrid.setAutoFetchData(true); //allow users to add formula and summary fields //accessible in the grid header context menu countryGrid.setCanAddFormulaFields(true); countryGrid.setCanAddSummaryFields(true); ListGridField countryCodeField = new ListGridField("countryCode", "Flag", 50); countryCodeField.setAlign(Alignment.CENTER); countryCodeField.setType(ListGridFieldType.IMAGE); countryCodeField.setImageURLPrefix("flags/16/"); countryCodeField.setImageURLSuffix(".png"); countryCodeField.setCanSort(false); ListGridField nameField = new ListGridField("countryName", "Country"); ListGridField capitalField = new ListGridField("capital", "Capital"); ListGridField populationField = new ListGridField("population", "Population"); populationField.setCellFormatter(new CellFormatter() { public String format(Object value, ListGridRecord record, int rowNum, int colNum) { if (value == null) return null; try { NumberFormat nf = NumberFormat.getFormat("0,000"); return nf.format(((Number) value).longValue()); } catch (Exception e) { return value.toString(); } } }); ListGridField areaField = new ListGridField("area", "Area (km²)"); areaField.setType(ListGridFieldType.INTEGER); areaField.setCellFormatter(new CellFormatter() { public String format(Object value, ListGridRecord record, int rowNum, int colNum) { if (value == null) return null; String val = null; try { NumberFormat nf = NumberFormat.getFormat("0,000"); val = nf.format(((Number) value).longValue()); } catch (Exception e) { return value.toString(); } return val + "km²"; } }); countryGrid.setFields(countryCodeField, nameField, capitalField, populationField, areaField); ToolStripButton formulaButton = new ToolStripButton("Formula Builder", "crystal/oo/sc_insertformula.png"); formulaButton.setAutoFit(true); formulaButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { countryGrid.addFormulaField(); } }); ToolStripButton summaryBuilder = new ToolStripButton("Summary Builder", "crystal/16/apps/tooloptions.png"); summaryBuilder.setAutoFit(true); summaryBuilder.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { countryGrid.addSummaryField(); } }); ToolStripButton savePreference = new ToolStripButton("Persist State", "silk/database_gear.png"); savePreference.setAutoFit(true); savePreference.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { String viewState = countryGrid.getViewState(); Offline.put("exampleState", viewState); SC.say("Preferences persisted."); } }); //toolstrip to attach to the country grid ToolStrip countryGridToolStrip = new ToolStrip(); countryGridToolStrip.setWidth100(); countryGridToolStrip.addFill(); countryGridToolStrip.addButton(formulaButton); countryGridToolStrip.addButton(summaryBuilder); countryGridToolStrip.addSeparator(); countryGridToolStrip.addButton(savePreference); VLayout countryGridLayout = new VLayout(0); countryGridLayout.setWidth(650); countryGridLayout.addMember(countryGridToolStrip); countryGridLayout.addMember(countryGrid); layout.addMember(countryGridLayout); final String previouslySavedState = (String) Offline.get("exampleState"); if (previouslySavedState != null) { countryGrid.addDrawHandler(new DrawHandler() { @Override public void onDraw(DrawEvent event) { //restore any previously saved view state for this grid countryGrid.setViewState(previouslySavedState); } }); } return layout; }
From source file:com.square.composant.contrat.personne.morale.square.client.view.ContratGarantiePersonneMoraleViewImpl.java
License:Open Source License
/** * Constructeur.// w w w .ja v a 2 s . co m * @param constantesApp constantes de l'application * @param ressources les ressources. * @param garantie la garantie. */ public ContratGarantiePersonneMoraleViewImpl(ConstantesModel constantesApp, ComposantContratPersonneMoraleResources ressources, GarantiePersonneMoraleModel garantie) { this.viewConstants = (ContratGarantiePMViewImplConstants) GWT .create(ContratGarantiePMViewImplConstants.class); numberFormat = NumberFormat.getFormat("#,##0.00 " + viewConstants.symboleMonnaie()); this.constantesApp = constantesApp; this.ressources = ressources; construireBlocContenu(garantie); final CaptionPanel captionPanel = new CaptionPanel(garantie.getLibelle()); captionPanel.setStylePrimaryName(this.ressources.css().panelGarantieContrat()); captionPanel.add(conteneurGlobal); initWidget(captionPanel); }
From source file:com.square.composant.contrat.square.client.view.ContratGarantieAjustementViewImpl.java
License:Open Source License
/** * Constructeur./*from w w w .ja va 2 s.c o m*/ * @param ajustement ajustement */ public ContratGarantieAjustementViewImpl(AjustementTarifModel ajustement) { ContratGarantieViewImplConstants constants = GWT.create(ContratGarantieViewImplConstants.class); numberFormat = NumberFormat.getFormat("#,##0.00 " + constants.symboleMonnaie()); labelReference = new Label(ajustement.getReference()); labelLibelle = new Label(ajustement.getNature()); labelTarif = new Label(numberFormat.format(ajustement.getMontant())); labelDateDebut = new Label(ajustement.getDateDebut()); labelDateFin = new Label(ajustement.getDateFin()); }
From source file:com.square.composant.contrat.square.client.view.ContratGarantieViewImpl.java
License:Open Source License
/** * Constructeur./*from ww w.ja v a 2 s. co m*/ * @param resources les ressources * @param garantie la garantie * @param style le style */ public ContratGarantieViewImpl(ComposantContratResources resources, GarantieModel garantie, String style) { this.viewConstants = (ContratGarantieViewImplConstants) GWT.create(ContratGarantieViewImplConstants.class); numberFormat = NumberFormat.getFormat("#,##0.00 " + viewConstants.symboleMonnaie()); construireBlocContenu(garantie); final CaptionPanel captionPanel = new CaptionPanel(garantie.getLibelle()); captionPanel.setStylePrimaryName(resources.css().panelGarantieContrat()); captionPanel.add(conteneurGlobal); initWidget(captionPanel); if (style != null) { captionPanel.addStyleName(style); } }
From source file:com.tasktop.c2c.server.common.web.client.widgets.Pager.java
License:Open Source License
/** * Overridden to display "0 of 0" when there are no records(otherwise you get "1-1 of 0") and "1 of 1" when there is * only one record (otherwise you get "1-1 of 1"). Not internationalized (but neither is SimplePager) * //from w ww . jav a 2s .c om * @return page index text */ protected String createText() { NumberFormat formatter = NumberFormat.getFormat("#,###"); HasRows display = getDisplay(); Range range = display.getVisibleRange(); int pageStart = range.getStart() + 1; int pageSize = range.getLength(); int dataSize = display.getRowCount(); int endIndex = Math.min(dataSize, pageStart + pageSize - 1); endIndex = Math.max(pageStart, endIndex); boolean exact = display.isRowCountExact(); if (dataSize == 0) { return "0 of 0"; } else if (pageStart == endIndex) { return formatter.format(pageStart) + " of " + formatter.format(dataSize); } return formatter.format(pageStart) + "-" + formatter.format(endIndex) + (exact ? " of " : " of over ") + formatter.format(dataSize); }
From source file:com.tasktop.c2c.server.profile.web.ui.client.view.PageIndexingSimplePager.java
License:Open Source License
/** * Overridden to display "0 of 0" when there are no records(otherwise you get "1-1 of 0") and "1 of 1" when there is * only one record (otherwise you get "1-1 of 1"). * /*w w w. java 2s.c o m*/ * @return page index text */ protected String createText() { NumberFormat formatter = NumberFormat.getFormat("#,###"); HasRows display = getDisplay(); Range range = display.getVisibleRange(); int pageStart = range.getStart() + 1; int pageSize = range.getLength(); int dataSize = display.getRowCount(); int endIndex = Math.min(dataSize, pageStart + pageSize - 1); endIndex = Math.max(pageStart, endIndex); boolean exact = display.isRowCountExact(); if (dataSize == 0) { return profileMessages.pagerOf("0", "0"); } else if (pageStart == endIndex) { return profileMessages.pagerOf(formatter.format(pageStart), formatter.format(dataSize)); } String currentRange = formatter.format(pageStart) + "-" + formatter.format(endIndex); return exact ? profileMessages.pagerOf(currentRange, formatter.format(dataSize)) : profileMessages.pagerOfOver(currentRange, formatter.format(dataSize)); }
From source file:com.tsa.puridiom.client.msrrequest.MSRRequestUI.java
License:Apache License
private void initTableColumns(DragAndDropCellTable<ContactInfo> cellTable, final SelectionModel<ContactInfo> selectionModel) { String[] colNames = getColumns(); int index = 0; TextColumn<ContactInfo> numColumn = new TextColumn<ContactInfo>() { @Override//ww w .java2s.c om public String getValue(ContactInfo object) { return object.getLineNumber(); } }; cellTable.addColumn(numColumn, "Line"); cellTable.setColumnWidth(numColumn, "2%"); for (final String columnName : colNames) { final int jIndex = index; DragAndDropColumn<ContactInfo, String> column = new DragAndDropColumn<ContactInfo, String>( new TextCell()) { @Override public String getValue(ContactInfo object) { String desc = object.getDescription(); if (columnName.equals("Item #/Desc.")) return object.getItemNumber() + " - " + (desc.length() > 30 ? desc.substring(0, 30) + "..." : desc); /*else if (columnName.equals("Supplier Id")) return object.getSupplierId();*/ else if (columnName.equals("Catalog/Proc Level")) return object.getCatalog() + "<br />" + object.getProcLevel(); /*else if (columnName.equals("Commodity/Ind Class")) return object.getCommodity() + "<br />" + object.getIndClass();*/ else if (columnName.equals("Quantity")) return numberFormat.format(object.getQuantity()); else if (columnName.equals("U/M")) return object.getUorm(); else if (columnName.equals("Unit Cost")) return "$" + numberFormat.format(object.getUnitCost()); else if (columnName.equals("Ext. Cost")) return "$" + numberFormat.format(object.getExtCost()); else if (columnName.equals("Requisition #")) return object.getReqNumber(); else if (jIndex == 7 && columnName.equals("Status")) return object.getReqStatus(); else if (columnName.equals("Kit/Inventory Location")) return object.getReqLocation(); else if (columnName.equals("PO #")) return object.getPoNumber(); else if (jIndex == 10 && columnName.equals("Status")) return object.getPoStatus(); else if (columnName.equals("Receipt #")) return object.getRecieptNumber(); else if (jIndex == 12 && columnName.equals("Status")) return object.getRecieptStatus(); else if (columnName.equals("Invoice #")) return object.getInvoiceNumber(); else if (jIndex == 14 && columnName.equals("Status")) return object.getInvoiceStatus(); else return ""; } @Override public void render(Context context, ContactInfo object, SafeHtmlBuilder sb) { String desc = object.getDescription(); if (columnName.equals("Item #/Desc.")) sb.appendHtmlConstant(object.getItemNumber() + " - " + (desc.length() > 30 ? desc.substring(0, 30) + "..." : desc)); /*else if (columnName.equals("Supplier Id")) sb.appendHtmlConstant(object.getSupplierId());*/ else if (columnName.equals("Catalog/Proc Level")) sb.appendHtmlConstant(object.getCatalog() + "<br />" + object.getProcLevel()); /*else if (columnName.equals("Commodity/Ind Class")) sb.appendHtmlConstant(object.getCommodity() + "<br />" + object.getIndClass());*/ else if (columnName.equals("Quantity")) sb.appendHtmlConstant(numberFormat.format(object.getQuantity())); else if (columnName.equals("U/M")) sb.appendHtmlConstant(object.getUorm()); else if (columnName.equals("Unit Cost")) sb.appendHtmlConstant("$" + numberFormat.format(object.getUnitCost())); else if (columnName.equals("Ext. Cost")) sb.appendHtmlConstant("$" + numberFormat.format(object.getExtCost())); else if (columnName.equals("Requisition #")) sb.appendHtmlConstant(object.getReqNumber()); else if (columnName.equals("Kit/Inventory Location")) { if (object.isPopup()) { sb.appendHtmlConstant(object.getReqLocation()); } else { int lne = (int) Double.parseDouble(object.getLineNumber()); String line = NumberFormat.getFormat("0000").format(lne); sb.appendHtmlConstant("<a href=\"javascript: showInvBinLocation('" + object.getMsrNumber() + "." + line + "', '" + object.getReqLocation() + "'); void(0);\">" + object.getReqLocation() + "</a>"); } } else if (jIndex == 7 && columnName.equals("Status")) sb.appendHtmlConstant(object.getReqStatus()); else if (columnName.equals("PO #")) sb.appendHtmlConstant(object.getPoNumber()); else if (jIndex == 10 && columnName.equals("Status")) sb.appendHtmlConstant(object.getPoStatus()); else if (columnName.equals("Receipt #")) sb.appendHtmlConstant(object.getRecieptNumber()); else if (jIndex == 12 && columnName.equals("Status")) sb.appendHtmlConstant(object.getRecieptStatus()); else if (columnName.equals("Invoice #")) sb.appendHtmlConstant(object.getInvoiceNumber()); else if (jIndex == 14 && columnName.equals("Status")) sb.appendHtmlConstant(object.getInvoiceStatus()); } }; ListHandler<ContactInfo> columnSortHandler = new ListHandler<ContactInfo>( MSRRequestData.get().getDataProvider(Category.OTHERS).getList()); columnSortHandler.setComparator(column, new Comparator<ContactInfo>() { public int compare(ContactInfo o1, ContactInfo o2) { if (o1 == o2) { return 0; } // Compare the name columns. if (o1 != null && columnName.equals("Item #/Desc.")) { return (o2 != null) ? o1.getItemNumber().toLowerCase().compareTo(o2.getItemNumber().toLowerCase()) : 1; } /*else if (o1 != null && columnName.equals("Supplier Id")) { return (o2 != null) ? o1.getSupplierId().toLowerCase().compareTo(o2.getSupplierId().toLowerCase()) : 1; } */else if (o1 != null && columnName.equals("Catalog/Proc Level")) { return (o2 != null) ? o1.getCatalog().compareTo(o2.getCatalog()) : 1; } /*else if (o1 != null && columnName.equals("Commodity/Ind Class")) { return (o2 != null) ? o1.getIndClass().toLowerCase().compareTo(o2.getIndClass().toLowerCase()) : 1; } */ return -1; } }); cellTable.addColumnSortHandler(columnSortHandler); boolean flag = getColumns().length < 8 ? true : false; if (columnName.equals("Item #/Desc.")) cellTable.setColumnWidth(column, flag ? "30%" : "17%"); /*else if (columnName.equals("Supplier Id")) cellTable.setColumnWidth(column, flag ? "10%" : "4%");*/ else if (columnName.equals("Catalog/Proc Level")) cellTable.setColumnWidth(column, flag ? "15%" : "8%"); /*else if (columnName.equals("Commodity/Ind Class")) cellTable.setColumnWidth(column, flag ? "15%" : "8%");*/ else if (columnName.equals("Quantity")) cellTable.setColumnWidth(column, flag ? "10%" : "4%"); else if (columnName.equals("U/M")) cellTable.setColumnWidth(column, flag ? "10%" : "4%"); else if (columnName.equals("Unit Cost")) cellTable.setColumnWidth(column, flag ? "10%" : "4%"); else if (columnName.equals("Ext. Cost")) cellTable.setColumnWidth(column, flag ? "10%" : "4%"); else if (columnName.equals("Requisition #")) cellTable.setColumnWidth(column, "8%"); else if (columnName.equals("PO #")) cellTable.setColumnWidth(column, "8%"); else if (columnName.equals("Receipt #")) cellTable.setColumnWidth(column, "8%"); else if (columnName.equals("Invoice #")) cellTable.setColumnWidth(column, "8%"); else if (columnName.equals("Status")) cellTable.setColumnWidth(column, "4%"); if (columnName.equals("Item #/Desc.") || columnName.equals("Supplier Id") || columnName.equals("Catalog/Proc Level") || columnName.equals("Commodity/Ind Class")) column.setSortable(true); cellTable.addColumn(column, columnName); if (columnName.equals("Item #/Desc.")) { column.setCellDraggableOnly(); // cellTable.getColumnSortList().push(column); } else if (columnName.equals("Unit Cost") || columnName.equals("Ext. Cost")) column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); else if (columnName.equals("Catalog/Proc Level") || columnName.equals("Commodity/Ind Class") || columnName.equals("Quantity") || columnName.equals("U/M") || columnName.equals("Requisition #") || columnName.equals("PO #") || columnName.equals("Status") || columnName.equals("Receipt #") || columnName.equals("Invoice #") || columnName.equals("Kit/Inventory Location")) { column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); } initDragOperation(column); index++; } }
From source file:com.vaadin.addon.timeline.gwt.client.VTimelineWidget.java
private void handleVerticalAxisNumberFormat(UIDL uidl) { if (uidl.hasAttribute(TimelineConstants.ATTRIBUTE_VERTICAL_NUMBER_FORMAT)) { NumberFormat format = NumberFormat .getFormat(uidl.getStringAttribute(TimelineConstants.ATTRIBUTE_VERTICAL_NUMBER_FORMAT)); display.setVerticalAxisNumberFormat(format); }/*from w w w. j a v a2 s. c o m*/ }
From source file:com.vaadin.client.debug.internal.VDebugWindow.java
License:Apache License
/** * Formats the given milliseconds as hours, minutes, seconds and * milliseconds.//from w w w . j a v a2s. c o m * * @param ms * @return */ static String formatDuration(int ms) { NumberFormat fmt = NumberFormat.getFormat("00"); String seconds = fmt.format((ms / 1000) % 60); String minutes = fmt.format((ms / (1000 * 60)) % 60); String hours = fmt.format((ms / (1000 * 60 * 60)) % 24); String millis = NumberFormat.getFormat("000").format(ms % 1000); return hours + "h " + minutes + "m " + seconds + "s " + millis + "ms"; }