Search in sources :

Example 11 with DashboardDescriptor

use of org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor in project dbeaver by dbeaver.

the class DashboardManagerDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    getShell().setMinimumSize(300, 300);
    Composite dialogArea = super.createDialogArea(parent);
    Composite group = UIUtils.createPlaceholder(dialogArea, 2);
    group.setLayoutData(new GridData(GridData.FILL_BOTH));
    {
        treeViewer = new TreeViewer(group, SWT.BORDER);
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 300;
        gd.widthHint = 300;
        treeViewer.getControl().setLayoutData(gd);
        treeViewer.getTree().setHeaderVisible(true);
        UIUtils.createTreeColumn(treeViewer.getTree(), SWT.LEFT, UIDashboardMessages.dialog_dashboard_manager_treecolumn_name);
        // UIUtils.createTreeColumn(treeViewer.getTree(), SWT.LEFT, "Description");
        treeViewer.setContentProvider(new TreeContentProvider() {

            @Override
            public Object[] getChildren(Object parentElement) {
                List<? extends DBPNamedObject> result = null;
                if (parentElement instanceof List) {
                    result = (List) parentElement;
                } else if (parentElement instanceof DBPDataSourceProviderDescriptor) {
                    result = DashboardRegistry.getInstance().getDashboards((DBPDataSourceProviderDescriptor) parentElement, false);
                } else if (parentElement instanceof DBPDriver) {
                    result = DashboardRegistry.getInstance().getDashboards((DBPDriver) parentElement, false);
                }
                if (result == null) {
                    return new Object[0];
                }
                result.sort(DBUtils.nameComparator());
                return result.toArray();
            }

            @Override
            public boolean hasChildren(Object element) {
                if (element instanceof DashboardDescriptor) {
                    return false;
                }
                return true;
            }
        });
        treeViewer.setLabelProvider(new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DBPNamedObject element = (DBPNamedObject) cell.getElement();
                if (cell.getColumnIndex() == 0) {
                    cell.setText(element.getName());
                    if (element instanceof DBPDriver) {
                        cell.setImage(DBeaverIcons.getImage(((DBPDriver) element).getIcon()));
                    } else if (element instanceof DBPDataSourceProviderDescriptor) {
                        cell.setImage(DBeaverIcons.getImage(((DBPDataSourceProviderDescriptor) element).getIcon()));
                    } else if (element instanceof DashboardDescriptor) {
                        DashboardDescriptor dashboardDescriptor = (DashboardDescriptor) element;
                        DBPImage icon;
                        if (dashboardDescriptor.isCustom()) {
                            icon = DBIcon.TYPE_OBJECT;
                        } else {
                            icon = dashboardDescriptor.getDefaultViewType().getIcon();
                        }
                        if (icon != null) {
                            cell.setImage(DBeaverIcons.getImage(icon));
                        }
                    }
                } else {
                    if (element instanceof DBPDriver) {
                        cell.setText(CommonUtils.notEmpty(((DBPDriver) element).getDescription()));
                    } else if (element instanceof DBPDataSourceProviderDescriptor) {
                        cell.setText(((DBPDataSourceProviderDescriptor) element).getDescription());
                    }
                }
            }
        });
        treeViewer.setInput(DashboardRegistry.getInstance().getAllSupportedSources());
        treeViewer.addDoubleClickListener(event -> {
            if (selectedDashboard != null) {
                editDashboard();
            }
        });
        treeViewer.addSelectionChangedListener(event -> {
            this.selectedDashboard = null;
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                Object selectedObject = ((IStructuredSelection) selection).getFirstElement();
                if (selectedObject instanceof DashboardDescriptor) {
                    this.selectedDashboard = (DashboardDescriptor) selectedObject;
                }
            }
            this.updateButtons();
        });
        UIUtils.asyncExec(() -> {
            treeViewer.expandAll();
            UIUtils.packColumns(treeViewer.getTree(), true, null);
        });
    }
    {
        Composite buttonBar = new Composite(group, SWT.TOP);
        buttonBar.setLayout(new GridLayout(1, false));
        GridData gd = new GridData(GridData.FILL_VERTICAL);
        buttonBar.setLayoutData(gd);
        newButton = UIUtils.createPushButton(buttonBar, UIDashboardMessages.dialog_dashboard_manager_button_new, null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                createDashboard();
            }
        });
        newButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        copyButton = UIUtils.createPushButton(buttonBar, UIDashboardMessages.dialog_dashboard_manager_button_copy, null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                copyDashboard();
            }
        });
        copyButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        editButton = UIUtils.createPushButton(buttonBar, UIDashboardMessages.dialog_dashboard_manager_button_edit, null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                editDashboard();
            }
        });
        editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        deleteButton = UIUtils.createPushButton(buttonBar, UIDashboardMessages.dialog_dashboard_manager_button_delete, null, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                deleteDashboard();
            }
        });
        deleteButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    }
    UIUtils.createInfoLabel(dialogArea, UIDashboardMessages.dialog_dashboard_manager_infolabel_predifined_dashboard);
    this.updateButtons();
    return group;
}
Also used : UIDashboardMessages(org.jkiss.dbeaver.ui.dashboard.internal.UIDashboardMessages) UIDashboardActivator(org.jkiss.dbeaver.ui.dashboard.internal.UIDashboardActivator) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) DBPImage(org.jkiss.dbeaver.model.DBPImage) BaseDialog(org.jkiss.dbeaver.ui.dialogs.BaseDialog) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) Composite(org.eclipse.swt.widgets.Composite) UIUtils(org.jkiss.dbeaver.ui.UIUtils) GridData(org.eclipse.swt.layout.GridData) TreeContentProvider(org.jkiss.dbeaver.ui.controls.TreeContentProvider) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DashboardRegistry(org.jkiss.dbeaver.ui.dashboard.registry.DashboardRegistry) CommonUtils(org.jkiss.utils.CommonUtils) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) NLS(org.eclipse.osgi.util.NLS) DBUtils(org.jkiss.dbeaver.model.DBUtils) org.eclipse.jface.viewers(org.eclipse.jface.viewers) List(java.util.List) DBIcon(org.jkiss.dbeaver.model.DBIcon) DBPDataSourceProviderDescriptor(org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor) DashboardDescriptor(org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor) SWT(org.eclipse.swt.SWT) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) GridLayout(org.eclipse.swt.layout.GridLayout) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBPImage(org.jkiss.dbeaver.model.DBPImage) TreeContentProvider(org.jkiss.dbeaver.ui.controls.TreeContentProvider) GridLayout(org.eclipse.swt.layout.GridLayout) DashboardDescriptor(org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) List(java.util.List) DBPDataSourceProviderDescriptor(org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor)

