Search in sources :

Example 26 with UIServiceSQL

use of org.jkiss.dbeaver.runtime.ui.UIServiceSQL in project dbeaver by dbeaver.

the class PostgreFDWConfigWizardPageFinal method generateScript.

private void generateScript() {
    StringBuilder script = new StringBuilder();
    try {
        PostgreDataSource dataSource = getWizard().getDatabase().getDataSource();
        getWizard().getRunnableContext().run(true, true, monitor -> {
            try {
                DBExecUtils.tryExecuteRecover(monitor, dataSource, param -> {
                    try {
                        monitor.beginTask("Generate FDW script", 2);
                        monitor.subTask("Read actions");
                        List<DBEPersistAction> actions = getWizard().generateScript(monitor);
                        monitor.subTask("Generate script");
                        script.append(SQLUtils.generateScript(dataSource, actions.toArray(new DBEPersistAction[0]), false));
                        monitor.done();
                    } catch (DBException e) {
                        throw new InvocationTargetException(e);
                    }
                });
            } catch (DBException e) {
                throw new InvocationTargetException(e);
            }
        });
    } catch (InvocationTargetException e) {
        log.debug(e.getTargetException());
        setErrorMessage(e.getTargetException().getMessage());
        return;
    } catch (InterruptedException e) {
        return;
    }
    setErrorMessage(null);
    scriptText = script.toString();
    UIServiceSQL service = DBWorkbench.getService(UIServiceSQL.class);
    if (service != null) {
        service.setSQLPanelText(sqlPanel, scriptText);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) PostgreDataSource(org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 27 with UIServiceSQL

use of org.jkiss.dbeaver.runtime.ui.UIServiceSQL in project dbeaver by dbeaver.

the class DashboardItemConfigDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    Composite composite = super.createDialogArea(parent);
    {
        Group infoGroup = UIUtils.createControlGroup(composite, UIDashboardMessages.dialog_dashboard_item_config_dashboardinfo, 4, GridData.FILL_HORIZONTAL, 0);
        // UIUtils.createLabelText(infoGroup, "ID", dashboardConfig.getDashboardDescriptor().getId(), SWT.BORDER | SWT.READ_ONLY);
        UIUtils.createLabelText(infoGroup, UIDashboardMessages.dialog_dashboard_item_config_dashboardinfo_labels_name, dashboardConfig.getDashboardDescriptor().getName(), SWT.BORDER | SWT.READ_ONLY).setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false, 3, 1));
        UIUtils.createControlLabel(infoGroup, UIDashboardMessages.dialog_dashboard_item_config_dashboardinfo_labels_description).setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
        Text descriptionText = new Text(infoGroup, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
        descriptionText.setText(CommonUtils.notEmpty(dashboardConfig.getDescription()));
        descriptionText.addModifyListener(e -> {
            dashboardConfig.setDescription(descriptionText.getText());
        });
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.widthHint = 200;
        gd.heightHint = 50;
        descriptionText.setLayoutData(gd);
        if (SHOW_QUERIES_BUTTON) {
            Composite btnGroup = UIUtils.createComposite(infoGroup, 1);
            btnGroup.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false, 4, 1));
            Button queriesButton = new Button(btnGroup, SWT.PUSH);
            queriesButton.setText(UIDashboardMessages.dialog_dashboard_item_config_buttons_sqlqueries);
            queriesButton.setImage(DBeaverIcons.getImage(UIIcon.SQL_SCRIPT));
            queriesButton.setLayoutData(new GridData(GridData.END, GridData.BEGINNING, true, false));
            queriesButton.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    StringBuilder sql = new StringBuilder();
                    for (DashboardDescriptor.QueryMapping query : dashboardConfig.getDashboardDescriptor().getQueries()) {
                        sql.append(query.getQueryText()).append(";\n");
                    }
                    UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
                    if (serviceSQL != null) {
                        serviceSQL.openSQLViewer(DBUtils.getDefaultContext(dashboardContainer.getDataSourceContainer().getDataSource(), true), UIDashboardMessages.dialog_dashboard_item_config_buttons_sqlqueries_dash, UIIcon.SQL_SCRIPT, sql.toString(), false, false);
                    }
                }
            });
            queriesButton.setEnabled(dashboardContainer.getDataSourceContainer().isConnected());
        }
    }
    {
        Group updateGroup = UIUtils.createControlGroup(composite, UIDashboardMessages.dialog_dashboard_item_config_dashboardupdate, 2, GridData.FILL_HORIZONTAL, 0);
        Text updatePeriodText = UIUtils.createLabelText(updateGroup, UIDashboardMessages.dialog_dashboard_item_config_dashboardupdate_labels_updateperiod, String.valueOf(dashboardConfig.getUpdatePeriod()), SWT.BORDER, new GridData(GridData.FILL_HORIZONTAL));
        updatePeriodText.addModifyListener(e -> {
            dashboardConfig.setUpdatePeriod(CommonUtils.toLong(updatePeriodText.getText(), dashboardConfig.getUpdatePeriod()));
        });
        Text maxItemsText = UIUtils.createLabelText(updateGroup, UIDashboardMessages.dialog_dashboard_item_config_dashboardupdate_labels_maxitems, String.valueOf(dashboardConfig.getMaxItems()), SWT.BORDER, new GridData(GridData.FILL_HORIZONTAL));
        maxItemsText.addModifyListener(e -> {
            dashboardConfig.setMaxItems(CommonUtils.toInt(maxItemsText.getText(), dashboardConfig.getMaxItems()));
        });
    /*
            Text maxAgeText = UIUtils.createLabelText(updateGroup, "Maximum age (ISO-8601)", DashboardUtils.formatDuration(dashboardConfig.getMaxAge()), SWT.BORDER, new GridData(GridData.FILL_HORIZONTAL));
            maxAgeText.addModifyListener(e -> {
                dashboardConfig.setMaxAge(DashboardUtils.parseDuration(maxAgeText.getText(), dashboardConfig.getMaxAge()));
            });
*/
    }
    {
        Group viewGroup = UIUtils.createControlGroup(composite, UIDashboardMessages.dialog_dashboard_item_config_dashboardview, 2, GridData.FILL_HORIZONTAL, 0);
        Combo typeCombo = UIUtils.createLabelCombo(viewGroup, UIDashboardMessages.dialog_dashboard_item_config_dashboardview_combos_view, UIDashboardMessages.dialog_dashboard_item_config_dashboardview_combos_view_tooltip, SWT.BORDER | SWT.READ_ONLY);
        typeCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        {
            List<DashboardViewType> viewTypes = DashboardRegistry.getInstance().getSupportedViewTypes(dashboardConfig.getDashboardDescriptor().getDataType());
            for (DashboardViewType viewType : viewTypes) {
                typeCombo.add(viewType.getTitle());
            }
            typeCombo.setText(dashboardConfig.getViewType().getTitle());
            typeCombo.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    dashboardConfig.setViewType(viewTypes.get(typeCombo.getSelectionIndex()));
                }
            });
        }
        UIUtils.createCheckbox(viewGroup, UIDashboardMessages.dialog_dashboard_item_config_dashboardview_checkboxes_legend, UIDashboardMessages.dialog_dashboard_item_config_dashboardview_checkboxes_legend_tooltip, dashboardConfig.isLegendVisible(), 2).addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                dashboardConfig.setLegendVisible(((Button) e.widget).getSelection());
            }
        });
        UIUtils.createCheckbox(viewGroup, UIDashboardMessages.dialog_dashboard_item_config_dashboardview_checkboxes_grid, UIDashboardMessages.dialog_dashboard_item_config_dashboardview_checkboxes_grid_tooltip, dashboardConfig.isGridVisible(), 2).addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                dashboardConfig.setGridVisible(((Button) e.widget).getSelection());
            }
        });
        UIUtils.createCheckbox(viewGroup, UIDashboardMessages.dialog_dashboard_item_config_dashboardview_checkboxes_domainaxis, UIDashboardMessages.dialog_dashboard_item_config_dashboardview_checkboxes_domainaxis_tooltip, dashboardConfig.isDomainTicksVisible(), 2).addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                dashboardConfig.setDomainTicksVisible(((Button) e.widget).getSelection());
            }
        });
        UIUtils.createCheckbox(viewGroup, UIDashboardMessages.dialog_dashboard_item_config_dashboardview_checkboxes_rangeaxis, UIDashboardMessages.dialog_dashboard_item_config_dashboardview_checkboxes_rangeaxis_tooltip, dashboardConfig.isDomainTicksVisible(), 2).addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                dashboardConfig.setRangeTicksVisible(((Button) e.widget).getSelection());
            }
        });
    /*
            Text widthRatioText = UIUtils.createLabelText(viewGroup, "Width ratio", String.valueOf(dashboardConfig.getWidthRatio()), SWT.BORDER, new GridData(GridData.FILL_HORIZONTAL));
            widthRatioText.addModifyListener(e -> {
                dashboardConfig.setWidthRatio((float) CommonUtils.toDouble(widthRatioText.getText(), dashboardConfig.getWidthRatio()));
            });
*/
    }
    return parent;
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) DashboardContainer(org.jkiss.dbeaver.ui.dashboard.model.DashboardContainer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DashboardRegistry(org.jkiss.dbeaver.ui.dashboard.registry.DashboardRegistry) CommonUtils(org.jkiss.utils.CommonUtils) DashboardItemViewConfiguration(org.jkiss.dbeaver.ui.dashboard.model.DashboardItemViewConfiguration) UIDashboardMessages(org.jkiss.dbeaver.ui.dashboard.internal.UIDashboardMessages) NLS(org.eclipse.osgi.util.NLS) DBUtils(org.jkiss.dbeaver.model.DBUtils) org.eclipse.swt.widgets(org.eclipse.swt.widgets) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) DashboardViewConfiguration(org.jkiss.dbeaver.ui.dashboard.model.DashboardViewConfiguration) BaseDialog(org.jkiss.dbeaver.ui.dialogs.BaseDialog) List(java.util.List) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) UIUtils(org.jkiss.dbeaver.ui.UIUtils) DashboardDescriptor(org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor) SWT(org.eclipse.swt.SWT) UIIcon(org.jkiss.dbeaver.ui.UIIcon) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) DashboardViewType(org.jkiss.dbeaver.ui.dashboard.model.DashboardViewType) DashboardViewType(org.jkiss.dbeaver.ui.dashboard.model.DashboardViewType) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DashboardDescriptor(org.jkiss.dbeaver.ui.dashboard.registry.DashboardDescriptor) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL)

