Home » Modeling » EMF » disabling / locking the new child/sibling Items
disabling / locking the new child/sibling Items [message #414095] |
Wed, 24 October 2007 10:32  |
Eclipse User |
|
|
|
Hi all!
I am currently trying to block or disable the create child/sibling menu
item after right-click based on a specific condition. But unfortunately it
doesn't work. It makes no difference to me wheter the menu item isn't
selectable or it is disappeared after right click.
I am not sure where axactly this can be done in the ActionBarContributor
class!
is such an action possible at all?
If yes i need 2 Information. Which method is invoked if a activate the
pull-down menu (here i want to refresh my condition)?! and at which point
should i place my condition to disable the items?
best regards,
Lee
|
|
| |
Re: disabling / locking the new child/sibling Items [message #414124 is a reply to message #414099] |
Thu, 25 October 2007 09:27   |
Eclipse User |
|
|
|
Hi Ed!
except the setCommand i have never used the command framwork so excuse me
if i bother you too much:-)
As you know i have only one containment realationship. Book -->page. So
book is the only root-element. there are many pages allowed
I am trying to do what you suggested but i have the following issues:
i add the following code to my Book item provider class to override the
createChildCommand
public Command createCommand(Object object, EditingDomain domain, Class
commandClass, CommandParameter commandParameter)
{
if(commandClass == CreateChildCommand.class)
{
//System.out.println(commandParameter.getEOwner()); System.out.println(commandParameter.getEStructuralFeature()) ;
//System.out.println(commandParameter.getIndex()); //System.out.println(commandParameter.getCollection());
return new CreatePageCommand(domain,
commandParameter.getEOwner(),
commandParameter.getEStructuralFeature(),
commandParameter.getIndex(),
commandParameter.getCollection());
}
return super.createCommand(object, domain, commandClass,
commandParameter);
}
the code of CreatePageCommand is as follow:
public class CreatePageCommand extends CreateChildCommand {
public String abstractionLevel = "";
public CreateDecisionCommand(EditingDomain domain, EObject owner,
EStructuralFeature structuralFeature, int index, Collection collection)
{
super(domain, owner, structuralFeature, index, collection);
RuntimeManager info = RuntimeManager.getInstance();
HashMap<String,String> naviMap = info.getSelectedDimensionElements();
abstractionLevel = (String)naviMap.get("Abstraction Level");
}
public boolean canExecute()
{
boolean result = false;
if(abstractionLevel.equals("Full"))
{
result = false;
}
else if(!abstractionLevel.equals("Full")) {
result = true;
}
return result;
}
public void execute()
{
super.execute();
}
}
now i get the strange Effect that the canExecute Method is correctly
executed. So the add item as sibbling or child is only allowed if the
condition is true, but there is no more "page"-Item available in the
pull-down menu. This means that after right click i have "Object" instead
of my "page". and After clicking on "object" there is no object added!
In my Oponion i am doing something wrong in overriding the
createChildCommand beacause the commandParameter.getEStructuralFeature()
is null!?
best regards and many thanks
|
|
|
Re: disabling / locking the new child/sibling Items [message #414126 is a reply to message #414124] |
Thu, 25 October 2007 10:25   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------060305060302080409020309
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Lee,
Comments below.
lee wrote:
> Hi Ed!
>
> except the setCommand i have never used the command framwork so excuse
> me if i bother you too much:-)
>
> As you know i have only one containment realationship. Book -->page.
> So book is the only root-element. there are many pages allowed
>
> I am trying to do what you suggested but i have the following issues:
>
> i add the following code to my Book item provider class to override
> the createChildCommand
>
> public Command createCommand(Object object, EditingDomain domain,
> Class commandClass, CommandParameter commandParameter)
> {
> if(commandClass == CreateChildCommand.class)
> {
>
> //System.out.println(commandParameter.getEOwner());
> System.out.println(commandParameter.getEStructuralFeature()) ;
>
> //System.out.println(commandParameter.getIndex());
> //System.out.println(commandParameter.getCollection());
> return new CreatePageCommand(domain,
> commandParameter.getEOwner(),
> commandParameter.getEStructuralFeature(),
> commandParameter.getIndex(),
> commandParameter.getCollection());
> }
> return super.createCommand(object, domain, commandClass,
> commandParameter);
> }
>
> the code of CreatePageCommand is as follow:
This factoring is already done in the base class, so best to override
createCreateChildCommand directly (and have a look at which constructor
that existing method calls to answer your question at the bottom of the
note).
else if (commandClass == CreateChildCommand.class)
{
CommandParameter newChildParameter =
(CommandParameter)commandParameter.getValue();
result =
createCreateChildCommand
(domain,
commandParameter.getEOwner(),
newChildParameter.getEStructuralFeature(),
newChildParameter.getValue(),
newChildParameter.getIndex(),
commandParameter.getCollection());
}
>
> public class CreatePageCommand extends CreateChildCommand {
>
> public String abstractionLevel = "";
Why does the constructor not match the class name?
> public CreateDecisionCommand(EditingDomain domain, EObject owner,
> EStructuralFeature structuralFeature, int index, Collection collection)
> {
> super(domain, owner, structuralFeature, index, collection);
> RuntimeManager info = RuntimeManager.getInstance();
> HashMap<String,String> naviMap =
> info.getSelectedDimensionElements();
>
> abstractionLevel = (String)naviMap.get("Abstraction Level");
>
> }
>
> public boolean canExecute()
> {
> boolean result = false;
> if(abstractionLevel.equals("Full"))
> {
> result = false;
> }
> else if(!abstractionLevel.equals("Full")) {
> result = true;
> }
> return result;
> }
This seems an incredibly complex way to express
return !"Full".equals(abstractionlevel);
>
>
> public void execute()
> {
> super.execute();
> }
What purpose does this serve.
>
> }
>
>
> now i get the strange Effect that the canExecute Method is correctly
> executed. So the add item as sibbling or child is only allowed if the
> condition is true, but there is no more "page"-Item available in the
> pull-down menu. This means that after right click i have "Object"
> instead of my "page". and After clicking on "object" there is no
> object added!
>
> In my Oponion i am doing something wrong in overriding the
> createChildCommand beacause the
> commandParameter.getEStructuralFeature() is null!?
>
> best regards and many thanks
>
--------------060305060302080409020309
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Lee,<br>
<br>
Comments below.<br>
<br>
lee wrote:
<blockquote
cite="mid:be0ae79a1c8dbcd8e389a86dd6513a31$1@www.eclipse.org"
type="cite">Hi Ed!
<br>
<br>
except the setCommand i have never used the command framwork so excuse
me if i bother you too much:-)
<br>
<br>
As you know i have only one containment realationship. Book -->page.
So book is the only root-element. there are many pages allowed
<br>
<br>
I am trying to do what you suggested but i have the following issues:
<br>
<br>
i add the following code to my Book item provider class to override the
createChildCommand
<br>
<br>
public Command createCommand(Object object, EditingDomain domain, Class
commandClass, CommandParameter commandParameter)
<br>
|
|
| |
Goto Forum:
Current Time: Tue Jul 15 13:10:57 EDT 2025
Powered by FUDForum. Page generated in 0.28388 seconds
|