ich habe ein tree mit popup Menü. Das popup Menü öffnet sich auch aber es reagiert nicht wenn ich einen menüpunkt auswähle. hab es auch schon im DebugModus durchlaufen lassen aber der ActionListener springt nicht an.
Mein Code
Mein Code
Code:
public class Sca1View extends FrameView implements ActionListener{
.......
public void createPopupMenu() {
JMenuItem menuItem;
//Create the popup menu.
JPopupMenu popup = new JPopupMenu();
menuItem = new JMenuItem(New_Project);
menuItem.setActionCommand(New_Project);
menuItem.addActionListener(this);
popup.add(menuItem);
menuItem = new JMenuItem("New_Build");
menuItem.setActionCommand(New_Build);
menuItem.addActionListener(this);
popup.add(menuItem);
menuItem = new JMenuItem("Delete");
menuItem.setActionCommand(Delete);
menuItem.addActionListener(this);
popup.add(menuItem);
//Add listener to the text area so the popup menu can come up.
MouseListener popupListener = new PopupListener(popup);
jTree1.addMouseListener(popupListener);
}
public void actionPerformed(ActionEvent e,String Wert) {
String url = "jdbc:postgresql://localhost:5432/QualityDB"
+ "?user=postgres&password=xxx";
String NodeName = null;
Integer depth = null;
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)
jTree1.getLastSelectedPathComponent();
if (selectedNode == null){
return;
}
if (e.getActionCommand().equals("Delete")){
if (selectedNode.getParent() != null)
depth = selectedNode.getChildCount();
if (depth == 1)
NodeName = "'" + selectedNode.toString() + "'";
try
{
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection(url);
stmt = conn.createStatement();
String query = "DELETE FROM project WHERE(project_name = "+NodeName+")";
stmt.executeQuery(query);
}
catch (Exception a){
jLabel1.setText("Fehler: " + a.getMessage());
}
if (depth == 0)
NodeName = "'" + selectedNode.toString() + "'";
try
{
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection(url);
stmt = conn.createStatement();
String query = "DELETE FROM build WHERE(project_name = "+NodeName+")";
stmt.executeQuery(query);
}
catch (Exception a){
jLabel1.setText("Fehler: " + a.getMessage());
}
return;
}
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("New");
if (e.getActionCommand().equals("New Project")){
DefaultMutableTreeNode parent = (DefaultMutableTreeNode)
selectedNode.getParent();
if (parent != null){
int selectedIndex = parent.getIndex(selectedNode);
// model.insertNodeInto(newNode, parent, selectedIndex+1);
//
// }
}
else if (e.getActionCommand().equals("New Build")){
// model.insertNodeInto(newNode, selectedNode, selectedNode.getChildCount());
}
//
// Code um neuen Build anzulegen!!!
//
}
}