Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » disabling / locking the new child/sibling Items
disabling / locking the new child/sibling Items [message #414095] Wed, 24 October 2007 14:32 Go to next message
lee is currently offline leeFriend
Messages: 11
Registered: July 2009
Junior Member
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 #414099 is a reply to message #414095] Wed, 24 October 2007 14:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Lee,

I think you'd want to specialize the item provider's
createCreateChildCommand to produce a command for which canExecute is
true or false depending on your condition.


lee wrote:
> 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
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: disabling / locking the new child/sibling Items [message #414124 is a reply to message #414099] Thu, 25 October 2007 13:27 Go to previous messageGo to next message
lee is currently offline leeFriend
Messages: 11
Registered: July 2009
Junior Member
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 14:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
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 --&gt;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>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: disabling / locking the new child/sibling Items [message #414138 is a reply to message #414126] Thu, 25 October 2007 17:31 Go to previous message
lee is currently offline leeFriend
Messages: 11
Registered: July 2009
Junior Member
HI Ed,


I love EMF :-)

After changing the constructor to the one with Helper parameter (to pass
the child Object) and overriding the createCreateChildCommand directly in
the Itemprovider it seems to work :-)

many thanks,

Lee
Previous Topic:Refactor : File move/rename
Next Topic:Validating additions to a list
Goto Forum:
  


Current Time: Wed Sep 25 19:10:19 GMT 2024

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

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

Back to the top