use of org.jkiss.dbeaver.registry.task.TaskTypeDescriptor in project dbeaver by serge-rider.
the class SQLToolTaskWizardPageSettings method createControl.
@Override
public void createControl(Composite parent) {
initializeDialogUnits(parent);
Composite composite = UIUtils.createComposite(parent, 1);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
SashForm previewSplitter = new SashForm(composite, SWT.VERTICAL);
previewSplitter.setLayoutData(new GridData(GridData.FILL_BOTH));
SashForm settingsPanel = new SashForm(previewSplitter, SWT.HORIZONTAL);
Group objectsPanel;
{
objectsPanel = UIUtils.createControlGroup(settingsPanel, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_group_label_objects, 2, GridData.FILL_BOTH, 0);
objectsViewer = new TableViewer(objectsPanel, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
objectsViewer.setContentProvider(new ListContentProvider());
objectsViewer.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return DBUtils.getObjectFullName((DBPNamedObject) element, DBPEvaluationContext.UI);
}
@Override
public Image getImage(Object element) {
return DBeaverIcons.getImage(DBValueFormatting.getObjectImage((DBPObject) element));
}
});
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 150;
gd.widthHint = 200;
final Table objectTable = objectsViewer.getTable();
objectTable.setLayoutData(gd);
ToolBar buttonsToolbar = new ToolBar(objectsPanel, SWT.VERTICAL);
buttonsToolbar.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_add_string, UIIcon.ROW_ADD, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(sqlWizard.getProject());
SQLToolTaskObjectSelectorDialog objectListDialog = new SQLToolTaskObjectSelectorDialog(getShell(), projectNode, (TaskTypeDescriptor) sqlWizard.getTaskType());
if (objectListDialog.open() == IDialogConstants.OK_ID) {
for (DBSObject object : objectListDialog.getSelectedObjects()) {
if (!selectedObjects.contains(object)) {
selectedObjects.add(object);
}
}
refreshObjects();
updatePageCompletion();
}
}
});
ToolItem deleteItem = UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_remove_string, UIIcon.ROW_DELETE, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ISelection selection = objectsViewer.getSelection();
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
for (Object element : ((IStructuredSelection) selection).toArray()) {
if (element instanceof DBSObject) {
selectedObjects.remove(element);
}
}
refreshObjects();
updatePageCompletion();
}
}
});
UIUtils.createToolBarSeparator(buttonsToolbar, SWT.HORIZONTAL);
ToolItem[] moveButtons = new ToolItem[2];
moveButtons[0] = UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_move_script_up, UIIcon.ARROW_UP, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = objectTable.getSelectionIndex();
if (selectionIndex > 0) {
DBSObject prevScript = selectedObjects.get(selectionIndex - 1);
selectedObjects.set(selectionIndex - 1, selectedObjects.get(selectionIndex));
selectedObjects.set(selectionIndex, prevScript);
refreshObjects();
}
moveButtons[0].setEnabled(selectionIndex > 1);
moveButtons[1].setEnabled(selectionIndex < objectTable.getItemCount() - 1);
}
});
moveButtons[1] = UIUtils.createToolItem(buttonsToolbar, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_tool_item_text_move_script_down, UIIcon.ARROW_DOWN, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = objectTable.getSelectionIndex();
if (selectionIndex < objectTable.getItemCount() - 1) {
DBSObject nextScript = selectedObjects.get(selectionIndex + 1);
selectedObjects.set(selectionIndex + 1, selectedObjects.get(selectionIndex));
selectedObjects.set(selectionIndex, nextScript);
refreshObjects();
}
moveButtons[0].setEnabled(selectionIndex > 0);
moveButtons[1].setEnabled(selectionIndex < objectTable.getItemCount() - 2);
}
});
objectsViewer.addSelectionChangedListener(event -> {
int selectionIndex = objectTable.getSelectionIndex();
deleteItem.setEnabled(selectionIndex >= 0);
moveButtons[0].setEnabled(selectionIndex > 0);
moveButtons[1].setEnabled(selectionIndex < objectTable.getItemCount() - 1);
});
deleteItem.setEnabled(false);
moveButtons[0].setEnabled(false);
moveButtons[1].setEnabled(false);
}
{
Group optionsPanel = UIUtils.createControlGroup(settingsPanel, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_group_label_settings, 1, GridData.FILL_BOTH, 0);
taskOptionsViewer = new PropertyTreeViewer(optionsPanel, SWT.BORDER);
taskOptionsViewer.addPropertyChangeListener(event -> updateScriptPreview());
}
Composite previewPanel = UIUtils.createComposite(previewSplitter, 1);
previewPanel.setLayout(new FillLayout());
serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
try {
sqlPreviewPanel = serviceSQL.createSQLPanel(UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite(), previewPanel, this, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_sql_panel_name, true, "");
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError(TasksSQLUIMessages.sql_tool_task_wizard_page_settings_title_sql_preview_error, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_message_sql_preview_panel, e);
}
}
Composite controlsPanel = UIUtils.createComposite(composite, 2);
UIUtils.createDialogButton(controlsPanel, TasksSQLUIMessages.sql_tool_task_wizard_page_settings_dialog_button_label_copy, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String text = serviceSQL.getSQLPanelText(sqlPreviewPanel);
if (!CommonUtils.isEmpty(text)) {
UIUtils.setClipboardContents(getShell().getDisplay(), TextTransfer.getInstance(), text);
}
}
});
getWizard().createTaskSaveButtons(controlsPanel, true, 1);
loadSettings();
if (taskOptionsViewer.getTree().getItemCount() == 0) {
settingsPanel.setMaximizedControl(objectsPanel);
}
setControl(composite);
}
use of org.jkiss.dbeaver.registry.task.TaskTypeDescriptor in project dbeaver by serge-rider.
the class TaskConfigurationWizardDialog method openNewTaskDialog.
public static int openNewTaskDialog(IWorkbenchWindow window, DBPProject project, String taskTypeId, IStructuredSelection selection) {
TaskTypeDescriptor taskType = TaskRegistry.getInstance().getTaskType(taskTypeId);
if (taskType == null) {
DBWorkbench.getPlatformUI().showError("Bad task type", "Task type '" + taskTypeId + "' not found");
return IDialogConstants.CANCEL_ID;
}
try {
DBTTask task = project.getTaskManager().createTemporaryTask(taskType, taskType.getName());
task.setProperties(new HashMap<>());
DBTTaskConfigurator configurator = TaskUIRegistry.getInstance().createConfigurator(taskType);
TaskConfigurationWizard configWizard = configurator.createTaskConfigWizard(task);
TaskConfigurationWizardDialog dialog = new TaskConfigurationWizardDialog(window, configWizard, selection);
return dialog.open();
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError("Task create error", "Error creating task '" + taskTypeId + "'", e);
return IDialogConstants.CANCEL_ID;
}
}
Aggregations