Search in sources :

Example 1 with DBNModel

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;
}
Also used : DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

Example 2 with DBNModel

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;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

Example 3 with DBNModel

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);
}
Also used : DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IProject(org.eclipse.core.resources.IProject) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

Example 4 with DBNModel

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));
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) UITask(org.jkiss.dbeaver.ui.UITask) ConnectionLostDialog(org.jkiss.dbeaver.ui.dialogs.ConnectionLostDialog) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) EntityEditorInput(org.jkiss.dbeaver.ui.editors.entity.EntityEditorInput) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

Example 5 with DBNModel

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;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) NodeEditorInput(org.jkiss.dbeaver.ui.editors.entity.NodeEditorInput) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

Aggregations

DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)10 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)6 DBException (org.jkiss.dbeaver.DBException)5 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)5 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 IProject (org.eclipse.core.resources.IProject)2 DBSDataContainer (org.jkiss.dbeaver.model.struct.DBSDataContainer)2 File (java.io.File)1 List (java.util.List)1 KeyAdapter (org.eclipse.swt.events.KeyAdapter)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)1 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)1 DefaultCertificateStorage (org.jkiss.dbeaver.model.impl.app.DefaultCertificateStorage)1