提交 d8f62ca2 编写于 作者: S serge-rider

dbeaver/dbeaver#342 RSV decorator additions

上级 cb2b60f1
......@@ -969,7 +969,7 @@ public final class DBUtils {
}
@NotNull
public static Collection<? extends DBSEntityAttribute> getBestTableIdentifier(@NotNull DBRProgressMonitor monitor, @NotNull DBSEntity entity)
public static List<? extends DBSEntityAttribute> getBestTableIdentifier(@NotNull DBRProgressMonitor monitor, @NotNull DBSEntity entity)
throws DBException
{
if (entity instanceof DBSTable && ((DBSTable) entity).isView()) {
......
......@@ -19,16 +19,16 @@ package org.jkiss.dbeaver.ui.controls.resultset;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.DBPContextProvider;
import org.jkiss.dbeaver.model.app.DBPProject;
import org.jkiss.dbeaver.model.data.DBDDataFilter;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSDataContainer;
/**
* Result set provider
*/
public interface IResultSetContainer {
public interface IResultSetContainer extends DBPContextProvider {
/**
* Owner project.
......@@ -37,13 +37,6 @@ public interface IResultSetContainer {
@Nullable
DBPProject getProject();
/**
* Execution context which will be used by Results viewer to read data
* @return execution context. Maybe null is container is not connected
*/
@Nullable
DBCExecutionContext getExecutionContext();
/**
* Hosted results controller
* @return controller or null
......
......@@ -29,13 +29,23 @@ public interface IResultSetDecorator {
long FEATURE_STATUS_BAR = 2;
long FEATURE_PANELS = 4;
long FEATURE_EDIT = 8;
long FEATURE_PRESENTATIONS = 16;
long getDecoratorFeatures();
/**
* Primary presentation ID.
* @return presentation ID or null.
*/
String getPreferredPresentation();
String getEmptyDataMessage();
String getEmptyDataDescription();
/**
* Fill additional menu actions
*/
void fillContributions(IContributionManager contributionManager);
void registerDragAndDrop(IResultSetPresentation presentation);
......
......@@ -25,7 +25,7 @@ public class QueryResultsDecorator extends ResultSetDecoratorBase {
@Override
public long getDecoratorFeatures() {
return FEATURE_FILTERS | FEATURE_STATUS_BAR | FEATURE_PANELS | FEATURE_EDIT;
return FEATURE_FILTERS | FEATURE_STATUS_BAR | FEATURE_PANELS | FEATURE_PRESENTATIONS | FEATURE_EDIT;
}
@Override
......
......@@ -25,7 +25,12 @@ import org.eclipse.jface.action.IContributionManager;
public abstract class ResultSetDecoratorBase implements IResultSetDecorator {
@Override
public long getDecoratorFeatures() {
return 0;
return FEATURE_NONE;
}
@Override
public String getPreferredPresentation() {
return null;
}
@Override
......
......@@ -245,23 +245,29 @@ public class ResultSetViewer extends Viewer
this.defaultBackground = UIStyles.getDefaultTextBackground();
this.defaultForeground = UIStyles.getDefaultTextForeground();
boolean supportsPanels = (decorator.getDecoratorFeatures() & IResultSetDecorator.FEATURE_PANELS) != 0;
long decoratorFeatures = decorator.getDecoratorFeatures();
boolean supportsPanels = (decoratorFeatures & IResultSetDecorator.FEATURE_PANELS) != 0;
this.mainPanel = UIUtils.createPlaceholder(parent, supportsPanels ? 3 : 2);
this.autoRefreshControl = new AutoRefreshControl(
this.mainPanel, ResultSetViewer.class.getSimpleName(), monitor -> refreshData(null));
if ((decorator.getDecoratorFeatures() & IResultSetDecorator.FEATURE_FILTERS) != 0) {
if ((decoratorFeatures & IResultSetDecorator.FEATURE_FILTERS) != 0) {
this.filtersPanel = new ResultSetFilterPanel(this, this.mainPanel);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = ((GridLayout)mainPanel.getLayout()).numColumns;
this.filtersPanel.setLayoutData(gd);
}
this.presentationSwitchFolder = new VerticalFolder(mainPanel, SWT.LEFT);
this.presentationSwitchFolder.setLayoutData(new GridData(GridData.FILL_VERTICAL));
CSSUtils.setCSSClass(this.presentationSwitchFolder, DBStyles.COLORED_BY_CONNECTION_TYPE);
if ((decoratorFeatures & IResultSetDecorator.FEATURE_PRESENTATIONS) != 0) {
this.presentationSwitchFolder = new VerticalFolder(mainPanel, SWT.LEFT);
this.presentationSwitchFolder.setLayoutData(new GridData(GridData.FILL_VERTICAL));
CSSUtils.setCSSClass(this.presentationSwitchFolder, DBStyles.COLORED_BY_CONNECTION_TYPE);
} else {
this. presentationSwitchFolder = null;
}
this.viewerPanel = UIUtils.createPlaceholder(mainPanel, 1);
this.viewerPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
......@@ -620,7 +626,21 @@ public class ResultSetViewer extends Viewer
} else {
// Regular results
IResultSetContext context = new ResultSetContextImpl(this, resultSet);
final List<ResultSetPresentationDescriptor> newPresentations = ResultSetPresentationRegistry.getInstance().getAvailablePresentations(resultSet, context);
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()) {
......@@ -667,6 +687,9 @@ public class ResultSetViewer extends Viewer
}
private void updatePresentationInToolbar() {
if (presentationSwitchFolder == null) {
return;
}
// Update combo
mainPanel.setRedraw(false);
try {
......@@ -1392,10 +1415,12 @@ public class ResultSetViewer extends Viewer
ResultSetPropertyTester.firePropertyChange(ResultSetPropertyTester.PROP_CHANGED);
fireResultSetChange();
updateToolbar();
// Enable presentations
for (VerticalButton pb : presentationSwitchFolder.getItems()) {
if (pb.getData() instanceof ResultSetPresentationDescriptor) {
pb.setVisible(!recordMode || ((ResultSetPresentationDescriptor) pb.getData()).supportsRecordMode());
if (presentationSwitchFolder != null) {
// Enable presentations
for (VerticalButton pb : presentationSwitchFolder.getItems()) {
if (pb.getData() instanceof ResultSetPresentationDescriptor) {
pb.setVisible(!recordMode || ((ResultSetPresentationDescriptor) pb.getData()).supportsRecordMode());
}
}
}
}
......
......@@ -49,7 +49,7 @@ class ValidateUniqueKeyUsageDialog extends MessageDialogWithToggle {
{
super(
viewer.getControl().getShell(),
"Possible multiple rows modification",
"No unique key - multiple rows modification possible",
null,
"There is no physical unique key defined for '" + DBUtils.getObjectFullName(viewer.getVirtualEntityIdentifier().getUniqueKey().getParentObject(), DBPEvaluationContext.UI) +
"'.\nDBeaver will use all columns as unique key. Possible multiple rows modification. \nAre you sure you want to proceed?",
......
......@@ -50,7 +50,7 @@ public class GroupingResultsDecorator extends ResultSetDecoratorBase {
@Override
public long getDecoratorFeatures() {
return FEATURE_NONE;
return FEATURE_PRESENTATIONS;
}
@Override
......
......@@ -32,7 +32,7 @@ public class ReferencesResultsDecorator extends QueryResultsDecorator {
@Override
public long getDecoratorFeatures() {
return FEATURE_NONE;
return FEATURE_PRESENTATIONS;
}
@Override
......
......@@ -111,6 +111,8 @@ import java.util.*;
*/
public class SpreadsheetPresentation extends AbstractPresentation implements IResultSetEditor, ISelectionProvider, IStatefulControl, IAdaptable, IGridController {
public static final String PRESENTATION_ID = "spreadsheet";
private static final Log log = Log.getLog(SpreadsheetPresentation.class);
private Spreadsheet spreadsheet;
......@@ -740,7 +742,9 @@ public class SpreadsheetPresentation extends AbstractPresentation implements IRe
showAttrOrdering = preferenceStore.getBoolean(ResultSetPreferences.RESULT_SET_SHOW_ATTR_ORDERING);
showAttributeIcons = controller.getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_SHOW_ATTR_ICONS);
showAttributeDescription = getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_SHOW_DESCRIPTION);
supportsAttributeFilter = (controller.getDataContainer().getSupportedFeatures() & DBSDataContainer.DATA_FILTER) != 0 &&
supportsAttributeFilter =
(controller.getDecorator().getDecoratorFeatures() & IResultSetDecorator.FEATURE_FILTERS) != 0 &&
(controller.getDataContainer().getSupportedFeatures() & DBSDataContainer.DATA_FILTER) != 0 &&
controller.getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_SHOW_ATTR_FILTERS);
autoFetchSegments = controller.getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_AUTO_FETCH_NEXT_SEGMENT);
calcColumnWidthByValue = getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_CALC_COLUMN_WIDTH_BY_VALUES);
......
......@@ -194,7 +194,7 @@ public class CursorViewDialog extends ValueViewDialog implements IResultSetConta
return new QueryResultsDecorator() {
@Override
public long getDecoratorFeatures() {
return FEATURE_PANELS | FEATURE_STATUS_BAR;
return FEATURE_PANELS | FEATURE_PRESENTATIONS | FEATURE_STATUS_BAR;
}
};
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册