I have grid in my Vaadin project. I need to edit the cell/s by click on the cell. I dont need buffered mode, but I need help with this.
My grid code:
Grid grid = new Grid();
IndexedContainer container = new IndexedContainer();
grid.setContainerDataSource(container);
container.addContainerProperty("March",String.class, "");
container.addContainerProperty("January",String.class, "");
container.addContainerProperty("February",String.class, "");
grid.getColumn("March").setEditable(true);
grid.getColumn("January").setEditable(true);
grid.getColumn("February").setEditable(true);
container.addItem(1);
Item item = container.getItem(1);
item.getItemProperty("March").setValue("01.03.2017");
grid.setSelectionMode(SelectionMode.NONE);
//Here I want have my addItemClickListener
grid.addItemClickListener(event ->
Notification.show("Y: " + event.getPropertyId() + " X: " + event.getItemId()));
I want change the cell "01.03.2017" E.G to "Something else". Or add a new data to the free cells from other Container property. Thanks !
Add grid.setEditorEnabled(true);
Related
I am doing a selenium test against a web page which returns a table with some rows and columns showing payment data. I'm trying to strip some characters/words from the result of the XPATH i'm using because i dont need the part while doing an assertion (check if the data in table is correct).
Normally the webpage also returns a "Dropdown Button" as text (there is an icon), just before the identification number (e.g 168.3285.6021 as seen below).
What i used is it.set(it.next().replaceAll("DropDown Arrow ","")); so the DropDown Arrow text is replaced with nothing, which only works for the first line, but the other 2 lines don't get replaced. Any tips?
public void check_receivals() {
// Check how many lines and assert the size (from xpath)
List<WebElement> Receivals = driver.findElements(By.xpath("//*[#id='received-overview']//div[#class='bdpo-overview-table-row']/div[#class='claims']"));
System.out.println(Receivals.size() + " receival lines found");
assertEquals(7, Receivals.size());
// Test data to compare against..aka expectedResultList
List<String> expectedResultList = new ArrayList<>();
expectedResultList.add ("168.3285.6021\n" + "Payment 2015\n" + "01-01-2015\n" + "€ 246");
expectedResultList.add ("143.8407.8413\n" + "Payment 2015\n" + "01-01-2015\n" + "€ 233");
expectedResultList.add ("154.2841.2407\n" + "Payment 2015\n" + "01-01-2015\n" + "€ 253");
// Assert
List<WebElement> ReceivalLines = driver.findElements(By.xpath("//*[#id='received-overview']//div[#class='bdpo-overview-table-row']/div[#class='claims']"));
List<String> ReceivalLines_List = ReceivalLines.stream().map(WebElement::getText).collect(Collectors.toList());
ListIterator<String> it = ReceivalLines_List.listIterator();
while(it.hasNext()) {
it.set(it.next().replaceAll("DropDown Arrow ",""));
assertEquals(ReceivalLines_List, expectedResultList);
THe issue is that you are modifying the iterator as you are working with it. I would suggest making the replace part of the stream operation using the map function.
List<String> ReceivalLines_List = ReceivalLines.stream().map(WebElement::getText).map(s -> s.replaceAll("DropDown Arrow ","")).collect(Collectors.toList());
I am trying to produce several reports (i.e. N PPTX files) based on different inputs/for different users on the same PPTX template I created.
I have several preformatted XSLFTextShape on the PPTX template that contains a single XSLFTextParagraph already formatted (i.e. both the shape and the text). Each shape contains a particular placeholder that I need to substitute with a dynimic value. I have this value in a Map (placeholder,newValue). I am successful in updating the placeholder with the new value using:
textShape.clearText();
XSLFTextRun run = paragraph.addNewTextRun();
run.setText(newText);
So, when I produce the PPTX in output the text is updated but font color, font formatting, font size are changed compared to those I defined in the template. How can I keep the same formatting?
Any solutions to simply change the text while keeping original formatting?
Thanks in advance!
For everybody which may be interested in this topic in the future - I post the solution (working if one TextBox has a single Paragraph). This solution loops on all text boxes and in the case one contain one of the vales specified in the Placeholder->newValue map, it will update it maintaining the formatting.
public static void updateTextBoxesWithDesiredValues(XMLSlideShow ppt, Map<String, String> placeHolderDefinedValue) {
logger.info("ElapsedTime: " + tM.getTimeElapsedReadableFormat() + " ########## Updating single text box content...");
List<XSLFSlide> allSlides = ppt.getSlides();
int updatedElements = 0;
for (XSLFSlide currentSlide : allSlides) {
for (XSLFShape shape : currentSlide.getShapes()) {
if (shape instanceof XSLFTextShape) {
XSLFTextShape textBox = (XSLFTextShape) shape;
String elementTextContent = textBox.getText();
for (Object key : placeHolderDefinedValue.keySet()) {
if (elementTextContent.equals(key)) {
List<XSLFTextParagraph> textBoxParagraphs = textBox.getTextParagraphs();
List<XSLFTextRun> textBoxParagraphTextRuns = textBoxParagraphs.get(0).getTextRuns();
//System.out.println("########################## check paragraph number in textbox: " + textBoxParagraphs.size() + " - TextRuns: " + textBoxParagraphs.get(0).getTextRuns().size());
logger.info("ElapsedTime: " + tM.getTimeElapsedReadableFormat() + updatedElements + ") Updating: " + textBox.getText() + " --> " + placeHolderDefinedValue.get(key));
for (XSLFTextRun r : textBoxParagraphTextRuns) {
r.setText(placeHolderDefinedValue.get(key));
}
updatedElements++;
//break;
}
}
}
}
}
logger.info("ElapsedTime: " + tM.getTimeElapsedReadableFormat() + " Total Text Element Content Updated: " + updatedElements + " #########################");
}
It's kind of horrible - but yeah there's a reason they called it "POI".
Here's my approach to "only reset text" of an existing XSLFTextShape (that must have at least some text pre-set!):
textShape.getTextParagraphs().get(0).getTextRuns().get(0).setText(text);
for (int i = 1; i < textShape.getTextParagraphs().get(0).getTextRuns().size(); i++) {
textShape.getTextParagraphs().get(0).getTextRuns().get(i).setText("");
}
for (int i = 1; i < textShape.getTextParagraphs().size(); i++) {
textShape.getTextParagraphs().get(i).getTextRuns().stream().filter(tr -> !tr.getRawText().equals("\n")).forEach(tr -> tr.setText(""));
}
It will replace all existing text(paragraphs/runs) with "empty" text, but linebreaks can't be replaced for some reason. So this might leave you with some trailing lines - as they usually(!) are transparent this won't really hurt a lot.
.clearText / removing paragraphs either destoyed the formatting for me, or didn't work. Trying to reset the style (fontColor, fontFamily, fontSize, isBold, isItalit, ...) didn't result in satisfying results :(
In this example, an image of a map is set on a ScrollPane in the FXML file.
http://hg.openjdk.java.net/openjfx/8u-dev/rt/rev/36a59c629605
The image is resizable by some other method that changes the scale of the Group - zoomGroup - containing the image.
+ private void zoom(double scaleValue) {
+// System.out.println("airportapp.Controller.zoom, scaleValue: " + scaleValue);
+ double scrollH = map_scrollpane.getHvalue();
+ double scrollV = map_scrollpane.getVvalue();
+ zoomGroup.setScaleX(scaleValue);
+ zoomGroup.setScaleY(scaleValue);
+ map_scrollpane.setHvalue(scrollH);
+ map_scrollpane.setVvalue(scrollV);
+ }
But in order to make sure the ScrollPane re-computes its scrollbars (so the scrollable area effectively changes to include the entire image at any scale) the Group that wraps the Image, zoomGroup, is then wrapped in another Group, contentGroup, which is set as the ScrollPane's content.
+ // Wrap scroll content in a Group so ScrollPane re-computes scroll bars
+ Group contentGroup = new Group();
+ zoomGroup = new Group();
+ contentGroup.getChildren().add(zoomGroup);
+ zoomGroup.getChildren().add(map_scrollpane.getContent());
+ map_scrollpane.setContent(contentGroup);
Can someone explain why this is necessary?
This is the video that accompanies the files:
https://www.youtube.com/watch?v=ij0HwRAlCmo
I am editing .jasper file using report tool. I am changing the alignment for parameter left to centre then i save that file. it generates the "jrxml" file also. in my Java code I can pass the .jasper location to print some items. but my changes not affect and the old design remains same..
Help me , How can I edit and save .jasper???
public static JasperPrint createRefundPrint(Ticket ticket, HashMap map) throws Exception {
final String FILE_RECEIPT_REPORT = "/com/floreantpos/report/template/RefundReceipt.jasper";
TicketDataSource dataSource = new TicketDataSource(ticket);
return createJasperPrint(FILE_RECEIPT_REPORT, map, new JRTableModelDataSource(dataSource));
}
if you use a IReport for editing your .jrxml reports, you should just press the "Preview" button. Then the .jasper report file will be generated automatically in folder that contains the .jrxml file
To edit jasper report, you make your changes in the JRXML file. Once you build or compile your report it will generate a .jasper file which is used in your java code.
you try make dynamic report.
You do not have a location problem when you generate your own report.
Example;
public JasperDesign createDesign() throws JRException {
JasperDesign jasperDesign = new JasperDesign();
jasperDesign.setName("sampleDynamicJasperDesign");
jasperDesign.setPageWidth(595); // page width
jasperDesign.setPageHeight(842); // page height
jasperDesign.setColumnWidth(515); // column width of page
jasperDesign.setColumnSpacing(0);
jasperDesign.setLeftMargin(40);
jasperDesign.setRightMargin(40);
jasperDesign.setTopMargin(20);
jasperDesign.setBottomMargin(20);
JRDesignExpression expression = new JRDesignExpression();
//Set style of page.
JRDesignStyle normalStyle = new JRDesignStyle();
normalStyle.setName("Sans_Normal");
normalStyle.setDefault(true);
normalStyle.setFontName("DejaVu Sans");
normalStyle.setFontSize(12);
normalStyle.setPdfFontName("Helvetica");
normalStyle.setPdfEncoding("Cp1252");
normalStyle.setPdfEmbedded(false);
jasperDesign.addStyle(normalStyle);
/*
* Generate field dynamically
* */
JRDesignField field = new JRDesignField();
field.setName("firstName");
field.setValueClass(String.class);
jasperDesign.addField(field);
field = new JRDesignField();
field.setName("lastName"); // set name for field.
field.setValueClass(String.class); // set class for field. Its always depends upon data type which we want to get in this field.
jasperDesign.addField(field); // Added field in design.
field = new JRDesignField();
field.setName("age");
field.setValueClass(Integer.class);
jasperDesign.addField(field);
JRDesignBand band = new JRDesignBand();
//Title Band
band = new JRDesignBand();
band.setHeight(30);
JRDesignStaticText staticText = new JRDesignStaticText();
staticText.setText("Person's Specification");
staticText.setX(0);
staticText.setY(0);
staticText.setHeight(20);
staticText.setWidth(515);
staticText.setHorizontalAlignment(HorizontalAlignEnum.CENTER);
band.addElement(staticText);
jasperDesign.setTitle(band);
band = new JRDesignBand(); // New band
band.setHeight(20); // Set band height
/*Create text field dynamically*/
JRDesignTextField textField = new JRDesignTextField();
textField.setX(0); // x position of text field.
textField.setY(0); // y position of text field.
textField.setWidth(160); // set width of text field.
textField.setHeight(20); // set height of text field.
JRDesignExpression jrExpression = new JRDesignExpression(); // new instanse of expression. We need create new instance always when need to set expression.
jrExpression.setText(""" + "First Name: " + """ + "+" + "$F{firstName}"); // Added String before field in expression.
textField.setExpression(jrExpression); // set expression value in textfield.
band.addElement(textField); // Added element in textfield.
textField = new JRDesignTextField();
textField.setX(160);
textField.setY(0);
textField.setWidth(160);
textField.setHeight(20);
jrExpression = new JRDesignExpression();
jrExpression.setText("$F{lastName}" + "+" + """ + " :Last Name" + """); // Added string after field value
textField.setExpression(jrExpression);
band.addElement(textField);
textField = new JRDesignTextField();
textField.setX(320);
textField.setY(0);
textField.setWidth(160);
textField.setHeight(20);
jrExpression = new JRDesignExpression();
String age = """ + "<font>" + """ + "+" + """ + "Age is: " + """ + "+" + """ + "</font><font>" + """ + "+" + "$F{age}" + "+" + """ + "</font>" + """; // added html in text field with different color.
jrExpression.setText(age);
textField.setExpression(jrExpression);
textField.setMarkup("html"); // By Default markup is none, We need to set it as html if we set expression as html.
band.addElement(textField);
((JRDesignSection) jasperDesign.getDetailSection()).addBand(band);
return jasperDesign;
}
You can compile a .jrxml in Project Explorer window of Jaspersoft Studio. For that first find your .jrxml report and rightclick on it. In context menu choose 'Compile report'. Then you get compiled .jasper report.
As it says on the tin.. I cannot get a label's text to wrap. Essentially I am building like a comments panel, user enters a comment and its displayed with timestamp etc.
I want the labels to both display with ContentMode.PREFORMATTED but also wrap.
The layouts of which contain the label are fixed width (100%) as is the label obviously by default, from what I have readin the book of vaadin what I am doing should work?
here is my code snippet:
VerticalLayout container = new VerticalLayout();
rootLayout.addComponent(container);
VerticalLayout comment = new VerticalLayout();
container.addComponent(comment);
Label createdByLbl = new Label(entity.getManagedMetadata().getAttrValue("createdBy") + " said:");
createdByLbl.setId("conversation.comment.username." + repositoryUID);
createdByLbl.setStyleName("conversation-comment-username");
Label createdDateLbl = new Label(entity.getManagedMetadata().getAttrValue("createdDate"));
createdDateLbl.setId("conversation.comment.createddate." + repositoryUID);
createdDateLbl.setSizeUndefined();
String text = entity.getDataNode().getAttrValue("text");
Label textLbl = new Label(text, ContentMode.PREFORMATTED);
textLbl.setId("conversation.comment.text." + repositoryUID);
comment.addComponent(createdByLbl);
comment.addComponent(textLbl);
comment.addComponent(createdDateLbl);
comment.setExpandRatio(createdByLbl, 0.2f);
comment.setExpandRatio(textLbl, 0.7f);
comment.setExpandRatio(createdDateLbl, 0.1f);
Note the container is also wrapped by CssLayout (rootLayout), which is full sized.
I want the textLbl as seen above to display as formatted should the user enter text on separate lines themselves and wrap if they have entered a long paragraph comment.
Here is a picturing showing my dilemma.
Any help would be appreciated.
Thanks,
Try with css.
For example:
textLbl.addStyleName("wrapLine");
Css:
.wrapLine{
word-wrap: break-word; /* IE */
white-space: -moz-pre-wrap; /* Firefox */
}