How to wirte Public Dialog addClickListener write back Form TextField - vaadin14

I’m a beginner, I can’t pass this level, please help.
I have a lot of forms with TextField (cust_no, cust_name), each with a button on the right,
press the button
A dialog can be display custom record, after selecting the required customer,
Write the selected cust_no, cust_name back to the Text_Field of Form.
I hope to write dialog as a public class, so that many class Forms can use this function, and can also smoothly write cust_no and cust_name back to their respective Form TextField.
In addition to backfilling cust_no,cust_name TextField for some Forms, some also need to query the consumption amount and write back the specified cust_amt TextField.
My trouble is that form button.addClickListener open a dialog,
Dialog’s Button_OK.addClickListener cannot know how I want to write back Form TextField and some have special query mechanisms, how to customize

Without seeing exactly how your code is structured, I can only give a quite generic answer. What you need is typically that something associated with the button for opening the dialog can know what to do with the result from the dialog, and it can also configure the dialog's OK button to carry out that action.
public class HelloWorldView extends VerticalLayout {
public HelloWorldView() {
TextField customerNumberField = new TextField("Customer number");
TextField customerNameField = new TextField("Customer name");
Button nameDialogButton = new Button("Open dialog", dialogOpenClick -> {
showDialog(customer -> {
customerNumberField.setValue(customer.getNumber());
customerNameField.setValue(customer.getName());
});
});
add(customerNumberField, customerNameField, nameDialogButton);
}
private void showDialog(Consumer<Customer> selectionAction) {
Select<Customer> customerSelect = new Select<>(new Customer("1", "Customer 1"),
new Customer("2", "Customer 2"));
customerSelect.setTextRenderer(customer -> customer.getName());
Dialog dialog = new Dialog();
dialog.add(customerSelect);
dialog.add(new Button("Select customer", click -> {
Customer selectedCustomer = customerSelect.getValue();
if (selectedCustomer != null) {
selectionAction.accept(selectedCustomer);
}
dialog.close();
}));
dialog.open();
}
}

Related

Codename One set action event from different class for button in dialog

I have an Android application with a dialog and a few buttons inside.
I want to reuse the dialog for different purposes and looking for a way to call the button from a separate class and define an action event for it.
Creating a test class, I managed to define an action event for a button inside a form, but the same code does not work for a button inside a dialog, and I can't get my head around why it is not working for the dialog.
Below is what I already have. Any suggestions would be appreciated.
public Class One {
Test test = new Test();
test.testOne(); // this is working : button prints
test.testTwo(); // this is not working : button does not print
buttonTest = test.getTestButton();
buttonTest.setText("Hello World"); // not working for a button in a dialog
buttonTest.addActionListener(l-> { // prints when the button in a Form
System.out.println("try"); // does not print when the button is in a dialog
});
}
public class Test {
Dialog dialog = new Dialog();
Form form = new Form();
Button button;
public void testOne() {
button = new Button("Test");
form.add(button);
form.show();
}
public void testTwo() {
button = new Button("Testing");
dialog.add(button);
dialog.show();
}
public Button getTestButton () {
return button;
}
}
You add the action listener after showing the form and dialog. This isn't a problem for the form since the forms show method will continue. But a dialogs show() method will block.
Two solutions:
Move the listener binding higher in the code (before the show) that would be a problem since the button doesn't exist yet so you will need some refactoring.
Change the show() call on the dialog to showModless()

Display screen on button click in blackberry eclipse

I recently started creating an app for blackberry. I want the app to display a screen (Let's say it's called "InfoScreen") but as I said i am still very new to this. What code will I have to use if I want the "InfoScreen" to be show when the button "buttonInfo" is clicked?
Here is some code I used to create the button that is might relevant to this question.
//Create button
ButtonField buttonInfo = new ButtonField("Information", Field.FIELD_HCENTER);
//Center buttons
VerticalFieldManager vfm = new VerticalFieldManager(Field.USE_ALL_WIDTH);
vfm.add(buttonInfo);
add(vfm);
What code will have to be used for both touch-screen devices and those that use the track-pad?
Thanks
Try this:
FieldChangeListener infoListener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
UiApplication.getUiApplication().pushScreen(new InfoScreen());
}
};
buttonInfo.setChangeListener(infoListener);

Extend View and Custom Dialogs