Example 28 with UIServiceSQL

use of org.jkiss.dbeaver.runtime.ui.UIServiceSQL in project dbeaver by dbeaver.

the class ErrorPresentation method createPresentation.

@Override
public void createPresentation(@NotNull IResultSetController controller, @NotNull Composite parent) {
    super.createPresentation(controller, parent);
    CustomSashForm partDivider = UIUtils.createPartDivider(controller.getSite().getPart(), parent, SWT.HORIZONTAL);
    partDivider.setLayoutData(new GridData(GridData.FILL_BOTH));
    errorComposite = UIUtils.createComposite(partDivider, 1);
    errorComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    statusPart = new StatusPart(errorComposite, status);
    for (Control child : errorComposite.getChildren()) {
        if (child instanceof Text) {
            TextEditorUtils.enableHostEditorKeyBindingsSupport(controller.getSite(), child);
        }
    }
    sqlPanel = UIUtils.createComposite(partDivider, 1);
    sqlPanel.setLayout(new FillLayout());
    UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
    try {
        editorPanel = serviceSQL.createSQLPanel(controller.getSite(), sqlPanel, controller, "SQL", true, sqlText);
        if (editorPanel instanceof TextViewer) {
            textWidget = ((TextViewer) editorPanel).getTextWidget();
        }
    } catch (DBException e) {
        textWidget = new StyledText(sqlPanel, SWT.BORDER | SWT.READ_ONLY);
        textWidget.setText(sqlText);
    }
    try {
        boolean widthSet = false;
        IDialogSettings viewSettings = ResultSetUtils.getViewerSettings(SETTINGS_SECTION_ERROR_PANEL);
        String errorWidth = viewSettings.get(PROP_ERROR_WIDTH);
        if (errorWidth != null) {
            String[] widthStrs = errorWidth.split(":");
            if (widthStrs.length == 2) {
                partDivider.setWeights(new int[] { Integer.parseInt(widthStrs[0]), Integer.parseInt(widthStrs[1]) });
            }
            widthSet = true;
        }
        if (!widthSet) {
            partDivider.setWeights(new int[] { 700, 300 });
        }
        partDivider.addCustomSashFormListener((firstControlWeight, secondControlWeight) -> {
            int[] weights = partDivider.getWeights();
            viewSettings.put(PROP_ERROR_WIDTH, weights[0] + ":" + weights[1]);
        });
    } catch (Throwable e) {
        log.debug(e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) StyledText(org.eclipse.swt.custom.StyledText) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) FillLayout(org.eclipse.swt.layout.FillLayout) TextViewer(org.eclipse.jface.text.TextViewer) Control(org.eclipse.swt.widgets.Control) CustomSashForm(org.jkiss.dbeaver.ui.controls.CustomSashForm) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) GridData(org.eclipse.swt.layout.GridData) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) StatusPart(org.eclipse.ui.internal.part.StatusPart)

