ConfirmDialog add-on in customcomponent? - java

I did download ConfirmDialog add-on. Now, I'm trying create a confirmdialong in my customcomponent, but I guess that doesn't work with this ui.
public class Customer extends CustomComponent implements Button.ClickListener{
private Button btnSave;
private VerticalLayout vLayout;
public Customer(){
vLayout = new VerticalLayout();
setCompositionRoot(vLayout);
btnSave = new Button("Save");
btnSave.addClickListener(this);
vLayout.addComponent(btnSave);
}
#Override
public void buttonClick(ClickEvent event) {
if(event.getButton() == btnSave){
save();
}
}
/** save informations if ConfirmDialog return true */
private void save(){
ConfirmDialog.show(this, "Please Confirm:", "Are you really sure?",
"I am", "Not quite", new ConfirmDialog.Listener() {
public void onClose(ConfirmDialog dialog) {
if (dialog.isConfirmed()) {
System.out.println(dialog.isConfirmed());
} else {
System.out.println(dialog.isConfirmed()); }
}
});
}
}
when I create ConfirmDialog and pass my CustomComponent as Ui(this) does not accept. I tryed pass null, but does not work also.

the problem is solved. I did use UI.getCurrent() and works.
/** save informations if ConfirmDialog return true */
private void save(){
ConfirmDialog.show(UI.getCurrent(), "Please Confirm:", "Are you really sure?",
"I am", "Not quite", new ConfirmDialog.Listener() {
public void onClose(ConfirmDialog dialog) {
if (dialog.isConfirmed()) {
System.out.println(dialog.isConfirmed());
} else {
System.out.println(dialog.isConfirmed()); }
}
});
}

Related

Java Swing buttongroup clear on click

i have one button group with 2 radio buttons:
private javax.swing.JRadioButton jRadioButtonESPRINCIPAL;
private javax.swing.JRadioButton jRadioButtonESSECUNDARIO;
buttonGroup1 = new javax.swing.ButtonGroup();
I know that i can clear the group by buttonGroup1.clearSelection(), but i want to do this only if i click on a clicked radio button.
I have tried
private void jRadioButtonESPRINCIPALMouseClicked(java.awt.event.MouseEvent evt) {
if (jRadioButtonESPRINCIPAL.isSelected()) {
buttonGroup1.clearSelection();
}
else{
jRadioButtonESPRINCIPAL.setSelected(true);
}
}
private void jRadioButtonESSECUNDARIOMouseClicked(java.awt.event.MouseEvent evt) {
if (jRadioButtonESSECUNDARIO.isSelected()) {
buttonGroup1.clearSelection();
}
else{
jRadioButtonESSECUNDARIO.setSelected(true);
}
}
But didnt works
Any help will be appreciate
My previous answer was wrong sorry. You have to use ActionListeners like this:
jRadioButtonESPRINCIPAL.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
//your code goes here
}
});
and then use a variable to store the last RadioButton that was selected. In the ActionListener you then have to check if the isSelected() equals the last selection. If yes, then use buttonGroup1.clearSelection();.
So the final code should look like this:
jRadioButtonESPRINCIPAL.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
if (jRadioButtonESPRINCIPAL.equals(lastSelectedRadioButton)) {
buttonGroup1.clearSelection();
lastSelectedRadioButton = null;
}
else {
lastSelectedRadioButton = jRadioButtonESPRINCIPAL;
}
}
});
jRadioButtonESSECUNDARIO.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
if (jRadioButtonESSECUNDARIO.equals(lastSelectedRadioButton)) {
buttonGroup1.clearSelection();
lastSelectedRadioButton = null;
}
else {
lastSelectedRadioButton = jRadioButtonESSECUNDARIO;
}
}
});

add server side data into html list?

