<NME> SQLGeneratorDialog.java
<BEF> /*
 * DBeaver - Universal Database Manager
 * Copyright (C) 2010-2022 DBeaver Corp and others
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jkiss.dbeaver.ui.editors.sql.generator;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.ui.IWorkbenchPartSite;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.sql.generator.SQLGenerator;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.editors.sql.dialogs.ViewSQLDialog;
import org.jkiss.dbeaver.ui.editors.sql.internal.SQLEditorMessages;
import org.jkiss.utils.CommonUtils;

class SQLGeneratorDialog extends ViewSQLDialog {

    private static final String PROP_USE_FQ_NAMES = "GenerateSQL.useFQNames";
    private static final String PROP_USE_COMPACT_SQL = "GenerateSQL.compactSQL";
    private static final String PROP_EXCLUDE_AUTO_GENERATED_COLUMNS = "GenerateSQL.excludeAutoGeneratedColumn";
    private static final String PROP_USE_CUSTOM_DATA_FORMAT = "GenerateSQL.useCustomDataFormat";
    private static final String PROP_USE_SEPARATE_FK_STATEMENTS = "GenerateSQL.useSeparateFKStatements";

    private final SQLGenerator<?> sqlGenerator;

    SQLGeneratorDialog(IWorkbenchPartSite parentSite, DBCExecutionContext context, SQLGenerator<?> sqlGenerator) {

    @Override
    protected Composite createDialogArea(Composite parent) {
        sqlGenerator.setFullyQualifiedNames(
            getDialogBoundsSettings().get(PROP_USE_FQ_NAMES) == null ||
                getDialogBoundsSettings().getBoolean(PROP_USE_FQ_NAMES));
        sqlGenerator.setCompactSQL(
            getDialogBoundsSettings().get(PROP_USE_COMPACT_SQL) != null &&
                getDialogBoundsSettings().getBoolean(PROP_USE_COMPACT_SQL));
        UIUtils.runInUI(sqlGenerator);
        Object sql = sqlGenerator.getResult();
        if (sql != null) {
                    break; //it supports everything
        }

        Composite composite = super.createDialogArea(parent);

        Group settings = UIUtils.createControlGroup(composite, "Settings", 2, GridData.FILL_HORIZONTAL, SWT.DEFAULT);
        Button useFQNames = UIUtils.createCheckbox(settings, "Use fully qualified names", sqlGenerator.isFullyQualifiedNames());
        useFQNames.addSelectionListener(new SelectionAdapter() {
            @Override
        sqlGenerator.setShowPermissions(getDialogBoundsSettings().get(DBPScriptObject.OPTION_INCLUDE_PERMISSIONS) != null &&
                getDialogBoundsSettings().getBoolean(DBPScriptObject.OPTION_INCLUDE_PERMISSIONS));
        sqlGenerator.setShowComments(getDialogBoundsSettings().get(DBPScriptObject.OPTION_INCLUDE_COMMENTS) != null &&
                getDialogBoundsSettings().getBoolean(DBPScriptObject.OPTION_INCLUDE_COMMENTS));
        sqlGenerator.setShowFullDdl(getDialogBoundsSettings().get(DBPScriptObject.OPTION_INCLUDE_NESTED_OBJECTS) != null &&
                getDialogBoundsSettings().getBoolean(DBPScriptObject.OPTION_INCLUDE_NESTED_OBJECTS));

        UIUtils.runInUI(sqlGenerator);
        Object sql = sqlGenerator.getResult();
        if (sql != null) {
            setSQLText(CommonUtils.toString(sql));
        }

        Composite composite = super.createDialogArea(parent);
        
        if (!sqlGenerator.hasOptions()) {
            return composite;
        }
        
        Group settings = UIUtils.createControlGroup(composite, "Settings", 5, GridData.FILL_HORIZONTAL, SWT.DEFAULT);
        settings.setLayout(new RowLayout());
        Button useFQNames = UIUtils.createCheckbox(settings, SQLEditorMessages.sql_generator_dialog_button_use_fully_names, sqlGenerator.isFullyQualifiedNames());
        useFQNames.addSelectionListener(new SelectionAdapter() {
            @Override
                }
            }
        });

        return composite;
    }
}
                    }
                }
            });
        }
        if (sqlGenerator.isDDLOption()) {
            if (supportComments) {
                Button useShowComments = UIUtils.createCheckbox(settings, SQLEditorMessages.sql_generator_dialog_button_show_comments, sqlGenerator.isShowComments());
                useShowComments.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        sqlGenerator.setShowComments(useShowComments.getSelection());
                        getDialogBoundsSettings().put(DBPScriptObject.OPTION_INCLUDE_COMMENTS, useShowComments.getSelection());

                        UIUtils.runInUI(sqlGenerator);
                        Object sql = sqlGenerator.getResult();
                        if (sql != null) {
                            setSQLText(CommonUtils.toString(sql));
                            updateSQL();
                        }
                    }
                });
            }
            if (supportPermissions) {
                Button useShowPermissions = UIUtils.createCheckbox(settings, SQLEditorMessages.sql_generator_dialog_button_show_permissions, sqlGenerator.isIncludePermissions());
                useShowPermissions.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        sqlGenerator.setShowPermissions(useShowPermissions.getSelection());
                        getDialogBoundsSettings().put(DBPScriptObject.OPTION_INCLUDE_PERMISSIONS, useShowPermissions.getSelection());

                        UIUtils.runInUI(sqlGenerator);
                        Object sql = sqlGenerator.getResult();
                        if (sql != null) {
                            setSQLText(CommonUtils.toString(sql));
                            updateSQL();
                        }
                    }
                });
            }
        }
        if (supportFullDDL) {
            Button useShowFullDdl = UIUtils.createCheckbox(settings, SQLEditorMessages.sql_generator_dialog_button_show_full_DDL, sqlGenerator.isShowFullDdl());
            useShowFullDdl.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    sqlGenerator.setShowFullDdl(useShowFullDdl.getSelection());
                    getDialogBoundsSettings().put(DBPScriptObject.OPTION_INCLUDE_COMMENTS, useShowFullDdl.getSelection());

                    UIUtils.runInUI(sqlGenerator);
                    Object sql = sqlGenerator.getResult();
                    if (sql != null) {
                        setSQLText(CommonUtils.toString(sql));
                        updateSQL();
                    }
                }
            });
        }
        if (supportSeparateFKStatements) {
            Button useSeparateFkStatements = UIUtils.createCheckbox(settings, SQLEditorMessages.sql_generator_dialog_button_separate_fk_constraints_definition, sqlGenerator.isUseSeparateForeignKeys());
            useSeparateFkStatements.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    sqlGenerator.setUseSeparateForeignKeys(useSeparateFkStatements.getSelection());
                    getDialogBoundsSettings().put(DBPScriptObject.OPTION_DDL_SEPARATE_FOREIGN_KEYS_STATEMENTS, useSeparateFkStatements.getSelection());

                    UIUtils.runInUI(sqlGenerator);
                    Object sql = sqlGenerator.getResult();
                    if (sql != null) {
                        setSQLText(CommonUtils.toString(sql));
                        updateSQL();
                    }
                }
            });
        }
        if (supportsPartitionsDDL) {
            Button supportsPartitionsDDLButton = UIUtils.createCheckbox(
                settings,
                SQLEditorMessages.sql_generator_dialog_button_show_partitions_DDL,
                sqlGenerator.isShowPartitionsDDL());
            supportsPartitionsDDLButton.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    sqlGenerator.setShowPartitionsDDL(supportsPartitionsDDLButton.getSelection());
                    getDialogBoundsSettings().put(DBPScriptObject.OPTION_INCLUDE_PARTITIONS, supportsPartitionsDDLButton.getSelection());

                    UIUtils.runInUI(sqlGenerator);
                    Object sql = sqlGenerator.getResult();
                    if (sql != null) {
                        setSQLText(CommonUtils.toString(sql));
                        updateSQL();
                    }
                }
            });
        }
        return composite;
    }
}

<MSG> Merge pull request #9497 from dbeaver/postgre-table-comment-ddl#9387

Postgre table comment ddl#9387

Former-commit-id: deeac2e2f5da9ee245fdc8a36a53719661044c75
<DFF> @@ -24,6 +24,8 @@ import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Group;
 import org.eclipse.ui.IWorkbenchPartSite;
+import org.jkiss.dbeaver.model.DBPScriptObject;
+import org.jkiss.dbeaver.model.DBPScriptObjectExt2;
 import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
 import org.jkiss.dbeaver.model.sql.generator.SQLGenerator;
 import org.jkiss.dbeaver.ui.UIUtils;
@@ -46,12 +48,39 @@ class SQLGeneratorDialog extends ViewSQLDialog {
 
     @Override
     protected Composite createDialogArea(Composite parent) {
-        sqlGenerator.setFullyQualifiedNames(
-            getDialogBoundsSettings().get(PROP_USE_FQ_NAMES) == null ||
+        sqlGenerator.setFullyQualifiedNames(getDialogBoundsSettings().get(PROP_USE_FQ_NAMES) == null ||
                 getDialogBoundsSettings().getBoolean(PROP_USE_FQ_NAMES));
-        sqlGenerator.setCompactSQL(
-            getDialogBoundsSettings().get(PROP_USE_COMPACT_SQL) != null &&
+        sqlGenerator.setCompactSQL(getDialogBoundsSettings().get(PROP_USE_COMPACT_SQL) != null &&
                 getDialogBoundsSettings().getBoolean(PROP_USE_COMPACT_SQL));
+
+        boolean supportPermissions = false;
+        boolean supportComments = false;
+        boolean supportFullDDL = false;
+        for (Object object : sqlGenerator.getObjects()) {
+            if (object instanceof DBPScriptObjectExt2) {
+                DBPScriptObjectExt2 sourceObject = (DBPScriptObjectExt2) object;
+                if (sourceObject.supportsObjectDefinitionOption(DBPScriptObject.OPTION_INCLUDE_PERMISSIONS)) {
+                    supportPermissions = true;
+                }
+                if (sourceObject.supportsObjectDefinitionOption(DBPScriptObject.OPTION_INCLUDE_COMMENTS)) {
+                    supportComments = true;
+                }
+                if (sourceObject.supportsObjectDefinitionOption(DBPScriptObject.OPTION_INCLUDE_NESTED_OBJECTS)) {
+                    supportFullDDL = true;
+                }
+                if (supportPermissions && supportComments && supportFullDDL) {
+                    break; //it supports everything
+                }
+            }
+        }
+
+        sqlGenerator.setShowPermissions(getDialogBoundsSettings().get(DBPScriptObject.OPTION_INCLUDE_PERMISSIONS) != null &&
+                getDialogBoundsSettings().getBoolean(DBPScriptObject.OPTION_INCLUDE_PERMISSIONS));
+        sqlGenerator.setShowComments(getDialogBoundsSettings().get(DBPScriptObject.OPTION_INCLUDE_COMMENTS) != null &&
+                getDialogBoundsSettings().getBoolean(DBPScriptObject.OPTION_INCLUDE_COMMENTS));
+        sqlGenerator.setShowFullDdl(getDialogBoundsSettings().get(DBPScriptObject.OPTION_INCLUDE_NESTED_OBJECTS) != null &&
+                getDialogBoundsSettings().getBoolean(DBPScriptObject.OPTION_INCLUDE_NESTED_OBJECTS));
+
         UIUtils.runInUI(sqlGenerator);
         Object sql = sqlGenerator.getResult();
         if (sql != null) {
@@ -59,8 +88,7 @@ class SQLGeneratorDialog extends ViewSQLDialog {
         }
 
         Composite composite = super.createDialogArea(parent);
-
-        Group settings = UIUtils.createControlGroup(composite, "Settings", 2, GridData.FILL_HORIZONTAL, SWT.DEFAULT);
+        Group settings = UIUtils.createControlGroup(composite, "Settings", 5, GridData.FILL_HORIZONTAL, SWT.DEFAULT);
         Button useFQNames = UIUtils.createCheckbox(settings, "Use fully qualified names", sqlGenerator.isFullyQualifiedNames());
         useFQNames.addSelectionListener(new SelectionAdapter() {
             @Override
@@ -91,7 +119,57 @@ class SQLGeneratorDialog extends ViewSQLDialog {
                 }
             }
         });
+        if (supportComments) {
+            Button useShowComments = UIUtils.createCheckbox(settings, "Show comments", sqlGenerator.isShowComments());
+            useShowComments.addSelectionListener(new SelectionAdapter() {
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    sqlGenerator.setShowComments(useShowComments.getSelection());
+                    getDialogBoundsSettings().put(DBPScriptObject.OPTION_INCLUDE_COMMENTS, useShowComments.getSelection());
 
+                    UIUtils.runInUI(sqlGenerator);
+                    Object sql = sqlGenerator.getResult();
+                    if (sql != null) {
+                        setSQLText(CommonUtils.toString(sql));
+                        updateSQL();
+                    }
+                }
+            });
+        }
+        if (supportPermissions) {
+            Button useShowPermissions = UIUtils.createCheckbox(settings, "Show permissions", sqlGenerator.isIncludePermissions());
+            useShowPermissions.addSelectionListener(new SelectionAdapter() {
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    sqlGenerator.setShowPermissions(useShowPermissions.getSelection());
+                    getDialogBoundsSettings().put(DBPScriptObject.OPTION_INCLUDE_PERMISSIONS, useShowPermissions.getSelection());
+
+                    UIUtils.runInUI(sqlGenerator);
+                    Object sql = sqlGenerator.getResult();
+                    if (sql != null) {
+                        setSQLText(CommonUtils.toString(sql));
+                        updateSQL();
+                    }
+                }
+            });
+        }
+        if (supportFullDDL) {
+            Button useShowFullDdl = UIUtils.createCheckbox(settings, "Show full DDL", sqlGenerator.isShowFullDdl());
+            useShowFullDdl.addSelectionListener(new SelectionAdapter() {
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    sqlGenerator.setShowFullDdl(useShowFullDdl.getSelection());
+                    getDialogBoundsSettings().put(DBPScriptObject.OPTION_INCLUDE_COMMENTS, useShowFullDdl.getSelection());
+
+                    UIUtils.runInUI(sqlGenerator);
+                    Object sql = sqlGenerator.getResult();
+                    if (sql != null) {
+                        setSQLText(CommonUtils.toString(sql));
+                        updateSQL();
+                    }
+                }
+            });
+        }
         return composite;
     }
 }

{'addition_count': 84, 'commit_subject': 'Merge pull request #9497 from dbeaver/postgre-table-comment-ddl#9387', 'deletion_count': 6, 'file_extension': '.java', 'lang': 'jkiss', 'license': 'apache-2.0', 'repo_name': 'dbeaver/dbeaver'}