Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Programatically Select Elements in the Model-Explorer and the Papyrus Editor
Programatically Select Elements in the Model-Explorer and the Papyrus Editor [message #1718573] Sun, 27 December 2015 15:19 Go to next message
Moritz Kiehl is currently offline Moritz KiehlFriend
Messages: 8
Registered: November 2015
Junior Member
Hi there,

im Working on a bigger Project and at first i want to Implement a way to get elements out of either the Editor or the ModelExplorer and then i want to highlight it in the other.

I think i already got the solotion for getting my elements out of the Dev-Codeexamples, but the selection is not working like i want.

Here is my already existing code and i hope you can help me.

public class SelectElement {

	protected List<Object> getSelectedElement() {
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		ISelection selection = page.getSelection();
		if (selection instanceof IStructuredSelection) {
			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
			return structuredSelection.toList();
		} else if (selection instanceof TreeSelection) {
			TreeSelection treeSelection = (TreeSelection) selection;
			return treeSelection.toList();
		}
		return null;
	}

	protected void setSelectedElementsInEditor(List<Object> list) {

	}

	protected void setSelectedElementsInModelExplorer() {
	
		ModelExplorerView.selectReveal(new StructuredSelection(list), View);
		}
}


in the method SetSelectedElementsInModelExplorer i get a the errors:

Quote:

Multiple markers at this line
- The type org.eclipse.ui.navigator.CommonNavigator cannot be resolved. It is indirectly referenced from required .class files
- The type org.eclipse.emf.edit.domain.IEditingDomainProvider cannot be resolved. It is indirectly referenced from required .class files
- The method selectReveal(ISelection) in the type ModelExplorerView is not applicable for the arguments (List<Object>)
- The type org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement cannot be resolved. It is indirectly referenced from
required .class files


and i dont know how to fix them.

It would be great if you can help me or give me at least a hint so i may solve the problem on my own.

Best regards

Moritz Kiehl
Re: Programatically Select Elements in the Model-Explorer and the Papyrus Editor [message #1718575 is a reply to message #1718573] Sun, 27 December 2015 16:19 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Add the unreferenced classes as imports explicitly to an in-project Java
file and let the quyick fxes help you fix the project setup.

Regards

Ed Willink

On 27/12/2015 15:19, Moritz Kiehl wrote:
> Hi there,
>
> im Working on a bigger Project and at first i want to Implement a way
> to get elements out of either the Editor or the ModelExplorer and then
> i want to highlight it in the other.
>
> I think i already got the solotion for getting my elements out of the
> Dev-Codeexamples, but the selection is not working like i want.
>
> Here is my already existing code and i hope you can help me.
>
>
> public class SelectElement {
>
> protected List<Object> getSelectedElement() {
> IWorkbenchPage page =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
> ISelection selection = page.getSelection();
> if (selection instanceof IStructuredSelection) {
> IStructuredSelection structuredSelection =
> (IStructuredSelection) selection;
> return structuredSelection.toList();
> } else if (selection instanceof TreeSelection) {
> TreeSelection treeSelection = (TreeSelection) selection;
> return treeSelection.toList();
> }
> return null;
> }
>
> protected void setSelectedElementsInEditor(List<Object> list) {
>
> }
>
> protected void setSelectedElementsInModelExplorer() {
>
> ModelExplorerView.selectReveal(new StructuredSelection(list),
> View);
> }
> }
>
>
> in the method SetSelectedElementsInModelExplorer i get a the errors:
>
> Quote:
>> Multiple markers at this line
>> - The type org.eclipse.ui.navigator.CommonNavigator cannot be
>> resolved. It is indirectly referenced from required .class files
>> - The type org.eclipse.emf.edit.domain.IEditingDomainProvider
>> cannot be resolved. It is indirectly referenced from required .class
>> files
>> - The method selectReveal(ISelection) in the type
>> ModelExplorerView is not applicable for the arguments (List<Object>)
>> - The type
>> org.eclipse.papyrus.infra.widgets.util.IRevealSemanticElement cannot
>> be resolved. It is indirectly referenced from required .class files
>
>
> and i dont know how to fix them.
>
> It would be great if you can help me or give me at least a hint so i
> may solve the problem on my own.
>
> Best regards
>
> Moritz Kiehl
Re: Programatically Select Elements in the Model-Explorer and the Papyrus Editor [message #1720162 is a reply to message #1718575] Thu, 14 January 2016 20:17 Go to previous messageGo to next message
Moritz Kiehl is currently offline Moritz KiehlFriend
Messages: 8
Registered: November 2015
Junior Member
Hi

I fixed the Project Build Path and i looked into other posts and found something similar to my problem.

i have my Code mad up to this point :

IWorkbench workbench = PlatformUI.getWorkbench();
		IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
		IViewPart modelexplorer;
		IStructuredSelection selection = (IStructuredSelection) window.getActivePage().getSelection();

		try {
			modelexplorer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
					.showView(ModelExplorerPageBookView.VIEW_ID);

		} catch (PartInitException ex) {
			System.out.println("ERROR");
			return;
		}
		ModelExplorerPageBookView view = (ModelExplorerPageBookView) modelexplorer;
		IPage currentPage = view.getCurrentPage();
		ModelExplorerPage page = (ModelExplorerPage) currentPage;
		IViewPart viewer = page.getViewer();
		ModelExplorerView modelExplorerView = (ModelExplorerView) viewer;
		modelExplorerView.setFocus();
		modelExplorerView.selectReveal(selection);
		


In my plugin i select the modelexplorer but not the elements inside.

I hope you can help me a bit.

best regard
Moritz

Re: Programatically Select Elements in the Model-Explorer and the Papyrus Editor [message #1720208 is a reply to message #1720162] Fri, 15 January 2016 09:01 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 952
Registered: February 2011
Senior Member
Hi Moritz,

The active page will return a selection of EditParts (Assuming you select something in a Papyrus Diagram). The ModelExplorer expects semantic elements (EObjects).

You can use the Papyrus EMFHelper to extract EObjects from a selected (graphical) element:

EObject eObject = EMFHelper.getEObject(selectedElement);


You need to iterate on all selected elements (Via IStructuredSelection#iterator()) and extract an EObject for each (Note that the EObject may be null in some cases, so you need to exclude these)

Then you can either build a new StructuredSelection from these EObjects, or a simple Java List and use ModelExplorerView#revealSemanticElement(LIst)

HTH,
Camille


Camille Letavernier
Re: Programatically Select Elements in the Model-Explorer and the Papyrus Editor [message #1720224 is a reply to message #1720208] Fri, 15 January 2016 11:50 Go to previous message
Moritz Kiehl is currently offline Moritz KiehlFriend
Messages: 8
Registered: November 2015
Junior Member
Thank you very Much

its working now.

Moritz
Previous Topic:State Diagram Animation and Java Code Generation
Next Topic:[SysML] Fork Node Orientation
Goto Forum:
  


Current Time: Fri Apr 19 18:38:45 GMT 2024

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

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

Back to the top