Do you know any components in smartgwt in order to do some like this?
I´ve done it using several componets, Labels, Camva, Img, Layouts....
Thanks
Well, I have found this option SC.showPrompt and SC.clearPrompt but I think that it´s not possible add images into of panel.
I did this in the past you can have a try
public class Attente extends Window{
private Label message = new Label();
public String getMessage() {
return message.getTitle();
}
public void setMessage(String message) {
this.message.setContents(message) ;
}
private Img image = new Img("64/Wait-icon.png",64,64);
/**
* Instantie un nouveau attente.
*/
public Attente(){
this.setTitle("Opération en cours, veuillez patienter");
this.setShowHeader(true);
this.centerInPage();
this.setAutoCenter(true);
this.setWidth(300);
this.setHeight(140);
this.setShowCloseButton(false);
this.setShowMinimizeButton(false);
this.setShowMaximizeButton(false);
VLayout layout = new VLayout();
HLayout hLayout = new HLayout();
message.setHeight(15);
message.setAlign(Alignment.CENTER);
message.setStyleName("plVersionCatalogue");
hLayout.addMember(new LayoutSpacer());
hLayout.addMember(image);
hLayout.addMember(new LayoutSpacer());
layout.addMember(new LayoutSpacer());
layout.addMember(hLayout);
layout.addMember(new LayoutSpacer());
layout.addMember(message);
this.addItem(layout);
}
}
And in the code I had a singleton instance of this class which I can use like this when I need:
MyContext.getAttente().show();
or
MyContext.getAttente().hide();
Related
I am using Vaadin 8 and I am facing a problem.
In my constructor, I create a grid which I add to a layout.
Grid<Row> grid = new Grid<>(); grid.removeAllColumns(); //Here, I add columns to the grid grid.addColumn(... grid.addColumn(… …
I then want to add a converter to my grid as follows:
grid.getColumn("delete").setConverter(new StringToUrlConverter("dustbin"));
What I do not understand is the error message indicating why I cannot add the converter. The error message is the folloing one:
The method setConverter(StringToUrlConverter) is undefined for the type >Grid.Column<ContactView.Row,capture#1-of ?>
So how do I have to set my converter?
This is my converter:
package com.example.vaadin;
import com.vaadin.data.Converter;
import com.vaadin.data.Result;
import com.vaadin.data.ValueContext;
public class StringToUrlConverter implements Converter<String, String> {
/**
*
*/
private static final long serialVersionUID = 1L;
String imagePath = "";
public StringToUrlConverter(String path) {
this.imagePath=path;
}
public String getImagePath() {
return imagePath;
}
#Override
public Result<String> convertToModel(String value, ValueContext context) {
return Result.ok(null);
}
#Override
public String convertToPresentation(String value, ValueContext context) {
if(value.equals("delete")) {
return "<span><img src='img/" + getImagePath() + ".jpg' width='20' height='20'></span>";
}
return "";
}
}
There is no setConverter method in Vaadin 8, it was in Vaadin 7. Instead in Vaadin 8 and newer versions you should use version of addColumn method with value provider. See old discussion in Vaadin's Forum.
StringToUrlConverter converter = new StringToUrlConverter (path);
grid.addColumn(row -> converter.convertToPresentation(row.getDelete(), String.class, ui.getLocale())).setCaption("Delete");
But, in your case you probably do not need that either. I see from your code that you simply want to add delete button or something like that in the Grid's cell.
You can add component in Grid from Vaadin 8 onwards using:
grid.addComponentColumn(row -> {
Image image = new Image();
image.setSrc(path);
image.addClickListener(event -> {
// add code to remove the row
grid.getDataProvider().refreshAll();
});
return image;
}
After implementing nested layouts i faced the problem with rendering component containing grid. The analysis shows that is present in html but it has display-block attributes and the grid is never visible.
I read the similar question (Vaadin 14 - Grid not Displaying/Populating When Used in Nested Layout) but the suggestions listed there brought me no result.
Here comes my code:
MainLayout.kt:
#Theme(value = Material::class, variant = Material.DARK)
class MainLayout : Composite<Div>(), RouterLayout {
//Component to delegate content through.
private val mainContent: Div = Div()
private val layout = VerticalLayout(
Span("from MainLayout top"),
mainContent,
Span("from MainLayout bottom"))
override fun showRouterLayoutContent(hasElement: HasElement) {
Objects.requireNonNull(hasElement)
Objects.requireNonNull(hasElement.element)
mainContent.removeAll()
mainContent.element.appendChild(hasElement.element)
}
init {
content.add(layout)
}
}
LayoutWithMenuBar.kt:
#ParentLayout(value = MainLayout::class)
class LayoutWithMenuBar : Composite<Div>(), RouterLayout {
private val mainContent: Div = Div()
private val menuBar = HorizontalLayout(
RouterLink("Home", MainView::class.java),
RouterLink("Tprojects", TProjectDashboard::class.java),
RouterLink("ViewA", ViewA::class.java),
RouterLink("ViewB", ViewB::class.java))
private val root = VerticalLayout(menuBar, mainContent)
override fun showRouterLayoutContent(hasElement: HasElement) {
Objects.requireNonNull(hasElement)
Objects.requireNonNull(hasElement.element)
mainContent.removeAll()
mainContent.element.appendChild(hasElement.element)
}
init {
content.add(root)
}
}
and a component containing grid - TProjectDashboard:
#Route("dashboard/tproject", layout = LayoutWithMenuBar::class)
class TProjectDashboard(#Autowired val tprojectService: TProjectService): VerticalLayout() {
var tprojectGrid = Grid<TProject>(TProject::class.java)
init {
//tprojectGrid
tprojectGrid.setColumns(
TProject::tprojectUuid.name,
TProject::tprojectClass.name,
TProject::tprojectState.name,
TProject::tentityState.name,
TProject::size.name)
tprojectGrid.setItems(tprojectService.findAll())
tprojectGrid.setSizeFull()
tprojectGrid.setWidthFull()
tprojectGrid.setHeightFull()
add(tprojectGrid)
setSizeFull()
setHeightFull()
setWidthFull()
}
}
The same result i have when changing TProjectDashboard parent from VerticalLayout to Composite.
The nested layouts approach works well for simple components like Span and if i remove layout reference from #Route annotation i will see my grid.
Here is the screen how it looks like now:
enter image description here
Would appreciate for any hints or solutions.
Thanks in advance.
It's probably a sizing issue that unfortunately happens too often. I would start with calling setSizeFull() on the mainContent div. If that doesn't help, go through the elements in the browser devtools and try to see where the size disappears, e.g. what is the first element that has 0 width or height.
Edit: Setting setSizeFull() on all components works. I would simplify your layouts slightly, though, by changing the composites to be of type VerticalLayout. Then you can get rid of a lot of the setSizeFull() calls.
The code below is in Java as I don't have Kotlin set up, you can call getContent().setSizeFull() in MainLayout if you want it to take the full height of the page.
MainLayout
#Theme(value = Material.class, variant = Material.DARK)
public class MainLayout extends Composite<VerticalLayout> implements RouterLayout {
//Component to delegate content through.
private Div mainContent = new Div();
public MainLayout() {
getContent().add(
new Span("from MainLayout top"),
mainContent,
new Span("from MainLayout bottom"));
mainContent.setSizeFull();
}
#Override
public void showRouterLayoutContent(HasElement hasElement) {
Objects.requireNonNull(hasElement);
Objects.requireNonNull(hasElement.getElement());
mainContent.removeAll();
mainContent.getElement().appendChild(hasElement.getElement());
}
}
LayoutWithMenuBar
#ParentLayout(value = MainLayout.class)
public class LayoutWithMenuBar extends Composite<VerticalLayout> implements RouterLayout {
private Div mainContent = new Div();
private HorizontalLayout menuBar = new HorizontalLayout(
new RouterLink("Tprojects", TProjectDashboard.class));
public LayoutWithMenuBar() {
getContent().add(menuBar, mainContent);
mainContent.setSizeFull();
}
#Override
public void showRouterLayoutContent(HasElement hasElement) {
Objects.requireNonNull(hasElement);
Objects.requireNonNull(hasElement.getElement());
mainContent.removeAll();
mainContent.getElement().appendChild(hasElement.getElement());
}
}
TProjectDashboard
#Route(value = "dashboard/tproject", layout = LayoutWithMenuBar.class)
public class TProjectDashboard extends VerticalLayout {
private Grid<TProject> tprojectGrid = new Grid<>(TProject.class);
public TProjectDashboard() {
tprojectGrid.setItems(
new TProject("Erik", "Software Engineer"),
new TProject("Fia", "Kindergarden teacher"),
new TProject("Jack", "All trades")
);
add(tprojectGrid);
}
}
I've come across an error saying i've reached the end of the file while parsing. I have an idea as to what to do, but am unsure as to where the missing Bracket should go. Please Help!
package fahrenheit;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Fahrenheit {
public static void main(String[] args) {
JFrame frame = new JFrame ("Fahrenheit to Celsius");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
FahrenheitPanel panel = new FahrenheitPanel();
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
public class FahrenheitPanel extends JPanel {
private JLabel inputLabel, outputLabel, resultLabel;
private JTextField fahrenheit;
public FahrenheitPanel() {
inputLabel = new JLabel ("Enter Fahrenheit Temperature:");
outputLabel = new JLabel ("Temperature in Celsius");
resultLabel = new JLabel ("---");
fahrenheit = new JTextField (5);
fahrenheit.addActionListener (new TempListener());
add (inputLabel);
add (fahrenheit);
add (outputLabel);
add (resultLabel);
setPreferredSize (new Dimension (300, 75));
setBackground (Color.yellow);
}
private class TempListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
int fahrenheitTemp, celsiusTemp;
String text = fahrenheit.getText();
fahrenheitTemp = Integer.parseInt (text);
celsiusTemp = (fahrenheitTemp-32) * 5/9;
resultLabel.setText (Integer.toString (celsiusTemp));
}
}
}
I am Really unsure as to where i need to place the bracket. PLEASE if someone could help that would be FANTASTIC!
Instead using
Integer.toString(...)
use
String.valueOf(...)
You cannot reference non-static classes in a static class. Make the FahrenheitPanel class static. And the posted code is missing a parenthesis at the very end.
I know that it is really easy to create a FileDownloader and call extend with a Button. But how do I start a download without the Button?
In my specific situation right now I have a ComboBox and the file I'd like to send to the user is generated after changing its value, based on the input. The file should be sent immediately without waiting for another click. Is that easily possible?
Thanks
raffael
I found a solution myself. Actually two.
The first one uses the deprecated method Page.open()
public class DownloadComponent extends CustomComponent implements ValueChangeListener {
private ComboBox cb = new ComboBox();
public DownloadComponent() {
cb.addValueChangeListener(this);
cb.setNewItemsAllowed(true);
cb.setImmediate(true);
cb.setNullSelectionAllowed(false);
setCompositionRoot(cb);
}
#Override
public void valueChange(ValueChangeEvent event) {
String val = (String) event.getProperty().getValue();
FileResource res = new FileResource(new File(val));
Page.getCurrent().open(res, null, false);
}
}
The javadoc here mentions some memory and security problems as reason for marking it deprecated
In the second I try to go around this deprecated method by registering the resource in the DownloadComponent. I'd be glad if a vaadin expert comments this solution.
public class DownloadComponent extends CustomComponent implements ValueChangeListener {
private ComboBox cb = new ComboBox();
private static final String MYKEY = "download";
public DownloadComponent() {
cb.addValueChangeListener(this);
cb.setNewItemsAllowed(true);
cb.setImmediate(true);
cb.setNullSelectionAllowed(false);
setCompositionRoot(cb);
}
#Override
public void valueChange(ValueChangeEvent event) {
String val = (String) event.getProperty().getValue();
FileResource res = new FileResource(new File(val));
setResource(MYKEY, res);
ResourceReference rr = ResourceReference.create(res, this, MYKEY);
Page.getCurrent().open(rr.getURL(), null);
}
}
Note: I do not really allow the user to open all my files on the server and you should not do that either. It is just for demonstration.
Here is my work-around. It works like a charm for me. Hope it will help you.
Create a button and hide it by Css (NOT by code: button.setInvisible(false))
final Button downloadInvisibleButton = new Button();
downloadInvisibleButton.setId("DownloadButtonId");
downloadInvisibleButton.addStyleName("InvisibleButton");
In your theme, add this rule to hide the downloadInvisibleButton:
.InvisibleButton {
display: none;
}
When the user clicks on menuItem: extend the fileDownloader to the downloadInvisibleButton, then simulate the click on the downloadInvisibleButton by JavaScript.
menuBar.addItem("Download", new MenuBar.Command() {
#Override
public void menuSelected(MenuBar.MenuItem selectedItem) {
FileDownloader fileDownloader = new FileDownloader(...);
fileDownloader.extend(downloadInvisibleButton);
//Simulate the click on downloadInvisibleButton by JavaScript
Page.getCurrent().getJavaScript()
.execute("document.getElementById('DownloadButtonId').click();");
}
});
i am trying to add a custom window in blackberry but before this i am trying to add a custom label in that popup screen for my satisfaction that i can add or cant . so at the time when i am adding that i am facing the problem of IllegalArguementException error , so can you please tell me how can i solve that problem . i am doing like this .
see this is my MYScreen class which i am using to add pop-up . so pop-up is added when ever i clicked that press button , which is added in the Screen .
public final class MyScreen extends MainScreen implements FieldChangeListener
{
private ButtonField btn;
public MyScreen()
{
setTitle("MyTitle");
btn = new ButtonField ("press");
btn.setChangeListener(this);
add(btn) ;
}
public void fieldChanged(Field field, int context)
{
if ( field == btn )
{
Dialog.inform("hello");
pop_manager manager_object = new pop_manager(0);
UiApplication.getUiApplication().pushScreen( new up_pop_test( manager_object ) );
}
}
}
so in this i have added , new_up_pop_test class which is :
public class up_pop_test extends PopupScreen
{
public up_pop_test( pop_manager delegate)
{
super(delegate);
add(delegate);
}
}
and pop_manager is :
public class pop_manager extends Manager
{
protected pop_manager(long style)
{
super(style);
}
protected void sublayout(int w, int h)
{
Field f = getField(0);
layoutChild( f , w/3+w/3 , 50 ) ;
setPositionChild ( f , w/33 + w/33 , w/67+w/104 );
setExtent(w,h);
}
}
You don't need to do as much work as you were trying to...
All you need is a PopupScreen, which you can customise at will, just like a normal screen.
public class MyPopup extends PopupScreen {
public MyPopup() {
super(new VerticalFieldManager());
LabelField infoLabel = new LabelField("Here is a label in a popup");
add(infoLabel);
}
}
In order to call it, all you need to do is push like a normal screen.
UiApplication.getUiApplication().pushScreen(new MyPopup());
You cannot gain control over the Dialog class, these are for simple operations like informing the user or asking a question, and are standardised