Home » Modeling » EMF » disabling / locking the new child/sibling Items
| |
Re: disabling / locking the new child/sibling Items [message #414124 is a reply to message #414099] |
Thu, 25 October 2007 13:27 |
lee 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 |
Ed Merks 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 -->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/
|
|
| |
Goto Forum:
Current Time: Wed Sep 25 19:10:19 GMT 2024
Powered by FUDForum. Page generated in 0.03901 seconds
|