Search in sources :

Example 1 with DBTTask

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

the class DataTransferWizard method performFinish.

@Override
public boolean performFinish() {
    saveDialogSettings();
    if (!super.performFinish()) {
        return false;
    }
    try {
        DBTTask currentTask = getCurrentTask();
        if (currentTask == null) {
            // Execute directly - without task serialize/deserialize
            // We need it because some data producers cannot be serialized properly (e.g. ResultSetDatacontainer - see #7342)
            DataTransferWizardExecutor executor = new DataTransferWizardExecutor(getRunnableContext(), DTMessages.data_transfer_wizard_job_name, getSettings());
            executor.executeTask();
        }
    } catch (DBException e) {
        DBWorkbench.getPlatformUI().showError(e.getMessage(), DTUIMessages.data_transfer_wizard_message_init_data_transfer, e);
        return false;
    }
    return true;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBTTask(org.jkiss.dbeaver.model.task.DBTTask)

Example 2 with DBTTask

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

the class AbstractNativeToolWizard method performFinish.

@Override
public boolean performFinish() {
    // Save settings
    settings.saveSettings(getRunnableContext(), getPreferenceStore());
    if (!validateClientFiles()) {
        return false;
    }
    if (getCurrentTask() != null) {
        return super.performFinish();
    }
    showLogPage();
    try {
        // Execute directly - without task serialize/deserialize
        // We need it because some data producers cannot be serialized properly (e.g. ResultSetDatacontainer - see #7342)
        DBTTask temporaryTask = getProject().getTaskManager().createTemporaryTask(getTaskType(), getTaskType().getName());
        saveConfigurationToTask(temporaryTask);
        TaskWizardExecutor executor = new TaskWizardExecutor(getRunnableContext(), temporaryTask, log, logPage.getLogWriter());
        executor.executeTask();
        return false;
    } catch (Exception e) {
        DBWorkbench.getPlatformUI().showError(e.getMessage(), "Error running task", e);
        return false;
    }
}
Also used : DBTTask(org.jkiss.dbeaver.model.task.DBTTask) TaskWizardExecutor(org.jkiss.dbeaver.tasks.ui.wizard.TaskWizardExecutor) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException)

Example 3 with DBTTask

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

the class TaskHandlerCopy method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structSelection = (IStructuredSelection) selection;
        Object firstElement = structSelection.getFirstElement();
        if (firstElement instanceof DBTTask) {
            DBTTask oldTask = (DBTTask) firstElement;
            for (; ; ) {
                EnterNameDialog taskNameDialog = new EnterNameDialog(HandlerUtil.getActiveShell(event), TaskUIMessages.task_handler_copy_name_dialog_enter_task, oldTask.getName());
                String newTaskName = taskNameDialog.chooseName();
                if (newTaskName == null) {
                    return null;
                }
                DBTTaskManager taskManager = oldTask.getProject().getTaskManager();
                if (taskManager.getTaskByName(newTaskName) != null) {
                    UIUtils.showMessageBox(HandlerUtil.getActiveShell(event), "Duplicate task name", "Task '" + newTaskName + "' already exists", SWT.ICON_ERROR);
                    continue;
                }
                try {
                    DBTTask newTask = taskManager.createTask(oldTask.getType(), newTaskName, oldTask.getDescription(), new LinkedHashMap<>(oldTask.getProperties()));
                    taskManager.updateTaskConfiguration(newTask);
                    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
                    if (activePart instanceof DatabaseTasksView) {
                        UIUtils.asyncExec(() -> {
                            ((DatabaseTasksView) activePart).getTasksTree().getViewer().setSelection(new StructuredSelection(newTask), true);
                            ActionUtils.runCommand(DatabaseTasksView.EDIT_TASK_CMD_ID, activePart.getSite());
                        });
                    }
                } catch (DBException e) {
                    DBWorkbench.getPlatformUI().showError("Task copy error", "Error copying task '" + oldTask.getName() + "'", e);
                }
                break;
            }
        }
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) EnterNameDialog(org.jkiss.dbeaver.ui.dialogs.EnterNameDialog) DBTTask(org.jkiss.dbeaver.model.task.DBTTask) DBTTaskManager(org.jkiss.dbeaver.model.task.DBTTaskManager) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 4 with DBTTask

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

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 5 with DBTTask

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

the class TaskHandlerRun method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    String taskId = CommonUtils.toString(parameters.get("task"));
    if (!CommonUtils.isEmpty(taskId)) {
        DBTTask task = NavigatorUtils.getSelectedProject().getTaskManager().getTaskById(taskId);
        if (task != null) {
            DBPImage taskIcon = task.getType().getIcon();
            if (taskIcon == null)
                taskIcon = DBIcon.TREE_TASK;
            element.setIcon(DBeaverIcons.getImageDescriptor(taskIcon));
            element.setText(task.getName());
        }
    }
}
Also used : DBTTask(org.jkiss.dbeaver.model.task.DBTTask) DBPImage(org.jkiss.dbeaver.model.DBPImage)

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