Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » classpath problems(A standalone app works, but frame included in RCP Editor don't)
classpath problems [message #499317] Fri, 20 November 2009 18:39 Go to next message
Mauro Condarelli is currently offline Mauro Condarelli
Messages: 418
Registered: September 2009
Senior Member
Hi,
I'm writing an RCP app.
I need a fairly good Text editor, so I'm trying to included OOWriter in a frame and pack that into an EditorPart.

I have a wrapper for OOWriter that is (for now) fairly simple and works as expected using the include main().
package it.condarelli.swt.ooo;

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Panel;

import javax.swing.JPanel;
import javax.swing.JRootPane;

import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.sun.star.comp.beans.NoConnectionException;
import com.sun.star.comp.beans.OOoBean;
import com.sun.star.comp.beans.SystemWindowException;
import com.sun.star.frame.XDesktop;
import com.sun.star.io.IOException;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.util.CloseVetoException;

public class OOoEditor extends Composite {

	public final String SWRITER = "private:factory/swriter";

	private static final long serialVersionUID = -1408623115735065822L;

	private OOoBean aBean;

	public OOoEditor(Composite parent, int style) {
		super(parent, style | SWT.NO_BACKGROUND | SWT.EMBEDDED);

		try {
			System.setProperty("sun.awt.noerasebackground", "true");
		} catch (NoSuchMethodError error) {
		}

		/* Create and setting up frame */
		Frame frame = SWT_AWT.new_Frame(this);
		Panel panel = new Panel(new BorderLayout()) {
			private static final long serialVersionUID = -5464002272885975878L;

			public void update(java.awt.Graphics g) {
				paint(g);
			}
		};
		frame.add(panel);
		JRootPane root = new JRootPane();
		panel.add(root);
		java.awt.Container contentPane = root.getContentPane();

		JPanel p = new JPanel();
		aBean = new OOoBean();
		p.setLayout(new java.awt.BorderLayout());
		p.add(aBean, java.awt.BorderLayout.CENTER);
		contentPane.add(p);
	}

	public void setDocument(String url) throws IllegalArgumentException,
			CloseVetoException, NoConnectionException, IOException,
			SystemWindowException {
		try {
			aBean.loadFromURL(url, null);
//			try {
//				XPropertySet ps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aBean.getFrame());
//				try {
//					XLayoutManager lm = (XLayoutManager) UnoRuntime.queryInterface(XLayoutManager.class, ps.getPropertyValue("LayoutManager"));
////					lm.hideElement("private:resource/menubar/menubar");
//					lm.showElement("private:resource/menubar/menubar");
//				} catch (UnknownPropertyException e) {
//					e.printStackTrace();
//				} catch (WrappedTargetException e) {
//					e.printStackTrace();
//				}
//			} catch (NoConnectionException e) {
//				e.printStackTrace();
//			}

		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (java.io.IOException e) {
			e.printStackTrace();
		}
		aBean.aquireSystemWindow();
	}

	/**
	 * closes the bean viewer and tries to terminate OOo.
	 */
	public void terminate() throws NoConnectionException {
		setVisible(false);
		XDesktop xDesktop = null;
		xDesktop = aBean.getOOoDesktop();
		aBean.stopOOoConnection();
		if (xDesktop != null)
			xDesktop.terminate();
	}

	/**
	 * closes the bean viewer, leaves OOo running.
	 */
	public void close() {
		setVisible(false);
		aBean.stopOOoConnection();
	}

	private static final String OFFICE_DOCUMENT = "file:///C:/Users/mauro/Downloads/TeX/Libro/yWriter/RTF5/RTF_00007.rtf";

	private static final String NEW_WRITER_DOCUMENT = "private:factory/swriter";

	public static void main(String[] args) {
		boolean empty = false;

		final Display display = new Display();
		final Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());
		shell.setSize(900, 800);
		final OOoEditor viewer = new OOoEditor(shell, SWT.NONE);

		try {
			if (empty) {
				viewer.setDocument(NEW_WRITER_DOCUMENT);
			} else {
				viewer.setDocument(OFFICE_DOCUMENT);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		shell.open();
		shell.addDisposeListener(new DisposeListener() {

			public void widgetDisposed(DisposeEvent e) {
				try {
					viewer.close();
				} catch (RuntimeException exception) {
					exception.printStackTrace();
				}
			}

		});
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}

}


Unfortunately when I try to use it in an EditorPart I get a runtime error.

I'm trying to use like this:
	@Override
	public void createPartControl(Composite parent) {
		GridData gridData = new GridData();
		gridData.horizontalAlignment = GridData.FILL;
		gridData.grabExcessHorizontalSpace = true;
		gridData.grabExcessVerticalSpace = true;
		gridData.verticalAlignment = GridData.FILL;
		top = new Composite(parent, SWT.NONE);
		top.setLayout(new GridLayout());
		oooE = new OOoEditor(top, SWT.NONE);
		oooE.setLayoutData(gridData);
	}

but it bombs out at the oooE = new OOoEditor(top, SWT.NONE); line with error:
/Users/mauro/Downloads/TeX/Libro/yWriter/RTF5/RTF_00004.rtf
!SESSION 2009-11-20 19:15:49.510 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_17
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=it_IT
Framework arguments:  -product it.condarelli.rcp.yw.product
Command-line arguments:  -product it.condarelli.rcp.yw.product -data C:\Users\mauro\workspace/../runtime-it.condarelli.rcp.yw.product -dev file:C:/Users/mauro/workspace/.metadata/.plugins/org.eclipse.pde.core/it.condarelli.rcp.yw.product/dev.properties -os win32 -ws win32 -arch x86 -consoleLog

!ENTRY org.eclipse.ui 4 0 2009-11-20 19:15:57.937
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NoClassDefFoundError: com/sun/star/comp/beans/OOoBean
	at it.condarelli.rcp.yw.RTFEditor.createPartControl(RTFEditor.java:65)
	at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:662)
	at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:462)
	at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
	at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:313)
	at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:180)
	at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:270)
	at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
	at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:473)
	at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1256)
	at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1209)
	at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1608)
	at org.eclipse.ui.internal.PartStack.add(PartStack.java:499)
	at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:103)
	at org.eclipse.ui.internal.PartStack.add(PartStack.java:485)
	at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:112)
	at org.eclipse.ui.internal.EditorSashContainer.addEditor(EditorSashContainer.java:63)
	at org.eclipse.ui.internal.EditorAreaHelper.addToLayout(EditorAreaHelper.java:225)
	at org.eclipse.ui.internal.EditorAreaHelper.addEditor(EditorAreaHelper.java:213)
	at org.eclipse.ui.internal.EditorManager.createEditorTab(EditorManager.java:778)
	at org.eclipse.ui.internal.EditorManager.openEditorFromDescriptor(EditorManager.java:677)
	at org.eclipse.ui.internal.EditorManager.openEditor(EditorManager.java:638)
	at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.java:2854)
	at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2762)
	at org.eclipse.ui.internal.WorkbenchPage.access$11(WorkbenchPage.java:2754)
	at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:2705)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2701)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2685)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2668)
	at it.condarelli.rcp.yw.Scene$1.widgetSelected(Scene.java:114)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3880)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3473)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at it.condarelli.rcp.yw.Application.start(Application.java:20)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