Example 29 with UIServiceSQL

use of org.jkiss.dbeaver.runtime.ui.UIServiceSQL in project dbeaver by dbeaver.

the class ErrorPresentation method dispose.

@Override
public void dispose() {
    super.dispose();
    UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
    if (serviceSQL != null) {
        serviceSQL.disposeSQLPanel(editorPanel);
    }
}
Also used : UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL)

Example 30 with UIServiceSQL

use of org.jkiss.dbeaver.runtime.ui.UIServiceSQL in project dbeaver by dbeaver.

the class SaveScriptDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    Composite messageGroup = super.createDialogArea(parent);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.minimumWidth = 400;
    messageGroup.setLayoutData(gd);
    UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
    if (serviceSQL != null) {
        Composite sqlContainer = new Composite(messageGroup, SWT.NONE);
        gd = new GridData(GridData.FILL_BOTH);
        sqlContainer.setLayout(new FillLayout());
        gd.widthHint = 500;
        gd.heightHint = 400;
        sqlContainer.setLayoutData(gd);
        try {
            sqlPanel = serviceSQL.createSQLPanel(viewer.getSite(), sqlContainer, viewer, UINavigatorMessages.editors_entity_dialog_preview_title, true, "");
        } catch (Exception e) {
            DBWorkbench.getPlatformUI().showError("Can't create SQL panel", "Error creating SQL panel", e);
        }
    }
    populateSQL();
    boolean useDeleteCascade = saveReport.isHasReferences() && saveReport.getDeletes() > 0;
    createDeleteCascadeControls(messageGroup, saveSettings, useDeleteCascade, this::populateSQL);
    return messageGroup;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) FillLayout(org.eclipse.swt.layout.FillLayout)

Aggregations

UIServiceSQL (org.jkiss.dbeaver.runtime.ui.UIServiceSQL)34 GridData (org.eclipse.swt.layout.GridData)12 DBException (org.jkiss.dbeaver.DBException)12 FillLayout (org.eclipse.swt.layout.FillLayout)10 DBEPersistAction (org.jkiss.dbeaver.model.edit.DBEPersistAction)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 Composite (org.eclipse.swt.widgets.Composite)6 ArrayList (java.util.ArrayList)4 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)4 TextViewer (org.eclipse.jface.text.TextViewer)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 StyledText (org.eclipse.swt.custom.StyledText)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 DBSDataContainer (org.jkiss.dbeaver.model.struct.DBSDataContainer)3 File (java.io.File)2 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2