List of usage examples for org.apache.commons.vfs2 FileObject getName
FileName getName();
From source file:org.pentaho.di.ui.job.entries.trans.JobEntryBaseDialog.java
protected void selectLogFile(String[] filters) { FileDialog dialog = new FileDialog(shell, SWT.SAVE); dialog.setFilterExtensions(new String[] { "*.txt", "*.log", "*" }); dialog.setFilterNames(filters);/*w ww. j a v a 2 s . c om*/ if (wLogfile.getText() != null) { dialog.setFileName(jobMeta.environmentSubstitute(wLogfile.getText())); } if (dialog.open() != null) { wLogfile.setText(dialog.getFilterPath() + Const.FILE_SEPARATOR + dialog.getFileName()); String filename = dialog.getFilterPath() + Const.FILE_SEPARATOR + dialog.getFileName(); FileObject file = null; try { file = KettleVFS.getFileObject(filename); // Set file extension .. wLogext.setText(file.getName().getExtension()); // Set filename without extension ... wLogfile.setText(wLogfile.getText().substring(0, wLogfile.getText().length() - wLogext.getText().length() - 1)); } catch (Exception ex) { // Ignore } if (file != null) { try { file.close(); } catch (IOException ex) { /* Ignore */ } } } }
From source file:org.pentaho.di.ui.trans.step.BaseStreamingDialog.java
protected Optional<String> selectFile(TextVar fileWidget, String[] fileFilters) { String curFile = transMeta.environmentSubstitute(fileWidget.getText()); FileObject root = null;/*w w w . jav a 2 s . c om*/ try { root = KettleVFS.getFileObject(curFile != null ? curFile : Const.getUserHomeDirectory()); VfsFileChooserDialog vfsFileChooser = Spoon.getInstance().getVfsFileChooserDialog(root.getParent(), root); FileObject file = vfsFileChooser.open(shell, null, fileFilters, Const.getTransformationFilterNames(), VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE); if (file == null) { return Optional.empty(); } String filePath = getRelativePath(file.getName().toString()); fileWidget.setText(filePath); return Optional.ofNullable(filePath); } catch (IOException | KettleException e) { new ErrorDialog(shell, BaseMessages.getString(PKG, "TransExecutorDialog.ErrorLoadingTransformation.DialogTitle"), BaseMessages.getString(PKG, "TransExecutorDialog.ErrorLoadingTransformation.DialogMessage"), e); } return Optional.empty(); }
From source file:org.pentaho.di.ui.trans.steps.fileinput.text.TextFileInputDialog.java
private List<String> getFirst(int nrlines, boolean skipHeaders) throws KettleException { TextFileInputMeta meta = new TextFileInputMeta(); getInfo(meta, true);// ww w. j ava2 s . c om FileInputList textFileList = meta.getFileInputList(transMeta); InputStream fi; CompressionInputStream f = null; StringBuilder lineStringBuilder = new StringBuilder(256); int fileFormatType = meta.getFileFormatTypeNr(); List<String> retval = new ArrayList<>(); if (textFileList.nrOfFiles() > 0) { FileObject file = textFileList.getFile(0); try { fi = KettleVFS.getInputStream(file); CompressionProvider provider = CompressionProviderFactory.getInstance() .createCompressionProviderInstance(meta.content.fileCompression); f = provider.createInputStream(fi); InputStreamReader reader; if (meta.getEncoding() != null && meta.getEncoding().length() > 0) { reader = new InputStreamReader(f, meta.getEncoding()); } else { reader = new InputStreamReader(f); } EncodingType encodingType = EncodingType.guessEncodingType(reader.getEncoding()); int linenr = 0; int maxnr = nrlines + (meta.content.header ? meta.content.nrHeaderLines : 0); if (skipHeaders) { // Skip the header lines first if more then one, it helps us position if (meta.content.layoutPaged && meta.content.nrLinesDocHeader > 0) { int skipped = 0; String line = TextFileInputUtils.getLine(log, reader, encodingType, fileFormatType, lineStringBuilder); while (line != null && skipped < meta.content.nrLinesDocHeader - 1) { skipped++; line = TextFileInputUtils.getLine(log, reader, encodingType, fileFormatType, lineStringBuilder); } } // Skip the header lines first if more then one, it helps us position if (meta.content.header && meta.content.nrHeaderLines > 0) { int skipped = 0; String line = TextFileInputUtils.getLine(log, reader, encodingType, fileFormatType, lineStringBuilder); while (line != null && skipped < meta.content.nrHeaderLines - 1) { skipped++; line = TextFileInputUtils.getLine(log, reader, encodingType, fileFormatType, lineStringBuilder); } } } String line = TextFileInputUtils.getLine(log, reader, encodingType, fileFormatType, lineStringBuilder); while (line != null && (linenr < maxnr || nrlines == 0)) { retval.add(line); linenr++; line = TextFileInputUtils.getLine(log, reader, encodingType, fileFormatType, lineStringBuilder); } } catch (Exception e) { throw new KettleException( BaseMessages.getString(PKG, "TextFileInputDialog.Exception.ErrorGettingFirstLines", "" + nrlines, file.getName().getURI()), e); } finally { try { if (f != null) { f.close(); } } catch (Exception e) { // Ignore errors } } } return retval; }
From source file:org.pentaho.di.ui.trans.steps.textfileoutput.TextFileOutputDialog.java
public String open() { Shell parent = getParent();/*from ww w .ja va 2 s .com*/ Display display = parent.getDisplay(); shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN); props.setLook(shell); setShellImage(shell, input); ModifyListener lsMod = new ModifyListener() { public void modifyText(ModifyEvent e) { input.setChanged(); } }; changed = input.hasChanged(); FormLayout formLayout = new FormLayout(); formLayout.marginWidth = Const.FORM_MARGIN; formLayout.marginHeight = Const.FORM_MARGIN; shell.setLayout(formLayout); shell.setText(getDialogTitle()); int middle = props.getMiddlePct(); int margin = Const.MARGIN; // Stepname line wlStepname = new Label(shell, SWT.RIGHT); wlStepname.setText(BaseMessages.getString(PKG, "System.Label.StepName")); props.setLook(wlStepname); fdlStepname = new FormData(); fdlStepname.left = new FormAttachment(0, 0); fdlStepname.top = new FormAttachment(0, margin); fdlStepname.right = new FormAttachment(middle, -margin); wlStepname.setLayoutData(fdlStepname); wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); wStepname.setText(stepname); props.setLook(wStepname); wStepname.addModifyListener(lsMod); fdStepname = new FormData(); fdStepname.left = new FormAttachment(middle, 0); fdStepname.top = new FormAttachment(0, margin); fdStepname.right = new FormAttachment(100, 0); wStepname.setLayoutData(fdStepname); wTabFolder = new CTabFolder(shell, SWT.BORDER); props.setLook(wTabFolder, Props.WIDGET_STYLE_TAB); wTabFolder.setSimple(false); // //////////////////////// // START OF FILE TAB/// // / wFileTab = new CTabItem(wTabFolder, SWT.NONE); wFileTab.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.FileTab.TabTitle")); Composite wFileComp = new Composite(wTabFolder, SWT.NONE); props.setLook(wFileComp); FormLayout fileLayout = new FormLayout(); fileLayout.marginWidth = 3; fileLayout.marginHeight = 3; wFileComp.setLayout(fileLayout); // Filename line wlFilename = new Label(wFileComp, SWT.RIGHT); wlFilename.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.Filename.Label")); props.setLook(wlFilename); fdlFilename = new FormData(); fdlFilename.left = new FormAttachment(0, 0); fdlFilename.top = new FormAttachment(0, margin); fdlFilename.right = new FormAttachment(middle, -margin); wlFilename.setLayoutData(fdlFilename); wbFilename = new Button(wFileComp, SWT.PUSH | SWT.CENTER); props.setLook(wbFilename); wbFilename.setText(BaseMessages.getString(PKG, "System.Button.Browse")); fdbFilename = new FormData(); fdbFilename.right = new FormAttachment(100, 0); fdbFilename.top = new FormAttachment(0, 0); wbFilename.setLayoutData(fdbFilename); wFilename = new TextVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wFilename); wFilename.addModifyListener(lsMod); fdFilename = new FormData(); fdFilename.left = new FormAttachment(middle, 0); fdFilename.top = new FormAttachment(0, margin); fdFilename.right = new FormAttachment(wbFilename, -margin); wFilename.setLayoutData(fdFilename); Control topControl = addAdditionalComponentIfNeed(middle, margin, wFileComp, wFilename); // Output to servlet (browser, ws) // wlServletOutput = new Label(wFileComp, SWT.RIGHT); wlServletOutput.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.ServletOutput.Label")); props.setLook(wlServletOutput); fdlServletOutput = new FormData(); fdlServletOutput.left = new FormAttachment(0, 0); fdlServletOutput.top = new FormAttachment(topControl, margin); fdlServletOutput.right = new FormAttachment(middle, -margin); wlServletOutput.setLayoutData(fdlServletOutput); wServletOutput = new Button(wFileComp, SWT.CHECK); wServletOutput.setToolTipText(BaseMessages.getString(PKG, "TextFileOutputDialog.ServletOutput.Tooltip")); props.setLook(wServletOutput); fdServletOutput = new FormData(); fdServletOutput.left = new FormAttachment(middle, 0); fdServletOutput.top = new FormAttachment(topControl, margin); fdServletOutput.right = new FormAttachment(100, 0); wServletOutput.setLayoutData(fdServletOutput); wServletOutput.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); setFlagsServletOption(); } }); // Create Parent Folder wlCreateParentFolder = new Label(wFileComp, SWT.RIGHT); wlCreateParentFolder.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.CreateParentFolder.Label")); props.setLook(wlCreateParentFolder); fdlCreateParentFolder = new FormData(); fdlCreateParentFolder.left = new FormAttachment(0, 0); fdlCreateParentFolder.top = new FormAttachment(wServletOutput, margin); fdlCreateParentFolder.right = new FormAttachment(middle, -margin); wlCreateParentFolder.setLayoutData(fdlCreateParentFolder); wCreateParentFolder = new Button(wFileComp, SWT.CHECK); wCreateParentFolder .setToolTipText(BaseMessages.getString(PKG, "TextFileOutputDialog.CreateParentFolder.Tooltip")); props.setLook(wCreateParentFolder); fdCreateParentFolder = new FormData(); fdCreateParentFolder.left = new FormAttachment(middle, 0); fdCreateParentFolder.top = new FormAttachment(wServletOutput, margin); fdCreateParentFolder.right = new FormAttachment(100, 0); wCreateParentFolder.setLayoutData(fdCreateParentFolder); wCreateParentFolder.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); // Open new File at Init wlDoNotOpenNewFileInit = new Label(wFileComp, SWT.RIGHT); wlDoNotOpenNewFileInit .setText(BaseMessages.getString(PKG, "TextFileOutputDialog.DoNotOpenNewFileInit.Label")); props.setLook(wlDoNotOpenNewFileInit); fdlDoNotOpenNewFileInit = new FormData(); fdlDoNotOpenNewFileInit.left = new FormAttachment(0, 0); fdlDoNotOpenNewFileInit.top = new FormAttachment(wCreateParentFolder, margin); fdlDoNotOpenNewFileInit.right = new FormAttachment(middle, -margin); wlDoNotOpenNewFileInit.setLayoutData(fdlDoNotOpenNewFileInit); wDoNotOpenNewFileInit = new Button(wFileComp, SWT.CHECK); wDoNotOpenNewFileInit .setToolTipText(BaseMessages.getString(PKG, "TextFileOutputDialog.DoNotOpenNewFileInit.Tooltip")); props.setLook(wDoNotOpenNewFileInit); fdDoNotOpenNewFileInit = new FormData(); fdDoNotOpenNewFileInit.left = new FormAttachment(middle, 0); fdDoNotOpenNewFileInit.top = new FormAttachment(wCreateParentFolder, margin); fdDoNotOpenNewFileInit.right = new FormAttachment(100, 0); wDoNotOpenNewFileInit.setLayoutData(fdDoNotOpenNewFileInit); wDoNotOpenNewFileInit.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); /* next Lines */ // FileNameInField line wlFileNameInField = new Label(wFileComp, SWT.RIGHT); wlFileNameInField.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.FileNameInField.Label")); props.setLook(wlFileNameInField); fdlFileNameInField = new FormData(); fdlFileNameInField.left = new FormAttachment(0, 0); fdlFileNameInField.top = new FormAttachment(wDoNotOpenNewFileInit, margin); fdlFileNameInField.right = new FormAttachment(middle, -margin); wlFileNameInField.setLayoutData(fdlFileNameInField); wFileNameInField = new Button(wFileComp, SWT.CHECK); props.setLook(wFileNameInField); fdFileNameInField = new FormData(); fdFileNameInField.left = new FormAttachment(middle, 0); fdFileNameInField.top = new FormAttachment(wDoNotOpenNewFileInit, margin); fdFileNameInField.right = new FormAttachment(100, 0); wFileNameInField.setLayoutData(fdFileNameInField); wFileNameInField.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); activeFileNameField(); } }); // FileNameField Line wlFileNameField = new Label(wFileComp, SWT.RIGHT); wlFileNameField.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.FileNameField.Label")); props.setLook(wlFileNameField); fdlFileNameField = new FormData(); fdlFileNameField.left = new FormAttachment(0, 0); fdlFileNameField.right = new FormAttachment(middle, -margin); fdlFileNameField.top = new FormAttachment(wFileNameInField, margin); wlFileNameField.setLayoutData(fdlFileNameField); wFileNameField = new ComboVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wFileNameField); wFileNameField.addModifyListener(lsMod); fdFileNameField = new FormData(); fdFileNameField.left = new FormAttachment(middle, 0); fdFileNameField.top = new FormAttachment(wFileNameInField, margin); fdFileNameField.right = new FormAttachment(100, 0); wFileNameField.setLayoutData(fdFileNameField); wFileNameField.setEnabled(false); wFileNameField.addFocusListener(new FocusListener() { public void focusLost(org.eclipse.swt.events.FocusEvent e) { } public void focusGained(org.eclipse.swt.events.FocusEvent e) { Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT); shell.setCursor(busy); getFields(); shell.setCursor(null); busy.dispose(); } }); /* End */ // Extension line wlExtension = new Label(wFileComp, SWT.RIGHT); wlExtension.setText(BaseMessages.getString(PKG, "System.Label.Extension")); props.setLook(wlExtension); fdlExtension = new FormData(); fdlExtension.left = new FormAttachment(0, 0); fdlExtension.top = new FormAttachment(wFileNameField, margin); fdlExtension.right = new FormAttachment(middle, -margin); wlExtension.setLayoutData(fdlExtension); wExtension = new TextVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); wExtension.setText(""); props.setLook(wExtension); wExtension.addModifyListener(lsMod); fdExtension = new FormData(); fdExtension.left = new FormAttachment(middle, 0); fdExtension.top = new FormAttachment(wFileNameField, margin); fdExtension.right = new FormAttachment(100, 0); wExtension.setLayoutData(fdExtension); // Create multi-part file? wlAddStepnr = new Label(wFileComp, SWT.RIGHT); wlAddStepnr.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.AddStepnr.Label")); props.setLook(wlAddStepnr); fdlAddStepnr = new FormData(); fdlAddStepnr.left = new FormAttachment(0, 0); fdlAddStepnr.top = new FormAttachment(wExtension, margin); fdlAddStepnr.right = new FormAttachment(middle, -margin); wlAddStepnr.setLayoutData(fdlAddStepnr); wAddStepnr = new Button(wFileComp, SWT.CHECK); props.setLook(wAddStepnr); fdAddStepnr = new FormData(); fdAddStepnr.left = new FormAttachment(middle, 0); fdAddStepnr.top = new FormAttachment(wExtension, margin); fdAddStepnr.right = new FormAttachment(100, 0); wAddStepnr.setLayoutData(fdAddStepnr); wAddStepnr.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); // Create multi-part file? wlAddPartnr = new Label(wFileComp, SWT.RIGHT); wlAddPartnr.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.AddPartnr.Label")); props.setLook(wlAddPartnr); fdlAddPartnr = new FormData(); fdlAddPartnr.left = new FormAttachment(0, 0); fdlAddPartnr.top = new FormAttachment(wAddStepnr, margin); fdlAddPartnr.right = new FormAttachment(middle, -margin); wlAddPartnr.setLayoutData(fdlAddPartnr); wAddPartnr = new Button(wFileComp, SWT.CHECK); props.setLook(wAddPartnr); fdAddPartnr = new FormData(); fdAddPartnr.left = new FormAttachment(middle, 0); fdAddPartnr.top = new FormAttachment(wAddStepnr, margin); fdAddPartnr.right = new FormAttachment(100, 0); wAddPartnr.setLayoutData(fdAddPartnr); wAddPartnr.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); // Create multi-part file? wlAddDate = new Label(wFileComp, SWT.RIGHT); wlAddDate.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.AddDate.Label")); props.setLook(wlAddDate); fdlAddDate = new FormData(); fdlAddDate.left = new FormAttachment(0, 0); fdlAddDate.top = new FormAttachment(wAddPartnr, margin); fdlAddDate.right = new FormAttachment(middle, -margin); wlAddDate.setLayoutData(fdlAddDate); wAddDate = new Button(wFileComp, SWT.CHECK); props.setLook(wAddDate); fdAddDate = new FormData(); fdAddDate.left = new FormAttachment(middle, 0); fdAddDate.top = new FormAttachment(wAddPartnr, margin); fdAddDate.right = new FormAttachment(100, 0); wAddDate.setLayoutData(fdAddDate); wAddDate.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); // Create multi-part file? wlAddTime = new Label(wFileComp, SWT.RIGHT); wlAddTime.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.AddTime.Label")); props.setLook(wlAddTime); fdlAddTime = new FormData(); fdlAddTime.left = new FormAttachment(0, 0); fdlAddTime.top = new FormAttachment(wAddDate, margin); fdlAddTime.right = new FormAttachment(middle, -margin); wlAddTime.setLayoutData(fdlAddTime); wAddTime = new Button(wFileComp, SWT.CHECK); props.setLook(wAddTime); fdAddTime = new FormData(); fdAddTime.left = new FormAttachment(middle, 0); fdAddTime.top = new FormAttachment(wAddDate, margin); fdAddTime.right = new FormAttachment(100, 0); wAddTime.setLayoutData(fdAddTime); wAddTime.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); // Specify date time format? wlSpecifyFormat = new Label(wFileComp, SWT.RIGHT); wlSpecifyFormat.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.SpecifyFormat.Label")); props.setLook(wlSpecifyFormat); fdlSpecifyFormat = new FormData(); fdlSpecifyFormat.left = new FormAttachment(0, 0); fdlSpecifyFormat.top = new FormAttachment(wAddTime, margin); fdlSpecifyFormat.right = new FormAttachment(middle, -margin); wlSpecifyFormat.setLayoutData(fdlSpecifyFormat); wSpecifyFormat = new Button(wFileComp, SWT.CHECK); props.setLook(wSpecifyFormat); wSpecifyFormat.setToolTipText(BaseMessages.getString(PKG, "TextFileOutputDialog.SpecifyFormat.Tooltip")); fdSpecifyFormat = new FormData(); fdSpecifyFormat.left = new FormAttachment(middle, 0); fdSpecifyFormat.top = new FormAttachment(wAddTime, margin); fdSpecifyFormat.right = new FormAttachment(100, 0); wSpecifyFormat.setLayoutData(fdSpecifyFormat); wSpecifyFormat.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); setDateTimeFormat(); } }); // DateTimeFormat wlDateTimeFormat = new Label(wFileComp, SWT.RIGHT); wlDateTimeFormat.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.DateTimeFormat.Label")); props.setLook(wlDateTimeFormat); fdlDateTimeFormat = new FormData(); fdlDateTimeFormat.left = new FormAttachment(0, 0); fdlDateTimeFormat.top = new FormAttachment(wSpecifyFormat, margin); fdlDateTimeFormat.right = new FormAttachment(middle, -margin); wlDateTimeFormat.setLayoutData(fdlDateTimeFormat); wDateTimeFormat = new CCombo(wFileComp, SWT.BORDER | SWT.READ_ONLY); wDateTimeFormat.setEditable(true); props.setLook(wDateTimeFormat); wDateTimeFormat.addModifyListener(lsMod); fdDateTimeFormat = new FormData(); fdDateTimeFormat.left = new FormAttachment(middle, 0); fdDateTimeFormat.top = new FormAttachment(wSpecifyFormat, margin); fdDateTimeFormat.right = new FormAttachment(100, 0); wDateTimeFormat.setLayoutData(fdDateTimeFormat); String[] dats = Const.getDateFormats(); for (int x = 0; x < dats.length; x++) { wDateTimeFormat.add(dats[x]); } wbShowFiles = new Button(wFileComp, SWT.PUSH | SWT.CENTER); props.setLook(wbShowFiles); wbShowFiles.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.ShowFiles.Button")); fdbShowFiles = new FormData(); fdbShowFiles.left = new FormAttachment(middle, 0); fdbShowFiles.top = new FormAttachment(wDateTimeFormat, margin * 2); wbShowFiles.setLayoutData(fdbShowFiles); wbShowFiles.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TextFileOutputMeta tfoi = new TextFileOutputMeta(); saveInfoInMeta(tfoi); String[] files = tfoi.getFiles(transMeta); if (files != null && files.length > 0) { EnterSelectionDialog esd = new EnterSelectionDialog(shell, files, BaseMessages.getString(PKG, "TextFileOutputDialog.SelectOutputFiles.DialogTitle"), BaseMessages.getString(PKG, "TextFileOutputDialog.SelectOutputFiles.DialogMessage")); esd.setViewOnly(); esd.open(); } else { MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); mb.setMessage(BaseMessages.getString(PKG, "TextFileOutputDialog.NoFilesFound.DialogMessage")); mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title")); mb.open(); } } }); // Add File to the result files name wlAddToResult = new Label(wFileComp, SWT.RIGHT); wlAddToResult.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.AddFileToResult.Label")); props.setLook(wlAddToResult); fdlAddToResult = new FormData(); fdlAddToResult.left = new FormAttachment(0, 0); fdlAddToResult.top = new FormAttachment(wbShowFiles, 2 * margin); fdlAddToResult.right = new FormAttachment(middle, -margin); wlAddToResult.setLayoutData(fdlAddToResult); wAddToResult = new Button(wFileComp, SWT.CHECK); wAddToResult.setToolTipText(BaseMessages.getString(PKG, "TextFileOutputDialog.AddFileToResult.Tooltip")); props.setLook(wAddToResult); fdAddToResult = new FormData(); fdAddToResult.left = new FormAttachment(middle, 0); fdAddToResult.top = new FormAttachment(wbShowFiles, 2 * margin); fdAddToResult.right = new FormAttachment(100, 0); wAddToResult.setLayoutData(fdAddToResult); SelectionAdapter lsSelR = new SelectionAdapter() { public void widgetSelected(SelectionEvent arg0) { input.setChanged(); } }; wAddToResult.addSelectionListener(lsSelR); fdFileComp = new FormData(); fdFileComp.left = new FormAttachment(0, 0); fdFileComp.top = new FormAttachment(0, 0); fdFileComp.right = new FormAttachment(100, 0); fdFileComp.bottom = new FormAttachment(100, 0); wFileComp.setLayoutData(fdFileComp); wFileComp.layout(); wFileTab.setControl(wFileComp); // /////////////////////////////////////////////////////////// // / END OF FILE TAB // /////////////////////////////////////////////////////////// // //////////////////////// // START OF CONTENT TAB/// // / wContentTab = new CTabItem(wTabFolder, SWT.NONE); wContentTab.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.ContentTab.TabTitle")); FormLayout contentLayout = new FormLayout(); contentLayout.marginWidth = 3; contentLayout.marginHeight = 3; Composite wContentComp = new Composite(wTabFolder, SWT.NONE); props.setLook(wContentComp); wContentComp.setLayout(contentLayout); // Append to end of file? wlAppend = new Label(wContentComp, SWT.RIGHT); wlAppend.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.Append.Label")); props.setLook(wlAppend); fdlAppend = new FormData(); fdlAppend.left = new FormAttachment(0, 0); fdlAppend.top = new FormAttachment(0, 0); fdlAppend.right = new FormAttachment(middle, -margin); wlAppend.setLayoutData(fdlAppend); wAppend = new Button(wContentComp, SWT.CHECK); props.setLook(wAppend); fdAppend = new FormData(); fdAppend.left = new FormAttachment(middle, 0); fdAppend.top = new FormAttachment(0, 0); fdAppend.right = new FormAttachment(100, 0); wAppend.setLayoutData(fdAppend); wAppend.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } private void headerDisabling() { wHeader.setSelection(false); wHeader.setEnabled(!wAppend.getSelection()); } }); wlSeparator = new Label(wContentComp, SWT.RIGHT); wlSeparator.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.Separator.Label")); props.setLook(wlSeparator); fdlSeparator = new FormData(); fdlSeparator.left = new FormAttachment(0, 0); fdlSeparator.top = new FormAttachment(wAppend, margin); fdlSeparator.right = new FormAttachment(middle, -margin); wlSeparator.setLayoutData(fdlSeparator); wbSeparator = new Button(wContentComp, SWT.PUSH | SWT.CENTER); props.setLook(wbSeparator); wbSeparator.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.Separator.Button")); fdbSeparator = new FormData(); fdbSeparator.right = new FormAttachment(100, 0); fdbSeparator.top = new FormAttachment(wAppend, 0); wbSeparator.setLayoutData(fdbSeparator); wbSeparator.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent se) { // wSeparator.insert("\t"); wSeparator.getTextWidget().insert("\t"); } }); wSeparator = new TextVar(transMeta, wContentComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wSeparator); wSeparator.addModifyListener(lsMod); fdSeparator = new FormData(); fdSeparator.left = new FormAttachment(middle, 0); fdSeparator.top = new FormAttachment(wAppend, margin); fdSeparator.right = new FormAttachment(wbSeparator, -margin); wSeparator.setLayoutData(fdSeparator); // Enclosure line... wlEnclosure = new Label(wContentComp, SWT.RIGHT); wlEnclosure.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.Enclosure.Label")); props.setLook(wlEnclosure); fdlEnclosure = new FormData(); fdlEnclosure.left = new FormAttachment(0, 0); fdlEnclosure.top = new FormAttachment(wSeparator, margin); fdlEnclosure.right = new FormAttachment(middle, -margin); wlEnclosure.setLayoutData(fdlEnclosure); wEnclosure = new TextVar(transMeta, wContentComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wEnclosure); wEnclosure.addModifyListener(lsMod); fdEnclosure = new FormData(); fdEnclosure.left = new FormAttachment(middle, 0); fdEnclosure.top = new FormAttachment(wSeparator, margin); fdEnclosure.right = new FormAttachment(100, 0); wEnclosure.setLayoutData(fdEnclosure); wlEnclForced = new Label(wContentComp, SWT.RIGHT); wlEnclForced.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.EnclForced.Label")); props.setLook(wlEnclForced); fdlEnclForced = new FormData(); fdlEnclForced.left = new FormAttachment(0, 0); fdlEnclForced.top = new FormAttachment(wEnclosure, margin); fdlEnclForced.right = new FormAttachment(middle, -margin); wlEnclForced.setLayoutData(fdlEnclForced); wEnclForced = new Button(wContentComp, SWT.CHECK); props.setLook(wEnclForced); fdEnclForced = new FormData(); fdEnclForced.left = new FormAttachment(middle, 0); fdEnclForced.top = new FormAttachment(wEnclosure, margin); fdEnclForced.right = new FormAttachment(100, 0); wEnclForced.setLayoutData(fdEnclForced); wEnclForced.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); wlDisableEnclosureFix = new Label(wContentComp, SWT.RIGHT); wlDisableEnclosureFix .setText(BaseMessages.getString(PKG, "TextFileOutputDialog.DisableEnclosureFix.Label")); props.setLook(wlDisableEnclosureFix); fdlDisableEnclosureFix = new FormData(); fdlDisableEnclosureFix.left = new FormAttachment(0, 0); fdlDisableEnclosureFix.top = new FormAttachment(wEnclForced, margin); fdlDisableEnclosureFix.right = new FormAttachment(middle, -margin); wlDisableEnclosureFix.setLayoutData(fdlDisableEnclosureFix); wDisableEnclosureFix = new Button(wContentComp, SWT.CHECK); props.setLook(wDisableEnclosureFix); fdDisableEnclosureFix = new FormData(); fdDisableEnclosureFix.left = new FormAttachment(middle, 0); fdDisableEnclosureFix.top = new FormAttachment(wEnclForced, margin); fdDisableEnclosureFix.right = new FormAttachment(100, 0); wDisableEnclosureFix.setLayoutData(fdDisableEnclosureFix); wDisableEnclosureFix.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); wlHeader = new Label(wContentComp, SWT.RIGHT); wlHeader.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.Header.Label")); props.setLook(wlHeader); fdlHeader = new FormData(); fdlHeader.left = new FormAttachment(0, 0); fdlHeader.top = new FormAttachment(wDisableEnclosureFix, margin); fdlHeader.right = new FormAttachment(middle, -margin); wlHeader.setLayoutData(fdlHeader); wHeader = new Button(wContentComp, SWT.CHECK); props.setLook(wHeader); fdHeader = new FormData(); fdHeader.left = new FormAttachment(middle, 0); fdHeader.top = new FormAttachment(wDisableEnclosureFix, margin); fdHeader.right = new FormAttachment(100, 0); wHeader.setLayoutData(fdHeader); wHeader.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); wlFooter = new Label(wContentComp, SWT.RIGHT); wlFooter.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.Footer.Label")); props.setLook(wlFooter); fdlFooter = new FormData(); fdlFooter.left = new FormAttachment(0, 0); fdlFooter.top = new FormAttachment(wHeader, margin); fdlFooter.right = new FormAttachment(middle, -margin); wlFooter.setLayoutData(fdlFooter); wFooter = new Button(wContentComp, SWT.CHECK); props.setLook(wFooter); fdFooter = new FormData(); fdFooter.left = new FormAttachment(middle, 0); fdFooter.top = new FormAttachment(wHeader, margin); fdFooter.right = new FormAttachment(100, 0); wFooter.setLayoutData(fdFooter); wFooter.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); wlFormat = new Label(wContentComp, SWT.RIGHT); wlFormat.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.Format.Label")); props.setLook(wlFormat); fdlFormat = new FormData(); fdlFormat.left = new FormAttachment(0, 0); fdlFormat.top = new FormAttachment(wFooter, margin); fdlFormat.right = new FormAttachment(middle, -margin); wlFormat.setLayoutData(fdlFormat); wFormat = new CCombo(wContentComp, SWT.BORDER | SWT.READ_ONLY); wFormat.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.Format.Label")); props.setLook(wFormat); for (int i = 0; i < TextFileOutputMeta.formatMapperLineTerminator.length; i++) { // add e.g. TextFileOutputDialog.Format.DOS, .UNIX, .CR, .None wFormat.add(BaseMessages.getString(PKG, "TextFileOutputDialog.Format." + TextFileOutputMeta.formatMapperLineTerminator[i])); } wFormat.select(0); wFormat.addModifyListener(lsMod); fdFormat = new FormData(); fdFormat.left = new FormAttachment(middle, 0); fdFormat.top = new FormAttachment(wFooter, margin); fdFormat.right = new FormAttachment(100, 0); wFormat.setLayoutData(fdFormat); wlCompression = new Label(wContentComp, SWT.RIGHT); wlCompression.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.Compression.Label")); props.setLook(wlCompression); fdlCompression = new FormData(); fdlCompression.left = new FormAttachment(0, 0); fdlCompression.top = new FormAttachment(wFormat, margin); fdlCompression.right = new FormAttachment(middle, -margin); wlCompression.setLayoutData(fdlCompression); wCompression = new CCombo(wContentComp, SWT.BORDER | SWT.READ_ONLY); wCompression.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.Compression.Label")); props.setLook(wCompression); wCompression.setItems(CompressionProviderFactory.getInstance().getCompressionProviderNames()); wCompression.addModifyListener(lsMod); fdCompression = new FormData(); fdCompression.left = new FormAttachment(middle, 0); fdCompression.top = new FormAttachment(wFormat, margin); fdCompression.right = new FormAttachment(100, 0); wCompression.setLayoutData(fdCompression); wlEncoding = new Label(wContentComp, SWT.RIGHT); wlEncoding.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.Encoding.Label")); props.setLook(wlEncoding); fdlEncoding = new FormData(); fdlEncoding.left = new FormAttachment(0, 0); fdlEncoding.top = new FormAttachment(wCompression, margin); fdlEncoding.right = new FormAttachment(middle, -margin); wlEncoding.setLayoutData(fdlEncoding); wEncoding = new CCombo(wContentComp, SWT.BORDER | SWT.READ_ONLY); wEncoding.setEditable(true); props.setLook(wEncoding); wEncoding.addModifyListener(lsMod); fdEncoding = new FormData(); fdEncoding.left = new FormAttachment(middle, 0); fdEncoding.top = new FormAttachment(wCompression, margin); fdEncoding.right = new FormAttachment(100, 0); wEncoding.setLayoutData(fdEncoding); wEncoding.addFocusListener(new FocusListener() { public void focusLost(org.eclipse.swt.events.FocusEvent e) { } public void focusGained(org.eclipse.swt.events.FocusEvent e) { Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT); shell.setCursor(busy); setEncodings(); shell.setCursor(null); busy.dispose(); } }); wlPad = new Label(wContentComp, SWT.RIGHT); wlPad.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.Pad.Label")); props.setLook(wlPad); fdlPad = new FormData(); fdlPad.left = new FormAttachment(0, 0); fdlPad.top = new FormAttachment(wEncoding, margin); fdlPad.right = new FormAttachment(middle, -margin); wlPad.setLayoutData(fdlPad); wPad = new Button(wContentComp, SWT.CHECK); props.setLook(wPad); fdPad = new FormData(); fdPad.left = new FormAttachment(middle, 0); fdPad.top = new FormAttachment(wEncoding, margin); fdPad.right = new FormAttachment(100, 0); wPad.setLayoutData(fdPad); wPad.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); wlFastDump = new Label(wContentComp, SWT.RIGHT); wlFastDump.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.FastDump.Label")); props.setLook(wlFastDump); fdlFastDump = new FormData(); fdlFastDump.left = new FormAttachment(0, 0); fdlFastDump.top = new FormAttachment(wPad, margin); fdlFastDump.right = new FormAttachment(middle, -margin); wlFastDump.setLayoutData(fdlFastDump); wFastDump = new Button(wContentComp, SWT.CHECK); props.setLook(wFastDump); fdFastDump = new FormData(); fdFastDump.left = new FormAttachment(middle, 0); fdFastDump.top = new FormAttachment(wPad, margin); fdFastDump.right = new FormAttachment(100, 0); wFastDump.setLayoutData(fdFastDump); wFastDump.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); wlSplitEvery = new Label(wContentComp, SWT.RIGHT); wlSplitEvery.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.SplitEvery.Label")); props.setLook(wlSplitEvery); fdlSplitEvery = new FormData(); fdlSplitEvery.left = new FormAttachment(0, 0); fdlSplitEvery.top = new FormAttachment(wFastDump, margin); fdlSplitEvery.right = new FormAttachment(middle, -margin); wlSplitEvery.setLayoutData(fdlSplitEvery); wSplitEvery = new TextVar(transMeta, wContentComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wSplitEvery); wSplitEvery.addModifyListener(lsMod); fdSplitEvery = new FormData(); fdSplitEvery.left = new FormAttachment(middle, 0); fdSplitEvery.top = new FormAttachment(wFastDump, margin); fdSplitEvery.right = new FormAttachment(100, 0); wSplitEvery.setLayoutData(fdSplitEvery); // Bruise: wlEndedLine = new Label(wContentComp, SWT.RIGHT); wlEndedLine.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.EndedLine.Label")); props.setLook(wlEndedLine); fdlEndedLine = new FormData(); fdlEndedLine.left = new FormAttachment(0, 0); fdlEndedLine.top = new FormAttachment(wSplitEvery, margin); fdlEndedLine.right = new FormAttachment(middle, -margin); wlEndedLine.setLayoutData(fdlEndedLine); wEndedLine = new TextVar(transMeta, wContentComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wEndedLine); wEndedLine.addModifyListener(lsMod); fdEndedLine = new FormData(); fdEndedLine.left = new FormAttachment(middle, 0); fdEndedLine.top = new FormAttachment(wSplitEvery, margin); fdEndedLine.right = new FormAttachment(100, 0); wEndedLine.setLayoutData(fdEndedLine); fdContentComp = new FormData(); fdContentComp.left = new FormAttachment(0, 0); fdContentComp.top = new FormAttachment(0, 0); fdContentComp.right = new FormAttachment(100, 0); fdContentComp.bottom = new FormAttachment(100, 0); wContentComp.setLayoutData(fdContentComp); wContentComp.layout(); wContentTab.setControl(wContentComp); // /////////////////////////////////////////////////////////// // / END OF CONTENT TAB // /////////////////////////////////////////////////////////// // Fields tab... // wFieldsTab = new CTabItem(wTabFolder, SWT.NONE); wFieldsTab.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.FieldsTab.TabTitle")); FormLayout fieldsLayout = new FormLayout(); fieldsLayout.marginWidth = Const.FORM_MARGIN; fieldsLayout.marginHeight = Const.FORM_MARGIN; Composite wFieldsComp = new Composite(wTabFolder, SWT.NONE); wFieldsComp.setLayout(fieldsLayout); props.setLook(wFieldsComp); wGet = new Button(wFieldsComp, SWT.PUSH); wGet.setText(BaseMessages.getString(PKG, "System.Button.GetFields")); wGet.setToolTipText(BaseMessages.getString(PKG, "System.Tooltip.GetFields")); wMinWidth = new Button(wFieldsComp, SWT.PUSH); wMinWidth.setText(BaseMessages.getString(PKG, "TextFileOutputDialog.MinWidth.Button")); wMinWidth.setToolTipText(BaseMessages.getString(PKG, "TextFileOutputDialog.MinWidth.Tooltip")); wMinWidth.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); setButtonPositions(new Button[] { wGet, wMinWidth }, margin, null); final int FieldsCols = 10; final int FieldsRows = input.getOutputFields().length; // Prepare a list of possible formats... String[] nums = Const.getNumberFormats(); int totsize = dats.length + nums.length; String[] formats = new String[totsize]; for (int x = 0; x < dats.length; x++) { formats[x] = dats[x]; } for (int x = 0; x < nums.length; x++) { formats[dats.length + x] = nums[x]; } colinf = new ColumnInfo[FieldsCols]; colinf[0] = new ColumnInfo(BaseMessages.getString(PKG, "TextFileOutputDialog.NameColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false); colinf[1] = new ColumnInfo(BaseMessages.getString(PKG, "TextFileOutputDialog.TypeColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaFactory.getValueMetaNames()); colinf[2] = new ColumnInfo(BaseMessages.getString(PKG, "TextFileOutputDialog.FormatColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, formats); colinf[3] = new ColumnInfo(BaseMessages.getString(PKG, "TextFileOutputDialog.LengthColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false); colinf[4] = new ColumnInfo(BaseMessages.getString(PKG, "TextFileOutputDialog.PrecisionColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false); colinf[5] = new ColumnInfo(BaseMessages.getString(PKG, "TextFileOutputDialog.CurrencyColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false); colinf[6] = new ColumnInfo(BaseMessages.getString(PKG, "TextFileOutputDialog.DecimalColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false); colinf[7] = new ColumnInfo(BaseMessages.getString(PKG, "TextFileOutputDialog.GroupColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false); colinf[8] = new ColumnInfo(BaseMessages.getString(PKG, "TextFileOutputDialog.TrimTypeColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaString.trimTypeDesc, true); colinf[9] = new ColumnInfo(BaseMessages.getString(PKG, "TextFileOutputDialog.NullColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false); wFields = new TableView(transMeta, wFieldsComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, FieldsRows, lsMod, props); fdFields = new FormData(); fdFields.left = new FormAttachment(0, 0); fdFields.top = new FormAttachment(0, 0); fdFields.right = new FormAttachment(100, 0); fdFields.bottom = new FormAttachment(wGet, -margin); wFields.setLayoutData(fdFields); // // Search the fields in the background final Runnable runnable = new Runnable() { public void run() { StepMeta stepMeta = transMeta.findStep(stepname); if (stepMeta != null) { try { RowMetaInterface row = transMeta.getPrevStepFields(stepMeta); // Remember these fields... for (int i = 0; i < row.size(); i++) { inputFields.put(row.getValueMeta(i).getName(), Integer.valueOf(i)); } setComboBoxes(); } catch (KettleException e) { logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message")); } } } }; new Thread(runnable).start(); fdFieldsComp = new FormData(); fdFieldsComp.left = new FormAttachment(0, 0); fdFieldsComp.top = new FormAttachment(0, 0); fdFieldsComp.right = new FormAttachment(100, 0); fdFieldsComp.bottom = new FormAttachment(100, 0); wFieldsComp.setLayoutData(fdFieldsComp); wFieldsComp.layout(); wFieldsTab.setControl(wFieldsComp); fdTabFolder = new FormData(); fdTabFolder.left = new FormAttachment(0, 0); fdTabFolder.top = new FormAttachment(wStepname, margin); fdTabFolder.right = new FormAttachment(100, 0); fdTabFolder.bottom = new FormAttachment(100, -50); wTabFolder.setLayoutData(fdTabFolder); wOK = new Button(shell, SWT.PUSH); wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); wCancel = new Button(shell, SWT.PUSH); wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); setButtonPositions(new Button[] { wOK, wCancel }, margin, wTabFolder); // Add listeners lsOK = new Listener() { public void handleEvent(Event e) { ok(); } }; lsGet = new Listener() { public void handleEvent(Event e) { get(); } }; lsMinWidth = new Listener() { public void handleEvent(Event e) { setMinimalWidth(); } }; lsCancel = new Listener() { public void handleEvent(Event e) { cancel(); } }; wOK.addListener(SWT.Selection, lsOK); wGet.addListener(SWT.Selection, lsGet); wMinWidth.addListener(SWT.Selection, lsMinWidth); wCancel.addListener(SWT.Selection, lsCancel); lsDef = new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent e) { ok(); } }; wStepname.addSelectionListener(lsDef); wFilename.addSelectionListener(lsDef); wSeparator.addSelectionListener(lsDef); // Whenever something changes, set the tooltip to the expanded version: wFilename.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { wFilename.setToolTipText(transMeta.environmentSubstitute(wFilename.getText())); } }); wbFilename.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { VfsFileChooserDialog fileChooserDialog = Spoon.getInstance().getVfsFileChooserDialog(null, null); if (wFilename.getText() != null) { try { fileChooserDialog.initialFile = KettleVFS .getFileObject(transMeta.environmentSubstitute(wFilename.getText())); } catch (KettleException ex) { fileChooserDialog.initialFile = null; } } FileObject selectedFile = fileChooserDialog.open(shell, null, "file", new String[] { "*.txt", "*.csv", "*" }, new String[] { BaseMessages.getString(PKG, "System.FileType.TextFiles"), BaseMessages.getString(PKG, "System.FileType.CSVFiles"), BaseMessages.getString(PKG, "System.FileType.AllFiles") }, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE_OR_DIRECTORY); if (selectedFile != null) { String file = selectedFile.getName().getURI(); if (!StringUtils.isBlank(file)) { file = file.replace("file://", "").replace("/C:", "C:"); } if (!file.contains(System.getProperty("file.separator"))) { if (!System.getProperty("file.separator").equals("/") && !Const.isWindows()) { file = file.replace("/", System.getProperty("file.separator")); } } wFilename.setText(file); } } }); // Detect X or ALT-F4 or something that kills this window... shell.addShellListener(new ShellAdapter() { public void shellClosed(ShellEvent e) { cancel(); } }); lsResize = new Listener() { public void handleEvent(Event event) { Point size = shell.getSize(); wFields.setSize(size.x - 10, size.y - 50); wFields.table.setSize(size.x - 10, size.y - 50); wFields.redraw(); } }; shell.addListener(SWT.Resize, lsResize); wTabFolder.setSelection(0); // Set the shell size, based upon previous time... setSize(); getData(); activeFileNameField(); enableParentFolder(); input.setChanged(changed); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } return stepname; }
From source file:org.pentaho.di.utils.TestUtils.java
public static String createRamFile(String path) { try {//from w w w . j a v a2 s. c o m FileObject file = KettleVFS.getInstance().getFileSystemManager().resolveFile("ram://" + path); file.createFile(); return file.getName().getURI(); } catch (FileSystemException e) { throw new RuntimeException(e); } }
From source file:org.pentaho.di.www.RegisterPackageServlet.java
@Override WebResult generateBody(HttpServletRequest request, HttpServletResponse response, boolean useXML) throws KettleException, IOException { FileObject tempFile = KettleVFS.createTempFile("export", ".zip", System.getProperty("java.io.tmpdir")); OutputStream out = KettleVFS.getOutputStream(tempFile, false); IOUtils.copy(request.getInputStream(), out); out.flush();//from w w w . ja v a2s . c o m IOUtils.closeQuietly(out); String archiveUrl = tempFile.getName().toString(); String load = request.getParameter(PARAMETER_LOAD); // the resource to load if (!Utils.isEmpty(load)) { String fileUrl = MessageFormat.format(ZIP_CONT, archiveUrl, load); boolean isJob = TYPE_JOB.equalsIgnoreCase(request.getParameter(PARAMETER_TYPE)); String resultId; if (isJob) { Node node = getConfigNodeFromZIP(archiveUrl, Job.CONFIGURATION_IN_EXPORT_FILENAME, JobExecutionConfiguration.XML_TAG); JobExecutionConfiguration jobExecutionConfiguration = new JobExecutionConfiguration(node); JobMeta jobMeta = new JobMeta(fileUrl, jobExecutionConfiguration.getRepository()); JobConfiguration jobConfiguration = new JobConfiguration(jobMeta, jobExecutionConfiguration); Job job = createJob(jobConfiguration); resultId = job.getContainerObjectId(); } else { Node node = getConfigNodeFromZIP(archiveUrl, Trans.CONFIGURATION_IN_EXPORT_FILENAME, TransExecutionConfiguration.XML_TAG); TransExecutionConfiguration transExecutionConfiguration = new TransExecutionConfiguration(node); TransMeta transMeta = new TransMeta(fileUrl, transExecutionConfiguration.getRepository()); TransConfiguration transConfiguration = new TransConfiguration(transMeta, transExecutionConfiguration); Trans trans = createTrans(transConfiguration); resultId = trans.getContainerObjectId(); } return new WebResult(WebResult.STRING_OK, fileUrl, resultId); } return null; }
From source file:org.pentaho.hadoop.shim.common.DistributedCacheUtilImpl.java
/** * Move files from the source folder to the destination folder, overwriting any files that may already exist there. * * @param fs File system to write to * @param dest Destination to move source file/folder into * @param pluginFolder Big Data plugin folder * @throws KettleFileException/*from w w w. j av a2 s. c o m*/ * @throws IOException */ private void stageBigDataPlugin(FileSystem fs, Path dest, FileObject pluginFolder) throws KettleFileException, IOException { Path pluginsDir = new Path(dest, PATH_PLUGINS); Path libDir = new Path(dest, PATH_LIB); Path bigDataPluginDir = new Path(pluginsDir, pluginFolder.getName().getBaseName()); // Stage everything except the hadoop-configurations and pmr libraries for (FileObject f : pluginFolder.findFiles(new FileDepthSelector(1, 1))) { if (!"hadoop-configurations".equals(f.getName().getBaseName()) && !"pentaho-mapreduce-libraries.zip".equals(f.getName().getBaseName())) { stageForCache(f, fs, new Path(bigDataPluginDir, f.getName().getBaseName()), true, false); } } // Stage the current Hadoop configuration without its client-only or pmr libraries (these will be copied into the // lib dir) Path hadoopConfigDir = new Path(new Path(bigDataPluginDir, "hadoop-configurations"), configuration.getIdentifier()); for (FileObject f : configuration.getLocation().findFiles(new FileSelector() { @Override public boolean includeFile(FileSelectInfo info) throws Exception { return FileType.FILE.equals(info.getFile().getType()); } @Override public boolean traverseDescendents(FileSelectInfo info) throws Exception { String name = info.getFile().getName().getBaseName(); return !((PATH_PMR.equals(name) || PATH_CLIENT.equals(name)) && PATH_LIB.equals(info.getFile().getParent().getName().getBaseName())); } })) { // Create relative path to write to String relPath = configuration.getLocation().getName().getRelativeName(f.getName()); stageForCache(f, fs, new Path(hadoopConfigDir, relPath), true, false); } // Stage all pmr libraries for the Hadoop configuration into the root library path for the Kettle environment for (FileObject f : configuration.getLocation().resolveFile(PATH_LIB).resolveFile(PATH_PMR) .findFiles(new FileTypeSelector(FileType.FILE))) { stageForCache(f, fs, new Path(libDir, f.getName().getBaseName()), true, false); } }
From source file:org.pentaho.hadoop.shim.common.DistributedCacheUtilImpl.java
/** * Attempts to find a plugin's installation folder on disk within all known plugin folder locations * * @param pluginFolderName Name of plugin folder * @return Tuple of [(FileObject) Location of the first plugin folder found as a direct descendant of one of the known * plugin folder locations, (String) Relative path from parent] * @throws KettleFileException Error getting plugin folders *//*from ww w . ja v a 2 s. c o m*/ protected Object[] findPluginFolder(final String pluginFolderName) throws KettleFileException { List<PluginFolderInterface> pluginFolders = PluginFolder.populateFolders(null); if (pluginFolders != null) { for (PluginFolderInterface pluginFolder : pluginFolders) { FileObject folder = KettleVFS.getFileObject(pluginFolder.getFolder()); try { if (folder.exists()) { FileObject[] files = folder.findFiles(new FileSelector() { @Override public boolean includeFile(FileSelectInfo fileSelectInfo) throws Exception { if (fileSelectInfo.getFile().equals(fileSelectInfo.getBaseFolder())) { // Do not consider the base folders return false; } // Determine relative name to compare int baseNameLength = fileSelectInfo.getBaseFolder().getName().getPath().length() + 1; String relativeName = fileSelectInfo.getFile().getName().getPath() .substring(baseNameLength); // Compare plugin folder name with the relative name return pluginFolderName.equals(relativeName); } @Override public boolean traverseDescendents(FileSelectInfo fileSelectInfo) throws Exception { return true; } }); if (files != null && files.length > 0) { return new Object[] { files[0], folder.getName().getRelativeName(files[0].getName()) }; // Return the first match } } } catch (FileSystemException ex) { throw new KettleFileException("Error searching for folder '" + pluginFolderName + "'", ex); } } } return null; }
From source file:org.pentaho.hadoop.shim.HadoopConfigurationLocator.java
/** * Attempt to find any Hadoop configuration as a direct descendant of the provided directory. * * @param baseDir Directory to look for Hadoop configurations in * @throws ConfigurationException/*from w ww .ja v a2 s . co m*/ */ private void findHadoopConfigurations(FileObject baseDir, ActiveHadoopConfigurationLocator activeLocator) throws ConfigurationException { configurations = new HashMap<String, HadoopConfiguration>(); try { if (!baseDir.exists()) { throw new ConfigurationException(BaseMessages.getString(PKG, "Error.HadoopConfigurationDirectoryDoesNotExist", baseDir.getURL())); } for (FileObject f : baseDir.findFiles(new FileSelector() { @Override public boolean includeFile(FileSelectInfo info) throws Exception { return info.getDepth() == 1 && FileType.FOLDER.equals(info.getFile().getType()); } @Override public boolean traverseDescendents(FileSelectInfo info) throws Exception { return info.getDepth() == 0; } })) { // Only load the specified configuration (ID should match the basename, we allow case-insensitivity) if (f.getName().getBaseName().equalsIgnoreCase(activeLocator.getActiveConfigurationId())) { HadoopConfiguration config = loadHadoopConfiguration(f); if (config != null) { configurations.put(config.getIdentifier(), config); } } } } catch (FileSystemException ex) { throw new ConfigurationException(BaseMessages.getString(PKG, "Error.UnableToLoadConfigurations", baseDir.getName().getFriendlyURI()), ex); } }
From source file:org.pentaho.hadoop.shim.HadoopConfigurationLocator.java
/** * Attempt to discover a valid Hadoop configuration from the provided folder. * * @param folder Folder that may represent a Hadoop configuration * @return A Hadoop configuration for the folder provided or null if none is found. * @throws ConfigurationException Error when loading the Hadoop configuration. *///from ww w . ja v a 2 s . c om protected HadoopConfiguration loadHadoopConfiguration(FileObject folder) throws ConfigurationException { ShimProperties configurationProperties = new ShimProperties(); try { FileObject configFile = folder.getChild(CONFIG_PROPERTIES_FILE); if (configFile != null) { configurationProperties.putAll(loadProperties(configFile)); } } catch (Exception ex) { throw new ConfigurationException(BaseMessages.getString(PKG, "Error.UnableToLoadConfigurationProperties", CONFIG_PROPERTIES_FILE)); } for (Entry<String, String> entry : configurationProperties.getPrefixedProperties("java.system") .entrySet()) { System.setProperty(entry.getKey(), entry.getValue()); } try { List<URL> classpathElements = null; if (!isRunningOnCluster()) { // Parse all URLs from an optional classpath from the configuration file classpathElements = parseURLs(folder, configurationProperties.getProperty(CONFIG_PROPERTY_CLASSPATH)); } // Allow external configuration of classes to ignore String ignoredClassesProperty = configurationProperties.getProperty(CONFIG_PROPERTY_IGNORE_CLASSES); String[] ignoredClasses = null; if (!StringUtil.isEmpty(ignoredClassesProperty)) { ignoredClasses = ignoredClassesProperty.split(","); } // Pass our class loader in to the configurations' CL as its parent so it // can find the same // API classes we're using ClassLoader cl = createConfigurationLoader(folder, getClass().getClassLoader(), classpathElements, configurationProperties, ignoredClasses); verifyClasses(cl, configurationProperties.getProperty("required.classes"), configurationProperties.getProperty("name")); // Treat the Hadoop shim special. It is absolutely required for a Hadoop configuration. HadoopShim hadoopShim = null; List<PentahoHadoopShim> shims = new ArrayList<PentahoHadoopShim>(); // Attempt to locate a shim within this folder for (Class<? extends PentahoHadoopShim> shimType : SHIM_TYPES) { PentahoHadoopShim s = locateServiceImpl(cl, shimType); if (s == null && shimType.getAnnotation(Required.class) != null) { logger.warn(BaseMessages.getString(PKG, "Error.MissingRequiredShim", shimType.getSimpleName())); // Do not continue to load the configuration if we are missing a required shim return null; } if (HadoopShim.class.isAssignableFrom(shimType)) { hadoopShim = (HadoopShim) s; } else { shims.add(s); } } String id = folder.getName().getBaseName(); String name = configurationProperties.getProperty(CONFIG_PROPERTY_NAME, id); HadoopConfiguration config = new HadoopConfiguration(configurationProperties, folder, id, name, hadoopShim, shims.toArray(EMPTY_SHIM_ARRAY)); // Register native libraries after everything else has been loaded successfully registerNativeLibraryPaths(configurationProperties.getProperty(CONFIG_PROPERTY_LIBRARY_PATH)); hadoopShim.onLoad(config, fsm); return config; } catch (Throwable t) { throw new ConfigurationException( BaseMessages.getString(PKG, "Error.LoadingConfiguration") + " " + t.toString(), t); } }