I am working on a game where I am extending the view and performing operations in the class. I need to have a popup in the game which will have 3 buttons inside it. I have managed to have the popup show-up using custom dialogs but when I configure the onClick as follows:
private void popUp() {
Context mContext = getContext();
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.custom_fullimage_dialog);
dialog.setTitle("Cheese Market");
Button one = (Button)findViewById(R.id.firstpack);
one.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
cheeseLeft = cheeseLeft + 10;
masterMoveLock = false;
return;
}
});
}
It force closes giving a nullpointerexeption even though it is defined in the custom_fullimage_dialog layout.
Can someone help me figure out how to have the button click detected in this scenario?
Thank you.
Try calling dialog.findViewById instead.
You're setting the contentView for the dialog, but by calling findViewById you're looking for it under your activity's content view.

filter look up in dialog

I Have created a dialog in a class, the dialog method is as below
static void dialog(Args _args)
{
Dialog dialog;
DialogField dialogFieldCurrentState;
DialogField dialogFieldNewState;
CustInvoiceTable custInvoiceTable;
;
custInvoiceTable = _args.record();
dialog = new Dialog("Change State");
dialogFieldCurrentState = dialog.addField(TypeID(State_LT),"Current State: ");
dialogFieldCurrentState.value(custInvoiceTable.State);
dialogFieldCurrentState.enabled(false);
dialogFieldNewState = dialog.addField(TypeID(State_LT),"New State: ");
if (dialog.run())
{
custInvoiceTable.State = dialogFieldNewState.value();
}
}
in my dialog there are two fileds Current State and New State .Now when i select the New State the list of all
states is displayed(irrespective of country) which i dont want. Only the states respective of country has to be shown
in the lookup
. I need to make use of a filter something like e.g. while select while select AddressState
where addressState.CountryRegionId == custInvoiceTable.CountryRegionId; so that only states which
are related to a country is shown.
State_LT here is an string EDT (where i put in the relation of State_LT) State_LT == AddressState.StateId
IN AdressState there is a method lookupStateId(), How to call it from a dialog(code above)
?
I am answering to your last question: "IN AdressState THERE IS A METHOD lookupStateId(), HOW TO CALL IT FROM A DIALOG(code above) ?" - by the way writing in capital letters doesn't help people understand your point better.
It is not clear why your dialog is a static method, anyway you'd need the following.
Let's say your ClassDeclaration looks something like this:
class TestClass1 extends RunBase
{
Dialog dialog;
DialogField dialogFieldCurrentState;
DialogField dialogFieldNewState;
// etcetera
}
Your dialog is something like this:
public Object dialog()
{
;
dialog = super();
dialogFieldCurrentState = dialog.addField(TypeID(AddressStateId),"Current State: ");
dialogFieldCurrentState.enabled(false);
dialogFieldNewState = dialog.addField(TypeID(AddressStateId),"New State: ");
dialogFieldNewState.lookupButton(FormLookupButton::Always); // If needed
return dialog;
}
To implement a lookup the way you want it you need to do two things. First, open the dialog, right click on the New State, click Setup, and check the control's System Name. If for example it is Fld2_1 then you need to create the following method:
void fld2_1_lookup()
{
Object control = dialog.formRun().controlCallingMethod();
;
AddressState::lookupStateId(control, dialogFieldNewState.value());
}
Second, it is necessary to override the following method:
public void dialogPostRun(DialogRunbase _dialog)
{
super(_dialog);
_dialog.dialogForm().formRun().controlMethodOverload(true);
_dialog.dialogForm().formRun().controlMethodOverloadObject(this);
}
That should do the trick. I haven't done it for a while but I don't think I forgot something.
Example of looking up customer in dialog:
For example, to have a customer choice dropdown in the dialog,
In report class declaration method --->
DialogField CustomerDlg;
CustAccount customer;
In the reports dialog method: ----->
dialog.addGroup("Customer");
CustomerDlg = dialog.addField(typeid(CustAccount));
CustomerDlg.value(customer);
In the getFromDialog method: ---->
...
customer = CustomerDlg.value();

drop down list for country selection in j2me form

I want to make a form where then is login and password textfield.
Ans I want to add one dropdown list of country by which user can select the one of the country from that list.
How is it possible in j2me?
You can use ChoiceGroup for this. See this demo application,
public class ChoiceGroup extends MIDlet
{
Display display=Display.getDisplay(this);
public void startApp()
{
Form form = new Form("Choice Form");
//ChoiceGroup(label,type,elements,image)
ChoiceGroup CoursePOP = new ChoiceGroup ("Pop Up choice", Choice.POPUP,
new String[] {"India", "Usa","UK"}, null);
form.append(CoursePOP);
display.setCurrent(form);
}
}

Resources