/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
* Copyright (C) 2011-2012 Eugene Fradkin (eugene.fradkin@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.postgresql.tools;
import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
import org.eclipse.jface.fieldassist.TextContentAdapter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.*;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dialogs.DialogUtils;
import org.jkiss.utils.CommonUtils;
import java.io.File;
class PostgreBackupWizardPageSettings extends PostgreWizardPageSettings<PostgreBackupWizard>
{
private Text outputFolderText;
private Text outputFileText;
private Combo formatCombo;
private Combo compressCombo;
private Combo encodingCombo;
protected PostgreBackupWizardPageSettings(PostgreBackupWizard wizard)
{
super(wizard, "Settings");
setTitle("Backup settings");
setDescription("Database backup settings");
}
@Override
public boolean isPageComplete()
{
return super.isPageComplete() && wizard.getOutputFolder() != null;
}
@Override
public void createControl(Composite parent)
{
Composite composite = UIUtils.createPlaceholder(parent, 1);
SelectionListener changeListener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateState();
}
};
Group formatGroup = UIUtils.createControlGroup(composite, "Settings", 2, GridData.FILL_HORIZONTAL, 0);
formatCombo = UIUtils.createLabelCombo(formatGroup, "Format", SWT.DROP_DOWN | SWT.READ_ONLY);
formatCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
for (PostgreBackupWizard.ExportFormat format : PostgreBackupWizard.ExportFormat.values()) {
formatCombo.add(format.getTitle());
}
formatCombo.select(wizard.format.ordinal());
formatCombo.addSelectionListener(changeListener);
compressCombo = UIUtils.createLabelCombo(formatGroup, "Compression", SWT.DROP_DOWN | SWT.READ_ONLY);
compressCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
compressCombo.add("");
for (int i = 0; i <= 9; i++) {
compressCombo.add(String.valueOf(i));
}
compressCombo.select(0);
compressCombo.addSelectionListener(changeListener);
UIUtils.createControlLabel(formatGroup, "Encoding");
encodingCombo = UIUtils.createEncodingCombo(formatGroup, null);
encodingCombo.addSelectionListener(changeListener);
Group outputGroup = UIUtils.createControlGroup(composite, "Output", 2, GridData.FILL_HORIZONTAL, 0);
outputFolderText = DialogUtils.createOutputFolderChooser(outputGroup, "Output folder", new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateState();
}
});
outputFileText = UIUtils.createLabelText(outputGroup, "File name pattern", wizard.getOutputFilePattern());
UIUtils.setContentProposalToolTip(outputFileText, "Output file name pattern", "host", "database", "table", "timestamp");
UIUtils.installContentProposal(
outputFileText,
new TextContentAdapter(),
new SimpleContentProposalProvider(new String[]{"${host}", "${database}", "${table}", "${timestamp}"}));
outputFileText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
wizard.setOutputFilePattern(outputFileText.getText());
}
});
if (wizard.getOutputFolder() != null) {
outputFolderText.setText(wizard.getOutputFolder().getAbsolutePath());
}
createSecurityGroup(composite);
setControl(composite);
}
private void updateState()
{
String fileName = outputFolderText.getText();
wizard.setOutputFolder(CommonUtils.isEmpty(fileName) ? null : new File(fileName));
wizard.setOutputFilePattern(outputFileText.getText());
wizard.format = PostgreBackupWizard.ExportFormat.values()[formatCombo.getSelectionIndex()];
wizard.compression = compressCombo.getText();
wizard.encoding = encodingCombo.getText();
getContainer().updateButtons();
}
}