use of org.jkiss.dbeaver.model.navigator.DBNModel in project dbeaver by serge-rider.
the class NavigatorHandlerObjectBase method getNodeByObject.
public static DBNDatabaseNode getNodeByObject(DBSObject object) {
DBNModel model = DBeaverCore.getInstance().getNavigatorModel();
DBNDatabaseNode node = model.findNode(object);
if (node == null) {
NodeLoader nodeLoader = new NodeLoader(model, Collections.singleton(object));
try {
DBeaverUI.runInProgressService(nodeLoader);
} catch (InvocationTargetException e) {
log.warn("Can't load node for object '" + object.getName() + "'", e.getTargetException());
} catch (InterruptedException e) {
// do nothing
}
if (!nodeLoader.nodes.isEmpty()) {
node = nodeLoader.nodes.get(0);
}
}
return node;
}
use of org.jkiss.dbeaver.model.navigator.DBNModel in project dbeaver by serge-rider.
the class NavigatorHandlerObjectBase method getNodesByObjects.
public static Collection<DBNDatabaseNode> getNodesByObjects(Collection<Object> objects) {
DBNModel model = DBeaverCore.getInstance().getNavigatorModel();
List<DBNDatabaseNode> result = new ArrayList<>();
List<Object> missingObjects = new ArrayList<>();
for (Object object : objects) {
if (object instanceof DBSObject) {
DBNDatabaseNode node = model.findNode((DBSObject) object);
if (node != null) {
result.add(node);
continue;
}
}
missingObjects.add(object);
}
if (!missingObjects.isEmpty()) {
NodeLoader nodeLoader = new NodeLoader(model, missingObjects);
try {
DBeaverUI.runInProgressService(nodeLoader);
} catch (InvocationTargetException e) {
log.warn("Can't load node for objects " + missingObjects.size(), e.getTargetException());
} catch (InterruptedException e) {
// do nothing
}
result.addAll(nodeLoader.nodes);
}
return result;
}
use of org.jkiss.dbeaver.model.navigator.DBNModel in project dbeaver by serge-rider.
the class SearchDataQuery method run.
@Override
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
try {
String searchString = params.getSearchString();
//monitor.subTask("Collect tables");
Set<DBPDataSource> dataSources = new HashSet<>();
for (DBSDataContainer searcher : params.sources) {
dataSources.add(searcher.getDataSource());
}
// Search
DBNModel dbnModel = DBeaverCore.getInstance().getNavigatorModel();
monitor.beginTask("Search \"" + searchString + "\" in " + params.sources.size() + " table(s) / " + dataSources.size() + " database(s)", params.sources.size());
try {
for (DBSDataContainer dataContainer : params.sources) {
if (monitor.isCanceled()) {
break;
}
String objectName = DBUtils.getObjectFullName(dataContainer, DBPEvaluationContext.DML);
DBNDatabaseNode node = dbnModel.findNode(dataContainer);
if (node == null) {
log.warn("Can't find tree node for object \"" + objectName + "\"");
continue;
}
monitor.subTask(objectName);
DBPDataSource dataSource = dataContainer.getDataSource();
if (dataSource == null) {
log.warn("Object \"" + objectName + "\" not connected");
continue;
}
SearchTableMonitor searchMonitor = new SearchTableMonitor();
try (DBCSession session = DBUtils.openUtilSession(searchMonitor, dataSource, "Search rows in " + objectName)) {
TestDataReceiver dataReceiver = new TestDataReceiver(searchMonitor);
findRows(session, dataContainer, dataReceiver);
if (dataReceiver.rowCount > 0) {
SearchDataObject object = new SearchDataObject(node, dataReceiver.rowCount, dataReceiver.filter);
searchResult.addObjects(Collections.singletonList(object));
}
}
monitor.worked(1);
}
} finally {
monitor.done();
}
return Status.OK_STATUS;
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
}
use of org.jkiss.dbeaver.model.navigator.DBNModel in project dbeaver by serge-rider.
the class DBeaverCore method initialize.
private void initialize() {
long startTime = System.currentTimeMillis();
log.debug("Initialize Core...");
// Register properties adapter
this.workspace = ResourcesPlugin.getWorkspace();
this.localSystem = new OSDescriptor(Platform.getOS(), Platform.getOSArch());
QMUtils.initApplication(this);
this.queryManager = new QMControllerImpl();
this.qmLogWriter = new QMLogFileWriter();
this.queryManager.registerMetaListener(qmLogWriter);
// Init default network settings
Authenticator.setDefault(new GlobalProxyAuthenticator());
ProxySelector.setDefault(new GlobalProxySelector(ProxySelector.getDefault()));
this.certificateStorage = new DefaultCertificateStorage(new File(DBeaverActivator.getInstance().getStateLocation().toFile(), "security"));
// Init project registry
this.projectRegistry = new ProjectRegistry(workspace);
// Projects registry
initializeProjects();
// Navigator model
this.navigatorModel = new DBNModel(this);
this.navigatorModel.initialize();
// Activate plugin services
for (IPluginService pluginService : PluginServiceRegistry.getInstance().getServices()) {
try {
pluginService.activateService();
activatedServices.add(pluginService);
} catch (Throwable e) {
log.error("Error activating plugin service", e);
}
}
// Keep-alive job
new KeepAliveJob().scheduleMonitor();
log.debug("Core initialized (" + (System.currentTimeMillis() - startTime) + "ms)");
}
use of org.jkiss.dbeaver.model.navigator.DBNModel in project dbeaver by serge-rider.
the class DatabaseConsumerPageMapping method createControl.
@Override
public void createControl(Composite parent) {
initializeDialogUnits(parent);
final DatabaseConsumerSettings settings = getWizard().getPageSettings(this, DatabaseConsumerSettings.class);
Composite composite = new Composite(parent, SWT.NULL);
GridLayout gl = new GridLayout();
gl.marginHeight = 0;
gl.marginWidth = 0;
composite.setLayout(gl);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
{
// Target container
Composite containerPanel = new Composite(composite, SWT.NONE);
containerPanel.setLayout(new GridLayout(4, false));
containerPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
UIUtils.createControlLabel(containerPanel, "Target container");
containerIcon = new Label(containerPanel, SWT.NONE);
containerIcon.setImage(DBeaverIcons.getImage(DBIcon.TYPE_UNKNOWN));
containerName = new Text(containerPanel, SWT.BORDER | SWT.READ_ONLY);
containerName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
containerName.setText("");
Button browseButton = new Button(containerPanel, SWT.PUSH);
browseButton.setImage(DBeaverIcons.getImage(DBIcon.TREE_FOLDER));
browseButton.setText("...");
browseButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IProject activeProject = DBeaverCore.getInstance().getProjectRegistry().getActiveProject();
if (activeProject != null) {
final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
final DBNProject rootNode = navigatorModel.getRoot().getProject(activeProject);
DBNNode selectedNode = settings.getContainerNode();
if (selectedNode == null && !settings.getDataMappings().isEmpty()) {
// Use first source object as cur selection (it's better than nothing)
DBSDataContainer firstSource = settings.getDataMappings().keySet().iterator().next();
selectedNode = navigatorModel.getNodeByObject(firstSource);
while (selectedNode != null) {
if (selectedNode instanceof DBSWrapper && ((DBSWrapper) selectedNode).getObject() instanceof DBSObjectContainer) {
break;
} else {
selectedNode = selectedNode.getParentNode();
}
}
}
DBNNode node = BrowseObjectDialog.selectObject(getShell(), "Choose container", rootNode.getDatabases(), selectedNode, new Class[] { DBSObjectContainer.class }, null);
if (node instanceof DBNDatabaseNode) {
settings.setContainerNode((DBNDatabaseNode) node);
containerIcon.setImage(DBeaverIcons.getImage(node.getNodeIconDefault()));
containerName.setText(settings.getContainerFullName());
// Reset mappings
for (DatabaseMappingContainer mappingContainer : settings.getDataMappings().values()) {
if (mappingContainer.getMappingType() == DatabaseMappingType.create) {
try {
mappingContainer.refreshMappingType(getContainer(), DatabaseMappingType.create);
} catch (DBException e1) {
log.error(e1);
}
}
}
mappingViewer.refresh();
updatePageCompletion();
}
}
}
});
}
createMappingsTree(composite);
{
// Control buttons
Composite buttonsPanel = new Composite(composite, SWT.NONE);
buttonsPanel.setLayout(new GridLayout(4, false));
buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
final Button mapTableButton = new Button(buttonsPanel, SWT.PUSH);
mapTableButton.setImage(DBeaverIcons.getImage(DBIcon.TREE_TABLE));
mapTableButton.setText("Existing table ...");
mapTableButton.setEnabled(false);
mapTableButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
mapExistingTable((DatabaseMappingContainer) getSelectedMapping());
}
});
final Button createNewButton = new Button(buttonsPanel, SWT.PUSH);
createNewButton.setImage(DBeaverIcons.getImage(DBIcon.TREE_VIEW));
createNewButton.setText("New table...");
createNewButton.setEnabled(false);
createNewButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
mapNewTable((DatabaseMappingContainer) getSelectedMapping());
}
});
final Button columnsButton = new Button(buttonsPanel, SWT.PUSH);
columnsButton.setImage(DBeaverIcons.getImage(DBIcon.TREE_COLUMNS));
columnsButton.setText("Columns' mappings ...");
columnsButton.setEnabled(false);
columnsButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DatabaseMappingObject selectedMapping = getSelectedMapping();
mapColumns(selectedMapping instanceof DatabaseMappingContainer ? (DatabaseMappingContainer) selectedMapping : ((DatabaseMappingAttribute) selectedMapping).getParent());
}
});
final Button ddlButton = new Button(buttonsPanel, SWT.PUSH);
ddlButton.setImage(DBeaverIcons.getImage(UIIcon.SQL_TEXT));
ddlButton.setText("DDL ...");
ddlButton.setEnabled(false);
ddlButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DatabaseMappingObject selectedMapping = getSelectedMapping();
showDDL(selectedMapping instanceof DatabaseMappingContainer ? (DatabaseMappingContainer) selectedMapping : ((DatabaseMappingAttribute) selectedMapping).getParent());
}
});
mappingViewer.getTree().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
try {
boolean updated = false;
Object element = null;
if (e.character == SWT.CR) {
//Object element = mappingViewer.getStructuredSelection().getFirstElement();
//mappingViewer.editElement(element, 1);
} else if (e.character == SWT.DEL) {
for (TreeItem item : mappingViewer.getTree().getSelection()) {
element = item.getData();
if (element instanceof DatabaseMappingAttribute) {
DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) element;
attribute.setMappingType(DatabaseMappingType.skip);
} else if (element instanceof DatabaseMappingContainer) {
DatabaseMappingContainer container = (DatabaseMappingContainer) element;
container.refreshMappingType(getContainer(), DatabaseMappingType.skip);
}
}
updated = true;
} else if (e.character == SWT.SPACE) {
for (TreeItem item : mappingViewer.getTree().getSelection()) {
element = item.getData();
if (element instanceof DatabaseMappingAttribute) {
DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) item.getData();
attribute.setMappingType(DatabaseMappingType.existing);
attribute.updateMappingType(VoidProgressMonitor.INSTANCE);
} else if (element instanceof DatabaseMappingContainer) {
DatabaseMappingContainer container = (DatabaseMappingContainer) element;
setMappingTarget(container, container.getSource().getName());
}
}
updated = true;
}
if (updated) {
mappingViewer.refresh();
updatePageCompletion();
if (element instanceof DatabaseMappingContainer) {
// Select next container
@SuppressWarnings("unchecked") List<DatabaseMappingContainer> model = (List<DatabaseMappingContainer>) mappingViewer.getInput();
int curIndex = model.indexOf(element);
if (curIndex < model.size() - 1) {
mappingViewer.setSelection(new StructuredSelection(model.get(curIndex + 1)), true);
}
}
}
} catch (DBException e1) {
UIUtils.showDatabaseError(getShell(), "Mapping error", "Error mapping table", e1);
}
}
});
mappingViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
DatabaseMappingObject mapping = getSelectedMapping();
mapTableButton.setEnabled(mapping instanceof DatabaseMappingContainer);
createNewButton.setEnabled(mapping instanceof DatabaseMappingContainer && settings.getContainerNode() != null);
final boolean hasMappings = (mapping instanceof DatabaseMappingContainer && mapping.getMappingType() != DatabaseMappingType.unspecified) || (mapping instanceof DatabaseMappingAttribute && ((DatabaseMappingAttribute) mapping).getParent().getMappingType() != DatabaseMappingType.unspecified);
columnsButton.setEnabled(hasMappings);
ddlButton.setEnabled(hasMappings);
}
});
mappingViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
DatabaseMappingObject selectedMapping = getSelectedMapping();
if (selectedMapping != null) {
if (selectedMapping instanceof DatabaseMappingContainer) {
/*
if (selectedMapping.getMappingType() == DatabaseMappingType.unspecified) {
mapExistingTable((DatabaseMappingContainer) selectedMapping);
} else {
mapColumns((DatabaseMappingContainer) selectedMapping);
}
*/
}
}
}
});
}
{
Composite hintPanel = new Composite(composite, SWT.NONE);
hintPanel.setLayout(new GridLayout(3, false));
hintPanel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
new Label(hintPanel, SWT.NONE).setText("* DEL - skip column(s) SPACE - map column(s)");
}
setControl(composite);
}
Aggregations