List of usage examples for com.vaadin.ui Label setData
public void setData(Object data)
From source file:com.esofthead.mycollab.module.file.view.components.FileDownloadWindow.java
License:Open Source License
private void constructBody() { final MVerticalLayout layout = new MVerticalLayout(); final Embedded iconEmbed = new Embedded(); iconEmbed.setSource(MyCollabResource.newResource("icons/page_white.png")); layout.with(iconEmbed).withAlign(iconEmbed, Alignment.MIDDLE_CENTER); final GridFormLayoutHelper info = new GridFormLayoutHelper(1, 4, "100%", "80px", Alignment.TOP_LEFT); info.getLayout().setWidth("100%"); info.getLayout().setMargin(new MarginInfo(false, true, false, true)); info.getLayout().setSpacing(false);// www . ja v a2s. c o m if (this.content.getDescription() != null) { final Label desvalue = new Label(); if (!this.content.getDescription().equals("")) { desvalue.setData(this.content.getDescription()); } else { desvalue.setValue(" "); desvalue.setContentMode(ContentMode.HTML); } info.addComponent(desvalue, "Description", 0, 0); } final Label author = new Label(this.content.getCreatedBy()); info.addComponent(author, "Created by", 0, 1); final Label size = new Label(ResourceUtils.getVolumeDisplay(this.content.getSize())); info.addComponent(size, "Size", 0, 2); final Label dateCreate = new Label(AppContext.formatDate(this.content.getCreated().getTime())); info.addComponent(dateCreate, "Date created", 0, 3); layout.addComponent(info.getLayout()); final MHorizontalLayout buttonControls = new MHorizontalLayout(); buttonControls.setSpacing(true); buttonControls.setMargin(new MarginInfo(true, false, true, false)); final Button downloadBtn = new Button("Download"); List<Resource> resources = new ArrayList<Resource>(); resources.add(content); StreamResource downloadResource = StreamDownloadResourceUtil.getStreamResourceSupportExtDrive(resources); FileDownloader fileDownloader = new FileDownloader(downloadResource); fileDownloader.extend(downloadBtn); downloadBtn.addStyleName(UIConstants.THEME_GREEN_LINK); buttonControls.with(downloadBtn).withAlign(downloadBtn, Alignment.MIDDLE_CENTER); final Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { FileDownloadWindow.this.close(); } }); cancelBtn.addStyleName(UIConstants.THEME_GRAY_LINK); buttonControls.with(cancelBtn).withAlign(cancelBtn, Alignment.MIDDLE_CENTER); layout.with(buttonControls).withAlign(buttonControls, Alignment.MIDDLE_CENTER); this.setContent(layout); }
From source file:com.github.peholmst.mvp4vaadin.navigation.ui.NavigationBar.java
License:Apache License
/** * Adds a breadcrumb to the navigation bar for the specified view. If there * already is one or more breadcrumbs in the bar, a separator will be added * before the actual navigation button:/*from ww w . ja v a 2s . co m*/ * * <pre> * First view >> Second view >> Third view * </pre> * * A click on the navigation button will result in a request to the view * controller to navigate to that particular view. * * @see #addViewButton(String) * @see #addViewSeparator() * * @param view * the view to add (must not be <code>null</code>). */ protected void addBreadcrumbForView(final ControllableView view) { if (getViewController().getTrail().size() > 1) { Label separator = addViewSeparator(); separator.setData(view); } final Button btn = addViewButton(view.getDisplayName()); btn.setDescription(view.getViewDescription()); btn.addListener(new Button.ClickListener() { private static final long serialVersionUID = -2163467482631873920L; @Override public void buttonClick(ClickEvent event) { getViewController().goToView(view); } }); btn.setData(view); }
From source file:com.mycollab.module.file.view.components.FileDownloadWindow.java
License:Open Source License
private void constructBody() { final MVerticalLayout layout = new MVerticalLayout().withFullWidth(); CssLayout iconWrapper = new CssLayout(); final ELabel iconEmbed = ELabel.fontIcon(FileAssetsUtil.getFileIconResource(content.getName())); iconEmbed.addStyleName("icon-48px"); iconWrapper.addComponent(iconEmbed); layout.with(iconWrapper).withAlign(iconWrapper, Alignment.MIDDLE_CENTER); final GridFormLayoutHelper inforLayout = GridFormLayoutHelper.defaultFormLayoutHelper(1, 4); if (content.getDescription() != null) { final Label descLbl = new Label(); if (!content.getDescription().equals("")) { descLbl.setData(content.getDescription()); } else {/*from w w w .j a va2s.c o m*/ descLbl.setValue(" "); descLbl.setContentMode(ContentMode.HTML); } inforLayout.addComponent(descLbl, "Description", 0, 0); } UserService userService = AppContextUtil.getSpringBean(UserService.class); SimpleUser user = userService.findUserByUserNameInAccount(content.getCreatedUser(), AppContext.getAccountId()); if (user == null) { inforLayout.addComponent(new UserLink(AppContext.getUsername(), AppContext.getUserAvatarId(), AppContext.getUserDisplayName()), "Created by", 0, 1); } else { inforLayout.addComponent(new UserLink(user.getUsername(), user.getAvatarid(), user.getDisplayName()), "Created by", 0, 1); } final Label size = new Label(FileUtils.getVolumeDisplay(content.getSize())); inforLayout.addComponent(size, "Size", 0, 2); ELabel dateCreate = new ELabel().prettyDateTime(content.getCreated().getTime()); inforLayout.addComponent(dateCreate, "Created date", 0, 3); layout.addComponent(inforLayout.getLayout()); final MHorizontalLayout buttonControls = new MHorizontalLayout() .withMargin(new MarginInfo(true, false, true, false)); final Button downloadBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_DOWNLOAD)); List<Resource> resources = new ArrayList<>(); resources.add(content); StreamResource downloadResource = StreamDownloadResourceUtil.getStreamResourceSupportExtDrive(resources); FileDownloader fileDownloader = new FileDownloader(downloadResource); fileDownloader.extend(downloadBtn); downloadBtn.setIcon(FontAwesome.DOWNLOAD); downloadBtn.addStyleName(UIConstants.BUTTON_ACTION); final Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { close(); } }); cancelBtn.addStyleName(UIConstants.BUTTON_OPTION); buttonControls.with(cancelBtn, downloadBtn).alignAll(Alignment.TOP_RIGHT); layout.with(buttonControls).withAlign(buttonControls, Alignment.TOP_RIGHT); this.setContent(layout); }
From source file:com.mycollab.module.file.view.FileDownloadWindow.java
License:Open Source License
private void constructBody() { final MVerticalLayout layout = new MVerticalLayout().withFullWidth(); CssLayout iconWrapper = new CssLayout(); final ELabel iconEmbed = ELabel.fontIcon(FileAssetsUtil.getFileIconResource(content.getName())); iconEmbed.addStyleName("icon-48px"); iconWrapper.addComponent(iconEmbed); layout.with(iconWrapper).withAlign(iconWrapper, Alignment.MIDDLE_CENTER); final GridFormLayoutHelper inforLayout = GridFormLayoutHelper.defaultFormLayoutHelper(1, 4); if (content.getDescription() != null) { final Label descLbl = new Label(); if (!content.getDescription().equals("")) { descLbl.setData(content.getDescription()); } else {// w w w . j ava 2 s .c o m descLbl.setValue(" "); descLbl.setContentMode(ContentMode.HTML); } inforLayout.addComponent(descLbl, UserUIContext.getMessage(GenericI18Enum.FORM_DESCRIPTION), 0, 0); } UserService userService = AppContextUtil.getSpringBean(UserService.class); SimpleUser user = userService.findUserByUserNameInAccount(content.getCreatedUser(), MyCollabUI.getAccountId()); if (user == null) { inforLayout.addComponent( new UserLink(UserUIContext.getUsername(), UserUIContext.getUserAvatarId(), UserUIContext.getUserDisplayName()), UserUIContext.getMessage(GenericI18Enum.OPT_CREATED_BY), 0, 1); } else { inforLayout.addComponent(new UserLink(user.getUsername(), user.getAvatarid(), user.getDisplayName()), UserUIContext.getMessage(GenericI18Enum.OPT_CREATED_BY), 0, 1); } final Label size = new Label(FileUtils.getVolumeDisplay(content.getSize())); inforLayout.addComponent(size, UserUIContext.getMessage(FileI18nEnum.OPT_SIZE), 0, 2); ELabel dateCreate = new ELabel().prettyDateTime(content.getCreated().getTime()); inforLayout.addComponent(dateCreate, UserUIContext.getMessage(GenericI18Enum.FORM_CREATED_TIME), 0, 3); layout.addComponent(inforLayout.getLayout()); MButton downloadBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_DOWNLOAD)) .withIcon(FontAwesome.DOWNLOAD).withStyleName(WebThemes.BUTTON_ACTION); List<Resource> resources = new ArrayList<>(); resources.add(content); StreamResource downloadResource = StreamDownloadResourceUtil.getStreamResourceSupportExtDrive(resources); FileDownloader fileDownloader = new FileDownloader(downloadResource); fileDownloader.extend(downloadBtn); MButton cancelBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_CANCEL), clickEvent -> close()).withStyleName(WebThemes.BUTTON_OPTION); final MHorizontalLayout buttonControls = new MHorizontalLayout(cancelBtn, downloadBtn); layout.with(buttonControls).withAlign(buttonControls, Alignment.MIDDLE_RIGHT); this.setContent(layout); }
From source file:fi.semantum.strategia.widget.Indicator.java
License:Open Source License
public static void updateIndicators(final Main main, final Base base, boolean canWrite) { final Database database = main.getDatabase(); List<IndicatorDescription> descs = new ArrayList<IndicatorDescription>(); fillIndicatorDescriptions(main, base, "", descs); boolean isMap = base instanceof Strategiakartta; if (isMap && (!descs.isEmpty() || canWrite)) { HorizontalLayout indiHeader = new HorizontalLayout(); indiHeader.setSpacing(true);/* w w w . j a v a 2 s. c o m*/ Label header = new Label("Indikaattorit (ennuste)"); main.propertyCells.add(Utils.excelRow(header.getValue())); header.setHeight("32px"); header.addStyleName(ValoTheme.LABEL_HUGE); header.addStyleName(ValoTheme.LABEL_BOLD); indiHeader.addComponent(header); indiHeader.setComponentAlignment(header, Alignment.BOTTOM_CENTER); if (canWrite) { final Image editIndicators = new Image(null, new ThemeResource("chart_line_edit.png")); editIndicators.setHeight("24px"); editIndicators.setWidth("24px"); editIndicators.addClickListener(new MouseEvents.ClickListener() { private static final long serialVersionUID = 2661060702097338722L; @Override public void click(com.vaadin.event.MouseEvents.ClickEvent event) { Utils.loseFocus(editIndicators); manageIndicators(main, main.getUIState().currentItem); } }); indiHeader.addComponent(editIndicators); indiHeader.setComponentAlignment(editIndicators, Alignment.BOTTOM_CENTER); } main.properties.addComponent(indiHeader); main.properties.setComponentAlignment(indiHeader, Alignment.MIDDLE_CENTER); VerticalLayout indicators = new VerticalLayout(); boolean showYears = main.getUIState().time.equals(Property.AIKAVALI_KAIKKI); Property time = Property.find(database, Property.AIKAVALI); int index = 0; for (final IndicatorDescription desc : descs) { ArrayList<String> excelRow = new ArrayList<String>(); Indicator indicator = desc.indicator; final HorizontalLayout hl = new HorizontalLayout(); hl.addStyleName((((index++) & 1) == 0) ? "evenProperty" : "oddProperty"); hl.setSpacing(true); Label l = new Label(desc.caption); excelRow.add(l.getValue().replace("%nbsp", "")); l.setContentMode(ContentMode.HTML); l.setWidth("450px"); l.addStyleName("propertyName"); l.setData(desc); hl.addComponent(l); hl.setComponentAlignment(l, Alignment.MIDDLE_LEFT); String value = updateIndicatorValue(main, hl, base, indicator, canWrite); excelRow.add(value); Label unit = new Label(indicator.getUnit()); unit.setWidth("100px"); hl.addComponent(unit); hl.setComponentAlignment(unit, Alignment.MIDDLE_LEFT); excelRow.add(unit.getValue()); Label comment = new Label(indicator.getValueShortComment()); comment.setWidth("150px"); hl.addComponent(comment); hl.setComponentAlignment(comment, Alignment.MIDDLE_LEFT); excelRow.add(comment.getValue()); if (showYears) { HorizontalLayout hl2 = new HorizontalLayout(); hl2.setWidth("70px"); hl2.setHeight("100%"); hl.addComponent(hl2); hl.setComponentAlignment(hl2, Alignment.MIDDLE_LEFT); String years = time.getPropertyValue(indicator); if (years == null) years = Property.AIKAVALI_KAIKKI; final Label region = new Label(years); region.setWidthUndefined(); excelRow.add(region.getValue()); hl2.addComponent(region); hl2.setComponentAlignment(region, Alignment.MIDDLE_CENTER); } final Image wiki = new Image(); wiki.setSource(new ThemeResource("table_edit.png")); wiki.setHeight("24px"); wiki.setWidth("24px"); wiki.addClickListener(new MouseEvents.ClickListener() { private static final long serialVersionUID = 2661060702097338722L; @Override public void click(com.vaadin.event.MouseEvents.ClickEvent event) { Wiki.openWiki(main, desc.indicator); } }); hl.addComponent(wiki); hl.setComponentAlignment(wiki, Alignment.MIDDLE_CENTER); indicators.addComponent(hl); indicators.setComponentAlignment(hl, Alignment.MIDDLE_CENTER); main.propertyCells.add(excelRow); } indicators.addLayoutClickListener(new LayoutClickListener() { private static final long serialVersionUID = 3295743025581923380L; private String extractData(Component c) { if (c instanceof AbstractComponent) { Object data = ((AbstractComponent) c).getData(); if (data instanceof IndicatorDescription) { IndicatorDescription desc = (IndicatorDescription) data; return desc.indicator.getDescription(database); } } return null; } @Override public void layoutClick(LayoutClickEvent event) { String desc = extractData(event.getClickedComponent()); if (desc == null) return; String content = "<div style=\"width: 700px; border: 2px solid; padding: 5px\">"; content += "<div style=\"text-align: center; white-space:normal; font-size: 36px; padding: 10px\">" + desc + "</div>"; content += "</div>"; Notification n = new Notification(content, Notification.Type.HUMANIZED_MESSAGE); n.setHtmlContentAllowed(true); n.show(Page.getCurrent()); } }); main.properties.addComponent(indicators); main.properties.setComponentAlignment(indicators, Alignment.MIDDLE_CENTER); } }
From source file:fi.semantum.strategia.widget.Meter.java
License:Open Source License
public static void updateMeters(final Main main, boolean canWrite) { if (main.getUIState().currentItem instanceof Strategiakartta) return;//ww w .ja v a 2 s . com final Database database = main.getDatabase(); final Base base = main.getUIState().currentItem; List<MeterDescription> descs = makeMeterDescriptions(main, base, false); if (!descs.isEmpty() || canWrite) { HorizontalLayout meterHeader = new HorizontalLayout(); meterHeader.setSpacing(true); Label header = new Label("Mittarit"); main.propertyCells.add(Utils.excelRow(header.getValue())); header.setHeight("32px"); header.addStyleName(ValoTheme.LABEL_HUGE); header.addStyleName(ValoTheme.LABEL_BOLD); meterHeader.addComponent(header); meterHeader.setComponentAlignment(header, Alignment.BOTTOM_CENTER); if (canWrite) { final Image editMeters = new Image(null, new ThemeResource("chart_bar_edit.png")); editMeters.setHeight("24px"); editMeters.setWidth("24px"); editMeters.addClickListener(new MouseEvents.ClickListener() { private static final long serialVersionUID = 2661060702097338722L; @Override public void click(com.vaadin.event.MouseEvents.ClickEvent event) { Utils.loseFocus(editMeters); manageMeters(main, main.getUIState().currentItem); } }); meterHeader.addComponent(editMeters); meterHeader.setComponentAlignment(editMeters, Alignment.BOTTOM_CENTER); } main.properties.addComponent(meterHeader); main.properties.setComponentAlignment(meterHeader, Alignment.MIDDLE_CENTER); VerticalLayout meters = new VerticalLayout(); boolean showYears = main.getUIState().time.equals(Property.AIKAVALI_KAIKKI); Property time = Property.find(database, Property.AIKAVALI); int index = 0; for (final MeterDescription desc : descs) { ArrayList<String> excelRow = new ArrayList<String>(); final Meter meter = desc.meter; final HorizontalLayout hl = new HorizontalLayout(); hl.addStyleName((((index++) & 1) == 0) ? "evenProperty" : "oddProperty"); hl.setSpacing(true); Label l = new Label(desc.caption); excelRow.add(l.getValue().replace("%nbsp", "")); l.setContentMode(ContentMode.HTML); l.setWidth("450px"); l.addStyleName("propertyName"); l.setData(desc); hl.addComponent(l); hl.setComponentAlignment(l, Alignment.MIDDLE_LEFT); String value = updateMeterValue(main, hl, base, meter, canWrite); excelRow.add(value); String shortComment = ""; Indicator indicator = meter.getPossibleIndicator(database); if (indicator != null) shortComment = indicator.getValueShortComment(); Label comment = new Label(shortComment); comment.setWidth("150px"); hl.addComponent(comment); hl.setComponentAlignment(comment, Alignment.MIDDLE_LEFT); excelRow.add(comment.getValue()); if (showYears) { HorizontalLayout hl2 = new HorizontalLayout(); hl2.setWidth("70px"); hl2.setHeight("100%"); hl.addComponent(hl2); hl.setComponentAlignment(hl2, Alignment.MIDDLE_LEFT); String years = time.getPropertyValue(meter); if (years == null) years = Property.AIKAVALI_KAIKKI; final Label region = new Label(years); region.setWidthUndefined(); excelRow.add(region.getValue()); hl2.addComponent(region); hl2.setComponentAlignment(region, Alignment.MIDDLE_CENTER); } AbsoluteLayout image = new AbsoluteLayout(); image.setWidth("32px"); image.setHeight("32px"); image.addStyleName("meterColor" + index); String color = meter.getTrafficColor(database); Styles styles = Page.getCurrent().getStyles(); styles.add( ".fi_semantum_strategia div." + "meterColor" + index + " { background: " + color + "; }"); hl.addComponent(image); hl.setComponentAlignment(image, Alignment.MIDDLE_CENTER); hl.setExpandRatio(image, 0.0f); meters.addComponent(hl); meters.setComponentAlignment(hl, Alignment.MIDDLE_CENTER); ThemeResource res = desc.meter.showInMap ? new ThemeResource("zoom.png") : new ThemeResource("zoom_out.png"); final Image show = new Image(); show.setSource(res); show.setHeight("24px"); show.setWidth("24px"); if (canWrite) { show.setDescription("Klikkaamalla voit valita, nytetnk mittaria strategiakartassa"); show.addClickListener(new MouseEvents.ClickListener() { private static final long serialVersionUID = 7156984656942915939L; @Override public void click(com.vaadin.event.MouseEvents.ClickEvent event) { desc.meter.setShowInMap(!desc.meter.showInMap); Updates.update(main, true); } }); } hl.addComponent(show); hl.setComponentAlignment(show, Alignment.MIDDLE_CENTER); final Image wiki = new Image(); wiki.setSource(new ThemeResource("table_edit.png")); wiki.setHeight("24px"); wiki.setWidth("24px"); wiki.setDescription("Klikkaamalla voit siirty tausta-asiakirjaan"); wiki.addClickListener(new MouseEvents.ClickListener() { private static final long serialVersionUID = 7156984656942915939L; @Override public void click(com.vaadin.event.MouseEvents.ClickEvent event) { Wiki.openWiki(main, desc.meter); } }); hl.addComponent(wiki); hl.setComponentAlignment(wiki, Alignment.MIDDLE_CENTER); if (canWrite) { final Button principalButton = new Button(); if (meter.isPrincipal) { principalButton.setCaption("Poista kokonaisarvio"); } else { principalButton.setCaption("Aseta kokonaisarvioksi"); } principalButton.setStyleName(ValoTheme.BUTTON_TINY); principalButton.addClickListener(new ClickListener() { private static final long serialVersionUID = 8247560202892661226L; @Override public void buttonClick(ClickEvent event) { if (meter.isPrincipal) { meter.isPrincipal = false; } else { for (Meter m : base.getMeters(database)) m.isPrincipal = false; meter.isPrincipal = true; } Updates.update(main, true); } }); hl.addComponent(principalButton); hl.setComponentAlignment(principalButton, Alignment.MIDDLE_CENTER); } main.propertyCells.add(excelRow); } meters.addLayoutClickListener(new LayoutClickListener() { private static final long serialVersionUID = 3295743025581923380L; private String extractData(Component c) { if (c instanceof AbstractComponent) { Object data = ((AbstractComponent) c).getData(); if (data instanceof MeterDescription) { MeterDescription desc = (MeterDescription) data; return desc.meter.getDescription(database); } } return null; } @Override public void layoutClick(LayoutClickEvent event) { String desc = extractData(event.getClickedComponent()); if (desc == null) return; String content = "<div style=\"width: 700px; border: 2px solid; padding: 5px\">"; content += "<div style=\"text-align: center; white-space:normal; font-size: 36px; padding: 10px\">" + desc + "</div>"; content += "</div>"; Notification n = new Notification(content, Notification.Type.HUMANIZED_MESSAGE); n.setHtmlContentAllowed(true); n.show(Page.getCurrent()); } }); main.properties.addComponent(meters); main.properties.setComponentAlignment(meters, Alignment.MIDDLE_CENTER); } }
From source file:fr.amapj.view.engine.grid.currencyvector.PopupCurrencyVector.java
License:Open Source License
private void addRow(int lig) { List<Object> cells = new ArrayList<Object>(); Label dateLabel = new Label(param.leftPartLine.get(lig)); dateLabel.addStyleName("date-saisie"); dateLabel.setWidth(param.largeurCol + "px"); cells.add(dateLabel);/*from ww w . j a v a 2s . c o m*/ int qte = param.montant[lig]; boolean isExcluded = isExcluded(lig); if (param.readOnly) { // String txt; if (isExcluded) { txt = "XXXXXX"; } else if (qte == 0) { txt = ""; } else { txt = "" + new CurrencyTextFieldConverter().convertToString(qte); } Label tf = new Label(txt); tf.addStyleName("cell-voir"); tf.setWidth((param.largeurCol - 10) + "px"); cells.add(tf); } else { if (isExcluded) { TextField tf = new TextField(); tf.setValue("XXXXXX"); tf.setEnabled(false); tf.addStyleName("cell-voir"); tf.setWidth((param.largeurCol - 10) + "px"); cells.add(tf); } else { // // Si derniere ligne : on autorise les nombres ngatifs (sauf si on en mode de saisie de la dernire ligne) boolean allowNegativeNumber = (lig == param.nbLig - 1) && (param.computeLastLine == true); final TextField tf = BaseUiTools.createCurrencyField("", allowNegativeNumber); tf.setData(new GridIJData(lig, 0)); tf.setConvertedValue(new Integer(qte)); tf.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { try { updateModele(); } catch (ErreurSaisieException e) { NotificationHelper.displayNotificationMontant(); } } }); tf.addStyleName("cell-saisie"); tf.setWidth((param.largeurCol - 10) + "px"); shortCutManager.registerTextField(tf); cells.add(tf); // Si derniere ligne : on desactive la saisie , sauf si pas de recalcul if ((lig == param.nbLig - 1) && (param.computeLastLine == true)) { tf.setEnabled(false); lastLineTextField = tf; } } } table.addItem(cells.toArray(), new Integer(lig)); }
From source file:fr.amapj.view.engine.grid.integergrid.PopupIntegerGrid.java
License:Open Source License
private void addRow(int lig) { List<Object> cells = new ArrayList<Object>(); Label dateLabel = new Label(param.leftPartLine.get(lig), ContentMode.HTML); dateLabel.addStyleName(param.leftPartLineStyle); cells.add(dateLabel);// ww w. ja va2 s . c o m for (int j = 0; j < param.nbCol; j++) { int qte = param.qte[lig][j]; boolean isExcluded = isExcluded(lig, j); // En lecture simple if (param.readOnly) { // String txt; if (isExcluded) { txt = "XXXXXX"; } else if (qte == 0) { txt = ""; } else { txt = "" + qte; } Label tf = new Label(txt); tf.addStyleName("cell-voir"); tf.setWidth((param.largeurCol - 10) + "px"); cells.add(tf); } // En mode normal else { // Si la cellule est exclue if (isExcluded) { TextField tf = new TextField(); tf.setValue("XXXXXX"); tf.setEnabled(false); tf.addStyleName("cell-voir"); tf.setWidth((param.largeurCol - 10) + "px"); cells.add(tf); } else { // final TextField tf = BaseUiTools.createQteField(""); tf.setData(new GridIJData(lig, j)); if (qte == 0) { tf.setConvertedValue(null); } else { tf.setConvertedValue(new Integer(qte)); } tf.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { try { GridIJData ij = (GridIJData) tf.getData(); int qte = readValueInCell(tf); param.updateQte(ij.i(), ij.j(), qte); displayMontantTotal(); } catch (ErreurSaisieException e) { NotificationHelper.displayNotificationQte(); } } }); tf.addStyleName("cell-saisie"); tf.setWidth((param.largeurCol - 10) + "px"); shortCutManager.registerTextField(tf); cells.add(tf); } } } table.addItem(cells.toArray(), new Integer(lig)); }
From source file:rs.pupin.jpo.esta_ld.EstaLdComponent.java
private void refreshDimensions() { // clean everything just in case dimLayout.removeAllComponents();/* ww w. j a v a 2 s . com*/ geoDimension = null; timeDimension = null; measures = null; btnGeo = null; boxGeo = null; dimNames = null; dimValues = null; if (selectDataSet.getValue() == null) return; // VerticalLayout lLayout = new VerticalLayout(); // lLayout.setSizeUndefined(); // lLayout.setSpacing(true); // lLayout.setDebugId("dim-btn-layout"); // dimLayout.addComponent(lLayout); // VerticalLayout rLayout = new VerticalLayout(); // rLayout.setSizeUndefined(); // rLayout.setSpacing(true); // rLayout.setWidth("100%"); // dimLayout.addComponent(rLayout); // dimLayout.setExpandRatio(rLayout, 2.0f); final DataSet ds = (DataSet) selectDataSet.getValue(); measures = ds.getStructure().getMeasures(); StringBuilder builderMeasures = new StringBuilder(); StringBuilder builderMeasureNames = new StringBuilder(); for (Measure m : measures) { builderMeasures.append(", '"); builderMeasures.append(m.getUri()); builderMeasures.append("'"); if (m.getLabel() != null) { builderMeasureNames.append(", '"); builderMeasureNames.append(m.getLabel()); builderMeasureNames.append("'"); } else { builderMeasureNames.append(", undefined"); } } builderMeasureNames.replace(0, 2, "[").append("]"); builderMeasures.replace(0, 2, "javaSetMeasures(["); builderMeasures.append("], ").append(builderMeasureNames.toString()).append(")"); getWindow().executeJavaScript(builderMeasures.toString()); measName = new Button("Measure"); // measName.setSizeUndefined(); // measName.setWidth("100%"); measName.setHeight(CONTENT_ELEM_HEIGHT); measName.setWidth(CONTENT_ELEM_WIDTH); measName.addStyleName("dim-name"); measName.addStyleName("unselectable"); measValues = new ComboBox(null, measures); measValues.setImmediate(true); measValues.setSizeUndefined(); measValues.setWidth("100%"); measValues.setHeight(CONTENT_ELEM_HEIGHT); measValues.addStyleName("dim-value"); measValues.setNullSelectionAllowed(false); measValues.select(measures.iterator().next()); measValues.addListener(dimListener); // measValues.addListener(new Property.ValueChangeListener() { // public void valueChange(Property.ValueChangeEvent event) { // Measure m = (Measure)event.getProperty().getValue(); // // put measure in // } // }); int rowIndex = 0; int columnIndex = 0; dimLayout.addComponent(measName, columnIndex, rowIndex); columnIndex++; // dimLayout.setExpandRatio(measName, 2.0f); dimLayout.addComponent(measValues, columnIndex, rowIndex, columnIndex + 1, rowIndex); columnIndex += 2; // dimLayout.setComponentAlignment(measValues, Alignment.BOTTOM_LEFT); LinkedList<Dimension> dimsForShow = new LinkedList<Dimension>(); for (Dimension dim : ds.getStructure().getDimensions()) { if (dim.isGeoDimension()) geoDimension = dim; else if (dim.isTimeDimension()) { timeDimension = dim; dimsForShow.addFirst(dim); } else dimsForShow.add(dim); } dimNames = new Button[dimsForShow.size()]; dimAggregIndicators = new Label[dimsForShow.size()]; dimValues = new ComboBox[dimsForShow.size()]; int i = 0; StringBuilder builderPossibleValues = new StringBuilder(); boolean firstPass = true; for (Dimension dim : dimsForShow) { // add dimension pick // first create a button to represent dimension name final Button btnName = new Button(dim.toString()); // btnName.setSizeUndefined(); // btnName.setWidth("100%"); btnName.setHeight(CONTENT_ELEM_HEIGHT); btnName.setWidth(CONTENT_ELEM_WIDTH); btnName.setData(dim); btnName.addStyleName("dim-name"); if (firstPass) { btnName.addStyleName("selected"); firstPass = false; } btnName.addListener(new Button.ClickListener() { public void buttonClick(Button.ClickEvent event) { if (btnName.getStyleName().contains("selected")) { btnName.removeStyleName("selected"); } else { btnName.addStyleName("selected"); } freeDimensionsChanged(); } }); dimNames[i] = btnName; final Label btnAggreg = new Label("<span>Σ</span>", Label.CONTENT_XHTML); btnAggreg.setWidth("30px"); btnAggreg.setHeight(CONTENT_ELEM_HEIGHT); btnAggreg.setData(dim); btnAggreg.addStyleName("dim-name"); btnAggreg.addStyleName("dim-aggreg"); // this will have to go to the layout listener // btnAggreg.addListener(new Button.ClickListener() { // public void buttonClick(Button.ClickEvent event) { // if (btnAggreg.getStyleName().contains("selected")) { // btnAggreg.removeStyleName("selected"); // } else { // btnAggreg.addStyleName("selected"); // aggregDimensionsChanged(); // } // } // }); dimAggregIndicators[i] = btnAggreg; // create a combo box for picking dimension value Collection<Value> vals = ds.getValuesForDimension(dim); Collection<ValueWrapper> valsWrapped = new LinkedList<ValueWrapper>(); for (Value v : vals) valsWrapped.add(new ValueWrapper(v)); builderPossibleValues.append(",").append(stringifyCollection(vals)); ComboBox boxValue = new ComboBox(null, valsWrapped); boxValue.setImmediate(true); boxValue.setNullSelectionAllowed(false); if (valsWrapped.iterator().hasNext()) boxValue.select(valsWrapped.iterator().next()); else boxValue.setEnabled(false); boxValue.setSizeUndefined(); boxValue.setWidth("100%"); boxValue.setHeight(CONTENT_ELEM_HEIGHT); boxValue.addStyleName("dim-value"); boxValue.addListener(dimListener); dimValues[i] = boxValue; // put them in a horizontal layout and add to the view // HorizontalLayout layout = new HorizontalLayout(); // layout.setSizeUndefined(); // layout.setWidth("100%"); // layout.setSpacing(true); // dimLayout.addComponent(layout); // dimLayout.setExpandRatio(layout, 2.0f); // layout.addComponent(btnName); // layout.addComponent(boxValue); // layout.setExpandRatio(boxValue, 2.0f); // lLayout.addComponent(btnName); // lLayout.setExpandRatio(btnName, 2.0f); // rLayout.addComponent(boxValue); // rLayout.setComponentAlignment(boxValue, Alignment.BOTTOM_LEFT); dimLayout.addComponent(btnName, columnIndex, rowIndex); if (++columnIndex == 6) { columnIndex = 0; rowIndex++; dimLayout.setRows(rowIndex + 1); } dimLayout.addComponent(btnAggreg, columnIndex, rowIndex); if (++columnIndex == 6) { columnIndex = 0; rowIndex++; dimLayout.setRows(rowIndex + 1); } dimLayout.addComponent(boxValue, columnIndex, rowIndex); if (++columnIndex == 6) { columnIndex = 0; rowIndex++; dimLayout.setRows(rowIndex + 1); } i++; } if (timeDimension != null) getWindow().executeJavaScript("javaSetHasTimeDimension(true)"); else getWindow().executeJavaScript("javaSetHasTimeDimension(false)"); if (geoDimension != null) { btnGeo = new Button(geoDimension.toString()); // btnGeo.setSizeUndefined(); // btnGeo.setWidth("100%"); btnGeo.setHeight(CONTENT_ELEM_HEIGHT); btnGeo.setWidth(CONTENT_ELEM_WIDTH); btnGeo.setData(geoDimension); btnGeo.addStyleName("dim-name"); btnGeo.addStyleName("geo-name"); btnGeo.addListener(new Button.ClickListener() { public void buttonClick(Button.ClickEvent event) { if (btnGeo.getStyleName().contains("selected")) { btnGeo.removeStyleName("selected"); } else { btnGeo.addStyleName("selected"); } freeDimensionsChanged(); } }); btnAggregGeo = new Label("<span>Σ</span>", Label.CONTENT_XHTML); btnAggregGeo.setHeight(CONTENT_ELEM_HEIGHT); btnAggregGeo.setData(geoDimension); btnAggregGeo.addStyleName("dim-name"); btnAggregGeo.addStyleName("dim-aggreg"); StringBuilder builder = new StringBuilder(); Collection<Value> posVals = ds.getValuesForDimension(geoDimension); Collection<ValueWrapper> posValsWrapped = new LinkedList<ValueWrapper>(); for (Value v : posVals) posValsWrapped.add(new ValueWrapper(v)); Value selectedVal = posVals.iterator().next(); String selectedValString = ""; if (selectedVal instanceof URI) { selectedValString = "<" + selectedVal.stringValue() + ">"; } else { selectedValString = "\"" + selectedVal.stringValue() + "\""; URI dataType = ((Literal) selectedVal).getDatatype(); if (dataType != null && !dataType.stringValue().contains("string")) { selectedValString += "^^<" + dataType.stringValue() + ">"; } } builder.append("javaSetGeoAll('").append(geoDimension.getUri()); builder.append("',").append(stringifyCollection(posVals)); builder.append(",'").append(selectedValString).append("',true)"); boxGeo = new ComboBox(null, posValsWrapped); boxGeo.setData(posVals); boxGeo.setImmediate(true); boxGeo.setNullSelectionAllowed(false); boxGeo.select(posValsWrapped.iterator().next()); boxGeo.setSizeUndefined(); boxGeo.setWidth("100%"); boxGeo.setHeight(CONTENT_ELEM_HEIGHT); boxGeo.addStyleName("geo-value"); boxGeo.addListener(geoListener); // lLayout.addComponent(btnGeo); // lLayout.setExpandRatio(btnGeo, 2.0f); // rLayout.addComponent(boxGeo); // rLayout.setComponentAlignment(boxGeo, Alignment.BOTTOM_LEFT); dimLayout.addComponent(btnGeo, columnIndex, rowIndex); columnIndex++; dimLayout.addComponent(btnAggregGeo, columnIndex, rowIndex); columnIndex++; dimLayout.addComponent(boxGeo, columnIndex, rowIndex); columnIndex++; getWindow().executeJavaScript(builder.toString()); } else { getWindow().executeJavaScript("javaSetGeoAll('',[],'',true)"); } // TODO cover the case where there is more than 1 geo dimension builderPossibleValues.replace(0, 1, "javaSetPossibleValues(["); builderPossibleValues.append("])"); getWindow().executeJavaScript(builderPossibleValues.toString()); if (dimsForShow.isEmpty()) { if (geoDimension != null) getWindow().executeJavaScript("javaSetGeoFree(true)"); else getWindow().executeJavaScript("javaSetGeoFree(false)"); getWindow().executeJavaScript("javaSetFreeDimensions([], true)"); } else { getWindow().executeJavaScript("javaSetGeoFree(false)"); getWindow().executeJavaScript("javaSetFreeDimensions([0], true)"); } dimListener.valueChange(null); getWindow().executeJavaScript("setTimeout(expandDimNameButtons(),200)"); }