前回まででGUIの実装は完了しましたので,
プラグインプロジェクトのダウンロード
YAMLファイルの読み書きを実装したプラグインプロジェクトを下記のリンクからダウンロードし,
変更の判定
マニフェストエディターで内容を変更すると,
ISaveablePartインタフェースのisDirty()メソッド
public interface ISaveablePart {
...
/**
* Returns whether the contents of this part have changed since the last save
* operation. If this value changes the part must fire a property listener
* event with <code>PROP_DIRTY</code>.
* <p>
* <b>Note:</b> this method is called often on a part open or part
* activation switch, for example by actions to determine their
* enabled status.
* </p>
*
* @return <code>true</code> if the contents have been modified and need
* saving, and <code>false</code> if they have not changed since the last
* save
*/
public boolean isDirty();
...
}
JavaDocの説明を読むと,
FormEditorクラスのisDirty()メソッド
public abstract class FormEditor extends MultiPageEditorPart implements IPageChangeProvider {
...
public boolean isDirty() {
if (pages != null) {
for (int i = 0; i < pages.size(); i++) {
Object page = pages.get(i);
if (page instanceof IFormPage) {
IFormPage fpage = (IFormPage) page;
if (fpage.isDirty())
return true;
}
}
}
return super.isDirty();
}
...
}
FormEditorクラスのisDirty()メソッドではaddPage()メソッドで追加されたIFormPageクラスのisDirty()メソッドを確認していることがわかります。このように,
Eclipseのエディターでどのように変更の判定が行われているかを理解したところで,
- フィールドが追加されたとき
- フィールドが削除されたとき
- フィールドが上下に移動されたとき
- フィールドの詳細が変更されたとき
1~3についてはそれぞれ対応するボタンが実行されたときに,
変更の状態は保管されたときにリセットされる必要があります。そこでFormDeisgnerEditorクラスのdoSave()メソッドを実装します。
FormDesignerEditorクラスのdoSave()メソッド
public class FormDesignerEditor extends FormEditor {
...
@Override
public void doSave(IProgressMonitor monitor) {
commitPages(true);
editorDirtyStateChanged();
}
...
}
}
commitPages()メソッドはisDirty()メソッドと同じように保持しているIFormPageオブジェクトやIManagedFormオブジェクトに対してcommit()メソッドを呼び出し,