|
|
| Re: dynamically add part to partStack [message #988410 is a reply to message #988219] |
Thu, 29 November 2012 14:35   |
Aljoscha Steffens Messages: 295 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 14:35] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
| Re: dynamically add part to partStack [message #988844 is a reply to message #988688] |
Mon, 03 December 2012 07:48   |
Aljoscha Steffens Messages: 295 Registered: November 2012 |
Senior Member |
|
|
Thanks a lot Sopot Cela! I'm not yet a 100% clear what you mean but about 90% 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
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);
}
}
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?
[Updated on: Mon, 03 December 2012 07:50] Report message to a moderator
|
|
|
| Re: dynamically add part to partStack [message #988852 is a reply to message #988844] |
Mon, 03 December 2012 08:13   |
Thomas Schindl Messages: 4462 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 14:28   |
Aljoscha Steffens Messages: 295 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 14:32] Report message to a moderator
|
|
|
|
|
|
| Re: dynamically add part to partStack [message #989332 is a reply to message #989216] |
Wed, 05 December 2012 11:37   |
Aljoscha Steffens Messages: 295 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 11:38] Report message to a moderator
|
|
|
|
|
|
|
| Re: dynamically add part to partStack [message #992313 is a reply to message #989700] |
Fri, 21 December 2012 05:32  |
Aljoscha Steffens Messages: 295 Registered: November 2012 |
Senior Member |
|
|
Sorry for the late respond.
Sopot Cela wrote on Fri, 07 December 2012 05:472.Get access to the part (the ModelViewer) I have just created to modify the class?
like:
part.setContributionURI("bundleclass://Test/test.parts.ModelViewer");
part.setInputURI("fileName.txt");
part.getCreatedInstanceOfModelViewer().setModel(Model);
>>>>>>>>>>
part.getObject() and cast it to your class.
Ah okay. The crucial thing is to call the method after
partService.showPart(part, PartState.ACTIVATE);
otherwise it doesn't work.
Thanks a lot again!
|
|
|
Powered by
FUDForum. Page generated in 0.02778 seconds