use of org.jkiss.dbeaver.model.struct.DBSObject 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.model.struct.DBSObject in project dbeaver by serge-rider.
the class DataSourceToolsContributor method fillContributionItems.
@Override
protected void fillContributionItems(List<IContributionItem> menuItems) {
IWorkbenchPage activePage = UIUtils.getActiveWorkbenchWindow().getActivePage();
IWorkbenchPart activePart = activePage.getActivePart();
if (activePart == null) {
return;
}
DBSObject selectedObject = null;
INavigatorModelView navigatorModelView = GeneralUtils.adapt(activePart, INavigatorModelView.class);
if (navigatorModelView != null) {
final ISelectionProvider selectionProvider = activePart.getSite().getSelectionProvider();
if (selectionProvider != null) {
ISelection selection = selectionProvider.getSelection();
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
selectedObject = RuntimeUtils.getObjectAdapter(((IStructuredSelection) selection).getFirstElement(), DBSObject.class);
List<ToolDescriptor> tools = getAvailableTools((IStructuredSelection) selection);
fillToolsMenu(menuItems, tools, selection);
}
}
} else if (activePart instanceof IEditorPart) {
IEditorInput editorInput = ((IEditorPart) activePart).getEditorInput();
if (editorInput instanceof IDatabaseEditorInput) {
selectedObject = ((IDatabaseEditorInput) editorInput).getDatabaseObject();
} else if (activePart instanceof IDataSourceContainerProvider) {
selectedObject = ((IDataSourceContainerProvider) activePart).getDataSourceContainer();
}
}
if (selectedObject != null) {
// Contribute standard tools like session manager
DBPDataSource dataSource = selectedObject.getDataSource();
if (dataSource != null) {
DBPDataSourceContainer dataSourceContainer = dataSource.getContainer();
DBPEditorContribution[] contributedEditors = DBWorkbench.getPlatform().getDataSourceProviderRegistry().getContributedEditors(DBPEditorContribution.MB_CONNECTION_EDITOR, dataSourceContainer);
if (contributedEditors.length > 0) {
menuItems.add(new Separator());
for (DBPEditorContribution ec : contributedEditors) {
menuItems.add(new ActionContributionItem(new OpenToolsEditorAction(activePage, dataSource, ec)));
}
}
}
}
// Tasks management
{
menuItems.add(new Separator());
menuItems.add(ActionUtils.makeCommandContribution(activePart.getSite(), DatabaseTasksView.CREATE_TASK_CMD_ID));
}
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class DataSourceToolsContributor method getAvailableTools.
private List<ToolDescriptor> getAvailableTools(IStructuredSelection selection) {
List<DBSObject> objects = NavigatorUtils.getSelectedObjects(selection);
List<ToolDescriptor> result = new ArrayList<>();
if (!objects.isEmpty()) {
for (ToolDescriptor descriptor : ToolsRegistry.getInstance().getTools()) {
if (descriptor.isSingleton() && objects.size() > 1) {
continue;
}
boolean applies = true;
for (DBSObject object : objects) {
if (!descriptor.appliesTo(object)) {
applies = false;
break;
}
}
if (applies) {
result.add(descriptor);
}
}
}
return result;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class ContentPanelEditor method makeValueId.
private String makeValueId() {
String valueId;
DBSTypedObject valueType = valueController.getValueType();
if (valueType instanceof DBDAttributeBinding) {
valueType = ((DBDAttributeBinding) valueType).getAttribute();
}
if (valueType instanceof DBSObject) {
DBSObject object = (DBSObject) valueType;
valueId = DBUtils.getObjectFullName(object, DBPEvaluationContext.DDL);
if (object.getParentObject() != null) {
valueId = DBUtils.getObjectFullName(object.getParentObject(), DBPEvaluationContext.DDL) + ":" + valueId;
}
} else {
valueId = valueController.getValueName();
}
String dsId = "unknown";
if (valueController.getExecutionContext() != null) {
dsId = valueController.getExecutionContext().getDataSource().getContainer().getId();
}
return dsId + ":" + valueId;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class SQLEditorHandlerRunProcedureConsole method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
SQLNavigatorContext navContext = null;
String procName = null;
ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
List<DBSObject> selectedObjects = NavigatorUtils.getSelectedObjects(currentSelection);
List<DBSProcedure> entities = new ArrayList<>();
for (DBSObject object : selectedObjects) {
if (object instanceof DBSProcedure) {
DBSProcedure proc = (DBSProcedure) object;
procName = proc.getName();
entities.add(proc);
if (navContext == null) {
navContext = new SQLNavigatorContext(object);
}
}
}
if (navContext == null || navContext.getDataSourceContainer() == null) {
log.debug("No active datasource");
return null;
}
DBRRunnableWithResult<String> generator = SQLGeneratorContributor.CALL_GENERATOR(entities);
String title = "Stored procedures call";
if (entities.size() == 1 && !CommonUtils.isEmpty(procName)) {
title = procName + " call";
}
try {
openConsole(workbenchWindow, generator, navContext, title, false, currentSelection);
} catch (Exception e) {
DBWorkbench.getPlatformUI().showError("Open console", "Can open SQL editor", e);
}
return null;
}
Aggregations