Open modal JFace Dialog on top of another modal JFace Dialog - java

I have a custom JFace Dialog (called PropertyDialog) which extends the FormDialog. I would like to open a modal Message Dialog over the PropertryDialog as soon as it opens, to display a message to the user.
How could this be accomplished? Would I have to override the open() method? Note that it is required that the PropertyDialog.open() does not return until a button is pressed on the button bar.
Thanks for your help.

You can do this by displaying the message at the end of the createContents method, like this:
#Override
protected Control createContents(final Composite parent)
{
final Control control = super.createContents(parent);
parent.getDisplay().asyncExec(new Runnable() {
public void run()
{
MessageDialog.openInformation(getShell(), "title", "message");
}
});
return control;
}
You need to use Display.asyncExec so that the dialog is not displayed until the parent dialog has been displayed.

Related

changing screen after ok button is pressed in dialog box

I was trying to show a success message with dialog box to user before changing the screen. And I want it to wait for user to click the ok button or press Enter key and then change the screen. Since I have to put lots of dialog boxes in my program, to avoid duplicates, I tried to have one createDialog method in my MainClass which creates the dialog boxes and it will add it to the stage which I passed to the method. But the thing is I want it to change the screen to the one I passed to it after the ok button was pressed by user but dialog's result function is an inner method which doesn't access the Screen which I passed to the function. So is there any way that I can do this?
public class MainClass extends Game {
.
.
.
public void createDialog(String message, boolean isWarning, Stage stage, Screen screen) {
Skin skin2Json = new Skin(Gdx.files.internal("freezing/skin/freezing-ui.json"));
Dialog dialog;
String title = "Success Message";
if (isWarning) title = "Error";
dialog = new Dialog(title, skin2Json, "dialog"){
#Override
protected void result(Object object) {
if((Boolean) object)
//if it is a success message ,I want to set screen to the screen passed to the createDialog function
}
};
dialog.getBackground().setMinWidth(400);
dialog.getBackground().setMinHeight(200);
dialog.text(message);
dialog.button("Ok", true);
dialog.key(Input.Keys.ENTER, true);
dialog.show(stage);
}
}
Any help is appreciated.
There are different ways you could do that I guess, but mine would be :
to use a variable in your class, in the render function, that triggers the change of screen
to set that variable once you hit the OK in the dialog box.
That would give something like :
public class MainClass extends Game {
private Boolean ChangeScreen = false;
public void render () {
// This is your typical render function
if(ChangeScreen) Game.setscreen(new MyOtherScreen());
}
public void createDialog(String message, boolean isWarning, Stage stage, Screen screen) {
Skin skin2Json = new Skin(Gdx.files.internal("freezing/skin/freezing-ui.json"));
Dialog dialog;
String title = "Success Message";
if (isWarning) title = "Error";
dialog = new Dialog(title, skin2Json, "dialog"){
#Override
protected void result(Object object) {
if((Boolean) object)
// The OK button has been hit
ChangeScreen = true;
}
};
dialog.getBackground().setMinWidth(400);
dialog.getBackground().setMinHeight(200);
dialog.text(message);
dialog.button("Ok", true);
dialog.key(Input.Keys.ENTER, true);
dialog.show(stage);
}
}
Maybe not the most elegant way but it should do the trick.

How to create a popup with a scroll view programmatically?

I need to create a popup window programmatically, with a scrollview is this possible? i need to do everything in java side.
I was using a alert dialog but maybe is better a popup window, but didn't find much information on how to do it programatically.
i was using this code for the alert dialog
AlertDialog.Builder alert = new AlertDialog.Builder(OFActivityA.this);
alert.setTitle("Something");
alert.setText("fe");
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//what you need to do after click "OK"
}
});
alert.show();
i need to do everything in java side., not really - you can create your custom dialog with a custom layout and have any kind of layout that you would like to have.
For example, create dialogClass:
public class ProgressDialog extends Dialog {
public ProgressDialog(#NonNull Context context) {
super(context);
setContentView(R.layout.progress_dialog); //this is your layout for the dialog
}
}
And all you need to do to show your dialog is call those line:
ProgressDialog progressDialog = new ProgressDialog(getContext());
progressDialog.show(); // this line shows your dialog
You can put all your logic into the class using java as you want to only that now you can control your layout and how it looks in easier way.

How to disable back button in all dialogs and layouts?

In my code:
#Override
public void onBackPressed() {
}
It works fine, but if I call a dialog, for example
final Dialog dialogPopupGewonnen = new Dialog(Start.this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialogPopup.setContentView(R.layout.popup);
I can use the back button (the back button close the dialog popup). But I want to disable the back button in all layouts and dialogs.
You should override onBackPressed in all of your activities and for Dialog you can use setCancelable(false) like:
final Dialog dialogPopupGewonnen = new Dialog(Start.this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialogPopup.setContentView(R.layout.popup);
dialogPopup.setCancelable(false);

How to add buttons to the JFace ErrorDialog

I'm trying to add a "Cancel" button to this popup dialog, the dialog basically just gives the user some info and allows them to hit Yes or view details. The problem is that there is no Cancel button and I would like to add one.
The dialog is a JFace ErrorDialog which uses a premade MultiStatus to display the error message. The dialog opens and gives an OK button or a Cancel button. Is there anyway to directly manipulate how the dialog creates buttons or some other method I could use to change how it looks? Any help is appreciated!
if (ErrorDialog.openError(shell,
Messages.ConsistencyAction_confirm_dialog_title, null,
multiStatus, IStatus.WARNING) != Window.OK) {
return;
}
This is the dialog I'm trying to change. This is basically checking to make sure that someone presses ok, if they don't then you exit. You can exit it by hitting the red X in the corner but it'd be less confusing to have a button.
You can extend the ErrorDialog class so that you can override the createButtonsForButtonBar method.
For example this is from the Eclipse p2 install plugin:
public class OkCancelErrorDialog extends ErrorDialog {
public OkCancelErrorDialog(Shell parentShell, String dialogTitle, String message, IStatus status, int displayMask) {
super(parentShell, dialogTitle, message, status, displayMask);
}
#Override
protected void createButtonsForButtonBar(Composite parent) {
// create OK, Cancel and Details buttons
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, true);
createDetailsButton(parent);
}
}
With this you can't use the static ErrorDialog.openError method, instead you will have to do something like:
OkCancelErrorDialog dialog = new OkCancelErrorDialog(shell, Messages.ConsistencyAction_confirm_dialog_title, null, multiStatus, IStatus.WARNING);

dispatchKeyEvent doesn't effect to EditText inside PopupWindow

I have popup window that contains some EditTexts. I want to create my custom numerical keyboard inside the popup window. So I have 10 buttons that represent digits 0-9. Inside buttons' onClickListener I trying to dispatch key event
public void onClick(View v) {
dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_0));
}
but it doesn't effect to EditTexts. I tried to do it with focusable equals true and false, but the result is the same. When I am trying to dispatch key event in the main layout of activity it works well, so what I should change to make my code work inside popup window?
Have you tried requesting focus on the EditTexts? Not only using
editText.setFocusable(true);
but also
editText.requestFocus();
I think it's also possible that is not working because you're not injecting a DOWN event first. Try the following:
Instrumentation mInstrumentation = new Instrumentation();
final Thread t = new Thread() {
public void run(){
mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_0);
};
t.start();
This will inject an event which will be processed by the view that has the focus

Categories

Resources