I've had a menu item that initializes use case diagrams based on the
Macroscope approach (Fujitsu). My problem is that I'm able to add a new use
case into the package who contains the diagram, but I'm not able to add a
shortcut of this new created element into the use case diagram. Here is my
code. You see in comment all the things I'd tried. Sorry for the French :-).
public void initialiser(Element element) {
UseCase casDUtilisation;
this._diagram = (UseCaseDiagramImpl)element;
this._paquetage = (Package)this._diagram.getOwner();
this._usecasesFactory =
UsecasesFactory.REGISTRY.getFactory(this._paquetage.getIProject(),
this._paquetage.getSession());
if (this._paquetage.getStereotypes().contains(Stereotypes.P_FONCTION)) {
casDUtilisation = this.creerCasDUtilisation("UniteDeTache",
Stereotypes.P_UNITE_DE_TACHE);
this._paquetage.getOwnedMembers().add(casDUtilisation);
//this._diagram.eContents().add(casDUtilisation);
//this._diagram.eCrossReferences().add(casDUtilisation);
//this._diagram.getAttachments().add(casDUtilisation);
//this._diagram.getChildren().add(casDUtilisation);
//this._diagram.getDependencies().add(casDUtilisation);
}
else {
JOptionPane.showMessageDialog(null, "Aucune initialisation n'est
disponible pour l'élément sélectionné.");
}
}
Regards,
Dave
the code below creates a diagram reference
(com.borland.tg.emfapi.diagram.Node) for element and adds it to UseCase
diagram:
UsecasesFactory ucFactory =
UsecasesFactory.REGISTRY.getFactory(_paquetage.getIProject(),
_paquetage.getSession());
DiagramFactory diagramFactory =
DiagramFactory.REGISTRY.getFactory(_paquetage.getIProject(),
_paquetage.getSession());
//create a new UseCase diagram
UseCaseDiagram myUseCaseDiagram = ucFactory.createUseCaseDiagram();
myUseCaseDiagram.setName("MyUsecases");
//create a new UseCase
UseCase myUseCase = ucFactory.createUseCase();
myUseCase.setName("MyUC");
_paquetage.getOwnedMembers().add(myUseCase);
//create a new reference
Node node = diagramFactory.createNode();
//set usecase created above as reference's element (node becomes a shortcut
to myUseCase)
node.setElement(myUseCase);
//now add this shortcut to the diagram
myUseCaseDiagram.getChildren().add(node);
//this is just FYI - bonus: how to set positions for the newly added
shortcut
Bounds bounds = diagramFactory.createBounds();
LocationStyle style = diagramFactory.createLocationStyle();
style.setLocationSetByUser(true);
BoundsStyle bStyle = diagramFactory.createBoundsStyle();
bStyle.setBoundsSetByUser(true);
node.getStyles().add(style);
node.getStyles().add(bStyle);
bounds.setX(100);
bounds.setY(200);
bounds.setHeight(80);
bounds.setWidth(50);
node.setLayoutConstraint(bounds);
"Dave Couture" <dave_c...@dmr.ca> wrote in message
news:45ca404e$1...@newsgroups.borland.com...
"ElenaA" <Elena.A...@borland.com> a écrit dans le message de news:
45cb...@newsgroups.borland.com...