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();
}
});
}
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();
}
}
}
}
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();
}
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);
}
}
Aggregations