Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » OpenOffice + RCP: impossible?(I think I'm at a dead end: can someone confirm?)
OpenOffice + RCP: impossible? [message #499645] Mon, 23 November 2009 10:33 Go to next message
Mauro Condarelli is currently offline Mauro Condarelli
Messages: 417
Registered: September 2009
Senior Member
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 #499673 is a reply to message #499645] Mon, 23 November 2009 11:36 Go to previous messageGo to next message
Antonio is currently offline Antonio
Messages: 39
Registered: July 2009
Member
Hi Mauro do you wont to create a wysiwyg Editor?
your RCP write a file RTF or HTML?
regads
Antonio







"Mauro Condarelli" <mc5686@mclink.it> ha scritto nel messaggio
news:heea0n$5di$1@build.eclipse.org...
> 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 #499677 is a reply to message #499673] Mon, 23 November 2009 11:52 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro Condarelli
Messages: 417
Registered: September 2009
Senior Member
Antonio wrote on Mon, 23 November 2009 11:36
Hi Mauro do you wont to create a wysiwyg Editor?
your RCP write a file RTF or HTML?
regads
Antonio



Currently RTF.
Do You have good (free and portable) alternatives?

TiA
Mauro
Re: OpenOffice + RCP: impossible? [message #499699 is a reply to message #499645] Mon, 23 November 2009 13:36 Go to previous messageGo to next message
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 #499746 is a reply to message #499699] Mon, 23 November 2009 17:07 Go to previous messageGo to next message
Antonio is currently offline Antonio
Messages: 39
Registered: July 2009
Member
Hi Gilbert
tree month ago Markus Krueger write that the plug in NOA4E work whit Swing
libraries,
infact you use this import in the example:
import javax.swing.JPanel;
this is a problem if you want use the RCP in other operative system that
Windows.
Do you have other information?
regads
Antonio


"Gilbert Mirenque" <formatzeh@gmx.de> ha scritto nel messaggio
news:heekmi$6o7$1@build.eclipse.org...
> 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 04:02 Go to previous messageGo to next message
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 #499831 is a reply to message #499645] Tue, 24 November 2009 05:12 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro Condarelli
Messages: 417
Registered: September 2009
Senior Member
Hi Gilbert,
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)?
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 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();
	}
but i don't know how to use the IEditorInput with noa4e!
I currently have something like:
	private static ITextDocument doc = null;
	private static ITextDocument getDoc(Shell shell) {
		if (doc == null) {
			IOfficeApplication app = EditorCorePlugin.getDefault().getManagedLocalOfficeApplication();
			if(!app.isActive()) {
				//Shell shell = Display.getCurrent().getActiveShell();
				IStatus status = NOAUIPlugin.startLocalOfficeApplication(shell, app);
				if (status.getSeverity() != IStatus.ERROR) {
					try {
						doc = (ITextDocument)app.getDocumentService().constructNewDocument(IDocument.WRITER, DocumentDescriptor.DEFAULT_HIDDEN);
						
					} catch (NOAException e) {
						e.printStackTrace();
					} catch (OfficeApplicationException e) {
						e.printStackTrace();
					}
				}
			}
		}
		return doc;
	}
	
	@Override
	public void createPartControl(Composite parent) {
		ITextDocument doc = getDoc(parent.getShell());
		IEditorInput ei = getEditorInput();
		FileStoreEditorInput fsei = (FileStoreEditorInput) ei.getAdapter(FileStoreEditorInput.class);
		URI uri = fsei.getURI();
		String url = uri.toString();
		//now I should open the url in doc
		doc.????(url);
What should I do?

TiA
Mauro
Re: OpenOffice + RCP: impossible? [message #500015 is a reply to message #499831] Tue, 24 November 2009 12:27 Go to previous messageGo to next message
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 03:42 Go to previous message
Mauro Condarelli is currently offline Mauro Condarelli
Messages: 417
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
Previous Topic:Referencing resources from other plugins in plugin.xml
Next Topic:how to place views when opening a perspective?
Goto Forum:
  


Current Time: Fri Aug 22 11:54:06 EDT 2014

Powered by FUDForum. Page generated in 0.14022 seconds