Skip to main content


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
Mariem Makni is currently offline Mariem MakniFriend
Messages: 46
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 Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
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: Thu Apr 25 05:41:41 GMT 2024

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

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

Back to the top