use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by serge-rider.
the class OracleCompilerDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
GridData gd;
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
{
Composite unitsGroup = new Composite(composite, SWT.NONE);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 250;
gd.heightHint = 200;
gd.verticalIndent = 0;
gd.horizontalIndent = 0;
unitsGroup.setLayoutData(gd);
unitsGroup.setLayout(new GridLayout(1, false));
unitTable = new TableViewer(unitsGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
{
final Table table = unitTable.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
table.setLinesVisible(true);
table.setHeaderVisible(true);
}
ViewerColumnController columnController = new ViewerColumnController("OracleCompilerDialog", unitTable);
columnController.addColumn(OracleUIMessages.views_oracle_compiler_dialog_column_name, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DBSObject unit = (DBSObject) cell.getElement();
final DBNDatabaseNode node = DBNUtils.getNodeByObject(unit);
if (node != null) {
cell.setText(node.getNodeName());
cell.setImage(DBeaverIcons.getImage(node.getNodeIconDefault()));
} else {
cell.setText(unit.toString());
}
}
});
columnController.addColumn(OracleUIMessages.views_oracle_compiler_dialog_column_type, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DBSObject unit = (DBSObject) cell.getElement();
final DBNDatabaseNode node = DBNUtils.getNodeByObject(unit);
if (node != null) {
cell.setText(node.getNodeType());
} else {
// $NON-NLS-1$
cell.setText("???");
}
}
});
columnController.createColumns();
unitTable.addSelectionChangedListener(event -> {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
getButton(COMPILE_ID).setEnabled(!selection.isEmpty());
});
unitTable.addDoubleClickListener(event -> {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (!selection.isEmpty()) {
OracleSourceObject unit = (OracleSourceObject) selection.getFirstElement();
NavigatorHandlerObjectOpen.openEntityEditor(unit);
}
});
unitTable.setContentProvider(new ListContentProvider());
unitTable.setInput(compileUnits);
}
{
Composite infoGroup = new Composite(composite, SWT.NONE);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 400;
gd.heightHint = 200;
gd.verticalIndent = 0;
gd.horizontalIndent = 0;
infoGroup.setLayoutData(gd);
infoGroup.setLayout(new GridLayout(1, false));
compileLog = new ObjectCompilerLogViewer(infoGroup, null, true);
}
return composite;
}
use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by serge-rider.
the class ObjectListDialog method createObjectSelector.
@NotNull
protected static <T extends DBPObject> DatabaseObjectListControl<T> createObjectSelector(Composite group, boolean singleSelection, String listId, List<T> selectedObjects, DBRRunnableWithResult<List<T>> objectReader) {
return new DatabaseObjectListControl<T>(group, (singleSelection ? SWT.SINGLE : SWT.MULTI), null, new ListContentProvider()) {
private Font boldFont;
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 {
objectReader.run(monitor);
return objectReader.getResult();
}
@Override
public Object getFamily() {
return ObjectListDialog.class;
}
}, new ObjectsLoadVisualizer() {
@Override
public void completeLoading(Collection<T> items) {
super.completeLoading(items);
performSearch(SearchType.NONE);
getItemsViewer().getControl().setFocus();
}
});
}
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
public 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(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)) {
if (boldFont == null) {
boldFont = UIUtils.makeBoldFont(group.getFont());
group.addDisposeListener(e -> boldFont.dispose());
}
return boldFont;
}
return null;
}
}
};
}
use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by dbeaver.
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.ui.controls.ListContentProvider in project dbeaver by dbeaver.
the class PostgreCreateExtensionDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
final Composite composite = super.createDialogArea(parent);
final Composite group = new Composite(composite, SWT.NONE);
group.setLayout(new GridLayout(2, false));
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 600;
gd.heightHint = 200;
gd.verticalIndent = 0;
gd.horizontalIndent = 0;
group.setLayoutData(gd);
// $NON-NLS-2$
final Text databaseText = UIUtils.createLabelText(group, PostgreMessages.dialog_create_extension_database, newextension.getDatabase().getName(), SWT.BORDER | SWT.READ_ONLY);
final Combo schemaCombo = UIUtils.createLabelCombo(group, PostgreMessages.dialog_create_extension_schema, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
final Label lblExtension = UIUtils.createLabel(group, PostgreMessages.dialog_create_extension_name);
extTable = new TableViewer(group, SWT.BORDER | SWT.UNDERLINE_SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
{
final Table table = extTable.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
UIUtils.packColumns(table);
UIUtils.maxTableColumnsWidth(table);
table.removeControlListener(this);
}
});
}
ViewerColumnController columnController = new ViewerColumnController("AvailabelExtensionDialog", extTable);
columnController.addColumn(PostgreMessages.dialog_create_extension_column_name, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(((PostgreAvailableExtension) cell.getElement()).getName());
}
});
columnController.addColumn(PostgreMessages.dialog_create_extension_column_version, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(((PostgreAvailableExtension) cell.getElement()).getVersion());
}
});
columnController.addColumn(PostgreMessages.dialog_create_extension_column_description, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(((PostgreAvailableExtension) cell.getElement()).getDescription());
}
});
columnController.createColumns();
extTable.addSelectionChangedListener(event -> {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (!selection.isEmpty()) {
// installed.get(extensionCombo.getSelectionIndex());
extension = (PostgreAvailableExtension) selection.getFirstElement();
checkEnabled();
}
});
extTable.setContentProvider(new ListContentProvider());
schemaCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
schema = allSchemas.get(schemaCombo.getSelectionIndex());
checkEnabled();
}
});
new AbstractJob("Load schemas") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
allSchemas = new ArrayList<>(newextension.getDatabase().getSchemas(monitor));
UIUtils.syncExec(() -> {
for (PostgreSchema schema : allSchemas) {
schemaCombo.add(schema.getName());
}
schema = DBUtils.findObject(allSchemas, PostgreConstants.PUBLIC_SCHEMA_NAME);
if (schema != null) {
schemaCombo.setText(schema.getName());
}
});
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
new AbstractJob("Load available extensions") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
final List<PostgreAvailableExtension> installed = new ArrayList<>(newextension.getDatabase().getAvailableExtensions(monitor));
UIUtils.syncExec(() -> {
extTable.setInput(installed);
});
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
return composite;
}
use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by dbeaver.
the class DashboardAddDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
Composite dialogArea = super.createDialogArea(parent);
// AdvancedListViewer listViewer = new AdvancedListViewer(dialogArea, SWT.NONE);
// listViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
TableViewer dashboardTable = new TableViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION);
dashboardTable.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
Table table = dashboardTable.getTable();
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 400;
gd.heightHint = 200;
table.setLayoutData(gd);
table.setHeaderVisible(true);
UIUtils.createTableColumn(table, SWT.LEFT, UIDashboardMessages.dialog_add_dashboard_column_name);
UIUtils.createTableColumn(table, SWT.LEFT, UIDashboardMessages.dialog_add_dashboard_column_description);
dashboardTable.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DashboardDescriptor dashboardDescriptor = (DashboardDescriptor) cell.getElement();
if (cell.getColumnIndex() == 0) {
cell.setText(dashboardDescriptor.getName());
} else {
cell.setText(CommonUtils.notEmpty(dashboardDescriptor.getDescription()));
}
}
});
dashboardTable.addDoubleClickListener(event -> {
if (!dashboardTable.getSelection().isEmpty()) {
okPressed();
}
});
dashboardTable.addSelectionChangedListener(event -> {
ISelection selection = dashboardTable.getSelection();
getButton(IDialogConstants.OK_ID).setEnabled(!selection.isEmpty());
if (selection instanceof IStructuredSelection) {
selectedDashboard = (DashboardDescriptor) ((IStructuredSelection) selection).getFirstElement();
}
getButton(IDialogConstants.OK_ID).setEnabled(selectedDashboard != null);
});
table.addPaintListener(e -> {
if (table.getItemCount() == 0) {
final String dbmsName = viewConfiguration.getDataSourceContainer().getDriver().getName();
final String msg = NLS.bind(UIDashboardMessages.dialog_add_dashboard_message_no_more_dashboards_for, dbmsName);
UIUtils.drawMessageOverControl(table, e, msg, 0);
}
});
dashboardTable.setContentProvider(new ListContentProvider());
java.util.List<DashboardDescriptor> dashboards = new ArrayList<>(DashboardRegistry.getInstance().getDashboards(viewConfiguration.getDataSourceContainer(), false));
dashboards.removeIf(descriptor -> viewConfiguration.getDashboardConfig(descriptor.getId()) != null);
dashboardTable.setInput(dashboards);
UIUtils.asyncExec(() -> UIUtils.packColumns(table, true));
return dialogArea;
}
Aggregations