Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » How to change the method selectionChanged(IAction action, ISelection selection)(method selectionChanged(IAction action, ISelection selection) with commands and handlers)
How to change the method selectionChanged(IAction action, ISelection selection) [message #1014744] Tue, 26 February 2013 11:35 Go to next message
sabrina ing is currently offline sabrina ingFriend
Messages: 39
Registered: February 2013
Member
Hi,

I'm doing a project using the Plug-in papyrus Marte in eclipse, I add a popup menu

named "named import platform" using commands and Handlers in the view of the Model

Explorer when creating a papyrus Model.

I want to change the method selectionChanged(IAction action, ISelection selection) to

be used by commands and handlers not with actions.

public void selectionChanged(IAction action, ISelection selection) {

// the action is enabled only on UML packages stereotyped
// GaAnalysisContext
action.setEnabled(false);

// set the current selection
IStructuredSelection sselection = (IStructuredSelection) selection;
mySelection = sselection;

// look for selected Element
Object e = ((IStructuredSelection) selection).getFirstElement();

// set the editing domain
editDomain = EditorUtils.getTransactionalEditingDomain();
System.err.println(editDomain);

if (e instanceof IUMLNamedElementEditPart) {
Element element = ((IUMLNamedElementEditPart) e).getUMLElement();
if (element instanceof Package
&& element
.isStereotypeApplied(((Package) element)
.getApplicableStereotype("MARTE::MARTE_AnalysisModel::GQAM::GaAnalysisContext"))) {
if ((Package) element.getEAnnotation("annotation") != null) {
action.setEnabled(true);
selectedPackage = (Package) element;
}
}
}

else if (e instanceof ModelElementItem) {
EObject eObj = ((ModelElementItem) e).getEObject();
if (eObj instanceof Package
&& ((Package) eObj)
.isStereotypeApplied(((Package) eObj)
.getApplicableStereotype("MARTE::MARTE_AnalysisModel::GQAM::GaAnalysisContext"))) {
// if (((Package)eObj).getEAnnotation("annotation")!=null){
action.setEnabled(true);
selectedPackage = (Package) eObj;
// }
}
}
}

If you have some link or if you can advise me I would appreciate.

Thanks in advance.

Best Regards
Re: How to change the method selectionChanged(IAction action, ISelection selection) [message #1014801 is a reply to message #1014744] Tue, 26 February 2013 13:36 Go to previous message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 830
Registered: July 2009
Senior Member
Hi,

Command handlers get the selection from the HandlerUtil utility API.
For example,

ISelection HandlerUtil::getCurrentSelection(ExecutionEvent event)

Is this what you're asking?

Christian


On 2013-02-26 11:35:32 +0000, Mariem Makni said:

> Hi,
>
> I'm doing a project using the Plug-in papyrus Marte in eclipse, I add a
> popup menu
> named "named import platform" using commands and Handlers in the view
> of the Model
> Explorer when creating a papyrus Model.
>
> I want to change the method selectionChanged(IAction action, ISelection
> selection) to
> be used by commands and handlers not with actions.
>
> public void selectionChanged(IAction action, ISelection selection) {
>
> // the action is enabled only on UML packages stereotyped
> // GaAnalysisContext
> action.setEnabled(false);
>
> // set the current selection
> IStructuredSelection sselection = (IStructuredSelection) selection;
> mySelection = sselection;
>
> // look for selected Element
> Object e = ((IStructuredSelection) selection).getFirstElement();
>
> // set the editing domain
> editDomain = EditorUtils.getTransactionalEditingDomain();
> System.err.println(editDomain);
>
> if (e instanceof IUMLNamedElementEditPart) {
> Element element = ((IUMLNamedElementEditPart) e).getUMLElement();
> if (element instanceof Package
> && element
> .isStereotypeApplied(((Package) element)
>
> .getApplicableStereotype("MARTE::MARTE_AnalysisModel::GQAM::GaAnalysisContext")))
> {
> if ((Package) element.getEAnnotation("annotation") != null) {
> action.setEnabled(true);
> selectedPackage = (Package) element;
> }
> }
> }
>
> else if (e instanceof ModelElementItem) {
> EObject eObj = ((ModelElementItem) e).getEObject();
> if (eObj instanceof Package
> && ((Package) eObj)
> .isStereotypeApplied(((Package) eObj)
>
> .getApplicableStereotype("MARTE::MARTE_AnalysisModel::GQAM::GaAnalysisContext")))
> {
> // if (((Package)eObj).getEAnnotation("annotation")!=null){
> action.setEnabled(true);
> selectedPackage = (Package) eObj;
> // }
> }
> }
> }
>
> If you have some link or if you can advise me I would appreciate.
>
> Thanks in advance.
>
> Best Regards
Previous Topic:Could not initialize services
Next Topic:Changin Element properties by applying stereotypes?
Goto Forum:
  


Current Time: Mon Nov 24 14:22:20 GMT 2014

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

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