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 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.DBNModel in project dbeaver by serge-rider.
the class DatabaseEditorInputFactory method createElement.
@Override
public IAdaptable createElement(IMemento memento) {
// Get the node path.
final String inputClass = memento.getString(TAG_CLASS);
final String nodePath = memento.getString(TAG_NODE);
final String nodeName = memento.getString(TAG_NODE_NAME);
final String dataSourceId = memento.getString(TAG_DATA_SOURCE);
if (nodePath == null || inputClass == null || dataSourceId == null) {
//$NON-NLS-2$
log.error("Corrupted memento");
return null;
}
final String activePageId = memento.getString(TAG_ACTIVE_PAGE);
final String activeFolderId = memento.getString(TAG_ACTIVE_FOLDER);
final DBPDataSourceContainer dataSourceContainer = DataSourceRegistry.findDataSource(dataSourceId);
if (dataSourceContainer == null) {
//$NON-NLS-2$
log.error("Can't find data source '" + dataSourceId + "'");
return null;
}
if (lookupEditor && !dataSourceContainer.isConnected()) {
//. for some object. Connection must be instantiated.
return null;
}
final IProject project = dataSourceContainer.getRegistry().getProject();
final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
navigatorModel.ensureProjectLoaded(project);
return new DatabaseLazyEditorInput(dataSourceContainer, project, nodePath, nodeName, activePageId, activeFolderId);
}
use of org.jkiss.dbeaver.model.navigator.DBNModel in project dbeaver by serge-rider.
the class DatabaseLazyEditorInput method initializeRealInput.
public IDatabaseEditorInput initializeRealInput(final DBRProgressMonitor monitor) throws DBException {
final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
while (!dataSource.isConnected()) {
boolean connected;
try {
connected = dataSource.connect(monitor, true, true);
} catch (final DBException e) {
// Connection error
final Integer result = new UITask<Integer>() {
@Override
protected Integer runTask() {
ConnectionLostDialog clDialog = new ConnectionLostDialog(DBeaverUI.getActiveWorkbenchShell(), dataSource, e, "Close");
return clDialog.open();
}
}.execute();
if (result == IDialogConstants.STOP_ID) {
// Close editor
return null;
} else if (result == IDialogConstants.RETRY_ID) {
continue;
} else {
return new ErrorEditorInput(GeneralUtils.makeExceptionStatus(e), navigatorModel.getNodeByObject(dataSource));
}
}
if (!connected) {
throw new DBException("Connection to '" + dataSource.getName() + "' canceled");
}
break;
}
try {
DBNDataSource dsNode = (DBNDataSource) navigatorModel.getNodeByObject(monitor, dataSource, true);
if (dsNode == null) {
throw new DBException("Datasource '" + dataSource.getName() + "' navigator node not found");
}
dsNode.initializeNode(monitor, null);
final DBNNode node = navigatorModel.getNodeByPath(monitor, project, nodePath);
if (node == null) {
throw new DBException("Navigator node '" + nodePath + "' not found");
}
if (node instanceof DBNDatabaseNode) {
EntityEditorInput realInput = new EntityEditorInput((DBNDatabaseNode) node);
realInput.setDefaultFolderId(activeFolderId);
realInput.setDefaultPageId(activePageId);
return realInput;
} else {
throw new DBException("Database node has bad type: " + node.getClass().getName());
}
} catch (DBException e) {
return new ErrorEditorInput(GeneralUtils.makeExceptionStatus(e), navigatorModel.getNodeByObject(dataSource));
}
}
use of org.jkiss.dbeaver.model.navigator.DBNModel in project dbeaver by serge-rider.
the class NodeEditorInputFactory method createElement.
@Override
public IAdaptable createElement(IMemento memento) {
// Get the node path.
final String nodePath = memento.getString(TAG_NODE);
if (nodePath == null) {
return null;
}
final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
try {
final DBNNode node = navigatorModel.getNodeByPath(VoidProgressMonitor.INSTANCE, nodePath);
if (node != null) {
return new NodeEditorInput(node);
}
} catch (DBException e) {
log.error("Error opening node '" + nodePath + "'", e);
return null;
}
return null;
}
Aggregations