Can you disable the back button in a JFace wizard? - java

I'm writing a wizard for an Eclipse RCP application. After doing some processing on a file and taking some user input, I don't want to let the user go back to make changes. At this point they must either accept or reject the changes they are about to make to the system.
What I can't seem to find is a method call that lets me override the buttons that display or the user's ability to hit the back button. I'd prefer that it not be there or at least be disabled.
Has anyone found a way to do this using the JFace Wizard and WizardPage?
Usability-wise, am I breaking wizard conventions? Should I consider a different approach to the problem?

You can return null from the getPreviousPage() method in your wizard page implementation.

Expanding on jodonell's answer:
Disabling the back button is harder than it should be, due to non-intuitive behavior in the default implementation of WizardPage.getPreviousPage(). You can call setPreviousPage( null ), and getPreviousPage() still returns the previous page. You need to override the implementation of getPreviousPage() in order to disable the back button:
public abstract class MyWizardPage extends WizardPage {
private boolean backButtonEnabled = true;
public void setBackButtonEnabled(boolean enabled) {
backButtonEnabled = enabled;
getContainer().updateButtons();
}
#Override
public IWizardPage getPreviousPage() {
if (!backButtonEnabled) {
return null;
}
return super.getPreviousPage();
}
}
See my blog post for a few more JFace wizard tips and tricks:
http://nsawadsky.blogspot.com/2011/07/jface-wizard-tips-and-tricks.html

From a UI perspective this seems rather bad. Your users are going to get frustrated if they make a mistake and want to go back and correct it and you don't let them. I think it would be much better to change the application to allow going back rather than looking for ways to prevent it.

There is no way to do this using standard JFace wizard APIs. My team accomplished this by writing a custom WizardDialog. We did this on an Eclipse RCP application and not on an eclipse plugin. Disabling the back button is breaking convention, but our business analysts really wanted the functionality.

Related

Create a MultipageEditor for XML

