Is it possible to change Finish button text to Done in Wizard? - java

I have created a custom wizard with some pages in eclipse plugin. The pages are created by extending the WizardPage. The wizard has Next back Finish and cancel button, and everything works fine.
Now, I want to change the name/text of Finish button to Done. Is it possible to do this in eclipse? Or will I need to provide all the buttons by myself, even this would be fine.

This should do:
#Override
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
Button finish = getButton(IDialogConstants.FINISH_ID)
finish.setText("Done");
setButtonLayoutData(finish);
}
Here is a related question.

So this is how I was using the wizard:
MyCustomWizard wizard = new MyCustomWizard ("title");
WizardDialog wizardDialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard);
wizardDialog.open();
Now I created a new class, MyCustomDialog extending the WizardDialog:
public class MyCustomDialog extends WizardDialog {
public MyCustomDialog(Shell parentShell, IWizard newWizard) {
super(parentShell, newWizard);
}
#Override
public void createButtonsForButtonBar(Composite parent){
super.createButtonsForButtonBar(parent);
Button finishButton = getButton(IDialogConstants.FINISH_ID);
finishButton.setText(windowTitle);
}
}
And now I changed the code where I create wizard and wizard dialog as:
MyCustomWizard wizard = new MyCustomWizard ("title");
MyCustomDialog wizardDialog = new MyCustomDialog(Display.getDefault().getActiveShell(), wizard);
wizardDialog.open();
Hope it is useful to someone! :)
Thanks for the help #greg-449 and #Baz

There is one more way to change the label of any button. You can override createButton of WizardDialog class as :
#Override
protected Button createButton(Composite parent, int id, String label,
boolean defaultButton) {
if (id == IDialogConstants.FINISH_ID) {
return super.createButton(parent, id,
"Done", defaultButton);
}
return super.createButton(parent, id, label, defaultButton);
}

Related

How to properly code the confirm dialogs with Android?

