List of usage examples for org.apache.commons.vfs2 FileObject getFileSystem
FileSystem getFileSystem();
From source file:org.pentaho.di.trans.steps.avroinput.AvroInputDialog.java
public String open() { Shell parent = getParent();/* w w w . j a va 2 s . c om*/ 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 {//from w w w. j ava 2 s. c om 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 ww .ja va2s . co m 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.reporting.designer.extensions.pentaho.drilldown.PentahoParameterRefreshHandler.java
private static String getParameterServicePath(final AuthenticationData loginData, final PentahoPathModel pathModel) { try {/*from www . j a va 2s . c o m*/ final FileObject fileSystemRoot = PublishUtil.createVFSConnection(VFS.getManager(), loginData); final FileSystem fileSystem = fileSystemRoot.getFileSystem(); // as of version 3.7 we do not need to check anything other than that the version information is there // later we may have to add additional checks in here to filter out known broken versions. final String localPath = pathModel.getLocalPath(); final FileObject object = fileSystemRoot.resolveFile(localPath); final FileContent content = object.getContent(); final String majorVersionText = (String) fileSystem.getAttribute(WebSolutionFileSystem.MAJOR_VERSION); if (StringUtils.isEmpty(majorVersionText) == false) { final String paramService = (String) content.getAttribute("param-service-url"); if (StringUtils.isEmpty(paramService)) { return null; } if (paramService.startsWith("http://") || paramService.startsWith("https://")) { return paramService; } try { // Encode the URL (must use URI as URL encoding doesn't work on spaces correctly) final URL target = new URL(loginData.getUrl()); final String host; if (target.getPort() != -1) { host = target.getHost() + ":" + target.getPort(); } else { host = target.getHost(); } return target.getProtocol() + "://" + host + paramService; } catch (MalformedURLException e) { UncaughtExceptionsModel.getInstance().addException(e); return null; } } final String extension = IOUtils.getInstance().getFileExtension(localPath); if (".prpt".equals(extension)) { logger.debug( "Ancient pentaho system detected: parameter service does not deliver valid parameter values"); final String name = pathModel.getName(); final String path = pathModel.getPath(); final String solution = pathModel.getSolution(); final FastMessageFormat messageFormat = new FastMessageFormat( "/content/reporting/?renderMode=XML&solution={0}&path={1}&name={2}"); messageFormat.setNullString(""); return loginData.getUrl() + messageFormat.format(new Object[] { solution, path, name }); } logger.debug("Ancient pentaho system detected: We will not have access to a working parameter service"); return null; } catch (FileSystemException e) { UncaughtExceptionsModel.getInstance().addException(e); return null; } }
From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.actions.PublishToServerTask.java
public void run() { final MasterReport report = reportDesignerContext.getActiveContext().getContextRoot(); final DocumentMetaData metaData = report.getBundle().getMetaData(); try {/*from w w w . j ava 2 s. co m*/ final String oldName = extractLastFileName(report); SelectFileForPublishTask selectFileForPublishTask = new SelectFileForPublishTask(uiContext); readBundleMetaData(report, metaData, selectFileForPublishTask); final String selectedReport = selectFileForPublishTask.selectFile(loginData, oldName); if (selectedReport == null) { return; } loginData.setOption("lastFilename", selectedReport); storeBundleMetaData(report, selectedReport, selectFileForPublishTask); reportDesignerContext.getActiveContext().getAuthenticationStore().add(loginData, storeUpdates); final byte[] data = PublishUtil.createBundleData(report); int responseCode = PublishUtil.publish(data, selectedReport, loginData); if (responseCode == 200) { final Component glassPane = SwingUtilities.getRootPane(uiContext).getGlassPane(); try { glassPane.setVisible(true); glassPane.setCursor(new Cursor(Cursor.WAIT_CURSOR)); FileObject fileSystemRoot = PublishUtil.createVFSConnection(loginData); final JCRSolutionFileSystem fileSystem = (JCRSolutionFileSystem) fileSystemRoot.getFileSystem(); fileSystem.getLocalFileModel().refresh(); } catch (Exception e1) { UncaughtExceptionsModel.getInstance().addException(e1); } finally { glassPane.setVisible(false); glassPane.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } if (JOptionPane.showConfirmDialog(uiContext, Messages.getInstance().getString("PublishToServerAction.Successful.LaunchNow"), Messages.getInstance().getString("PublishToServerAction.Successful.LaunchTitle"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { PublishUtil.launchReportOnServer(loginData.getUrl(), selectedReport); } } else if (responseCode == 403) { logger.error("Publish failed. Server responded with status-code " + responseCode); JOptionPane.showMessageDialog(uiContext, Messages.getInstance().getString("PublishToServerAction.FailedAccess"), Messages.getInstance().getString("PublishToServerAction.FailedAccessTitle"), JOptionPane.ERROR_MESSAGE); } else { logger.error("Publish failed. Server responded with status-code " + responseCode); showErrorMessage(); } } catch (Exception exception) { logger.error("Publish failed. Unexpected error:", exception); showErrorMessage(); } }
From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.actions.ValidateLoginTask.java
public boolean validateLoginData() throws FileSystemException { if (loginData == null) { return true; }//from w w w. j a va 2 s .c o m final FileObject vfsConnection = PublishUtil.createVFSConnection(VFS.getManager(), loginData); try { final FileSystem fileSystem = vfsConnection.getFileSystem(); if (fileSystem instanceof WebSolutionFileSystem) { final WebSolutionFileSystem webSolutionFileSystem = (WebSolutionFileSystem) fileSystem; final Long l = (Long) webSolutionFileSystem .getAttribute(WebSolutionFileSystem.LAST_REFRESH_TIME_ATTRIBUTE); if (l != null) { if ((System.currentTimeMillis() - l) > 500) { webSolutionFileSystem.getLocalFileModel().refresh(); } } return true; } } catch (FileSystemException fse) { // not all file systems support attributes .. } catch (IOException e) { return false; } final FileType type = vfsConnection.getType(); if (type != FileType.FOLDER) { return false; } return true; }
From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.dialogs.RepositoryPublishDialog.java
protected boolean validateInputs(final boolean onConfirm) { if (super.validateInputs(onConfirm) == false) { return false; }/*from ww w . j a va2 s. c o m*/ if (onConfirm == false) { return true; } final String reportName = getFileNameTextField().getText(); if (StringUtils.isEmpty(reportName) == false && reportName.endsWith(REPORT_BUNDLE_EXTENSION) == false) { final String safeReportName = reportName + REPORT_BUNDLE_EXTENSION; getFileNameTextField().setText(safeReportName); } try { final FileObject selectedView = getSelectedView(); final String validateName = getSelectedFile(); if (validateName == null || selectedView == null) { return false; } String filename = getFileNameTextField().getText(); if (!PublishUtil.validateName(filename)) { JOptionPane.showMessageDialog(RepositoryPublishDialog.this, Messages.getInstance().formatMessage("PublishToServerAction.IllegalName", filename, PublishUtil.getReservedCharsDisplay()), Messages.getInstance().getString("PublishToServerAction.Error.Title"), JOptionPane.ERROR_MESSAGE); return false; } final FileObject targetFile = selectedView .resolveFile(URLEncoder.encodeUTF8(getFileNameTextField().getText()).replaceAll(":", "%3A") .replaceAll("\\+", "%2B").replaceAll("\\!", "%21")); final FileObject fileObject = selectedView.getFileSystem().resolveFile(targetFile.getName()); if (fileObject.getType() == FileType.IMAGINARY) { return true; } final int result = JOptionPane.showConfirmDialog(this, Messages.getInstance().formatMessage("PublishToServerAction.FileExistsOverride", validateName), Messages.getInstance().getString("PublishToServerAction.Information.Title"), JOptionPane.YES_NO_OPTION); return result == JOptionPane.YES_OPTION; } catch (FileSystemException fse) { UncaughtExceptionsModel.getInstance().addException(fse); return false; } catch (UnsupportedEncodingException uee) { UncaughtExceptionsModel.getInstance().addException(uee); return false; } }
From source file:org.pentaho.vfs.ui.VfsFileChooserDialog.java
public void createCustomUIPanel(final Shell dialog) { customUIPanel = new Composite(dialog, SWT.NONE); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false); customUIPanel.setLayoutData(gridData); customUIPanel.setLayout(new GridLayout(1, false)); comboPanel = new Composite(customUIPanel, SWT.NONE); comboPanel.setLayoutData(gridData);/*from w ww.ja va 2 s . c o m*/ comboPanel.setLayout(new GridLayout(2, false)); comboPanel.setData("donotremove"); Label lookInLabel = new Label(comboPanel, SWT.NONE); lookInLabel.setText(Messages.getString("VfsFileChooserDialog.LookIn")); gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false); lookInLabel.setLayoutData(gridData); customUIPicker = new Combo(comboPanel, SWT.READ_ONLY); gridData = new GridData(SWT.LEFT, SWT.CENTER, true, false); customUIPicker.setLayoutData(gridData); if (!showLocation) { comboPanel.setParent(fakeShell); } if (!showCustomUI) { customUIPanel.setParent(fakeShell); } customUIPicker.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent event) { selectCustomUI(); } public void widgetDefaultSelected(SelectionEvent event) { selectCustomUI(); } }); customUIPicker.addKeyListener(new KeyListener() { public void keyReleased(KeyEvent arg0) { selectCustomUI(); } public void keyPressed(KeyEvent arg0) { selectCustomUI(); } }); boolean createdLocal = false; for (CustomVfsUiPanel panel : customUIPanels) { if (panel.getVfsScheme().equals("file")) { createdLocal = true; } } if (!createdLocal) { CustomVfsUiPanel localPanel = new CustomVfsUiPanel("file", "Local", this, SWT.None) { public void activate() { try { File startFile = new File(System.getProperty("user.home")); if (startFile == null || !startFile.exists()) { startFile = File.listRoots()[0]; } FileObject dot = fsm.resolveFile(startFile.toURI().toURL().toExternalForm()); rootFile = dot.getFileSystem().getRoot(); selectedFile = rootFile; setInitialFile(selectedFile); openFileCombo.setText(selectedFile.getName().getURI()); resolveVfsBrowser(); } catch (Throwable t) { } } }; addVFSUIPanel(localPanel); } }
From source file:org.pentaho.vfs.ui.VfsFileChooserDialog.java
public FileObject open(Shell applicationShell, String[] schemeRestrictions, String initialScheme, boolean showFileScheme, String fileName, String[] fileFilters, String[] fileFilterNames, boolean returnUserAuthenticatedFile, int fileDialogMode, boolean showLocation, boolean showCustomUI) { this.fileDialogMode = fileDialogMode; this.fileFilters = fileFilters; this.fileFilterNames = fileFilterNames; this.applicationShell = applicationShell; this.showFileScheme = showFileScheme; this.initialScheme = initialScheme; this.schemeRestrictions = schemeRestrictions; this.showLocation = showLocation; this.showCustomUI = showCustomUI; FileObject tmpInitialFile = initialFile; if (defaultInitialFile != null && rootFile == null) { try {//from ww w . j av a 2s.c om rootFile = defaultInitialFile.getFileSystem().getRoot(); initialFile = defaultInitialFile; } catch (FileSystemException ignored) { // well we tried } } createDialog(applicationShell); if (!showLocation) { comboPanel.setParent(fakeShell); } else { comboPanel.setParent(customUIPanel); } if (!showCustomUI) { customUIPanel.setParent(fakeShell); } else { customUIPanel.setParent(dialog); } // create our file chooser tool bar, contains parent folder combo and various controls createToolbarPanel(dialog); // create our vfs browser component createVfsBrowser(dialog); populateCustomUIPanel(dialog); if (fileDialogMode == VFS_DIALOG_SAVEAS) { createFileNamePanel(dialog, fileName); } else { // create file filter panel createFileFilterPanel(dialog); } // create our ok/cancel buttons createButtonPanel(dialog); initialFile = tmpInitialFile; // set the initial file selection try { if (initialFile != null || rootFile != null) { vfsBrowser.selectTreeItemByFileObject(initialFile != null ? initialFile : rootFile, true); updateParentFileCombo(initialFile != null ? initialFile : rootFile); setSelectedFile(initialFile != null ? initialFile : rootFile); openFileCombo.setText( initialFile != null ? initialFile.getName().getURI() : rootFile.getName().getURI()); } } catch (FileSystemException e) { MessageBox box = new MessageBox(dialog.getShell()); box.setText(Messages.getString("VfsFileChooserDialog.error")); //$NON-NLS-1$ box.setMessage(e.getMessage()); box.open(); } // set the size and show the dialog int height = 550; int width = 800; dialog.setSize(width, height); Rectangle bounds = dialog.getDisplay().getPrimaryMonitor().getClientArea(); int x = (bounds.width - width) / 2; int y = (bounds.height - height) / 2; dialog.setLocation(x, y); dialog.open(); if (rootFile != null && fileDialogMode == VFS_DIALOG_SAVEAS) { if (!rootFile.getFileSystem().hasCapability(Capability.WRITE_CONTENT)) { MessageBox messageDialog = new MessageBox(dialog.getShell(), SWT.OK); messageDialog.setText(Messages.getString("VfsFileChooserDialog.warning")); //$NON-NLS-1$ messageDialog.setMessage(Messages.getString("VfsFileChooserDialog.noWriteSupport")); //$NON-NLS-1$ messageDialog.open(); } } vfsBrowser.fileSystemTree.forceFocus(); while (!dialog.isDisposed()) { if (!dialog.getDisplay().readAndDispatch()) dialog.getDisplay().sleep(); } // we just woke up, we are probably disposed already.. if (!dialog.isDisposed()) { hideCustomPanelChildren(); dialog.dispose(); } if (okPressed) { FileObject returnFile = vfsBrowser.getSelectedFileObject(); if (returnFile != null && fileDialogMode == VFS_DIALOG_SAVEAS) { try { if (returnFile.getType().equals(FileType.FILE)) { returnFile = returnFile.getParent(); } returnFile = returnFile.resolveFile(enteredFileName); } catch (FileSystemException e) { e.printStackTrace(); } } // put user/pass on the filename so it comes out in the getUri call. if (!returnUserAuthenticatedFile) { // make sure to put the user/pass on the url if it's not there if (returnFile != null && returnFile.getName() instanceof URLFileName) { URLFileName urlFileName = (URLFileName) returnFile.getName(); if (urlFileName.getUserName() == null || urlFileName.getPassword() == null) { // set it String user = ""; String pass = ""; UserAuthenticator userAuthenticator = DefaultFileSystemConfigBuilder.getInstance() .getUserAuthenticator(returnFile.getFileSystem().getFileSystemOptions()); if (userAuthenticator != null) { UserAuthenticationData data = userAuthenticator .requestAuthentication(AUTHENTICATOR_TYPES); user = String.valueOf(data.getData(UserAuthenticationData.USERNAME)); pass = String.valueOf(data.getData(UserAuthenticationData.PASSWORD)); try { user = URLEncoder.encode(user, "UTF-8"); pass = URLEncoder.encode(pass, "UTF-8"); } catch (UnsupportedEncodingException e) { // ignore, just use the un encoded values } } // build up the url with user/pass on it int port = urlFileName.getPort(); String portString = (port < 1) ? "" : (":" + port); String urlWithUserPass = urlFileName.getScheme() + "://" + user + ":" + pass + "@" + urlFileName.getHostName() + portString + urlFileName.getPath(); try { returnFile = currentPanel.resolveFile(urlWithUserPass); } catch (FileSystemException e) { // couldn't resolve with user/pass on url??? interesting e.printStackTrace(); } } } } return returnFile; } else { return null; } }
From source file:org.pentaho.vfs.ui.VfsFileChooserDialog.java
public void fireFileObjectDoubleClicked(FileObject selectedItem) { if (fileDialogMode != VFS_DIALOG_SAVEAS) { // let's try drilling into the file as a new vfs root first String scheme = null;/* w w w. j ava2 s .c o m*/ if (selectedItem.getName().getExtension().contains("jar")) { scheme = "jar:"; } else if (selectedItem.getName().getExtension().contains("zip")) { scheme = "zip:"; } else if (selectedItem.getName().getExtension().contains("gz")) { scheme = "gz:"; } else if (selectedItem.getName().getExtension().contains("war")) { scheme = "war:"; } else if (selectedItem.getName().getExtension().contains("ear")) { scheme = "ear:"; } else if (selectedItem.getName().getExtension().contains("sar")) { scheme = "sar:"; } else if (selectedItem.getName().getExtension().contains("tar")) { scheme = "tar:"; } else if (selectedItem.getName().getExtension().contains("tbz2")) { scheme = "tbz2:"; } else if (selectedItem.getName().getExtension().contains("tgz")) { scheme = "tgz:"; } else if (selectedItem.getName().getExtension().contains("bz2")) { scheme = "bz2:"; } if (scheme != null) { try { FileObject jarFileObject = selectedItem.getFileSystem().getFileSystemManager() .resolveFile(scheme + selectedItem.getName().getURI()); vfsBrowser.resetVfsRoot(jarFileObject); updateParentFileCombo(jarFileObject); vfsBrowser.fileSystemTree.forceFocus(); } catch (FileSystemException e) { e.printStackTrace(); okPressed = true; hideCustomPanelChildren(); dialog.dispose(); } } else { okPressed = true; hideCustomPanelChildren(); dialog.dispose(); } } else { // anything? } }