Search in sources :

Example 1 with IResultSetSelection

use of org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection in project dbeaver by serge-rider.

the class GenerateUUIDHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart == null) {
        return null;
    }
    IResultSetController rsc = activePart.getAdapter(IResultSetController.class);
    if (rsc != null && UIUtils.hasFocus(rsc.getControl())) {
        IResultSetSelection selection = rsc.getSelection();
        if (selection != null && !selection.isEmpty()) {
            for (Object cell : selection.toArray()) {
                DBDAttributeBinding attr = selection.getElementAttribute(cell);
                ResultSetRow row = selection.getElementRow(cell);
                if (row != null && attr != null) {
                    ResultSetValueController valueController = new ResultSetValueController(rsc, attr, row, IValueController.EditType.NONE, null);
                    DBDValueHandler valueHandler = valueController.getValueHandler();
                    String uuid = generateUUID();
                    valueController.updateValue(uuid, false);
                }
            }
            rsc.redrawData(false, false);
            rsc.updateEditControls();
        }
    } else {
        ITextViewer textViewer = activePart.getAdapter(ITextViewer.class);
        if (textViewer != null) {
            ISelection selection = textViewer.getSelectionProvider().getSelection();
            if (selection instanceof TextSelection) {
                try {
                    int offset = ((TextSelection) selection).getOffset();
                    int length = ((TextSelection) selection).getLength();
                    String uuid = generateUUID();
                    textViewer.getDocument().replace(offset, length, uuid);
                    textViewer.getSelectionProvider().setSelection(new TextSelection(offset + uuid.length(), 0));
                } catch (BadLocationException e) {
                    DBWorkbench.getPlatformUI().showError("Insert UUID", "Error inserting UUID in text editor", e);
                }
            }
        }
    }
    return null;
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) IResultSetSelection(org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection) DBDValueHandler(org.jkiss.dbeaver.model.data.DBDValueHandler) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) IResultSetController(org.jkiss.dbeaver.ui.controls.resultset.IResultSetController) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) ITextViewer(org.eclipse.jface.text.ITextViewer) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) ResultSetValueController(org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with IResultSetSelection

use of org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection in project dbeaver by serge-rider.

the class GenerateSQLContributor method getContributionItems.

//////////////////////////////////////////////////////////
// Contributors
@Override
protected IContributionItem[] getContributionItems() {
    IWorkbenchPart part = DBeaverUI.getActiveWorkbenchWindow().getActivePage().getActivePart();
    IStructuredSelection structuredSelection = GenerateSQLContributor.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<DBSEntity> entities = new ArrayList<>();
        List<DBPScriptObject> scriptObjects = new ArrayList<>();
        for (Object sel : structuredSelection.toArray()) {
            final DBSObject object = ((DBNDatabaseNode) RuntimeUtils.getObjectAdapter(sel, DBNNode.class)).getObject();
            if (object instanceof DBSEntity) {
                entities.add((DBSEntity) object);
            }
            if (object instanceof DBPScriptObject) {
                scriptObjects.add((DBPScriptObject) object);
            }
        }
        if (!entities.isEmpty()) {
            makeTableContributions(menu, entities);
        }
        if (!scriptObjects.isEmpty()) {
            makeScriptContributions(menu, scriptObjects);
        }
    }
    return menu.toArray(new IContributionItem[menu.size()]);
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) IResultSetSelection(org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 3 with IResultSetSelection

use of org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection in project dbeaver by dbeaver.

the class GenerateSQLContributor method getContributionItems.

// ////////////////////////////////////////////////////////
// Contributors
@Override
protected IContributionItem[] getContributionItems() {
    IWorkbenchPart part = DBeaverUI.getActiveWorkbenchWindow().getActivePage().getActivePart();
    IStructuredSelection structuredSelection = GenerateSQLContributor.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<DBSEntity> entities = new ArrayList<>();
        List<DBPScriptObject> scriptObjects = new ArrayList<>();
        for (Object sel : structuredSelection.toArray()) {
            final DBSObject object = RuntimeUtils.getObjectAdapter(sel, DBSObject.class);
            if (object instanceof DBSEntity) {
                entities.add((DBSEntity) object);
            }
            if (object instanceof DBPScriptObject) {
                scriptObjects.add((DBPScriptObject) object);
            }
        }
        if (!entities.isEmpty()) {
            makeTableContributions(menu, entities);
        }
        if (!scriptObjects.isEmpty()) {
            makeScriptContributions(menu, scriptObjects);
        }
    }
    return menu.toArray(new IContributionItem[menu.size()]);
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IResultSetSelection(org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 4 with IResultSetSelection

use of org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection in project dbeaver by serge-rider.

the class GISBrowserViewer method primeEditorValue.

@Override
public void primeEditorValue(@Nullable Object value) throws DBException {
    List<DBGeometry> geometries = new ArrayList<>();
    IDataController dataController = valueController.getDataController();
    if (dataController instanceof IResultSetController) {
        IResultSetController resultSetController = (IResultSetController) dataController;
        DBSTypedObject valueType = valueController.getValueType();
        List<GeometryDataUtils.GeomAttrs> geomAttrs = null;
        if (valueType instanceof DBSAttributeBase) {
            geomAttrs = GeometryDataUtils.extractGeometryAttributes(resultSetController);
        }
        IResultSetSelection selection = resultSetController.getSelection();
        Object[] selectedValues = selection.toArray();
        if (ArrayUtils.isEmpty(selectedValues)) {
            selectedValues = new Object[] { value };
        }
        for (Object cell : selectedValues) {
            DBGeometry geometry;
            DBDAttributeBinding attr;
            ResultSetRow row;
            if (cell instanceof DBGeometry) {
                attr = resultSetController.getActivePresentation().getCurrentAttribute();
                row = resultSetController.getCurrentRow();
                geometry = (DBGeometry) cell;
            } else {
                attr = selection.getElementAttribute(cell);
                row = selection.getElementRow(cell);
                Object cellValue = resultSetController.getModel().getCellValue(attr, row);
                geometry = GisTransformUtils.getGeometryValueFromObject(valueController.getDataController().getDataContainer(), valueController.getValueHandler(), valueController.getValueType(), cellValue);
            }
            if (geometry != null) {
                geometries.add(geometry);
                // Set properties
                if (valueType instanceof DBSAttributeBase) {
                    for (GeometryDataUtils.GeomAttrs ga : geomAttrs) {
                        if (ga.geomAttr.matches(attr, false)) {
                            GeometryDataUtils.setGeometryProperties(resultSetController, ga, geometry, row);
                            break;
                        }
                    }
                }
                if (geometry.getProperties() == null) {
                    geometry.setProperties(Collections.singletonMap("Object", geometry.getSRID()));
                }
            }
        }
    }
    leafletViewer.setGeometryData(geometries.toArray(new DBGeometry[0]));
}
Also used : GeometryDataUtils(org.jkiss.dbeaver.ui.gis.GeometryDataUtils) ArrayList(java.util.ArrayList) DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase) IResultSetSelection(org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) IResultSetController(org.jkiss.dbeaver.ui.controls.resultset.IResultSetController) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) IDataController(org.jkiss.dbeaver.ui.data.IDataController) DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject)

Example 5 with IResultSetSelection

use of org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection 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

IResultSetSelection (org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection)5 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 ArrayList (java.util.ArrayList)2 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)2 IResultSetController (org.jkiss.dbeaver.ui.controls.resultset.IResultSetController)2 ResultSetRow (org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow)2 BadLocationException (org.eclipse.jface.text.BadLocationException)1 ITextViewer (org.eclipse.jface.text.ITextViewer)1 TextSelection (org.eclipse.jface.text.TextSelection)1 ISelection (org.eclipse.jface.viewers.ISelection)1 DBPObject (org.jkiss.dbeaver.model.DBPObject)1 DBPScriptObject (org.jkiss.dbeaver.model.DBPScriptObject)1 DBDValueHandler (org.jkiss.dbeaver.model.data.DBDValueHandler)1 DBGeometry (org.jkiss.dbeaver.model.gis.DBGeometry)1 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)1 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)1 SQLGeneratorDescriptor (org.jkiss.dbeaver.model.sql.registry.SQLGeneratorDescriptor)1 DBSAttributeBase (org.jkiss.dbeaver.model.struct.DBSAttributeBase)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1