use of org.pentaho.di.ui.core.dialog.EnterTextDialog in project pentaho-kettle by pentaho.
the class GetXMLDataDialog method getLoopPathList.
private void getLoopPathList() {
try {
GetXMLDataMeta meta = new GetXMLDataMeta();
getInfo(meta);
if (meta.isInFields()) {
if (meta.isReadUrl()) {
// Read URL
String url = XMLSource;
if (url == null) {
EnterStringDialog d = new EnterStringDialog(shell, "", BaseMessages.getString(PKG, "GetXMLDataDialog.AskURL.Title"), BaseMessages.getString(PKG, "GetXMLDataDialog.AskURL.Message"));
url = d.open();
}
populateLoopPaths(meta, url, true, true);
} else if (meta.getIsAFile()) {
// Read file
String str = XMLSource;
if (str == null) {
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
dialog.setFilterExtensions(new String[] { "*.xml;*.XML", "*" });
dialog.setFilterNames(new String[] { BaseMessages.getString(PKG, "System.FileType.XMLFiles"), BaseMessages.getString(PKG, "System.FileType.AllFiles") });
if (dialog.open() != null) {
str = dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName();
}
populateLoopPaths(meta, str, false, false);
}
} else {
// Read xml
String xml = XMLSource;
if (xml == null) {
EnterTextDialog d = new EnterTextDialog(shell, BaseMessages.getString(PKG, "GetXMLDataDialog.AskXML.Title"), BaseMessages.getString(PKG, "GetXMLDataDialog.AskXML.Message"), null);
xml = d.open();
}
populateLoopPaths(meta, xml, true, false);
}
} else {
FileInputList fileinputList = meta.getFiles(transMeta);
if (fileinputList.nrOfFiles() > 0) {
if (fileinputList.getFile(0).exists()) {
populateLoopPaths(meta, KettleVFS.getFilename(fileinputList.getFile(0)), false, false);
} else {
// The file not exists !
throw new KettleException(BaseMessages.getString(PKG, "GetXMLDataDialog.Exception.FileDoesNotExist", KettleVFS.getFilename(fileinputList.getFile(0))));
}
} else {
// No file specified
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "GetXMLDataDialog.FilesMissing.DialogMessage"));
mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
mb.open();
}
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "GetXMLDataDialog.UnableToGetListOfPaths.Title"), BaseMessages.getString(PKG, "GetXMLDataDialog.UnableToGetListOfPaths.Message"), e);
}
}
use of org.pentaho.di.ui.core.dialog.EnterTextDialog in project pentaho-kettle by pentaho.
the class XMLInputStreamDialog method preview.
// Preview the data
private void preview() {
// execute a complete preview transformation in the background.
// This is how we do it...
//
XMLInputStreamMeta oneMeta = new XMLInputStreamMeta();
getInfo(oneMeta);
TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "XMLInputStreamDialog.Dialog.EnterPreviewSize.Title"), BaseMessages.getString(PKG, "XMLInputStreamDialog.Dialog.EnterPreviewSize.Message"));
int previewSize = numberDialog.open();
if (previewSize > 0) {
TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
progressDialog.open();
Trans trans = progressDialog.getTrans();
String loggingText = progressDialog.getLoggingText();
if (!progressDialog.isCancelled()) {
if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
etd.setReadOnly();
etd.open();
}
}
PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText);
prd.open();
}
}
use of org.pentaho.di.ui.core.dialog.EnterTextDialog in project pentaho-kettle by pentaho.
the class Translator2 method saveFiles.
protected boolean saveFiles() {
java.util.List<MessagesStore> changedMessagesStores = store.getChangedMessagesStores();
if (changedMessagesStores.size() > 0) {
StringBuilder msg = new StringBuilder();
for (MessagesStore messagesStore : changedMessagesStores) {
String filename = messagesStore.getSaveFilename(messagesStore.getSourceFolder());
messagesStore.setFilename(filename);
msg.append(messagesStore.getFilename());
if (!new File(filename).exists()) {
msg.append(" (NEW!)");
}
msg.append(Const.CR);
}
EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "i18nDialog.ChangedFiles"), BaseMessages.getString(PKG, "i18nDialog.ChangedMessagesFiles"), msg.toString());
if (dialog.open() != null) {
try {
for (MessagesStore messagesStore : changedMessagesStores) {
messagesStore.write();
log.logBasic(BaseMessages.getString(PKG, "i18n.Log.SavedMessagesFile", messagesStore.getFilename()));
}
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "i18n.UnexpectedError"), "There was an error saving the changed messages files:", e);
return false;
}
return true;
} else {
return false;
}
} else {
// TODO: disable the button if nothing changed.
return true;
}
}
use of org.pentaho.di.ui.core.dialog.EnterTextDialog in project pentaho-kettle by pentaho.
the class SalesforceInputDialog method preview.
// Preview the data
private void preview() {
try {
SalesforceInputMeta oneMeta = new SalesforceInputMeta();
getInfo(oneMeta);
// check if the path is given
TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "SalesforceInputDialog.NumberRows.DialogTitle"), BaseMessages.getString(PKG, "SalesforceInputDialog.NumberRows.DialogMessage"));
int previewSize = numberDialog.open();
if (previewSize > 0) {
TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
progressDialog.open();
if (!progressDialog.isCancelled()) {
Trans trans = progressDialog.getTrans();
String loggingText = progressDialog.getLoggingText();
if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
etd.setReadOnly();
etd.open();
}
PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText);
prd.open();
}
}
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInputDialog.ErrorPreviewingData.DialogTitle"), BaseMessages.getString(PKG, "SalesforceInputDialog.ErrorPreviewingData.DialogMessage"), e);
}
}
use of org.pentaho.di.ui.core.dialog.EnterTextDialog in project pentaho-kettle by pentaho.
the class S3CsvInputDialog method getCSV.
// Get the data layout
private void getCSV() {
InputStream inputStream = null;
try {
S3CsvInputMeta meta = new S3CsvInputMeta();
getInfo(meta);
String filename = transMeta.environmentSubstitute(meta.getFilename());
String bucketname = transMeta.environmentSubstitute(meta.getBucket());
int maxLineSize = Const.toInt(transMeta.environmentSubstitute(meta.getMaxLineSize()), 2000);
wFields.table.removeAll();
S3ObjectsProvider s3ObjProvider = new S3ObjectsProvider(meta.getS3Service(transMeta));
S3Bucket s3bucket = s3ObjProvider.getBucket(bucketname);
if (s3bucket == null) {
throw new Exception(Messages.getString("S3DefaultService.Exception.UnableToFindBucket.Message", bucketname));
}
// Now we can continue reading the rows of data and we can guess the
// Sample a few lines to determine the correct type of the fields...
//
String shellText = Messages.getString("S3CsvInputDialog.LinesToSample.DialogTitle");
String lineText = Messages.getString("S3CsvInputDialog.LinesToSample.DialogMessage");
EnterNumberDialog end = new EnterNumberDialog(shell, 100, shellText, lineText);
int samples = end.open();
if (samples < 0) {
return;
}
// Only get the first lines, not the complete file
// And grab an input stream to the data...
inputStream = s3ObjProvider.getS3Object(s3bucket, filename, 0L, (long) samples * (long) maxLineSize).getDataInputStream();
InputStreamReader reader = new InputStreamReader(inputStream);
// Read a line of data to determine the number of rows...
//
String line = TextFileInput.getLine(log, reader, TextFileInputMeta.FILE_FORMAT_MIXED, new StringBuilder(1000));
// Split the string, header or data into parts...
//
String[] fieldNames = Const.splitString(line, meta.getDelimiter());
if (!meta.isHeaderPresent()) {
// Don't use field names from the header...
// Generate field names F1 ... F10
//
// $NON-NLS-1$
DecimalFormat df = new DecimalFormat("000");
for (int i = 0; i < fieldNames.length; i++) {
// $NON-NLS-1$
fieldNames[i] = "Field_" + df.format(i);
}
} else {
if (!Utils.isEmpty(meta.getEnclosure())) {
for (int i = 0; i < fieldNames.length; i++) {
if (fieldNames[i].startsWith(meta.getEnclosure()) && fieldNames[i].endsWith(meta.getEnclosure()) && fieldNames[i].length() > 1) {
fieldNames[i] = fieldNames[i].substring(1, fieldNames[i].length() - 1);
}
}
}
}
//
for (int i = 0; i < fieldNames.length; i++) {
fieldNames[i] = Const.trim(fieldNames[i]);
}
//
for (int i = 0; i < fieldNames.length; i++) {
TableItem item = new TableItem(wFields.table, SWT.NONE);
item.setText(1, fieldNames[i]);
item.setText(2, ValueMeta.getTypeDesc(ValueMetaInterface.TYPE_STRING));
}
wFields.removeEmptyRows();
wFields.setRowNums();
wFields.optWidth(true);
getInfo(meta);
TextFileCSVImportProgressDialog pd = new TextFileCSVImportProgressDialog(shell, meta, transMeta, reader, samples, true);
String message = pd.open();
if (message != null) {
wFields.removeAll();
// OK, what's the result of our search?
getData(meta);
wFields.removeEmptyRows();
wFields.setRowNums();
wFields.optWidth(true);
EnterTextDialog etd = new EnterTextDialog(shell, Messages.getString("S3CsvInputDialog.ScanResults.DialogTitle"), Messages.getString("S3CsvInputDialog.ScanResults.DialogMessage"), message, true);
etd.setReadOnly();
etd.open();
}
} catch (IOException e) {
new ErrorDialog(shell, Messages.getString("S3CsvInputDialog.IOError.DialogTitle"), Messages.getString("S3CsvInputDialog.IOError.DialogMessage"), e);
} catch (Exception e) {
new ErrorDialog(shell, Messages.getString("System.Dialog.Error.Title"), Messages.getString("S3CsvInputDialog.ErrorGettingFileDesc.DialogMessage"), e);
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (Exception e) {
log.logError(stepname, "Error closing s3 data input stream", e);
}
}
}
Aggregations