Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » editPart in an IAction?
editPart in an IAction? [message #154390] Tue, 09 October 2007 10:18 Go to next message
Eclipse UserFriend
Hi All,

Quick question about editPart in an IAction. I want to be able to change
the color of nodes through an IAction and have found a solution here:

http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg02061.html

which references editPart.

I don't understand where this comes from. I've tried to get it with

EditPart targetEditPart = getTargetEditPart(request);
if (targetEditPart instanceof IGraphicalEditPart == false)
return null;

IGraphicalEditPart editPart = (IGraphicalEditPart) targetEditPart;
EObject modelElement = editPart.resolveSemanticElement();



but this only works with Command getOpenCommand(Request request)

As I understand it getOpenCommand with request is only used in
EditPolicies?


Two other questions with regards this IAction:

1) Can this be applied to multiple Diagram elements (of same and different
type)

2) Can something similar be used to alter diagram elements properties in
IAction? - I can do this with an EditPolicy so can EditPolicies be called
from IAction


Thanks for your help,

Gaff
Re: editPart in an IAction? [message #154415 is a reply to message #154390] Tue, 09 October 2007 11:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

So you basically want the edit part of the selected element?

This can be done with:

private xxxEditPart selectedElement;

public void run(IAction action) {

//do whatever you want with the EditPart

Remember to set correct selectionChanged() method.



Gaff wrote:
> Hi All,
>
> Quick question about editPart in an IAction. I want to be able to change
> the color of nodes through an IAction and have found a solution here:
>
> http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg02061.html
>
> which references editPart.
>
> I don't understand where this comes from. I've tried to get it with
> EditPart targetEditPart = getTargetEditPart(request); if
> (targetEditPart instanceof IGraphicalEditPart == false)
> return null;
>
> IGraphicalEditPart editPart = (IGraphicalEditPart) targetEditPart;
> EObject modelElement = editPart.resolveSemanticElement();
>
>
>
> but this only works with Command getOpenCommand(Request request)
>
> As I understand it getOpenCommand with request is only used in
> EditPolicies?
>
>
> Two other questions with regards this IAction:
>
> 1) Can this be applied to multiple Diagram elements (of same and
> different type)
>
> 2) Can something similar be used to alter diagram elements properties in
> IAction? - I can do this with an EditPolicy so can EditPolicies be
> called from IAction
>
> Thanks for your help,
>
> Gaff
>
Re: editPart in an IAction? [message #154448 is a reply to message #154415] Tue, 09 October 2007 12:34 Go to previous messageGo to next message
Eclipse UserFriend
Okay I see, I thought editPart needed to be assigned a value from the
Diagram.

Thanks Tomas

Unfortunately the IAction is clear of errors but doesn't work. Not sure
why, all I get is "the chosen operation is not currently available"

Code is same as from original post:

http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg02061.html

So my code looks like (being called from a drop down menu):

import org.eclipse.jface.action.IAction;
import
org.eclipse.gmf.runtime.diagram.ui.requests.ChangePropertyVa lueRequest;
import org.eclipse.gmf.runtime.common.core.util.StringStatics;
import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
import org.eclipse.gmf.runtime.diagram.ui.figures.DiagramColorConst ants;
import org.eclipse.gef.commands.Command;
import com.test.myapp.diagram.edit.parts.NodeOneEditPart;
import org.eclipse.emf.workspace.AbstractEMFOperation;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.gmf.runtime.diagram.ui.internal.properties.Prope rties;

public class TestAction {

private NodeOneEditPart editPart;


public void run(IAction action) {



ChangePropertyValueRequest req = new ChangePropertyValueRequest(
StringStatics.BLANK,Properties.ID_LINECOLOR,
FigureUtilities.colorToInteger(DiagramColorConstants.red));


final Command cmd = editPart.getCommand(req);


AbstractEMFOperation operation = new
AbstractEMFOperation(((IGraphicalEditPart) editPart).getEditingDomain(),
StringStatics.BLANK, null) {
protected IStatus doExecute(IProgressMonitor monitor, IAdaptable
info)throws ExecutionException {
cmd.execute();
return Status.OK_STATUS;
}
};

try {

operation.execute(new NullProgressMonitor(), null);
} catch (ExecutionException e) {
// nothing to do here
}



}



}


Any ideas?

Thanks for your help,


Gaff
Re: editPart in an IAction? [message #154466 is a reply to message #154448] Tue, 09 October 2007 12:57 Go to previous messageGo to next message
Eclipse UserFriend
Hi Gaff,

The "the chosen operation is not currently available" message normally
means there are problems with action declaration in plugin.xml. Actions
registered via plugin.xml must implement certain interfaces (depending
on how exactly they are registered), but PDE does not give you enough
hints...

Best regards,
Boris


Gaff wrote:
> Okay I see, I thought editPart needed to be assigned a value from the
> Diagram.
>
> Thanks Tomas
>
> Unfortunately the IAction is clear of errors but doesn't work. Not sure
> why, all I get is "the chosen operation is not currently available"
>
> Code is same as from original post:
>
> http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg02061.html
>
> So my code looks like (being called from a drop down menu):
>
> import org.eclipse.jface.action.IAction;
> import
> org.eclipse.gmf.runtime.diagram.ui.requests.ChangePropertyVa lueRequest;
> import org.eclipse.gmf.runtime.common.core.util.StringStatics;
> import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
> import org.eclipse.gmf.runtime.diagram.ui.figures.DiagramColorConst ants;
> import org.eclipse.gef.commands.Command;
> import com.test.myapp.diagram.edit.parts.NodeOneEditPart;
> import org.eclipse.emf.workspace.AbstractEMFOperation;
> import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art;
> import org.eclipse.core.runtime.NullProgressMonitor;
> import org.eclipse.core.commands.ExecutionException;
> import org.eclipse.core.runtime.IAdaptable;
> import org.eclipse.core.runtime.IProgressMonitor;
> import org.eclipse.core.runtime.IStatus;
> import org.eclipse.core.runtime.Status;
> import org.eclipse.gmf.runtime.diagram.ui.internal.properties.Prope rties;
>
> public class TestAction {
>
> private NodeOneEditPart editPart;
>
>
> public void run(IAction action) {
>
>
>
> ChangePropertyValueRequest req = new ChangePropertyValueRequest(
> StringStatics.BLANK,Properties.ID_LINECOLOR,
> FigureUtilities.colorToInteger(DiagramColorConstants.red));
>
>
> final Command cmd = editPart.getCommand(req);
>
> AbstractEMFOperation operation = new
> AbstractEMFOperation(((IGraphicalEditPart) editPart).getEditingDomain(),
> StringStatics.BLANK, null) {
> protected IStatus doExecute(IProgressMonitor monitor,
> IAdaptable info)throws ExecutionException {
> cmd.execute();
> return Status.OK_STATUS;
> }
> };
> try {
> operation.execute(new
> NullProgressMonitor(), null);
> } catch (ExecutionException e) {
> // nothing to do here
> }
>
>
>
> }
>
>
>
> }
>
>
> Any ideas?
>
> Thanks for your help,
>
>
> Gaff
>
Re: editPart in an IAction? [message #154474 is a reply to message #154466] Tue, 09 October 2007 13:38 Go to previous messageGo to next message
Eclipse UserFriend
Okay, so there's possibly something wrong with my plugin.xml?

I thought I had everything in bu possibly not are there some fields in
need to fill in.

As far as I thought it worked:
1. Set up extension pt so have extra menu options (for certain nodes)
2. Associate IAction that will carry out operation.


I'd really appreciate your help.

Thanks,

Gaff



<extension point="org.eclipse.ui.popupMenus">
<?gmfgen generated="false"?>

...

<objectContribution
adaptable="false"
id="TestOne"

objectClass="com.test.myapp.diagram.edit.parts.NodeOneEditPart ">
<menu
id="MyAppInsert"
label="&amp;Color"
path="additions">
<separator name="group1"/>
</menu>
<action
class="com.test.myapp.diagram.part.MyAppTestAction"
id="TestTwo"
label="&amp;Red"
menubarPath="MyAppInsert/group1">
</action>
</objectContribution>
</extension>
Re: editPart in an IAction? [message #154638 is a reply to message #154474] Wed, 10 October 2007 06:11 Go to previous messageGo to next message
Eclipse UserFriend
Hi again,

I've tried a different approach to try and figure out if it's my plugin or
my IAction that's the problem. I tried adding an extension point so as to
have the same option in the menu bar hoping I could get the action to work
from there. I tested the menu bar with another action (just a simple swt
pop-up) and it worked. I then switched to the color change action but
again got the same result.


Would anyone be able to help me with this?

Thanks for your help,

Gaff
Help with extension pt for pop-up menu? [message #154959 is a reply to message #154390] Fri, 12 October 2007 06:13 Go to previous message
Eclipse UserFriend
Would someone be able to help me out with this?


I'm guessing it's a problem with extension pt.

I have the pop-up menu on the node coming up but the action isn't being
performed.

Possibly I'm missing something or have something wrong? (Basically copied
this from the existing pop up menu that's already there and works)
Have tried this:


<extension point="org.eclipse.ui.popupMenus">
<?gmfgen generated="false"?>

..... <- the CasetoolLoadResourceAction is here and is the object
Contribution I've tried copying to make this work

<objectContribution
adaptable="false"
id=" com.test.myapp.diagram.ui.objectContribution.NodeOneEditPart 2 "
objectClass="com.test.myapp.diagram.edit.parts.NodeOneEditPart ">
<action
class="com.test.myapp.diagram.part.MyappDiagramTestAction"
enablesFor="1"
id="com.test.myapp.diagram.part.NodeOneEditPartActionID"
label="Red"
menubarPath="additions">
</action>
</objectContribution>
</extension>


If anyone could tell me if I'm doing anything wrong?

Does it matter what the id is for the objectContribution? I don't think it
does? (I've set it in a similar to pop up menu that works)
Is the object class right?
What is enables for?


I also realized that this function and extension pt already exists:

Format>Line Color>Red

I've had a look for this but can't find it, presume it's in plugin.xml?

Any help would be appreciated.

Thanks,

Gaff
Previous Topic:Swing componets DND on the Editor
Next Topic:reconciling the gmfgen
Goto Forum:
  


Current Time: Sun May 11 04:18:37 EDT 2025

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

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

Back to the top