OpenOffice + RCP: impossible? [message #499645] |
Mon, 23 November 2009 10:33  |
Eclipse User |
|
|
|
Hi, I strongly fear I will have to drop my attempt to use OOoWriter to as an integrated editor (EditPart) in an Eclipse RCP Application.
Reason is I see in the OpenOffice.org 3.1 Developer's Guide:Quote: | A standard OpenOffice.org is a prerequisite. The OpenOffice.org executable, as well as the UNO libraries and runtime, is found using the Java Class Loader. Moving or copying the needed class files will not result in a working OOoBean.
|
While Paul Webster (RCP) tells me:Quote: | To write a plugin your classpath has to be entirely described by your MANIFEST.MF.
That means the jars providing have to be included in your plugin (and on the bundle classpath) or have to be turned into bundles themselves (and required from your bundle).
|
I seem to understand the latter means I have to copy the class+.dll into a bundle, but this is forbidden by the former.
I tried and I actually got a "No connection" error.
I would like someone knowledgeable to confirm it's useless to try to make this work.
Alternatively I would like a workaround, if available.
In particular it would be nice to know if there's a way to display a complete external application (exec(program, arg)) in a SWT Widget.
I will send an equivalent message also to the OpenOffice forum.
TiA
Mauro
|
|
|
|
|
|
|
|
|
|
Re: OpenOffice + RCP: impossible? [message #500156 is a reply to message #500015] |
Wed, 25 November 2009 03:42  |
Eclipse User |
|
|
|
Hi Gilbert,
Thanks for Your input.
I managed to open generic files using the following code:public class RTFEditor extends EditorPart {
public static final String ID = "it.condarelli.rcp.yw.rtfeditor";
private Composite top = null;
private static int usecount = 0;
private static ITextDocument doc = null;
private static IOfficeApplication app = null;
public RTFEditor() {
super();
usecount++;
}
@Override
public void dispose() {
if (doc != null) {
doc.close();
doc = null;
}
if (usecount > 0) {
if (--usecount == 0) {
if (app != null) {
if (app.isActive())
try {
app.deactivate();
} catch (OfficeApplicationException e) {
e.printStackTrace();
}
app.dispose();
app = null;
}
}
}
super.dispose();
}
@Override
public void doSave(IProgressMonitor monitor) {
if (doc != null) {
if (doc.isModified()) {
IPersistenceService ps = doc.getPersistenceService();
try {
ps.store();
} catch (DocumentException e) {
e.printStackTrace();
}
}
}
}
@Override
public void doSaveAs() {
}
@Override
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
setSite(site);
setInput(input);
}
@Override
public boolean isDirty() {
if (doc != null) {
return doc.isModified();
}
return false;
}
@Override
public boolean isSaveAsAllowed() {
return false;
}
@Override
public void createPartControl(Composite parent) {
IOfficeApplication a = EditorCorePlugin.getDefault().getManagedLocalOfficeApplication();
if(!a.isActive()) {
app = null;
Shell shell = parent.getShell();
IStatus status = NOAUIPlugin.startLocalOfficeApplication(shell, a);
if (status.getSeverity() != IStatus.ERROR) {
app = a;
}
}
if (app != null) {
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.verticalAlignment = GridData.FILL;
top = new Composite(parent, SWT.NO_BACKGROUND | SWT.EMBEDDED);
top.setLayout(new GridLayout());
Frame frame = SWT_AWT.new_Frame(top);
try {
IFrame ifr = app.getDesktopService().constructNewOfficeFrame(frame);
IEditorInput ei = getEditorInput();
FileStoreEditorInput fsei = (FileStoreEditorInput) ei.getAdapter(FileStoreEditorInput.class);
URI uri = fsei.getURI();
String url = uri.toString();
try {
IDocumentService s = app.getDocumentService();
IDocument d = s.loadDocument(ifr, url);
if (d instanceof ITextDocument) {
doc = (ITextDocument) d;
try {
URL u = uri.toURL();
String t = u.getFile();
int i = t.lastIndexOf('/');
t = t.substring(i+1);
setPartName(t);
} catch (MalformedURLException e) {}
}
} catch (DocumentException e1) {
e1.printStackTrace();
} catch (OfficeApplicationException e1) {
e1.printStackTrace();
}
} catch (DesktopException e) {
e.printStackTrace();
} catch (OfficeApplicationException e) {
e.printStackTrace();
}
}
}
@Override
public void setFocus() {
doc.getFrame().setFocus();
}
}
This is activatrd with something like: String tf = "file:///C:/what/ever/path/to/your/file.rtf";
try {
URI uri = new URI(tf);
try {
IFileStore fs = EFS.getStore(uri);
IEditorInput ei = new FileStoreEditorInput(fs);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
try {
page.openEditor(ei, RTFEditor.ID);
} catch (PartInitException e1) {
e1.printStackTrace();
}
} catch (CoreException e2) {
e2.printStackTrace();
}
} catch (URISyntaxException e2) {
e2.printStackTrace();
}
I had a lot of problems finding out a workable combination and this seems ok.
I still have several problems to solve, if someone cares to help:
- I need to hook to the editor close event in order to ask for save and, even more important, to notify to OpenOffice to close and discard the document. Currently I need to completely shut down OOo after editing because simply closing the EditorPart does not notify OOo and thus an headless document remains open and I can reopen it only in read-only mode. (I partially solved this in the latest code, but I'm not sure this is all that is needed).
- I would like to change some of the default settings, most notably I would like to set View->Web Layout mode. I didn't (yet) found a way to do that programmatically.
- Do save/restore and dirty-page handling programmatically, so I can completely disable the main-menu.
- Programmatically disable the main menu (i know how to do that with OOoBean, but not with noa4e).
- Some other minor issues.
Tia
Mauro
|
|
|
Powered by
FUDForum. Page generated in 0.07483 seconds