Search in sources :

Example 31 with DBPProject

use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.

the class KeepAliveListenerJob method run.

@Override
protected IStatus run(DBRProgressMonitor monitor) {
    if (platform.isShuttingDown()) {
        return Status.OK_STATUS;
    }
    if (lastPingTime > 0 && System.currentTimeMillis() - lastPingTime > SYSTEM_SUSPEND_INTERVAL) {
        log.debug("System suspend detected! Reinitialize all remote connections.");
    }
    lastPingTime = System.currentTimeMillis();
    final DBPWorkspace workspace = platform.getWorkspace();
    for (DBPProject project : workspace.getProjects()) {
        if (project.isOpen() && project.isRegistryLoaded()) {
            DBPDataSourceRegistry dataSourceRegistry = project.getDataSourceRegistry();
            for (DBPDataSourceContainer ds : dataSourceRegistry.getDataSources()) {
                checkDataSourceAlive(ds);
            }
        }
    }
    if (!platform.isShuttingDown()) {
        scheduleMonitor();
    }
    return Status.OK_STATUS;
}
Also used : DBPWorkspace(org.jkiss.dbeaver.model.app.DBPWorkspace) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPDataSourceRegistry(org.jkiss.dbeaver.model.app.DBPDataSourceRegistry) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 32 with DBPProject

use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.

the class QueryLogViewer method openSelectionInEditor.

private void openSelectionInEditor() {
    DBPDataSourceContainer dsContainer = null;
    StringBuilder sql = new StringBuilder();
    TableItem[] items = logTable.getSelection();
    for (TableItem item : items) {
        QMMetaEvent event = (QMMetaEvent) item.getData();
        QMMObject object = event.getObject();
        if (object instanceof QMMStatementExecuteInfo) {
            QMMStatementExecuteInfo stmtExec = (QMMStatementExecuteInfo) object;
            if (dsContainer == null) {
                QMMSessionInfo session = stmtExec.getStatement().getSession();
                DBPProject project = session.getProject();
                String containerId = session.getContainerId();
                if (project != null) {
                    dsContainer = project.getDataSourceRegistry().getDataSource(containerId);
                } else {
                    dsContainer = DBUtils.findDataSource(containerId);
                }
            }
            String queryString = stmtExec.getQueryString();
            if (!CommonUtils.isEmptyTrimmed(queryString)) {
                if (sql.length() > 0) {
                    // $NON-NLS-1$
                    sql.append("\n");
                }
                queryString = queryString.trim();
                sql.append(queryString);
                if (!queryString.endsWith(SQLConstants.DEFAULT_STATEMENT_DELIMITER)) {
                    // $NON-NLS-1$
                    sql.append(SQLConstants.DEFAULT_STATEMENT_DELIMITER).append("\n");
                }
            }
        }
    }
    if (sql.length() > 0) {
        SQLEditorHandlerOpenEditor.openSQLConsole(UIUtils.getActiveWorkbenchWindow(), new SQLNavigatorContext(dsContainer), // $NON-NLS-1$
        "QueryManager", sql.toString());
    }
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject) SQLNavigatorContext(org.jkiss.dbeaver.ui.editors.sql.handlers.SQLNavigatorContext) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 33 with DBPProject

use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.

the class SQLEditor method createPartControl.

