Search in sources :

Example 16 with DBTTask

use of org.jkiss.dbeaver.model.task.DBTTask in project dbeaver by serge-rider.

the class TaskConfigurationWizardPageSettings method activatePage.

@Override
public void activatePage() {
    DBTTask currentTask = getWizard().getCurrentTask();
    DBTTaskType selectedTaskType = currentTask != null ? currentTask.getType() : getTaskPage().getSelectedTaskType();
    if (curTaskType == selectedTaskType) {
        return;
    }
    curTaskType = selectedTaskType;
    createTaskSettingsUI();
    if (curTaskType == null) {
        setTitle(TaskUIMessages.task_config_wizard_page_settings_title_task_prop);
        setDescription(TaskUIMessages.task_config_wizard_page_settings_descr_set_task);
    } else {
        String title = curTaskType.getName();
        if (getWizard().getCurrentTask() != null) {
            title += " (" + getWizard().getCurrentTask().getName() + ")";
        }
        setTitle(title);
        setDescription(NLS.bind(TaskUIMessages.task_config_wizard_page_settings_config, curTaskType.getName()));
    }
    setPageComplete(determinePageCompletion());
}
Also used : DBTTask(org.jkiss.dbeaver.model.task.DBTTask) DBTTaskType(org.jkiss.dbeaver.model.task.DBTTaskType)

Example 17 with DBTTask

use of org.jkiss.dbeaver.model.task.DBTTask in project dbeaver by serge-rider.

the class TaskHandlerRun method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    String taskId = event.getParameter("task");
    DBTTask task = null;
    if (!CommonUtils.isEmpty(taskId)) {
        task = NavigatorUtils.getSelectedProject().getTaskManager().getTaskById(taskId);
    } else {
        final ISelection selection = HandlerUtil.getCurrentSelection(event);
        if (selection instanceof IStructuredSelection) {
            Object element = ((IStructuredSelection) selection).getFirstElement();
            if (element instanceof DBTTask) {
                task = (DBTTask) element;
            }
        }
    }
    if (task != null) {
        runTask(task);
    }
    return null;
}
Also used : DBTTask(org.jkiss.dbeaver.model.task.DBTTask) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 18 with DBTTask

use of org.jkiss.dbeaver.model.task.DBTTask in project dbeaver by serge-rider.