It's supposed to be a very common thing: having dialog boxes to confirm to proceed the flow of the interaction with users. But the best I can come up with with the information I've dug doesn't seem good to me. I primarily extended DialogFragment (following the first searches for examples) and implement the NoticeDialogListener.
I came to believe that this is not the better way because as far as program flow is concerned, it's very cumbersome. Program flow-wise I understand it can be cumbersome anyway as Dialog appears as another thread from the main to begin with, but I suppose there should be a better way to assign different responding method to different dialog. But I haven't been able to find a way except what's following.
Hopefully I've described my question clearly. Thanks in advance for the response.
public class Confirm extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(sQ);
builder
.setPositiveButton(sYes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mListener.Yes();
}
})
.setNegativeButton(sNo, null);
return builder.create();
}
public interface NoticeDialogListener {
void Yes();
}
private NoticeDialogListener mListener;
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mListener = (NoticeDialogListener) activity;
}
}
public class Main extends ActionBarActivity
implements Confirm.NoticeDialogListener {
...
private int iDialogMode;
private final static int DIALOG_ST_0 = 0;
private final static int DIALOG_ST_1 = DIALOG_ST_1 + 1;
private final static int DIALOG_ST_2 = DIALOG_ST_1 + 1;
#Override
public void Yes() {
switch (iDialogMode) {
case DIALOG_ST_0: // follow up HERE0 for what that dialog prompted
break;
case DIALOG_ST_1: // HERE1: feeling not smart
break;
case DIALOG_ST_2: // HERE2: believe there should be a better way
break;
}
}
public ... State_0_doing_something (...) {
...
Confirm diaBox = new Confirm (...);
iDialogMode = DIALOG_ST_0;
diaBox.show(getSupportFragmentManager(), "State_0");
// what's supposed to continue if confirmed will be followed up in HERE0 in Yes()
}
public ... State_1_doing_something_else (...) {
...
Confirm diaBox = new Confirm (...);
iDialogMode = DIALOG_ST_1;
diaBox.show(getSupportFragmentManager(), "State_2");
// what's supposed to continue if confirmed will be followed up in HERE1 in Yes()
}
public ... State_2_doing_yet_something_else (...) {
...
Confirm diaBox = new Confirm (...);
iDialogMode = DIALOG_ST_2;
diaBox.show(getSupportFragmentManager(), "State_3");
// what's supposed to continue if confirmed will be followed up in HERE2 in Yes()
}
}
I am thinking if I can attach a different click listener to each Confirm dialog box created instead of setting the dialog mode/state using global variable/member like that. Am missing function pointers here...
"By the way, how come I couldn't properly post the beginning declaration and ending bracket in the grey box? "
Add 4 blank spaces before that text, or add the ` character at the beggining and end of the code text.
Example:
Fake code that does nothing
"Program flow-wise I understand it can be cumbersome anyway as Dialog appears as another thread from the main to begin with"
This is basically why its not intended for the user to keep on using dialog boxes. The way I saw most programs so far, is that only actions that could severely delay the application or that could possibly charge the user would use dialogs.
Also, note the Activity lifecycle will make you keep its "state" remembered, this can further add to issues with onPause/onResume with your app.
Solved: the only problem is that it's not as nice looking
AlertDialog.Builder builder = new AlertDialog.Builder(Home.theContext);
builder.setMessage(R.string.confirm_delete);
builder.setCancelable(true);
builder.setPositiveButton(R.string.confirm_yes, vCabDelete());
builder.setNegativeButton(Home.theContext.getString(R.string.confirm_no), null);
AlertDialog dialog = builder.create();
dialog.show();
....
private static DialogInterface.OnClickListener vCabDelete() {
return new DialogInterface.OnClickListener() {
public void onClick(DialogInterface di, int id) {
....
}
};
}

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

Jface Dialog, How to retrieve correctly what button pressed the user?

I'm having troubles with a custom Dialog in Eclipse.
in the first place, I created a Class that extend Dialog.
public class ModificarGrupoBCDialog extends Dialog {
private static final int CANCELAR = 999;
private static final int MODIFICAR = 1;
...
somewhere I create the buttons...
protected void createButtonsForButtonBar(Composite parent) {
this.createButton(parent, MODIFICAR, "Modificar", true);
this.getButton(MODIFICAR).setEnabled(puedeAltaGrupoBC());
this.bt_ok = this.getButton(MODIFICAR);
this.createButton(parent, CANCELAR, "Cancelar", false);
Display display = window.getShell().getDisplay();
Image image = new Image(display, ModificarGrupoBCDialog.class.getResourceAsStream("/icons/modificar.png"));
this.getButton(MODIFICAR).setImage(image);
image = new Image(display, ModificarGrupoBCDialog.class.getResourceAsStream("/icons/cancelar.png"));
this.getButton(CANCELAR).setImage(image);
}
and when the user clicks...
protected void buttonPressed(int buttonId) {
switch (buttonId) {
case MODIFICAR:
// Some Code, for Change Button
break;
case CANCELAR:
setReturnCode(CANCELAR);
close();
break;
}
Finally, this is how I open and get the returnCode, in the caller object.
...
ModificarGrupoBCDialog modificarGrupoBC = new ModificarGrupoBCDialog(window.getShell(), window, gr_bc);
if (modificarGrupoBC.getReturnCode() == Window.OK) {
//... Some code on OK
} else {
//another code when cancel pressed.
}
;
as you can see, after trying a while, I have to write setReturnCode() in CANCELAR switch block, is that OK ?
I spect that Dialog class automatically asign the correct return code.
May be someone could point me to a good sample.
I'm reading Vogela's blog, and may be the solution is to override okPressed() method ?
Best Regards.
The standard dialog sets the return code in two places:
protected void okPressed() {
setReturnCode(OK);
close();
}
protected void cancelPressed() {
setReturnCode(CANCEL);
close();
}
so your code doing:
setReturnCode(xxxx);
close();
should be fine as long as the button id you are using does not match the Cancel or OK button ids.
You could also use the approach used by MessageDialog which simply does this:
protected void buttonPressed(int buttonId) {
setReturnCode(buttonId);
close();
}

How to set Dialog result while clicking X - close window button in ControlsFX

I extended ControlsFX Dialog to create a custom ValidationDialog. I added some custom buttons where, one of them trigger a validation operation after clicking on it. If validation is passed, the dialog is closed with the OK result, but if dialog is not valid, a dummy Action objech is assigned to a dialog result action. It purpose (dumy result) is just to save information that user tried to fill dialog, and allow him to make some corrections (not to close window). Everything would be ok, but there is one scenario which creates wrong result. If user will fill form with an error data, than click validation button and after that he will click X button (close window). After those steps the dialog result will be still a validation button. I tried to bind some listener to window onCloseRequest() property, but it is not reacting. How to solve this issue?
Below is a shortened version of my code:
public class ValidationDialog extends Dialog {
private ValidationDialog thisDialog;
public final Action DUMMY_ACTION = new AbstractAction("OTHER") {
{
ButtonBar.setType(this, ButtonBar.ButtonType.OTHER);
}
#Override
public void execute(ActionEvent actionEvent) {
//do nothing
}
};
public final Action VALID_OK = new AbstractAction("OK"){
{
ButtonBar.setType(this, ButtonBar.ButtonType.OK_DONE);
}
#Override
public void execute(ActionEvent ae) {
if (isValid()) {
thisDialog.setResult(this);
thisDialog.hide();
} else {
thisDialog.setResult(DUMMY_ACTION);
}
}
};
public ValidationDialog(Object owner, String title) {
super(owner, title);
thisDialog = this;
}
private boolean isValid(){
return false;
}
}
and it's call:
ValidationDialog validationDialog = new ValidationDialog(stage, "Fill form");
Action result = validationDialog.show();
if (result.equals(validationDialog.VALID_OK)){
//do important stuff
}
One would have expected that clicking X will always mean cancel.
So far the only way is to create own boolean variable like "valid" with getter, then set it before hide().
outside do:
if (dlg.isValid()) {
//dlg success
} else {
//dlg fail
}

How to change the size of the dialog?

I created a dialog class:
myDailog extends Dialog
public myDailog (Shell parentShell, String tatgetEntity) {
super(parentShell)
}
#Override
protected Control createDialogArea(final Composite parent) {
final Composite body = (Composite) super.createDialogArea(parent);
...//some logic to create tableViewwer
}
The problem that I can't change the size of the dialog (stretch the windows).
Do I need to use different dialog?
Override the isResizable method of org.eclipse.jface.dialogs.Dialog:
#Override
protected boolean isResizable()
{
return true;
}
You may need to use this public method to enable the dialog to be resizable:
public void setResizable(boolean resizable)
ps I'm assuming you are using this java.awt.Dialog class

Categories

Resources