//Extraction de la figure pour un objet EditPart GuiTestObject figureTO = EntityEditPart().getFigure(); //Recherche une figure contenant le texte. TestObject foundTO[] = figureTO.find(atDescendant("text", "label")); if(foundTO != null) { int numFound = foundTO.length; for(int index = 0; index < numFound ; index ++) { if(foundTO[index] != null && foundTO[index] instanceof GuiTestObject) { //Pour rechercher une propriété spécifique sur la figure Object figWidth = foundTO[index].getProperty("width"); if(figWidth != null) ((GuiTestObject)foundTO[index]).click(); } } }
//Répertorie les connecteurs du parent du noeud TestObject parent = EntityEditPart().getParent(); if(parent != null && parent instanceof GefEditPartTestObject) { TestObject connectors[] = ((GefEditPartTestObject)parent).getConnectors(); if(connectors != null) { int numConnector = connectors.length; for(int conIndex = 0; conIndex < numConnector; conIndex ++) { if(connectors[conIndex] != null && connectors[conIndex] instanceof GefEditPartTestObject) { GuiTestObject figConnector = ((GefEditPartTestObject)connectors[conIndex]).getFigure(); //Recherche une figure contenant du texte. TestObject foundConn[] = figConnector.find(atDescendant("text", "association")); if(foundConn != null && foundConn.length > 0) { //S'il n'existe qu'un libellé contenant le texte "Association" if(foundConn[0] != null && foundConn[0] instanceof GuiTestObject) { ((GuiTestObject)foundConn[0]).click(); } } } } } }
Exemple 3 : L'exemple suivant alimente une liste avec les connecteurs qui sont des descendants de l'EditPart sélectionné, à l'aide de l'API isConnector()
//Supposons que vous avez "RootEditPart" dans la mappe d'objets. ArrayList connList = new ArrayList(); enumerateAllConnectors(RootEditPart(),connList); } private static void enumerateAllConnectors(TestObject editPart,ArrayList connList) { if(editPart != null ) { if(editPart instanceof GefEditPartTestObject) { boolean isConnector = ((GefEditPartTestObject)editPart).isConnector(); if(isConnector) connList.add(editPart); } TestObject []children = editPart.getChildren(); if(children != null) { int numChild = children.length; for(int i=0; i < numChild ; i++) { enumerateAllConnectors(children[i], connList); } } } }