frame.setVisible(true);
Panel panel = new Panel(new BorderLayout());
frame.add(panel);
IOfficeApplication officeApplication = getOfficeApplication(parent.getShell());
if(officeApplication.isActive()) {
IFrame officeFrame = officeApplication.getDesktopService().constructNewOfficeFrame(panel);
setFrame(officeFrame);
//resfresh file if possible
if(editorInput instanceof IFileEditorInput) {
IFile fileToRefresh = ((IFileEditorInput)editorInput).getFile();
fileToRefresh.refreshLocal(0,null);
}
//get URL of document if possible
URL documentURL = getURLFromEditorInput(editorInput);
DocumentDescriptor documentDescriptor = new DocumentDescriptor();
documentDescriptor.setTitle(editorInput.getName());
if(documentURL != null) {
documentDescriptor.setURL(documentURL.toString());
documentDescriptor.setBaseURL(documentURL.toString());
}
isSaveAsAllowed = true;
InputStream inputStream = null;
LoadDocumentOperation loadTextDocumentOperation = null;
//Load document with input stream if it is not a base document
if(!isBaseDocumentURL(documentURL) && editorInput instanceof IStorageEditorInput) {
IStorageEditorInput storageEditorInput = (IStorageEditorInput)editorInput;
boolean readOnly = false;
IStorage storage = storageEditorInput.getStorage();
if(storage == null || storage.isReadOnly())
readOnly = true;
documentDescriptor.setReadOnly(readOnly);
inputStream = storageEditorInput.getStorage().getContents();
if(documentURL != null && documentURL.getFile().endsWith(".xml")) { //$NON-NLS-1$
setXMLLoadFilter(composite.getShell(),documentDescriptor);
}
loadTextDocumentOperation = new LoadDocumentOperation(null, officeApplication, officeFrame, inputStream, documentDescriptor);
}
else if(documentURL != null) {
loadTextDocumentOperation = new LoadDocumentOperation(null,officeApplication, officeFrame, documentURL, documentDescriptor);
}
try {
if(loadTextDocumentOperation == null)
throw new CoreException(
new Status(
IStatus.ERROR,
EditorUIPlugin.PLUGIN_ID,
IStatus.ERROR,
Messages.OfficeEditorAdvisor_error_invalid_editor_input + editorInput.getClass().getName(),
null));
EditorUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().run(true, true, loadTextDocumentOperation);
}
catch(InterruptedException interruptedException) {
//do not consume
//TODO: clear the document in the office system
officeFrame.close();
frame.dispose();
composite.dispose();
composite = new Composite(parent, SWT.EMBEDDED);
return composite;
}