the class TaskHandlerDelete method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    List<DBTTask> tasksToDelete = new ArrayList<>();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structSelection = (IStructuredSelection) selection;
        for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
            Object element = iter.next();
            if (element instanceof DBTTask) {
                tasksToDelete.add((DBTTask) element);
            }
        }
    }
    if (!tasksToDelete.isEmpty()) {
        if (tasksToDelete.size() == 1) {
            if (!UIUtils.confirmAction(HandlerUtil.getActiveShell(event), TaskUIMessages.task_handler_delete_confirm_title_delete_task, NLS.bind(TaskUIMessages.task_handler_delete_confirm_question_delete_task, tasksToDelete.get(0).getName()))) {
                return null;
            }
        } else {
            if (!UIUtils.confirmAction(HandlerUtil.getActiveShell(event), TaskUIMessages.task_handler_delete_confirm_title_delete_tasks, NLS.bind(TaskUIMessages.task_handler_delete_confirm_question_delete_tasks, tasksToDelete.size()))) {
                return null;
            }
        }
        for (DBTTask task : tasksToDelete) {
            try {
                task.getProject().getTaskManager().deleteTaskConfiguration(task);
            } catch (DBException e) {
                DBWorkbench.getPlatformUI().showError(TaskUIMessages.task_handler_delete_error_deleting_task_from_scheduler_title, NLS.bind(TaskUIMessages.task_handler_delete_error_deleting_task_from_scheduler_message, task.getId()), e);
            }
        }
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBTTask(org.jkiss.dbeaver.model.task.DBTTask) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 19 with DBTTask

use of org.jkiss.dbeaver.model.task.DBTTask in project dbeaver by dbeaver.

the class EditTaskConfigurationDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    Composite composite = super.createDialogArea(parent);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    Composite formPanel = UIUtils.createComposite(composite, 2);
    formPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
    ModifyListener modifyListener = e -> {
        updateButtons();
    };
    UIUtils.createLabelText(formPanel, TaskUIMessages.edit_task_config_dialog_label_type, taskType.getCategory().getName() + " / " + taskType.getName(), SWT.BORDER | SWT.READ_ONLY);
    boolean taskSaved = task != null && !CommonUtils.isEmpty(task.getId());
    taskLabelCombo = UIUtils.createLabelCombo(formPanel, TaskUIMessages.edit_task_config_dialog_label_name, "", SWT.BORDER | (taskSaved ? SWT.READ_ONLY : SWT.NONE));
    ((GridData) taskLabelCombo.getLayoutData()).widthHint = 300;
    if (task != null) {
        taskLabelCombo.setText(task.getName());
    } else {
        taskLabelCombo.add("");
        DBTTaskManager taskManager = project.getTaskManager();
        allTasks = taskManager.getAllTaskByType(taskType);
        for (DBTTask tc : allTasks) {
            taskLabelCombo.add(tc.getName());
        }
    /*
            taskLabelCombo.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    int selectionIndex = taskLabelCombo.getSelectionIndex();
                    if (selectionIndex == 0) {
                        task = null;
                        setTitle("Create task " + taskType.getName());
                    } else {
                        task = (TaskImpl) allTasks[selectionIndex - 1];
                        taskDescriptionText.setText(CommonUtils.notEmpty(task.getDescription()));
                        setTitle("Edit task " + task.getName());
                    }
                }
            });
*/
    }
    taskLabelCombo.addModifyListener(modifyListener);
    if (taskSaved) {
        taskLabelCombo.setEnabled(false);
    }
    // if (!CommonUtils.isEmpty(task.getId())) {
    // UIUtils.createLabelText(formPanel, "ID", task.getId(), SWT.BORDER | SWT.READ_ONLY);
    // }
    taskDescriptionText = UIUtils.createLabelText(formPanel, TaskUIMessages.edit_task_config_dialog_label_descr, task == null ? "" : CommonUtils.notEmpty(task.getDescription()), SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
    ((GridData) taskDescriptionText.getLayoutData()).heightHint = taskDescriptionText.getLineHeight() * 5;
    taskDescriptionText.addModifyListener(modifyListener);
    UIUtils.asyncExec(() -> taskLabelCombo.setFocus());
    return composite;
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) Date(java.util.Date) DBTTaskType(org.jkiss.dbeaver.model.task.DBTTaskType) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) NotNull(org.jkiss.code.NotNull) BaseDialog(org.jkiss.dbeaver.ui.dialogs.BaseDialog) LinkedHashMap(java.util.LinkedHashMap) Composite(org.eclipse.swt.widgets.Composite) UIUtils(org.jkiss.dbeaver.ui.UIUtils) DBTTaskManager(org.jkiss.dbeaver.model.task.DBTTaskManager) Map(java.util.Map) DBTTask(org.jkiss.dbeaver.model.task.DBTTask) TaskImpl(org.jkiss.dbeaver.registry.task.TaskImpl) GridData(org.eclipse.swt.layout.GridData) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) CommonUtils(org.jkiss.utils.CommonUtils) Text(org.eclipse.swt.widgets.Text) TaskUIMessages(org.jkiss.dbeaver.tasks.ui.internal.TaskUIMessages) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) DBIcon(org.jkiss.dbeaver.model.DBIcon) DBException(org.jkiss.dbeaver.DBException) ModifyListener(org.eclipse.swt.events.ModifyListener) SWT(org.eclipse.swt.SWT) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) DBTTaskManager(org.jkiss.dbeaver.model.task.DBTTaskManager) DBTTask(org.jkiss.dbeaver.model.task.DBTTask) GridData(org.eclipse.swt.layout.GridData)

Example 20 with DBTTask

use of org.jkiss.dbeaver.model.task.DBTTask in project dbeaver by dbeaver.

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

DBTTask (org.jkiss.dbeaver.model.task.DBTTask)26 DBException (org.jkiss.dbeaver.DBException)14 ISelection (org.eclipse.jface.viewers.ISelection)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 DBTTaskType (org.jkiss.dbeaver.model.task.DBTTaskType)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 DBPImage (org.jkiss.dbeaver.model.DBPImage)4 DBPProject (org.jkiss.dbeaver.model.app.DBPProject)4 DBTTaskManager (org.jkiss.dbeaver.model.task.DBTTaskManager)4 TaskWizardExecutor (org.jkiss.dbeaver.tasks.ui.wizard.TaskWizardExecutor)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Action (org.eclipse.jface.action.Action)2 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)2 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 SWT (org.eclipse.swt.SWT)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2