Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Embed an editor into a view???
Embed an editor into a view??? [message #285861] Thu, 26 May 2005 21:59 Go to next message
W W is currently offline W WFriend
Messages: 45
Registered: July 2009
Member
Currently I'm using Eclipse 3.1M6. I have a need to create a view that
has an editor embedded into the view. The view has to have other SWT
controls around the editor. Unfortunately its unacceptable to create an
editor with several views around it. I have to match the current look and
feel of another application which has a textbox list, buttons, text
fields, and an editor all in one window.

public class EmbeddedEditorView extends ViewPart {

public void createPartControl(Composite parent) {}
public void setFocus()

In the createPartControl() method I am trying to use an experimental class
called IWorkbenchPartFactory to accomplish this.

IWorkbenchPartFactory workbenchPartFactory = new
WorkbenchPartFactory(getSite().getPage());

Unfortunately the getSite() returns null so I can't get the page to
construct the WorkBenchPartFactory :(

And if I could figure out how to instantiate the IWorkbenchPartFactory,
then use the following method:

Part
org.eclipse.ui.internal.part.components.services.IWorkbenchP artFactory.createEditor(String
editorId, Composite parentComposite, IEditorInput input, IMemento
savedState, ServiceFactory context) throws ComponentException

I can get an editorId from my editor. The parent composite is passed in.
And I can get the editor input. I haven't used IMemento or ServiceFactory
before.

Not sure where to proceed after I do get this part back.

1) Is this the correct class to use to accomplish this?
2) If not what would be another way?
3) If so what am I doing wrong?
4) And I have no idea why the getSite() returns null or if I can get a
page another way.

Any help would be greatly appreciated. Anyone with examples?

I came across this class from the following link:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=46207

