Search in sources :

Example 6 with DBTTask

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

the class SQLToolTaskWizard method performFinish.

@Override
public boolean performFinish() {
    if (isRunTaskOnFinish()) {
        // Only if task is not temporary
        saveConfigurationToTask(getCurrentTask());
        return super.performFinish();
    }
    try {
        // Execute task in wizard
        DBTTask task = getCurrentTask();
        saveConfigurationToTask(task);
        pageStatus.clearLog();
        getContainer().showPage(pageStatus);
        TaskWizardExecutor executor = new SQLTaskExecutor(task);
        executor.executeTask();
        if (taskHandler.needsRefreshOnFinish()) {
            refreshOnFinish();
        }
        return false;
    } catch (Exception e) {
        DBWorkbench.getPlatformUI().showError(e.getMessage(), TasksSQLUIMessages.sql_tool_task_wizard_message_error_running_task, e);
        return false;
    }
}
Also used : DBTTask(org.jkiss.dbeaver.model.task.DBTTask) TaskWizardExecutor(org.jkiss.dbeaver.tasks.ui.wizard.TaskWizardExecutor) DBCException(org.jkiss.dbeaver.model.exec.DBCException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException)

Example 7 with DBTTask

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

the class TaskHandlerEdit method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof DBTTask) {
            DBTTask task = (DBTTask) element;
            DBTTaskType taskTypeDescriptor = task.getType();
            if (!TaskUIRegistry.getInstance().supportsConfigurator(taskTypeDescriptor)) {
                DBWorkbench.getPlatformUI().showError("No configurator", "Task '" + taskTypeDescriptor.getName() + "' has no configurator");
                return null;
            }
            try {
                TaskConfigurationWizard wizard = TaskUIRegistry.getInstance().createConfigurator(taskTypeDescriptor).createTaskConfigWizard(task);
                if (wizard != null) {
                    TaskConfigurationWizardDialog dialog = new TaskConfigurationWizardDialog(HandlerUtil.getActiveWorkbenchWindow(event), wizard);
                    dialog.setEditMode(true);
                    dialog.open();
                }
            } catch (Throwable e) {
                DBWorkbench.getPlatformUI().showError("Task configuration", "Error opening task '" + task.getName() + "' configuration editor", e);
            }
        }
    }
    return null;
}
Also used : DBTTask(org.jkiss.dbeaver.model.task.DBTTask) ISelection(org.eclipse.jface.viewers.ISelection) TaskConfigurationWizardDialog(org.jkiss.dbeaver.tasks.ui.wizard.TaskConfigurationWizardDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TaskConfigurationWizard(org.jkiss.dbeaver.tasks.ui.wizard.TaskConfigurationWizard) DBTTaskType(org.jkiss.dbeaver.model.task.DBTTaskType)

Example 8 with DBTTask

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

the class TaskHandlerProperties 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 element = structSelection.getFirstElement();
        if (element instanceof DBTTask) {
            EditTaskConfigurationDialog dialog = new EditTaskConfigurationDialog(HandlerUtil.getActiveShell(event), (DBTTask) element);
            dialog.open();
        }
    }
    return null;
}
Also used : EditTaskConfigurationDialog(org.jkiss.dbeaver.tasks.ui.wizard.EditTaskConfigurationDialog) DBTTask(org.jkiss.dbeaver.model.task.DBTTask) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 9 with DBTTask

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

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)

Example 10 with DBTTask

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

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)

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