Search in sources :

Example 1 with DbImportTreeUndoableEdit

use of org.apache.cayenne.modeler.undo.DbImportTreeUndoableEdit in project cayenne by apache.

the class TreeManipulationAction method putReverseEngineeringToUndoManager.

protected void putReverseEngineeringToUndoManager(ReverseEngineering reverseEngineeringOldCopy) {
    ReverseEngineering reverseEngineeringNewCopy = new ReverseEngineering(tree.getReverseEngineering());
    DbImportTreeUndoableEdit undoableEdit = new DbImportTreeUndoableEdit(reverseEngineeringOldCopy, reverseEngineeringNewCopy, tree, getProjectController());
    getProjectController().getApplication().getUndoManager().addEdit(undoableEdit);
}
Also used : DbImportTreeUndoableEdit(org.apache.cayenne.modeler.undo.DbImportTreeUndoableEdit) ReverseEngineering(org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering)

Example 2 with DbImportTreeUndoableEdit

use of org.apache.cayenne.modeler.undo.DbImportTreeUndoableEdit 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)

Aggregations

ReverseEngineering (org.apache.cayenne.dbsync.reverse.dbimport.ReverseEngineering)2 DbImportTreeUndoableEdit (org.apache.cayenne.modeler.undo.DbImportTreeUndoableEdit)2 TreePath (javax.swing.tree.TreePath)1 DbImportTreeNode (org.apache.cayenne.modeler.dialog.db.load.DbImportTreeNode)1 DbImportView (org.apache.cayenne.modeler.editor.dbimport.DbImportView)1