关键代码在org.eclipse.ui.internal.editorsupport.win32.OleEditor,
先创建OleFrame对象
@Override
public void createPartControl(Composite parent) {
// Create a frame.
clientFrame = new OleFrame(parent, SWT.CLIP_CHILDREN);
clientFrame.setBackground(JFaceColors.getBannerBackground(clientFrame
.getDisplay()));
initializeWorkbenchMenus();
createClientSite();
updateDirtyFlag();
oleActivate();
}
再创建OleClientSite对象
private void createClientSite() {
//If there was an OLE Error or nothing has been created yet
if (clientFrame == null || clientFrame.isDisposed())
return;
// Create a OLE client site.
try {
clientSite = new OleClientSite(clientFrame, SWT.NONE, source);
} catch (SWTException exception) {
IStatus errorStatus = new Status(IStatus.ERROR,
WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR,
OLE_CREATE_EXCEPTION_REASON, exception);
//ErrorDialog.openError(null, OLE_EXCEPTION_TITLE, OLE_CREATE_EXCEPTION_REASON, errorStatus);
ErrorDialog.openError(null, OLE_EXCEPTION_TITLE, OLE_CREATE_EXCEPTION_MESSAGE, errorStatus);
return;
}
clientSite.setBackground(JFaceColors.getBannerBackground(clientFrame
.getDisplay()));
}
修改后调用save保存
private boolean saveFile(File file) {
File tempFile = new File(file.getAbsolutePath() + ".tmp"); //$NON-NLS-1$
file.renameTo(tempFile);
boolean saved = false;
if (OLE.isOleFile(file) || usesStorageFiles(clientSite.getProgramID())) {
saved = clientSite.save(file, true);
} else {
saved = clientSite.save(file, false);
}
if (saved) {
// save was successful so discard the backup
tempFile.delete();
return true;
}
// save failed so restore the backup
tempFile.renameTo(file);
return false;
}