views:

620

answers:

3

On an Eclipse RCP application, I'm building an Editor in which some fields are mandatory.

If the user saves the editor with theses fields not filled, what is the best way/practice to handle this ?

(my first guess is to show an error dialog if theses fields are empty in doSave() method but I'm not sure it's the "eclipse" way to deal with this kind of problem)

+2  A: 
VonC
Thanks you for that answer. It's a very clever idea.However, I'm not in a wizard but in an editor (like the "editor" view for plugin.xml for example). So, I don't have a button in my form but I have a "save" button in my toolbar (which btw, I don't know how to disable, see question 650775).
paulgreg
Argh... I had answered that one too! I still think the declarative option is not the best way to manage the Save Action state.
VonC
Yes, that's true ! But I would like to make it work through a declarative way... If I can't, I will use your solution.
paulgreg
+1  A: 

I agree with VonC and would disable the "Save" button, as long as the user has filed all the important fields. Showig a warning which fields the user has to fill would help a lot.

EDIT:

Create a component which added himself as change listener. When someone changes the component, you can check whether the input is correct. Create a window whith all the self-checking components and add the window as listener to all the components.

When somebody change a compounent you can directly check if the input is valid and the user can step to the next page or save the page.

In RCP (Example FieldEditorPreferencePage) a lot of components have the doSave() and isValid() methods. In isValid() you can check all the components you can find in the window and in doSave(), you sould check the isValid() state, when it is not done automatically, and do some additional save actions.

Markus Lausberg
I agree.So, is there a way to add an mark or an icon to a label ?
paulgreg
I updated my message and hope you can handle this by implementing isValid().
Markus Lausberg
Thanks, I'll try that !
paulgreg
+1  A: 

You could use FieldDecorations to mark the mandatory fields and provide visual feedback if the content of a field is incorrect.

ftl