Search in sources :

Example 6 with DBTTaskType

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;
}
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 7 with DBTTaskType

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);
}
Also used : ActiveWizardPage(org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage) java.util(java.util) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBTTaskType(org.jkiss.dbeaver.model.task.DBTTaskType) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) UIUtils(org.jkiss.dbeaver.ui.UIUtils) Log(org.jkiss.dbeaver.Log) DBTTask(org.jkiss.dbeaver.model.task.DBTTask) TaskImpl(org.jkiss.dbeaver.registry.task.TaskImpl) NavigatorUtils(org.jkiss.dbeaver.ui.navigator.NavigatorUtils) GridData(org.eclipse.swt.layout.GridData) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) CommonUtils(org.jkiss.utils.CommonUtils) org.eclipse.swt.events(org.eclipse.swt.events) TaskUIMessages(org.jkiss.dbeaver.tasks.ui.internal.TaskUIMessages) NLS(org.eclipse.osgi.util.NLS) org.eclipse.swt.widgets(org.eclipse.swt.widgets) DBTTaskConfigurator(org.jkiss.dbeaver.tasks.ui.DBTTaskConfigurator) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) TaskUIRegistry(org.jkiss.dbeaver.tasks.ui.registry.TaskUIRegistry) DBTTaskCategory(org.jkiss.dbeaver.model.task.DBTTaskCategory) TaskRegistry(org.jkiss.dbeaver.registry.task.TaskRegistry) List(java.util.List) DBIcon(org.jkiss.dbeaver.model.DBIcon) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridData(org.eclipse.swt.layout.GridData) DBTTaskType(org.jkiss.dbeaver.model.task.DBTTaskType)

Example 8 with DBTTaskType

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);
    }
}
Also used : DBTTaskType(org.jkiss.dbeaver.model.task.DBTTaskType)

Aggregations

DBTTaskType (org.jkiss.dbeaver.model.task.DBTTaskType)8 DBTTask (org.jkiss.dbeaver.model.task.DBTTask)6 ISelection (org.eclipse.jface.viewers.ISelection)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 java.util (java.util)2 List (java.util.List)2 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)2 NLS (org.eclipse.osgi.util.NLS)2 SWT (org.eclipse.swt.SWT)2 org.eclipse.swt.events (org.eclipse.swt.events)2 GridData (org.eclipse.swt.layout.GridData)2 org.eclipse.swt.widgets (org.eclipse.swt.widgets)2 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 DBException (org.jkiss.dbeaver.DBException)2 Log (org.jkiss.dbeaver.Log)2 DBIcon (org.jkiss.dbeaver.model.DBIcon)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBPProject (org.jkiss.dbeaver.model.app.DBPProject)2 DBTTaskCategory (org.jkiss.dbeaver.model.task.DBTTaskCategory)2