Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Re: dynamically add part to partStack
Re: dynamically add part to partStack [message #988190] Wed, 28 November 2012 13:24 Go to next message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

Aljoscha Steffens wrote on Wed, 28 November 2012 19:22
> Hi,
> how can I achieve sth like the eclipse GUI? If the user loads a file, it will be placed in an editor/partstack as a tab.
> I just found how to create a new part and add it to the window.
> www. vogella.com/articles/EclipseRCP/article.html#modeldynamics_example2



Take a look at https://github.com/semanticsoft/vaaclipse/blob/master/org.semanticsoft.vaaclipse.demo.contacts/src/org/semanticsoft/vaaclipse/demo/handlers/NewContactHandler.java

This adds a part to a part stack after finding it with an ID. It's used for the vaadin renderer but the model API is widget agnostic.
Re: dynamically add part to partStack [message #988219 is a reply to message #988190] Wed, 28 November 2012 16:50 Go to previous messageGo to next message
Aljoscha Steffens is currently offline Aljoscha Steffens
Messages: 302
Registered: November 2012
Senior Member
wtf happend here? can someone delete all this messages? Don't know what's gone wrong... Thank you, i'll have a look at it tomorrow
Re: dynamically add part to partStack [message #988410 is a reply to message #988219] Thu, 29 November 2012 14:35 Go to previous messageGo to next message
Aljoscha Steffens is currently offline 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 14:35]

Report message to a moderator

Re: dynamically add part to partStack [message #988413 is a reply to message #988410] Thu, 29 November 2012 14:52 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5294
Registered: July 2009
Senior Member
Am 29.11.12 20:35, schrieb Aljoscha Steffens:
> I can't get it working. This Quote:
>> MPart part = partService.createPart("my_part_id");
>
> returns a null pointer. Do I have to register my parts somewhere?
>

Yes you need to register a MPartDescriptor before!

> 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");
^^^^^^^^^^^^^^^^^^^^^^^
=> This is the wrong attribute you need to use setContributionURI!!!

> partStack.getChildren().add(part);
> partService.activate(part)
> but it just creates an empty part. The constructor of DataViewer isn't
> even called
Re: dynamically add part to partStack [message #988415 is a reply to message #988413] Thu, 29 November 2012 15:06 Go to previous messageGo to next message
Aljoscha Steffens is currently offline Aljoscha Steffens
Messages: 302
Registered: November 2012
Senior Member
Thanks! works fine now. I got the code from this tutorial http://www.vogella.com/articles/EclipseRCP/article.html#modeldynamics_example2 and it says "part.setContributorURI".
Re: dynamically add part to partStack [message #988417 is a reply to message #988415] Thu, 29 November 2012 15:11 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5294
Registered: July 2009
Senior Member
Then Lars is wrong ;-)

The contributorURI should be set to the plugin which makes the
contribution. Currently we use this uri when doing translations look ups
but we could also detect uninstalls with it at runtime and remove
elements from the UI.

Tom

Am 29.11.12 21:06, schrieb Aljoscha Steffens:
> Thanks! works fine now. I got the code from this tutorial
> http://www.vogella.com/articles/EclipseRCP/article.html#modeldynamics_example2
> and it says "part.setContributorURI".
>
Re: dynamically add part to partStack [message #988447 is a reply to message #988417] Thu, 29 November 2012 17:04 Go to previous messageGo to next message
Aljoscha Steffens is currently offline Aljoscha Steffens
Messages: 302
Registered: November 2012
Senior Member
Thanks.
I read a lot of articles from you and Lars, but didn't expect you to be (one of) the developers of the eclipse platform. Nice to talk to an insider Razz

Some more questions:
what is the basic difference between
 MPart part = partService.createPart("new.contact.part");

and
 MPart part = MBasicFactory.INSTANCE.createPart();
part.setContributionURI("bundleclass://Test/Test.parts.ModelViewer");


and I would like to access the class my part is relying on. How can I get it? Or is my approach wrong? I want to display a file in each part. The contributer class is an extension of Composite.

For any reason I barely find any information relating MPart with google so sorry for the stupid questions (btw: why is there no class description of MPart on the Eclipse site?).

Aljo
Re: dynamically add part to partStack [message #988458 is a reply to message #988447] Thu, 29 November 2012 19:16 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5294
Registered: July 2009
Senior Member
MPartDescriptor is a blueprint for you can create MPart instances from
later on. Having descriptors make sense if you e.g. would like to
present a list of available Parts/Views in a menu similar to Window >
Show View.

To your question. Do you ask to get the instance of ModelViewer the
framework created? The created object is available through
MContribution#getObject() but this one is only created when the MPart is
shown which is lazy e.g. if it is part of a MPartStack.

If I get you right what you want is to pass on informations to your part
when it is created. You have multiple possibilities:
a) Use an MInputPart and before adding it to a container set the inputURI
b) put your value into MContext#properties the key is the one used by
the DI container
c) put it into MApplicationElement#transientData or persistedData

Tom

Am 29.11.12 23:04, schrieb Aljoscha Steffens:
> Thanks.
> I read a lot of articles from you and Lars, but didn't expect you to be
> (one of) the developers of the eclipse platform. Nice to talk to an
> insider :p
>
> Some more questions:
> what is the basic difference between MPart part =
> partService.createPart("new.contact.part");
> and MPart part = MBasicFactory.INSTANCE.createPart();
> part.setContributionURI("bundleclass://Test/Test.parts.ModelViewer");
>
> and I would like to access the class my part is relying on. How can I
> get it? Or is my approach wrong? I want to display a file in each part.
> The contributer class is an extension of Composite.
>
> For any reason I barely find any information relating MPart with google
> so sorry for the stupid questions (btw: why is there no class
> description of MPart on the Eclipse site?).
>
> Aljo
Re: dynamically add part to partStack [message #988518 is a reply to message #988458] Fri, 30 November 2012 05:42 Go to previous messageGo to next message
Aljoscha Steffens is currently offline Aljoscha Steffens
Messages: 302
Registered: November 2012
Senior Member
What is the general idea behind 'M-Classes'? Like 'I-Classes' represent interfaces.

And for the MInputPart I could just find one source http://www.vogella.com/articles/Eclipse4Editor/article.html#eclipse4editor but in this tutorial it's not mentinoned how the different classes Part1 and MyInout look like.
For example: I have this ModelViewer class which extends a Composite and displays a TextViewer Object. Is this correct for an input object? How should the Part-Class look like? Does it need to be extended from some other class? Does it need to provide some functions?
As I said, right now I use this ModelViewer as the Contribution for the parts.
Re: dynamically add part to partStack [message #988659 is a reply to message #988518] Fri, 30 November 2012 17:17 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

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 #988688 is a reply to message #988415] Sat, 01 December 2012 05:41 Go to previous messageGo to next message
Lars Vogel is currently offline Lars Vogel
Messages: 1049
Registered: July 2009
Senior Member

Thanks for noting my typo, http://www.vogella.com/articles/EclipseRCP/article.html#modeldynamics_example2 has been updated.
Re: dynamically add part to partStack [message #988844 is a reply to message #988688] Mon, 03 December 2012 07:48 Go to previous messageGo to next message
Aljoscha Steffens is currently offline Aljoscha Steffens
Messages: 302
Registered: November 2012
Senior Member
Thanks a lot Sopot Cela! I'm not yet a 100% clear what you mean but about 90% Razz 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 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5294
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 Go to previous messageGo to next message
Aljoscha Steffens is currently offline 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 14:32]

Report message to a moderator

Re: dynamically add part to partStack [message #989145 is a reply to message #989143] Tue, 04 December 2012 14:46 Go to previous messageGo to next message
Lars Vogel is currently offline Lars Vogel
Messages: 1049
Registered: July 2009
Senior Member

I didn't follow the complete discussion but MPart has the getPersistedData() method. See http://www.vogella.com/articles/EclipseRCP/article.html#model_supplementary for an example with persisted data for a model addon. This works similar in a Part only that you also of the @PersistState annotation.
Re: dynamically add part to partStack [message #989168 is a reply to message #989143] Tue, 04 December 2012 18:34 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5294
Registered: July 2009
Senior Member
The contributorURI is the URI to the bundle that contributed the model
element this is e.g. used when doing translations. For your purpose it
is needless and I'm 99.9% sure that an MPart instance has
getPersistedData().

The value in the inputURI should point to the file you want to show!

Tom


Am 04.12.12 20:28, schrieb Aljoscha Steffens:
> 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. It 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?
>
> 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?
>
Re: dynamically add part to partStack [message #989216 is a reply to message #989168] Wed, 05 December 2012 04:18 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

it's getPersistedState()
Re: dynamically add part to partStack [message #989332 is a reply to message #989216] Wed, 05 December 2012 11:37 Go to previous messageGo to next message
Aljoscha Steffens is currently offline 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 11:38]

Report message to a moderator

Re: dynamically add part to partStack [message #989387 is a reply to message #989332] Wed, 05 December 2012 20:07 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5294
Registered: July 2009
Senior Member
I think you didn't get the concept of how to create a part at all.

First of all a MPart always has to have an contributionURI which points
to a Java-Class (e.g. your ModelViewer) the framework can create an
instance of.

Now if i got your request right you model viewer has to know which
model-file it should show. This information is passed best through inputURI.

MInputPart part = MBasicFactory.INSTANCE.createInputPart();
part.setContributionURI("bundleclass://Test/test.parts.ModelViewer");
part.setInputURI("file://C:/bla.model");

public class ModelViewer {
private ModelObject model;

@Inject
public ModelViewer(MInputPart part){
this.model = new ModelObject(part.getInputURI());
}

@PostConstruct
private void createContents(Composite parent){
TextViewer viewer = new TextViewer(parent, SWT.V_SCROLL |
SWT.H_SCROLL
| SWT.WRAP | SWT.MULTI ) ;
IDocument document = new Document();
document.set(model.getContent());
viewer.setDocument(document);
}
}


Am 05.12.12 17:37, schrieb Aljoscha Steffens:
> 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);
> //[b] 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);
>
> }
>
> }
>
>
Re: dynamically add part to partStack [message #989692 is a reply to message #989387] Fri, 07 December 2012 05:31 Go to previous messageGo to next message
Aljoscha Steffens is currently offline Aljoscha Steffens
Messages: 302
Registered: November 2012
Senior Member
Thomas Schindl wrote on Wed, 05 December 2012 20:07
I think you didn't get the concept of how to create a part at all.

Thats correct Razz

Thanks alot so far, I did finally get it working.
But of course there are still questions remaining Smile

As the InputURI, I can set a fileName(String)or I can set any ClassURI. But is also one of those two things also possible?:
1.Set an instance of an object as input? (So not class ModelObject but an instance of ModelObject which I created previously)
like:

part.setContributionURI("bundleclass://Test/test.parts.ModelViewer");
Model model = new Model();
part.setInput(model);


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

[Updated on: Fri, 07 December 2012 05:32]

Report message to a moderator

Re: dynamically add part to partStack [message #989700 is a reply to message #989692] Fri, 07 December 2012 05:47 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

2.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.
Re: dynamically add part to partStack [message #989720 is a reply to message #989692] Fri, 07 December 2012 07:25 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5294
Registered: July 2009
Senior Member
Through an URI you can only pass a String which you can use to e.g.
create an instance of the Java-Object through Reflection.

Say you have 2 bundles:
* my.viewer: holds your UI-Viewer which displays your model instance
Class: my.viewer.Viewer

* my.bundle: holds the Java-Class you want to create an instance and
show
Class: my.bundle.mymodel.MyClass

You would create a part like this:

part.setContributionURI("bundleclass://my.viewer/my.viewer.Viewer");
part.setInputURI("bundleclass://my.bundle/my.bundle.mymodel.MyClass");

class Viewer {

@PostConstruct
void initUI(MInputPart part, Composite parent) {
String uri = part.getInputURI();
String bundleId = // ... extract from URI
String classname = // ... extract from URI
Bundle b = // ... find bundle with bundleId
Class<?> cl = b.loadClass(classname);
Object o = cl.newInstance();

// .. your UI creation
}
}
---------------------------------

That's it!

So now because you used the same URL concept the e4 container uses to
create instances you can reuse our stuff to create an instance.

class Viewer {

@PostConstruct
void initUI(MInputPart part, Composite parent,
IEclipseContext context, IContributionFactory f) {
Object o = f.create(part.getInputURI());
// .. your UI creation
}

}

Please note through both concepts you can only create instance of
classes available in your runtime and not of e.g. classes in your
IDE-Project but that should be quite obvious I hope.

Tom

Am 07.12.12 11:31, schrieb Aljoscha Steffens:
> Thomas Schindl wrote on Wed, 05 December 2012 20:07
>> I think you didn't get the concept of how to create a part at all.
>
> Thats correct :p
>
> Thanks alot so far, I did finally get it working.
> But of course there are still questions remaining :)
>
> As the InputURI, I set now a fileName(String). Or I can set any
> ClassURI. But is one of those two things also possible?:
> 1.Set an instance of an object as input? (So not class ModelObject but
> an instance of ModelObject which I created previously)
> like:
>
> part.setContributionURI("bundleclass://Test/test.parts.ModelViewer");
> Model model = new Model();
> part.setInput(model);
>
>
> 2.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);
>
Re: dynamically add part to partStack [message #992313 is a reply to message #989700] Fri, 21 December 2012 05:32 Go to previous message
Aljoscha Steffens is currently offline Aljoscha Steffens
Messages: 302
Registered: November 2012
Senior Member
Sorry for the late respond.

Sopot Cela wrote on Fri, 07 December 2012 05:47
2.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!
Previous Topic:Add some margin to a PartSash ?
Next Topic:Eclipse contexts & Gemini blueprint
Goto Forum:
  


Current Time: Thu Aug 28 19:23:24 EDT 2014

Powered by FUDForum. Page generated in 0.09819 seconds