Search in sources :

Example 1 with UIServiceSQL

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

the class NavigatorObjectsDeleter method showScriptWindow.

boolean showScriptWindow() {
    final String sql = collectSQL();
    boolean result = false;
    if (sql.length() > 0) {
        UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
        if (serviceSQL != null) {
            result = serviceSQL.openSQLViewer(// command context is not null because sql is not empty, see appendSQL()
            commandContext.getExecutionContext(), UINavigatorMessages.actions_navigator_delete_script, UIIcon.SQL_PREVIEW, sql, true, false) == IDialogConstants.PROCEED_ID;
        }
    } else {
        result = UIUtils.confirmAction(window.getShell(), UINavigatorMessages.actions_navigator_delete_script, UINavigatorMessages.question_no_sql_available);
    }
    commandContext.resetChanges(!result);
    return result;
}
Also used : UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL)

Example 2 with UIServiceSQL

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

the class ResultSetFilterPanel method openEditorForActiveQuery.

private void openEditorForActiveQuery() {
    DBSDataContainer dataContainer = viewer.getDataContainer();
    String editorName;
    if (dataContainer instanceof DBSEntity) {
        editorName = dataContainer.getName();
    } else {
        editorName = "Query";
    }
    UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
    if (serviceSQL != null) {
        serviceSQL.openSQLConsole(dataContainer == null || dataContainer.getDataSource() == null ? null : dataContainer.getDataSource().getContainer(), viewer.getExecutionContext(), editorName, viewer.getActiveQueryText());
    }
}
Also used : DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer)

Example 3 with UIServiceSQL

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

the class ResultSetFilterPanel method createObjectPanel.

@NotNull
private Control createObjectPanel(Shell popup) throws PartInitException {
    Composite panel = new Composite(popup, SWT.NONE);
    GridLayout gl = new GridLayout(2, false);
    // gl.marginWidth = 0;
    gl.marginHeight = 0;
    // gl.horizontalSpacing = 0;
    panel.setLayout(gl);
    Label iconLabel = new Label(panel, SWT.NONE);
    DBPImage activeObjectImage = getActiveObjectImage();
    if (activeObjectImage != null) {
        iconLabel.setImage(DBeaverIcons.getImage(activeObjectImage));
    }
    iconLabel.setToolTipText(ResultSetMessages.sql_editor_resultset_filter_panel_label);
    iconLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    iconLabel.setCursor(getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    iconLabel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent e) {
            openEditorForActiveQuery();
        }
    });
    Composite editorPH = new Composite(panel, SWT.NONE);
    editorPH.setLayoutData(new GridData(GridData.FILL_BOTH));
    editorPH.setLayout(new FillLayout());
    try {
        UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
        if (serviceSQL != null) {
            Object sqlPanel = serviceSQL.createSQLPanel(viewer.getSite(), editorPH, viewer, ResultSetViewer.DEFAULT_QUERY_TEXT, false, viewer.getActiveQueryText());
            if (sqlPanel instanceof TextViewer) {
                StyledText textWidget = ((TextViewer) sqlPanel).getTextWidget();
                // textWidget.setAlwaysShowScrollBars(false);
                panel.setBackground(textWidget.getBackground());
                return textWidget;
            }
        }
        return null;
    } catch (DBException e) {
        throw new PartInitException("Error creating SQL panel", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) StyledText(org.eclipse.swt.custom.StyledText) FillLayout(org.eclipse.swt.layout.FillLayout) TextViewer(org.eclipse.jface.text.TextViewer) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) PartInitException(org.eclipse.ui.PartInitException) NotNull(org.jkiss.code.NotNull)

Example 4 with UIServiceSQL

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

the class DatabaseConsumerPageMapping method showDDL.

private void showDDL(DatabaseMappingContainer mapping) {
    final DatabaseConsumerSettings settings = getDatabaseConsumerSettings();
    final DBSObjectContainer container = settings.getContainer();
    if (container == null) {
        return;
    }
    DBPDataSource dataSource = container.getDataSource();
    final DBEPersistAction[][] ddl = new DBEPersistAction[1][];
    try {
        getWizard().getRunnableContext().run(true, true, monitor -> {
            monitor.beginTask(DTUIMessages.database_consumer_page_mapping_monitor_task, 1);
            try {
                DBCExecutionContext executionContext = DBUtils.getDefaultContext(dataSource, true);
                ddl[0] = DatabaseTransferUtils.generateTargetTableDDL(monitor, executionContext, container, mapping);
            } catch (DBException e) {
                throw new InvocationTargetException(e);
            }
            monitor.done();
        });
    } catch (InvocationTargetException e) {
        DBWorkbench.getPlatformUI().showError(DTUIMessages.database_consumer_page_mapping_title_target_DDL, DTUIMessages.database_consumer_page_mapping_message_error_generating_target_DDL, e);
        return;
    } catch (InterruptedException e) {
        return;
    }
    DBEPersistAction[] persistActions = ddl[0];
    if (ArrayUtils.isEmpty(persistActions)) {
        UIUtils.showMessageBox(getShell(), "No schema changes", "No changes are needed for this mapping", SWT.ICON_INFORMATION);
        return;
    }
    UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
    if (serviceSQL != null) {
        String sql = SQLUtils.generateScript(dataSource, persistActions, false);
        int result = serviceSQL.openSQLViewer(DBUtils.getDefaultContext(container, true), DTUIMessages.database_consumer_page_mapping_sqlviewer_title, null, sql, dataSource.getContainer().hasModifyPermission(DBPDataSourcePermission.PERMISSION_EDIT_METADATA), false);
        if (result == IDialogConstants.PROCEED_ID) {
            if (UIUtils.confirmAction(getShell(), "Create target objects", "Database metadata will be modified by creating new table(s) and column(s).\nAre you sure you want to proceed?")) {
                // Create target objects
                if (applySchemaChanges(dataSource, mapping, persistActions)) {
                    autoAssignMappings();
                    updateMappingsAndButtons();
                }
            }
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL)

Example 5 with UIServiceSQL

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

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