package components.main.left;

import controller.TitanMainController;

import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class TitanTree extends JTree {
    public TitanTree() {
        // Init Tree
        super();
        setModel(null);
    }

    // Init fields
    /*
    addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) { // Check right click
                int selectedRow = getRowForLocation(e.getX(), e.getY());

                if (selectedRow > 0) { // Check valid position excluding root
                    TreePath selectedPath = getPathForRow(selectedRow);
                    Object selectedComponent = selectedPath.getLastPathComponent();

                    if (!getModel().isLeaf(selectedComponent)) {
                        popupMenu.show(this, e.getX(), e.getY());
                    }
                }
            }
        }
    });
    */
}

@@ -35,154 +35,69 @@
 ort 
-controller.TitanMainController;%0A%0Aimport javax.swing.*;%0Aimport javax.swing.event.TreeSelectionEvent;%0Aimport javax.swing.event.TreeSelectionListener
+javax.swing.*;%0Aimport javax.swing.tree.DefaultMutableTreeNode
 ;%0Aim
@@ -238,16 +238,58 @@
 JTree %7B%0A
+    public TitanLeftPopupMenu popupMenu;%0A%0A
     publ
@@ -371,15 +371,13 @@
 l);%0A
+%0A
     
-%7D%0A%0A
     
@@ -399,11 +399,54 @@
     
-/*%0A
+    popupMenu = new TitanLeftPopupMenu();%0A    
     
@@ -491,16 +491,20 @@
         
+    
 @Overrid
@@ -505,16 +505,20 @@
 verride%0A
+    
         
@@ -554,24 +554,28 @@
 eEvent e) %7B%0A
+    
             
@@ -638,16 +638,20 @@
 t click%0A
+    
         
@@ -728,24 +728,28 @@
             
+    
 if (selected
@@ -798,16 +798,20 @@
 ng root%0A
+    
         
@@ -898,138 +898,251 @@
     
-Object selectedComponent = selectedPath.getLastPathComponent();%0A%0A                    if (!getModel().isLeaf(selectedComponent)) %7B%0A
+    DefaultMutableTreeNode selectedComponent = (DefaultMutableTreeNode) selectedPath.getLastPathComponent();%0A%0A                        if (selectedComponent.getAllowsChildren()) %7B%0A                            setSelectionPath(selectedPath);%0A    
     
@@ -1176,16 +1176,26 @@
 nu.show(
+TitanTree.
 this, e.
@@ -1213,16 +1213,42 @@
 etY());%0A
+                        %7D%0A
         
@@ -1306,22 +1306,15 @@
    %7D
+);
 %0A    %7D
-);%0A    */
 %0A%7D%0A

implement group right click