Example 12 with DashboardDescriptor

use of org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor in project dbeaver by dbeaver.

the class HandlerDashboardAddItem method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    DashboardView view = getActiveDashboardView(event);
    if (view != null) {
        DashboardAddDialog addDialog = new DashboardAddDialog(HandlerUtil.getActiveShell(event), view.getConfiguration());
        if (addDialog.open() == IDialogConstants.OK_ID) {
            DashboardDescriptor selectedDashboard = addDialog.getSelectedDashboard();
            if (selectedDashboard != null) {
                view.getConfiguration().readDashboardConfiguration(selectedDashboard);
                view.getDashboardListViewer().getDefaultGroup().addItem(selectedDashboard.getId());
            }
        }
    }
    return null;
}
Also used : DashboardDescriptor(org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor)

Example 13 with DashboardDescriptor

use of org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor in project dbeaver by dbeaver.

the class DashboardAddDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    Composite dialogArea = super.createDialogArea(parent);
    // AdvancedListViewer listViewer = new AdvancedListViewer(dialogArea, SWT.NONE);
    // listViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    TableViewer dashboardTable = new TableViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION);
    dashboardTable.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    Table table = dashboardTable.getTable();
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 400;
    gd.heightHint = 200;
    table.setLayoutData(gd);
    table.setHeaderVisible(true);
    UIUtils.createTableColumn(table, SWT.LEFT, UIDashboardMessages.dialog_add_dashboard_column_name);
    UIUtils.createTableColumn(table, SWT.LEFT, UIDashboardMessages.dialog_add_dashboard_column_description);
    dashboardTable.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            DashboardDescriptor dashboardDescriptor = (DashboardDescriptor) cell.getElement();
            if (cell.getColumnIndex() == 0) {
                cell.setText(dashboardDescriptor.getName());
            } else {
                cell.setText(CommonUtils.notEmpty(dashboardDescriptor.getDescription()));
            }
        }
    });
    dashboardTable.addDoubleClickListener(event -> {
        if (!dashboardTable.getSelection().isEmpty()) {
            okPressed();
        }
    });
    dashboardTable.addSelectionChangedListener(event -> {
        ISelection selection = dashboardTable.getSelection();
        getButton(IDialogConstants.OK_ID).setEnabled(!selection.isEmpty());
        if (selection instanceof IStructuredSelection) {
            selectedDashboard = (DashboardDescriptor) ((IStructuredSelection) selection).getFirstElement();
        }
        getButton(IDialogConstants.OK_ID).setEnabled(selectedDashboard != null);
    });
    table.addPaintListener(e -> {
        if (table.getItemCount() == 0) {
            final String dbmsName = viewConfiguration.getDataSourceContainer().getDriver().getName();
            final String msg = NLS.bind(UIDashboardMessages.dialog_add_dashboard_message_no_more_dashboards_for, dbmsName);
            UIUtils.drawMessageOverControl(table, e, msg, 0);
        }
    });
    dashboardTable.setContentProvider(new ListContentProvider());
    java.util.List<DashboardDescriptor> dashboards = new ArrayList<>(DashboardRegistry.getInstance().getDashboards(viewConfiguration.getDataSourceContainer(), false));
    dashboards.removeIf(descriptor -> viewConfiguration.getDashboardConfig(descriptor.getId()) != null);
    dashboardTable.setInput(dashboards);
    UIUtils.asyncExec(() -> UIUtils.packColumns(table, true));
    return dialogArea;
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ArrayList(java.util.ArrayList) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) DashboardDescriptor(org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor) GridData(org.eclipse.swt.layout.GridData)

