|
@@ -71,6 +71,21 @@ public class NetworkTreePanel extends JScrollPane implements Observer {
|
|
|
* Right click menu
|
|
|
*/
|
|
|
private JPopupMenu rightClick;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * MenuItem for editing of Links, Connections & Devices
|
|
|
+ */
|
|
|
+ private JMenuItem mntmEdit = new JMenuItem("Edit");
|
|
|
+ /**
|
|
|
+ * MenuItem for deletion of devices
|
|
|
+ */
|
|
|
+ private JMenuItem mntmDelete = new JMenuItem("Delete");
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Clicked object (Device, Link or Connection)
|
|
|
+ */
|
|
|
+ private Object clickedObject;
|
|
|
+
|
|
|
/**
|
|
|
* Creates a new Network Tree Panel
|
|
|
*
|
|
@@ -129,6 +144,11 @@ public class NetworkTreePanel extends JScrollPane implements Observer {
|
|
|
@Override
|
|
|
public void windowClosing(WindowEvent e) {
|
|
|
controller.removeObserver(that);
|
|
|
+ that.setVisible(false);
|
|
|
+ tree.setVisible(false);
|
|
|
+ rightClick.setVisible(false);
|
|
|
+ parent.setVisible(false);
|
|
|
+ parent.dispose();
|
|
|
super.windowClosing(e);
|
|
|
}
|
|
|
});
|
|
@@ -193,9 +213,26 @@ public class NetworkTreePanel extends JScrollPane implements Observer {
|
|
|
*/
|
|
|
private void initializeRightClickMenu() {
|
|
|
rightClick = new JPopupMenu();
|
|
|
- rightClick.add(new JMenuItem("Option 1"));
|
|
|
- rightClick.add(new JMenuItem("Option 2"));
|
|
|
- this.add(rightClick);
|
|
|
+ mntmEdit.addActionListener(a->{
|
|
|
+ if(clickedObject == null)return;
|
|
|
+ rightClick.setVisible(false);
|
|
|
+ if(clickedObject instanceof SmartDevice){
|
|
|
+ SmartDeviceCreationPopUp p = new SmartDeviceCreationPopUp((SmartDevice) clickedObject, true, controller);
|
|
|
+ p.setLocationRelativeTo(that);
|
|
|
+ p.setEnabled(true);
|
|
|
+ p.setVisible(true);
|
|
|
+ }else if(clickedObject instanceof Connection){
|
|
|
+ new ConnectionCreationDialog((Connection) clickedObject, controller, that);
|
|
|
+ }else if(clickedObject instanceof Link){
|
|
|
+ new LinkCreationDialog((Link) clickedObject, controller, that);
|
|
|
+ }else{
|
|
|
+ //Invalid object
|
|
|
+ }
|
|
|
+ });
|
|
|
+ rightClick.add(mntmEdit);
|
|
|
+
|
|
|
+ rightClick.add(mntmDelete);
|
|
|
+ parent.add(rightClick);
|
|
|
|
|
|
}
|
|
|
/**
|
|
@@ -211,14 +248,22 @@ public class NetworkTreePanel extends JScrollPane implements Observer {
|
|
|
rightClick.setVisible(false);
|
|
|
rightClick.setEnabled(false);
|
|
|
}else{
|
|
|
- Object o = clicked.getLastPathComponent();
|
|
|
- if(o instanceof SmartDevice){
|
|
|
+ clickedObject = ((DefaultMutableTreeNode)clicked.getLastPathComponent()).getUserObject();
|
|
|
+ if(clickedObject instanceof SmartDevice){
|
|
|
//TODO: Specific actions
|
|
|
+ System.out.println("Clicked SmartDevice");
|
|
|
+ if(clickedObject instanceof SmartDevice) System.out.println(((SmartDevice)clickedObject).getName());
|
|
|
+ } else if(clickedObject instanceof Connection){
|
|
|
+ System.out.println("Clicked Connection");
|
|
|
+ }else if(clickedObject instanceof Link){
|
|
|
+ System.out.println("Clicked Link");
|
|
|
+ }else{
|
|
|
+ System.out.println("Clicked unknown: "+clickedObject.getClass().getSimpleName());
|
|
|
}
|
|
|
- rightClick.setLocation(e.getLocationOnScreen());
|
|
|
- rightClick.setVisible(true);
|
|
|
+
|
|
|
+ rightClick.show(this,e.getX(), e.getY());
|
|
|
rightClick.setEnabled(true);
|
|
|
- if(o instanceof SmartDevice) System.out.println(((SmartDevice)o).getName());
|
|
|
+ rightClick.setVisible(true);
|
|
|
|
|
|
}
|
|
|
}
|