Search in sources :

Example 21 with UIServiceSQL

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

the class NavigatorHandlerObjectBase method showScript.

protected static boolean showScript(IWorkbenchWindow workbenchWindow, DBECommandContext commandContext, Map<String, Object> options, String dialogTitle) {
    Collection<? extends DBECommand> commands = commandContext.getFinalCommands();
    StringBuilder script = new StringBuilder();
    try {
        UIUtils.runInProgressService(monitor -> {
            try {
                for (DBECommand command : commands) {
                    DBEPersistAction[] persistActions = command.getPersistActions(monitor, commandContext.getExecutionContext(), options);
                    script.append(SQLUtils.generateScript(commandContext.getExecutionContext().getDataSource(), persistActions, false));
                    if (script.length() == 0) {
                        script.append(SQLUtils.generateComments(commandContext.getExecutionContext().getDataSource(), persistActions, false));
                    }
                }
            } catch (DBException e) {
                throw new InvocationTargetException(e);
            }
        });
    } catch (InvocationTargetException e) {
        DBWorkbench.getPlatformUI().showError("Script generation error", "Error generating alter script", e.getTargetException());
    } catch (InterruptedException e) {
        return false;
    }
    if (script.length() > 0) {
        UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
        if (serviceSQL != null) {
            return serviceSQL.openSQLViewer(commandContext.getExecutionContext(), dialogTitle, UIIcon.SQL_PREVIEW, script.toString(), true, false) == IDialogConstants.PROCEED_ID;
        }
    } else {
        return UIUtils.confirmAction(workbenchWindow.getShell(), dialogTitle, "No SQL script available.\nAre you sure you want to proceed?");
    }
    return false;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBECommand(org.jkiss.dbeaver.model.edit.DBECommand) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 22 with UIServiceSQL

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

the class NavigatorHandlerObjectOpen method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    if (UIUtils.isInDialog()) {
        // If some modal dialog is open then we don't do this
        return null;
    }
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        if (structSelection.size() > MAX_OBJECT_SIZE_NO_CONFIRM) {
            if (!UIUtils.confirmAction(HandlerUtil.getActiveShell(event), "Open " + structSelection.size() + " editors", "You are about to open " + structSelection.size() + " editors. Are you sure?")) {
                return null;
            }
        }
        for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
            Object element = iter.next();
            DBNNode node = null;
            if (element instanceof IResource) {
                UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
                if (serviceSQL != null) {
                    serviceSQL.openResource((IResource) element);
                }
                continue;
            } else if (element instanceof DBNNode) {
                node = (DBNNode) element;
            } else {
                DBSObject object = RuntimeUtils.getObjectAdapter(element, DBSObject.class);
                if (object != null) {
                    node = getNodeByObject(object);
                }
            }
            if (node != null) {
                NavigatorUtils.openNavigatorNode(node, HandlerUtil.getActiveWorkbenchWindow(event), event.getParameters());
            }
        }
    }
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ISelection(org.eclipse.jface.viewers.ISelection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) IResource(org.eclipse.core.resources.IResource)

Example 23 with UIServiceSQL

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

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

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

the class NavigatorHandlerObjectBase method showScript.

protected static boolean showScript(IWorkbenchWindow workbenchWindow, DBECommandContext commandContext, Map<String, Object> options, String dialogTitle) {
    Collection<? extends DBECommand> commands = commandContext.getFinalCommands();
    StringBuilder script = new StringBuilder();
    try {
        UIUtils.runInProgressService(monitor -> {
            try {
                for (DBECommand command : commands) {
                    DBEPersistAction[] persistActions = command.getPersistActions(monitor, commandContext.getExecutionContext(), options);
                    script.append(SQLUtils.generateScript(commandContext.getExecutionContext().getDataSource(), persistActions, false));
                    if (script.length() == 0) {
                        script.append(SQLUtils.generateComments(commandContext.getExecutionContext().getDataSource(), persistActions, false));
                    }
                }
            } catch (DBException e) {
                throw new InvocationTargetException(e);
            }
        });
    } catch (InvocationTargetException e) {
        DBWorkbench.getPlatformUI().showError("Script generation error", "Error generating alter script", e.getTargetException());
    } catch (InterruptedException e) {
        return false;
    }
    if (script.length() > 0) {
        UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
        if (serviceSQL != null) {
            return serviceSQL.openSQLViewer(commandContext.getExecutionContext(), dialogTitle, UIIcon.SQL_PREVIEW, script.toString(), true, false) == IDialogConstants.PROCEED_ID;
        }
    } else {
        return UIUtils.confirmAction(workbenchWindow.getShell(), dialogTitle, "No SQL script available.\nAre you sure you want to proceed?");
    }
    return false;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBECommand(org.jkiss.dbeaver.model.edit.DBECommand) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 25 with UIServiceSQL

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

the class NavigatorHandlerObjectOpen method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    if (UIUtils.isInDialog()) {
        // If some modal dialog is open then we don't do this
        return null;
    }
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        if (structSelection.size() > MAX_OBJECT_SIZE_NO_CONFIRM) {
            if (!UIUtils.confirmAction(HandlerUtil.getActiveShell(event), "Open " + structSelection.size() + " editors", "You are about to open " + structSelection.size() + " editors. Are you sure?")) {
                return null;
            }
        }
        for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
            Object element = iter.next();
            DBNNode node = null;
            if (element instanceof IResource) {
                UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
                if (serviceSQL != null) {
                    serviceSQL.openResource((IResource) element);
                }
                continue;
            } else if (element instanceof DBNNode) {
                node = (DBNNode) element;
            } else {
                DBSObject object = RuntimeUtils.getObjectAdapter(element, DBSObject.class);
                if (object != null) {
                    node = getNodeByObject(object);
                }
            }
            if (node != null) {
                NavigatorUtils.openNavigatorNode(node, HandlerUtil.getActiveWorkbenchWindow(event), event.getParameters());
            }
        }
    }
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ISelection(org.eclipse.jface.viewers.ISelection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) IResource(org.eclipse.core.resources.IResource)

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