Search in sources :

Example 6 with DBeaverCore

use of org.jkiss.dbeaver.core.DBeaverCore in project dbeaver by serge-rider.

the class SelectDataSourceDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    getShell().setText(CoreMessages.dialog_select_datasource_title);
    Composite group = (Composite) super.createDialogArea(parent);
    GridData gd = new GridData(GridData.FILL_BOTH);
    group.setLayoutData(gd);
    DBeaverCore core = DBeaverCore.getInstance();
    DBNNode rootNode = null;
    if (project != null) {
        DBNProject projectNode = core.getNavigatorModel().getRoot().getProject(project);
        if (projectNode != null) {
            rootNode = projectNode.getDatabases();
        }
    }
    if (rootNode == null) {
        rootNode = core.getNavigatorModel().getRoot();
    }
    DatabaseNavigatorTree dataSourceTree = new DatabaseNavigatorTree(group, rootNode, SWT.SINGLE | SWT.BORDER, false);
    dataSourceTree.setLayoutData(new GridData(GridData.FILL_BOTH));
    final Text descriptionText = new Text(group, SWT.READ_ONLY);
    descriptionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    dataSourceTree.getViewer().addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return element instanceof DBNProject || element instanceof DBNProjectDatabases || element instanceof DBNLocalFolder || element instanceof DBNDataSource;
        }
    });
    dataSourceTree.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection structSel = (IStructuredSelection) event.getSelection();
            Object selNode = structSel.isEmpty() ? null : structSel.getFirstElement();
            if (selNode instanceof DBNDataSource) {
                dataSource = ((DBNDataSource) selNode).getObject();
                getButton(IDialogConstants.OK_ID).setEnabled(true);
                String description = dataSource.getDescription();
                if (description == null) {
                    description = dataSource.getName();
                }
                descriptionText.setText(description);
            } else {
                dataSource = null;
                getButton(IDialogConstants.OK_ID).setEnabled(false);
            }
        }
    });
    dataSourceTree.getViewer().addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (getButton(IDialogConstants.OK_ID).isEnabled()) {
                okPressed();
            }
        }
    });
    return group;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Text(org.eclipse.swt.widgets.Text) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) DBeaverCore(org.jkiss.dbeaver.core.DBeaverCore) GridData(org.eclipse.swt.layout.GridData)

Example 7 with DBeaverCore

use of org.jkiss.dbeaver.core.DBeaverCore in project dbeaver by serge-rider.

the class KeepAliveJob method run.

@Override
protected IStatus run(DBRProgressMonitor monitor) {
    if (DBeaverCore.isClosing()) {
        return Status.OK_STATUS;
    }
    final DBeaverCore core = DBeaverCore.getInstance();
    final ProjectRegistry projectRegistry = core.getProjectRegistry();
    if (projectRegistry == null) {
        return Status.OK_STATUS;
    }
    for (DataSourceDescriptor ds : DataSourceRegistry.getAllDataSources()) {
        checkDataSourceAlive(monitor, ds);
    }
    if (!DBeaverCore.isClosing()) {
        scheduleMonitor();
    }
    return Status.OK_STATUS;
}
Also used : DBeaverCore(org.jkiss.dbeaver.core.DBeaverCore) ProjectRegistry(org.jkiss.dbeaver.registry.ProjectRegistry) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Aggregations

DBeaverCore (org.jkiss.dbeaver.core.DBeaverCore)7 GridData (org.eclipse.swt.layout.GridData)3 DatabaseNavigatorTree (org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 SashForm (org.eclipse.swt.custom.SashForm)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)2 ProjectRegistry (org.jkiss.dbeaver.registry.ProjectRegistry)2 TreeLoadNode (org.jkiss.dbeaver.ui.navigator.database.load.TreeLoadNode)2 ArrayList (java.util.ArrayList)1 IStatus (org.eclipse.core.runtime.IStatus)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Composite (org.eclipse.swt.widgets.Composite)1 Text (org.eclipse.swt.widgets.Text)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 PartInitException (org.eclipse.ui.PartInitException)1