[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.modeling.gmf] Re: Displaying and Editing Properties
|
- From: Vlad Ciubotariu <vcciubot@xxxxxxxxxxxx>
- Date: Wed, 08 Nov 2006 17:36:46 -0500
- Newsgroups: eclipse.modeling.gmf
- Organization: EclipseCorner
- User-agent: Pan/0.14.2.91 (As She Crawled Across the Table (Debian GNU/Linux))
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(createCommand, 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;
> }
> }