Search in sources :

Example 1 with DashboardDescriptor

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

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)

Example 2 with DashboardDescriptor

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

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 3 with DashboardDescriptor

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

the class DashboardViewConfiguration method loadSettings.

private void loadSettings() {
    File configFile = getConfigFile();
    if (!configFile.exists()) {
        return;
    }
    try {
        Document document = XMLUtils.parseDocument(configFile);
        for (Element viewElement : XMLUtils.getChildElementList(document.getDocumentElement(), "view")) {
            openConnectionOnActivate = CommonUtils.getBoolean(viewElement.getAttribute("openConnectionOnActivate"), openConnectionOnActivate);
            useSeparateConnection = CommonUtils.getBoolean(viewElement.getAttribute("useSeparateConnection"), useSeparateConnection);
        }
        for (Element dbElement : XMLUtils.getChildElementList(document.getDocumentElement(), "dashboard")) {
            String dashboardId = dbElement.getAttribute("id");
            DashboardDescriptor dashboard = DashboardRegistry.getInstance().getDashboard(dashboardId);
            if (dashboard != null) {
                DashboardItemViewConfiguration itemConfig = new DashboardItemViewConfiguration(dashboard, dbElement);
                items.add(itemConfig);
            } else {
                log.warn("Dashboard '" + dashboardId + "' not found");
            }
        }
    } catch (Exception e) {
        log.error("Error loading dashboard view configuration", e);
    }
    items.sort(Comparator.comparingInt(DashboardItemViewConfiguration::getIndex));
}
Also used : DashboardDescriptor(org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) File(java.io.File)

Example 4 with DashboardDescriptor

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

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 5 with DashboardDescriptor

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

the class DashboardViewConfiguration method loadSettings.

private void loadSettings() {
    File configFile = getConfigFile();
    if (!configFile.exists()) {
        return;
    }
    try {
        Document document = XMLUtils.parseDocument(configFile);
        for (Element viewElement : XMLUtils.getChildElementList(document.getDocumentElement(), "view")) {
            openConnectionOnActivate = CommonUtils.getBoolean(viewElement.getAttribute("openConnectionOnActivate"), openConnectionOnActivate);
            useSeparateConnection = CommonUtils.getBoolean(viewElement.getAttribute("useSeparateConnection"), useSeparateConnection);
        }
        for (Element dbElement : XMLUtils.getChildElementList(document.getDocumentElement(), "dashboard")) {
            String dashboardId = dbElement.getAttribute("id");
            DashboardDescriptor dashboard = DashboardRegistry.getInstance().getDashboard(dashboardId);
            if (dashboard != null) {
                DashboardItemViewConfiguration itemConfig = new DashboardItemViewConfiguration(dashboard, dbElement);
                items.add(itemConfig);
            } else {
                log.warn("Dashboard '" + dashboardId + "' not found");
            }
        }
    } catch (Exception e) {
        log.error("Error loading dashboard view configuration", e);
    }
    items.sort(Comparator.comparingInt(DashboardItemViewConfiguration::getIndex));
}
Also used : DashboardDescriptor(org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) File(java.io.File)

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