There is an excellent post on the Eclipse Community Forums about this: http://www.eclipse.org/forums/index.php/t/140214/
An extract:
You are using an instance of FormEditor as your editor. This editor
contains instances of FormPage as pages. I hope that you have
specialized SectionParts (or AbstractParts) as sections in the page.
In the section you have Text widgets that display some data and have
an ModifyListener attached. In this listener call markDirty() for the
section and the ManagedForm and FormEditor will handle dirty state for
you. And don't forget to add each SectionPart to the ManagedForm by
addPart(section)!
So essentially all you need is:
public class MyPage extends FormPage implements ModifyListener {
private SectionPart secPart;
private Text myText;
public MyPage(FormEditor editor, String id, String title) {
super(editor, id, title);
}
@Override
protected void createFormContent(IManagedForm form) {
secPart = new SectionPart(formBody, toolkit, Section.DESCRIPTION
| Section.TITLE_BAR);
Section section = secPart.getSection();
//add labels and controls for the three fields
myText = new Text(composite, SWT.BORDER);
myText.addModifyListener(this);
form.addPart(secPart);
}
public void modifyText(ModifyEvent arg0) {
secPart.markDirty();
}
}
As a side note, editorDirtyStateChanged() from FormEditor will nudge your plugin after you have made a save - to make the pages follow suit use commitPages(true). These methods are to be used AFTER you have saved of course - to let your workbench know everything is clean again.