use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class DatabaseConsumerPageMapping method activatePage.
@Override
public void activatePage() {
final DatabaseConsumerSettings settings = getWizard().getPageSettings(this, DatabaseConsumerSettings.class);
settings.loadNode(getContainer());
DBNDatabaseNode containerNode = settings.getContainerNode();
if (containerNode != null) {
containerIcon.setImage(DBeaverIcons.getImage(containerNode.getNodeIconDefault()));
containerName.setText(containerNode.getNodeFullName());
}
if (mappingViewer.getInput() == null) {
Map<DBSDataContainer, DatabaseMappingContainer> dataMappings = settings.getDataMappings();
for (DataTransferPipe pipe : getWizard().getSettings().getDataPipes()) {
if (pipe.getProducer() == null) {
continue;
}
DBSDataContainer sourceObject = (DBSDataContainer) pipe.getProducer().getSourceObject();
if (!dataMappings.containsKey(sourceObject)) {
DatabaseMappingContainer mapping;
if (pipe.getConsumer() instanceof DatabaseTransferConsumer && ((DatabaseTransferConsumer) pipe.getConsumer()).getTargetObject() != null) {
try {
mapping = new DatabaseMappingContainer(getContainer(), sourceObject, ((DatabaseTransferConsumer) pipe.getConsumer()).getTargetObject());
} catch (DBException e) {
setMessage(e.getMessage(), IMessageProvider.ERROR);
mapping = new DatabaseMappingContainer(sourceObject);
}
} else {
mapping = new DatabaseMappingContainer(sourceObject);
}
dataMappings.put(sourceObject, mapping);
}
}
List<DatabaseMappingContainer> model = new ArrayList<>(dataMappings.values());
mappingViewer.setInput(model);
Tree table = mappingViewer.getTree();
int totalWidth = table.getClientArea().width;
TreeColumn[] columns = table.getColumns();
columns[0].setWidth(totalWidth * 40 / 100);
columns[1].setWidth(totalWidth * 40 / 100);
columns[2].setWidth(totalWidth * 20 / 100);
}
updatePageCompletion();
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class DataImportHandler method chooseProducer.
@Override
protected IDataTransferProducer chooseProducer(ExecutionEvent event, IDataTransferConsumer consumer) {
final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
final DBNNode rootNode = DBeaverCore.getInstance().getLiveProjects().size() == 1 ? navigatorModel.getRoot().getProject(DBeaverCore.getInstance().getProjectRegistry().getActiveProject()) : navigatorModel.getRoot();
DBNNode node = BrowseObjectDialog.selectObject(HandlerUtil.getActiveShell(event), "Select source container for '" + consumer.getTargetName() + "'", rootNode, null, new Class[] { DBSObjectContainer.class, DBSDataContainer.class }, new Class[] { DBSDataContainer.class });
if (node instanceof DBNDatabaseNode) {
DBSObject object = ((DBNDatabaseNode) node).getObject();
if (object instanceof DBSDataContainer) {
return new DatabaseTransferProducer((DBSDataContainer) object);
}
}
return null;
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class CompareObjectsExecutor method compareChildren.
private void compareChildren(DBRProgressMonitor monitor, List<DBNDatabaseNode> nodes) throws DBException, InterruptedException {
// Compare children
int nodeCount = nodes.size();
List<DBNDatabaseNode[]> allChildren = new ArrayList<>(nodeCount);
for (int i = 0; i < nodeCount; i++) {
DBNDatabaseNode node = nodes.get(i);
// Cache structure if possible
if (node.getObject() instanceof DBSObjectContainer) {
((DBSObjectContainer) node.getObject()).cacheStructure(monitor, DBSObjectContainer.STRUCT_ALL);
}
try {
DBNDatabaseNode[] children = node.getChildren(monitor);
allChildren.add(children);
} catch (Exception e) {
log.warn("Error reading child nodes for compare", e);
allChildren.add(null);
}
}
Set<String> allChildNames = new LinkedHashSet<>();
for (DBNDatabaseNode[] childList : allChildren) {
if (childList == null)
continue;
for (DBNDatabaseNode child : childList) {
DBXTreeNode meta = child.getMeta();
if (meta.isVirtual()) {
// Skip virtual nodes
continue;
}
if (settings.isSkipSystemObjects() && child.getObject() instanceof DBPSystemObject && ((DBPSystemObject) child.getObject()).isSystem()) {
// Skip system objects
continue;
}
allChildNames.add(child.getNodeName());
}
}
for (String childName : allChildNames) {
int[] childIndexes = new int[nodeCount];
for (int i = 0; i < nodeCount; i++) {
childIndexes[i] = -1;
DBNDatabaseNode[] childList = allChildren.get(i);
if (childList == null)
continue;
for (int k = 0; k < childList.length; k++) {
DBNDatabaseNode child = childList[k];
if (child.getNodeName().equals(childName)) {
childIndexes[i] = k;
break;
}
}
}
List<DBNDatabaseNode> nodesToCompare = new ArrayList<>(nodeCount);
for (int i = 0; i < nodeCount; i++) {
if (childIndexes[i] == -1) {
// Missing
} else {
for (int k = 0; k < nodeCount; k++) {
if (k != i && childIndexes[k] != childIndexes[i]) {
// Wrong index - add to report
break;
}
}
final DBNDatabaseNode[] childList = allChildren.get(i);
if (childList != null) {
nodesToCompare.add(childList[childIndexes[i]]);
}
}
}
// Compare children recursively
compareNodes(monitor, nodesToCompare);
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class CompareObjectsWizard method renderReport.
private void renderReport(DBRProgressMonitor monitor, CompareReport report) {
try {
File reportFile;
switch(settings.getOutputType()) {
case BROWSER:
reportFile = File.createTempFile("compare-report", ".html");
break;
default:
{
//"compare-report.html";
StringBuilder fileName = new StringBuilder("compare");
for (DBNDatabaseNode node : report.getNodes()) {
fileName.append("-").append(CommonUtils.escapeIdentifier(node.getName()));
}
fileName.append("-report.html");
reportFile = new File(settings.getOutputFolder(), fileName.toString());
break;
}
}
reportFile.deleteOnExit();
try (OutputStream outputStream = new FileOutputStream(reportFile)) {
monitor.beginTask("Render report", report.getReportLines().size());
CompareReportRenderer reportRenderer = new CompareReportRenderer();
reportRenderer.renderReport(monitor, report, getSettings(), outputStream);
monitor.done();
}
UIUtils.launchProgram(reportFile.getAbsolutePath());
} catch (IOException e) {
showError(e.getMessage());
log.error(e);
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by serge-rider.
the class NavigatorHandlerRefresh method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
//final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
final IWorkbenchPart workbenchPart = HandlerUtil.getActivePart(event);
INavigatorModelView navigatorView;
if (workbenchPart instanceof INavigatorModelView) {
navigatorView = (INavigatorModelView) workbenchPart;
} else {
navigatorView = workbenchPart.getAdapter(INavigatorModelView.class);
}
if (navigatorView == null) {
// Try to refresh as refreshable part
if (workbenchPart instanceof IRefreshablePart) {
((IRefreshablePart) workbenchPart).refreshPart(this, true);
}
return null;
}
final List<DBNNode> refreshObjects = new ArrayList<>();
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode rootNode = navigatorView.getRootNode();
if (rootNode == null) {
if (workbenchPart instanceof IEditorPart) {
if (((IEditorPart) workbenchPart).getEditorInput() instanceof IDatabaseEditorInput) {
rootNode = ((IDatabaseEditorInput) ((IEditorPart) workbenchPart).getEditorInput()).getNavigatorNode();
}
}
}
if (rootNode != null && rootNode.getParentNode() instanceof DBNDatabaseNode) {
refreshObjects.add(rootNode);
} else if (selection instanceof IStructuredSelection) {
final IStructuredSelection structSelection = (IStructuredSelection) selection;
for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
Object object = iter.next();
if (object instanceof DBNNode) {
refreshObjects.add((DBNNode) object);
}
}
}
// Refresh objects
if (!refreshObjects.isEmpty()) {
refreshNavigator(refreshObjects);
}
return null;
}
Aggregations