use of org.jkiss.dbeaver.ui.controls.resultset.panel.ResultSetPanelDescriptor in project dbeaver by serge-rider.
the class ResultSetViewer method setActivePresentation.
private void setActivePresentation(@NotNull IResultSetPresentation presentation) {
boolean focusInPresentation = UIUtils.isParent(presentationPanel, viewerPanel.getDisplay().getFocusControl());
// Dispose previous presentation and panels
if (activePresentation != null) {
activePresentation.dispose();
}
UIUtils.disposeChildControls(presentationPanel);
if (panelFolder != null) {
CTabItem curItem = panelFolder.getSelection();
for (CTabItem panelItem : panelFolder.getItems()) {
if (panelItem != curItem) {
panelItem.dispose();
}
}
if (curItem != null) {
curItem.dispose();
}
}
// Set new presentation
activePresentation = presentation;
availablePanels.clear();
activePanels.clear();
IResultSetContext context = new ResultSetContextImpl(this, null);
if (activePresentationDescriptor != null) {
availablePanels.addAll(ResultSetPresentationRegistry.getInstance().getSupportedPanels(context, getDataSource(), activePresentationDescriptor.getId(), activePresentationDescriptor.getPresentationType()));
} else if (activePresentation instanceof StatisticsPresentation) {
// Stats presentation
availablePanels.addAll(ResultSetPresentationRegistry.getInstance().getSupportedPanels(context, getDataSource(), null, IResultSetPresentation.PresentationType.COLUMNS));
}
activePresentation.createPresentation(this, presentationPanel);
// Clear panels toolbar
if (panelSwitchFolder != null) {
UIUtils.disposeChildControls(panelSwitchFolder);
}
// Activate panels
if (supportsPanels()) {
boolean panelsVisible = false;
boolean verticalLayout = false;
int[] panelWeights = new int[] { 700, 300 };
if (activePresentationDescriptor != null) {
PresentationSettings settings = getPresentationSettings();
panelsVisible = settings.panelsVisible;
verticalLayout = settings.verticalLayout;
if (settings.panelRatio > 0) {
panelWeights = new int[] { 1000 - settings.panelRatio, settings.panelRatio };
}
activateDefaultPanels(settings);
}
viewerSash.setOrientation(verticalLayout ? SWT.VERTICAL : SWT.HORIZONTAL);
viewerSash.setWeights(panelWeights);
showPanels(panelsVisible, false, false);
if (!availablePanels.isEmpty()) {
VerticalButton panelsButton = new VerticalButton(panelSwitchFolder, SWT.RIGHT | SWT.CHECK);
{
panelsButton.setText(ResultSetMessages.controls_resultset_config_panels);
panelsButton.setImage(DBeaverIcons.getImage(UIIcon.PANEL_CUSTOMIZE));
panelsButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showPanels(!isPanelsVisible(), true, true);
panelsButton.setChecked(isPanelsVisible());
updatePanelsButtons();
}
});
String toolTip = ActionUtils.findCommandDescription(ResultSetHandlerMain.CMD_TOGGLE_PANELS, getSite(), false);
if (!CommonUtils.isEmpty(toolTip)) {
panelsButton.setToolTipText(toolTip);
}
panelsButton.setChecked(panelsVisible);
}
// Add all panels
for (final ResultSetPanelDescriptor panel : availablePanels) {
VerticalButton panelButton = new VerticalButton(panelSwitchFolder, SWT.RIGHT | SWT.CHECK);
GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
gd.verticalIndent = 2;
gd.horizontalIndent = 1;
panelButton.setLayoutData(gd);
panelButton.setData(panel);
panelButton.setImage(DBeaverIcons.getImage(panel.getIcon()));
panelButton.setToolTipText(panel.getLabel());
String toolTip = ActionUtils.findCommandDescription(ResultSetHandlerTogglePanel.CMD_TOGGLE_PANEL, getSite(), true, ResultSetHandlerTogglePanel.PARAM_PANEL_ID, panel.getId());
if (!CommonUtils.isEmpty(toolTip)) {
panelButton.setToolTipText(panel.getLabel() + " (" + toolTip + ")");
}
panelButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean isPanelVisible = isPanelsVisible() && isPanelVisible(panel.getId());
if (isPanelVisible) {
closePanel(panel.getId());
} else {
activatePanel(panel.getId(), true, true);
}
panelButton.setChecked(!isPanelVisible);
panelsButton.setChecked(isPanelsVisible());
if (panelSwitchFolder != null) {
panelSwitchFolder.redraw();
}
}
});
panelButton.setChecked(panelsVisible && isPanelVisible(panel.getId()));
}
UIUtils.createEmptyLabel(panelSwitchFolder, 1, 1).setLayoutData(new GridData(GridData.FILL_VERTICAL));
VerticalButton.create(panelSwitchFolder, SWT.RIGHT | SWT.CHECK, getSite(), ResultSetHandlerMain.CMD_TOGGLE_LAYOUT, false);
}
} else {
if (viewerSash != null) {
viewerSash.setMaximizedControl(viewerSash.getChildren()[0]);
}
}
mainPanel.layout(true, true);
if (recordModeButton != null) {
recordModeButton.setVisible(activePresentationDescriptor != null && activePresentationDescriptor.supportsRecordMode());
}
// Update dynamic find/replace target
{
IFindReplaceTarget nested = null;
if (presentation instanceof IAdaptable) {
nested = ((IAdaptable) presentation).getAdapter(IFindReplaceTarget.class);
}
findReplaceTarget.setTarget(nested);
}
if (!toolbarList.isEmpty()) {
for (ToolBarManager tb : toolbarList) {
tb.update(true);
}
}
// Listen presentation selection change
if (presentation instanceof ISelectionProvider) {
((ISelectionProvider) presentation).addSelectionChangedListener(this::fireResultSetSelectionChange);
}
// Use async exec to avoid focus switch after user UI interaction (e.g. combo)
if (focusInPresentation) {
UIUtils.asyncExec(() -> {
Control control = activePresentation.getControl();
if (control != null && !control.isDisposed()) {
control.setFocus();
}
});
}
}
use of org.jkiss.dbeaver.ui.controls.resultset.panel.ResultSetPanelDescriptor in project dbeaver by serge-rider.
the class ResultSetPresentationRegistry method getSupportedPanels.
public List<ResultSetPanelDescriptor> getSupportedPanels(IResultSetContext context, DBPDataSource dataSource, String presentationId, IResultSetPresentation.PresentationType presentationType) {
List<ResultSetPanelDescriptor> result = new ArrayList<>();
for (ResultSetPanelDescriptor panel : panels) {
if (panel.supportedBy(context, dataSource, presentationId, presentationType)) {
result.add(panel);
}
}
result.sort(Comparator.comparing(ResultSetPanelDescriptor::getLabel));
return result;
}
use of org.jkiss.dbeaver.ui.controls.resultset.panel.ResultSetPanelDescriptor in project dbeaver by serge-rider.
the class ResultSetHandlerTogglePanel method updateElement.
@Override
public void updateElement(UIElement element, Map parameters) {
// Put panel name in command label
String panelId = (String) parameters.get(PARAM_PANEL_ID);
if (panelId != null) {
ResultSetPanelDescriptor panel = ResultSetPresentationRegistry.getInstance().getPanel(panelId);
if (panel != null) {
element.setText(panel.getLabel());
if (!CommonUtils.isEmpty(panel.getDescription())) {
element.setTooltip(panel.getDescription());
}
}
IWorkbenchPart workbenchPart = element.getServiceLocator().getService(IWorkbenchPart.class);
if (workbenchPart != null) {
IResultSetController resultSet = ResultSetHandlerMain.getActiveResultSet(workbenchPart);
if (resultSet != null) {
element.setChecked(((ResultSetViewer) resultSet).isPanelVisible(panelId));
}
}
}
}
use of org.jkiss.dbeaver.ui.controls.resultset.panel.ResultSetPanelDescriptor in project dbeaver by dbeaver.
the class ResultSetViewer method fillPanelsMenu.
private List<IContributionItem> fillPanelsMenu() {
List<IContributionItem> items = new ArrayList<>();
for (final ResultSetPanelDescriptor panel : availablePanels) {
CommandContributionItemParameter params = new CommandContributionItemParameter(site, panel.getId(), ResultSetHandlerTogglePanel.CMD_TOGGLE_PANEL, CommandContributionItem.STYLE_CHECK);
Map<String, String> parameters = new HashMap<>();
parameters.put(ResultSetHandlerTogglePanel.PARAM_PANEL_ID, panel.getId());
params.parameters = parameters;
items.add(new CommandContributionItem(params));
}
items.add(new Separator());
// if (viewerSash.getMaximizedControl() == null) {
// items.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_TOGGLE_LAYOUT));
// }
items.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_TOGGLE_MAXIMIZE));
// items.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_TOGGLE_PANELS));
items.add(ActionUtils.makeCommandContribution(site, ResultSetHandlerMain.CMD_ACTIVATE_PANELS));
return items;
}
use of org.jkiss.dbeaver.ui.controls.resultset.panel.ResultSetPanelDescriptor in project dbeaver by dbeaver.
the class ResultSetViewer method activatePanel.
@Override
public boolean activatePanel(String id, boolean setActive, boolean showPanels) {
if (!supportsPanels()) {
return false;
}
if (showPanels && !isPanelsVisible()) {
showPanels(true, false, false);
}
PresentationSettings presentationSettings = getPresentationSettings();
IResultSetPanel panel = activePanels.get(id);
if (panel != null) {
CTabItem panelTab = getPanelTab(id);
if (panelTab != null) {
if (setActive) {
panelFolder.setSelection(panelTab);
presentationSettings.activePanelId = id;
if (showPanels) {
panel.setFocus();
}
// panelTab.getControl().setFocus();
}
return true;
} else {
log.debug("Panel '" + id + "' tab not found");
}
}
// Create panel
ResultSetPanelDescriptor panelDescriptor = getPanelDescriptor(id);
if (panelDescriptor == null) {
log.debug("Panel '" + id + "' not found");
return false;
}
try {
panel = panelDescriptor.createInstance();
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError("Can't show panel", "Can't create panel '" + id + "'", e);
return false;
}
activePanels.put(id, panel);
// Create control and tab item
panelFolder.setRedraw(false);
try {
Control panelControl = panel.createContents(activePresentation, panelFolder);
boolean firstPanel = panelFolder.getItemCount() == 0;
CTabItem panelTab = new CTabItem(panelFolder, SWT.CLOSE);
panelTab.setData(id);
panelTab.setText(panelDescriptor.getLabel());
panelTab.setImage(DBeaverIcons.getImage(panelDescriptor.getIcon()));
panelTab.setToolTipText(panelDescriptor.getDescription());
panelTab.setControl(panelControl);
UIUtils.disposeControlOnItemDispose(panelTab);
if (setActive || firstPanel) {
panelFolder.setSelection(panelTab);
}
if (showPanels) {
panel.setFocus();
}
} finally {
panelFolder.setRedraw(true);
}
presentationSettings.enabledPanelIds.add(id);
if (setActive) {
setActivePanel(id);
}
updatePanelsButtons();
return true;
}
Aggregations