Example 14 with DashboardDescriptor

use of org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor in project dbeaver by dbeaver.

the class DashboardList method addItem.

@Override
public void addItem(String dashboardId) {
    DashboardDescriptor dashboardDescriptor = DashboardRegistry.getInstance().getDashboard(dashboardId);
    if (dashboardDescriptor == null) {
        return;
    }
    viewContainer.getViewConfiguration().readDashboardConfiguration(dashboardDescriptor);
    new DashboardItem(this, dashboardId);
    viewContainer.getViewConfiguration().saveSettings();
    layout(true, true);
}
Also used : DashboardDescriptor(org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor)

Aggregations

DashboardDescriptor (org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor)14 GridData (org.eclipse.swt.layout.GridData)4 Composite (org.eclipse.swt.widgets.Composite)4 File (java.io.File)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)2 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)2 org.eclipse.jface.viewers (org.eclipse.jface.viewers)2 NLS (org.eclipse.osgi.util.NLS)2 SWT (org.eclipse.swt.SWT)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Shell (org.eclipse.swt.widgets.Shell)2 Table (org.eclipse.swt.widgets.Table)2 DBIcon (org.jkiss.dbeaver.model.DBIcon)2 DBPImage (org.jkiss.dbeaver.model.DBPImage)2 DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)2