public class FMultiPageEditor extends MultiPageEditorPart implements IResourceChangeListener{
/**
* Creates page f of the multi-page editor,
* which contains a text editor.
*/
void createHPage() {
FEditorInput fInput = (FEditorInput) getEditorInput();
// h file
IFile hFile = formInput.getHFile();
try {
FileEditorInput fed = new FileEditorInput(hFile);
htmlEditorPart = makeDefaultEditorFor("default" + ".html");
int index = addPage(htmlEditorPart, fed);
setPageText(index, "");
setPageImage(index, fed.getImageDescriptor().createImage());
} catch (PartInitException e) {
ErrorDialog.openError(getSite().getShell(),
"r", null, e.getStatus());
} catch (Exception e) {
e.printStackTrace();
}
}
private IEditorPart makeDefaultEditorFor(String name) {
IEditorDescriptor editorDescriptor = getSite().getWorkbenchWindow()
.getWorkbench().getEditorRegistry().getDefaultEditor(name);
IEditorRegistry reg = WorkbenchPlugin.getDefault().getEditorRegistry();
EditorDescriptor desc = (EditorDescriptor) reg
.findEditor(editorDescriptor.getId());
if (desc == null)
return /*new TextEditor()*/null;
IEditorPart part = null;
try {
if (desc.getClassName() != null
&& desc.getClassName().equals(getClass().getName())) {
IEditorDescriptor[] editors = getSite().getWorkbenchWindow()
.getWorkbench().getEditorRegistry().getEditors(name);
for (int i = 0; i < editors.length; i++) {
if (editors[i].getId() != editorDescriptor.getId()) {
editorDescriptor = editors[i];
desc = (EditorDescriptor) reg
.findEditor(editorDescriptor.getId());
if (desc.getClassName() != null
&& !desc.getClassName().equals(
getClass().getName()))
break;
}
}
}
if (desc.getClassName() == null
|| desc.getClassName().equals(getClass().getName()))
part = new TextEditor();
else
part = desc.createEditor();
} catch (CoreException e) {
e.printStackTrace();
part = new TextEditor();
}
return part;
}