Search in sources :

Example 1 with DbImportTreeNode

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

the class AddSchemaAction method performAction.

@Override
public void performAction(ActionEvent e) {
    ReverseEngineering reverseEngineeringOldCopy = prepareElements();
    Schema newSchema = new Schema(name);
    if (canBeInserted(selectedElement)) {
        ((SchemaContainer) selectedElement.getUserObject()).addSchema(newSchema);
        selectedElement.add(new DbImportTreeNode(newSchema));
        updateSelected = true;
    } else if (canInsert()) {
        if (parentElement.isReverseEngineering()) {
            ((ReverseEngineering) parentElement.getUserObject()).addSchema(newSchema);
        } else {
            ((Catalog) parentElement.getUserObject()).addSchema(newSchema);
        }
        parentElement.add(new DbImportTreeNode(newSchema));
        updateSelected = false;
    }
    completeInserting(reverseEngineeringOldCopy);
}
Also used : SchemaContainer(org.apache.cayenne.dbsync.reverse.dbimport.SchemaContainer) 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)

Example 2 with DbImportTreeNode

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

the class TreeManipulationAction method updateAfterInsert.

void updateAfterInsert() {
    updateModel(updateSelected);
    if (!movedFromDbSchema) {
        if (updateSelected) {
            tree.startEditingAtPath(new TreePath(((DbImportTreeNode) selectedElement.getLastChild()).getPath()));
        } else {
            tree.startEditingAtPath(new TreePath(((DbImportTreeNode) parentElement.getLastChild()).getPath()));
        }
    }
    resetActionFlags();
}
Also used : TreePath(javax.swing.tree.TreePath) DbImportTreeNode(org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode)

Example 3 with DbImportTreeNode

use of org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode 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 4 with DbImportTreeNode

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

the class AddCatalogAction method performAction.

@Override
public void performAction(ActionEvent e) {
    ReverseEngineering reverseEngineeringOld = prepareElements();
    Catalog newCatalog = new Catalog(name);
    if (canBeInserted(selectedElement)) {
        ((ReverseEngineering) selectedElement.getUserObject()).addCatalog(newCatalog);
        selectedElement.add(new DbImportTreeNode(newCatalog));
        updateSelected = true;
    } else if (canInsert()) {
        ((ReverseEngineering) parentElement.getUserObject()).addCatalog(newCatalog);
        parentElement.add(new DbImportTreeNode(newCatalog));
        updateSelected = false;
    }
    completeInserting(reverseEngineeringOld);
}
Also used : ReverseEngineering(org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering) DbImportTreeNode(org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode) Catalog(org.apache.cayenne.dbsync.reverse.dbimport.Catalog)

Example 5 with DbImportTreeNode

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

the class AddPatternParamAction method addPatternParamToIncludeTable.

private void addPatternParamToIncludeTable(Class paramClass, Object selectedObject, String name, DbImportTreeNode node) {
    IncludeTable includeTable = (IncludeTable) selectedObject;
    PatternParam element = null;
    if (paramClass == IncludeColumn.class) {
        element = new IncludeColumn(name);
        includeTable.addIncludeColumn((IncludeColumn) element);
    } else if (paramClass == ExcludeColumn.class) {
        element = new ExcludeColumn(name);
        includeTable.addExcludeColumn((ExcludeColumn) element);
    }
    node.add(new DbImportTreeNode(element));
}
Also used : PatternParam(org.apache.cayenne.dbsync.reverse.dbimport.PatternParam) DbImportTreeNode(org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode) IncludeTable(org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable) ExcludeColumn(org.apache.cayenne.dbsync.reverse.dbimport.ExcludeColumn) IncludeColumn(org.apache.cayenne.dbsync.reverse.dbimport.IncludeColumn)

Aggregations

DbImportTreeNode (org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode)34 IncludeTable (org.apache.cayenne.dbsync.reverse.dbimport.IncludeTable)10 ReverseEngineering (org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering)10 TreePath (javax.swing.tree.TreePath)9 Catalog (org.apache.cayenne.dbsync.reverse.dbimport.Catalog)7 Schema (org.apache.cayenne.dbsync.reverse.dbimport.Schema)7 TransferableNode (org.apache.cayenne.modeler.dialog.db.load.TransferableNode)7 IncludeColumn (org.apache.cayenne.dbsync.reverse.dbimport.IncludeColumn)5 ExcludeTable (org.apache.cayenne.dbsync.reverse.dbimport.ExcludeTable)3 FilterContainer (org.apache.cayenne.dbsync.reverse.dbimport.FilterContainer)3 PatternParam (org.apache.cayenne.dbsync.reverse.dbimport.PatternParam)3 DbImportView (org.apache.cayenne.modeler.editor.dbimport.DbImportView)3 ArrayList (java.util.ArrayList)2 TreeExpansionEvent (javax.swing.event.TreeExpansionEvent)2 TreeExpansionListener (javax.swing.event.TreeExpansionListener)2 ExcludeColumn (org.apache.cayenne.dbsync.reverse.dbimport.ExcludeColumn)2 LoadDbSchemaAction (org.apache.cayenne.modeler.action.LoadDbSchemaAction)2 FlowLayout (java.awt.FlowLayout)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1