editPart in an IAction? [message #154390] |
Tue, 09 October 2007 10:18  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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
>
|
|
|
|
|
Help with extension pt for pop-up menu? [message #154959 is a reply to message #154390] |
Fri, 12 October 2007 06:13  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03883 seconds