Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » [SOLVED!!!]I have a question on DirectEditingFeature
[SOLVED!!!]I have a question on DirectEditingFeature [message #1731587] Sat, 07 May 2016 10:17 Go to next message
raffaele bologna is currently offline raffaele bolognaFriend
Messages: 5
Registered: November 2014
Junior Member
Hi,
I have a question.
How can I modify the name of an business object in a diagram only via code using DirectEditFeature ?

Example:

public class MyDirectEdit {

String newName ="NEW_NAME";

IFile file = root.getIProject().getFile("src/diagrams/example.diagram");
ResourceSetImpl res = new ResourceSetImpl();
Diagram diagram =GraphitiUiInternal.getEmfService().getDiagramFromFile(file,res);
String DTP = "test.diagram.TESTDiagramTypeProvider"
IDiagramTypeProviderdtp=GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram,DTP);

Object myObject = getObject();
AddContext addContext = new AddContext();
addContext.setNewObject(myObject);
ContainerShape containerShape = (ContainerShape)dtp.getFeatureProvider().addIfPossible(addContext);

DirectEditingContext editContext = new DirectEditingContext (containerShape,containerShape.getGraphicsAlgorithm());
dtp.getFeatureProvider().getDirectEditingFeature(editContext).setValue(newName,editContext);

}

This code is correct! But unfortunately, when you open the editor the object name has not changed!
Any solution?

Regards
Raffaele



[Updated on: Sat, 07 May 2016 21:02]

Report message to a moderator

Re: I have a question on DirectEditingFeature [message #1731603 is a reply to message #1731587] Sat, 07 May 2016 16:53 Go to previous message
raffaele bologna is currently offline raffaele bolognaFriend
Messages: 5
Registered: November 2014
Junior Member
Solution.
I explain my solution with an example
I have two diagrams, A and B, with different business object. I want that when I edit a new object name on diagram A, the diagram B change the business object with the same name.

In the diagram A I write the class:
public class MyDirectEdit {

String newName ="NEW_NAME";

IFile file = root.getIProject().getFile("src/diagrams/example.diagram");
ResourceSetImpl res = new ResourceSetImpl();
Diagram diagram =GraphitiUiInternal.getEmfService().getDiagramFromFile(file,res);
String DTP = "test.diagram.TESTDiagramTypeProvider"
IDiagramTypeProvider dtp=GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram,DTP);

String newObject = "oldname/newName/.editClass";
AddContext addContext = new AddContext();
addContext.setNewObject(oldNameObject);
ContainerShape containerShape = (ContainerShape)dtp.getFeatureProvider().addIfPossible(addContext);

EObject bo = agentshape.getLink().getBusinessObjects().get(0);

saveResource(bo, diagram);

}

In the diagram B I create a special class AddFindShapeFeature where addContext.getNewObject is a String type:

// diagram B featureProvider
public class DiagramB_FeatureProvider extends DefaultFeatureProvider{
public IAddFeature getAddFeature(IAddContext context) {
if(context.getNewObject() instanceof String){
String string = (String) context.getNewObject();
if(string.endsWith(".editClass")){
return new AddMyEditFeature(this);
}
}
}

//This class find the containerShape of the business object on diagram B
public class AddFindShapeFeature extends AbstractAddShapeFeature {

@Override
public boolean canAdd(IAddContext context) {

if(context.getNewObject() instanceof String )
return true;

return false;
}

public PictogramElement add(IAddContext context) {

String string = (String) context.getNewObject();

// string parser
String [] text = string.split(".editClass");
String [] info = text[0].split("/");


String oldName = info[0];
String newName = info [1];

ContainerShape shapeEClass = getShape(oldName);
EClass eClass = (EClass) getBusinessObjectForPictogramElement(agentShape);
eClass.setName(newName);

return shapeEClass;
}

}

At the end, in the diagram A I use commands:
ContainerShape containerShape =(ContainerShape)dtp.getFeatureProvider().addIfPossible(addContext);
EObject bo = agentshape.getLink().getBusinessObjects().get(0);
saveResource(bo, diagram);

When I open the editor of diagram B ,the object name is changed!!!
This topic: https://www.eclipse.org/forums/index.php/t/664647/ helped me.
I'm sorry if my description is confused. I hope it is useful! Smile

Regards
Raffaele

[Updated on: Sat, 07 May 2016 21:01]

Report message to a moderator

Previous Topic:Rearranging shapes according to EMF model
Next Topic:What is the best approach to implement a palette with a tree view
Goto Forum:
  


Current Time: Wed Apr 24 18:17:58 GMT 2024

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

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

Back to the top