Search in sources :

Example 1 with TaskTypeDescriptor

use of org.jkiss.dbeaver.registry.task.TaskTypeDescriptor in project dbeaver by serge-rider.

the class SQLToolTaskWizardPageSettings method createControl.

@Override
public void createControl(Composite parent) {
    initializeDialogUnits(parent);
    Composite composite = UIUtils.createComposite(parent, 1);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    SashForm previewSplitter = new SashForm(composite, SWT.VERTICAL);
    previewSplitter.setLayoutData(new GridData(GridData.FILL_BOTH));
    SashForm settingsPanel = new SashForm(previewSplitter, SWT.HORIZONTAL);
    Group objectsPanel;
    {
        objectsPanel = UIUtils.createControlGroup(settingsPanel, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_group_label_objects, 2, GridData.FILL_BOTH, 0);
        objectsViewer = new TableViewer(objectsPanel, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
        objectsViewer.setContentProvider(new ListContentProvider());
        objectsViewer.setLabelProvider(new ColumnLabelProvider() {

            @Override
            public String getText(Object element) {
                return DBUtils.getObjectFullName((DBPNamedObject) element, DBPEvaluationContext.UI);
            }

            @Override
            public Image getImage(Object element) {
                return DBeaverIcons.getImage(DBValueFormatting.getObjectImage((DBPObject) element));
            }
        });
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 150;
        gd.widthHint = 200;
        final Table objectTable = objectsViewer.getTable();
        objectTable.setLayoutData(gd);
        ToolBar buttonsToolbar = new ToolBar(objectsPanel, SWT.VERTICAL);
        buttonsToolbar.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
        UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_add_string, UIIcon.ROW_ADD, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(sqlWizard.getProject());
                SQLToolTaskObjectSelectorDialog objectListDialog = new SQLToolTaskObjectSelectorDialog(getShell(), projectNode, (TaskTypeDescriptor) sqlWizard.getTaskType());
                if (objectListDialog.open() == IDialogConstants.OK_ID) {
                    for (DBSObject object : objectListDialog.getSelectedObjects()) {
                        if (!selectedObjects.contains(object)) {
                            selectedObjects.add(object);
                        }
                    }
                    refreshObjects();
                    updatePageCompletion();
                }
            }
        });
        ToolItem deleteItem = UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_remove_string, UIIcon.ROW_DELETE, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                ISelection selection = objectsViewer.getSelection();
                if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
                    for (Object element : ((IStructuredSelection) selection).toArray()) {
                        if (element instanceof DBSObject) {
                            selectedObjects.remove(element);
                        }
                    }
                    refreshObjects();
                    updatePageCompletion();
                }
            }
        });
        UIUtils.createToolBarSeparator(buttonsToolbar, SWT.HORIZONTAL);
        ToolItem[] moveButtons = new ToolItem[2];
        moveButtons[0] = UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_move_script_up, UIIcon.ARROW_UP, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = objectTable.getSelectionIndex();
                if (selectionIndex > 0) {
                    DBSObject prevScript = selectedObjects.get(selectionIndex - 1);
                    selectedObjects.set(selectionIndex - 1, selectedObjects.get(selectionIndex));
                    selectedObjects.set(selectionIndex, prevScript);
                    refreshObjects();
                }
                moveButtons[0].setEnabled(selectionIndex > 1);
                moveButtons[1].setEnabled(selectionIndex < objectTable.getItemCount() - 1);
            }
        });
        moveButtons[1] = UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_move_script_down, UIIcon.ARROW_DOWN, new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                int selectionIndex = objectTable.getSelectionIndex();
                if (selectionIndex < objectTable.getItemCount() - 1) {
                    DBSObject nextScript = selectedObjects.get(selectionIndex + 1);
                    selectedObjects.set(selectionIndex + 1, selectedObjects.get(selectionIndex));
                    selectedObjects.set(selectionIndex, nextScript);
                    refreshObjects();
                }
                moveButtons[0].setEnabled(selectionIndex > 0);
                moveButtons[1].setEnabled(selectionIndex < objectTable.getItemCount() - 2);
            }
        });
        objectsViewer.addSelectionChangedListener(event -> {
            int selectionIndex = objectTable.getSelectionIndex();
            deleteItem.setEnabled(selectionIndex >= 0);
            moveButtons[0].setEnabled(selectionIndex > 0);
            moveButtons[1].setEnabled(selectionIndex < objectTable.getItemCount() - 1);
        });
        deleteItem.setEnabled(false);
        moveButtons[0].setEnabled(false);
        moveButtons[1].setEnabled(false);
    }
    {
        Group optionsPanel = UIUtils.createControlGroup(settingsPanel, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_group_label_settings, 1, GridData.FILL_BOTH, 0);
        taskOptionsViewer = new PropertyTreeViewer(optionsPanel, SWT.BORDER);
        taskOptionsViewer.addPropertyChangeListener(event -> updateScriptPreview());
    }
    Composite previewPanel = UIUtils.createComposite(previewSplitter, 1);
    previewPanel.setLayout(new FillLayout());
    serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
    if (serviceSQL != null) {
        try {
            sqlPreviewPanel = serviceSQL.createSQLPanel(UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite(), previewPanel, this, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_sql_panel_name, true, "");
        } catch (DBException e) {
            DBWorkbench.getPlatformUI().showError(TasksSQLUIMessages.sql_tool_task_wizard_page_settings_title_sql_preview_error, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_message_sql_preview_panel, e);
        }
    }
    Composite controlsPanel = UIUtils.createComposite(composite, 2);
    UIUtils.createDialogButton(controlsPanel, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_dialog_button_label_copy, new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String text = serviceSQL.getSQLPanelText(sqlPreviewPanel);
            if (!CommonUtils.isEmpty(text)) {
                UIUtils.setClipboardContents(getShell().getDisplay(), TextTransfer.getInstance(), text);
            }
        }
    });
    getWizard().createTaskSaveButtons(controlsPanel, true, 1);
    loadSettings();
    if (taskOptionsViewer.getTree().getItemCount() == 0) {
        settingsPanel.setMaximizedControl(objectsPanel);
    }
    setControl(composite);
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) ActiveWizardPage(org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) SashForm(org.eclipse.swt.custom.SashForm) Image(org.eclipse.swt.graphics.Image) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) DBCException(org.jkiss.dbeaver.model.exec.DBCException) Nullable(org.jkiss.code.Nullable) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) TaskTypeDescriptor(org.jkiss.dbeaver.registry.task.TaskTypeDescriptor) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) ArrayList(java.util.ArrayList) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) UIUtils(org.jkiss.dbeaver.ui.UIUtils) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Log(org.jkiss.dbeaver.Log) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) UIIcon(org.jkiss.dbeaver.ui.UIIcon) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) org.jkiss.dbeaver.model(org.jkiss.dbeaver.model) SQLToolExecuteSettings(org.jkiss.dbeaver.model.sql.task.SQLToolExecuteSettings) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) NLS(org.eclipse.osgi.util.NLS) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) org.eclipse.swt.widgets(org.eclipse.swt.widgets) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) PropertySourceEditable(org.jkiss.dbeaver.runtime.properties.PropertySourceEditable) List(java.util.List) SQLToolExecuteHandler(org.jkiss.dbeaver.model.sql.task.SQLToolExecuteHandler) DBException(org.jkiss.dbeaver.DBException) TasksSQLUIMessages(org.jkiss.dbeaver.tasks.ui.sql.internal.TasksSQLUIMessages) SWT(org.eclipse.swt.SWT) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBException(org.jkiss.dbeaver.DBException) PropertyTreeViewer(org.jkiss.dbeaver.ui.properties.PropertyTreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) SashForm(org.eclipse.swt.custom.SashForm) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) GridData(org.eclipse.swt.layout.GridData) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 2 with TaskTypeDescriptor

