|
|
|
Re: OpenOffice + RCP: impossible? [message #499699 is a reply to message #499645] |
Mon, 23 November 2009 18:36 |
Eclipse User |
|
|
|
Originally posted by: formatzeh.gmx.de
Hi Mauro,
> I would like someone knowledgeable to confirm it's useless to try to
> make this work.
I can say that I got OO integrated into my RCP app with the noa4e
plugins. If you add all those plugins to your runtime config you can for
example create an empty file with the following snippet:
File tempFile; // specify the desired path
IOfficeApplication app =
EditorCorePlugin.getDefault().getManagedLocalOfficeApplicati on();
if(!app.isActive()) {
Shell shell = Display.getCurrent().getActiveShell();
IStatus status = NOAUIPlugin.startLocalOfficeApplication(shell, app);
if (status.getSeverity() != IStatus.ERROR) {
ITextDocument doc = (ITextDocument)
app.getDocumentService().constructNewDocument(IDocument.WRIT ER,
DocumentDescriptor.DEFAULT_HIDDEN);
doc.getTextService().getText().setText("");
FileOutputStream fos = new FileOutputStream(tempFile);
doc.getPersistenceService().store(fos);
doc.close();
}
}
HTH,
Gilbert
|
|
|
|
Re: OpenOffice + RCP: impossible? [message #499803 is a reply to message #499746] |
Tue, 24 November 2009 09:02 |
Eclipse User |
|
|
|
Originally posted by: formatzeh.gmx.de
Hi Antonio,
I checked out the example and you are right - it seems that noa4e has
dependencies to swing. I can only say that it works in my RCP app and I
know from a friend that this app worked under his Linux as well. Sorry,
for not having more detailed information.
best regards,
Gilbert
|
|
|
|
Re: OpenOffice + RCP: impossible? [message #500015 is a reply to message #499831] |
Tue, 24 November 2009 17:27 |
Eclipse User |
|
|
|
Originally posted by: formatzeh.gmx.de
Hi Mauro,
> I'm trying to make noa4e work for me, but I have some problems because I
> couldn't find any documentation.
> Do You know where it is (if it exists)?
Well, indeed the documentation of noa is very reserved. There is a
little forum [1] which is very asynchronous.
> Current problem is I want to open a file in my EditorPart and I see only
> services to add text, delete text, ... etc. I just want to edit a file
> on my filesystem (not workspace), so I have the normal: URI uri = new
I don't know if this is possible. Some time ago I had problems with
errors because my files I wanted to open physically were situated in a
folder in the workspace but were just copied with normal file operations
from the Java API instead of Eclipse IFile operations. After changing
that issue - means that I made changes in my file system only with IFile
operations - I could open the files. Before always the exception came
that the given resource doesn't exist. Thus I can imagine that you can
only open files in your workspace but I'm not sure about that.
> IFileStore fs = EFS.getStore(uri);
> IEditorInput ei = new FileStoreEditorInput(fs);
> IWorkbenchWindow window =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow();
> IWorkbenchPage page = window.getActivePage();
> page.openEditor(ei, RTFEditor.ID);
This should be enough to open an existing file with the noa4e editor.
The only mistake is the editor id you have used. here you have to take
the correct one for the OpenOffice editor. For the OO writer it is for
example ag.ion.bion.workbench.office.editor.ui.TextOfficeEditor. You can
do this programmatically with the following snippet:
String fileName;
IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
IEditorDescriptor descriptor = registry.getDefaultEditor(fileName);
String id = descriptor.getId();
If you have correctly installed the noa4e plugins this should give the
adequate id.
HTH,
Gilbert
[1] http://ubion.ion.ag/mainForumFolder
|
|
|
Re: OpenOffice + RCP: impossible? [message #500156 is a reply to message #500015] |
Wed, 25 November 2009 08:42 |
Mauro Condarelli Messages: 428 Registered: September 2009 |
Senior Member |
|
|
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.04295 seconds