use of org.jkiss.dbeaver.model.data.DBDDataFilter in project dbeaver by dbeaver.
the class OpenSpreadsheetHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IResultSetController resultSet = ResultSetHandlerMain.getActiveResultSet(HandlerUtil.getActivePart(event));
if (resultSet == null) {
DBWorkbench.getPlatformUI().showError("Open Excel", "No active results viewer");
return null;
}
ResultSetDataContainerOptions options = new ResultSetDataContainerOptions();
IResultSetSelection rsSelection = resultSet.getSelection();
List<ResultSetRow> rsSelectedRows = rsSelection.getSelectedRows();
if (rsSelectedRows.size() > 1) {
List<Long> selectedRows = new ArrayList<>();
for (ResultSetRow selectedRow : rsSelectedRows) {
selectedRows.add((long) selectedRow.getRowNumber());
}
List<String> selectedAttributes = new ArrayList<>();
for (DBDAttributeBinding attributeBinding : rsSelection.getSelectedAttributes()) {
selectedAttributes.add(attributeBinding.getName());
}
options.setSelectedRows(selectedRows);
options.setSelectedColumns(selectedAttributes);
}
ResultSetDataContainer dataContainer = new ResultSetDataContainer(resultSet, options);
if (dataContainer.getDataSource() == null) {
DBWorkbench.getPlatformUI().showError("Open Excel", ModelMessages.error_not_connected_to_database);
return null;
}
AbstractJob exportJob = new AbstractJob("Open Excel") {
{
setUser(true);
setSystem(false);
}
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
File tempDir = DBWorkbench.getPlatform().getTempFolder(monitor, "office-files");
File tempFile = new File(tempDir, CommonUtils.escapeFileName(CommonUtils.truncateString(dataContainer.getName(), 32)) + "." + new SimpleDateFormat("yyyyMMdd-HHmmss").format(System.currentTimeMillis()) + ".xlsx");
tempFile.deleteOnExit();
StreamExporterAbstract exporter = new DataExporterXLSX();
StreamTransferConsumer consumer = new StreamTransferConsumer();
StreamConsumerSettings settings = new StreamConsumerSettings();
settings.setOutputEncodingBOM(false);
settings.setOpenFolderOnFinish(false);
settings.setOutputFolder(tempDir.getAbsolutePath());
settings.setOutputFilePattern(tempFile.getName());
Map<String, Object> properties = DataExporterXLSX.getDefaultProperties();
consumer.initTransfer(dataContainer, settings, new IDataTransferConsumer.TransferParameters(true, false), exporter, properties);
DBDDataFilter dataFilter = resultSet.getModel().getDataFilter();
DatabaseTransferProducer producer = new DatabaseTransferProducer(dataContainer, dataFilter);
DatabaseProducerSettings producerSettings = new DatabaseProducerSettings();
producerSettings.setExtractType(DatabaseProducerSettings.ExtractType.SINGLE_QUERY);
producerSettings.setQueryRowCount(false);
producerSettings.setSelectedRowsOnly(true);
producerSettings.setSelectedColumnsOnly(true);
producer.transferData(monitor, consumer, null, producerSettings, null);
consumer.finishTransfer(monitor, false);
UIUtils.asyncExec(() -> {
if (!UIUtils.launchProgram(tempFile.getAbsolutePath())) {
DBWorkbench.getPlatformUI().showError("Open XLSX", "Can't open XLSX file '" + tempFile.getAbsolutePath() + "'");
}
});
} catch (Exception e) {
DBWorkbench.getPlatformUI().showError("Error opening in Excel", null, e);
}
return Status.OK_STATUS;
}
};
exportJob.schedule();
return null;
}
use of org.jkiss.dbeaver.model.data.DBDDataFilter in project dbeaver by dbeaver.
the class SchedulerJobLogEditor method getEditorDataFilter.
@Override
protected DBDDataFilter getEditorDataFilter() {
OracleSchedulerJob job = getDatabaseObject();
OracleTableBase logView = getJobLogView();
if (logView == null) {
return null;
}
List<DBDAttributeConstraint> constraints = new ArrayList<>();
try {
DBRProgressMonitor monitor = new VoidProgressMonitor();
OracleTableColumn ownerAttr = logView.getAttribute(monitor, "OWNER");
if (ownerAttr != null) {
DBDAttributeConstraint ac = new DBDAttributeConstraint(ownerAttr, ownerAttr.getOrdinalPosition());
ac.setVisible(false);
ac.setOperator(DBCLogicalOperator.EQUALS);
ac.setValue(job.getOwner());
constraints.add(ac);
}
OracleTableColumn jobNameAttr = logView.getAttribute(monitor, "JOB_NAME");
if (jobNameAttr != null) {
DBDAttributeConstraint ac = new DBDAttributeConstraint(jobNameAttr, jobNameAttr.getOrdinalPosition());
ac.setVisible(false);
ac.setOperator(DBCLogicalOperator.EQUALS);
ac.setValue(job.getName());
constraints.add(ac);
}
OracleTableColumn logDateAttr = logView.getAttribute(monitor, "LOG_DATE");
if (logDateAttr != null) {
DBDAttributeConstraint ac = new DBDAttributeConstraint(logDateAttr, logDateAttr.getOrdinalPosition());
ac.setOrderPosition(1);
ac.setOrderDescending(true);
ac.setVisible(true);
constraints.add(ac);
}
} catch (DBException e) {
log.error(e);
}
return new DBDDataFilter(constraints);
}
use of org.jkiss.dbeaver.model.data.DBDDataFilter in project dbeaver by dbeaver.
the class ResultSetFilterPanel method setCustomDataFilter.
private void setCustomDataFilter() {
DBCExecutionContext context = viewer.getExecutionContext();
if (context == null) {
return;
}
String condition = filtersText.getText();
StringBuilder currentCondition = new StringBuilder();
SQLUtils.appendConditionString(viewer.getModel().getDataFilter(), context.getDataSource(), null, currentCondition, true);
if (currentCondition.toString().trim().equals(condition.trim())) {
// The same
return;
}
DBDDataFilter newFilter = new DBDDataFilter(viewer.getModel().getDataFilter());
for (DBDAttributeConstraint ac : newFilter.getConstraints()) {
ac.setCriteria(null);
}
newFilter.setWhere(condition);
viewer.setDataFilter(newFilter, true);
// viewer.getControl().setFocus();
}
use of org.jkiss.dbeaver.model.data.DBDDataFilter in project dbeaver by dbeaver.
the class FilterByAttributeAction method run.
@Override
public void run() {
Object value = type.getValue(resultSetViewer, attribute, operator, false);
if (operator.getArgumentCount() != 0 && value == null) {
return;
}
DBDDataFilter filter = new DBDDataFilter(resultSetViewer.getModel().getDataFilter());
DBDAttributeConstraint constraint = filter.getConstraint(attribute);
if (constraint != null) {
constraint.setOperator(operator);
constraint.setValue(value);
resultSetViewer.setDataFilter(filter, true);
}
}
use of org.jkiss.dbeaver.model.data.DBDDataFilter in project dbeaver by dbeaver.
the class FilterResetAttributeAction method run.
@Override
public void run() {
DBDDataFilter dataFilter = new DBDDataFilter(resultSetViewer.getModel().getDataFilter());
DBDAttributeConstraint constraint = dataFilter.getConstraint(attribute);
if (constraint != null) {
constraint.setCriteria(null);
resultSetViewer.setDataFilter(dataFilter, true);
}
}
Aggregations