@Override
public void createPartControl(Composite parent) {
    setRangeIndicator(new DefaultRangeIndicator());
    // divides editor area and results/panels area
    resultsSash = UIUtils.createPartDivider(this, parent, resultSetOrientation.getSashOrientation() | SWT.SMOOTH);
    CSSUtils.setCSSClass(resultsSash, DBStyles.COLORED_BY_CONNECTION_TYPE);
    resultsSash.setSashWidth(5);
    UIUtils.setHelp(resultsSash, IHelpContextIds.CTX_SQL_EDITOR);
    Composite editorContainer;
    sqlEditorPanel = UIUtils.createPlaceholder(resultsSash, 3, 0);
    // Create left vertical toolbar
    createControlsBar(sqlEditorPanel);
    // Create editor presentations sash
    Composite pPlaceholder = null;
    if (extraPresentationDescriptor != null) {
        presentationSash = UIUtils.createPartDivider(this, sqlEditorPanel, ((resultSetOrientation.getSashOrientation() == SWT.VERTICAL) ? SWT.HORIZONTAL : SWT.VERTICAL) | SWT.SMOOTH);
        presentationSash.setSashWidth(5);
        presentationSash.setLayoutData(new GridData(GridData.FILL_BOTH));
        editorContainer = presentationSash;
        pPlaceholder = new Composite(presentationSash, SWT.NONE);
        pPlaceholder.setLayout(new FillLayout());
    } else {
        editorContainer = sqlEditorPanel;
    }
    super.createPartControl(editorContainer);
    getEditorControlWrapper().setLayoutData(new GridData(GridData.FILL_BOTH));
    // Create right vertical toolbar
    createPresentationSwitchBar(sqlEditorPanel);
    if (pPlaceholder != null) {
        switch(extraPresentationDescriptor.getActivationType()) {
            case HIDDEN:
                presentationSash.setMaximizedControl(presentationSash.getChildren()[SQL_EDITOR_CONTROL_INDEX]);
                break;
            case MAXIMIZED:
            case VISIBLE:
                extraPresentation.createPresentation(pPlaceholder, this);
                if (extraPresentationDescriptor.getActivationType() == SQLEditorPresentation.ActivationType.MAXIMIZED) {
                    if (presentationSash.getChildren()[EXTRA_CONTROL_INDEX] != null) {
                        presentationSash.setMaximizedControl(pPlaceholder);
                    }
                }
                break;
        }
    }
    getSite().setSelectionProvider(new DynamicSelectionProvider());
    DBPProject project = getProject();
    if (project != null && project.isRegistryLoaded()) {
        createResultTabs();
    } else {
        UIExecutionQueue.queueExec(this::createResultTabs);
    }
    setAction(ITextEditorActionConstants.SHOW_INFORMATION, null);
    SourceViewer viewer = getViewer();
    if (viewer != null) {
        StyledText textWidget = viewer.getTextWidget();
        if (textWidget != null) {
            textWidget.addModifyListener(this::onTextChange);
            textWidget.addFocusListener(new FocusAdapter() {

                @Override
                public void focusGained(FocusEvent e) {
                    refreshActions();
                }
            });
        }
    }
    SQLEditorFeatures.SQL_EDITOR_OPEN.use();
    // Start output reader
    new ServerOutputReader().schedule();
    updateExecutionContext(null);
    // Update controls
    UIExecutionQueue.queueExec(this::onDataSourceChange);
}
Also used : DefaultRangeIndicator(org.eclipse.ui.texteditor.DefaultRangeIndicator) SourceViewer(org.eclipse.jface.text.source.SourceViewer) StyledText(org.eclipse.swt.custom.StyledText) GridData(org.eclipse.swt.layout.GridData) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) FillLayout(org.eclipse.swt.layout.FillLayout) DefaultServerOutputReader(org.jkiss.dbeaver.model.impl.DefaultServerOutputReader)

Example 34 with DBPProject

use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.

the class ApplicationWorkbenchWindowAdvisor method computeTitle.

private String computeTitle() {
    // Use hardcoded pref constants to avoid E4.7 compile dependency
    IPreferenceStore ps = IDEWorkbenchPlugin.getDefault().getPreferenceStore();
    // $NON-NLS-1$
    StringJoiner sj = new StringJoiner(" - ");
    if (ps.getBoolean("SHOW_LOCATION_NAME")) {
        String workspaceName = ps.getString("WORKSPACE_NAME");
        if (workspaceName != null && workspaceName.length() > 0) {
            sj.add(workspaceName);
        }
    }
    if (ps.getBoolean("SHOW_LOCATION")) {
        String workspaceLocation = Platform.getLocation().toOSString();
        sj.add(workspaceLocation);
    }
    if (ps.getBoolean("SHOW_PERSPECTIVE_IN_TITLE")) {
        DBPProject activeProject = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
        if (activeProject != null) {
            // $NON-NLS-1$
            sj.add(activeProject.getName());
        }
    }
    if (ps.getBoolean("SHOW_PRODUCT_IN_TITLE")) {
        sj.add(GeneralUtils.getProductTitle());
    }
    IWorkbenchWindow window = getWindowConfigurer().getWindow();
    if (window != null) {
        IWorkbenchPage activePage = window.getActivePage();
        if (activePage != null) {
            IEditorPart activeEditor = activePage.getActiveEditor();
            if (activeEditor != null) {
                sj.add(activeEditor.getTitle());
            }
        }
    }
    return sj.toString();
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) StringJoiner(java.util.StringJoiner)

Example 35 with DBPProject

use of org.jkiss.dbeaver.model.app.DBPProject in project dbeaver by dbeaver.

the class NavigatorActiveProjectContributor method createMenu.

private void createMenu(final Menu menu) {
    final DBPProject activeProject = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
    for (final DBPProject project : DBWorkbench.getPlatform().getWorkspace().getProjects()) {
        MenuItem txnItem = new MenuItem(menu, SWT.RADIO);
        txnItem.setText(project.getName());
        txnItem.setSelection(project == activeProject);
        txnItem.setData(project);
        txnItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                NavigatorHandlerProjectSetActive.setActiveProject(project);
            }
        });
    }
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) MenuItem(org.eclipse.swt.widgets.MenuItem)

Aggregations

DBPProject (org.jkiss.dbeaver.model.app.DBPProject)90 IFile (org.eclipse.core.resources.IFile)20 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)18 DBException (org.jkiss.dbeaver.DBException)14 DBPDataSourceRegistry (org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)14 IFolder (org.eclipse.core.resources.IFolder)8 DBPWorkspace (org.jkiss.dbeaver.model.app.DBPWorkspace)8 IResource (org.eclipse.core.resources.IResource)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 IEditorPart (org.eclipse.ui.IEditorPart)6 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)6 GridData (org.eclipse.swt.layout.GridData)5 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ArrayList (java.util.ArrayList)4 CoreException (org.eclipse.core.runtime.CoreException)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 DBPImage (org.jkiss.dbeaver.model.DBPImage)4 Document (org.w3c.dom.Document)4