[SOLVED!!!]I have a question on DirectEditingFeature [message #1731587] |
Sat, 07 May 2016 06:17  |
Eclipse User |
|
|
|
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 17:02] by Moderator
|
|
|
Re: I have a question on DirectEditingFeature [message #1731603 is a reply to message #1731587] |
Sat, 07 May 2016 12:53  |
Eclipse User |
|
|
|
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!
Regards
Raffaele
[Updated on: Sat, 07 May 2016 17:01] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04034 seconds