Caused by: java.lang.ClassNotFoundException: com.sun.star.comp.beans.OOoBean
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:494)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:398)
	at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
	... 57 more

Apparently it is unable to find the
import com.sun.star.comp.beans.OOoBean;
in OOoEditor.java that is obviousli found ok when running the frame standalone.
I tried several configurations, including copying all required libs into the workspace.

I think it's obvious I do not understand how to set-up Referenced Libraries for RCP.

I have no problem uploading the whole project, if that's useful.

Can someone help me?
TiA
Mauro
Re: classpath problems [message #499318 is a reply to message #499317] Fri, 20 November 2009 18:50 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

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).

There should be more info in http://wiki.eclipse.org/PDE on how to include 3rd party jars in a plugin.

PW


Re: classpath problems [message #499351 is a reply to message #499318] Sat, 21 November 2009 05:26 Go to previous messageGo to next message
Lars Vogel is currently offline Lars Vogel
Messages: 1049
Registered: July 2009
Senior Member

Hi,

this explains how to convert jars into plugins:
http://www.vogella.de/articles/EclipseJarToPlugin/article.ht ml

Hope this helps, Lars

--
http://www.vogella.de/ - Eclipse plugin and Eclipse RCP Tutorials
http://www.twitter.com/vogella - vogella on Twitter


Paul Webster wrote:
> 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).
>
> There should be more info in http://wiki.eclipse.org/PDE on how to
> include 3rd party jars in a plugin.
>
> PW
>
Re: classpath problems [message #499368 is a reply to message #499317] Sat, 21 November 2009 14:20 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro Condarelli
Messages: 418
Registered: September 2009
Senior Member
Many thanks.
Now I'm almost there.
Problem is OOo interaction needs some native libs (.dll under win and .so under linux) How can (should) I include them in the plugin?
Lars's tutorial covers only the pure java part.
I saw no obvious extensions.

TiA
Mauro
Re: classpath problems [message #499606 is a reply to message #499368] Mon, 23 November 2009 14:31 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

If you include the DLLs (or .so for different platforms) in your bundle, then use Bundle-NativeCode to describe how to find them.

ex:
http://litrik.blogspot.com/2007/08/secrets-of-bundle-nativec ode.html

PW


Previous Topic:How to detect drop target window (view?) when drag and drop common navigator item between windows?
Next Topic:Load a class of a fragment dynamically from a String
Goto Forum:
  


Current Time: Tue Sep 30 16:02:44 GMT 2014

Powered by FUDForum. Page generated in 0.05816 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software