Search in sources :

Example 31 with IContributionManager

use of org.eclipse.jface.action.IContributionManager in project dbeaver by dbeaver.

the class MySQLSessionEditor method createSessionViewer.

@Override
protected SessionManagerViewer createSessionViewer(DBCExecutionContext executionContext, Composite parent) {
    return new SessionManagerViewer<MySQLSession>(this, parent, new MySQLSessionManager((MySQLDataSource) executionContext.getDataSource())) {

        private boolean hideSleeping;

        @Override
        protected void contributeToToolbar(DBAServerSessionManager sessionManager, IContributionManager contributionManager) {
            contributionManager.add(killSessionAction);
            contributionManager.add(terminateQueryAction);
            contributionManager.add(new Separator());
            contributionManager.add(new ControlContribution("MySQLSessionHideSleep") {

                @Override
                protected Control createControl(Composite parent) {
                    Button hideSleepingCheck = UIUtils.createCheckbox(parent, "Hide sleeping", "Show only active connections", hideSleeping, 0);
                    hideSleepingCheck.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            hideSleeping = hideSleepingCheck.getSelection();
                            refreshPart(MySQLSessionEditor.this, true);
                        }
                    });
                    return hideSleepingCheck;
                }
            });
            contributionManager.add(new Separator());
        }

        @Override
        protected void onSessionSelect(DBAServerSession session) {
            super.onSessionSelect(session);
            killSessionAction.setEnabled(session != null);
            terminateQueryAction.setEnabled(session != null && !CommonUtils.isEmpty(session.getActiveQuery()));
        }

        @Override
        public Map<String, Object> getSessionOptions() {
            if (hideSleeping) {
                return Collections.singletonMap(MySQLSessionManager.OPTION_HIDE_SLEEPING, true);
            }
            return super.getSessionOptions();
        }
    };
}
Also used : DBAServerSession(org.jkiss.dbeaver.model.admin.sessions.DBAServerSession) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ControlContribution(org.eclipse.jface.action.ControlContribution) SessionManagerViewer(org.jkiss.dbeaver.ui.views.session.SessionManagerViewer) Control(org.eclipse.swt.widgets.Control) MySQLDataSource(org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource) Button(org.eclipse.swt.widgets.Button) DBAServerSessionManager(org.jkiss.dbeaver.model.admin.sessions.DBAServerSessionManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MySQLSessionManager(org.jkiss.dbeaver.ext.mysql.model.session.MySQLSessionManager) IContributionManager(org.eclipse.jface.action.IContributionManager) Separator(org.eclipse.jface.action.Separator)

Example 32 with IContributionManager

use of org.eclipse.jface.action.IContributionManager in project dbeaver by dbeaver.

the class ExasolServerSessionEditor method createSessionViewer.

@Override
protected SessionManagerViewer createSessionViewer(DBCExecutionContext executionContext, Composite parent) {
    return new SessionManagerViewer<ExasolServerSession>(this, parent, new ExasolServerSessionManager((ExasolDataSource) executionContext.getDataSource())) {

        @Override
        @SuppressWarnings("rawtypes")
        protected void contributeToToolbar(DBAServerSessionManager sessionManager, IContributionManager contributionManager) {
            contributionManager.add(killSessionAction);
            contributionManager.add(terminateQueryAction);
            contributionManager.add(new Separator());
        }

        @Override
        protected void onSessionSelect(DBAServerSession session) {
            super.onSessionSelect(session);
            killSessionAction.setEnabled(session != null);
            terminateQueryAction.setEnabled(session != null && !CommonUtils.isEmpty(session.getActiveQuery()));
        }
    };
}
Also used : SessionManagerViewer(org.jkiss.dbeaver.ui.views.session.SessionManagerViewer) DBAServerSession(org.jkiss.dbeaver.model.admin.sessions.DBAServerSession) DBAServerSessionManager(org.jkiss.dbeaver.model.admin.sessions.DBAServerSessionManager) ExasolDataSource(org.jkiss.dbeaver.ext.exasol.model.ExasolDataSource) IContributionManager(org.eclipse.jface.action.IContributionManager) Separator(org.eclipse.jface.action.Separator)

Example 33 with IContributionManager

use of org.eclipse.jface.action.IContributionManager in project dbeaver by dbeaver.

the class OracleSessionEditor method createSessionViewer.

@Override
protected SessionManagerViewer createSessionViewer(DBCExecutionContext executionContext, Composite parent) {
    return new SessionManagerViewer<OracleServerSession>(this, parent, new OracleServerSessionManager(getExecutionContext())) {

        @Override
        protected void contributeToToolbar(DBAServerSessionManager sessionManager, IContributionManager contributionManager) {
            contributionManager.add(killSessionAction);
            contributionManager.add(disconnectSessionAction);
            contributionManager.add(new Separator());
        }

        @Override
        protected void onSessionSelect(DBAServerSession session) {
            super.onSessionSelect(session);
            killSessionAction.setEnabled(session != null);
            disconnectSessionAction.setEnabled(session != null);
        }
    };
}
Also used : SessionManagerViewer(org.jkiss.dbeaver.ui.views.session.SessionManagerViewer) DBAServerSession(org.jkiss.dbeaver.model.admin.sessions.DBAServerSession) DBAServerSessionManager(org.jkiss.dbeaver.model.admin.sessions.DBAServerSessionManager) OracleServerSessionManager(org.jkiss.dbeaver.ext.oracle.model.session.OracleServerSessionManager) IContributionManager(org.eclipse.jface.action.IContributionManager) Separator(org.eclipse.jface.action.Separator)

Example 34 with IContributionManager

use of org.eclipse.jface.action.IContributionManager in project dbeaver by dbeaver.

the class PostgreSessionEditor method createSessionViewer.

@Override
protected SessionManagerViewer createSessionViewer(DBCExecutionContext executionContext, Composite parent) {
    return new SessionManagerViewer<PostgreSession>(this, parent, new PostgreSessionManager((PostgreDataSource) executionContext.getDataSource())) {

        @Override
        protected void contributeToToolbar(DBAServerSessionManager sessionManager, IContributionManager contributionManager) {
            contributionManager.add(terminateQueryAction);
            contributionManager.add(new Separator());
        }

        @Override
        protected void onSessionSelect(DBAServerSession session) {
            super.onSessionSelect(session);
            terminateQueryAction.setEnabled(session != null && !CommonUtils.isEmpty(session.getActiveQuery()));
        }
    };
}
Also used : SessionManagerViewer(org.jkiss.dbeaver.ui.views.session.SessionManagerViewer) DBAServerSession(org.jkiss.dbeaver.model.admin.sessions.DBAServerSession) PostgreDataSource(org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource) DBAServerSessionManager(org.jkiss.dbeaver.model.admin.sessions.DBAServerSessionManager) PostgreSessionManager(org.jkiss.dbeaver.ext.postgresql.model.session.PostgreSessionManager) IContributionManager(org.eclipse.jface.action.IContributionManager) Separator(org.eclipse.jface.action.Separator)

Example 35 with IContributionManager

use of org.eclipse.jface.action.IContributionManager in project dbeaver by dbeaver.

the class SelectObjectDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite group = (Composite) super.createDialogArea(parent);
    GridData gd = new GridData(GridData.FILL_BOTH);
    group.setLayoutData(gd);
    final DatabaseObjectListControl<T> objectList = new DatabaseObjectListControl<T>(group, (singleSelection ? SWT.SINGLE : SWT.MULTI), null, new ListContentProvider()) {

        private ISearchExecutor searcher = new SearcherFilter();

        @NotNull
        @Override
        protected String getListConfigId(List<Class<?>> classList) {
            return listId;
        }

        @Override
        protected LoadingJob<Collection<T>> createLoadService() {
            return LoadingJob.createService(new AbstractLoadService<Collection<T>>() {

                @Override
                public Collection<T> evaluate(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    return objects;
                }

                @Override
                public Object getFamily() {
                    return SelectObjectDialog.this;
                }
            }, new ObjectsLoadVisualizer() {

                @Override
                public void completeLoading(Collection<T> items) {
                    super.completeLoading(items);
                    performSearch(ISearchContextProvider.SearchType.NONE);
                    getItemsViewer().getControl().setFocus();
                    closeOnFocusLost(getItemsViewer().getControl(), getSearchTextControl());
                }
            });
        }

        protected CellLabelProvider getColumnLabelProvider(ObjectColumn objectColumn) {
            return new ObjectLabelProvider(objectColumn);
        }

        @Override
        protected Object getObjectValue(T item) {
            if (item instanceof DBSWrapper) {
                return ((DBSWrapper) item).getObject();
            }
            return super.getObjectValue(item);
        }

        @Override
        protected DBPImage getObjectImage(T item) {
            if (item instanceof DBNDatabaseNode) {
                return ((DBNDatabaseNode) item).getNodeIcon();
            }
            return null;
        }

        @Override
        protected void setListData(Collection<T> items, boolean append) {
            super.setListData(items, append);
            if (selectedObjects != null) {
                getItemsViewer().setSelection(new StructuredSelection(selectedObjects), true);
            }
        }

        @Override
        protected void fillCustomActions(IContributionManager contributionManager) {
            super.fillCustomActions(contributionManager);
            addColumnConfigAction(contributionManager);
        }

        protected void addSearchAction(IContributionManager contributionManager) {
            contributionManager.add(new Action("Filter objects", DBeaverIcons.getImageDescriptor(UIIcon.SEARCH)) {

                @Override
                public void run() {
                    performSearch(ISearchContextProvider.SearchType.NONE);
                }
            });
        }

        @Override
        protected ISearchExecutor getSearchRunner() {
            return searcher;
        }

        class ObjectLabelProvider extends ObjectColumnLabelProvider implements IFontProvider {

            ObjectLabelProvider(ObjectColumn objectColumn) {
                super(objectColumn);
            }

            @Override
            public Font getFont(Object element) {
                if (selectedObjects.contains(element)) {
                    return boldFont;
                }
                return null;
            }
        }
    };
    objectList.createProgressPanel();
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 300;
    gd.minimumWidth = 300;
    objectList.setLayoutData(gd);
    objectList.getSelectionProvider().addSelectionChangedListener(event -> {
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        selectedObjects.clear();
        selectedObjects.addAll(selection.toList());
        if (!isModeless()) {
            getButton(IDialogConstants.OK_ID).setEnabled(!selectedObjects.isEmpty());
        }
    });
    objectList.setDoubleClickHandler(event -> {
        if (isModeless() || getButton(IDialogConstants.OK_ID).isEnabled()) {
            okPressed();
        }
    });
    objectList.loadData();
    return group;
}
Also used : Action(org.eclipse.jface.action.Action) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DatabaseObjectListControl(org.jkiss.dbeaver.ui.controls.itemlist.DatabaseObjectListControl) Font(org.eclipse.swt.graphics.Font) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) SWT(org.eclipse.swt.SWT) ArrayList(java.util.ArrayList) List(java.util.List) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) Composite(org.eclipse.swt.widgets.Composite) InvocationTargetException(java.lang.reflect.InvocationTargetException) GridData(org.eclipse.swt.layout.GridData) Collection(java.util.Collection) DBPObject(org.jkiss.dbeaver.model.DBPObject) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IContributionManager(org.eclipse.jface.action.IContributionManager)

Aggregations

IContributionManager (org.eclipse.jface.action.IContributionManager)52 Separator (org.eclipse.jface.action.Separator)31 DBAServerSession (org.jkiss.dbeaver.model.admin.sessions.DBAServerSession)22 DBAServerSessionManager (org.jkiss.dbeaver.model.admin.sessions.DBAServerSessionManager)22 SessionManagerViewer (org.jkiss.dbeaver.ui.views.session.SessionManagerViewer)22 Action (org.eclipse.jface.action.Action)9 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)8 ExasolDataSource (org.jkiss.dbeaver.ext.exasol.model.ExasolDataSource)7 PostgreDataSource (org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource)7 LockManagerViewer (org.jkiss.dbeaver.ext.ui.locks.manage.LockManagerViewer)7 DBAServerLock (org.jkiss.dbeaver.model.admin.locks.DBAServerLock)7 DBAServerLockItem (org.jkiss.dbeaver.model.admin.locks.DBAServerLockItem)7 DBAServerLockManager (org.jkiss.dbeaver.model.admin.locks.DBAServerLockManager)7 Composite (org.eclipse.swt.widgets.Composite)6 GridData (org.eclipse.swt.layout.GridData)5 OracleDataSource (org.jkiss.dbeaver.ext.oracle.model.OracleDataSource)5 HashMap (java.util.HashMap)4 DB2DataSource (org.jkiss.dbeaver.ext.db2.model.DB2DataSource)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ArrayList (java.util.ArrayList)3