Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » MCompositePart creation with EPartService.createPart()?
MCompositePart creation with EPartService.createPart()? [message #1759076] Wed, 05 April 2017 22:53 Go to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
Hmmm ... I don't see help to create an MCompositePart with EPartService, using a partDescriptor.

Looks like modelService.cloneElement might be used to create a deep copy of an existing MCompositePart nested description in the model. Is that the solution?


Re: MCompositePart creation with EPartService.createPart()? [message #1759089 is a reply to message #1759076] Thu, 06 April 2017 07:56 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
You could also put the MCompositePart in the snippets of then application and then use modelService.cloneSnippet to create a deep copy.
Re: MCompositePart creation with EPartService.createPart()? [message #1759141 is a reply to message #1759089] Thu, 06 April 2017 20:43 Go to previous messageGo to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
thanks. that worked. Below was the code to deep clone my MCompositePart from the root level snippets and place it into a partStack elsewhere in the layout. One thing I noted is that there are several levels in the model to put your snippets, but this cloneSnippet call only looks at the single level you specify in the first parameter.

MPartStack partStack = (MPartStack) modelService.find("com.xxx.partstack.xxxlStack", application);

MCompositePart element = (MCompositePart) modelService.cloneSnippet(application, "com.xxx.compositepart.xxx", null);

partStack.getChildren().add(element);
partService.showPart(element, PartState.VISIBLE);

Re: MCompositePart creation with EPartService.createPart()? [message #1759888 is a reply to message #1759141] Wed, 19 April 2017 06:53 Go to previous messageGo to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
I experimented some more with the snippet cloning.

A single call to the snippet cloning handler below was able to replicate a copy of the whole window.main model, placed under the Snippets ... menus, parts, perspectives, sash and stack containers ... everything. Pretty amazing capability.

I couldn't find a document of what to give as the element ID for the node shown as 'Windows and Dialogs' in the editor, so I passed in a the window.main id as a sibling command parameter, and looked up the parent.

I was also left with a question about replication of the ID strings of the application model elements. Apparently the application model doesn't require these to be unique. At least, I didn't do anything explicit to change the IDs after cloning multiple times. Is that right?

public class CloneSnippetHandler {

@Execute
public void cloneSnippet(@Named("snippetID") String snippetID,@Named("siblingID") String siblingID, EModelService modelService, MApplication application) {

MUIElement el = modelService.findSnippet(application,snippetID);
MUIElement sibling = modelService.find(siblingID, application);
MUIElement cloned = modelService.cloneSnippet(application, snippetID, null);
MElementContainer<MUIElement> cont = sibling.getParent();
cont.getChildren().add(cloned);
}
}
Re: MCompositePart creation with EPartService.createPart()? [message #1759908 is a reply to message #1759888] Wed, 19 April 2017 19:51 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
The "Windows and Dialogs" node shows the children of the application itself, so you can simplify your code by adding the cloned window directly to the application:
application.getChildren().add(cloned);
Re: MCompositePart creation with EPartService.createPart()? [message #1759920 is a reply to message #1759908] Wed, 19 April 2017 23:39 Go to previous message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
Christoph Keimel wrote on Wed, 19 April 2017 15:51
The "Windows and Dialogs" node shows the children of the application itself, so you can simplify your code by adding the cloned window directly to the application:
application.getChildren().add(cloned);


Yeah, thanks, but the handler can be reused for other snippet clone commands if I can consistently pass in a container ID.

I see that my application's ID is <project_name>.application, using application.getElementId().

String appId = application.getElementId();

Previous Topic:How to change default height of ListSelectionDialog
Next Topic:IWorkbenchHelpSystem can't injection
Goto Forum:
  


Current Time: Thu Apr 25 10:09:45 GMT 2024

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

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

Back to the top