Vaadin 7 - update textarea at value changed - java

I'm new at vaadin and I want to display some infologs in a textarea. Currently I have set the pushmode in my CustomComponent to PushMode.AUTOMATIC ( #Push(PushMode.AUTOMATIC) ). But this works only the first time. To refresh the text I have to resize the window manual or click a button.
I found something called ICEPush but I do not understand this stuff :( and do not found good tutorials...
Has anybody a hint for me?
Thanks for help!

have you made sure you changed the TextArea value using the ui.access method, and called the ui.push() method?
Kind of like this:
ui.access(new Runnable() {
#Override
public void run() {
textArea.setValue(newValue);
ui.push();
}
});

Related

Vaadin unbuffered grids won't close

I am having a weird problem on my Vaadin app. I have a screen with two separate unbuffered grids.
The user is able to edit the data in those two grids and then click a "Save" button to save the changes made.
My problem is that I want to close the editors when the user clicks on "Save".
I tried the following code:
private void closeEditors() {
if (tab1.getEditor().isOpen()) {
tab1.getEditor().closeEditor();
}
if (tab2.getEditor().isOpen()) {
tab2.getEditor().closeEditor();
}
}
I don't understand why this code doesn't work, editors stay opened. I also tried calling the cancel method but in vain.
I am using Vaadin 14.
I am posting this here with not much hope of finding an answer, this problem seems really precise.
But with any luck, maybe someone has experienced a similar issue ?
Maybe there is another glitchier way of forcing my editors to close ?
Any suggestion would be of great help, thanks in advance for anything you could think of !
EDIT: a little more code
This is the grids:
private Grid<Map<String, String>> tab1;
private Grid<Map<String, List<String>>> tab2;
This is the save function
public void saveData() {
saveDataFromTab1();
saveDataFromTab2();
try {
ServicesProxyImpl.getInstance().updateInBD(someObject);
saveButton.setEnabled(false);
cancelButton.setEnabled(false);
closeEditors();
Dialog dialog = VaadinComponentUtils.generateDialog(Constantes.MSG_SAVE_OK);
dialog.open();
} catch (JAXBException e) {
e.printStackTrace();
Dialog dialog = VaadinComponentUtils.generateDialog(Constantes.MSG_SAVE_KO);
dialog.open();
}
}
And this is the save button:
public Button getSaveButton() {
Button saveButton= VaadinComponentUtils.generateButton("Save",
VaadinIcon.CHECK_CIRCLE_O, null, true);
saveButton.setEnabled(false);
saveButton.addClickListener(event -> saveData());
return saveButton;
}
EDIT 2:
I have noticed something, when I click on an element of one of my two grids, I want the editor to open for that specific element and I want to close the editor on the other grid (the one not concerned by the modification). This works ! My grids behave like I want. It seems I am only losing control over my editors after I have actually modified one of the cells and clicked on my save button.
The isOpen function returns false on both grids after I call my closeEditors function, so it seems the grid thinks its editor is closed but it is still opened on my UI.
EDIT 3: I have found a workaround
Well, I have solved my problem by adding a close event listener on both my grids and calling resetGrids when the close event is fired. This function simply removes the grids from the UI, fetches the data to be displayed and then adds the grid one again, both editors being closed. I guess it solves my problem but I would have wanted to understand what was going on...
private void closeEditors() {
tableauHoraires.getEditor().addCloseListener(e -> resetGrids());
tableauRamassagePorteAPorte.getEditor().addCloseListener(e -> resetGrids());
if (tableauRamassagePorteAPorte.getEditor().isOpen()) {
tableauRamassagePorteAPorte.getEditor().closeEditor();
}
if (tableauHoraires.getEditor().isOpen()) {
tableauHoraires.getEditor().closeEditor();
tableauHoraires.getEditor().refresh();
}
}
Make sure that the objects in your grid have proper equals and hashcode methods and that the field(s) being edited do not influence them.
I use the PK from the database.

How call a JFrame from my Application Window SWT Builder

Here is my code in my ApplicationWindow. I have a widgetSelected happening for a bottom called "Welcome" that I want to open a new window with text, which I already have programmed.
//Welcome was clicked
mntmWelcome.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
Welcome2 newWindow = new Welcome2();
newWindow.setVisible(true);
}
});
And the welcome is a JDialog only showing some text and stuff, but when I use this the program crashes and I get
java.lang.IllegalArgumentException: defaultCloseOperation must be one of: DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, or DISPOSE_ON_CLOSE
and I have no idea where to set this, i tried within the override but the window never opens. I just want it to open and the previous window should still be there behind. How can I solve this?
Try adding this:
newWindow.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Please, refer to: https://chortle.ccsu.edu/java5/Notes/chap56/ch56_9.html
and read this https://docs.oracle.com/javase/7/docs/api/javax/swing/WindowConstants.html.
Documentations are really useful for beginners.

