Search in sources :

Example 11 with UIServiceSQL

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

the class PostgreFDWConfigWizardPageFinal method createControl.

@Override
public void createControl(Composite parent) {
    Composite composite = UIUtils.createComposite(parent, 1);
    {
        Group settingsGroup = UIUtils.createControlGroup(composite, "Script", 1, GridData.FILL_BOTH, 0);
        Composite sqlPanelPH = new Composite(settingsGroup, SWT.NONE);
        sqlPanelPH.setLayoutData(new GridData(GridData.FILL_BOTH));
        sqlPanelPH.setLayout(new FillLayout());
        UIServiceSQL service = DBWorkbench.getService(UIServiceSQL.class);
        if (service != null) {
            try {
                sqlPanel = service.createSQLPanel(UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite(), sqlPanelPH, getWizard(), "FDW Script", true, "");
            } catch (DBException e) {
                log.debug(e);
                setErrorMessage(e.getMessage());
            }
        }
        Composite buttonsPanel = UIUtils.createComposite(settingsGroup, 2);
        buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        UIUtils.createDialogButton(buttonsPanel, "Copy", new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                UIUtils.setClipboardContents(buttonsPanel.getDisplay(), TextTransfer.getInstance(), scriptText);
            }
        });
        UIUtils.createDialogButton(buttonsPanel, "Save ...", new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                final File saveFile = DialogUtils.selectFileForSave(buttonsPanel.getShell(), "Save SQL script", new String[] { "*.sql", "*.txt", "*", "*.*" }, null);
                if (saveFile != null) {
                    try {
                        IOUtils.writeFileFromString(saveFile, scriptText);
                    } catch (IOException e1) {
                        DBWorkbench.getPlatformUI().showError("Save scritp to file", "Error saving script to file " + saveFile.getAbsolutePath(), e1);
                    }
                }
            }
        });
    }
    setControl(composite);
}
Also used : Group(org.eclipse.swt.widgets.Group) DBException(org.jkiss.dbeaver.DBException) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FillLayout(org.eclipse.swt.layout.FillLayout) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) IOException(java.io.IOException) File(java.io.File)

Example 12 with UIServiceSQL

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

the class SavePreviewDialog method createDetailsContents.

