use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by dbeaver.
the class NodeListControl method createContentProvider.
private static IContentProvider createContentProvider(DBNNode node, DBXTreeNode metaNode) {
if (node instanceof DBNDatabaseNode) {
final DBNDatabaseNode dbNode = (DBNDatabaseNode) node;
if (metaNode == null) {
metaNode = dbNode.getMeta();
}
final List<DBXTreeNode> inlineMetas = collectInlineMetas(dbNode, metaNode);
if (!inlineMetas.isEmpty()) {
return new TreeContentProvider() {
@Override
public boolean hasChildren(Object parentElement) {
return parentElement instanceof DBNDatabaseNode && ((DBNDatabaseNode) parentElement).hasChildren(false);
}
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof DBNDatabaseNode) {
try {
// Read children with void progress monitor because inline children SHOULD be already cached
DBNNode[] children = NavigatorUtils.getNodeChildrenFiltered(new VoidProgressMonitor(), (DBNDatabaseNode) parentElement, false);
if (ArrayUtils.isEmpty(children)) {
return null;
} else {
return children;
}
} catch (DBException e) {
log.error(e);
}
}
return null;
}
};
}
}
return new ListContentProvider();
}
use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by dbeaver.
the class SelectObjectDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite group = (Composite) super.createDialogArea(parent);
GridData gd = new GridData(GridData.FILL_BOTH);
group.setLayoutData(gd);
final DatabaseObjectListControl<T> objectList = new DatabaseObjectListControl<T>(group, (singleSelection ? SWT.SINGLE : SWT.MULTI), null, new ListContentProvider()) {
private ISearchExecutor searcher = new SearcherFilter();
@NotNull
@Override
protected String getListConfigId(List<Class<?>> classList) {
return listId;
}
@Override
protected LoadingJob<Collection<T>> createLoadService() {
return LoadingJob.createService(new AbstractLoadService<Collection<T>>() {
@Override
public Collection<T> evaluate(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
return objects;
}
@Override
public Object getFamily() {
return SelectObjectDialog.this;
}
}, new ObjectsLoadVisualizer() {
@Override
public void completeLoading(Collection<T> items) {
super.completeLoading(items);
performSearch(ISearchContextProvider.SearchType.NONE);
getItemsViewer().getControl().setFocus();
closeOnFocusLost(getItemsViewer().getControl(), getSearchTextControl());
}
});
}
protected CellLabelProvider getColumnLabelProvider(ObjectColumn objectColumn) {
return new ObjectLabelProvider(objectColumn);
}
@Override
protected Object getObjectValue(T item) {
if (item instanceof DBSWrapper) {
return ((DBSWrapper) item).getObject();
}
return super.getObjectValue(item);
}
@Override
protected DBPImage getObjectImage(T item) {
if (item instanceof DBNDatabaseNode) {
return ((DBNDatabaseNode) item).getNodeIcon();
}
return null;
}
@Override
protected void setListData(Collection<T> items, boolean append) {
super.setListData(items, append);
if (selectedObjects != null) {
getItemsViewer().setSelection(new StructuredSelection(selectedObjects), true);
}
}
@Override
protected void fillCustomActions(IContributionManager contributionManager) {
super.fillCustomActions(contributionManager);
addColumnConfigAction(contributionManager);
}
protected void addSearchAction(IContributionManager contributionManager) {
contributionManager.add(new Action("Filter objects", DBeaverIcons.getImageDescriptor(UIIcon.SEARCH)) {
@Override
public void run() {
performSearch(ISearchContextProvider.SearchType.NONE);
}
});
}
@Override
protected ISearchExecutor getSearchRunner() {
return searcher;
}
class ObjectLabelProvider extends ObjectColumnLabelProvider implements IFontProvider {
ObjectLabelProvider(ObjectColumn objectColumn) {
super(objectColumn);
}
@Override
public Font getFont(Object element) {
if (selectedObjects.contains(element)) {
return boldFont;
}
return null;
}
}
};
objectList.createProgressPanel();
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
gd.minimumWidth = 300;
objectList.setLayoutData(gd);
objectList.getSelectionProvider().addSelectionChangedListener(event -> {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
selectedObjects.clear();
selectedObjects.addAll(selection.toList());
if (!isModeless()) {
getButton(IDialogConstants.OK_ID).setEnabled(!selectedObjects.isEmpty());
}
});
objectList.setDoubleClickHandler(event -> {
if (isModeless() || getButton(IDialogConstants.OK_ID).isEnabled()) {
okPressed();
}
});
objectList.loadData();
return group;
}
use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by serge-rider.
the class SQLScriptTaskPageSettings method createControl.
@Override
public void createControl(Composite parent) {
initializeDialogUnits(parent);
Composite composite = UIUtils.createComposite(parent, 1);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
SQLScriptExecuteSettings dtSettings = getWizard().getSettings();
SashForm mainGroup = new SashForm(composite, SWT.NONE);
mainGroup.setSashWidth(5);
mainGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(sqlWizard.getProject());
{
Composite filesGroup = UIUtils.createControlGroup(mainGroup, DTMessages.sql_script_task_page_settings_group_files, 2, GridData.FILL_BOTH, 0);
scriptsViewer = new TableViewer(filesGroup, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
scriptsViewer.setContentProvider(new ListContentProvider());
scriptsViewer.getTable().setHeaderVisible(true);
scriptsViewer.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((DBNResource) element).getResource().getProjectRelativePath().toString();
}
@Override
public Image getImage(Object element) {
return DBeaverIcons.getImage(((DBNResource) element).getNodeIconDefault());
}
});
scriptsViewer.addDoubleClickListener(event -> {
StructuredSelection selection = (StructuredSelection) event.getSelection();
IResource resource = ((DBNResource) selection.getFirstElement()).getResource();
if (resource != null) {
DBPResourceHandler handler = DBWorkbench.getPlatform().getWorkspace().getResourceHandler(resource);
if (handler != null) {
try {
handler.openResource(resource);
} catch (Exception e) {
log.error("Failed to open resource " + resource, e);
}
}
}
});
// GridData gd = new GridData(GridData.FILL_BOTH);
// gd.heightHint = 300;
// gd.widthHint = 400;
// scriptsViewer.getTable().setLayoutData(gd);
SQLScriptTaskScriptSelectorDialog.createScriptColumns(scriptsViewer);
final Table scriptTable = scriptsViewer.getTable();
scriptTable.setLayoutData(new GridData(GridData.FILL_BOTH));
ToolBar buttonsToolbar = new ToolBar(filesGroup, SWT.VERTICAL);
buttonsToolbar.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_add_script, UIIcon.ROW_ADD, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SQLScriptTaskScriptSelectorDialog dialog = new SQLScriptTaskScriptSelectorDialog(getShell(), projectNode);
if (dialog.open() == IDialogConstants.OK_ID) {
for (DBNResource script : dialog.getSelectedScripts()) {
if (!selectedScripts.contains(script)) {
selectedScripts.add(script);
}
}
refreshScripts();
}
}
});
ToolItem deleteItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_remove_script, UIIcon.ROW_DELETE, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ISelection selection = scriptsViewer.getSelection();
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
for (Object element : ((IStructuredSelection) selection).toArray()) {
if (element instanceof DBNResource) {
selectedScripts.remove(element);
}
}
refreshScripts();
}
}
});
UIUtils.createToolBarSeparator(buttonsToolbar, SWT.HORIZONTAL);
ToolItem moveUpItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_script_up, UIIcon.ARROW_UP, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = scriptTable.getSelectionIndex();
if (selectionIndex > 0) {
DBNResource prevScript = selectedScripts.get(selectionIndex - 1);
selectedScripts.set(selectionIndex - 1, selectedScripts.get(selectionIndex));
selectedScripts.set(selectionIndex, prevScript);
refreshScripts();
}
}
});
ToolItem moveDownItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_script_down, UIIcon.ARROW_DOWN, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = scriptTable.getSelectionIndex();
if (selectionIndex < scriptTable.getItemCount() - 1) {
DBNResource nextScript = selectedScripts.get(selectionIndex + 1);
selectedScripts.set(selectionIndex + 1, selectedScripts.get(selectionIndex));
selectedScripts.set(selectionIndex, nextScript);
refreshScripts();
}
}
});
scriptsViewer.addSelectionChangedListener(event -> {
int selectionIndex = scriptTable.getSelectionIndex();
deleteItem.setEnabled(selectionIndex >= 0);
moveUpItem.setEnabled(selectionIndex > 0);
moveDownItem.setEnabled(selectionIndex < scriptTable.getItemCount() - 1);
});
deleteItem.setEnabled(false);
}
{
Composite connectionsGroup = UIUtils.createControlGroup(mainGroup, DTMessages.sql_script_task_page_settings_group_connections, 2, GridData.FILL_BOTH, 0);
dataSourceViewer = new TableViewer(connectionsGroup, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
dataSourceViewer.setContentProvider(new ListContentProvider());
// dataSourceViewer.getTable().setHeaderVisible(true);
dataSourceViewer.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((DBNDataSource) element).getNodeName();
}
@Override
public Image getImage(Object element) {
return DBeaverIcons.getImage(((DBNDataSource) element).getNodeIcon());
}
});
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
gd.widthHint = 400;
dataSourceViewer.getTable().setLayoutData(gd);
final Table dsTable = dataSourceViewer.getTable();
dsTable.setLayoutData(new GridData(GridData.FILL_BOTH));
ToolBar buttonsToolbar = new ToolBar(connectionsGroup, SWT.VERTICAL);
buttonsToolbar.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_add_data_source, UIIcon.ROW_ADD, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SQLScriptTaskDataSourceSelectorDialog dialog = new SQLScriptTaskDataSourceSelectorDialog(getShell(), projectNode);
if (dialog.open() == IDialogConstants.OK_ID) {
for (DBNDataSource ds : dialog.getSelectedDataSources()) {
if (!selectedDataSources.contains(ds)) {
selectedDataSources.add(ds);
}
}
refreshDataSources();
updatePageCompletion();
}
}
});
ToolItem deleteItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_remove_data_source, UIIcon.ROW_DELETE, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ISelection selection = dataSourceViewer.getSelection();
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
for (Object element : ((IStructuredSelection) selection).toArray()) {
if (element instanceof DBNDataSource) {
selectedDataSources.remove(element);
}
}
refreshDataSources();
updatePageCompletion();
}
}
});
UIUtils.createToolBarSeparator(buttonsToolbar, SWT.HORIZONTAL);
ToolItem moveUpItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_data_source_up, UIIcon.ARROW_UP, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = dsTable.getSelectionIndex();
if (selectionIndex > 0) {
DBNDataSource prevScript = selectedDataSources.get(selectionIndex - 1);
selectedDataSources.set(selectionIndex - 1, selectedDataSources.get(selectionIndex));
selectedDataSources.set(selectionIndex, prevScript);
refreshDataSources();
}
}
});
ToolItem moveDownItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_data_source_down, UIIcon.ARROW_DOWN, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = dsTable.getSelectionIndex();
if (selectionIndex < dsTable.getItemCount() - 1) {
DBNDataSource nextScript = selectedDataSources.get(selectionIndex + 1);
selectedDataSources.set(selectionIndex + 1, selectedDataSources.get(selectionIndex));
selectedDataSources.set(selectionIndex, nextScript);
refreshScripts();
}
}
});
dataSourceViewer.addSelectionChangedListener(event -> {
int selectionIndex = dsTable.getSelectionIndex();
deleteItem.setEnabled(selectionIndex >= 0);
moveUpItem.setEnabled(selectionIndex > 0);
moveDownItem.setEnabled(selectionIndex < dsTable.getItemCount() - 1);
});
deleteItem.setEnabled(false);
}
{
Composite settingsGroup = UIUtils.createControlGroup(composite, DTMessages.sql_script_task_page_settings_group_script, 3, GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
ignoreErrorsCheck = UIUtils.createCheckbox(settingsGroup, DTMessages.sql_script_task_page_settings_option_ignore_errors, "", dtSettings.isIgnoreErrors(), 1);
dumpQueryCheck = UIUtils.createCheckbox(settingsGroup, DTMessages.sql_script_task_page_settings_option_dump_results, "", dtSettings.isDumpQueryResultsToLog(), 1);
dumpQueryCheck.setEnabled(false);
autoCommitCheck = UIUtils.createCheckbox(settingsGroup, DTMessages.sql_script_task_page_settings_option_auto_commit, "", dtSettings.isAutoCommit(), 1);
}
getWizard().createTaskSaveButtons(composite, true, 1);
loadSettings();
setControl(composite);
}
use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by serge-rider.
the class SQLToolTaskWizardPageStatus method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.BORDER);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
composite.setLayout(new FillLayout());
SashForm partDivider = new SashForm(composite, SWT.VERTICAL);
partDivider.setSashWidth(5);
statusTable = new ObjectListControl<SQLToolStatistics>(partDivider, SWT.SHEET, new ListContentProvider()) {
@NotNull
@Override
protected String getListConfigId(List<Class<?>> classList) {
return "SQLToolStatus." + getWizard().getTaskType().getId();
}
@Override
protected DBPImage getObjectImage(SQLToolStatistics item) {
return DBValueFormatting.getObjectImage(item.getObject());
}
@Override
protected LoadingJob<Collection<SQLToolStatistics>> createLoadService() {
return LoadingJob.createService(new DummyLoadService(), new ObjectsLoadVisualizer());
}
};
console = new MessageConsole(TasksSQLUIMessages.sql_tool_task_wizard_page_status_message_console_name_tool_log, null);
LogConsoleViewer consoleViewer = new LogConsoleViewer(partDivider);
console.setWaterMarks(1024 * 1024 * 3, 1024 * 1024 * 4);
try {
writer = new PrintStream(console.newMessageStream(), true, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
writer = new PrintStream(console.newMessageStream(), true);
}
setControl(composite);
}
use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by serge-rider.
the class ObjectACLEditor method createPartControl.
public void createPartControl(Composite parent) {
this.pageControl = new PageControl(parent);
SashForm composite = UIUtils.createPartDivider(getSite().getPart(), this.pageControl, SWT.HORIZONTAL);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
roleOrObjectTable = new DatabaseNavigatorTree(composite, DBWorkbench.getPlatform().getNavigatorModel().getRoot(), SWT.MULTI | SWT.FULL_SELECTION, false, isRoleEditor() ? new DatabaseObjectFilter() : null);
roleOrObjectTable.setLayoutData(new GridData(GridData.FILL_BOTH));
final TreeViewer treeViewer = roleOrObjectTable.getViewer();
treeViewer.setLabelProvider(new DatabaseNavigatorLabelProvider(treeViewer) {
@Override
public Font getFont(Object element) {
if (element instanceof DBNDatabaseNode) {
DBSObject object = ((DBNDatabaseNode) element).getObject();
if (object instanceof DBSSchema) {
String schemaPrefix = DBUtils.getQuotedIdentifier(object) + ".";
for (String tableName : privilegeMap.keySet()) {
if (tableName.startsWith(schemaPrefix)) {
return boldFont;
}
}
} else if (getObjectPermissions(object) != null) {
return boldFont;
}
}
return null;
}
});
treeViewer.addSelectionChangedListener(event -> handleSelectionChange());
treeViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof DBNNode && !(element instanceof DBNDatabaseNode)) {
return false;
}
if (element instanceof DBNDatabaseFolder) {
try {
String elementTypeName = ((DBNDatabaseFolder) element).getMeta().getType();
if (elementTypeName == null) {
return false;
}
Class<?> childType = Class.forName(elementTypeName);
return DBAPrivilegeOwner.class.isAssignableFrom(childType);
} catch (ClassNotFoundException e) {
return false;
}
}
return true;
}
});
{
permEditPanel = new Composite(composite, SWT.NONE);
permEditPanel.setLayout(new GridLayout(1, true));
permissionTable = new ObjectListControl<DBAPrivilege>(permEditPanel, SWT.FULL_SELECTION | SWT.CHECK, new ListContentProvider()) {
@Override
protected String getListConfigId(List<Class<?>> classList) {
return ObjectACLEditor.this.getClass().getName();
}
@Override
protected LoadingJob<Collection<DBAPrivilege>> createLoadService() {
return null;
}
};
permissionTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
/*
UIUtils.createTableColumn(permissionTable, SWT.LEFT, "Permission");
UIUtils.createTableColumn(permissionTable, SWT.CENTER, "With GRANT");
UIUtils.createTableColumn(permissionTable, SWT.CENTER, "With Hierarchy");
permissionTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.detail == SWT.CHECK) {
updateCurrentPrivileges(((TableItem) e.item).getChecked(), (DBAPrivilegeType) e.item.getData());
}
}
});
if (!isRoleEditor()) {
for (PRIVILEGE_TYPE pt : getACLManager().getPrivilegeTypes()) {
if (!pt.isValid() || !pt.supportsType(getDatabaseObject().getClass())) {
continue;
}
TableItem privItem = new TableItem(permissionTable, SWT.LEFT);
privItem.setText(0, pt.getName());
privItem.setData(pt);
}
}
*/
Composite buttonPanel = new Composite(permEditPanel, SWT.NONE);
buttonPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
buttonPanel.setLayout(new RowLayout());
UIUtils.createPushButton(buttonPanel, "Grant All", null, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
/*
boolean hadNonChecked = false;
for (TableItem item : permissionTable.getItems()) {
if (!item.getChecked()) hadNonChecked = true;
item.setChecked(true);
}
if (hadNonChecked) updateCurrentPrivileges(true, null);
*/
}
});
UIUtils.createPushButton(buttonPanel, "Revoke All", null, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
/*
boolean hadChecked = false;
for (TableItem item : permissionTable.getItems()) {
if (item.getChecked()) hadChecked = true;
item.setChecked(false);
}
if (hadChecked) {
updateCurrentPrivileges(false, null);
}
*/
}
});
objectDescriptionText = new Text(permEditPanel, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
objectDescriptionText.setLayoutData(new GridData(GridData.FILL_BOTH));
}
pageControl.createOrSubstituteProgressPanel(getSite());
updateObjectPermissions(null);
}
Aggregations