use of org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings in project dbeaver by dbeaver.
the class StreamPOIConsumerPageSettings method createControl.
@Override
public void createControl(Composite parent) {
initializeDialogUnits(parent);
final StreamConsumerSettings settings = getWizard().getPageSettings(this, StreamConsumerSettings.class);
Composite composite = new Composite(parent, SWT.NULL);
GridLayout gl = new GridLayout();
gl.marginHeight = 0;
gl.marginWidth = 0;
composite.setLayout(gl);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
{
Group generalSettings = new Group(composite, SWT.NONE);
generalSettings.setText(CoreMessages.data_transfer_wizard_settings_group_general);
gl = new GridLayout(4, false);
generalSettings.setLayout(gl);
generalSettings.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
{
Composite formattingGroup = UIUtils.createPlaceholder(generalSettings, 3);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 4;
formattingGroup.setLayoutData(gd);
UIUtils.createControlLabel(formattingGroup, CoreMessages.data_transfer_wizard_settings_label_formatting);
formatProfilesCombo = new Combo(formattingGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.widthHint = 200;
formatProfilesCombo.setLayoutData(gd);
formatProfilesCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (formatProfilesCombo.getSelectionIndex() > 0) {
settings.setFormatterProfile(DataFormatterRegistry.getInstance().getCustomProfile(UIUtils.getComboSelection(formatProfilesCombo)));
} else {
settings.setFormatterProfile(null);
}
}
});
Button profilesManageButton = new Button(formattingGroup, SWT.PUSH);
profilesManageButton.setText(CoreMessages.data_transfer_wizard_settings_button_edit);
profilesManageButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
PreferenceDialog propDialog = PreferencesUtil.createPropertyDialogOn(getShell(), DataFormatterRegistry.getInstance(), PrefPageDataFormat.PAGE_ID, null, getSelectedFormatterProfile(), PreferencesUtil.OPTION_NONE);
if (propDialog != null) {
propDialog.open();
reloadFormatProfiles();
}
}
});
reloadFormatProfiles();
}
}
Group exporterSettings = new Group(composite, SWT.NONE);
exporterSettings.setText(CoreMessages.data_transfer_wizard_settings_group_exporter);
exporterSettings.setLayoutData(new GridData(GridData.FILL_BOTH));
exporterSettings.setLayout(new GridLayout(1, false));
propsEditor = new PropertyTreeViewer(exporterSettings, SWT.BORDER);
setControl(composite);
}
use of org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings in project dbeaver by dbeaver.
the class StreamPOIConsumerPageSettings method reloadFormatProfiles.
private void reloadFormatProfiles() {
DataFormatterRegistry registry = DataFormatterRegistry.getInstance();
formatProfilesCombo.removeAll();
formatProfilesCombo.add(CoreMessages.data_transfer_wizard_settings_listbox_formatting_item_default);
for (DBDDataFormatterProfile profile : registry.getCustomProfiles()) {
formatProfilesCombo.add(profile.getProfileName());
}
final StreamConsumerSettings settings = getWizard().getPageSettings(this, StreamConsumerSettings.class);
DBDDataFormatterProfile formatterProfile = settings.getFormatterProfile();
if (formatterProfile != null) {
if (!UIUtils.setComboSelection(formatProfilesCombo, formatterProfile.getProfileName())) {
formatProfilesCombo.select(0);
}
} else {
formatProfilesCombo.select(0);
}
}
use of org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings in project dbeaver by dbeaver.
the class StreamPOIConsumerPageSettings method activatePage.
@Override
public void activatePage() {
final StreamConsumerSettings settings = getWizard().getPageSettings(this, StreamConsumerSettings.class);
DataTransferProcessorDescriptor processor = getWizard().getSettings().getProcessor();
propertySource = new PropertySourceCustom(processor.getProperties(), getWizard().getSettings().getProcessorProperties());
propsEditor.loadProperties(propertySource);
updatePageCompletion();
}
use of org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings in project dbeaver by serge-rider.
the class StreamConsumerPageSettings method createControl.
@Override
public void createControl(Composite parent) {
DBPDataFormatterRegistry dataFormatterRegistry = DBWorkbench.getPlatform().getDataFormatterRegistry();
initializeDialogUnits(parent);
final StreamConsumerSettings settings = getWizard().getPageSettings(this, StreamConsumerSettings.class);
Composite composite = UIUtils.createComposite(parent, 1);
{
Composite generalSettings = UIUtils.createControlGroup(composite, DTMessages.data_transfer_wizard_settings_group_general, 5, GridData.FILL_HORIZONTAL, 0);
((GridLayout) generalSettings.getLayout()).verticalSpacing = 0;
((GridLayout) generalSettings.getLayout()).marginHeight = 0;
((GridLayout) generalSettings.getLayout()).marginWidth = 0;
{
formatProfilesCombo = UIUtils.createLabelCombo(generalSettings, DTMessages.data_transfer_wizard_settings_label_formatting, SWT.DROP_DOWN | SWT.READ_ONLY);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 3;
formatProfilesCombo.setLayoutData(gd);
formatProfilesCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (formatProfilesCombo.getSelectionIndex() > 0) {
settings.setFormatterProfile(dataFormatterRegistry.getCustomProfile(UIUtils.getComboSelection(formatProfilesCombo)));
} else {
settings.setFormatterProfile(null);
}
}
});
UIUtils.createDialogButton(generalSettings, DTMessages.data_transfer_wizard_settings_button_edit, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
PreferenceDialog propDialog = PreferencesUtil.createPropertyDialogOn(getShell(), dataFormatterRegistry, // TODO: replace this hardcode with some model invocation
"org.jkiss.dbeaver.preferences.main.dataformat", null, getSelectedFormatterProfile(), PreferencesUtil.OPTION_NONE);
if (propDialog != null) {
propDialog.open();
reloadFormatProfiles();
}
}
});
reloadFormatProfiles();
UIUtils.createControlLabel(generalSettings, DTMessages.data_transfer_wizard_settings_label_binaries);
Composite binariesPanel = UIUtils.createComposite(generalSettings, 4);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 4;
binariesPanel.setLayoutData(gd);
lobExtractType = new Combo(binariesPanel, SWT.DROP_DOWN | SWT.READ_ONLY);
lobExtractType.setItems(DTMessages.data_transfer_wizard_settings_binaries_item_set_to_null, DTMessages.data_transfer_wizard_settings_binaries_item_save_to_file, DTMessages.data_transfer_wizard_settings_binaries_item_inline);
lobExtractType.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
switch(lobExtractType.getSelectionIndex()) {
case EXTRACT_LOB_SKIP:
settings.setLobExtractType(StreamConsumerSettings.LobExtractType.SKIP);
break;
case EXTRACT_LOB_FILES:
settings.setLobExtractType(StreamConsumerSettings.LobExtractType.FILES);
break;
case EXTRACT_LOB_INLINE:
settings.setLobExtractType(StreamConsumerSettings.LobExtractType.INLINE);
break;
}
updatePageCompletion();
}
});
lobEncodingLabel = UIUtils.createControlLabel(binariesPanel, DTMessages.data_transfer_wizard_settings_label_encoding);
lobEncodingCombo = new Combo(binariesPanel, SWT.DROP_DOWN | SWT.READ_ONLY);
lobEncodingCombo.setItems(// $NON-NLS-1$
"Base64", // $NON-NLS-1$
"Hex", // $NON-NLS-1$
"Binary", // $NON-NLS-1$
"Native");
lobEncodingCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
switch(lobEncodingCombo.getSelectionIndex()) {
case LOB_ENCODING_BASE64:
settings.setLobEncoding(StreamConsumerSettings.LobEncoding.BASE64);
break;
case LOB_ENCODING_HEX:
settings.setLobEncoding(StreamConsumerSettings.LobEncoding.HEX);
break;
case LOB_ENCODING_BINARY:
settings.setLobEncoding(StreamConsumerSettings.LobEncoding.BINARY);
break;
case LOB_ENCODING_NATIVE:
settings.setLobEncoding(StreamConsumerSettings.LobEncoding.NATIVE);
break;
}
}
});
}
}
{
Composite exporterSettings = UIUtils.createControlGroup(composite, DTMessages.data_transfer_wizard_settings_group_exporter, 1, GridData.FILL_BOTH, 0);
propsEditor = new PropertyTreeViewer(exporterSettings, SWT.BORDER);
}
setControl(composite);
}
use of org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings in project dbeaver by serge-rider.
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;
}
Aggregations