use of org.jkiss.dbeaver.registry.task.TaskTypeDescriptor in project dbeaver by serge-rider.

the class TaskConfigurationWizardDialog method openNewTaskDialog.

public static int openNewTaskDialog(IWorkbenchWindow window, DBPProject project, String taskTypeId, IStructuredSelection selection) {
    TaskTypeDescriptor taskType = TaskRegistry.getInstance().getTaskType(taskTypeId);
    if (taskType == null) {
        DBWorkbench.getPlatformUI().showError("Bad task type", "Task type '" + taskTypeId + "' not found");
        return IDialogConstants.CANCEL_ID;
    }
    try {
        DBTTask task = project.getTaskManager().createTemporaryTask(taskType, taskType.getName());
        task.setProperties(new HashMap<>());
        DBTTaskConfigurator configurator = TaskUIRegistry.getInstance().createConfigurator(taskType);
        TaskConfigurationWizard configWizard = configurator.createTaskConfigWizard(task);
        TaskConfigurationWizardDialog dialog = new TaskConfigurationWizardDialog(window, configWizard, selection);
        return dialog.open();
    } catch (DBException e) {
        DBWorkbench.getPlatformUI().showError("Task create error", "Error creating task '" + taskTypeId + "'", e);
        return IDialogConstants.CANCEL_ID;
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBTTaskConfigurator(org.jkiss.dbeaver.tasks.ui.DBTTaskConfigurator) DBTTask(org.jkiss.dbeaver.model.task.DBTTask) TaskTypeDescriptor(org.jkiss.dbeaver.registry.task.TaskTypeDescriptor)

Aggregations

DBException (org.jkiss.dbeaver.DBException)2 TaskTypeDescriptor (org.jkiss.dbeaver.registry.task.TaskTypeDescriptor)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 NLS (org.eclipse.osgi.util.NLS)1 SWT (org.eclipse.swt.SWT)1 SashForm (org.eclipse.swt.custom.SashForm)1 TextTransfer (org.eclipse.swt.dnd.TextTransfer)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Image (org.eclipse.swt.graphics.Image)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridData (org.eclipse.swt.layout.GridData)1 org.eclipse.swt.widgets (org.eclipse.swt.widgets)1 Nullable (org.jkiss.code.Nullable)1