I have had a look at it
It is hard to tell whether it will allow me to add images to text in a cell or whether I can have more than one image in cell and use them as buttons
With regards to the documentation provided :
I can’t see how to get it to work in my project
It assumes too much knowledge from the user
The example code does not seem to be complete
Maybe I don’t have understood your question. Please, correct me if I’m wrong:
To add an image (or two or three depending on edit, delete etc) to a cell an then be able to click on it/them
You can add a generated property whoose generator creates the components you need in the cell (buttons or even images with click listener)
gpc.addGeneratedProperty("btns", new PropertyValueGenerator<Component>() {
public Component getValue(Item item, Object itemId, Object propertyId) {
return new HorizontalLayout(
new Button(FontAwesome.SAVE),
new Image(null, new ThemeResource("images/icon.png"))
);
}
public Class<Component> getType() { return Component.class; }
});
grid.addColumn("btns").setRenderer(new ComponentRenderer());
Add an image after the text in the cell - for example to highlight a problem to the user.
A solution could be add a custom CellStyleGenerator to the grid and add use CSS to show the image
Thank you for your response
I will certainly try it out when I get a moment
With regards to the text: I think the text you are displaying is more of a tooltip idea what I am after is a column of text and on certain items I need an image next to it displaying some sort of error icon - it would probably be much easier with a font awesome icon next to the text but sadly the images hav already been created and approved
I have a problem implimenting the first section
It tells me I have already a column for property id ‘btns’
Also I had a problem making the componentRendere work I had to change the code a bit:
grid.addColumn(“btns”).setRenderer((Renderer<?>) new ComponentRenderer());
That’s weird, it works for me; can you share some of your code?
For the cast in setRenderer check maybe yuo are importing the class from the wrong package;
it must be
de.datenhahn.vaadin.componentrenderer.ComponentRenderer not
de.datenhahn.vaadin.componentrenderer.client.ComponentRenderer
Hi I have tried again:
java.lang.IllegalStateException: A column for property id ‘btns’ already exists in this grid
at com.vaadin.ui.Grid.addColumn(Grid.java:5066)
at com.cbp.ui.transportRequest.TransportRequestView.getSearchResultComponent(TransportRequestView.java:300)
I have used you code
gpc.addGeneratedProperty(“btns”, new PropertyValueGenerator() {
public Component getValue(Item item, Object itemId, Object propertyId) {
return new HorizontalLayout(
new Button(FontAwesome.SAVE),
new Image(null, new ThemeResource(“images/table_images/add.png”))
);
}
public Class getType() { return Component.class; }
});
grid.addColumn(“btns”).setRenderer(new ComponentRenderer());
Ok, that happens to me when the container is given to the grid before the generated property is added.
To fix use
grid.getColumns(“btns”) instead of
grid.addColumn(“btns”)
Yes!
I made your change and I have another column with a button in it
It should be
grid.getColumn(“btns”) singular
thanks!
now for the next bit - you didn’t really answer my question on whwther your solution to text and image was the case of adding an occasional image to text or a tooltip for images (I wanted the former)
I added your
grid.setCellStyleGenerator(cell →
(“myCell”.equals(cell.getPropertyId()) && “err”.equals(cell.getValue().toString()))
? “my-cell-warning” : null
) ;
and I get Lambda expressions are not supported at this language level - not sure what to do about that
Secondly:
I changed the
new Image(null, new ThemeResource(“images/icon.png”))
to a button which worked nicely BUT
I want to apply a style to it so it doesn’t have the default button characteristics
I would normally .setStyleName to the component but it is part of the ‘new’ so I am not sure how to do that
I thought I might have had the answer for the style for the buttons :
final Button earlyButton = new Button(null, new ThemeResource("images/clock.png"));
final Button publishButton = new Button(null, new ThemeResource("images/publish.png"));
earlyButton.setStyleName("tableIcon");
publishButton.setStyleName("tableIcon");
gpc.addGeneratedProperty("addOrRemove", new PropertyValueGenerator<Component>() {
public Component getValue(Item item, Object itemId, Object propertyId) {
return new HorizontalLayout(
new Button(FontAwesome.SAVE),
earlyButton , publishButton
);
}
public Class<Component> getType() { return Component.class; }
});
grid.getColumn("addOrRemove").setRenderer(new ComponentRenderer());
but they dont appear at all now - inspecting the element - there is only the icon no images ;-(