Howto implement a custom tool? [message #225333] |
Thu, 09 April 2009 19:12 |
Andreas Schoeneck Messages: 22 Registered: July 2009 |
Junior Member |
|
|
This is a multi-part message in MIME format.
--------------080306030503010605060603
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit
Hi, once again I need your help
My problem is that I want to make a custom tool that is capable of
marking diagram elements, that means: Select the tool -> click on a
diagram element -> diagram element gets different color or somewhat, of
course, in the background there's a model change.
What I've done so far is:
- Added the corresponding entry to the tooling definition.
- Created Tool, Request, EditPolicy, Command classes
- registered the EditPolicies through editpolicyProvider
- tried and tried and tried till I'm tired
I just don't know where the problem is or how to accomplish this.
You will find the mentioned classes attached.
I found out that the policy is called several times, but never when
mouse is over or clicked with my custom tool.
What I want the tool to do is change a model's property (addiction). The
edit part handles this change and changes its face automatically ( as
described in GMF FAQ).
I appreciate any little hint.
Regards
Andy
--------------080306030503010605060603
Content-Type: text/plain;
name="MarkCommand.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="MarkCommand.java"
package emftigeriruleeditor.diagram.custom;
import org.eclipse.gef.commands.Command;
public class MarkCommand extends Command {
MarkRequest request;
public MarkCommand(MarkRequest request) {
super();
this.request = request;
}
@Override
public void execute() {
System.out.println("Execute");
}
}
--------------080306030503010605060603
Content-Type: text/plain;
name="MarkingEditPolicy.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="MarkingEditPolicy.java"
package emftigeriruleeditor.diagram.custom;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.AbstractEditPolicy;
import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.GraphicalNod eEditPolicy;
public class MarkingEditPolicy extends GraphicalEditPolicy {
@Override
public Command getCommand(Request request) {
if (request.getType().equals(MarkRequest.MARK_TYPE)) {
return new MarkCommand((MarkRequest) request);
}
return super.getCommand(request);
}
public final static String ID = "Marking EditPolicy";
public MarkingEditPolicy() {
}
}
--------------080306030503010605060603
Content-Type: text/plain;
name="MarkingTool.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="MarkingTool.java"
package emftigeriruleeditor.diagram.custom;
import org.eclipse.draw2d.Cursors;
import org.eclipse.gef.Request;
import org.eclipse.gef.tools.TargetingTool;
public class MarkingTool extends TargetingTool {
public MarkingTool() {
setDisabledCursor(Cursors.NO);
setDefaultCursor(Cursors.HAND);
}
@Override
protected String getCommandName() {
return MarkRequest.MARK_TYPE;
}
@Override
protected Request createTargetRequest() {
MarkRequest request = new MarkRequest();
request.setType(getCommandName());
return request;
}
@Override
protected void updateTargetRequest() {
MarkRequest request = (MarkRequest)getTargetRequest();
request.setLocation(getLocation());
}
}
--------------080306030503010605060603
Content-Type: text/plain;
name="MarkRequest.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="MarkRequest.java"
package emftigeriruleeditor.diagram.custom;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.requests.LocationRequest;
import org.eclipse.gef.requests.TargetRequest;
import emftigeriruleeditor.ElementAddictionType;
public class MarkRequest extends LocationRequest implements TargetRequest {
public static final String MARK_TYPE = "Mark as Blah Command";
private ElementAddictionType addictionType;
private EditPart part;
public ElementAddictionType getAddictionType() {
return addictionType;
}
public void setAddictionType(ElementAddictionType addictionType) {
this.addictionType = addictionType;
}
@Override
public void setTargetEditPart(EditPart part) {
this.part = part;
}
}
--------------080306030503010605060603
Content-Type: text/plain;
name="EditPolicyProvider.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="EditPolicyProvider.java"
package emftigeriruleeditor.diagram.custom;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.common.core.service.IProviderChangeL istener;
import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.Creat eEditPoliciesOperation;
import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEdit PolicyProvider;
import emftigeriruleeditor.diagram.edit.parts.EdgeEditPart;
import emftigeriruleeditor.diagram.edit.parts.NodeEditPart;
public class EditPolicyProvider implements IEditPolicyProvider {
@Override
public void createEditPolicies(EditPart editPart) {
editPart.installEditPolicy(MarkRequest.MARK_TYPE,
new MarkingEditPolicy());
}
@Override
public void addProviderChangeListener(IProviderChangeListener listener) {
}
@Override
public boolean provides(IOperation operation) {
if (operation instanceof CreateEditPoliciesOperation) {
EditPart editPart = ((CreateEditPoliciesOperation) operation)
.getEditPart();
if (editPart instanceof NodeEditPart
|| editPart instanceof EdgeEditPart)
return true;
}
return false;
}
@Override
public void removeProviderChangeListener(IProviderChangeListener listener) {
}
}
--------------080306030503010605060603--
|
|
|
|
Powered by
FUDForum. Page generated in 0.02642 seconds