use of org.jkiss.dbeaver.model.task.DBTTaskManager 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;
}
use of org.jkiss.dbeaver.model.task.DBTTaskManager in project dbeaver by serge-rider.
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;
}
use of org.jkiss.dbeaver.model.task.DBTTaskManager in project dbeaver by serge-rider.
the class EditTaskConfigurationDialog method okPressed.
@Override
protected void okPressed() {
DBTTaskManager taskManager = project.getTaskManager();
try {
if (task == null) {
task = (TaskImpl) taskManager.createTask(taskType, taskLabelCombo.getText(), taskDescriptionText.getText(), state);
}
task.setName(taskLabelCombo.getText());
task.setDescription(taskDescriptionText.getText());
task.setUpdateTime(new Date());
task.setProperties(state);
taskManager.updateTaskConfiguration(task);
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError("Create task", "Error creating data transfer task", e);
return;
}
super.okPressed();
}
use of org.jkiss.dbeaver.model.task.DBTTaskManager in project dbeaver by dbeaver.
the class TaskHandlerCreate method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
DBPProject project = NavigatorUtils.getSelectedProject();
/*
CreateTaskConfigurationDialog dialog = new CreateTaskConfigurationDialog(
HandlerUtil.getActiveShell(event),
project
);
*/
TaskConfigurationWizardDialog dialog = new TaskConfigurationWizardDialog(HandlerUtil.getActiveWorkbenchWindow(event));
if (dialog.open() == IDialogConstants.OK_ID) {
DBTTaskManager taskManager = project.getTaskManager();
try {
/*
DBTTaskConfigurator configurator = dialog.getSelectedCategory().createConfigurator();
DBTTask task = taskManager.createTask(
dialog.getSelectedTaskType(),
dialog.getTaskName(),
dialog.getTaskDescription(),
dialog.getInitialProperties());
if (!configurator.createTaskConfigWizard(task)) {
taskManager.deleteTaskConfiguration(task);
}
*/
} catch (Exception e) {
DBWorkbench.getPlatformUI().showError("Create task failed", "Error while creating new task", e);
}
}
return null;
}
use of org.jkiss.dbeaver.model.task.DBTTaskManager 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;
}
Aggregations