@Override
protected Control createDetailsContents(Composite composite) {
    Composite group = new Composite(composite, SWT.NONE);
    group.setLayout(new GridLayout(1, true));
    group.setLayoutData(new GridData(GridData.FILL_BOTH));
    Composite previewFrame = new Composite(group, SWT.BORDER);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 250;
    previewFrame.setLayoutData(gd);
    previewFrame.setLayout(new FillLayout());
    UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
    if (serviceSQL != null) {
        try {
            sqlPanel = serviceSQL.createSQLPanel(viewer.getSite(), previewFrame, 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();
    return previewFrame;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL)

Example 13 with UIServiceSQL

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

the class NavigatorViewBase method createNavigatorTree.

private DatabaseNavigatorTree createNavigatorTree(Composite parent, DBNNode rootNode) {
    // Create tree
    final DatabaseNavigatorTree navigatorTree = new DatabaseNavigatorTree(parent, rootNode, getTreeStyle(), false, getNavigatorFilter());
    createTreeColumns(navigatorTree);
    navigatorTree.getViewer().addSelectionChangedListener(event -> onSelectionChange((IStructuredSelection) event.getSelection()));
    navigatorTree.getViewer().getTree().addListener(SWT.MouseDoubleClick, event -> {
        event.doit = false;
    });
    navigatorTree.getViewer().getTree().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            super.mouseDoubleClick(e);
        }

        @Override
        public void mouseDown(MouseEvent e) {
            super.mouseDown(e);
        }

        @Override
        public void mouseUp(MouseEvent e) {
            super.mouseUp(e);
        }
    });
    navigatorTree.getViewer().addDoubleClickListener(event -> {
        TreeViewer viewer = tree.getViewer();
        IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
        for (Object node : selection.toArray()) {
            // Object node = selection.getFirstElement();
            if ((node instanceof DBNResource && ((DBNResource) node).getResource() instanceof IFolder)) {
                toggleNode(viewer, node);
            } else if (node instanceof DBNDataSource) {
                NavigatorPreferences.DoubleClickBehavior dsBehaviorDefault = CommonUtils.valueOf(NavigatorPreferences.DoubleClickBehavior.class, DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.NAVIGATOR_CONNECTION_DOUBLE_CLICK), NavigatorPreferences.DoubleClickBehavior.EDIT);
                if (dsBehaviorDefault == NavigatorPreferences.DoubleClickBehavior.EXPAND) {
                    toggleNode(viewer, node);
                } else {
                    DBPDataSourceContainer dataSource = ((DBNDataSource) node).getObject();
                    switch(dsBehaviorDefault) {
                        case EDIT:
                            NavigatorHandlerObjectOpen.openEntityEditor((DBNDataSource) node, null, UIUtils.getActiveWorkbenchWindow());
                            break;
                        case CONNECT:
                            {
                                UIServiceConnections serviceConnections = DBWorkbench.getService(UIServiceConnections.class);
                                if (serviceConnections != null) {
                                    if (dataSource.isConnected()) {
                                        serviceConnections.disconnectDataSource(dataSource);
                                    } else {
                                        serviceConnections.connectDataSource(dataSource, null);
                                    }
                                }
                                break;
                            }
                        case SQL_EDITOR:
                            {
                                UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
                                if (serviceSQL != null) {
                                    serviceSQL.openRecentScript(dataSource);
                                }
                                break;
                            }
                        case SQL_EDITOR_NEW:
                            {
                                UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
                                if (serviceSQL != null) {
                                    serviceSQL.openNewScript(dataSource);
                                }
                                break;
                            }
                    }
                }
            } else if (node instanceof TreeNodeSpecial) {
                ((TreeNodeSpecial) node).handleDefaultAction(navigatorTree);
            } else {
                String defaultEditorPageId = null;
                NavigatorPreferences.DoubleClickBehavior dcBehaviorDefault = CommonUtils.valueOf(NavigatorPreferences.DoubleClickBehavior.class, DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.NAVIGATOR_OBJECT_DOUBLE_CLICK));
                if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof DBSDataContainer) {
                    defaultEditorPageId = DBWorkbench.getPlatform().getPreferenceStore().getString(NavigatorPreferences.NAVIGATOR_DEFAULT_EDITOR_PAGE);
                }
                boolean hasChildren = node instanceof DBNNode && ((DBNNode) node).hasChildren(true);
                if (hasChildren && dcBehaviorDefault == NavigatorPreferences.DoubleClickBehavior.EXPAND) {
                    toggleNode(viewer, node);
                } else {
                    Map<String, Object> parameters = null;
                    if (!CommonUtils.isEmpty(defaultEditorPageId)) {
                        parameters = Collections.singletonMap(MultiPageDatabaseEditor.PARAMETER_ACTIVE_PAGE, defaultEditorPageId);
                    }
                    NavigatorUtils.executeNodeAction(DBXTreeNodeHandler.Action.open, node, parameters, getSite());
                }
            }
        }
    });
    // Hook context menu
    NavigatorUtils.addContextMenu(this.getSite(), navigatorTree.getViewer());
    // Add drag and drop support
    NavigatorUtils.addDragAndDropSupport(navigatorTree.getViewer());
    DBWorkbench.getPlatform().getPreferenceStore().addPropertyChangeListener(this);
    return navigatorTree;
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TreeViewer(org.eclipse.jface.viewers.TreeViewer) MouseAdapter(org.eclipse.swt.events.MouseAdapter) NavigatorPreferences(org.jkiss.dbeaver.ui.navigator.NavigatorPreferences) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) UIServiceConnections(org.jkiss.dbeaver.runtime.ui.UIServiceConnections) TreeNodeSpecial(org.jkiss.dbeaver.ui.navigator.database.load.TreeNodeSpecial) IFolder(org.eclipse.core.resources.IFolder)

Example 14 with UIServiceSQL

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

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 15 with UIServiceSQL

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

the class PostgreFDWConfigWizardPageFinal method createControl.

@Override
public void createControl(Composite parent) {
    Composite composite = UIUtils.createComposite(parent, 1);
    {
        Group settingsGroup = UIUtils.createControlGroup(composite, "Script", 1, GridData.FILL_BOTH, 0);
        Composite sqlPanelPH = new Composite(settingsGroup, SWT.NONE);
        sqlPanelPH.setLayoutData(new GridData(GridData.FILL_BOTH));
        sqlPanelPH.setLayout(new FillLayout());
        UIServiceSQL service = DBWorkbench.getService(UIServiceSQL.class);
        if (service != null) {
            try {
                sqlPanel = service.createSQLPanel(UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite(), sqlPanelPH, getWizard(), "FDW Script", true, "");
            } catch (DBException e) {
                log.debug(e);
                setErrorMessage(e.getMessage());
            }
        }
        Composite buttonsPanel = UIUtils.createComposite(settingsGroup, 2);
        buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        UIUtils.createDialogButton(buttonsPanel, "Copy", new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                UIUtils.setClipboardContents(buttonsPanel.getDisplay(), TextTransfer.getInstance(), scriptText);
            }
        });
        UIUtils.createDialogButton(buttonsPanel, "Save ...", new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                final File saveFile = DialogUtils.selectFileForSave(buttonsPanel.getShell(), "Save SQL script", new String[] { "*.sql", "*.txt", "*", "*.*" }, null);
                if (saveFile != null) {
                    try {
                        IOUtils.writeFileFromString(saveFile, scriptText);
                    } catch (IOException e1) {
                        DBWorkbench.getPlatformUI().showError("Save scritp to file", "Error saving script to file " + saveFile.getAbsolutePath(), e1);
                    }
                }
            }
        });
    }
    setControl(composite);
}
Also used : Group(org.eclipse.swt.widgets.Group) DBException(org.jkiss.dbeaver.DBException) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FillLayout(org.eclipse.swt.layout.FillLayout) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) IOException(java.io.IOException) File(java.io.File)

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