Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Displaying and Editing Properties
Displaying and Editing Properties [message #75726] Wed, 08 November 2006 06:34 Go to next message
Eclipse UserFriend
Hi,

I've been trying to get a SWT pop up window for the properties of my
editor to work for some time. I want to be able to display AND edit the
properties of a node from a SWT window from double clicking on the node.

So far I can double click on the node, which then shows a SWT dialogue.

Double-click works from the nodes EditPart.java file, calling a new Edit
Policy called OpenEditorEditPolicy() which extends OpenEditPolicy :

protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.OPEN_ROLE, new
OpenEditorEditPolicy());
}


The code for OpenEditorPolicy is below, what I think I really need are the
set() and get() functions for the node that is the target(???). So if the
nodes are called A and has properties X and Y, I want ot be able to
display in SWT with A.getX() and change with A.setX(new_value_of_X) or
something that will achieve this result anyway.

I used the read_out/2 to check what is going on, I can see back the
logical address, etc but it's not what I need.

Been trying to get this to work for some time. Please help.

Thanks





public class OpenEditorEditPolicy extends OpenEditPolicy {
protected Command getOpenCommand(Request request) {
EditPart targetEditPart = getTargetEditPart(request);


if (targetEditPart instanceof IGraphicalEditPart) {
IGraphicalEditPart editPart = (IGraphicalEditPart) targetEditPart;
View view = editPart.getNotationView();
if (view != null) {
EObject element = ViewUtil.resolveSemanticElement(view);

String read_out = element.toString();

String read_out2 = view.toString();

/* SWT STUFF GOES IN HERE AND WORKS FINE*/


}
}

return null;
}
}
Re: Displaying and Editing Properties [message #76047 is a reply to message #75726] Wed, 08 November 2006 17:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vcciubot.uwaterloo.ca

Here's an example of writing to the model:

Given the selected edit part, cast it to a IGraphicalEditPart and use
resolveSemanticElement() to retrieve the model element.

AbstractTransactionalCommand createCommand = new CreateAbstractBlockCommand((Block) parentBlock, childrenBlock, diagramID);
try {
OperationHistoryFactory.getOperationHistory().execute(create Command, monitor, null);
} catch (ExecutionException e){
//ignore
}

Your command must subclass AbstractTransactionalCommand, here's my
example. Do your manipulation of the model in doExecuteWithResult().

public class CreateAbstractBlockCommand extends AbstractTransactionalCommand {

private List blocks;

private Block parent;

private String diagramID;

private static String label = "Create Abstract Command";

public CreateAbstractBlockCommand(Block parent, List blocks,
String diagramID) {
super(TransactionUtil.getEditingDomain(parent), label, Collections
.singletonList(WorkspaceSynchronizer
.getFile(parent.eResource())));
this.blocks = blocks;
this.parent = parent;
this.diagramID = diagramID;
}

/**
* @return The two port ends of the connection
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
IAdaptable info) throws ExecutionException {

AbstractBlock absBlock = B2CreationCommandUtil.createAbstractBlock(
parent, monitor);
absBlock.setDiagramID(diagramID);
absBlock.getConcreteBlocks().addAll(blocks);
createAbstractConnections(absBlock);

return CommandResult.newOKCommandResult(absBlock);

}
.....

}



On Wed, 08 Nov 2006 11:34:15 +0000, Gaff wrote:

> Hi,
>
> I've been trying to get a SWT pop up window for the properties of my
> editor to work for some time. I want to be able to display AND edit the
> properties of a node from a SWT window from double clicking on the node.
>
> So far I can double click on the node, which then shows a SWT dialogue.
>
> Double-click works from the nodes EditPart.java file, calling a new Edit
> Policy called OpenEditorEditPolicy() which extends OpenEditPolicy :
>
> protected void createDefaultEditPolicies() {
> super.createDefaultEditPolicies();
> installEditPolicy(EditPolicyRoles.OPEN_ROLE, new
> OpenEditorEditPolicy());
> }
>
>
> The code for OpenEditorPolicy is below, what I think I really need are the
> set() and get() functions for the node that is the target(???). So if the
> nodes are called A and has properties X and Y, I want ot be able to
> display in SWT with A.getX() and change with A.setX(new_value_of_X) or
> something that will achieve this result anyway.
>
> I used the read_out/2 to check what is going on, I can see back the
> logical address, etc but it's not what I need.
>
> Been trying to get this to work for some time. Please help.
>
> Thanks
>
>
>
>
>
> public class OpenEditorEditPolicy extends OpenEditPolicy {
> protected Command getOpenCommand(Request request) {
> EditPart targetEditPart = getTargetEditPart(request);
>
>
> if (targetEditPart instanceof IGraphicalEditPart) {
> IGraphicalEditPart editPart = (IGraphicalEditPart) targetEditPart;
> View view = editPart.getNotationView();
> if (view != null) {
> EObject element = ViewUtil.resolveSemanticElement(view);
>
> String read_out = element.toString();
>
> String read_out2 = view.toString();
>
> /* SWT STUFF GOES IN HERE AND WORKS FINE*/
>
>
> }
> }
>
> return null;
> }
> }
Re: Displaying and Editing Properties [message #78373 is a reply to message #76047] Fri, 17 November 2006 06:12 Go to previous message
Eclipse UserFriend
Hey,

So from the the extended OpenEditPolicy you retrive the model element and
then create an CreateAbstractBlockCommand which extends the
AbstractTransactionalCommand. With you on what's going on, but can't get
it to work.

I think I'm a bit lost with CreateAbstractBlockCommand.

You create a CreateAbstractBlockCommand object, which adds to the
AbstractTransactionalCommand instance variables that you want to modify,
so a model element of type Block and a String that will be its property
and a List, that I'm guessing are associated model elements.

For the constructor, you use the super of CreateAbstractBlockCommand to
specify the element you want to modify ->
TransactionUtil.getEditingDomain(parent), a label and the IFiles ->
Collections.singletonList(WorkspaceSynchronizer.getFile(pare nt.eResource())).

So when an object is created it includes the element to be modified.

After this the doExecuteWithResult is executed which then alters the model
element that is part of the CreateAbstractBlockCommand object (how does
this get called? does it happen automatically when the object is created?
then just return the altered model element or is it that you call an
execute on the AbstractTransactionalCommand object that invokes the
mehtod?)



I've tried implementing it, where Aaaa is the model element and aaainfo is
a property of Aaaa. The constructor seems to be okay, not so sure about
the CommandResult part.

Below that is the extended OpenEditPolicy that calls creates the
AbstractTransactionalCommand object. Problem I'm having with that is the
IProgressMonitor object may not have been initalized? I don't really
understand why I need to use this?

Questions:

1. Is the doExecuteWithResult part correct? Will it change the property of
the Aaaa oobject model?

2. Am I calling this method correctly?

3. How do I initalise the IProgressMonitor object? (and why do i need it?)

Your help would be greatly appreciated, Thanks


------------------------------------------------------------ ------------------

public class CreateAbstractBlockCommand extends
AbstractTransactionalCommand {

// AbstractTransactionalCommand is an abstract superclass for GMF that
modifies EMF model resources


//private List blocks; // what is the role of list Blocks in your
program, guessing that each of your nodes has a list of 'blocks'
associated with the element

private Aaaa parent; //the model element Aaaa that I want to modify

private String aaainfo; //the model element property aaainfo

private static String label = "Create Abstract Command";

public CreateAbstractBlockCommand(Aaaa parent, String aaaInfo) {



//TransactionUtil Static utilities for dealing with EMF elements and
resources in a transactional editing domain
//getEditingDomain Obtains the transactional editing domain that manages
the specified element

//Initializes me with the editing domain in which I am making model
changes, a label, and a list of IFiles that I anticipate modifying when I
am executed, undone or redone
super(TransactionUtil.getEditingDomain(parent), label,
Collections.singletonList(WorkspaceSynchronizer.getFile(pare nt.eResource())));

//this.blocks = blocks;
this.parent = parent;
this.aaainfo = aaaInfo;
}







//executes the command; which will get the child and the containaer from
the IAdaptable and then insert the child at the given index in the
containers child list.
protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
IAdaptable info) throws ExecutionException {

// manipulation of the model

parent.setAaaaInfo(aaainfo);

return CommandResult.newOKCommandResult(parent);

}
}

------------------------------------------------------------ ------------------
Previous Topic:how to include a figure inside existing figure?
Next Topic:Can not view .ecore_diagram in editor : problem is jdk 5.0 / Linux
Goto Forum:
  


Current Time: Thu Jul 17 21:59:06 EDT 2025

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

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

Back to the top