如何使用 Eclipse CNF 的 Saveable Protocol 实现对 View 的保存
2010-05-04 00:00:00 来源:WEB开发网第二步:为导航器上添加 ContentProvider 和 LabelProvider, 在 providesSaveables 属性上,将其值指明为 true. 同时 ContentProvider 属性所对应的类必须实现 IAdatpable 接口,能够适配于 SaveablesProvider 类型。
图 6. contentNavigator 扩展点的 providesSaveables 属性
清单 1. 样例代码
public class SaveableContentProvider extends SaveablesProvider implements
ITreeContentProvider, IAdaptable {
@Override
public Object[] getElements(Saveable saveable) {
if(saveable instanceof SaveablePart){
IWorkbenchPart part = ((SaveablePart)saveable).getWorkbenchPart();
IEditorInput editorInput = ((TextFileEditor)part).getEditorInput();
TextFile file = ((TextFileEditorInput)editorInput).getTextFile();
return new Object[]{ file };
}
return null;
}
@Override
public Saveable getSaveable(Object element) {
if (element instanceof TextFile) {
IWorkbenchPart part = FolderManager
.getWorkbenchPart((TextFile) element);
if(part != null){
final SaveablePart saveable = new SaveablePart(part);
return saveable;
}
}
return null;
}
@Override
public Saveable[] getSaveables() {
Object [] parts = FolderManager.getAllOpenedWorkbenchPart();
final Saveable[] saveables = new Saveable[parts.length];
return saveables;
}
}
更多精彩
赞助商链接