Search in sources :

Example 1 with DBTTaskCategory

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

the class TaskConfigurationWizardPageTask method addTaskCategories.

private void addTaskCategories(TreeItem parentItem, DBTTaskCategory[] categories) {
    List<DBTTaskCategory> allCats = Arrays.asList(categories);
    allCats.sort(Comparator.comparing(DBTTaskCategory::getName));
    for (DBTTaskCategory cat : categories) {
        if (!isTaskCategoryApplicable(cat)) {
            continue;
        }
        TreeItem item = parentItem == null ? new TreeItem(taskCategoryTree, SWT.NONE) : new TreeItem(parentItem, SWT.NONE);
        item.setText(0, cat.getName());
        item.setImage(0, DBeaverIcons.getImage(cat.getIcon() == null ? DBIcon.TREE_TASK : cat.getIcon()));
        item.setText(1, CommonUtils.notEmpty(cat.getDescription()));
        item.setData(cat);
        addTaskCategories(item, cat.getChildren());
        addTaskTypes(item, cat);
        item.setExpanded(true);
    }
}
Also used : DBTTaskCategory(org.jkiss.dbeaver.model.task.DBTTaskCategory)

Example 2 with DBTTaskCategory

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

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 3 with DBTTaskCategory

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

the class TaskConfigurationWizardPageTask method addTaskCategories.

private void addTaskCategories(TreeItem parentItem, DBTTaskCategory[] categories) {
    List<DBTTaskCategory> allCats = Arrays.asList(categories);
    allCats.sort(Comparator.comparing(DBTTaskCategory::getName));
    for (DBTTaskCategory cat : categories) {
        if (!isTaskCategoryApplicable(cat)) {
            continue;
        }
        TreeItem item = parentItem == null ? new TreeItem(taskCategoryTree, SWT.NONE) : new TreeItem(parentItem, SWT.NONE);
        item.setText(0, cat.getName());
        item.setImage(0, DBeaverIcons.getImage(cat.getIcon() == null ? DBIcon.TREE_TASK : cat.getIcon()));
        item.setText(1, CommonUtils.notEmpty(cat.getDescription()));
        item.setData(cat);
        addTaskCategories(item, cat.getChildren());
        addTaskTypes(item, cat);
        item.setExpanded(true);
    }
}
Also used : DBTTaskCategory(org.jkiss.dbeaver.model.task.DBTTaskCategory)

Example 4 with DBTTaskCategory

use of org.jkiss.dbeaver.model.task.DBTTaskCategory 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)

Aggregations

DBTTaskCategory (org.jkiss.dbeaver.model.task.DBTTaskCategory)4 java.util (java.util)2 List (java.util.List)2 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)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 DBTTask (org.jkiss.dbeaver.model.task.DBTTask)2 DBTTaskType (org.jkiss.dbeaver.model.task.DBTTaskType)2