Home » Modeling » UML2 Tools » Command for creating Generalization
|
Re: Command for creating Generalization [message #470786 is a reply to message #470785] |
Wed, 16 May 2007 17:55 |
Tatiana Fesenko Messages: 530 Registered: July 2009 |
Senior Member |
|
|
Hi Philippe!
The way links are created is different from the way usual elements are
created. Links contain source and target. That's why the command to create a
link is more complicated than the command to create a node.
Command to create e.g. Generalization link will look like
1.
public Command getCreateGeneralizationCommand() {
// descriptor contains information about semantic features of link
ConnectionViewDescriptor viewDescriptor =
getConnectionViewDescriptor(preferencesHint);
CreateConnectionViewAndElementRequest createViewRequest = new
CreateConnectionViewAndElementRequest(viewDescriptor);
// here we set notation properties - source/target EditParts and location
(is not nessesary)
connectionRequest.setTargetEditPart(sourceEditPart);
connectionRequest.setType(RequestConstants.REQ_CONNECTION_ST ART);
connectionRequest.setLocation(new Point(0, 0));
//
if (sourceEditPart.getCommand(connectionRequest) == null) {
return;
}
connectionRequest.setSourceEditPart(sourceEditPart);
connectionRequest.setTargetEditPart(targetEditPart);
connectionRequest.setType(RequestConstants.REQ_CONNECTION_EN D);
connectionRequest.setLocation(new Point(0, 0));
Command createConnectionCmd = targetEditPart.getCommand(connectionRequest);
return createConnectionCmd;
}
private ConnectionViewAndElementDescriptor
getConnectionViewDescriptor(PreferencesHint preferencesHint) {
String semanticHint = String.valueOf(GeneralizationEditPart.VISUAL_ID);
CreateRelationshipRequest createElementRequest = new
CreateRelationshipRequest(UMLElementTypes.Generalization_400 1);
createElementRequest.setSource(sourceClassifier);
createElementRequest.setTarget(targetClassifier);
ConnectionViewAndElementDescriptor viewDescriptor = new
ConnectionViewAndElementDescriptor(new
CreateElementRequestAdapter(createElementRequest), semanticHint,
preferencesHint);
return viewDescriptor;
}
2.
You also may directly use CreationTool this way ( taken from
org.eclipse.uml2.diagram.statemachine.tests.tools.CreationTo olTest )
getDiagramEditPart().getViewer().setSelection(new
StructuredSelection(sourceEditPart, targetEditPart));
createConnectionByTool(UMLElementTypes.Generalization_4001);
private void createConnectionByTool(IElementType elementType) {
UnspecifiedTypeConnectionTool tool = new
UnspecifiedTypeConnectionTool(Collections.singletonList(elem entType));
tool.setEditDomain((EditDomain)
getDiagramWorkbenchPart().getDiagramEditDomain());
tool.activate();
tool.mouseDoubleClick(createMouseEvent(0, 0),
getDiagramEditPart().getViewer());
tool.deactivate();
}
..
I also could recomment you to have a look at
org.eclipse.uml2.diagram.clazz.edit.commands.ChangeDependenc yTypeCommand or
org.eclipse.uml2.diagram.clazz.part.CreateGeneralizationLink Tool (more
complicated behaviour) classes.
Good luck!
Tatiana.
"Philippe" <philippeweber57@yahoo.fr> wrote in message
news:f2f3cl$57k$1@build.eclipse.org...
> Hi,
>
> I'm still searching the best way to modify a class diagram
> programmatically.
> I made good use of a past reply for creating a class
> List types = Arrays.asList(new IElementType[] {
> UMLElementTypes.Class_3007, UMLElementTypes.Class_2001, //you can
> use only this one for top level classes
> UMLElementTypes.Class_3003, UMLElementTypes.Class_3030, });
> CreateUnspecifiedTypeRequest request = new
> CreateUnspecifiedTypeRequest(elementTypes,
> UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
> Command result = getDiagramEditPart().getCommand(request);
>
> But now I need to create programmatically a Generalization between two
> classes, and I can't find the right way.
>
> Thanks for any help
> Philippe
>
|
|
|
Re: Command for creating Generalization [message #470788 is a reply to message #470786] |
Fri, 18 May 2007 11:21 |
Philippe Messages: 100 Registered: July 2009 |
Senior Member |
|
|
Hi Tatiana,
thanks for the hints, it worked great for me
But I'm a bit disappointed, I though at first that
if I make pure semantic change using UML2 API inside a transaction,
UML2Tools could handle the refresh.
The refresh works just fine for properties modification but the creation
of new element isn't reflected.
So what I exactly want to do is to create a new diagram element to link
it with an existing semantic element (class for example),
can this be integrated in the command I used so far with editpart ?
Many Thanks for the good work
Philippe
Tatiana Fesenko wrote:
> Hi Philippe!
>
> The way links are created is different from the way usual elements are
> created. Links contain source and target. That's why the command to create a
> link is more complicated than the command to create a node.
> Command to create e.g. Generalization link will look like
>
> 1.
> public Command getCreateGeneralizationCommand() {
> // descriptor contains information about semantic features of link
> ConnectionViewDescriptor viewDescriptor =
> getConnectionViewDescriptor(preferencesHint);
> CreateConnectionViewAndElementRequest createViewRequest = new
> CreateConnectionViewAndElementRequest(viewDescriptor);
> // here we set notation properties - source/target EditParts and location
> (is not nessesary)
> connectionRequest.setTargetEditPart(sourceEditPart);
> connectionRequest.setType(RequestConstants.REQ_CONNECTION_ST ART);
> connectionRequest.setLocation(new Point(0, 0));
> //
> if (sourceEditPart.getCommand(connectionRequest) == null) {
> return;
> }
>
> connectionRequest.setSourceEditPart(sourceEditPart);
> connectionRequest.setTargetEditPart(targetEditPart);
> connectionRequest.setType(RequestConstants.REQ_CONNECTION_EN D);
> connectionRequest.setLocation(new Point(0, 0));
>
> Command createConnectionCmd = targetEditPart.getCommand(connectionRequest);
> return createConnectionCmd;
> }
>
> private ConnectionViewAndElementDescriptor
> getConnectionViewDescriptor(PreferencesHint preferencesHint) {
> String semanticHint = String.valueOf(GeneralizationEditPart.VISUAL_ID);
> CreateRelationshipRequest createElementRequest = new
> CreateRelationshipRequest(UMLElementTypes.Generalization_400 1);
> createElementRequest.setSource(sourceClassifier);
> createElementRequest.setTarget(targetClassifier);
> ConnectionViewAndElementDescriptor viewDescriptor = new
> ConnectionViewAndElementDescriptor(new
> CreateElementRequestAdapter(createElementRequest), semanticHint,
> preferencesHint);
> return viewDescriptor;
> }
>
> 2.
> You also may directly use CreationTool this way ( taken from
> org.eclipse.uml2.diagram.statemachine.tests.tools.CreationTo olTest )
>
> getDiagramEditPart().getViewer().setSelection(new
> StructuredSelection(sourceEditPart, targetEditPart));
> createConnectionByTool(UMLElementTypes.Generalization_4001);
>
> private void createConnectionByTool(IElementType elementType) {
> UnspecifiedTypeConnectionTool tool = new
> UnspecifiedTypeConnectionTool(Collections.singletonList(elem entType));
> tool.setEditDomain((EditDomain)
> getDiagramWorkbenchPart().getDiagramEditDomain());
> tool.activate();
> tool.mouseDoubleClick(createMouseEvent(0, 0),
> getDiagramEditPart().getViewer());
> tool.deactivate();
> }
> .
> I also could recomment you to have a look at
> org.eclipse.uml2.diagram.clazz.edit.commands.ChangeDependenc yTypeCommand or
> org.eclipse.uml2.diagram.clazz.part.CreateGeneralizationLink Tool (more
> complicated behaviour) classes.
>
>
> Good luck!
> Tatiana.
>
> "Philippe" <philippeweber57@yahoo.fr> wrote in message
> news:f2f3cl$57k$1@build.eclipse.org...
>> Hi,
>>
>> I'm still searching the best way to modify a class diagram
>> programmatically.
>> I made good use of a past reply for creating a class
>> List types = Arrays.asList(new IElementType[] {
>> UMLElementTypes.Class_3007, UMLElementTypes.Class_2001, //you can
>> use only this one for top level classes
>> UMLElementTypes.Class_3003, UMLElementTypes.Class_3030, });
>> CreateUnspecifiedTypeRequest request = new
>> CreateUnspecifiedTypeRequest(elementTypes,
>> UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
>> Command result = getDiagramEditPart().getCommand(request);
>>
>> But now I need to create programmatically a Generalization between two
>> classes, and I can't find the right way.
>>
>> Thanks for any help
>> Philippe
>>
>
>
|
|
|
Re: Command for creating Generalization [message #470792 is a reply to message #470788] |
Fri, 18 May 2007 17:38 |
Tatiana Fesenko Messages: 530 Registered: July 2009 |
Senior Member |
|
|
Hi Philippe!
Use ViewDescriptor insteadof ViewAndElementDescriptor and CreateViewRequest
insteadof CreateViewAndElementRequest to create diagram presentation of
already existing element .
For example, the following code creates Rectangle notation for existing
org.eclipse.uml2.uml.Interface 'interface1':
String semanticHint = String.valueOf(Interface2EditPart.VISUAL_ID);
ViewDescriptor viewDescriptor =
new ViewDescriptor(new EObjectAdapter(interface1), Node.class,
semanticHint, getPreferencesHint());
CreateViewRequest createViewRequest = new CreateViewRequest(viewDescriptor);
Command result = editPart.getParent().getCommand(createViewRequest);
Best wishes,
Tatiana.
"Philippe" <philippeweber57@yahoo.fr> wrote in message
news:f2k2b8$hi$1@build.eclipse.org...
> Hi Tatiana,
>
> thanks for the hints, it worked great for me
>
> But I'm a bit disappointed, I though at first that
> if I make pure semantic change using UML2 API inside a transaction,
> UML2Tools could handle the refresh.
> The refresh works just fine for properties modification but the creation
> of new element isn't reflected.
> So what I exactly want to do is to create a new diagram element to link it
> with an existing semantic element (class for example),
> can this be integrated in the command I used so far with editpart ?
>
> Many Thanks for the good work
> Philippe
>
> Tatiana Fesenko wrote:
>> Hi Philippe!
>>
>> The way links are created is different from the way usual elements are
>> created. Links contain source and target. That's why the command to
>> create a link is more complicated than the command to create a node.
>> Command to create e.g. Generalization link will look like
>>
>> 1.
>> public Command getCreateGeneralizationCommand() {
>> // descriptor contains information about semantic features of link
>> ConnectionViewDescriptor viewDescriptor =
>> getConnectionViewDescriptor(preferencesHint);
>> CreateConnectionViewAndElementRequest createViewRequest = new
>> CreateConnectionViewAndElementRequest(viewDescriptor);
>> // here we set notation properties - source/target EditParts and location
>> (is not nessesary)
>> connectionRequest.setTargetEditPart(sourceEditPart);
>> connectionRequest.setType(RequestConstants.REQ_CONNECTION_ST ART);
>> connectionRequest.setLocation(new Point(0, 0));
>> //
>> if (sourceEditPart.getCommand(connectionRequest) == null) {
>> return;
>> }
>>
>> connectionRequest.setSourceEditPart(sourceEditPart);
>> connectionRequest.setTargetEditPart(targetEditPart);
>> connectionRequest.setType(RequestConstants.REQ_CONNECTION_EN D);
>> connectionRequest.setLocation(new Point(0, 0));
>>
>> Command createConnectionCmd =
>> targetEditPart.getCommand(connectionRequest);
>> return createConnectionCmd;
>> }
>>
>> private ConnectionViewAndElementDescriptor
>> getConnectionViewDescriptor(PreferencesHint preferencesHint) {
>> String semanticHint = String.valueOf(GeneralizationEditPart.VISUAL_ID);
>> CreateRelationshipRequest createElementRequest = new
>> CreateRelationshipRequest(UMLElementTypes.Generalization_400 1);
>> createElementRequest.setSource(sourceClassifier);
>> createElementRequest.setTarget(targetClassifier);
>> ConnectionViewAndElementDescriptor viewDescriptor = new
>> ConnectionViewAndElementDescriptor(new
>> CreateElementRequestAdapter(createElementRequest), semanticHint,
>> preferencesHint);
>> return viewDescriptor;
>> }
>>
>> 2.
>> You also may directly use CreationTool this way ( taken from
>> org.eclipse.uml2.diagram.statemachine.tests.tools.CreationTo olTest )
>>
>> getDiagramEditPart().getViewer().setSelection(new
>> StructuredSelection(sourceEditPart, targetEditPart));
>> createConnectionByTool(UMLElementTypes.Generalization_4001);
>>
>> private void createConnectionByTool(IElementType elementType) {
>> UnspecifiedTypeConnectionTool tool = new
>> UnspecifiedTypeConnectionTool(Collections.singletonList(elem entType));
>> tool.setEditDomain((EditDomain)
>> getDiagramWorkbenchPart().getDiagramEditDomain());
>> tool.activate();
>> tool.mouseDoubleClick(createMouseEvent(0, 0),
>> getDiagramEditPart().getViewer());
>> tool.deactivate();
>> }
>> .
>> I also could recomment you to have a look at
>> org.eclipse.uml2.diagram.clazz.edit.commands.ChangeDependenc yTypeCommand
>> or org.eclipse.uml2.diagram.clazz.part.CreateGeneralizationLink Tool (more
>> complicated behaviour) classes.
>>
>>
>> Good luck!
>> Tatiana.
>>
>> "Philippe" <philippeweber57@yahoo.fr> wrote in message
>> news:f2f3cl$57k$1@build.eclipse.org...
>>> Hi,
>>>
>>> I'm still searching the best way to modify a class diagram
>>> programmatically.
>>> I made good use of a past reply for creating a class
>>> List types = Arrays.asList(new IElementType[] {
>>> UMLElementTypes.Class_3007, UMLElementTypes.Class_2001, //you can
>>> use only this one for top level classes
>>> UMLElementTypes.Class_3003, UMLElementTypes.Class_3030, });
>>> CreateUnspecifiedTypeRequest request = new
>>> CreateUnspecifiedTypeRequest(elementTypes,
>>> UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
>>> Command result = getDiagramEditPart().getCommand(request);
>>>
>>> But now I need to create programmatically a Generalization between two
>>> classes, and I can't find the right way.
>>>
>>> Thanks for any help
>>> Philippe
>>>
>>
|
|
|
Re: Command for creating Generalization [message #594065 is a reply to message #470785] |
Wed, 16 May 2007 17:55 |
Tatiana Fesenko Messages: 530 Registered: July 2009 |
Senior Member |
|
|
Hi Philippe!
The way links are created is different from the way usual elements are
created. Links contain source and target. That's why the command to create a
link is more complicated than the command to create a node.
Command to create e.g. Generalization link will look like
1.
public Command getCreateGeneralizationCommand() {
// descriptor contains information about semantic features of link
ConnectionViewDescriptor viewDescriptor =
getConnectionViewDescriptor(preferencesHint);
CreateConnectionViewAndElementRequest createViewRequest = new
CreateConnectionViewAndElementRequest(viewDescriptor);
// here we set notation properties - source/target EditParts and location
(is not nessesary)
connectionRequest.setTargetEditPart(sourceEditPart);
connectionRequest.setType(RequestConstants.REQ_CONNECTION_ST ART);
connectionRequest.setLocation(new Point(0, 0));
//
if (sourceEditPart.getCommand(connectionRequest) == null) {
return;
}
connectionRequest.setSourceEditPart(sourceEditPart);
connectionRequest.setTargetEditPart(targetEditPart);
connectionRequest.setType(RequestConstants.REQ_CONNECTION_EN D);
connectionRequest.setLocation(new Point(0, 0));
Command createConnectionCmd = targetEditPart.getCommand(connectionRequest);
return createConnectionCmd;
}
private ConnectionViewAndElementDescriptor
getConnectionViewDescriptor(PreferencesHint preferencesHint) {
String semanticHint = String.valueOf(GeneralizationEditPart.VISUAL_ID);
CreateRelationshipRequest createElementRequest = new
CreateRelationshipRequest(UMLElementTypes.Generalization_400 1);
createElementRequest.setSource(sourceClassifier);
createElementRequest.setTarget(targetClassifier);
ConnectionViewAndElementDescriptor viewDescriptor = new
ConnectionViewAndElementDescriptor(new
CreateElementRequestAdapter(createElementRequest), semanticHint,
preferencesHint);
return viewDescriptor;
}
2.
You also may directly use CreationTool this way ( taken from
org.eclipse.uml2.diagram.statemachine.tests.tools.CreationTo olTest )
getDiagramEditPart().getViewer().setSelection(new
StructuredSelection(sourceEditPart, targetEditPart));
createConnectionByTool(UMLElementTypes.Generalization_4001);
private void createConnectionByTool(IElementType elementType) {
UnspecifiedTypeConnectionTool tool = new
UnspecifiedTypeConnectionTool(Collections.singletonList(elem entType));
tool.setEditDomain((EditDomain)
getDiagramWorkbenchPart().getDiagramEditDomain());
tool.activate();
tool.mouseDoubleClick(createMouseEvent(0, 0),
getDiagramEditPart().getViewer());
tool.deactivate();
}
..
I also could recomment you to have a look at
org.eclipse.uml2.diagram.clazz.edit.commands.ChangeDependenc yTypeCommand or
org.eclipse.uml2.diagram.clazz.part.CreateGeneralizationLink Tool (more
complicated behaviour) classes.
Good luck!
Tatiana.
"Philippe" <philippeweber57@yahoo.fr> wrote in message
news:f2f3cl$57k$1@build.eclipse.org...
> Hi,
>
> I'm still searching the best way to modify a class diagram
> programmatically.
> I made good use of a past reply for creating a class
> List types = Arrays.asList(new IElementType[] {
> UMLElementTypes.Class_3007, UMLElementTypes.Class_2001, //you can
> use only this one for top level classes
> UMLElementTypes.Class_3003, UMLElementTypes.Class_3030, });
> CreateUnspecifiedTypeRequest request = new
> CreateUnspecifiedTypeRequest(elementTypes,
> UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
> Command result = getDiagramEditPart().getCommand(request);
>
> But now I need to create programmatically a Generalization between two
> classes, and I can't find the right way.
>
> Thanks for any help
> Philippe
>
|
|
|
Re: Command for creating Generalization [message #594098 is a reply to message #470786] |
Fri, 18 May 2007 11:21 |
Philippe Messages: 100 Registered: July 2009 |
Senior Member |
|
|
Hi Tatiana,
thanks for the hints, it worked great for me
But I'm a bit disappointed, I though at first that
if I make pure semantic change using UML2 API inside a transaction,
UML2Tools could handle the refresh.
The refresh works just fine for properties modification but the creation
of new element isn't reflected.
So what I exactly want to do is to create a new diagram element to link
it with an existing semantic element (class for example),
can this be integrated in the command I used so far with editpart ?
Many Thanks for the good work
Philippe
Tatiana Fesenko wrote:
> Hi Philippe!
>
> The way links are created is different from the way usual elements are
> created. Links contain source and target. That's why the command to create a
> link is more complicated than the command to create a node.
> Command to create e.g. Generalization link will look like
>
> 1.
> public Command getCreateGeneralizationCommand() {
> // descriptor contains information about semantic features of link
> ConnectionViewDescriptor viewDescriptor =
> getConnectionViewDescriptor(preferencesHint);
> CreateConnectionViewAndElementRequest createViewRequest = new
> CreateConnectionViewAndElementRequest(viewDescriptor);
> // here we set notation properties - source/target EditParts and location
> (is not nessesary)
> connectionRequest.setTargetEditPart(sourceEditPart);
> connectionRequest.setType(RequestConstants.REQ_CONNECTION_ST ART);
> connectionRequest.setLocation(new Point(0, 0));
> //
> if (sourceEditPart.getCommand(connectionRequest) == null) {
> return;
> }
>
> connectionRequest.setSourceEditPart(sourceEditPart);
> connectionRequest.setTargetEditPart(targetEditPart);
> connectionRequest.setType(RequestConstants.REQ_CONNECTION_EN D);
> connectionRequest.setLocation(new Point(0, 0));
>
> Command createConnectionCmd = targetEditPart.getCommand(connectionRequest);
> return createConnectionCmd;
> }
>
> private ConnectionViewAndElementDescriptor
> getConnectionViewDescriptor(PreferencesHint preferencesHint) {
> String semanticHint = String.valueOf(GeneralizationEditPart.VISUAL_ID);
> CreateRelationshipRequest createElementRequest = new
> CreateRelationshipRequest(UMLElementTypes.Generalization_400 1);
> createElementRequest.setSource(sourceClassifier);
> createElementRequest.setTarget(targetClassifier);
> ConnectionViewAndElementDescriptor viewDescriptor = new
> ConnectionViewAndElementDescriptor(new
> CreateElementRequestAdapter(createElementRequest), semanticHint,
> preferencesHint);
> return viewDescriptor;
> }
>
> 2.
> You also may directly use CreationTool this way ( taken from
> org.eclipse.uml2.diagram.statemachine.tests.tools.CreationTo olTest )
>
> getDiagramEditPart().getViewer().setSelection(new
> StructuredSelection(sourceEditPart, targetEditPart));
> createConnectionByTool(UMLElementTypes.Generalization_4001);
>
> private void createConnectionByTool(IElementType elementType) {
> UnspecifiedTypeConnectionTool tool = new
> UnspecifiedTypeConnectionTool(Collections.singletonList(elem entType));
> tool.setEditDomain((EditDomain)
> getDiagramWorkbenchPart().getDiagramEditDomain());
> tool.activate();
> tool.mouseDoubleClick(createMouseEvent(0, 0),
> getDiagramEditPart().getViewer());
> tool.deactivate();
> }
> .
> I also could recomment you to have a look at
> org.eclipse.uml2.diagram.clazz.edit.commands.ChangeDependenc yTypeCommand or
> org.eclipse.uml2.diagram.clazz.part.CreateGeneralizationLink Tool (more
> complicated behaviour) classes.
>
>
> Good luck!
> Tatiana.
>
> "Philippe" <philippeweber57@yahoo.fr> wrote in message
> news:f2f3cl$57k$1@build.eclipse.org...
>> Hi,
>>
>> I'm still searching the best way to modify a class diagram
>> programmatically.
>> I made good use of a past reply for creating a class
>> List types = Arrays.asList(new IElementType[] {
>> UMLElementTypes.Class_3007, UMLElementTypes.Class_2001, //you can
>> use only this one for top level classes
>> UMLElementTypes.Class_3003, UMLElementTypes.Class_3030, });
>> CreateUnspecifiedTypeRequest request = new
>> CreateUnspecifiedTypeRequest(elementTypes,
>> UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
>> Command result = getDiagramEditPart().getCommand(request);
>>
>> But now I need to create programmatically a Generalization between two
>> classes, and I can't find the right way.
>>
>> Thanks for any help
>> Philippe
>>
>
>
|
|
|
Re: Command for creating Generalization [message #594157 is a reply to message #470788] |
Fri, 18 May 2007 17:38 |
Tatiana Fesenko Messages: 530 Registered: July 2009 |
Senior Member |
|
|
Hi Philippe!
Use ViewDescriptor insteadof ViewAndElementDescriptor and CreateViewRequest
insteadof CreateViewAndElementRequest to create diagram presentation of
already existing element .
For example, the following code creates Rectangle notation for existing
org.eclipse.uml2.uml.Interface 'interface1':
String semanticHint = String.valueOf(Interface2EditPart.VISUAL_ID);
ViewDescriptor viewDescriptor =
new ViewDescriptor(new EObjectAdapter(interface1), Node.class,
semanticHint, getPreferencesHint());
CreateViewRequest createViewRequest = new CreateViewRequest(viewDescriptor);
Command result = editPart.getParent().getCommand(createViewRequest);
Best wishes,
Tatiana.
"Philippe" <philippeweber57@yahoo.fr> wrote in message
news:f2k2b8$hi$1@build.eclipse.org...
> Hi Tatiana,
>
> thanks for the hints, it worked great for me
>
> But I'm a bit disappointed, I though at first that
> if I make pure semantic change using UML2 API inside a transaction,
> UML2Tools could handle the refresh.
> The refresh works just fine for properties modification but the creation
> of new element isn't reflected.
> So what I exactly want to do is to create a new diagram element to link it
> with an existing semantic element (class for example),
> can this be integrated in the command I used so far with editpart ?
>
> Many Thanks for the good work
> Philippe
>
> Tatiana Fesenko wrote:
>> Hi Philippe!
>>
>> The way links are created is different from the way usual elements are
>> created. Links contain source and target. That's why the command to
>> create a link is more complicated than the command to create a node.
>> Command to create e.g. Generalization link will look like
>>
>> 1.
>> public Command getCreateGeneralizationCommand() {
>> // descriptor contains information about semantic features of link
>> ConnectionViewDescriptor viewDescriptor =
>> getConnectionViewDescriptor(preferencesHint);
>> CreateConnectionViewAndElementRequest createViewRequest = new
>> CreateConnectionViewAndElementRequest(viewDescriptor);
>> // here we set notation properties - source/target EditParts and location
>> (is not nessesary)
>> connectionRequest.setTargetEditPart(sourceEditPart);
>> connectionRequest.setType(RequestConstants.REQ_CONNECTION_ST ART);
>> connectionRequest.setLocation(new Point(0, 0));
>> //
>> if (sourceEditPart.getCommand(connectionRequest) == null) {
>> return;
>> }
>>
>> connectionRequest.setSourceEditPart(sourceEditPart);
>> connectionRequest.setTargetEditPart(targetEditPart);
>> connectionRequest.setType(RequestConstants.REQ_CONNECTION_EN D);
>> connectionRequest.setLocation(new Point(0, 0));
>>
>> Command createConnectionCmd =
>> targetEditPart.getCommand(connectionRequest);
>> return createConnectionCmd;
>> }
>>
>> private ConnectionViewAndElementDescriptor
>> getConnectionViewDescriptor(PreferencesHint preferencesHint) {
>> String semanticHint = String.valueOf(GeneralizationEditPart.VISUAL_ID);
>> CreateRelationshipRequest createElementRequest = new
>> CreateRelationshipRequest(UMLElementTypes.Generalization_400 1);
>> createElementRequest.setSource(sourceClassifier);
>> createElementRequest.setTarget(targetClassifier);
>> ConnectionViewAndElementDescriptor viewDescriptor = new
>> ConnectionViewAndElementDescriptor(new
>> CreateElementRequestAdapter(createElementRequest), semanticHint,
>> preferencesHint);
>> return viewDescriptor;
>> }
>>
>> 2.
>> You also may directly use CreationTool this way ( taken from
>> org.eclipse.uml2.diagram.statemachine.tests.tools.CreationTo olTest )
>>
>> getDiagramEditPart().getViewer().setSelection(new
>> StructuredSelection(sourceEditPart, targetEditPart));
>> createConnectionByTool(UMLElementTypes.Generalization_4001);
>>
>> private void createConnectionByTool(IElementType elementType) {
>> UnspecifiedTypeConnectionTool tool = new
>> UnspecifiedTypeConnectionTool(Collections.singletonList(elem entType));
>> tool.setEditDomain((EditDomain)
>> getDiagramWorkbenchPart().getDiagramEditDomain());
>> tool.activate();
>> tool.mouseDoubleClick(createMouseEvent(0, 0),
>> getDiagramEditPart().getViewer());
>> tool.deactivate();
>> }
>> .
>> I also could recomment you to have a look at
>> org.eclipse.uml2.diagram.clazz.edit.commands.ChangeDependenc yTypeCommand
>> or org.eclipse.uml2.diagram.clazz.part.CreateGeneralizationLink Tool (more
>> complicated behaviour) classes.
>>
>>
>> Good luck!
>> Tatiana.
>>
>> "Philippe" <philippeweber57@yahoo.fr> wrote in message
>> news:f2f3cl$57k$1@build.eclipse.org...
>>> Hi,
>>>
>>> I'm still searching the best way to modify a class diagram
>>> programmatically.
>>> I made good use of a past reply for creating a class
>>> List types = Arrays.asList(new IElementType[] {
>>> UMLElementTypes.Class_3007, UMLElementTypes.Class_2001, //you can
>>> use only this one for top level classes
>>> UMLElementTypes.Class_3003, UMLElementTypes.Class_3030, });
>>> CreateUnspecifiedTypeRequest request = new
>>> CreateUnspecifiedTypeRequest(elementTypes,
>>> UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
>>> Command result = getDiagramEditPart().getCommand(request);
>>>
>>> But now I need to create programmatically a Generalization between two
>>> classes, and I can't find the right way.
>>>
>>> Thanks for any help
>>> Philippe
>>>
>>
|
|
|
Goto Forum:
Current Time: Tue Mar 19 04:08:58 GMT 2024
Powered by FUDForum. Page generated in 0.02733 seconds
|