i am new in gwt.i want to add data come from serverside in html listbox,so how can w do this??
name is splitted string which i want to add in the listbox...
actually i want to make jqxlistbox type module.http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxlistbox/index.htm
public class imagegrid implements EntryPoint
{
Label l = new Label("search");
TextBox tb=new TextBox();
VerticalPanel panel=new VerticalPanel();
String name=null;
private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
public void onModuleLoad()
{
tb.addKeyUpHandler(new handler());
panel.add(l);
panel.add(tb);
RootPanel.get().add(panel);
}
public class handler implements KeyUpHandler
{
public void onKeyUp(KeyUpEvent event)
{
String ab =tb.getText();
if(ab.length()>0)
{
greetingService.server(ab,new AsyncCallback<String>()
{
#Override
public void onFailure(Throwable caught)
{
Window.alert("Invalid");
}
#Override
public void onSuccess(String result)
{
System.out.println("At the client side..."+result);
if(result.isEmpty())
{
name="not found";
}
else
{
String match=tb.getText();
for (String retval: result.split("/"))
{
name=retval;
}
}
}
});
}
}
}
}
I think what you are looking for is CellList in GWT. You can find the sample code in showcase.
Sorry, I missed the search part of your question. For that you may need to create a new implementation og SuggestBox with CellList as drop-down. Like someone has shown here.

GWT - Get button's "addClickHandler" from a Widget

first of all Im working on a time tracking page with login authentication using ldap.
For the login I created a dialogbox setting verticalpanel as its widget. My verticalpanel contains two textboxes to enter username/password and one button to send data to the ldap server.
On module load the dialogbox pops up and gets the time tracking content on login success.
To my question:
"LoginWidget" and "LoginClickHandler" have separated classes, hence I need to get the login button on module load to add "LoginClickHandler".
What is the best way to handle this? - since I know that my solution isnt that good.
LoginWidget class
public class LoginWidget{
private Button loginButton;
private DialogBox dialogBox;
private TextBox tbxUser;
private PasswordTextBox tbxPw;
private Label lblUser;
private Label lblPW;
private Label lblError;
public LoginWidget(){
dialogBox = new DialogBox();
tbxUser = new TextBox();
tbxPw = new PasswordTextBox();
lblUser = new Label();
lblPW = new Label();
lblError = new Label();
dialogBox.setText("Login");
dialogBox.setAnimationEnabled(true);
loginButton = new Button("Login");
// set the id of a widget by accessing its Element
loginButton.getElement().setId("closeButton");
final HTML serverResponseLabel = new HTML();
VerticalPanel dialogVPanel = new VerticalPanel();
dialogVPanel.addStyleName("dialogVPanel");
dialogVPanel.add(lblUser);
lblUser.setText("User:");
dialogVPanel.add(tbxUser);
dialogVPanel.add(lblPW);
lblPW.setText("PW:");
dialogVPanel.add(tbxPw);
dialogVPanel.add(lblError);
dialogVPanel.add(serverResponseLabel);
dialogVPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
dialogVPanel.add(loginButton);
dialogBox.setWidget(dialogVPanel);
dialogBox.show();
dialogBox.center();
}
public Button getLoginButton(){
return loginButton;
}
public DialogBox getDialogBox(){
return dialogBox;
}
public TextBox getTbxUser(){
return tbxUser;
}
public TextBox getTbxPw(){
return tbxPw;
}
public Label getLblError(){
return lblError;
}
}
LoginClickHandler class
public class LoginClickHandler implements ClickHandler {
/**
*/
private LoginWidget lw;
private ServiceImplURL serviceImplURL;
private TimeTracking dtt = new TimeTracking();
public LoginClickHandler(ServiceImplURL sIU, LoginWidget _lw){
/**
*/
this.lw = _lw;
this.serviceImplURL = sIU;
}
public void onClick(ClickEvent event) {
/**
*/
serviceImplURL.getRpcLdap().authenticate(lw.getTbxPw().getText(), lw.getTbxUser().getText(), new AsyncCallback<Boolean>() {
/**
*/
#Override
public void onSuccess(Boolean isLdapAuthOk) {
/**
*/
if(isLdapAuthOk){
lw.getDialogBox().hide();
User user = new User(lw.getTbxUser().getText(), lw.getTbxPw().getText());
serviceImplURL.getRpcSession().setUsername(user.getUsername(), new AsyncCallback<Void>() {
#Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
#Override
public void onSuccess(Void result) {
// TODO Auto-generated method stub
}
});
serviceImplURL.getRpcDB().insertUser(user.getUsername(), new AsyncCallback<Void>() {
/**
*/
#Override
public void onFailure(Throwable caught) {
/*
* connection error to implement
*/
}
#Override
public void onSuccess(Void result) {
/*
* do nothing
*/
}
});
dtt.loadContent();
}
else{
lw.getLblError().setStyleName("error");
lw.getLblError().setText("Passwort oder Username falsch!");
}
}
#Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
});
}
}
My Entrypoint
#Override
public void onModuleLoad() {
/**
*/
loadLoginWidget();
}
/**
* Creates the login pop up.
*/
public void loadLoginWidget(){
/**
*/
LoginWidget lw = new LoginWidget();
LoginClickHandler lch = new LoginClickHandler(serviceImplURL, lw);
lw.getLoginButton().addClickHandler(lch);
}
I already tried to extend Button but I dont think its a difference.
Pass a listener class (eg. your LoginClickHandler) to the view constructor:
public LoginWidget( LoginClickHandler listener )
{
...
loginButton.addClickHandler( listener )
...
}
More generally you may want to interject an interface defining the actions and have LoginClickHandler implement it:
public interface LoginListener
{
void onLogin();
...
}
public class LoginWidget
{
public LoginWidget( LoginListener listener )
{
this.listener = listener;
Button loginButton = new Button( "Login" );
loginButton.addClickHandler( new ClickHandler()
{
public void onClick( ClickEvent event ) { listener.onLogin(); }
} );
}
...
}
and finally
public class LoginClickHandler implements LoginListener
{
#Override public void onLogin()
{
serviceImplURL.getRpcLdap()...
...
}
}
and
public void loadLoginWidget()
{
LoginWidget lw = new LoginWidget( new LoginClickHandler() );
...
}
Cheers,

