Search in sources :

Example 21 with DBTTask

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

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

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

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

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

the class RecentTasksMenuContributor method fillContributionItems.

@Override
protected void fillContributionItems(final List<IContributionItem> menuItems) {
    DBPProject project = NavigatorUtils.getSelectedProject();
    if (project == null) {
        return;
    }
    DBTTask[] tasks = project.getTaskManager().getAllTasks();
    Arrays.sort(tasks, (o1, o2) -> {
        DBTTaskRun lr1 = o1.getLastRun();
        DBTTaskRun lr2 = o1.getLastRun();
        if (lr1 == lr2)
            return o1.getCreateTime().compareTo(o2.getCreateTime());
        else if (lr1 == null)
            return -1;
        else if (lr2 == null)
            return 1;
        else
            return lr1.getStartTime().compareTo(lr2.getStartTime());
    });
    for (int i = 0; i < tasks.length && i <= MAX_ITEMS; i++) {
        DBTTask task = tasks[i];
        DBPImage taskIcon = task.getType().getIcon();
        if (taskIcon == null)
            taskIcon = DBIcon.TREE_TASK;
        menuItems.add(ActionUtils.makeActionContribution(new Action(task.getName(), DBeaverIcons.getImageDescriptor(taskIcon)) {

            @Override
            public void run() {
                TaskHandlerRun.runTask(task);
            }
        }, false));
    }
}
Also used : DBTTaskRun(org.jkiss.dbeaver.model.task.DBTTaskRun) Action(org.eclipse.jface.action.Action) DBTTask(org.jkiss.dbeaver.model.task.DBTTask) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPImage(org.jkiss.dbeaver.model.DBPImage)

Example 24 with DBTTask

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

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

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

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)

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