List of usage examples for org.apache.commons.vfs2 FileObject getURL
URL getURL() throws FileSystemException;
From source file:org.pentaho.di.resource.NameResourceIT.java
/** * This tests ResourceNamingInterface.nameResouce(), comparing the directory maps generated by the legacy and new * method.//from ww w . j ava 2 s . c om * * @param fileName * @param pathOnly * Resolve the path - leave out the file name * @throws Exception * * Legacy: namingResource(String, String, String, FileNamingType) New: namingResource(FileObject, TransMeta) */ private void testNamingResourceLegacyAndNew(String fileName, String extension, String fileMask) throws Exception { // Create a new transformation. TransMeta transMeta = new TransMeta(); FileObject fileObject = KettleVFS.getFileObject(fileName, transMeta); // This code is modeled after the legacy code in legacy step meta classes // that have an exportResources method that deal with file masks // e.g., ExcelInputMeta // // There is a big exception: where the legacy code does a "getName()" // this code does a "getURL()". This is because of the JIRA case // that resulted in the refactoring of ResourceNamingInterface. // // The UNC and VFS protocols where being dropped. // The code you see here would be the fix for that without adding // the new nameResource() to ResourceNamingInterface. // String path = null; String prefix = null; if (Utils.isEmpty(fileMask)) { prefix = fileObject.getName().getBaseName(); path = fileObject.getParent().getURL().toString(); } else { prefix = ""; path = fileObject.getURL().toString(); } // Create a resource naming interface to use the legacy method call ResourceNamingInterface resourceNamingInterface_LEGACY = new SequenceResourceNaming(); // Create two resource naming interfaces, one for legacy call, the other for new method call ResourceNamingInterface resourceNamingInterface_NEW = new SequenceResourceNaming(); // The old and new interfaces to get the file name. String resolvedFileName_LEGACY = resourceNamingInterface_LEGACY.nameResource(prefix, path, extension, FileNamingType.DATA_FILE); String resolvedFileName_NEW = resourceNamingInterface_NEW.nameResource(fileObject, transMeta, Utils.isEmpty(fileMask)); // get the variable name from both naming interfaces directory maps String pathFromMap_LEGACY = resourceNamingInterface_LEGACY.getDirectoryMap().get(path); String pathFromMap_NEW = resourceNamingInterface_NEW.getDirectoryMap().get(path); // The paths in both directories should be the same assertEquals(pathFromMap_LEGACY, pathFromMap_NEW); // The file names should be the same assertEquals(resolvedFileName_LEGACY, resolvedFileName_NEW); }
From source file:org.pentaho.di.sdk.samples.databases.demo.DemoDatabaseMeta.java
/** * @param hostname ignored in this implementation * @param port ignored in this implementation * @param databaseName the directory containing CSV files. * /*from w w w . java 2 s .c om*/ * @return the connection string based on hostname, port and databasename. */ public String getURL(String hostname, String port, String databaseName) throws KettleDatabaseException { File dbName = new File(databaseName); if (dbName != null && !dbName.exists()) { // CSV-JDBC requires local file paths // It may be a VFS path, test and convert to local if it is a VFS path FileObject vfsObject; try { vfsObject = KettleVFS.getFileObject(databaseName); if (vfsObject != null && vfsObject.exists()) { File temp = new File(vfsObject.getURL().getPath()); if (temp.exists()) { dbName = temp; } } } catch (KettleFileException | FileSystemException e) { throw new KettleDatabaseException(e); } } return "jdbc:relique:csv:" + dbName.getPath(); }
From source file:org.pentaho.di.sdk.samples.databases.demo.DemoDatabaseMetaTest.java
@Test public void testGetUrl() throws KettleException, FileSystemException { final String prefix = "jdbc:relique:csv:"; DemoDatabaseMeta dbMeta = new DemoDatabaseMeta(); // Test working directory assertEquals(prefix + System.getProperty("user.dir"), dbMeta.getURL(null, null, "")); // Test local file path String url = dbMeta.getURL(null, null, new File("target").getAbsolutePath()); assertEquals(prefix + System.getProperty("user.dir") + Const.FILE_SEPARATOR + "target", url); // Test VFS/*from www. j a v a 2s. com*/ FileObject vfsFile = KettleVFS.getFileObject(System.getProperty("user.dir")); url = dbMeta.getURL(null, null, vfsFile.getURL().toString()); assertEquals(prefix + System.getProperty("user.dir"), url); }
From source file:org.pentaho.di.sdk.samples.steps.mymapping.MyMappingDialog.java
private void selectFileTrans() { String curFile = wFilename.getText(); FileObject root;//w ww . j a v a 2 s . c o m try { root = KettleVFS.getFileObject(curFile != null ? curFile : Const.getUserHomeDirectory()); VfsFileChooserDialog vfsFileChooser = Spoon.getInstance().getVfsFileChooserDialog(root.getParent(), root); FileObject file = vfsFileChooser.open(shell, null, Const.STRING_TRANS_FILTER_EXT, Const.getTransformationFilterNames(), VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE); if (file == null) { return; } String fname; fname = file.getURL().getFile(); if (fname != null) { loadFileTrans(fname); wFilename.setText(mappingTransMeta.getFilename()); wTransname.setText(Const.NVL(mappingTransMeta.getName(), "")); wDirectory.setText(""); setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME); setRadioButtons(); } } catch (IOException e) { new ErrorDialog(shell, BaseMessages.getString(PKG, "MappingDialog.ErrorLoadingTransformation.DialogTitle"), BaseMessages.getString(PKG, "MappingDialog.ErrorLoadingTransformation.DialogMessage"), e); } catch (KettleException e) { new ErrorDialog(shell, BaseMessages.getString(PKG, "MappingDialog.ErrorLoadingTransformation.DialogTitle"), BaseMessages.getString(PKG, "MappingDialog.ErrorLoadingTransformation.DialogMessage"), e); } }
From source file:org.pentaho.di.trans.step.filestream.FileStream.java
private String getFilePath(String path) { try {// www. java 2 s . com final FileObject fileObject = KettleVFS.getFileObject(environmentSubstitute(path)); if (!fileObject.exists()) { throw new FileNotFoundException(path); } return Paths.get(fileObject.getURL().toURI()).normalize().toString(); } catch (URISyntaxException | FileNotFoundException | FileSystemException | KettleFileException e) { propagate(e); } return null; }
From source file:org.pentaho.di.trans.steps.avroinput.AvroInputDialog.java
public String open() { Shell parent = getParent();//from w w w. j a v a 2 s .co m Display display = parent.getDisplay(); shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX); props.setLook(shell); setShellImage(shell, m_currentMeta); // used to listen to a text field (m_wStepname) ModifyListener lsMod = new ModifyListener() { public void modifyText(ModifyEvent e) { m_currentMeta.setChanged(); } }; changed = m_currentMeta.hasChanged(); FormLayout formLayout = new FormLayout(); formLayout.marginWidth = Const.FORM_MARGIN; formLayout.marginHeight = Const.FORM_MARGIN; shell.setLayout(formLayout); shell.setText(BaseMessages.getString(PKG, "AvroInputDialog.Shell.Title")); int middle = props.getMiddlePct(); int margin = Const.MARGIN; // Stepname line m_stepnameLabel = new Label(shell, SWT.RIGHT); m_stepnameLabel.setText(BaseMessages.getString(PKG, "AvroInputDialog.StepName.Label")); props.setLook(m_stepnameLabel); FormData fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.right = new FormAttachment(middle, -margin); fd.top = new FormAttachment(0, margin); m_stepnameLabel.setLayoutData(fd); m_stepnameText = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); m_stepnameText.setText(stepname); props.setLook(m_stepnameText); m_stepnameText.addModifyListener(lsMod); // format the text field fd = new FormData(); fd.left = new FormAttachment(middle, 0); fd.top = new FormAttachment(0, margin); fd.right = new FormAttachment(100, 0); m_stepnameText.setLayoutData(fd); m_wTabFolder = new CTabFolder(shell, SWT.BORDER); props.setLook(m_wTabFolder, Props.WIDGET_STYLE_TAB); m_wTabFolder.setSimple(false); // start of the source tab m_wSourceTab = new CTabItem(m_wTabFolder, SWT.NONE); m_wSourceTab.setText(BaseMessages.getString(PKG, "AvroInputDialog.SourceTab.Title")); Composite wSourceComp = new Composite(m_wTabFolder, SWT.NONE); props.setLook(wSourceComp); FormLayout sourceLayout = new FormLayout(); sourceLayout.marginWidth = 3; sourceLayout.marginHeight = 3; wSourceComp.setLayout(sourceLayout); // source in file line Label fileSourceL = new Label(wSourceComp, SWT.RIGHT); props.setLook(fileSourceL); fileSourceL.setText(BaseMessages.getString(PKG, "AvroInputDialog.FileSource.Label")); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(0, margin); fd.right = new FormAttachment(middle, -margin); fileSourceL.setLayoutData(fd); m_sourceInFileBut = new Button(wSourceComp, SWT.CHECK); props.setLook(m_sourceInFileBut); fd = new FormData(); fd.right = new FormAttachment(100, 0); fd.left = new FormAttachment(middle, 0); fd.top = new FormAttachment(0, margin); m_sourceInFileBut.setLayoutData(fd); m_sourceInFileBut.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { m_currentMeta.setChanged(); m_sourceInFieldBut.setSelection(!m_sourceInFileBut.getSelection()); checkWidgets(); } }); // source in field line Label fieldSourceL = new Label(wSourceComp, SWT.RIGHT); props.setLook(fieldSourceL); fieldSourceL.setText(BaseMessages.getString(PKG, "AvroInputDialog.FieldSource.Label")); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(m_sourceInFileBut, margin); fd.right = new FormAttachment(middle, -margin); fieldSourceL.setLayoutData(fd); m_sourceInFieldBut = new Button(wSourceComp, SWT.CHECK); props.setLook(m_sourceInFieldBut); fd = new FormData(); fd.right = new FormAttachment(100, 0); fd.left = new FormAttachment(middle, 0); fd.top = new FormAttachment(m_sourceInFileBut, margin); m_sourceInFieldBut.setLayoutData(fd); m_sourceInFieldBut.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { m_currentMeta.setChanged(); m_sourceInFileBut.setSelection(!m_sourceInFieldBut.getSelection()); checkWidgets(); } }); // filename line Label filenameL = new Label(wSourceComp, SWT.RIGHT); props.setLook(filenameL); filenameL.setText(BaseMessages.getString(PKG, "AvroInputDialog.Filename.Label")); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(m_sourceInFieldBut, margin); fd.right = new FormAttachment(middle, -margin); filenameL.setLayoutData(fd); m_avroFileBrowse = new Button(wSourceComp, SWT.PUSH | SWT.CENTER); props.setLook(m_avroFileBrowse); m_avroFileBrowse.setText(BaseMessages.getString(PKG, "AvroInputDialog.Button.FileBrowse")); fd = new FormData(); fd.right = new FormAttachment(100, 0); fd.top = new FormAttachment(m_sourceInFieldBut, 0); m_avroFileBrowse.setLayoutData(fd); // add listener to pop up VFS browse dialog m_avroFileBrowse.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { try { String[] fileFilters = new String[] { "*" }; String[] fileFilterNames = new String[] { BaseMessages.getString(TextFileInputMeta.class, "System.FileType.AllFiles") }; // get current file FileObject rootFile = null; FileObject initialFile = null; FileObject defaultInitialFile = null; if (m_avroFilenameText.getText() != null) { String fname = transMeta.environmentSubstitute(m_avroFilenameText.getText()); if (!Const.isEmpty(fname)) { initialFile = KettleVFS.getFileObject(fname); rootFile = initialFile.getFileSystem().getRoot(); } else { defaultInitialFile = KettleVFS.getFileObject(Spoon.getInstance().getLastFileOpened()); } } else { defaultInitialFile = KettleVFS.getFileObject("file:///c:/"); } if (rootFile == null) { rootFile = defaultInitialFile.getFileSystem().getRoot(); } VfsFileChooserDialog fileChooserDialog = Spoon.getInstance().getVfsFileChooserDialog(rootFile, initialFile); fileChooserDialog.defaultInitialFile = defaultInitialFile; FileObject selectedFile = fileChooserDialog.open(shell, null, HadoopSpoonPlugin.HDFS_SCHEME, true, null, fileFilters, fileFilterNames, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE); if (selectedFile != null) { m_avroFilenameText.setText(selectedFile.getURL().toString()); } } catch (Exception ex) { logError(BaseMessages.getString(PKG, "AvroInputDialog.Error.KettleFileException"), ex); new ErrorDialog(shell, stepname, BaseMessages.getString(PKG, "AvroInputDialog.Error.KettleFileException"), ex); } } }); m_avroFilenameText = new TextVar(transMeta, wSourceComp, SWT.SIMPLE | SWT.LEFT | SWT.BORDER); props.setLook(m_avroFilenameText); m_avroFilenameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { m_currentMeta.setChanged(); m_avroFilenameText.setToolTipText(transMeta.environmentSubstitute(m_avroFilenameText.getText())); } }); fd = new FormData(); fd.left = new FormAttachment(middle, 0); fd.top = new FormAttachment(m_sourceInFieldBut, margin); fd.right = new FormAttachment(m_avroFileBrowse, -margin); m_avroFilenameText.setLayoutData(fd); Label avroFieldNameL = new Label(wSourceComp, SWT.RIGHT); props.setLook(avroFieldNameL); avroFieldNameL.setText(BaseMessages.getString(PKG, "AvroInputDialog.AvroField.Label")); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(m_avroFilenameText, margin); fd.right = new FormAttachment(middle, -margin); avroFieldNameL.setLayoutData(fd); m_avroFieldNameText = new CCombo(wSourceComp, SWT.BORDER); props.setLook(m_avroFieldNameText); m_avroFieldNameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { m_currentMeta.setChanged(); m_avroFieldNameText.setToolTipText(transMeta.environmentSubstitute(m_avroFieldNameText.getText())); } }); fd = new FormData(); fd.left = new FormAttachment(middle, 0); fd.top = new FormAttachment(m_avroFilenameText, margin); fd.right = new FormAttachment(100, 0); m_avroFieldNameText.setLayoutData(fd); // json encoded check box Label jsonL = new Label(wSourceComp, SWT.RIGHT); props.setLook(jsonL); jsonL.setText(BaseMessages.getString(PKG, "AvroInputDialog.JsonEncoded.Label")); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(m_avroFieldNameText, margin); fd.right = new FormAttachment(middle, -margin); jsonL.setLayoutData(fd); jsonL.setToolTipText(BaseMessages.getString(PKG, "AvroInputDialog.JsonEncoded.TipText")); m_jsonEncodedBut = new Button(wSourceComp, SWT.CHECK); props.setLook(m_jsonEncodedBut); fd = new FormData(); fd.right = new FormAttachment(100, 0); fd.left = new FormAttachment(middle, 0); fd.top = new FormAttachment(m_avroFieldNameText, margin); m_jsonEncodedBut.setLayoutData(fd); m_jsonEncodedBut.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { m_currentMeta.setChanged(); } }); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(0, 0); fd.right = new FormAttachment(100, 0); fd.bottom = new FormAttachment(100, 0); wSourceComp.setLayoutData(fd); wSourceComp.layout(); m_wSourceTab.setControl(wSourceComp); // -- start of the schema tab m_wSchemaTab = new CTabItem(m_wTabFolder, SWT.NONE); m_wSchemaTab.setText(BaseMessages.getString(PKG, "AvroInputDialog.SchemaTab.Title")); Composite wSchemaComp = new Composite(m_wTabFolder, SWT.NONE); props.setLook(wSchemaComp); FormLayout schemaLayout = new FormLayout(); schemaLayout.marginWidth = 3; schemaLayout.marginHeight = 3; wSchemaComp.setLayout(schemaLayout); // schema filename line m_defaultSchemaL = new Label(wSchemaComp, SWT.RIGHT); props.setLook(m_defaultSchemaL); m_defaultSchemaL.setText(BaseMessages.getString(PKG, "AvroInputDialog.SchemaFilename.Label")); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(0, margin); fd.right = new FormAttachment(middle, -margin); m_defaultSchemaL.setLayoutData(fd); m_defaultSchemaL.setToolTipText(BaseMessages.getString(PKG, "AvroInputDialog.SchemaFilename.TipText")); m_schemaFileBrowse = new Button(wSchemaComp, SWT.PUSH | SWT.CENTER); props.setLook(m_schemaFileBrowse); m_schemaFileBrowse.setText(BaseMessages.getString(PKG, "AvroInputDialog.Button.FileBrowse")); fd = new FormData(); fd.right = new FormAttachment(100, 0); fd.top = new FormAttachment(0, 0); m_schemaFileBrowse.setLayoutData(fd); // add listener to pop up VFS browse dialog m_schemaFileBrowse.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { try { String[] fileFilters = new String[] { "*" }; String[] fileFilterNames = new String[] { BaseMessages.getString(TextFileInputMeta.class, "System.FileType.AllFiles") }; // get current file FileObject rootFile = null; FileObject initialFile = null; FileObject defaultInitialFile = null; if (m_schemaFilenameText.getText() != null) { String fname = transMeta.environmentSubstitute(m_schemaFilenameText.getText()); if (!Const.isEmpty(fname)) { initialFile = KettleVFS.getFileObject(fname); rootFile = initialFile.getFileSystem().getRoot(); } else { defaultInitialFile = KettleVFS.getFileObject(Spoon.getInstance().getLastFileOpened()); } } else { defaultInitialFile = KettleVFS.getFileObject("file:///c:/"); } if (rootFile == null) { rootFile = defaultInitialFile.getFileSystem().getRoot(); } VfsFileChooserDialog fileChooserDialog = Spoon.getInstance().getVfsFileChooserDialog(rootFile, initialFile); fileChooserDialog.defaultInitialFile = defaultInitialFile; FileObject selectedFile = fileChooserDialog.open(shell, null, HadoopSpoonPlugin.HDFS_SCHEME, true, null, fileFilters, fileFilterNames, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE); if (selectedFile != null) { m_schemaFilenameText.setText(selectedFile.getURL().toString()); } } catch (Exception ex) { logError(BaseMessages.getString(PKG, "AvroInputDialog.Error.KettleFileException"), ex); new ErrorDialog(shell, stepname, BaseMessages.getString(PKG, "AvroInputDialog.Error.KettleFileException"), ex); } } }); m_schemaFilenameText = new TextVar(transMeta, wSchemaComp, SWT.SIMPLE | SWT.LEFT | SWT.BORDER); props.setLook(m_schemaFilenameText); m_schemaFilenameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { m_currentMeta.setChanged(); m_avroFilenameText.setToolTipText(transMeta.environmentSubstitute(m_schemaFilenameText.getText())); } }); fd = new FormData(); fd.left = new FormAttachment(middle, 0); fd.top = new FormAttachment(0, margin); fd.right = new FormAttachment(m_schemaFileBrowse, -margin); m_schemaFilenameText.setLayoutData(fd); // Schema in field line Label schemaInFieldL = new Label(wSchemaComp, SWT.RIGHT); props.setLook(schemaInFieldL); schemaInFieldL.setText(BaseMessages.getString(PKG, "AvroInputDialog.SchemaInField.Label")); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(m_schemaFilenameText, margin); fd.right = new FormAttachment(middle, -margin); schemaInFieldL.setLayoutData(fd); m_schemaInFieldBut = new Button(wSchemaComp, SWT.CHECK); props.setLook(m_schemaInFieldBut); fd = new FormData(); fd.right = new FormAttachment(100, 0); fd.left = new FormAttachment(middle, 0); fd.top = new FormAttachment(m_schemaFilenameText, margin); m_schemaInFieldBut.setLayoutData(fd); m_schemaInFieldBut.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { m_currentMeta.setChanged(); checkWidgets(); } }); // schema is path line m_schemaInFieldIsPathL = new Label(wSchemaComp, SWT.RIGHT); props.setLook(m_schemaInFieldIsPathL); m_schemaInFieldIsPathL.setText(BaseMessages.getString(PKG, "AvroInputDialog.SchemaInFieldIsPath.Label")); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(m_schemaInFieldBut, margin); fd.right = new FormAttachment(middle, -margin); m_schemaInFieldIsPathL.setLayoutData(fd); m_schemaInFieldIsPathBut = new Button(wSchemaComp, SWT.CHECK); props.setLook(m_schemaInFieldIsPathBut); fd = new FormData(); fd.right = new FormAttachment(100, 0); fd.left = new FormAttachment(middle, 0); fd.top = new FormAttachment(m_schemaInFieldBut, margin); m_schemaInFieldIsPathBut.setLayoutData(fd); // cache schemas line m_cacheSchemasL = new Label(wSchemaComp, SWT.RIGHT); props.setLook(m_cacheSchemasL); m_cacheSchemasL.setText(BaseMessages.getString(PKG, "AvroInputDialog.CacheSchemas.Label")); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(m_schemaInFieldIsPathBut, margin); fd.right = new FormAttachment(middle, -margin); m_cacheSchemasL.setLayoutData(fd); m_cacheSchemasBut = new Button(wSchemaComp, SWT.CHECK); props.setLook(m_cacheSchemasBut); fd = new FormData(); fd.right = new FormAttachment(100, 0); fd.left = new FormAttachment(middle, 0); fd.top = new FormAttachment(m_schemaInFieldIsPathBut, margin); m_cacheSchemasBut.setLayoutData(fd); // schema field name line m_schemaFieldNameL = new Label(wSchemaComp, SWT.RIGHT); props.setLook(m_schemaFieldNameL); m_schemaFieldNameL.setText(BaseMessages.getString(PKG, "AvroInputDialog.SchemaFieldName.Label")); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(m_cacheSchemasBut, margin); fd.right = new FormAttachment(middle, -margin); m_schemaFieldNameL.setLayoutData(fd); m_schemaFieldNameText = new CCombo(wSchemaComp, SWT.BORDER); props.setLook(m_schemaFieldNameText); m_schemaFieldNameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { m_currentMeta.setChanged(); m_schemaFieldNameText .setToolTipText(transMeta.environmentSubstitute(m_schemaFieldNameText.getText())); } }); fd = new FormData(); fd.left = new FormAttachment(middle, 0); fd.top = new FormAttachment(m_cacheSchemasBut, margin); fd.right = new FormAttachment(100, 0); m_schemaFieldNameText.setLayoutData(fd); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(0, 0); fd.right = new FormAttachment(100, 0); fd.bottom = new FormAttachment(100, 0); wSchemaComp.setLayoutData(fd); wSchemaComp.layout(); m_wSchemaTab.setControl(wSchemaComp); // -- start of the fields tab m_wFieldsTab = new CTabItem(m_wTabFolder, SWT.NONE); m_wFieldsTab.setText(BaseMessages.getString(PKG, "AvroInputDialog.FieldsTab.Title")); Composite wFieldsComp = new Composite(m_wTabFolder, SWT.NONE); props.setLook(wFieldsComp); FormLayout fieldsLayout = new FormLayout(); fieldsLayout.marginWidth = 3; fieldsLayout.marginHeight = 3; wFieldsComp.setLayout(fieldsLayout); // missing fields button Label missingFieldsLab = new Label(wFieldsComp, SWT.RIGHT); props.setLook(missingFieldsLab); missingFieldsLab.setText(BaseMessages.getString(PKG, "AvroInputDialog.MissingFields.Label")); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(0, margin); fd.right = new FormAttachment(middle, -margin); missingFieldsLab.setLayoutData(fd); m_missingFieldsBut = new Button(wFieldsComp, SWT.CHECK); props.setLook(m_missingFieldsBut); fd = new FormData(); fd.right = new FormAttachment(100, 0); fd.left = new FormAttachment(middle, 0); fd.top = new FormAttachment(0, margin); m_missingFieldsBut.setLayoutData(fd); // get fields button m_getFields = new Button(wFieldsComp, SWT.PUSH); m_getFields.setText(BaseMessages.getString(PKG, "AvroInputDialog.Button.GetFields")); props.setLook(m_getFields); fd = new FormData(); fd.right = new FormAttachment(100, 0); fd.bottom = new FormAttachment(100, 0); m_getFields.setLayoutData(fd); m_getFields.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // populate table from schema getFields(); } }); wPreview = new Button(wFieldsComp, SWT.PUSH | SWT.CENTER); wPreview.setText(BaseMessages.getString(PKG, "System.Button.Preview")); props.setLook(wPreview); fd = new FormData(); fd.right = new FormAttachment(m_getFields, margin); fd.bottom = new FormAttachment(100, 0); wPreview.setLayoutData(fd); wPreview.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { preview(); } }); // fields stuff final ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "AvroInputDialog.Fields.FIELD_NAME"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "AvroInputDialog.Fields.FIELD_PATH"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "AvroInputDialog.Fields.FIELD_TYPE"), ColumnInfo.COLUMN_TYPE_CCOMBO, false), new ColumnInfo(BaseMessages.getString(PKG, "AvroInputDialog.Fields.FIELD_INDEXED"), ColumnInfo.COLUMN_TYPE_TEXT, false), }; colinf[2].setComboValues(ValueMeta.getTypes()); m_fieldsView = new TableView(transMeta, wFieldsComp, SWT.FULL_SELECTION | SWT.MULTI, colinf, 1, lsMod, props); fd = new FormData(); fd.top = new FormAttachment(m_missingFieldsBut, margin * 2); fd.bottom = new FormAttachment(m_getFields, -margin * 2); fd.left = new FormAttachment(0, 0); fd.right = new FormAttachment(100, 0); m_fieldsView.setLayoutData(fd); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(0, 0); fd.right = new FormAttachment(100, 0); fd.bottom = new FormAttachment(100, 0); wFieldsComp.setLayoutData(fd); wFieldsComp.layout(); m_wFieldsTab.setControl(wFieldsComp); // -- start of the variables tab m_wVarsTab = new CTabItem(m_wTabFolder, SWT.NONE); m_wVarsTab.setText(BaseMessages.getString(PKG, "AvroInputDialog.VarsTab.Title")); Composite wVarsComp = new Composite(m_wTabFolder, SWT.NONE); props.setLook(wVarsComp); FormLayout varsLayout = new FormLayout(); varsLayout.marginWidth = 3; varsLayout.marginHeight = 3; wVarsComp.setLayout(varsLayout); // lookup fields (variables) tab final ColumnInfo[] colinf2 = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "AvroInputDialog.Fields.LOOKUP_NAME"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "AvroInputDialog.Fields.LOOKUP_VARIABLE"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "AvroInputDialog.Fields.LOOKUP_DEFAULT_VALUE"), ColumnInfo.COLUMN_TYPE_TEXT, false), }; // get lookup fields but m_getLookupFieldsBut = new Button(wVarsComp, SWT.PUSH | SWT.CENTER); props.setLook(m_getLookupFieldsBut); m_getLookupFieldsBut.setText(BaseMessages.getString(PKG, "AvroInputDialog.Button.GetLookupFields")); fd = new FormData(); fd.right = new FormAttachment(100, 0); fd.bottom = new FormAttachment(100, -margin * 2); m_getLookupFieldsBut.setLayoutData(fd); m_getLookupFieldsBut.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // get incoming field names getIncomingFields(); } }); m_lookupView = new TableView(transMeta, wVarsComp, SWT.FULL_SELECTION | SWT.MULTI, colinf2, 1, lsMod, props); fd = new FormData(); fd.top = new FormAttachment(0, margin * 2); fd.bottom = new FormAttachment(m_getLookupFieldsBut, -margin * 2); fd.left = new FormAttachment(0, 0); fd.right = new FormAttachment(100, 0); m_lookupView.setLayoutData(fd); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(0, 0); fd.right = new FormAttachment(100, 0); fd.bottom = new FormAttachment(100, 0); wVarsComp.setLayoutData(fd); wVarsComp.layout(); m_wVarsTab.setControl(wVarsComp); fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(m_stepnameText, margin); fd.right = new FormAttachment(100, 0); fd.bottom = new FormAttachment(100, -50); m_wTabFolder.setLayoutData(fd); populateFieldsCombo(); // Buttons inherited from BaseStepDialog 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, m_wTabFolder); // Add listeners lsCancel = new Listener() { public void handleEvent(Event e) { cancel(); } }; lsOK = new Listener() { public void handleEvent(Event e) { ok(); } }; wCancel.addListener(SWT.Selection, lsCancel); wOK.addListener(SWT.Selection, lsOK); lsDef = new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { ok(); } }; m_stepnameText.addSelectionListener(lsDef); // Detect X or ALT-F4 or something that kills this window... shell.addShellListener(new ShellAdapter() { @Override public void shellClosed(ShellEvent e) { cancel(); } }); m_wTabFolder.setSelection(0); setSize(); getData(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } return stepname; }
From source file:org.pentaho.di.ui.core.widget.VfsFileChooserControls.java
protected void browseForFileInputPath() { try {//w w w . j a v a 2 s . co m String path = space.environmentSubstitute(wPath.getText()); VfsFileChooserDialog fileChooserDialog; String fileName; if (path == null || path.length() == 0) { fileChooserDialog = getVfsFileChooserDialog(null, null); fileName = selectedVFSScheme.scheme + "://"; } else { FileObject initialFile = getInitialFile(wPath.getText()); FileObject rootFile = initialFile.getFileSystem().getRoot(); fileChooserDialog = getVfsFileChooserDialog(rootFile, initialFile); fileName = null; } FileObject selectedFile = fileChooserDialog.open(getParent().getShell(), null, selectedVFSScheme.scheme, true, fileName, FILES_FILTERS, fileFilterNames, true, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE_OR_DIRECTORY, true, true); if (selectedFile != null) { String filePath = selectedFile.getURL().toString(); if (!DEFAULT_LOCAL_PATH.equals(filePath)) { wPath.setText(filePath); updateLocation(); } } } catch (KettleFileException | FileSystemException ex) { log.logError(ex.getMessage()); } }
From source file:org.pentaho.di.ui.job.entries.copyfiles.JobEntryCopyFilesDialog.java
protected SelectionAdapter getFileSelectionAdapter() { return new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FileObject selectedFile = null; try { // Get current file FileObject rootFile = null; FileObject initialFile = null; FileObject defaultInitialFile = null; String original = wFields.getActiveTableItem().getText(wFields.getActiveTableColumn()); if (original != null) { String fileName = jobMeta.environmentSubstitute(original); if (fileName != null && !fileName.equals("")) { try { initialFile = KettleVFS.getFileObject(fileName); } catch (KettleException ex) { initialFile = KettleVFS.getFileObject(""); }//from w w w .j a va2 s . c om defaultInitialFile = KettleVFS.getFileObject("file:///c:/"); rootFile = initialFile.getFileSystem().getRoot(); } else { defaultInitialFile = KettleVFS.getFileObject(Spoon.getInstance().getLastFileOpened()); } } if (rootFile == null) { rootFile = defaultInitialFile.getFileSystem().getRoot(); initialFile = defaultInitialFile; } VfsFileChooserDialog fileChooserDialog = Spoon.getInstance().getVfsFileChooserDialog(rootFile, initialFile); fileChooserDialog.defaultInitialFile = defaultInitialFile; selectedFile = fileChooserDialog.open(shell, new String[] { "file" }, "file", true, null, new String[] { "*.*" }, FILETYPES, true, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE_OR_DIRECTORY, false, false); if (selectedFile != null) { String url = selectedFile.getURL().toString(); wFields.getActiveTableItem().setText(wFields.getActiveTableColumn(), url); } } catch (KettleFileException ex) { } catch (FileSystemException ex) { } } }; }
From source file:org.pentaho.hadoop.PropertiesConfigurationProperties.java
private static PropertiesConfiguration initPropertiesConfiguration(FileObject fileObject) throws FileSystemException, ConfigurationException { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(fileObject.getURL()); propertiesConfiguration.setAutoSave(true); FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy(); fileChangedReloadingStrategy.setRefreshDelay(1000L); propertiesConfiguration.setReloadingStrategy(fileChangedReloadingStrategy); return propertiesConfiguration; }
From source file:org.pentaho.hadoop.shim.common.DistributedCacheUtilImpl.java
/** * Stages the source file or folder to a Hadoop file system and sets their permission and replication value * appropriately to be used with the Distributed Cache. WARNING: This will delete the contents of dest before staging * the archive.//from ww w . ja v a2 s . c o m * * @param source File or folder to copy to the file system. If it is a folder all contents will be copied into * dest. * @param fs Hadoop file system to store the contents of the archive in * @param dest Destination to copy source into. If source is a file, the new file name will be exactly dest. If * source is a folder its contents will be copied into dest. For more info see {@link * FileSystem#copyFromLocalFile(org.apache.hadoop.fs.Path, org.apache.hadoop.fs.Path)}. * @param overwrite Should an existing file or folder be overwritten? If not an exception will be thrown. * @throws IOException Destination exists is not a directory * @throws KettleFileException Source does not exist or destination exists and overwrite is false. */ public void stageForCache(FileObject source, FileSystem fs, Path dest, boolean overwrite, boolean isPublic) throws IOException, KettleFileException { if (!source.exists()) { throw new KettleFileException(BaseMessages.getString(DistributedCacheUtilImpl.class, "DistributedCacheUtil.SourceDoesNotExist", source)); } if (fs.exists(dest)) { if (overwrite) { // It is a directory, clear it out fs.delete(dest, true); } else { throw new KettleFileException(BaseMessages.getString(DistributedCacheUtilImpl.class, "DistributedCacheUtil.DestinationExists", dest.toUri().getPath())); } } // Use the same replication we'd use for submitting jobs short replication = (short) fs.getConf().getInt("mapred.submit.replication", 10); if (source.getURL().toString().endsWith(CONFIG_PROPERTIES)) { copyConfigProperties(source, fs, dest); } else { Path local = new Path(source.getURL().getPath()); fs.copyFromLocalFile(local, dest); } if (isPublic) { fs.setPermission(dest, PUBLIC_CACHED_FILE_PERMISSION); } else { fs.setPermission(dest, CACHED_FILE_PERMISSION); } fs.setReplication(dest, replication); }