use of org.jkiss.dbeaver.model.sql.registry.SQLGeneratorDescriptor in project dbeaver by serge-rider.
the class SQLGeneratorContributor method makeResultSetContributions.
private void makeResultSetContributions(List<IContributionItem> menu, IResultSetSelection rss) {
final IResultSetController rsv = rss.getController();
DBSDataContainer dataContainer = rsv.getDataContainer();
final List<DBDAttributeBinding> visibleAttributes = rsv.getModel().getVisibleAttributes();
final DBSEntity entity = rsv.getModel().getSingleSource();
if (dataContainer != null && !visibleAttributes.isEmpty() && entity != null) {
final List<ResultSetRow> selectedRows = new ArrayList<>(rss.getSelectedRows());
if (!CommonUtils.isEmpty(selectedRows)) {
List<IResultSetController> objects = new ArrayList<>();
objects.add(rsv);
List<SQLGeneratorDescriptor> generators = SQLGeneratorConfigurationRegistry.getInstance().getApplicableGenerators(objects, rsv);
for (SQLGeneratorDescriptor gen : generators) {
if (gen.isMultiObject() && selectedRows.size() < 2) {
continue;
}
menu.add(makeAction(gen.getLabel(), gen, objects));
}
}
} else {
// if (dataContainer != null && !visibleAttributes.isEmpty() && entity != null)
String message = dataContainer == null ? "no data container" : (visibleAttributes.isEmpty() ? "empty attribute list" : "can't resolve table");
Action disabledAction = new Action("Not available - " + message) {
};
disabledAction.setEnabled(false);
menu.add(new ActionContributionItem(disabledAction));
}
}
use of org.jkiss.dbeaver.model.sql.registry.SQLGeneratorDescriptor in project dbeaver by serge-rider.
the class SQLGeneratorContributor method getContributionItems.
// ////////////////////////////////////////////////////////
// Contributors
@Override
protected IContributionItem[] getContributionItems() {
IWorkbenchPart part = UIUtils.getActiveWorkbenchWindow().getActivePage().getActivePart();
IStructuredSelection structuredSelection = NavigatorUtils.getSelectionFromPart(part);
if (structuredSelection == null || structuredSelection.isEmpty()) {
return new IContributionItem[0];
}
List<IContributionItem> menu = new ArrayList<>();
if (structuredSelection instanceof IResultSetSelection) {
// Results
makeResultSetContributions(menu, (IResultSetSelection) structuredSelection);
} else {
List<DBPObject> objects = new ArrayList<>();
for (Object obj : structuredSelection.toList()) {
DBSObject adaptedObject = GeneralUtils.adapt(obj, DBSObject.class);
if (adaptedObject != null) {
objects.add(adaptedObject);
} else if (obj instanceof DBSWrapper) {
objects.add(((DBSWrapper) obj).getObject());
} else if (obj instanceof DBPObject) {
objects.add((DBPObject) obj);
}
}
List<SQLGeneratorDescriptor> generators = SQLGeneratorConfigurationRegistry.getInstance().getApplicableGenerators(objects, structuredSelection);
int lastGrand = 0;
for (SQLGeneratorDescriptor gen : generators) {
int order = gen.getOrder();
if (order > 0 && order / 1000 > lastGrand) {
menu.add(new Separator());
}
lastGrand = order / 1000;
menu.add(makeAction(gen.getLabel(), gen, objects));
}
}
return menu.toArray(new IContributionItem[0]);
}
Aggregations