How to force a Value change on a Vaadin RichTextArea component

I have developed a custom component consist of a layout and two labels within it. This layout is draggable. The code is similar to this :
DragAndDropWrapper boxWrap= new DragAndDropWrapper(layout);
mainLayout.addComponent(boxWrap);
After that I have a RichTextArea that allows the layout to be dropped in it. With this code.
RichTextArea richText= new RichTextArea;
DragAndDropWrapper dndWrapper = new DragAndDropWrapper(richText);
dndWrapper.setDropHandler(new DropHandler() {
public void drop(DragAndDropEvent event) {
//Do whatever you want when something is dropped
}
//Criterio de aceptacion
public AcceptCriterion getAcceptCriterion() {
return AcceptAll.get();
}
});
The code works fine. But when I drop the layout within the RichTextArea y want to get the Text written in this area and add some text but the method richText.getValue() is not updated unless I change the focus to another component or tab out. I guess there is not being communication with the server side so the value is not updated. Is there any way to force a a focus change when mousedown on the layout? I tried with JavaScript but i dont know how to add a onmousedown="function()" attribute to the layout component. I also tried extending RichTextArea and implementing the MouseListener or something or a TextChangeListener, but nothing works.
Any clue? Thank you.
PS: The component cannot be different from a RichTextArea.
Have you set richText.setImmediate(true); ?

CustomTabbedPane: stop opening of tabs that are already open

I am using CustomTabbedPane in my class to show different panels within one frame. It works fine as far as functionality is concerned. I want my program to be elegant so I don't want a tab to show up, when a user click the button, that is already open. I have searched it for like more than 3 hours but didn't find anything similar to my problem. Below is my code snippet of action-listener for adding product.
addProduct.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
Product obj=new Product();
//if(isTabPresent()){
obj.start();
mainPane.addTab("Add Product",obj);
mainPane.setSelectedComponent(obj);
//}
}
});
I have also made a method isTabPresent() to check whether the tab is available in the mainPane(CustomTabbedPane) or not. I have commented isTabPresent() because it is not working the way I want.
public boolean isTabPresent(Object tab){
for(int i=0;i<mainPane.getTabCount();i++)
if(mainPane.getComponentAt(i).equals(tab))
return true;
return false;
}
This is what I have tried to get my job done but its not working. Any help or any better suggestion would be appreciated. Thanks a lot!

How to hide the gui in netbeans?

I have created a new DesktopApplication in Netbeans. When I start it, it shows the gui directly on the screen. How to hide it after startup?
Something like this:
DesktopApplication1.getApplication().getMainFrame().setVisible(false);
after the initComponents(); method doesn't work.
Is there a way to hide this window after starting up? (I only want to show it after clicking the tray-Icon of this application. Not after startup.)
Thanks.
This problem is reproduceable when you create a new DesktopApplication in Netbeans. I haven't changed the code (only added the line mentioned above.)
If you look at the source code for DesktopApplication1App, it says something like
//DesktopApplication1App.java
#Action public void startup(){
show(new DesktopApplication1View(this));
}
To fix this, just comment out the show() call, and replacing it with a dummy. For example:
//DesktopApplication1App.java
#Action public void startup(){
Object o = new DesktopApplication1View(this);
}
Later, if you want to set it to be visible, you can call this:
//DesktopApplication1View.java
DesktopApplication1App.getApplication().show(this);
// ----- OR -----
this.getFrame().setVisible(true);
whichever works for you.

Categories