Search in sources :

Example 16 with UIServiceSQL

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

the class ResultSetHandlerCopyAs method openResultsWith.

private static void openResultsWith(IResultSetController resultSet, DataTransferProcessorDescriptor processor) {
    ResultSetDataContainerOptions options = new ResultSetDataContainerOptions();
    IResultSetSelection rsSelection = resultSet.getSelection();
    List<ResultSetRow> rsSelectedRows = rsSelection.getSelectedRows();
    List<DBDAttributeBinding> rsSelectedAttributes = rsSelection.getSelectedAttributes();
    if (rsSelectedRows.size() > 1 || rsSelectedAttributes.size() > 1) {
        List<Long> selectedRows = new ArrayList<>();
        for (ResultSetRow selectedRow : rsSelectedRows) {
            selectedRows.add((long) selectedRow.getRowNumber());
        }
        List<String> selectedAttributes = new ArrayList<>();
        for (DBDAttributeBinding attributeBinding : rsSelectedAttributes) {
            selectedAttributes.add(attributeBinding.getName());
        }
        options.setSelectedRows(selectedRows);
        options.setSelectedColumns(selectedAttributes);
    }
    ResultSetDataContainer dataContainer = new ResultSetDataContainer(resultSet, options);
    if (dataContainer.getDataSource() == null) {
        DBWorkbench.getPlatformUI().showError("Copy as " + processor.getName(), ModelMessages.error_not_connected_to_database);
        return;
    }
    AbstractJob exportJob = new AbstractJob("Copy as " + processor.getName()) {

        {
            setUser(true);
            setSystem(false);
        }

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            monitor.beginTask("Copy data as", 3);
            try {
                monitor.subTask("Init");
                IDataTransferProcessor processorInstance = processor.getInstance();
                if (!(processorInstance instanceof IStreamDataExporter)) {
                    return Status.CANCEL_STATUS;
                }
                IStreamDataExporter exporter = (IStreamDataExporter) processorInstance;
                StreamTransferConsumer consumer = new StreamTransferConsumer();
                StreamConsumerSettings settings = new StreamConsumerSettings();
                settings.setOutputClipboard(true);
                settings.setOutputEncodingBOM(false);
                settings.setOpenFolderOnFinish(false);
                Map<String, Object> properties = new HashMap<>();
                for (DBPPropertyDescriptor prop : processor.getProperties()) {
                    properties.put(prop.getId(), prop.getDefaultValue());
                }
                consumer.initTransfer(dataContainer, settings, new IDataTransferConsumer.TransferParameters(processor.isBinaryFormat(), processor.isHTMLFormat()), exporter, properties);
                DBDDataFilter dataFilter = resultSet.getModel().getDataFilter();
                DatabaseTransferProducer producer = new DatabaseTransferProducer(dataContainer, dataFilter);
                DatabaseProducerSettings producerSettings = new DatabaseProducerSettings();
                producerSettings.setOpenNewConnections(false);
                if (resultSet.isHasMoreData()) {
                    // For long resultsets we may need to open new connection
                    UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
                    if (serviceSQL != null) {
                        producerSettings.setOpenNewConnections(serviceSQL.useIsolatedConnections(resultSet));
                    }
                }
                producerSettings.setExtractType(DatabaseProducerSettings.ExtractType.SINGLE_QUERY);
                producerSettings.setQueryRowCount(false);
                producerSettings.setSelectedRowsOnly(!CommonUtils.isEmpty(options.getSelectedRows()));
                producerSettings.setSelectedColumnsOnly(!CommonUtils.isEmpty(options.getSelectedColumns()));
                monitor.worked(1);
                monitor.subTask("Export data");
                producer.transferData(monitor, consumer, null, producerSettings, null);
                monitor.worked(1);
                monitor.subTask("Finalize export");
                consumer.finishTransfer(monitor, false);
                consumer.finishTransfer(monitor, true);
                monitor.worked(1);
            } catch (Exception e) {
                DBWorkbench.getPlatformUI().showError("Error opening in " + processor.getAppName(), null, e);
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        }
    };
    exportJob.schedule();
}
Also used : DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) StreamConsumerSettings(org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) StreamTransferConsumer(org.jkiss.dbeaver.tools.transfer.stream.StreamTransferConsumer) IDataTransferConsumer(org.jkiss.dbeaver.tools.transfer.IDataTransferConsumer) IDataTransferProcessor(org.jkiss.dbeaver.tools.transfer.IDataTransferProcessor) ExecutionException(org.eclipse.core.commands.ExecutionException) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) DatabaseProducerSettings(org.jkiss.dbeaver.tools.transfer.database.DatabaseProducerSettings) IStreamDataExporter(org.jkiss.dbeaver.tools.transfer.stream.IStreamDataExporter) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL)

Example 17 with UIServiceSQL

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

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

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

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

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

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

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

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)

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