JDialog with WindowStateListener

I am trying to catch an event of user clicking on and "X" button of a JDialog and only close if a user confirms. So here is skeleton of what I am doing:
public class MyDialog extends JDialog {
public MyDialog(){
super();
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
.........
}
.........
}
public class Waiter implements WindowStateListener{
#Override
public void windowStateChanged(WindowEvent event) {
System.out.println(event);
if (event.getNewState() == WindowEvent.WINDOW_CLOSING) {
if (shouldClose()) {
dialog.close();
}
}
}
}
MyDialog dialog = new MyDialog();
Waiter waiter = new Waiter();
dialog.addWindowStateListener(waiter);
As you can guess, when I click on "X" for the dialog, I do not get a message printed becasue the methodis never called. I am not sure where is the problem.
You want to use a WindowListener instead of a WindowStateListener.
Try this:
MyDialog dialog = new MyDialog();
dialog.addWindowListener(new WindowAdapter() {
#Override
public void windowClosing(final WindowEvent event) {
System.out.println(event);
if (shouldClose()) {
dialog.close();
}
}
});

How can I ask the user for some numbers in Java ME?

I am very new to Java Me (first time). I want my program to ask the user for an IP addres. So four numbers that are between 0 and 255. It doesn't need to be difficult, but as I said, I'm new to Java Me.
How do you want the user to input the IP address? Do you want to use a TextField for example? You could do something like the following:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
public class GetIPAddress extends MIDlet implements CommandListener {
private Display display;
private Form form = new Form("IP Adress Input");
private Command submit = new Command("Submit", Command.SCREEN, 1);
private Command exit = new Command("Exit", Command.EXIT, 1);
private TextField textfield = new TextField("IP Address:", "", 30, TextField.ANY);
public GetIPAddress() {
display = Display.getDisplay(this);
form.addCommand(exit);
form.addCommand(submit);
form.append(textfield);
form.setCommandListener(this);
}
public void startApp() {
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command, Displayable displayable) {
if (command == submit) {
// Do the manipulation of the IP address here.
// You can retrieve it using textfield.getString();
form.removeCommand(submit);
} else if (command == exit) {
destroyApp(false);
notifyDestroyed();
}
}
}

Categories