|
|
Re: dynamically add part to partStack [message #988410 is a reply to message #988219] |
Thu, 29 November 2012 19:35 |
Aljoscha Steffens Messages: 302 Registered: November 2012 |
Senior Member |
|
|
I can't get it working. This MPart part = partService.createPart("my_part_id");
returns a null pointer. Do I have to register my parts somewhere?
I also tried this version:
MPart part = MBasicFactory.INSTANCE.createPart();
part.setElementId("mynewid");
part.setLabel("A new Part");
part.setContributorURI("bundleclass://Test/Test.parts.DataViewer");
partStack.getChildren().add(part);
partService.activate(part)
but it just creates an empty part. The constructor of DataViewer isn't even called
[Updated on: Thu, 29 November 2012 19:35] Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: dynamically add part to partStack [message #988659 is a reply to message #988518] |
Fri, 30 November 2012 22:17 |
Eclipse User |
|
|
|
The M* types are model interfaces.
In e4 your application is modelled. What this means is that there is a layer between the runtime (DI and stuff that makes your app run) and what you see (SWT viewer and composites). That layer is called the application model and is that thing you edit through the e4 tools. There are also those things called renderers (provided by the platform but that you can override) which take that model and build your widgets *up to the part level*.
Think of it as in industrial production. First they model stuff in 3D and sketches and fancy drawings and when they are happy with it they put it into production and get the real thing. You model your application with those M classes on a high level and the renderers produce the real thing. If you swap the renderers (SWT -> JavaFX) you have a different thing out of the same model, again *up to the part level*. Mind that the model is not just about visual parts, it is also about handlers, commands, key bindings etc. Also the extension mechanism is built in in the model level (you are still in the "3D" phase) through fragments and processors. Most of visual manipulations are done in this abstract model layer like hiding parts, showing stacks, adding perspectives etc. and the renderers listens in real time and does the changes in the actual widgets.
What you call the Part-Class is not supposed to extend anything (POJO). When I say *up to the part level* I mean that the framework is responsible for widgets up to that gray composite which is linked to an MPart. This Composite (the class) is supplied to you through DI and if you write
@PostConstruct
public void pc(Composite parent){
new YourSWTStuffInsideThePart(parent,SWT.NONE);
}
that parent is all you need. The framework (DI) will bring that to you and you can start from there creating widgets using it as a parent.
|
|
|
|
|
Re: dynamically add part to partStack [message #988852 is a reply to message #988844] |
Mon, 03 December 2012 13:13 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Why does you ModelViewer extend Composite? I can't imagine that any of
our tutorials shows such a structure?
I already answered how you can pass information to your Part-Bean in my
last response to you.
One solution is to store informations on the MPart instance when
creating it.
class MyModelViewer {
@PostConstruct
void init(Composite comp, MPart part) {
part.getPersistedData().get("myspecial data");
}
}
If you happen to have created an MInputPart you could have filled the
inputURI field with data and accessed in a similar way.
class MyModelViewer {
@PostConstruct
void init(Composite comp, MInputPart part) {
part.getInputURI()
}
}
Tom
Am 03.12.12 13:48, schrieb Aljoscha Steffens:
> Thanks a lot Sopot Cela! I'm not yet a 100% clear what you mean but
> about 90% :p It's all new stuff for me and I guess, I'll reach the 100%
> if I see some more Model Interfaces and remember what you said.
>
> But I still have no idea how to handle my problem. So there is this
> parstack which holds parts. When I add a part to this partstack, it
> needs a Class URI. Is this the correct class for the job?public class
> ModelViewer extends Composite {
>
> private ModelObject model;
> @Inject
> //controller is only injected so there is an instance of it somewhere
> public ModelViewer(Composite parent, Controller controller){
> super(parent, SWT.NONE);
> this.setLayout(new FillLayout());
> this.model = new ModelObject("new File");
>
> }
>
> @PostConstruct
> private void createContents(){
> TextViewer viewer = new TextViewer(this, SWT.V_SCROLL |
> SWT.H_SCROLL | SWT.WRAP | SWT.MULTI ) ;
> IDocument document = new Document();
> document.set(model.getContent());
> viewer.setDocument(document);
>
> }
>
> }
>
> Or would I set sth else for the Class URI, which then implements my
> ModelViewer?
> So in this tutorial:
> http://www.vogella.com/articles/Eclipse4Editor/article.html#eclipse4editor
> what would be my Contribution URI and what my Input URI?
|
|
|
Re: dynamically add part to partStack [message #989143 is a reply to message #988852] |
Tue, 04 December 2012 19:28 |
Aljoscha Steffens Messages: 302 Registered: November 2012 |
Senior Member |
|
|
Hmm okay, extending a composite is not usefull. I read it in some other tutorial.
Sorry, but I still don't have any idea what to do. Actually it got worse.
First of all: MPart has not function called getPersistedData() (at least I can't find it).
But even if it did, I wouldn't know what to do since I don't understand the structure. And there literally 2 google entries when I look for 'MPart rcp'. Only thing usefull is this: http://www.vogella.com/articles/Eclipse4Services/article.html#selectedservices_partservice I'm very sorry, but I can't figure it out myself if I have barley any sources I can rely on.
So my idea of parts is, that they are basically views. A part would take something like a textedit (or my ModelViewer) and display it.
1.: So why would my ModelViewer need an instance of MPart or MInputPart?
public class NewModelHandler {
....
public void execute(EModelService modelService, MApplication app, EPartService partService) {
MInputPart part = MBasicFactory.INSTANCE.createInputPart();
part.setContributionURI("bundleclass://Test/Test.parts.ModelViewer");
part.setInputURI("bundleclass://Test/Test.parts.ModelViewer"); (same URIs)
part.setLabel("BLA");
part.setCloseable(true);
stack.getChildren().add(part);
partService.showPart(part, PartState.ACTIVATE);
}
This sounds logic to me. I create a part and set the source of the object that should be displayed. 2.: But what is the difference between the Contribution and the Input URI? 3.: For which would I take ModelViewer and what would I take for the other one? 4.: And when I set the Class URI in the Application model, would I choose the ModelViewer?
[Updated on: Tue, 04 December 2012 19:32] Report message to a moderator
|
|
|
|
|
|
Re: dynamically add part to partStack [message #989332 is a reply to message #989216] |
Wed, 05 December 2012 16:37 |
Aljoscha Steffens Messages: 302 Registered: November 2012 |
Senior Member |
|
|
Using input URI does not work. Or at least I don't know how to use it.
What is wrong with this code?
public class NewModelHandler {
@Execute
public void execute(EModelService modelService, MApplication app, EPartService partService) {
MPartStack stack = (MPartStack) modelService.find("test.partstack.editors", app);
MInputPart part = MBasicFactory.INSTANCE.createInputPart();
part.setInputURI("bundleclass://Test/test.parts.ModelViewer");
part.setCloseable(true);
_________________________________________________________________
// how can i get access to the created instance of ModelViewer?
_________________________________________________________________
part.getObject() returns null
stack.getChildren().add(part);
partService.showPart(part, PartState.ACTIVATE);
}
}
public class ModelViewer{
private ModelObject model;
@Inject
public ModelViewer(Composite parent){
super(parent, SWT.NONE);
this.setLayout(new FillLayout());
this.model = new ModelObject("new File");
}
@PostConstruct
private void createContents(){
TextViewer viewer = new TextViewer(this, SWT.V_SCROLL | SWT.H_SCROLL | SWT.WRAP | SWT.MULTI ) ;
IDocument document = new Document();
document.set(model.getContent());
viewer.setDocument(document);
}
}
[Updated on: Wed, 05 December 2012 16:38] Report message to a moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04958 seconds