use of org.jkiss.dbeaver.ui.controls.resultset.view.StatisticsPresentation in project dbeaver by serge-rider.
the class ResultSetViewer method updatePresentation.
void updatePresentation(final DBCResultSet resultSet) {
if (getControl().isDisposed()) {
return;
}
boolean changed = false;
try {
if (resultSet instanceof StatResultSet) {
// Statistics - let's use special presentation for it
availablePresentations = Collections.emptyList();
setActivePresentation(new StatisticsPresentation());
activePresentationDescriptor = null;
changed = true;
} else {
// Regular results
IResultSetContext context = new IResultSetContext() {
@Override
public boolean supportsAttributes() {
DBDAttributeBinding[] attrs = model.getAttributes();
return attrs.length > 0 && (attrs[0].getDataKind() != DBPDataKind.DOCUMENT || !CommonUtils.isEmpty(attrs[0].getNestedBindings()));
}
@Override
public boolean supportsDocument() {
return model.getDocumentAttribute() != null;
}
@Override
public String getDocumentContentType() {
DBDAttributeBinding docAttr = model.getDocumentAttribute();
return docAttr == null ? null : docAttr.getValueHandler().getValueContentType(docAttr);
}
};
final List<ResultSetPresentationDescriptor> newPresentations = ResultSetPresentationRegistry.getInstance().getAvailablePresentations(resultSet, context);
changed = CommonUtils.isEmpty(this.availablePresentations) || !newPresentations.equals(this.availablePresentations);
this.availablePresentations = newPresentations;
if (!this.availablePresentations.isEmpty()) {
for (ResultSetPresentationDescriptor pd : this.availablePresentations) {
if (pd == activePresentationDescriptor) {
// Keep the same presentation
return;
}
}
String defaultPresentationId = getPreferenceStore().getString(DBeaverPreferences.RESULT_SET_PRESENTATION);
ResultSetPresentationDescriptor newPresentation = null;
if (!CommonUtils.isEmpty(defaultPresentationId)) {
for (ResultSetPresentationDescriptor pd : this.availablePresentations) {
if (pd.getId().equals(defaultPresentationId)) {
newPresentation = pd;
break;
}
}
}
changed = true;
if (newPresentation == null) {
newPresentation = this.availablePresentations.get(0);
}
try {
IResultSetPresentation instance = newPresentation.createInstance();
activePresentationDescriptor = newPresentation;
setActivePresentation(instance);
} catch (Throwable e) {
log.error(e);
}
}
}
} finally {
if (changed) {
// Update combo
statusBar.setRedraw(false);
try {
boolean pVisible = activePresentationDescriptor != null;
((RowData) presentationSwitchToolbar.getLayoutData()).exclude = !pVisible;
presentationSwitchToolbar.setVisible(pVisible);
if (!pVisible) {
presentationSwitchToolbar.setEnabled(false);
} else {
presentationSwitchToolbar.setEnabled(true);
for (ToolItem item : presentationSwitchToolbar.getItems()) item.dispose();
for (ResultSetPresentationDescriptor pd : availablePresentations) {
ToolItem item = new ToolItem(presentationSwitchToolbar, SWT.CHECK);
item.setImage(DBeaverIcons.getImage(pd.getIcon()));
item.setText(pd.getLabel());
item.setToolTipText(pd.getDescription());
item.setData(pd);
if (pd == activePresentationDescriptor) {
item.setSelection(true);
}
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.widget != null && e.widget.getData() != null) {
switchPresentation((ResultSetPresentationDescriptor) e.widget.getData());
}
}
});
}
}
statusBar.layout();
} finally {
// Enable redraw
statusBar.setRedraw(true);
}
}
}
}
use of org.jkiss.dbeaver.ui.controls.resultset.view.StatisticsPresentation 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.view.StatisticsPresentation in project dbeaver by dbeaver.
the class ResultSetViewer method updatePresentation.
void updatePresentation(final DBCResultSet resultSet) {
if (getControl().isDisposed()) {
return;
}
boolean changed = false;
try {
if (resultSet instanceof StatResultSet) {
// Statistics - let's use special presentation for it
availablePresentations = Collections.emptyList();
setActivePresentation(new StatisticsPresentation());
activePresentationDescriptor = null;
changed = true;
} else {
// Regular results
IResultSetContext context = new IResultSetContext() {
@Override
public boolean supportsAttributes() {
DBDAttributeBinding[] attrs = model.getAttributes();
return attrs.length > 0 && (attrs[0].getDataKind() != DBPDataKind.DOCUMENT || !CommonUtils.isEmpty(attrs[0].getNestedBindings()));
}
@Override
public boolean supportsDocument() {
return model.getDocumentAttribute() != null;
}
@Override
public String getDocumentContentType() {
DBDAttributeBinding docAttr = model.getDocumentAttribute();
return docAttr == null ? null : docAttr.getValueHandler().getValueContentType(docAttr);
}
};
final List<ResultSetPresentationDescriptor> newPresentations = ResultSetPresentationRegistry.getInstance().getAvailablePresentations(resultSet, context);
changed = CommonUtils.isEmpty(this.availablePresentations) || !newPresentations.equals(this.availablePresentations);
this.availablePresentations = newPresentations;
if (!this.availablePresentations.isEmpty()) {
for (ResultSetPresentationDescriptor pd : this.availablePresentations) {
if (pd == activePresentationDescriptor) {
// Keep the same presentation
return;
}
}
String defaultPresentationId = getPreferenceStore().getString(DBeaverPreferences.RESULT_SET_PRESENTATION);
ResultSetPresentationDescriptor newPresentation = null;
if (!CommonUtils.isEmpty(defaultPresentationId)) {
for (ResultSetPresentationDescriptor pd : this.availablePresentations) {
if (pd.getId().equals(defaultPresentationId)) {
newPresentation = pd;
break;
}
}
}
changed = true;
if (newPresentation == null) {
newPresentation = this.availablePresentations.get(0);
}
try {
IResultSetPresentation instance = newPresentation.createInstance();
activePresentationDescriptor = newPresentation;
setActivePresentation(instance);
} catch (Throwable e) {
log.error(e);
}
}
}
} finally {
if (changed) {
// Update combo
statusBar.setRedraw(false);
try {
boolean pVisible = activePresentationDescriptor != null;
((RowData) presentationSwitchToolbar.getLayoutData()).exclude = !pVisible;
presentationSwitchToolbar.setVisible(pVisible);
if (!pVisible) {
presentationSwitchToolbar.setEnabled(false);
} else {
presentationSwitchToolbar.setEnabled(true);
for (ToolItem item : presentationSwitchToolbar.getItems()) item.dispose();
for (ResultSetPresentationDescriptor pd : availablePresentations) {
ToolItem item = new ToolItem(presentationSwitchToolbar, SWT.CHECK);
item.setImage(DBeaverIcons.getImage(pd.getIcon()));
item.setText(pd.getLabel());
item.setToolTipText(pd.getDescription());
item.setData(pd);
if (pd == activePresentationDescriptor) {
item.setSelection(true);
}
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.widget != null && e.widget.getData() != null) {
switchPresentation((ResultSetPresentationDescriptor) e.widget.getData());
}
}
});
}
}
statusBar.layout();
} finally {
// Enable redraw
statusBar.setRedraw(true);
}
}
}
}
use of org.jkiss.dbeaver.ui.controls.resultset.view.StatisticsPresentation in project dbeaver by serge-rider.
the class ResultSetViewer method updatePresentation.
void updatePresentation(final DBCResultSet resultSet, boolean metadataChanged) {
if (getControl().isDisposed()) {
return;
}
boolean changed = false;
try {
isUIUpdateRunning = true;
if (resultSet instanceof StatResultSet) {
// Statistics - let's use special presentation for it
availablePresentations = Collections.emptyList();
setActivePresentation(new StatisticsPresentation());
activePresentationDescriptor = null;
changed = true;
} else {
// Regular results
IResultSetContext context = new ResultSetContextImpl(this, resultSet);
final List<ResultSetPresentationDescriptor> newPresentations;
// Check for preferred presentation
String preferredPresentationId = getDecorator().getPreferredPresentation();
if (CommonUtils.isEmpty(preferredPresentationId)) {
newPresentations = ResultSetPresentationRegistry.getInstance().getAvailablePresentations(resultSet, context);
} else {
ResultSetPresentationDescriptor preferredPresentation = ResultSetPresentationRegistry.getInstance().getPresentation(preferredPresentationId);
if (preferredPresentation != null) {
newPresentations = Collections.singletonList(preferredPresentation);
} else {
log.error("Presentation '" + preferredPresentationId + "' not found");
newPresentations = Collections.emptyList();
}
}
changed = CommonUtils.isEmpty(this.availablePresentations) || !newPresentations.equals(this.availablePresentations);
this.availablePresentations = newPresentations;
if (!this.availablePresentations.isEmpty()) {
if (activePresentationDescriptor != null && (!metadataChanged || activePresentationDescriptor.getPresentationType().isPersistent())) {
if (this.availablePresentations.contains(activePresentationDescriptor)) {
// Keep the same presentation
return;
}
}
String defaultPresentationId = getPreferenceStore().getString(ResultSetPreferences.RESULT_SET_PRESENTATION);
ResultSetPresentationDescriptor newPresentation = null;
if (!CommonUtils.isEmpty(defaultPresentationId)) {
for (ResultSetPresentationDescriptor pd : this.availablePresentations) {
if (pd.getId().equals(defaultPresentationId)) {
newPresentation = pd;
break;
}
}
}
changed = true;
if (newPresentation == null) {
newPresentation = this.availablePresentations.get(0);
}
try {
IResultSetPresentation instance = newPresentation.createInstance();
activePresentationDescriptor = newPresentation;
setActivePresentation(instance);
} catch (Throwable e) {
DBWorkbench.getPlatformUI().showError("Presentation activate", "Can't instantiate data view '" + newPresentation.getLabel() + "'", e);
}
} else {
// No presentation for this resulset
log.debug("No presentations for result set [" + resultSet.getClass().getSimpleName() + "]");
showEmptyPresentation();
}
}
} finally {
if (changed && presentationSwitchFolder != null) {
updatePresentationInToolbar();
}
isUIUpdateRunning = false;
}
}
Aggregations