Search in sources :

Example 1 with DbImportView

use of org.apache.cayenne.modeler.editor.dbimport.DbImportView in project cayenne by apache.

the class DataMapTabbedView method initView.

/**
 * create tabs
 */
private void initView() {
    setTabPlacement(JTabbedPane.TOP);
    // add panels to tabs
    // note that those panels that have no internal scrollable tables
    // must be wrapped in a scroll pane
    JScrollPane dataMapScrollPane = new JScrollPane(new DataMapView(mediator));
    dbImportView = new DbImportView(mediator);
    dbImportScrollPane = new JScrollPane(dbImportView);
    codeGeneratorController = new CodeGeneratorController(mediator);
    cgenView = new JScrollPane(codeGeneratorController.getView());
    addTab("DataMap", dataMapScrollPane);
    addTab("DB Import", dbImportScrollPane);
    addTab("Class Generation", cgenView);
    addChangeListener(tab -> {
        if (isCgenTabActive()) {
            codeGeneratorController.initFromModel();
        } else if (isDbImportTabActive()) {
            dbImportView.initFromModel();
        }
    });
    mediator.addDataMapDisplayListener(e -> {
        if (e.getSource() instanceof CgenTab) {
            setSelectedComponent(cgenView);
        } else if (e.getSource() instanceof DbImportTab) {
            setSelectedComponent(dbImportScrollPane);
        } else if (isCgenTabActive() || isDbImportTabActive()) {
            fireStateChanged();
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) DbImportTab(org.apache.cayenne.modeler.editor.dbimport.domain.DbImportTab) DbImportView(org.apache.cayenne.modeler.editor.dbimport.DbImportView) CodeGeneratorController(org.apache.cayenne.modeler.editor.cgen.CodeGeneratorController) CgenTab(org.apache.cayenne.modeler.editor.cgen.domain.CgenTab)

Example 2 with DbImportView

use of org.apache.cayenne.modeler.editor.dbimport.DbImportView in project cayenne by apache.

the class MoveImportNodeAction method performAction.

@Override
public void performAction(ActionEvent e) {
    TreePath[] paths = sourceTree.getSelectionPaths();
    TreeManipulationAction action = null;
    String insertableName = EMPTY_NAME;
    DbImportView rootParent = (DbImportView) panel.getParent().getParent();
    rootParent.getReverseEngineeringProgress().setVisible(true);
    if (paths != null) {
        boolean isChanged = false;
        ReverseEngineering reverseEngineeringOldCopy = new ReverseEngineering(targetTree.getReverseEngineering());
        try {
            for (TreePath path : paths) {
                DbImportTreeNode selectedElement = (DbImportTreeNode) path.getLastPathComponent();
                DbImportTreeNode previousNode;
                DbImportTreeNode foundNode = targetTree.findNodeByParentsChain(targetTree.getRootNode(), selectedElement, 0);
                // If parent nodes from db schema doesn't exist, create it
                if (foundNode == null) {
                    for (int i = selectedElement.getParents().size() - 2; i >= 0; i--) {
                        DbImportTreeNode insertedNode = selectedElement.getParents().get(i);
                        previousNode = targetTree.findNodeByParentsChain(targetTree.getRootNode(), insertedNode, 0);
                        if (previousNode == null) {
                            previousNode = targetTree.getRootNode();
                        }
                        TreeManipulationAction manipulationAction = panel.getActionByNodeType(insertedNode.getUserObject().getClass());
                        if (canInsert(new TreePath(insertedNode.getPath()), previousNode)) {
                            manipulationAction.setFoundNode(previousNode);
                            manipulationAction.setInsertableNodeName(insertedNode.getSimpleNodeName());
                            manipulationAction.setTree(targetTree);
                            manipulationAction.setMovedFromDbSchema(true);
                            manipulationAction.actionPerformed(e);
                            manipulationAction.setFoundNode(null);
                            manipulationAction.setMultipleAction(false);
                        }
                    }
                }
                // Again find node where we insert our node
                foundNode = targetTree.findNodeByParentsChain(targetTree.getRootNode(), selectedElement, 0);
                if (!moveInverted) {
                    action = panel.getActionByNodeType(selectedElement.getUserObject().getClass());
                } else {
                    action = panel.getActionByNodeType(classMap.get(selectedElement.getUserObject().getClass()));
                }
                if (action != null) {
                    if (paths.length > 1) {
                        action.setMultipleAction(true);
                    } else {
                        action.setMultipleAction(false);
                    }
                    if (canInsert(path, foundNode)) {
                        insertableName = selectedElement.getSimpleNodeName();
                        action.setFoundNode(foundNode);
                        action.setInsertableNodeName(Matcher.quoteReplacement(insertableName));
                        action.setTree(targetTree);
                        action.setMovedFromDbSchema(true);
                        action.actionPerformed(e);
                        action.setFoundNode(null);
                        action.resetActionFlags();
                        isChanged = true;
                        sourceTree.setSelectionRow(-1);
                        panel.getMoveButton().setEnabled(false);
                        panel.getMoveInvertButton().setEnabled(false);
                    }
                }
            }
            if ((paths.length > 1) && (targetTree.getSelectionPath() != null)) {
                getProjectController().setDirty(true);
                ArrayList<DbImportTreeNode> expandList = targetTree.getTreeExpandList();
                targetTree.translateReverseEngineeringToTree(targetTree.getReverseEngineering(), false);
                targetTree.expandTree(expandList);
            }
            if ((isChanged) && (!insertableName.equals(EMPTY_NAME))) {
                ReverseEngineering reverseEngineeringNewCopy = new ReverseEngineering(targetTree.getReverseEngineering());
                DbImportTreeUndoableEdit undoableEdit = new DbImportTreeUndoableEdit(reverseEngineeringOldCopy, reverseEngineeringNewCopy, targetTree, getProjectController());
                getProjectController().getApplication().getUndoManager().addEdit(undoableEdit);
            }
        } finally {
            rootParent.getReverseEngineeringProgress().setVisible(false);
            if (action != null) {
                action.resetActionFlags();
            }
        }
    }
}
Also used : DbImportTreeUndoableEdit(org.apache.cayenne.modeler.undo.DbImportTreeUndoableEdit) DbImportView(org.apache.cayenne.modeler.editor.dbimport.DbImportView) TreePath(javax.swing.tree.TreePath) ReverseEngineering(org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering) DbImportTreeNode(org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode)

Example 3 with DbImportView

use of org.apache.cayenne.modeler.editor.dbimport.DbImportView in project cayenne by apache.

the class LoadDbSchemaAction method performAction.

public void performAction(ActionEvent e, TreePath tablePath) {
    final DbImportView rootParent = ((DbImportView) draggableTreePanel.getParent().getParent());
    rootParent.getLoadDbSchemaProgress().setVisible(true);
    rootParent.getLoadDbSchemaButton().setEnabled(false);
    Thread thread = new Thread(() -> {
        LoadDbSchemaAction.this.setEnabled(false);
        rootParent.lockToolbarButtons();
        draggableTreePanel.getMoveButton().setEnabled(false);
        draggableTreePanel.getMoveInvertButton().setEnabled(false);
        try {
            DBConnectionInfo connectionInfo = getConnectionInfo("Load Db Schema");
            if (connectionInfo == null) {
                return;
            }
            if (tablePath != null) {
                Object userObject = ((DbImportTreeNode) tablePath.getLastPathComponent()).getUserObject();
                if (userObject instanceof Catalog) {
                    Catalog catalog = (Catalog) userObject;
                    if (catalog.getSchemas().isEmpty()) {
                        loadTables(connectionInfo, tablePath, rootParent);
                    }
                } else if (userObject instanceof Schema) {
                    loadTables(connectionInfo, tablePath, rootParent);
                } else if (userObject instanceof IncludeTable) {
                    loadColumns(connectionInfo, tablePath);
                } else {
                    loadTables(connectionInfo, tablePath, rootParent);
                }
            } else {
                loadDataBase(connectionInfo);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(Application.getFrame(), ex.getMessage(), "Error loading db schema", JOptionPane.ERROR_MESSAGE);
            LOGGER.warn("Error loading db schema", ex);
        } finally {
            rootParent.getLoadDbSchemaButton().setEnabled(true);
            rootParent.getLoadDbSchemaProgress().setVisible(false);
            rootParent.unlockToolbarButtons();
        }
    });
    thread.start();
}
Also used : DbImportView(org.apache.cayenne.modeler.editor.dbimport.DbImportView) DbImportTreeNode(org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode) Schema(org.apache.cayenne.dbsync.reverse.dbimport.Schema) IncludeTable(org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable) DBConnectionInfo(org.apache.cayenne.modeler.pref.DBConnectionInfo) Catalog(org.apache.cayenne.dbsync.reverse.dbimport.Catalog) SQLException(java.sql.SQLException)

Example 4 with DbImportView

use of org.apache.cayenne.modeler.editor.dbimport.DbImportView in project cayenne by apache.

the class DeleteNodeAction method performAction.

@Override
public void performAction(ActionEvent e) {
    tree.stopEditing();
    final TreePath[] paths = tree.getSelectionPaths();
    final DbImportView rootParent = ((DbImportView) panel.getParent().getParent());
    rootParent.getLoadDbSchemaButton().setEnabled(false);
    rootParent.getReverseEngineeringProgress().setVisible(true);
    if (paths != null) {
        ReverseEngineering reverseEngineeringOldCopy = new ReverseEngineering(tree.getReverseEngineering());
        rootParent.lockToolbarButtons();
        for (TreePath path : paths) {
            selectedElement = (DbImportTreeNode) path.getLastPathComponent();
            parentElement = (DbImportTreeNode) selectedElement.getParent();
            if (parentElement != null) {
                Object parentUserObject = parentElement.getUserObject();
                if (parentUserObject instanceof ReverseEngineering) {
                    ReverseEngineering reverseEngineering = (ReverseEngineering) parentUserObject;
                    deleteChilds(reverseEngineering);
                } else if (parentUserObject instanceof Catalog) {
                    Catalog catalog = (Catalog) parentUserObject;
                    deleteChilds(catalog);
                } else if (parentUserObject instanceof Schema) {
                    Schema schema = (Schema) parentUserObject;
                    deleteChilds(schema);
                } else if (parentUserObject instanceof IncludeTable) {
                    IncludeTable includeTable = (IncludeTable) parentUserObject;
                    deleteChilds(includeTable);
                }
            }
        }
        if (paths.length > 1) {
            getProjectController().setDirty(true);
            ArrayList<DbImportTreeNode> expandList = tree.getTreeExpandList();
            tree.translateReverseEngineeringToTree(tree.getReverseEngineering(), false);
            tree.expandTree(expandList);
        } else {
            updateParentChilds();
        }
        putReverseEngineeringToUndoManager(reverseEngineeringOldCopy);
        rootParent.getLoadDbSchemaButton().setEnabled(true);
        rootParent.getReverseEngineeringProgress().setVisible(false);
    }
}
Also used : DbImportView(org.apache.cayenne.modeler.editor.dbimport.DbImportView) TreePath(javax.swing.tree.TreePath) ReverseEngineering(org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering) DbImportTreeNode(org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode) Schema(org.apache.cayenne.dbsync.reverse.dbimport.Schema) IncludeTable(org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable) Catalog(org.apache.cayenne.dbsync.reverse.dbimport.Catalog)

Aggregations

DbImportView (org.apache.cayenne.modeler.editor.dbimport.DbImportView)4 DbImportTreeNode (org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode)3 TreePath (javax.swing.tree.TreePath)2 Catalog (org.apache.cayenne.dbsync.reverse.dbimport.Catalog)2 IncludeTable (org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable)2 ReverseEngineering (org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering)2 Schema (org.apache.cayenne.dbsync.reverse.dbimport.Schema)2 SQLException (java.sql.SQLException)1 JScrollPane (javax.swing.JScrollPane)1 CodeGeneratorController (org.apache.cayenne.modeler.editor.cgen.CodeGeneratorController)1 CgenTab (org.apache.cayenne.modeler.editor.cgen.domain.CgenTab)1 DbImportTab (org.apache.cayenne.modeler.editor.dbimport.domain.DbImportTab)1 DBConnectionInfo (org.apache.cayenne.modeler.pref.DBConnectionInfo)1 DbImportTreeUndoableEdit (org.apache.cayenne.modeler.undo.DbImportTreeUndoableEdit)1