I couldn't find any other info on it using google or searching eclipse.org
:(
Re: Embed an editor into a view??? [message #285874 is a reply to message #285861] Fri, 27 May 2005 08:09 Go to previous messageGo to next message
Tom Hofmann is currently offline Tom HofmannFriend
Messages: 770
Registered: July 2009
Senior Member
You could try to embed a SourceViewer instead of the entire editor - for
example, see what EditTemplateDialog does in the
org.eclipse.ui.workbench.texteditor plug-in.

Note that embedding editors (and any other parts) is part of the
components proposal:

http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-ui-home/components-proposal/ComponentFrameworkProposal. html

-tom

Daniel W King wrote:
> Currently I'm using Eclipse 3.1M6. I have a need to create a view that
> has an editor embedded into the view. The view has to have other SWT
> controls around the editor. Unfortunately its unacceptable to create an
> editor with several views around it. I have to match the current look
> and feel of another application which has a textbox list, buttons, text
> fields, and an editor all in one window.
>
> public class EmbeddedEditorView extends ViewPart {
>
> public void createPartControl(Composite parent) {}
> public void setFocus()
>
> In the createPartControl() method I am trying to use an experimental
> class called IWorkbenchPartFactory to accomplish this.
>
> IWorkbenchPartFactory workbenchPartFactory = new
> WorkbenchPartFactory(getSite().getPage());
>
> Unfortunately the getSite() returns null so I can't get the page to
> construct the WorkBenchPartFactory :(
>
> And if I could figure out how to instantiate the IWorkbenchPartFactory,
> then use the following method:
>
> Part
> org.eclipse.ui.internal.part.components.services.IWorkbenchP artFactory.createEditor(String
> editorId, Composite parentComposite, IEditorInput input, IMemento
> savedState, ServiceFactory context) throws ComponentException
>
> I can get an editorId from my editor. The parent composite is passed
> in. And I can get the editor input. I haven't used IMemento or
> ServiceFactory before.
> Not sure where to proceed after I do get this part back.
>
> 1) Is this the correct class to use to accomplish this?
> 2) If not what would be another way?
> 3) If so what am I doing wrong?
> 4) And I have no idea why the getSite() returns null or if I can get a
> page another way.
>
> Any help would be greatly appreciated. Anyone with examples?
> I came across this class from the following link:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=46207
>
> I couldn't find any other info on it using google or searching
> eclipse.org :(
>
>
Re: Embed an editor into a view??? [message #285894 is a reply to message #285874] Fri, 27 May 2005 15:50 Go to previous messageGo to next message
W W is currently offline W WFriend
Messages: 45
Registered: July 2009
Member
Tom,

Thanks for the quick reply. I had read the draft proposal for 3.1 and
saw that there was a proposal for embedding editors and views. And since
I'm using 3.1M6, I would imagine this is actually implemented. Am I wrong
in this assumption? Is there documentation somewhere about which
proposals have been implemented and which ones have not?

The IWorkbenchPartFactory class looks like what would be implemented by
this proposal and note that the class is marked as @since 3.1.

I looked at the EditTemplateDialog and don't think that would be a
feasible way to go. I'm not working on the editor piece of this and the
editor is based upon a gef editor to create a basic word processor with
bold, italics, underline. So basically I just have the ability to make
calls and create the editor.
Re: Embed an editor into a view??? [message #285923 is a reply to message #285894] Fri, 27 May 2005 19:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bob.objfac.com

The "Embedding editors and views" sub-project is marked as "recently
deferred" in the 3.1 project plan.

http://www.eclipse.org/eclipse/development/eclipse_project_p lan_3_1.html

Bob Foster

Daniel W King wrote:
> Tom,
>
> Thanks for the quick reply. I had read the draft proposal for 3.1 and
> saw that there was a proposal for embedding editors and views. And
> since I'm using 3.1M6, I would imagine this is actually implemented. Am
> I wrong in this assumption? Is there documentation somewhere about
> which proposals have been implemented and which ones have not?
>
> The IWorkbenchPartFactory class looks like what would be implemented by
> this proposal and note that the class is marked as @since 3.1.
>
> I looked at the EditTemplateDialog and don't think that would be a
> feasible way to go. I'm not working on the editor piece of this and the
> editor is based upon a gef editor to create a basic word processor with
> bold, italics, underline. So basically I just have the ability to make
> calls and create the editor.
>
Re: Embed an editor into a view??? [message #285925 is a reply to message #285923] Fri, 27 May 2005 20:04 Go to previous messageGo to next message
W W is currently offline W WFriend
Messages: 45
Registered: July 2009
Member
Bob,

Thanks. I was wondering where you found out what was going to be
released etc. Even though this is deferred, it looks like the classes
have been made internal. So I would still like to use them and take the
risk of them definitely being broken in 3.2. The project I am working on
is for demo purposes only to prove that the eclipse platform especially
RCP is the way to go.

I solved my null pointer issue but I'm unsure as to why it worked the way
it did. I had declared my view in the plugin.xml as a extension point for
views and then added it to the perspective extension point and defined the
relationship as stacked to another view. This gave me the null pointer
when I tried to do getSite().getPage(); in the view's createPartControl()
method because the site was null or using
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
would give me a "Workbench has not been created yet".

I removed it from the perspective extension point and programmatically
added it to the createInitialLayout() using layout.addView().

At what point is the workbench completed? I would've thought adding it
programmatically or in the perspective extension point would've had the
same effect but apparently not.
Re: Embed an editor into a view??? [message #285937 is a reply to message #285925] Fri, 27 May 2005 21:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bob.objfac.com

Well, that's where you find out the current best guess at what's going
to be released. ;-} Note the item marked "previously committed; recently
deferred". All projects have items that fall off the wagon as it rounds
the final turn. The most reliable indication something will actually be
in is the notation "Work completed."

As I suppose you know, the "good" way to use internal classes is to make
a copy that is as isolated as possible from other internal dependencies.
Then you may survive the first 3.2 milestones long enough to upgrade
gracefully.

BTW, your project won't be proving that "RCP is the way to go". At best
it will show that some future version of RCP might be the way to go. ;-}
But I and many others would like to hear about your results when you try
to apply these futures to an RCP project today.

Bob

Daniel W King wrote:
> Bob,
>
> Thanks. I was wondering where you found out what was going to be
> released etc. Even though this is deferred, it looks like the classes
> have been made internal. So I would still like to use them and take the
> risk of them definitely being broken in 3.2. The project I am working
> on is for demo purposes only to prove that the eclipse platform
> especially RCP is the way to go.
>
> I solved my null pointer issue but I'm unsure as to why it worked the
> way it did. I had declared my view in the plugin.xml as a extension
> point for views and then added it to the perspective extension point and
> defined the relationship as stacked to another view. This gave me the
> null pointer when I tried to do getSite().getPage(); in the view's
> createPartControl() method because the site was null or using
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> would give me a "Workbench has not been created yet".
>
> I removed it from the perspective extension point and programmatically
> added it to the createInitialLayout() using layout.addView().
>
> At what point is the workbench completed? I would've thought adding it
> programmatically or in the perspective extension point would've had the
> same effect but apparently not.
>
>
Re: Embed an editor into a view??? [message #286036 is a reply to message #285937] Wed, 01 June 2005 00:36 Go to previous messageGo to next message
W W is currently offline W WFriend
Messages: 45
Registered: July 2009
Member
Bob,

Thanks for the reply. Given all you've said, I'm still wondering if
anyone has used 3.1 to embed an editor into a view using the
WorkbenchPartFactory class. And if they did if they would post an example
or some detail.

Anyone? Bueller? :P
Re: Embed an editor into a view??? - SOLVED!!! :) [message #286412 is a reply to message #286036] Wed, 08 June 2005 20:32 Go to previous message
W W is currently offline W WFriend
Messages: 45
Registered: July 2009
Member
Finally! I was able to accomplish embedding an editor into a view.

I would like to thank Stephan Xenos for indirectly helping me by providing
an example with this bug.

Here is the link and look at the last example zip since its the latest
version.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=46207

You'll notice that the packages aren't the same as what's in the example
and what's in 3.1 but my code below will work in 3.1.

My goal was to embed an editor in the middle of a view and put buttons,
text, etc around the editor because it all had to be contained within one
view.

Now for the code: (NOTE: The classes used are experimental and internal
in 3.1)


import org.eclipse.emf.common.ui.URIEditorInput;
import org.eclipse.emf.common.util.URI;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.internal.components.framework.FactoryMap;
import org.eclipse.ui.internal.part.Part;
import
org.eclipse.ui.internal.part.components.services.IWorkbenchP artFactory;
import org.eclipse.ui.internal.part.services.WorkbenchPartFactory;
import org.eclipse.ui.part.ViewPart;

public class EmbeddedEditorView extends ViewPart {


private Composite top;
private Control editorComposite;
private Composite composite1;

public void createPartControl(Composite parent) {

top = new Composite(parent, SWT.BORDER);
GridLayout gridLayout = new GridLayout(1, true);
top.setLayout(gridLayout);
createComposite();
createComposite1();
createComposite2();
}

public void setFocus() {

}

public void createComposite() {
// ... put buttons, text, etc
}

public void createComposite1() {

composite1 = new Composite(top, SWT.NONE);
GridLayout gridLayout = new GridLayout(1, true);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.minimumHeight = 400;
composite1.setLayoutData(gridData);
composite1.setLayout(gridLayout);

String filename =
" file:/C:/Documents%20and%20Settings/DKing/Desktop/sample.txt ";

IWorkbenchPartFactory workbenchPartFactory = new
WorkbenchPartFactory(getSite().getPage());
try {
URI fileURI = URI.createURI(filename);
URIEditorInput editorInput = new URIEditorInput(fileURI);

// MyEditor isn't the real name of my editor just an example.
// MyEditor.ID is defined as a String in MyEditor class and matches the
id of the editor extension in the plugin.xml
Part editorPart = workbenchPartFactory.createEditor(MyEditor.ID,
composite1, editorInput, null, new FactoryMap());
setEditorComposite(editorPart.getControl());
}
catch (Throwable t) {
t.printStackTrace();
}
}

private void setEditorComposite(Control newComposite) {

editorComposite = newComposite;
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
editorComposite.setLayoutData(data);
composite1.layout(true);
}


public void createComposite2() {
// ... put buttons, text, etc
}
}


I hope this helps anyone else who has wanted to embed an editor in a view,
embed views within a view, or embed a view within an editor. I would also
like to thank Bob and Tom for replying and trying to help. And if you
solve your questions then please post your solutions for the rest of us! :)
Previous Topic:Use update manager for update bug fixes only
Next Topic:What is an "Invalid Stack Frame" error?
Goto Forum:
  


Current Time: Thu Sep 26 12:14:49 GMT 2024

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

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

Back to the top