Séelction d'une cellule avec jgraph

cs_mina86 Messages postés 4 Date d'inscription dimanche 21 janvier 2007 Statut Membre Dernière intervention 26 juillet 2008 - 26 juil. 2008 à 20:42
saifdn Messages postés 5 Date d'inscription lundi 26 mars 2012 Statut Membre Dernière intervention 19 juin 2012 - 19 juin 2012 à 16:48
Bonjour,

j'utilise Jgraph pour composer des web services
un graph représente un service web composites et chaque cellule est une méthode d'un service web, j'ai créé un JPopupMenu lorsqu'on appuie sur le bouton droit sur les cellules du graph, (et contient "modifier" et "supprimer")mon premier but est de pouvoir modifier des informations déja introduites par exemple les entrées et sorties des méthodes du service web selectionné (cellule selectionné) sachant que pour insérer une cellule dans le graph un Jframe s'affiche pour saisir les informations néceessaires, comment je peux avoir la cellule selectionnée (defaultGraphCell) avec ses attributs (CellAttributes) (ie réafficher le Jframe correspondant rempli )?
merci d'avance

1 réponse

saifdn Messages postés 5 Date d'inscription lundi 26 mars 2012 Statut Membre Dernière intervention 19 juin 2012
19 juin 2012 à 16:48
Bonjour,
il faut ajouter un listener sur ton graphe
graph = new MyGraph(model, view);
graph.addMouseListener(new MouseAdapter() {

public void mousePressed(MouseEvent e) {
if(e.getButton()==MouseEvent.BUTTON3){
ClassMenuContextuel menuContext=null;
// Get Cell under Mousepointer
int x e.getX(), y e.getY();
Object cell = graph.getFirstCellForLocation(x, y);
// Print Cell Label
if (cell != null) {
objectText = graph.convertValueToString(cell);
if(objectText!=null){
menuContext=new ClassMenuContextuel();

menuContext.show(e.getComponent(),e.getX(),e.getY());
menuContext.setCellName(objectText);
menuContext.setVisible(true);
}
//TODO
}
}
}



public class ClassMenuContextuel extends JPopupMenu implements ActionListener{

/**
*
*/
private static final long serialVersionUID = 1L;
JMenu EditMenuItem;
JMenuItem editName;
JMenuItem editRelations;


JMenuItem deleteMenuItem;
JMenuItem PropertesMenuItem;


private String cellName=null;
public ClassMenuContextuel() {

editName=new JMenuItem("Name");
editName.setActionCommand("name");
editName.addActionListener(this);

editRelations=new JMenuItem("Relations");
editRelations.setActionCommand("relations");
editRelations.addActionListener(this);

EditMenuItem = new JMenu("Edit");
EditMenuItem.setActionCommand("edit");
EditMenuItem.addActionListener(this);
EditMenuItem.add(editName);
EditMenuItem.add(editRelations);
add(EditMenuItem);

deleteMenuItem = new JMenuItem("Delete");
deleteMenuItem.setActionCommand("delete");
deleteMenuItem.addActionListener(this);
add(deleteMenuItem);
PropertesMenuItem = new JMenuItem("Show properties");
PropertesMenuItem.setActionCommand("properties");
PropertesMenuItem.addActionListener(this);
setCellName(cellName);
add(PropertesMenuItem);

}


public void actionPerformed(ActionEvent e) {
if(cellName!=null){
String type=getCellType(cellName);
String name=getCellName(cellName);
if(e.getSource()==editName){
System.out.println("\n edit name here");
String s = (String)JOptionPane.showInputDialog(
this,
"",
"Edit name",
JOptionPane.QUESTION_MESSAGE,
new ImageIcon("src/main/java/ch/bfh/ti/zuse2/icon/editIcon.png"),
null, // c'est ouvert !!!
name); // valeur initiale

graph.removeSelectionCell(graph.getSelectionCell());
graph.repaint();
System.out.println("\n the new name is"+s);

}
if(e.getSource()==editRelations){
System.out.println("\n edit relations here");
}

if(e.getSource()==EditMenuItem){
System.out.println("\n\n edit : "+type+" that name is "+name);

}

else if (e.getSource()==deleteMenuItem){
System.out.println("\n\n delete : "+type+" that name is "+name);
manager=ObjectManager.getInstance();
manager.deleteObject(type, name);
graph.deleteSelection();
}
else if (e.getSource()==PropertesMenuItem){
System.out.println("\n\n show properties of : "+type+" that name is "+name);


}

}
else
System.out.println("\n cellname null");
}

public String getCellType(String cellName){
if(cellName!=null){
String str[]=cellName.split("-");
return str[0];
}
return null;
}
public String getCellName(String cellName){
if(cellName!=null){
String str[]=cellName.split("-");
return str[1];
}
return null;
}

public String getCellName() {
return cellName;
}

public void setCellName(String cellName) {
this.cellName = cellName;
}



}
0
Rejoignez-nous