Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Overidding Action in Child or Sibling Menus
Overidding Action in Child or Sibling Menus [message #389287] Wed, 17 November 2004 04:34 Go to next message
Mark Diggory is currently offline Mark DiggoryFriend
Messages: 202
Registered: July 2009
Senior Member
So I've figured out how to override Commands in the ItemProviders so
that I can perform further tasks when I create a child. I would like to
continue to maintain separation between the edit and edit.ui layers. How
can I override the Actions in these Child/Sibling menus so that they do
other tasks like open a wizard or file dialog prior to creating the
Child/Sibling so that I can gather input used to configure the
Child/Sibling?

-thanks,
Mark
Re: Overidding Action in Child or Sibling Menus [message #389296 is a reply to message #389287] Wed, 17 November 2004 12:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Mark,

The menus and actions are constructed in the generated
ActionBarContributor, so that would be the place to specialize the
behavior to do additional actions.


Mark Diggory wrote:

> So I've figured out how to override Commands in the ItemProviders so
> that I can perform further tasks when I create a child. I would like
> to continue to maintain separation between the edit and edit.ui
> layers. How can I override the Actions in these Child/Sibling menus so
> that they do other tasks like open a wizard or file dialog prior to
> creating the Child/Sibling so that I can gather input used to
> configure the Child/Sibling?
>
> -thanks,
> Mark


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Overidding Action in Child or Sibling Menus [message #389297 is a reply to message #389296] Wed, 17 November 2004 13:00 Go to previous messageGo to next message
Mark Diggory is currently offline Mark DiggoryFriend
Messages: 202
Registered: July 2009
Senior Member
My more specific question is actually how to best pass information
gathered in a Wizard or dialog into the custom Command I've created for
that feature. One thought I have is to somehow override the
CommandParameter to include this information such that the Command can
pick it out and use it. Is this logical?

-Mark

Ed Merks wrote:
> Mark,
>
> The menus and actions are constructed in the generated
> ActionBarContributor, so that would be the place to specialize the
> behavior to do additional actions.
>
>
> Mark Diggory wrote:
>
>> So I've figured out how to override Commands in the ItemProviders so
>> that I can perform further tasks when I create a child. I would like
>> to continue to maintain separation between the edit and edit.ui
>> layers. How can I override the Actions in these Child/Sibling menus so
>> that they do other tasks like open a wizard or file dialog prior to
>> creating the Child/Sibling so that I can gather input used to
>> configure the Child/Sibling?
>>
>> -thanks,
>> Mark
>
>
Re: Overidding Action in Child or Sibling Menus [message #389298 is a reply to message #389297] Wed, 17 November 2004 13:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Mark,

It may be possible for the wizard to use its information just to create
"regular" commands. But if you need/want to use specialized commands,
it's best to try to reuse the CommandParameter without overriding it by
encoding your additional information as part of the value or the
collection (kind of like the way the new child descriptor is passed as
the value of the command parameter). If necessary/desirable, you can
always create a new command class that's recognized directly
ItemProviderAdapter.createCommand...


Mark Diggory wrote:

> My more specific question is actually how to best pass information
> gathered in a Wizard or dialog into the custom Command I've created
> for that feature. One thought I have is to somehow override the
> CommandParameter to include this information such that the Command can
> pick it out and use it. Is this logical?
>
> -Mark
>
> Ed Merks wrote:
>
>> Mark,
>>
>> The menus and actions are constructed in the generated
>> ActionBarContributor, so that would be the place to specialize the
>> behavior to do additional actions.
>>
>>
>> Mark Diggory wrote:
>>
>>> So I've figured out how to override Commands in the ItemProviders so
>>> that I can perform further tasks when I create a child. I would like
>>> to continue to maintain separation between the edit and edit.ui
>>> layers. How can I override the Actions in these Child/Sibling menus
>>> so that they do other tasks like open a wizard or file dialog prior
>>> to creating the Child/Sibling so that I can gather input used to
>>> configure the Child/Sibling?
>>>
>>> -thanks,
>>> Mark
>>
>>
>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Overidding Action in Child or Sibling Menus [message #389299 is a reply to message #389298] Wed, 17 November 2004 13:39 Go to previous messageGo to next message
Mark Diggory is currently offline Mark DiggoryFriend
Messages: 202
Registered: July 2009
Senior Member
I've started to do something like this, I have the following in my
ActionBarContributor:

> protected Collection generateCreateChildActions(Collection descriptors, ISelection selection) {
> Collection actions = new ArrayList();
> if (descriptors != null) {
> for (Iterator i = descriptors.iterator(); i.hasNext(); ) {
> CommandParameter o = (CommandParameter)i.next();
>
> if(o.getValue() instanceof FeatureMap.Entry && ((FeatureMap.Entry)o.getValue()).getValue() instanceof SurveyType){
> actions.add(new CreateSurveyChildAction(activeEditorPart, selection, o));
> } else if(o.getValue() instanceof FeatureMap.Entry && ((FeatureMap.Entry)o.getValue()).getValue() instanceof CensusType){
> actions.add(new CreateSurveyChildAction(activeEditorPart, selection, o));
> } else {
> actions.add(new CreateChildAction(activeEditorPart, selection, o));
> }
> }
> }
> return actions;
> }

And a separate CreateSurveyChildAction class in which I will place the
wizard. In my "OutlineItemProvider" I'm overriding the createChild
method to insert a custom command like so:

> /* (non-Javadoc)
> * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#createCrea teChildCommand(org.eclipse.emf.edit.domain.EditingDomain, org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EStructuralFeature, java.lang.Object, int, java.util.Collection)
> */
> protected Command createCreateChildCommand(EditingDomain domain,
> EObject owner, EStructuralFeature feature, Object value, int index,
> Collection collection) {
>
> if(value instanceof FeatureMap.Entry && ((FeatureMap.Entry)value).getValue() instanceof SurveyType){
> return new TestCommand(super.createCreateChildCommand(domain, owner, feature, value,index, collection));
> } else if(value instanceof FeatureMap.Entry && ((FeatureMap.Entry)value).getValue() instanceof CensusType){
> return new TestCommand(super.createCreateChildCommand(domain, owner, feature, value,index, collection));
> }
>
> return super.createCreateChildCommand(domain, owner, feature, value,index, collection);
> }
>
> class TestCommand extends CommandWrapper implements CommandActionDelegate{
>
> public Logger log = Logger.getLogger(TestCommand.class);
>
> public TestCommand(Command someOtherCommand){
> super(someOtherCommand);
> }
>
> public void execute(){
> log.debug("Executing Command");
> super.execute();
> //doSomethingAfterExecution();
> }
> public Collection getResult(){
> return super.getResult();
> }
>
> /* (non-Javadoc)
> * @see org.eclipse.emf.edit.command.CommandActionDelegate#getImage( )
> */
> public Object getImage() {
> return ((CommandActionDelegate)super.command).getImage();
> }
>
> /* (non-Javadoc)
> * @see org.eclipse.emf.edit.command.CommandActionDelegate#getText()
> */
> public String getText() {
> return ((CommandActionDelegate)super.command).getText();
> }
>
> /* (non-Javadoc)
> * @see org.eclipse.emf.edit.command.CommandActionDelegate#getToolTi pText()
> */
> public String getToolTipText() {
> return ((CommandActionDelegate)super.command).getToolTipText();
> }
> };

Ultimately, what I want to do in the Command is load another resource
containing all the children to be inserted at this point and copy/paste
them into model instead of just creating the new child (theres a couple
other tasks, but thats the primary activity). I'd like to maintain one
"undo" step, so that the user can remove the entire modification done by
the Wizard in one undo Command if they decide they didn't like what it did.

-Mark

Ed Merks wrote:
> Mark,
>
> It may be possible for the wizard to use its information just to create
> "regular" commands. But if you need/want to use specialized commands,
> it's best to try to reuse the CommandParameter without overriding it by
> encoding your additional information as part of the value or the
> collection (kind of like the way the new child descriptor is passed as
> the value of the command parameter). If necessary/desirable, you can
> always create a new command class that's recognized directly
> ItemProviderAdapter.createCommand...
>
>
> Mark Diggory wrote:
>
>> My more specific question is actually how to best pass information
>> gathered in a Wizard or dialog into the custom Command I've created
>> for that feature. One thought I have is to somehow override the
>> CommandParameter to include this information such that the Command can
>> pick it out and use it. Is this logical?
>>
>> -Mark
>>
>> Ed Merks wrote:
>>
>>> Mark,
>>>
>>> The menus and actions are constructed in the generated
>>> ActionBarContributor, so that would be the place to specialize the
>>> behavior to do additional actions.
>>>
>>>
>>> Mark Diggory wrote:
>>>
>>>> So I've figured out how to override Commands in the ItemProviders so
>>>> that I can perform further tasks when I create a child. I would like
>>>> to continue to maintain separation between the edit and edit.ui
>>>> layers. How can I override the Actions in these Child/Sibling menus
>>>> so that they do other tasks like open a wizard or file dialog prior
>>>> to creating the Child/Sibling so that I can gather input used to
>>>> configure the Child/Sibling?
>>>>
>>>> -thanks,
>>>> Mark
>>>
>>>
>>>
>>>
Re: Overidding Action in Child or Sibling Menus [message #394110 is a reply to message #389299] Tue, 05 July 2005 06:40 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6690
Registered: July 2009
Senior Member
hi mark,

have you succeeded with your action that opens a dialog, creates and links a resource for children?
i'd be very interested in your solution. would you mind sharing it?!

cheers
/eike



Mark Diggory schrieb:
> I've started to do something like this, I have the following in my
> ActionBarContributor:
>
>> protected Collection generateCreateChildActions(Collection
>> descriptors, ISelection selection) {
>> Collection actions = new ArrayList();
>> if (descriptors != null) {
>> for (Iterator i = descriptors.iterator(); i.hasNext(); ) {
>> CommandParameter o = (CommandParameter)i.next();
>>
>> if(o.getValue() instanceof FeatureMap.Entry &&
>> ((FeatureMap.Entry)o.getValue()).getValue() instanceof SurveyType){
>> actions.add(new
>> CreateSurveyChildAction(activeEditorPart, selection, o));
>> } else if(o.getValue() instanceof FeatureMap.Entry &&
>> ((FeatureMap.Entry)o.getValue()).getValue() instanceof CensusType){
>> actions.add(new
>> CreateSurveyChildAction(activeEditorPart, selection, o));
>> } else {
>> actions.add(new
>> CreateChildAction(activeEditorPart, selection, o));
>> }
>> }
>> }
>> return actions;
>> }
>
>
> And a separate CreateSurveyChildAction class in which I will place the
> wizard. In my "OutlineItemProvider" I'm overriding the createChild
> method to insert a custom command like so:
>
>> /* (non-Javadoc)
>> * @see
>> org.eclipse.emf.edit.provider.ItemProviderAdapter#createCrea teChildCommand(org.eclipse.emf.edit.domain.EditingDomain,
>> org.eclipse.emf.ecore.EObject,
>> org.eclipse.emf.ecore.EStructuralFeature, java.lang.Object, int,
>> java.util.Collection)
>> */
>> protected Command createCreateChildCommand(EditingDomain domain,
>> EObject owner, EStructuralFeature feature, Object value,
>> int index,
>> Collection collection) {
>>
>> if(value instanceof FeatureMap.Entry &&
>> ((FeatureMap.Entry)value).getValue() instanceof SurveyType){
>> return new
>> TestCommand(super.createCreateChildCommand(domain, owner, feature,
>> value,index, collection));
>> } else if(value instanceof FeatureMap.Entry &&
>> ((FeatureMap.Entry)value).getValue() instanceof CensusType){
>> return new
>> TestCommand(super.createCreateChildCommand(domain, owner, feature,
>> value,index, collection));
>> }
>>
>> return super.createCreateChildCommand(domain, owner, feature,
>> value,index, collection);
>> }
>>
>> class TestCommand extends CommandWrapper implements
>> CommandActionDelegate{
>>
>> public Logger log = Logger.getLogger(TestCommand.class);
>>
>> public TestCommand(Command someOtherCommand){
>> super(someOtherCommand);
>> }
>> public void execute(){
>> log.debug("Executing Command");
>> super.execute();
>> //doSomethingAfterExecution();
>> }
>> public Collection getResult(){
>> return super.getResult();
>> }
>>
>> /* (non-Javadoc)
>> * @see
>> org.eclipse.emf.edit.command.CommandActionDelegate#getImage( )
>> */
>> public Object getImage() {
>> return ((CommandActionDelegate)super.command).getImage();
>> }
>>
>> /* (non-Javadoc)
>> * @see
>> org.eclipse.emf.edit.command.CommandActionDelegate#getText()
>> */
>> public String getText() {
>> return ((CommandActionDelegate)super.command).getText();
>> }
>>
>> /* (non-Javadoc)
>> * @see
>> org.eclipse.emf.edit.command.CommandActionDelegate#getToolTi pText()
>> */
>> public String getToolTipText() {
>> return
>> ((CommandActionDelegate)super.command).getToolTipText();
>> }
>> };
>
>
> Ultimately, what I want to do in the Command is load another resource
> containing all the children to be inserted at this point and copy/paste
> them into model instead of just creating the new child (theres a couple
> other tasks, but thats the primary activity). I'd like to maintain one
> "undo" step, so that the user can remove the entire modification done by
> the Wizard in one undo Command if they decide they didn't like what it did.
>
> -Mark
>
> Ed Merks wrote:
>
>> Mark,
>>
>> It may be possible for the wizard to use its information just to
>> create "regular" commands. But if you need/want to use specialized
>> commands, it's best to try to reuse the CommandParameter without
>> overriding it by encoding your additional information as part of the
>> value or the collection (kind of like the way the new child descriptor
>> is passed as the value of the command parameter). If
>> necessary/desirable, you can always create a new command class that's
>> recognized directly ItemProviderAdapter.createCommand...
>>
>>
>> Mark Diggory wrote:
>>
>>> My more specific question is actually how to best pass information
>>> gathered in a Wizard or dialog into the custom Command I've created
>>> for that feature. One thought I have is to somehow override the
>>> CommandParameter to include this information such that the Command
>>> can pick it out and use it. Is this logical?
>>>
>>> -Mark
>>>
>>> Ed Merks wrote:
>>>
>>>> Mark,
>>>>
>>>> The menus and actions are constructed in the generated
>>>> ActionBarContributor, so that would be the place to specialize the
>>>> behavior to do additional actions.
>>>>
>>>>
>>>> Mark Diggory wrote:
>>>>
>>>>> So I've figured out how to override Commands in the ItemProviders
>>>>> so that I can perform further tasks when I create a child. I would
>>>>> like to continue to maintain separation between the edit and
>>>>> edit.ui layers. How can I override the Actions in these
>>>>> Child/Sibling menus so that they do other tasks like open a wizard
>>>>> or file dialog prior to creating the Child/Sibling so that I can
>>>>> gather input used to configure the Child/Sibling?
>>>>>
>>>>> -thanks,
>>>>> Mark
>>>>
>>>>
>>>>
>>>>
>>>>


Re: Overidding Action in Child or Sibling Menus [message #394123 is a reply to message #394110] Tue, 05 July 2005 12:52 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.
--------------010800020307040101010102
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Eike,

I imagine it would involve overriding ResourceItemProvider something
like this:

public Collection getNewChildDescriptors(Object object,
EditingDomain editingDomain, Object sibling)
{
Collection newChildDescriptors = new ArrayList();
collectNewChildDescriptors(newChildDescriptors, object);
return newChildDescriptors;
}

protected void collectNewChildDescriptors(Collection
newChildDescriptors, Object object)
{
//super.collectNewChildDescriptors(newChildDescriptors, object);

newChildDescriptors.add
(createChildParameter
(new Integer(Resource.RESOURCE__CONTENTS),
EcoreFactory.eINSTANCE.createEObject()));
}

If there are change we should make in the framework to make this easier,
let us know.


Eike Stepper wrote:

> hi mark,
>
> have you succeeded with your action that opens a dialog, creates and
> links a resource for children?
> i'd be very interested in your solution. would you mind sharing it?!
>
> cheers
> /eike
>
>
>
> Mark Diggory schrieb:
>
>> I've started to do something like this, I have the following in my
>> ActionBarContributor:
>>
>>> protected Collection generateCreateChildActions(Collection
>>> descriptors, ISelection selection) {
>>> Collection actions = new ArrayList();
>>> if (descriptors != null) {
>>> for (Iterator i = descriptors.iterator(); i.hasNext(); ) {
>>> CommandParameter o = (CommandParameter)i.next();
>>> if(o.getValue() instanceof
>>> FeatureMap.Entry && ((FeatureMap.Entry)o.getValue()).getValue()
>>> instanceof SurveyType){
>>> actions.add(new
>>> CreateSurveyChildAction(activeEditorPart, selection, o));
>>> } else if(o.getValue() instanceof FeatureMap.Entry
>>> && ((FeatureMap.Entry)o.getValue()).getValue() instanceof CensusType){
>>> actions.add(new
>>> CreateSurveyChildAction(activeEditorPart, selection, o));
>>> } else {
>>> actions.add(new
>>> CreateChildAction(activeEditorPart, selection, o));
>>> } }
>>> }
>>> return actions;
>>> }
>>
>>
>>
>> And a separate CreateSurveyChildAction class in which I will place
>> the wizard. In my "OutlineItemProvider" I'm overriding the
>> createChild method to insert a custom command like so:
>>
>>> /* (non-Javadoc)
>>> * @see
>>> org.eclipse.emf.edit.provider.ItemProviderAdapter#createCrea teChildCommand(org.eclipse.emf.edit.domain.EditingDomain,
>>> org.eclipse.emf.ecore.EObject,
>>> org.eclipse.emf.ecore.EStructuralFeature, java.lang.Object, int,
>>> java.util.Collection)
>>> */
>>> protected Command createCreateChildCommand(EditingDomain domain,
>>> EObject owner, EStructuralFeature feature, Object value,
>>> int index,
>>> Collection collection) {
>>>
>>> if(value instanceof FeatureMap.Entry &&
>>> ((FeatureMap.Entry)value).getValue() instanceof SurveyType){
>>> return new
>>> TestCommand(super.createCreateChildCommand(domain, owner, feature,
>>> value,index, collection));
>>> } else if(value instanceof FeatureMap.Entry &&
>>> ((FeatureMap.Entry)value).getValue() instanceof CensusType){
>>> return new
>>> TestCommand(super.createCreateChildCommand(domain, owner, feature,
>>> value,index, collection));
>>> }
>>> return super.createCreateChildCommand(domain, owner,
>>> feature, value,index, collection);
>>> }
>>> class TestCommand extends CommandWrapper implements
>>> CommandActionDelegate{
>>> public Logger log = Logger.getLogger(TestCommand.class);
>>> public TestCommand(Command someOtherCommand){
>>> super(someOtherCommand);
>>> }
>>> public void execute(){
>>> log.debug("Executing Command");
>>> super.execute();
>>> //doSomethingAfterExecution();
>>> }
>>> public Collection getResult(){
>>> return super.getResult();
>>> }
>>>
>>> /* (non-Javadoc)
>>> * @see
>>> org.eclipse.emf.edit.command.CommandActionDelegate#getImage( )
>>> */
>>> public Object getImage() {
>>> return
>>> ((CommandActionDelegate)super.command).getImage();
>>> }
>>>
>>> /* (non-Javadoc)
>>> * @see
>>> org.eclipse.emf.edit.command.CommandActionDelegate#getText()
>>> */
>>> public String getText() {
>>> return
>>> ((CommandActionDelegate)super.command).getText();
>>> }
>>>
>>> /* (non-Javadoc)
>>> * @see
>>> org.eclipse.emf.edit.command.CommandActionDelegate#getToolTi pText()
>>> */
>>> public String getToolTipText() {
>>> return
>>> ((CommandActionDelegate)super.command).getToolTipText();
>>> }
>>> };
>>
>>
>>
>> Ultimately, what I want to do in the Command is load another resource
>> containing all the children to be inserted at this point and
>> copy/paste them into model instead of just creating the new child
>> (theres a couple other tasks, but thats the primary activity). I'd
>> like to maintain one "undo" step, so that the user can remove the
>> entire modification done by the Wizard in one undo Command if they
>> decide they didn't like what it did.
>>
>> -Mark
>>
>> Ed Merks wrote:
>>
>>> Mark,
>>>
>>> It may be possible for the wizard to use its information just to
>>> create "regular" commands. But if you need/want to use specialized
>>> commands, it's best to try to reuse the CommandParameter without
>>> overriding it by encoding your additional information as part of the
>>> value or the collection (kind of like the way the new child
>>> descriptor is passed as the value of the command parameter). If
>>> necessary/desirable, you can always create a new command class
>>> that's recognized directly ItemProviderAdapter.createCommand...
>>>
>>>
>>> Mark Diggory wrote:
>>>
>>>> My more specific question is actually how to best pass information
>>>> gathered in a Wizard or dialog into the custom Command I've created
>>>> for that feature. One thought I have is to somehow override the
>>>> CommandParameter to include this information such that the Command
>>>> can pick it out and use it. Is this logical?
>>>>
>>>> -Mark
>>>>
>>>> Ed Merks wrote:
>>>>
>>>>> Mark,
>>>>>
>>>>> The menus and actions are constructed in the generated
>>>>> ActionBarContributor, so that would be the place to specialize the
>>>>> behavior to do additional actions.
>>>>>
>>>>>
>>>>> Mark Diggory wrote:
>>>>>
>>>>>> So I've figured out how to override Commands in the ItemProviders
>>>>>> so that I can perform further tasks when I create a child. I
>>>>>> would like to continue to maintain separation between the edit
>>>>>> and edit.ui layers. How can I override the Actions in these
>>>>>> Child/Sibling menus so that they do other tasks like open a
>>>>>> wizard or file dialog prior to creating the Child/Sibling so that
>>>>>> I can gather input used to configure the Child/Sibling?
>>>>>>
>>>>>> -thanks,
>>>>>> Mark
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>


--------------010800020307040101010102
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Eike,<br>
<br>
I imagine it would involve overriding ResourceItemProvider something
like this:<br>
<blockquote>&nbsp; public Collection getNewChildDescriptors(Object object,
EditingDomain editingDomain, Object sibling)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; Collection newChildDescriptors = new ArrayList();<br>
&nbsp;&nbsp;&nbsp; collectNewChildDescriptors(newChildDescriptors, object);<br>
&nbsp;&nbsp;&nbsp; return newChildDescriptors;<br>
&nbsp; }<br>
<br>
&nbsp; protected void collectNewChildDescriptors(Collection
newChildDescriptors, Object object)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; //super.collectNewChildDescriptors(newChildDescriptors, object);<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; newChildDescriptors.add<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (createChildParameter<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; (new Integer(Resource.RESOURCE__CONTENTS),<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; EcoreFactory.eINSTANCE.createEObject()));<br>
&nbsp; }<br>
</blockquote>
If there are change we should make in the framework to make this
easier, let us know.<br>
<br>
<br>
Eike Stepper wrote:
<blockquote cite="mid42CA2B43.8050600@sympedia.de" type="cite">hi mark,
<br>
<br>
have you succeeded with your action that opens a dialog, creates and
links a resource for children?
<br>
i'd be very interested in your solution. would you mind sharing it?!
<br>
<br>
cheers
<br>
/eike
<br>
<br>
<br>
<br>
Mark Diggory schrieb:
<br>
<blockquote type="cite">I've started to do something like this, I
have the following in my ActionBarContributor:
<br>
<br>
<blockquote type="cite">&nbsp;&nbsp;&nbsp; protected Collection
generateCreateChildActions(Collection descriptors, ISelection
selection) {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Collection actions = new ArrayList();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if (descriptors != null) {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (Iterator i = descriptors.iterator(); i.hasNext(); ) {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CommandParameter o = (CommandParameter)i.next();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(o.getValue() instanceof
FeatureMap.Entry &amp;&amp; ((FeatureMap.Entry)o.getValue()).getValue()
instanceof SurveyType){
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; actions.add(new
CreateSurveyChildAction(activeEditorPart, selection, o));&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } else if(o.getValue() instanceof FeatureMap.Entry
&amp;&amp; ((FeatureMap.Entry)o.getValue()).getValue() instanceof
CensusType){
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; actions.add(new
CreateSurveyChildAction(activeEditorPart, selection, o));&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } else {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; actions.add(new CreateChildAction(activeEditorPart,
selection, o));&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return actions;
<br>
&nbsp;&nbsp;&nbsp; }
<br>
</blockquote>
<br>
<br>
And a separate CreateSurveyChildAction class in which I will place the
wizard. In my "OutlineItemProvider" I'm overriding the createChild
method to insert a custom command like so:
<br>
<br>
<blockquote type="cite">/* (non-Javadoc)
<br>
&nbsp;&nbsp;&nbsp;&nbsp; * @see
org.eclipse.emf.edit.provider.ItemProviderAdapter#createCrea teChildCommand(org.eclipse.emf.edit.domain.EditingDomain,
org.eclipse.emf.ecore.EObject,
org.eclipse.emf.ecore.EStructuralFeature, java.lang.Object, int,
java.util.Collection)
<br>
&nbsp;&nbsp;&nbsp;&nbsp; */
<br>
&nbsp;&nbsp;&nbsp; protected Command createCreateChildCommand(EditingDomain domain,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EObject owner, EStructuralFeature feature, Object value,
int index,
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Collection collection) {
<br>
&nbsp;
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if(value instanceof FeatureMap.Entry &amp;&amp;
((FeatureMap.Entry)value).getValue() instanceof SurveyType){
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new
TestCommand(super.createCreateChildCommand(domain, owner, feature,
value,index, collection));
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; } else if(value instanceof FeatureMap.Entry &amp;&amp;
((FeatureMap.Entry)value).getValue() instanceof CensusType){
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new
TestCommand(super.createCreateChildCommand(domain, owner, feature,
value,index, collection));
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return super.createCreateChildCommand(domain, owner,
feature, value,index, collection);
<br>
&nbsp;&nbsp;&nbsp; }
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; class TestCommand extends CommandWrapper implements
CommandActionDelegate{
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; public Logger log = Logger.getLogger(TestCommand.class);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; public TestCommand(Command someOtherCommand){
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super(someOtherCommand);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public void execute(){
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; log.debug("Executing Command");
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; super.execute();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; //doSomethingAfterExecution();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Collection getResult(){
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return super.getResult();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* (non-Javadoc)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @see
org.eclipse.emf.edit.command.CommandActionDelegate#getImage( )
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Object getImage() {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return
((CommandActionDelegate)super.command).getImage();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* (non-Javadoc)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @see
org.eclipse.emf.edit.command.CommandActionDelegate#getText()
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public String getText() {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return
((CommandActionDelegate)super.command).getText();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* (non-Javadoc)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @see
org.eclipse.emf.edit.command.CommandActionDelegate#getToolTi pText()
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public String getToolTipText() {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return
((CommandActionDelegate)super.command).getToolTipText();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
<br>
&nbsp;&nbsp;&nbsp;&nbsp; };
<br>
</blockquote>
<br>
<br>
Ultimately, what I want to do in the Command is load another resource
containing all the children to be inserted at this point and copy/paste
them into model instead of just creating the new child (theres a couple
other tasks, but thats the primary activity). I'd like to maintain one
"undo" step, so that the user can remove the entire modification done
by the Wizard in one undo Command if they decide they didn't like what
it did.
<br>
<br>
-Mark
<br>
<br>
Ed Merks wrote:
<br>
<br>
<blockquote type="cite">Mark,
<br>
<br>
It may be possible for the wizard to use its information just to create
"regular" commands.&nbsp; But if you need/want to use specialized commands,
it's best to try to reuse the CommandParameter without overriding it by
encoding your additional information as part of the value or the
collection (kind of like the way the new child descriptor is passed as
the value of the command parameter).&nbsp; If necessary/desirable, you can
always create a new command class that's recognized directly
ItemProviderAdapter.createCommand...
<br>
<br>
<br>
Mark Diggory wrote:
<br>
<br>
<blockquote type="cite">My more specific question is actually how
to best pass information gathered in a Wizard or dialog into the custom
Command I've created for that feature. One thought I have is to somehow
override the CommandParameter to include this information such that the
Command can pick it out and use it. Is this logical?
<br>
<br>
-Mark
<br>
<br>
Ed Merks wrote:
<br>
<br>
<blockquote type="cite">Mark,
<br>
<br>
The menus and actions are constructed in the generated
ActionBarContributor, so that would be the place to specialize the
behavior to do additional actions.
<br>
<br>
<br>
Mark Diggory wrote:
<br>
<br>
<blockquote type="cite">So I've figured out how to override
Commands in the ItemProviders so that I can perform further tasks when
I create a child. I would like to continue to maintain separation
between the edit and edit.ui layers. How can I override the Actions in
these Child/Sibling menus so that they do other tasks like open a
wizard or file dialog prior to creating the Child/Sibling so that I can
gather input used to configure the Child/Sibling?
<br>
<br>
-thanks,
<br>
Mark
<br>
</blockquote>
<br>
<br>
<br>
<br>
<br>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------010800020307040101010102--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Overidding Action in Child or Sibling Menus [message #394141 is a reply to message #394123] Tue, 05 July 2005 15:39 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6690
Registered: July 2009
Senior Member
Ed Merks schrieb:
> Eike,
>
> I imagine it would involve overriding ResourceItemProvider something
> like this:
>
> public Collection getNewChildDescriptors(Object object,
> EditingDomain editingDomain, Object sibling)
> {
> Collection newChildDescriptors = new ArrayList();
> collectNewChildDescriptors(newChildDescriptors, object);
> return newChildDescriptors;
> }
>
> protected void collectNewChildDescriptors(Collection
> newChildDescriptors, Object object)
> {
> //super.collectNewChildDescriptors(newChildDescriptors, object);
>
> newChildDescriptors.add
> (createChildParameter
> (new Integer(Resource.RESOURCE__CONTENTS),
> EcoreFactory.eINSTANCE.createEObject()));
> }
>
> If there are change we should make in the framework to make this easier,
> let us know.

Thanks Ed. I'll try it tomorrow and come back with comments ;-)

/Eike


>
>
> Eike Stepper wrote:
>
>> hi mark,
>>
>> have you succeeded with your action that opens a dialog, creates and
>> links a resource for children?
>> i'd be very interested in your solution. would you mind sharing it?!
>>
>> cheers
>> /eike
>>
>>
>>
>> Mark Diggory schrieb:
>>
>>> I've started to do something like this, I have the following in my
>>> ActionBarContributor:
>>>
>>>> protected Collection generateCreateChildActions(Collection
>>>> descriptors, ISelection selection) {
>>>> Collection actions = new ArrayList();
>>>> if (descriptors != null) {
>>>> for (Iterator i = descriptors.iterator(); i.hasNext(); ) {
>>>> CommandParameter o = (CommandParameter)i.next();
>>>> if(o.getValue() instanceof
>>>> FeatureMap.Entry && ((FeatureMap.Entry)o.getValue()).getValue()
>>>> instanceof SurveyType){
>>>> actions.add(new
>>>> CreateSurveyChildAction(activeEditorPart, selection, o));
>>>> } else if(o.getValue() instanceof FeatureMap.Entry
>>>> && ((FeatureMap.Entry)o.getValue()).getValue() instanceof CensusType){
>>>> actions.add(new
>>>> CreateSurveyChildAction(activeEditorPart, selection, o));
>>>> } else {
>>>> actions.add(new
>>>> CreateChildAction(activeEditorPart, selection, o));
>>>> } }
>>>> }
>>>> return actions;
>>>> }
>>>
>>>
>>>
>>> And a separate CreateSurveyChildAction class in which I will place
>>> the wizard. In my "OutlineItemProvider" I'm overriding the
>>> createChild method to insert a custom command like so:
>>>
>>>> /* (non-Javadoc)
>>>> * @see
>>>> org.eclipse.emf.edit.provider.ItemProviderAdapter#createCrea teChildCommand(org.eclipse.emf.edit.domain.EditingDomain,
>>>> org.eclipse.emf.ecore.EObject,
>>>> org.eclipse.emf.ecore.EStructuralFeature, java.lang.Object, int,
>>>> java.util.Collection)
>>>> */
>>>> protected Command createCreateChildCommand(EditingDomain domain,
>>>> EObject owner, EStructuralFeature feature, Object value,
>>>> int index,
>>>> Collection collection) {
>>>>
>>>> if(value instanceof FeatureMap.Entry &&
>>>> ((FeatureMap.Entry)value).getValue() instanceof SurveyType){
>>>> return new
>>>> TestCommand(super.createCreateChildCommand(domain, owner, feature,
>>>> value,index, collection));
>>>> } else if(value instanceof FeatureMap.Entry &&
>>>> ((FeatureMap.Entry)value).getValue() instanceof CensusType){
>>>> return new
>>>> TestCommand(super.createCreateChildCommand(domain, owner, feature,
>>>> value,index, collection));
>>>> }
>>>> return super.createCreateChildCommand(domain, owner,
>>>> feature, value,index, collection);
>>>> }
>>>> class TestCommand extends CommandWrapper implements
>>>> CommandActionDelegate{
>>>> public Logger log = Logger.getLogger(TestCommand.class);
>>>> public TestCommand(Command someOtherCommand){
>>>> super(someOtherCommand);
>>>> }
>>>> public void execute(){
>>>> log.debug("Executing Command");
>>>> super.execute();
>>>> //doSomethingAfterExecution();
>>>> }
>>>> public Collection getResult(){
>>>> return super.getResult();
>>>> }
>>>>
>>>> /* (non-Javadoc)
>>>> * @see
>>>> org.eclipse.emf.edit.command.CommandActionDelegate#getImage( )
>>>> */
>>>> public Object getImage() {
>>>> return
>>>> ((CommandActionDelegate)super.command).getImage();
>>>> }
>>>>
>>>> /* (non-Javadoc)
>>>> * @see
>>>> org.eclipse.emf.edit.command.CommandActionDelegate#getText()
>>>> */
>>>> public String getText() {
>>>> return
>>>> ((CommandActionDelegate)super.command).getText();
>>>> }
>>>>
>>>> /* (non-Javadoc)
>>>> * @see
>>>> org.eclipse.emf.edit.command.CommandActionDelegate#getToolTi pText()
>>>> */
>>>> public String getToolTipText() {
>>>> return
>>>> ((CommandActionDelegate)super.command).getToolTipText();
>>>> }
>>>> };
>>>
>>>
>>>
>>> Ultimately, what I want to do in the Command is load another resource
>>> containing all the children to be inserted at this point and
>>> copy/paste them into model instead of just creating the new child
>>> (theres a couple other tasks, but thats the primary activity). I'd
>>> like to maintain one "undo" step, so that the user can remove the
>>> entire modification done by the Wizard in one undo Command if they
>>> decide they didn't like what it did.
>>>
>>> -Mark
>>>
>>> Ed Merks wrote:
>>>
>>>> Mark,
>>>>
>>>> It may be possible for the wizard to use its information just to
>>>> create "regular" commands. But if you need/want to use specialized
>>>> commands, it's best to try to reuse the CommandParameter without
>>>> overriding it by encoding your additional information as part of the
>>>> value or the collection (kind of like the way the new child
>>>> descriptor is passed as the value of the command parameter). If
>>>> necessary/desirable, you can always create a new command class
>>>> that's recognized directly ItemProviderAdapter.createCommand...
>>>>
>>>>
>>>> Mark Diggory wrote:
>>>>
>>>>> My more specific question is actually how to best pass information
>>>>> gathered in a Wizard or dialog into the custom Command I've created
>>>>> for that feature. One thought I have is to somehow override the
>>>>> CommandParameter to include this information such that the Command
>>>>> can pick it out and use it. Is this logical?
>>>>>
>>>>> -Mark
>>>>>
>>>>> Ed Merks wrote:
>>>>>
>>>>>> Mark,
>>>>>>
>>>>>> The menus and actions are constructed in the generated
>>>>>> ActionBarContributor, so that would be the place to specialize the
>>>>>> behavior to do additional actions.
>>>>>>
>>>>>>
>>>>>> Mark Diggory wrote:
>>>>>>
>>>>>>> So I've figured out how to override Commands in the ItemProviders
>>>>>>> so that I can perform further tasks when I create a child. I
>>>>>>> would like to continue to maintain separation between the edit
>>>>>>> and edit.ui layers. How can I override the Actions in these
>>>>>>> Child/Sibling menus so that they do other tasks like open a
>>>>>>> wizard or file dialog prior to creating the Child/Sibling so that
>>>>>>> I can gather input used to configure the Child/Sibling?
>>>>>>>
>>>>>>> -thanks,
>>>>>>> Mark
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>


Previous Topic:[newbie] what is the use of uml2 providers?
Next Topic:XSDEcoreBuilder: metaObjectID == -1 for non XML-namespace typedefinitions
Goto Forum:
  


Current Time: Wed Sep 25 23:45:50 GMT 2024

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

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

Back to the top