Search in sources :

Example 1 with MockDataGenerateTool

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;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBException(org.jkiss.dbeaver.DBException) DBSDataManipulator(org.jkiss.dbeaver.model.struct.DBSDataManipulator) MockDataGenerateTool(org.jkiss.dbeaver.ext.mockdata.MockDataGenerateTool) IResultSetController(org.jkiss.dbeaver.ui.controls.resultset.IResultSetController) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer)

Aggregations

DBException (org.jkiss.dbeaver.DBException)1 MockDataGenerateTool (org.jkiss.dbeaver.ext.mockdata.MockDataGenerateTool)1 DBSDataContainer (org.jkiss.dbeaver.model.struct.DBSDataContainer)1 DBSDataManipulator (org.jkiss.dbeaver.model.struct.DBSDataManipulator)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1 IResultSetController (org.jkiss.dbeaver.ui.controls.resultset.IResultSetController)1