How to hide and unhide box from checkbox - java

I'm a student of android developer.
I need to make a project and I've ran into a problem.
basically the problem is that i need to make the box of a checkBox disappear and only after pushing a specific button, the box will appear and be clickable.
from my searches i've found that when i write:
myCheckBox.setButtonDrawable(new ColorDrawable(Color.TRANSPARENT));
it will disappear and it's good but couldn't find the way to make it appear after that..
thanks a lot. :)

You can achieve that my making the view disappear either by using
myCheckBox.setVisibility(View.GONE);
(OR)
myCheckBox.setVisibility(View.INVISIBLE);
And again you can make it to appear by
myCheckBox.setVisibility(View.VISIBLE);
Hope this is helpful:)

You need to use
yourCheckBox.setVisibility(View.GONE);
to make that visible again,
yourCheckBox.setVisibility(View.VISIBLE);

You can get the currently assigned drawable with getButtonDrawable() and store it in a field, for example:
class Foo {
private Drawable oldDrawable;
private CheckBox myCheckBox;
public void hideCheckbox() {
oldDrawable = myCheckBox.getButtonDrawable();
myCheckBox.setButtonDrawable(new ColorDrawable(Color.TRANSPARENT));
}
public void showCheckbox() {
myCheckBox.setButtonDrawable(oldDrawable);
}
}

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.

Vaadin 7 - update textarea at value changed

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();
}
});

How could I know if the window is opened or not in Vaadin?

I use one layout in few cases. But when I show this layout in the window (com.vaadin.ui.Window) I have to hide one button otherwise layout stays unchanged. So I would like to know is the window opened or not at the moment. Is the any way to figure that out?
with getWindows you get all the windows of an UI. and with isAttached you will find out, if it is attached to the session (in a state where the user should see it)
I don't fully understand your question, but maybe this helps:
public class MyLayout extends VerticalLayout {
private Button myButton; // set it in the constructor
#Override
public void setParent(HasComponents parent) {
super.setParent(parent);
myButton.setVisible(!(parent instanceof Window)); // or recursively if need
}
}

Create view only for specific editor in eclipse

How can I show view when specific editor is selected and hide it when another is selected? I was looking for this in extension points but I found nothing :(
Is there any way to do this?
You need to register IPartListener with IPartService and then do appropriate things in partActivated, partBroughtToTop, etc. methods.
Make sure that the part is the editor you want:
public void partActivated(IWorkbenchPart part) {
if (part instanceof MySuperEditor) {
part.getSite().getPage().showView(MySuperView.ID);
}
}
and so on.
Let me know if that helps.

Change stage titleProperty on selecting different tabs in javafx

I guess there should be some event for this, but didn't find any. The code I have now is
stage.titleProperty().bind(tabPane.getSelectionModel().getSelectedItem().textProperty());
But it doesn't change the title dynamically, what's the right solution?
Puce's explanation is correct. Here is a change listener example.
stage.setTitle(tabPane.getSelectionModel().getSelectedItem().getText());
tabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>() {
#Override public void changed(ObservableValue<? extends Tab> tab, Tab oldTab, Tab newTab) {
stage.setTitle(newTab.getText());
}
});
Use the above code instead of the sample code in your question.
I can't give you a solution right now, but I think I spot the problem:
You've bound the titleProperty to the textProperty of the tab which was selected at binding time. You probably need to listen for selection changes and change the stage title in the listener.

Categories