Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to embed OleControlSite in a MultiPageEditor?(Layout problems when embedding OleControlSite inside a page of a MultiPageEditor)
How to embed OleControlSite in a MultiPageEditor? [message #800505] Fri, 17 February 2012 06:45 Go to next message
Narendran Shanmugasundaram is currently offline Narendran ShanmugasundaramFriend
Messages: 5
Registered: July 2009
Junior Member
Hello,

I am trying to embed the MS Word OleControlSite in one of the pages of MultiPageEditor. I want to have a tree (which will display bookmarks) on the left and the OleControlSite on the right. I have added two composites - one for the tree and one for the ole control. Here is the code (the argument 'container' is obtained from MultiPageEditorPart.getContainer()) :

public Composite createContents(Composite container) {
		final ScrolledComposite scParent = new ScrolledComposite(container, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
		final Composite parent = new Composite(scParent,SWT.NONE);
		scParent.setContent(parent);
		
		GridLayout layout = new GridLayout();
		layout.numColumns = 10;

		parent.setLayout(layout);
		
		GridData gridData = new GridData();

		final Composite treeParent = new Composite(parent, 0);
		treeParent.setLayout(new GridLayout());
		gridData = new GridData(GridData.FILL_VERTICAL);
		gridData.horizontalSpan = 2;
		treeParent.setLayoutData(gridData);
		

		final Composite wordParent = new Composite(parent, 0);
		wordParent.setLayout(new GridLayout());
		gridData = new GridData(GridData.FILL_BOTH);
		gridData.horizontalSpan = 8;
		wordParent.setLayoutData(gridData);
		

		Shell wordShell = wordParent.getShell();
		wordShell.setLayout(new FillLayout());
		wordShell.setSize(parent.getSize());

		final TreeViewer sectionTreeViewer = new TreeViewer(treeParent);
		gridData = new GridData(GridData.FILL_BOTH);
		final Tree sectionTree = sectionTreeViewer.getTree();
		sectionTree.setLayoutData(gridData);

		OleFrame frame = new OleFrame(wordParent.getShell(), SWT.NONE);

		OleControlSite controlSite =
			new OleControlSite(frame, SWT.NONE, "Word.Document", new File("C:\\test\\test.docx"));

		controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);


		parent.setSize(parent.computeSize(1200, 800));
		parent.addDisposeListener(new DisposeListener(){

			@Override
			public void widgetDisposed(DisposeEvent e) {
				keysFont.dispose();
				whiteColor.dispose();
			}

		});
		return scParent;
	}


But the ole control always gets displayed outside the editor (attached image). I found that this does not happen when I change
wordShell.setLayout(new FillLayout())
to set any other layout. But when I change the layout, the ole control doesnt get displayed.

I am not sure how to fix this problem. Any help would be very welcome.

Thanks,
Naren.
Re: How to embed OleControlSite in a MultiPageEditor? [message #802820 is a reply to message #800505] Mon, 20 February 2012 13:50 Go to previous messageGo to next message
Lakshmi ShanmugamFriend
Messages: 274
Registered: July 2009
Location: India
Senior Member
Hi,

In your code, you are creating the OleFrame as child of the shell instead of child of wordParent. Also, you should set layout data for the frame if required.

Try,
OleFrame frame = new OleFrame(wordParent, SWT.NONE);
Instead of,
OleFrame frame = new OleFrame(wordParent.getShell(), SWT.NONE);


Here is a detailed article on Layouts--> http://www.eclipse.org/articles/article.php?file=Article-Understanding-Layouts/index.html





Lakshmi P Shanmugam
Re: How to embed OleControlSite in a MultiPageEditor? [message #803227 is a reply to message #802820] Tue, 21 February 2012 03:56 Go to previous message
Narendran Shanmugasundaram is currently offline Narendran ShanmugasundaramFriend
Messages: 5
Registered: July 2009
Junior Member
Hello Lakshmi,

Thanks a lot for your response. I was able to get it to work. I dont know why I was trying to embed the Ole Control on the shell instead of the composite. Here is the code that works:

                final Composite treeParent = new Composite(parent, SWT.SHELL_TRIM | SWT.RESIZE | SWT.BORDER);
		treeParent.setLayout(new GridLayout());
		gridData = new GridData(GridData.FILL_VERTICAL);
		gridData.horizontalSpan = 4;
		treeParent.setLayoutData(gridData);
		treeParent.setBackground(bgColor);

		final Composite wordParent = new Composite(parent, SWT.NONE | SWT.RESIZE | SWT.BORDER);
		wordParent.setLayout(new FillLayout());
		gridData = new GridData(GridData.FILL_BOTH);
		gridData.horizontalSpan = 6;
		wordParent.setLayoutData(gridData);
		wordParent.setBackground(bgColor);

                final TreeViewer sectionTreeViewer = new TreeViewer(treeParent);
		gridData = new GridData(GridData.FILL_BOTH);
		gridData.horizontalSpan = 4;
		final Tree sectionTree = sectionTreeViewer.getTree();
		sectionTree.setLayoutData(gridData);
		sectionTree.addMouseMoveListener(new MouseMoveListener() {
			@Override
			public void mouseMove(MouseEvent arg0) {
				sectionTree.setCursor(normalCursor);
			}
		});
		
		sectionTreeViewer.setContentProvider(new DocTreeContentProvider());
		sectionTreeViewer.setLabelProvider(new DocTreeLabelProvider());
		sectionTreeViewer.setInput(doc);
		

		OleFrame frame = new OleFrame(wordParent, SWT.NONE);
		
		OleControlSite controlSite =
			new OleControlSite(frame, SWT.NONE, "Word.Document", new File("C:/test/test.docx"));

		controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
  • Attachment: works.JPG
    (Size: 124.49KB, Downloaded 66 times)
Previous Topic:Google Chrome Frame in SWT Browser
Next Topic:Is it possible to modify how Text swt widget wrap word?
Goto Forum:
  


Current Time: Sun Nov 23 17:33:57 GMT 2014

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

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