Search in sources :

Example 1 with SQLGeneratorDescriptor

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));
    }
}
Also used : ArrayList(java.util.ArrayList) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) IResultSetController(org.jkiss.dbeaver.ui.controls.resultset.IResultSetController) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) SQLGeneratorDescriptor(org.jkiss.dbeaver.model.sql.registry.SQLGeneratorDescriptor) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer)

Example 2 with SQLGeneratorDescriptor

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]);
}
Also used : DBPObject(org.jkiss.dbeaver.model.DBPObject) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) ArrayList(java.util.ArrayList) IResultSetSelection(org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SQLGeneratorDescriptor(org.jkiss.dbeaver.model.sql.registry.SQLGeneratorDescriptor) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DBPScriptObject(org.jkiss.dbeaver.model.DBPScriptObject) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPObject(org.jkiss.dbeaver.model.DBPObject)

Aggregations

ArrayList (java.util.ArrayList)2 SQLGeneratorDescriptor (org.jkiss.dbeaver.model.sql.registry.SQLGeneratorDescriptor)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1 DBPObject (org.jkiss.dbeaver.model.DBPObject)1 DBPScriptObject (org.jkiss.dbeaver.model.DBPScriptObject)1 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)1 DBSDataContainer (org.jkiss.dbeaver.model.struct.DBSDataContainer)1 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1 DBSWrapper (org.jkiss.dbeaver.model.struct.DBSWrapper)1 IResultSetController (org.jkiss.dbeaver.ui.controls.resultset.IResultSetController)1 IResultSetSelection (org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection)1 ResultSetRow (org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow)1