I am working on an eclipse Plugin, and I would like to use an Editor, set some listeners on the current page(good terminology?), and remove these listeners when the user switches on another page (basically, the user is editing several files, as you could do with the default JAVA editor).
For the moment I have written a class extending StructuredTextEditor. The behavior of the plugin was the one expected, but when I try to work on several files, many problems occur. The main problem, according to me, is that I am not able to get notified when the user opens another page.
I read (and tested) a few things about MultiPageEditor, but it seems like it doesn't integrate an XML editor as default editor. How should I proceed in order to get a MultiPageEditor, with XML syntax coloring, and get notified when the user changes the current page to adjust my listeners ?
Thanks for reading.
the code is not perfect but at least you will have an example of a MultiPageEditor integrating an XMLEditor: https://github.com/fusesource/fuseide/blob/8.0.0.Beta2/editor/plugins/org.fusesource.ide.camel.editor/src/org/fusesource/ide/camel/editor/CamelEditor.java
The idea is to call addPage(new StructuredTextEditor()) inside createPages() method.
regards,
In your editor you can listen to selection changes in the editor text using:
getSelectionProvider().addSelectionChangedListener(listener);
where listener implements ISelectionChangedListener.
This applies to any editor derived from AbstractTextEditor (which includes StructuredTextEditor.
You need to do this fairly late in the editor creation. In the createPartControl method works:
#Override
public void createPartControl(final Composite parent)
{
super.createPartControl(parent);
getSelectionProvider().addSelectionChangedListener(listener);
}

How to make part tab inactive (disable) in Eclipse RCP?

I have partStack with a lot of parts in tabs. I'd like to know how can I make tabs inactive when I don't need them and active when I need.
By inactive I mean tab which is visible but I can't click on it and it is like disable function (for example text on it is gray instead of black).
I use an e4 RCP (with Application.e4xmi).
Thanks for help.
Handling of the selection of parts in a part stack is handled by the part stack renderer org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer which basically uses a CTabFolder.
You can use a renderer factory to override the stack renderer see here
You can extend the existing StackRenderer class and override methods to change its behavior. In this case probably the hookControllerLogic method. But you are going to have to study the source carefully to see what needs to be done.
You can try using using EPartService to manipulate a part but I think active/inactive part just means visible or not.
Or you can just loop and disable all swt controls yourself manually 😄
Use Renderer factory to override the stack renderer.
Extend the existing StackRenderer class and override hookControllerLogic() or activate() methods with empty implementation.
Example-
public class MyE4Part extends ContributedPartRenderer {
/*
* Don't activate the Part on part selection. part should not be gain the focus on any
* selection on part .
*/
#Override
public void hookControllerLogic( MUIElement me )
{
//Don't do anything.
//super.hookControllerLogic( me );
}
}

Prevent User From leaving unsaved forms with smartgwt

Right now I'm working in a big smartgwt project. I need to implement a nice feature but I have no idea how to do it.
Our application has a lots of forms located in different tabs and grids and so on. Each form has his own save button and when it gets pressed it performs some few actions before the save action. For the application, it is really important to only save the form when the user presses the button. What I need is some kind of handler to prevent a user leaving unsaved forms. My intention is to show some kind of warning popup but I have no idea how to bind the action.
I don't know even if it's possible to do something like that with smartgwt but it seems to me a very typical feature to have in a big web application.
Some ideas? Someone had this problem before?
You can intercept almost every user action in GWT. If you want for example to prevent user from leaving page you can use something like this:
Window.addWindowClosingHandler(new Window.ClosingHandler() {
#Override
public void onWindowClosing(ClosingEvent event) {
if (unsavedData) {
event.setMessage("There is unsaved data. Do you really want to leave?");
}
}
});
If you want to stop user on different action like closing tab you can also do that by adding proper event listener.
Determining whether there is some unsaved data is also fairly simple but depends on UI component.
For example in listGrid you can use listGrid.getAllEditRows().lenght
In form you can compare form.getOldValues() with form.getValues() (Guava library will be perfect for this task: Maps.difference(form.getOldValues(), form.getValues()).areEqual()) Maybe there is better way to check unsaved data in form but I don't know it.
And last problem - linking it all together. I created custom save controller with multiple save participants. With this approach you can ask controller.isThereAnyUnsavedData() and controller should ask each participant.

Test GWT SimplePager ImageButton enabled state in Selenium

We are using the GWT provided SimplePager to provide record/page navigation through data sets. We want to test that we are controlling the enabled state of the Next/Previous buttons properly. While SimplePager lets us specify enabled/disabled images for the buttons, the "button" itself is an internal class of ImageButton which extends Image rather than Button. Therefore the resulting HTML does not use Button enabled/disabled attributes, but rather provides a different embedded image for each state.
Is there any reasonable way to detect the SimplePager navigation button enabled states in Selenium?
In standard practice you should create custom component, let say Image button. I would suggest you to use ISFW which provides feature of creating custom component that can be used with annotation. In component you can specify behavior in as per AUT.
Re-writing the code sample to have better formatting.
public class ImageButton extends Component{
public ImageButtom (String loc){
super(locator);
}
#Override
public boolean isEnabled() {
//custom representation!...
return this.getAttribute("class").contains("imgdisabled");
//return this.getCssValue("background").contains("imgdisabled");
//return this.getAttribute("src").contains("imgdisabled");
}
}
You can use this component like Webelement in your test page
#FindBy(locator="locator")
ImageButton prevButton;
#FindBy(locator="locator")
ImageButton nextButton;
In your test code
page.prevButton.verifyEnabled();
page.prevButton.assertEnabled();
Looking at the source code of SimplePager, it looks like they use a generator to create the css styles, where the disabled state (and the enabled state) has a css class applied to it (i m going off this https://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/user/cellview/client/SimplePager.java?r=9614).
So if you can somehow get access to the actual Resources client bundle, then you can call resources.simplePagerStyle().disabledButton() to get a string that is the css class for the disabled button, and you can then use that as a locator in selenium. That might be really tricky tho, because the jvm running your selenium test may not be able to reference the compiled GWT code (i.e., the code that runs when you debug a GWT app).
Alternatively, you can subclass SimplePager, instead of using the DEFAULT_RESOURCES client bundle, pass in your own, and then you get to control the classname used for the disabled button (by making your own Style class, which just wraps the existing one you get from the original client bundle, but add a prefix or something to the return value).
It's a bit messy, because the component is quite encapsulated, and you are trying to get at its innards.

Add a more button to gwt Suggest Box

I have a gwt suggest box that does an RPC call to get some data from the server and display it. In some cases there are up to 2000 results. Whilst this works fine in chrome when the javascript runs in firefox it freezes the window for 5 seconds and sometime brings up script not responding warnings.
What I wanted to do was something like show 20 results and have a more button that can just append the next 20 without having to call back to the server every time it is clicked. I am fairly new to this, I have tried extending suggestBox and overriding showSuggestions() but it is protected so I can't.
Any suggestions/ ideas would be great.
Cheers,
Rob
See this question for pointers on how to extend the GWT's SuggestBox - basically, you want to provide your own SuggestOracle (it's used for fetching the suggestions), maybe your textbox (see the links in the question I mentioned earlier) and most likely a custom SuggestBox.SuggestionDisplay. Those three are passed via the constructor to SuggestBox. See the existing default implementations (MultiWordSuggestOracle, SuggestBox.DefaultSuggestionDisplay) for some ideas :)
If you want to change source code of SuggestBox see this
you should create com.google.gwt.user.client.ui packeges in your src root and copy there SuggestBox.java. When you use SuggestBox it calls your SuggestBox which is in your src.
Check this also it can be useful too
First solution come to mind is that write your own widget which extends from SuggestBox and the second solution maybe change the default css parameters of suggestbox
.gwt-SuggestBox {
}
.gwt-SuggestBoxPopup {
}
.gwt-SuggestBoxPopup .item {
}
.gwt-SuggestBoxPopup .item-selected {
}
.gwt-SuggestBoxPopup .suggestPopupContent {
}

Categories