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;
}
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()]);
}
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()]);
}
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]));
}
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]);
}
Aggregations