use of org.jkiss.dbeaver.model.task.DBTTaskType 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;
}
use of org.jkiss.dbeaver.model.task.DBTTaskType in project dbeaver by dbeaver.
the class TaskConfigurationWizardPageTask method createControl.
@Override
public void createControl(Composite parent) {
boolean taskSaved = task != null && !CommonUtils.isEmpty(task.getId());
Composite composite = UIUtils.createComposite(parent, 1);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
{
Composite formPanel = UIUtils.createControlGroup(composite, TaskUIMessages.task_config_wizard_page_task_label_task_type, task == null ? 1 : 2, GridData.FILL_BOTH, 0);
formPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
{
Composite infoPanel = UIUtils.createComposite(formPanel, 2);
infoPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
ModifyListener modifyListener = e -> updatePageCompletion();
taskLabelText = UIUtils.createLabelText(infoPanel, TaskUIMessages.task_config_wizard_page_task_text_label_name, task == null ? "" : CommonUtils.notEmpty(task.getName()), SWT.BORDER);
if (taskSaved) {
taskLabelText.setEditable(false);
// taskLabelText.setEnabled(false);
}
taskLabelText.addModifyListener(e -> {
taskName = taskLabelText.getText();
modifyListener.modifyText(e);
});
UIUtils.createControlLabel(infoPanel, TaskUIMessages.task_config_wizard_page_task_control_label_descr).setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
taskDescriptionText = new Text(infoPanel, SWT.BORDER | SWT.MULTI);
taskDescriptionText.setText(task == null ? "" : CommonUtils.notEmpty(task.getDescription()));
taskDescriptionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// ((GridData) taskDescriptionText.getLayoutData()).heightHint = taskDescriptionText.getLineHeight() * 6;
taskDescriptionText.addModifyListener(e -> {
taskDescription = taskDescriptionText.getText();
modifyListener.modifyText(e);
});
if (task != null && !CommonUtils.isEmpty(task.getId())) {
UIUtils.createLabelText(infoPanel, TaskUIMessages.task_config_wizard_page_task_text_label_task_id, task.getId(), SWT.BORDER | SWT.READ_ONLY);
}
UIUtils.asyncExec(() -> (taskSaved ? taskDescriptionText : taskLabelText).setFocus());
if (task != null) {
UIUtils.createControlLabel(infoPanel, TaskUIMessages.task_config_wizard_page_task_control_label_category);
Composite catPanel = UIUtils.createComposite(infoPanel, 2);
UIUtils.createLabel(catPanel, task.getType().getCategory().getIcon());
UIUtils.createLabel(catPanel, task.getType().getCategory().getName());
UIUtils.createControlLabel(infoPanel, TaskUIMessages.task_config_wizard_page_task_control_label_type);
Composite typePanel = UIUtils.createComposite(infoPanel, 2);
UIUtils.createLabel(typePanel, task.getType().getIcon());
UIUtils.createLabel(typePanel, task.getType().getName());
}
}
if (task == null) {
taskCategoryTree = new Tree(formPanel, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 100;
gd.widthHint = 200;
taskCategoryTree.setLayoutData(gd);
taskCategoryTree.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TreeItem[] selection = taskCategoryTree.getSelection();
if (selection.length == 1) {
Object itemData = selection[0].getData();
if (itemData instanceof DBTTaskType) {
if (selectedTaskType == itemData) {
return;
}
selectedTaskType = (DBTTaskType) itemData;
selectedCategory = selectedTaskType.getCategory();
} else {
if (selectedCategory == itemData && selectedTaskType == null) {
return;
}
selectedCategory = (DBTTaskCategory) itemData;
selectedTaskType = null;
}
updateTaskTypeSelection();
}
}
});
TreeColumn nameColumn = new TreeColumn(taskCategoryTree, SWT.LEFT);
nameColumn.setText("Task");
TreeColumn descColumn = new TreeColumn(taskCategoryTree, SWT.RIGHT);
descColumn.setText("Description");
addTaskCategories(null, TaskRegistry.getInstance().getRootCategories());
taskCategoryTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
if (canFlipToNextPage()) {
getWizard().getContainer().buttonPressed(IDialogConstants.NEXT_ID);
}
}
});
UIUtils.asyncExec(() -> UIUtils.packColumns(taskCategoryTree, true, new float[] { 0.3f, 0.7f }));
taskCategoryTree.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
UIUtils.packColumns(taskCategoryTree, true, new float[] { 0.3f, 0.7f });
taskCategoryTree.removeControlListener(this);
}
});
}
}
setPageComplete(determinePageCompletion());
setControl(composite);
}
use of org.jkiss.dbeaver.model.task.DBTTaskType in project dbeaver by dbeaver.
the class TaskConfigurationWizardPageTask method addTaskTypes.
private void addTaskTypes(TreeItem parentItem, DBTTaskCategory category) {
DBTTaskType[] taskTypes = category.getTaskTypes();
Arrays.sort(taskTypes, Comparator.comparing(DBTTaskType::getName));
for (DBTTaskType type : taskTypes) {
if (!isTaskTypeApplicable(type)) {
continue;
}
TreeItem item = new TreeItem(parentItem, SWT.NONE);
item.setText(0, type.getName());
item.setText(1, CommonUtils.notEmpty(type.getDescription()));
if (type.getIcon() != null) {
item.setImage(0, DBeaverIcons.getImage(type.getIcon()));
}
item.setData(type);
}
}
Aggregations