Consider this familiar New Java class wizard.
It has to keep track of the status of the source folder, package, enclosing type, name, ... When ever there is a change in these fields, the WizardPage's status has to be updated. The algorithm goes like this: find the most severe status and update the wizard page with that status. This is a very common operation can be applied to any WizardPage. So I've written a helper method which I usually use it in almost all of the WizardPage I create. Let me know if it can be improved
public static void applyStatus(WizardPage page, IStatus[] statuses) {
IStatus severeStatus = statuses[0];
for (IStatus status : statuses) {
severeStatus = severeStatus.getSeverity() >= status.getSeverity() ? severeStatus : status;
}
String message = severeStatus.getMessage();
switch (severeStatus.getSeverity()) {
case IStatus.OK:
page.setMessage(null, IMessageProvider.NONE);
page.setErrorMessage(null);
break;
case IStatus.WARNING:
page.setMessage(message, IMessageProvider.WARNING);
page.setErrorMessage(null);
break;
case IStatus.INFO:
page.setMessage(message, IMessageProvider.INFORMATION);
page.setErrorMessage(null);
break;
default:
if (message.length() == 0) {
message = null;
}
page.setMessage(null);
page.setErrorMessage(message);
break;
}
}
Feb 18, 2008
Handy util method for WizardPages
Posted by
Prakash G.R.
at
11:37 PM
Labels: guidelines, jface, wizards
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment