Search in sources :

Example 1 with DatabaseLoadService

use of org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService in project dbeaver by serge-rider.

the class ResultSetViewer method createStatusBar.

private void createStatusBar() {
    UIUtils.createHorizontalLine(viewerPanel);
    statusBar = new Composite(viewerPanel, SWT.NONE);
    statusBar.setBackgroundMode(SWT.INHERIT_FORCE);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    statusBar.setLayoutData(gd);
    RowLayout toolbarsLayout = new RowLayout(SWT.HORIZONTAL);
    toolbarsLayout.marginTop = 0;
    toolbarsLayout.marginBottom = 0;
    toolbarsLayout.center = true;
    toolbarsLayout.wrap = true;
    toolbarsLayout.pack = true;
    //toolbarsLayout.fill = true;
    statusBar.setLayout(toolbarsLayout);
    {
        ToolBarManager editToolbar = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
        // handle own commands
        editToolbar.add(new Separator());
        editToolbar.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_APPLY_CHANGES, "Save", null, null, true));
        editToolbar.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_REJECT_CHANGES, "Cancel", null, null, true));
        editToolbar.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_GENERATE_SCRIPT, "Script", null, null, true));
        editToolbar.add(new Separator());
        editToolbar.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_EDIT));
        editToolbar.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_ADD));
        editToolbar.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_COPY));
        editToolbar.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_DELETE));
        editToolbar.createControl(statusBar);
        toolbarList.add(editToolbar);
    }
    {
        ToolBarManager navToolbar = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
        navToolbar.add(new Separator());
        navToolbar.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_FIRST));
        navToolbar.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_PREVIOUS));
        navToolbar.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_NEXT));
        navToolbar.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_ROW_LAST));
        navToolbar.add(new Separator());
        navToolbar.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_FETCH_PAGE));
        navToolbar.add(ActionUtils.makeCommandContribution(site, ResultSetCommandHandler.CMD_FETCH_ALL));
        navToolbar.createControl(statusBar);
        toolbarList.add(navToolbar);
    }
    {
        ToolBarManager configToolbar = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
        configToolbar.add(new Separator());
        {
            //configToolbar.add(new ToggleModeAction());
            ActionContributionItem item = new ActionContributionItem(new ToggleModeAction());
            item.setMode(ActionContributionItem.MODE_FORCE_TEXT);
            configToolbar.add(item);
        }
        {
            CommandContributionItemParameter ciParam = new CommandContributionItemParameter(site, "org.jkiss.dbeaver.core.resultset.panels", ResultSetCommandHandler.CMD_TOGGLE_PANELS, CommandContributionItem.STYLE_PULLDOWN);
            ciParam.label = "Panels";
            ciParam.mode = CommandContributionItem.MODE_FORCE_TEXT;
            configToolbar.add(new CommandContributionItem(ciParam));
        }
        configToolbar.add(new Separator());
        configToolbar.add(new ConfigAction());
        configToolbar.add(new Separator());
        configToolbar.createControl(statusBar);
        toolbarList.add(configToolbar);
    }
    {
        presentationSwitchToolbar = new ToolBar(statusBar, SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
        RowData rd = new RowData();
        rd.exclude = true;
        presentationSwitchToolbar.setLayoutData(rd);
    }
    {
        final int fontHeight = UIUtils.getFontHeight(statusBar);
        statusLabel = new StatusLabel(statusBar, SWT.NONE, this);
        statusLabel.setLayoutData(new RowData(40 * fontHeight, SWT.DEFAULT));
        rowCountLabel = new ActiveStatusMessage(statusBar, DBeaverIcons.getImage(UIIcon.RS_REFRESH), "Calculate total row count", this) {

            @Override
            protected boolean isActionEnabled() {
                return hasData() && isHasMoreData();
            }

            @Override
            protected ILoadService<String> createLoadService() {
                return new DatabaseLoadService<String>("Load row count", getExecutionContext()) {

                    @Override
                    public String evaluate(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            long rowCount = readRowCount(monitor);
                            return ROW_COUNT_FORMAT.format(rowCount);
                        } catch (DBException e) {
                            log.error(e);
                            return e.getMessage();
                        }
                    }
                };
            }
        };
        rowCountLabel.setLayoutData(new RowData(10 * fontHeight, SWT.DEFAULT));
        rowCountLabel.setMessage("Row Count");
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DatabaseLoadService(org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService) RowData(org.eclipse.swt.layout.RowData) RowLayout(org.eclipse.swt.layout.RowLayout) CommandContributionItemParameter(org.eclipse.ui.menus.CommandContributionItemParameter) GridData(org.eclipse.swt.layout.GridData) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) CommandContributionItem(org.eclipse.ui.menus.CommandContributionItem)

Example 2 with DatabaseLoadService

use of org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService in project dbeaver by serge-rider.

the class MySQLUserEditorPrivileges method activatePart.

@Override
public synchronized void activatePart() {
    if (isLoaded) {
        return;
    }
    isLoaded = true;
    LoadingJob.createService(new DatabaseLoadService<java.util.List<MySQLPrivilege>>(MySQLMessages.editors_user_editor_privileges_service_load_privileges, getExecutionContext()) {

        @Override
        public java.util.List<MySQLPrivilege> evaluate(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                return getDatabaseObject().getDataSource().getPrivileges(monitor);
            } catch (DBException e) {
                throw new InvocationTargetException(e);
            }
        }
    }, pageControl.createPrivilegesLoadVisualizer()).schedule();
}
Also used : DBException(org.jkiss.dbeaver.DBException) java.util(java.util) DatabaseLoadService(org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with DatabaseLoadService

use of org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService in project dbeaver by serge-rider.

the class MySQLUserEditorGeneral method activatePart.

@Override
public void activatePart() {
    if (isLoaded) {
        return;
    }
    isLoaded = true;
    LoadingJob.createService(new DatabaseLoadService<List<MySQLPrivilege>>(MySQLMessages.editors_user_editor_general_service_load_catalog_privileges, getExecutionContext()) {

        @Override
        public List<MySQLPrivilege> evaluate(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                final List<MySQLPrivilege> privList = getDatabaseObject().getDataSource().getPrivilegesByKind(monitor, MySQLPrivilege.Kind.ADMIN);
                for (Iterator<MySQLPrivilege> iterator = privList.iterator(); iterator.hasNext(); ) {
                    MySQLPrivilege priv = iterator.next();
                    // Remove proxy (it is not singleton)
                    if (priv.getName().equalsIgnoreCase("proxy")) {
                        iterator.remove();
                    }
                }
                return privList;
            } catch (DBException e) {
                throw new InvocationTargetException(e);
            }
        }
    }, pageControl.createLoadVisualizer()).schedule();
}
Also used : DBException(org.jkiss.dbeaver.DBException) DatabaseLoadService(org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) MySQLPrivilege(org.jkiss.dbeaver.ext.mysql.model.MySQLPrivilege) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with DatabaseLoadService

use of org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService in project dbeaver by serge-rider.

the class ERDEditorEmbedded method loadDiagram.

@Override
protected synchronized void loadDiagram(final boolean refreshMetadata) {
    final DBSObject object = getRootObject();
    if (object == null) {
        return;
    }
    if (diagramLoadingJob != null) {
        // Do not start new one while old is running
        return;
    }
    diagramLoadingJob = LoadingJob.createService(new DatabaseLoadService<EntityDiagram>("Load diagram '" + object.getName() + "'", object.getDataSource()) {

        @Override
        public EntityDiagram evaluate(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            if (refreshMetadata && object instanceof DBPRefreshableObject) {
                try {
                    getEditorInput().getNavigatorNode().refreshNode(monitor, ERDEditorEmbedded.this);
                } catch (DBException e) {
                    log.warn("Error refreshing database metadata", e);
                }
            }
            try {
                return loadFromDatabase(monitor);
            } catch (DBException e) {
                log.error("Error loading ER diagram", e);
            }
            return null;
        }
    }, progressControl.createLoadVisualizer());
    diagramLoadingJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            diagramLoadingJob = null;
        }
    });
    diagramLoadingJob.schedule();
}
Also used : DBException(org.jkiss.dbeaver.DBException) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) DatabaseLoadService(org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) DBPRefreshableObject(org.jkiss.dbeaver.model.DBPRefreshableObject)

Aggregations

DBException (org.jkiss.dbeaver.DBException)4 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)4 DatabaseLoadService (org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 java.util (java.util)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 GridData (org.eclipse.swt.layout.GridData)1 RowData (org.eclipse.swt.layout.RowData)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 CommandContributionItem (org.eclipse.ui.menus.CommandContributionItem)1 CommandContributionItemParameter (org.eclipse.ui.menus.CommandContributionItemParameter)1 MySQLPrivilege (org.jkiss.dbeaver.ext.mysql.model.MySQLPrivilege)1 DBPRefreshableObject (org.jkiss.dbeaver.model.DBPRefreshableObject)1