Search in sources :

Example 1 with DefaultPopUpMenu

use of org.apache.cayenne.modeler.dialog.db.load.DefaultPopUpMenu in project cayenne by apache.

the class ReverseEngineeringTreePanel method initPopupMenus.

private void initPopupMenus() {
    popups = new HashMap<>();
    popups.put(Catalog.class, new CatalogPopUpMenu());
    popups.put(Schema.class, new SchemaPopUpMenu());
    popups.put(ReverseEngineering.class, new RootPopUpMenu());
    popups.put(String.class, new RootPopUpMenu());
    popups.put(IncludeTable.class, new IncludeTablePopUpMenu());
    popups.put(ExcludeTable.class, new DefaultPopUpMenu());
    popups.put(IncludeColumn.class, new DefaultPopUpMenu());
    popups.put(ExcludeColumn.class, new DefaultPopUpMenu());
    popups.put(IncludeProcedure.class, new DefaultPopUpMenu());
    popups.put(ExcludeProcedure.class, new DefaultPopUpMenu());
}
Also used : RootPopUpMenu(org.apache.cayenne.modeler.dialog.db.load.RootPopUpMenu) CatalogPopUpMenu(org.apache.cayenne.modeler.dialog.db.load.CatalogPopUpMenu) IncludeTablePopUpMenu(org.apache.cayenne.modeler.dialog.db.load.IncludeTablePopUpMenu) DefaultPopUpMenu(org.apache.cayenne.modeler.dialog.db.load.DefaultPopUpMenu) SchemaPopUpMenu(org.apache.cayenne.modeler.dialog.db.load.SchemaPopUpMenu)

Example 2 with DefaultPopUpMenu

use of org.apache.cayenne.modeler.dialog.db.load.DefaultPopUpMenu in project cayenne by apache.

the class ReverseEngineeringTreePanel method initListeners.

private void initListeners() {
    reverseEngineeringTree.addTreeSelectionListener(e -> treeToolbar.lockButtons());
    reverseEngineeringTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (reverseEngineeringTree.getRowForLocation(e.getX(), e.getY()) == -1) {
                reverseEngineeringTree.setSelectionRow(-1);
            }
            if (SwingUtilities.isRightMouseButton(e)) {
                if (reverseEngineeringTree.isEditing()) {
                    return;
                }
                int row = reverseEngineeringTree.getClosestRowForLocation(e.getX(), e.getY());
                reverseEngineeringTree.setSelectionRow(row);
                DefaultPopUpMenu popupMenu;
                DbImportTreeNode selectedElement;
                if (reverseEngineeringTree.getSelectionPath() != null) {
                    selectedElement = reverseEngineeringTree.getSelectedNode();
                    popupMenu = popups.get(selectedElement.getUserObject().getClass());
                } else {
                    selectedElement = reverseEngineeringTree.getRootNode();
                    popupMenu = popups.get(ReverseEngineering.class);
                }
                if (popupMenu != null) {
                    popupMenu.setProjectController(projectController);
                    popupMenu.setSelectedElement(selectedElement);
                    popupMenu.setParentElement(selectedElement.getParent());
                    popupMenu.setTree(reverseEngineeringTree);
                    popupMenu.show(e.getComponent(), e.getX(), e.getY());
                }
            } else if (reverseEngineeringTree.getSelectionPath() != null) {
                DbImportTreeNode selectedNode = reverseEngineeringTree.getSelectedNode();
                if (selectedNode.isExcludeColumn() || selectedNode.isIncludeColumn()) {
                    DbImportTreeNode expandNode = selectedNode.getParent();
                    DbImportTreeNode parentPath = dbSchemaTree.findNode(dbSchemaTree.getRootNode(), expandNode, 0);
                    if (parentPath != null) {
                        dbSchemaTree.expandPath(new TreePath((parentPath).getPath()));
                        scrollToNode(dbSchemaTree, parentPath);
                    }
                } else {
                    DbImportTreeNode findNode = dbSchemaTree.findNode(dbSchemaTree.getRootNode(), selectedNode, 0);
                    if (findNode != null) {
                        dbSchemaTree.expandPath(new TreePath(findNode.getParent().getPath()));
                        scrollToNode(dbSchemaTree, findNode);
                    }
                }
            }
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) TreePath(javax.swing.tree.TreePath) DbImportTreeNode(org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode) MouseAdapter(java.awt.event.MouseAdapter) DefaultPopUpMenu(org.apache.cayenne.modeler.dialog.db.load.DefaultPopUpMenu)

Aggregations

DefaultPopUpMenu (org.apache.cayenne.modeler.dialog.db.load.DefaultPopUpMenu)2 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 TreePath (javax.swing.tree.TreePath)1 CatalogPopUpMenu (org.apache.cayenne.modeler.dialog.db.load.CatalogPopUpMenu)1 DbImportTreeNode (org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode)1 IncludeTablePopUpMenu (org.apache.cayenne.modeler.dialog.db.load.IncludeTablePopUpMenu)1 RootPopUpMenu (org.apache.cayenne.modeler.dialog.db.load.RootPopUpMenu)1 SchemaPopUpMenu (org.apache.cayenne.modeler.dialog.db.load.SchemaPopUpMenu)1