use of org.jkiss.dbeaver.ext.mockdata.MockDataGenerateTool in project dbeaver by dbeaver.
the class MockDataHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
List<DBSObject> selectedObjects;
if (event.getCommand().getId().endsWith("button")) {
IResultSetController resultSet = ResultSetCommandHandler.getActiveResultSet(HandlerUtil.getActivePart(event));
if (resultSet == null) {
DBeaverUI.getInstance().showError("Mock Data", "No active results viewer");
return null;
}
DBSDataContainer dataContainer = resultSet.getDataContainer();
if (dataContainer == null || dataContainer.getDataSource() == null) {
DBeaverUI.getInstance().showError("Mock Data", "Not connected to a database");
return null;
}
if (!(dataContainer instanceof DBSDataManipulator)) {
DBeaverUI.getInstance().showError("Mock Data", "Mock Data can be generated for a table only");
return null;
}
selectedObjects = new ArrayList<>();
selectedObjects.add(dataContainer);
} else {
selectedObjects = NavigatorUtils.getSelectedObjects(HandlerUtil.getCurrentSelection(event));
}
MockDataGenerateTool mockDataGenerator = new MockDataGenerateTool();
try {
mockDataGenerator.execute(HandlerUtil.getActiveWorkbenchWindow(event), null, selectedObjects);
} catch (DBException e) {
log.error("Error launching the Mock Data Generator", e);
}
return null;
}
Aggregations