List of usage examples for org.apache.commons.vfs FileObject getFileSystem
public FileSystem getFileSystem();
From source file:org.objectweb.proactive.extensions.dataspaces.vfs.VFSMountManagerHelper.java
/** * tries to close the FileSystems represented by the given urls * * @param uris file system uris/*w w w .j av a2 s . co m*/ */ public static void closeFileSystems(Collection<String> uris) { try { writeLock.lock(); for (String uri : uris) { if (alreadyMountedSpaces.containsKey(uri)) { Future<FileObject> future = alreadyMountedSpaces.remove(uri); if (future.isDone()) { try { FileObject fo = future.get(); final FileSystem spaceFileSystem = fo.getFileSystem(); // we may not need to close FileObject, but with VFS you never know... try { fo.close(); } catch (org.apache.commons.vfs.FileSystemException x) { logger.debug("Could not close data space root file object : " + fo, x); ProActiveLogger.logEatedException(logger, String.format("Could not close data space %s root file object", fo), x); } vfsManager.closeFileSystem(spaceFileSystem); if (logger.isDebugEnabled()) logger.debug("Unmounted space: " + fo); } catch (InterruptedException e) { // ignore } catch (ExecutionException e) { // ignore } } else { future.cancel(true); } } } } finally { writeLock.unlock(); } }
From source file:org.ofbiz.commons.vfs.ofbiz.OfbizComponentProvider.java
public FileObject findFile(FileObject base, String name, FileSystemOptions properties) throws FileSystemException { try {/* w ww . ja v a 2 s . com*/ //name = name.replaceAll("^ofbiz-component://", ""); int nameLength = name.length(); int componentNameStart = 16; while (componentNameStart < nameLength && name.charAt(componentNameStart) == '/') componentNameStart++; if (componentNameStart == nameLength) throw new IllegalArgumentException("Invalid name(" + name + ")"); int componentNameEnd = componentNameStart; while (componentNameEnd < nameLength && name.charAt(componentNameEnd) != '/') componentNameEnd++; if (componentNameEnd == nameLength) throw new IllegalArgumentException("Invalid name(" + name + ")"); int restStart = componentNameEnd; while (restStart < nameLength && name.charAt(restStart) == '/') restStart++; if (restStart == nameLength) throw new IllegalArgumentException("Invalid name(" + name + ")"); String componentName = name.substring(componentNameStart, componentNameEnd); URL location = FlexibleLocation.resolveLocation("component://" + componentName + "/."); FileObject ofbizBase = getContext().resolveFile(location.toString(), properties); return VFSUtil.toFileObject(ofbizBase.getFileSystem().getFileSystemManager(), ofbizBase.resolveFile(name.substring(restStart)).getURL().toString(), properties); } catch (Exception e) { FileSystemException fse = new FileSystemException(e.getMessage(), null, e); fse.initCause(e); throw fse; } }
From source file:org.ofbiz.commons.vfs.ofbiz.OfbizHomeProvider.java
public FileObject findFile(FileObject base, String name, FileSystemOptions properties) throws FileSystemException { //new Exception("findFile(" + base + ", " + name + ")").printStackTrace(); try {//w w w .jav a 2 s. c om URL location = FlexibleLocation.resolveLocation("ofbizhome://."); FileObject ofbizBase = getContext().resolveFile(location.toString(), properties); return VFSUtil.toFileObject(ofbizBase.getFileSystem().getFileSystemManager(), ofbizBase.resolveFile(name.substring(13)).getURL().toString(), properties); } catch (Exception e) { FileSystemException fse = new FileSystemException(e.getMessage(), null, e); fse.initCause(e); throw fse; } }
From source file:org.openbi.kettle.plugins.parquetoutput.ParquetOutputDialog.java
public String open() { Shell parent = getParent();/*from w ww . j av a 2s .c o m*/ 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(BaseMessages.getString(PKG, "ParquetOutputDialog.DialogTitle")); 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, "ParquetOutputDialog.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, "ParquetOutputDialog.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); // Create Schema File // wlFilenameInField = new Label(wFileComp, SWT.RIGHT); wlFilenameInField.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.FilenameInField.Label")); props.setLook(wlFilenameInField); fdlFilenameInField = new FormData(); fdlFilenameInField.left = new FormAttachment(0, 0); fdlFilenameInField.top = new FormAttachment(wFilename, 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(wFilename, margin); fdFilenameInField.right = new FormAttachment(100, 0); wFilenameInField.setLayoutData(fdFilenameInField); wFilenameInField.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); setFilenameInField(); } }); // input Field Line wlFilenameField = new Label(wFileComp, SWT.RIGHT); wlFilenameField.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.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 */ // Clean Output // wlCleanOutput = new Label(wFileComp, SWT.RIGHT); wlCleanOutput.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.CleanOutput.Label")); props.setLook(wlCleanOutput); fdlCleanOutput = new FormData(); fdlCleanOutput.left = new FormAttachment(0, 0); fdlCleanOutput.top = new FormAttachment(wFilenameField, margin); fdlCleanOutput.right = new FormAttachment(middle, -margin); wlCleanOutput.setLayoutData(fdlCleanOutput); wCleanOutput = new Button(wFileComp, SWT.CHECK); wCleanOutput.setToolTipText(BaseMessages.getString(PKG, "ParquetOutputDialog.CleanOutput.Tooltip")); props.setLook(wCleanOutput); fdCleanOutput = new FormData(); fdCleanOutput.left = new FormAttachment(middle, 0); fdCleanOutput.top = new FormAttachment(wFilenameField, margin); fdCleanOutput.right = new FormAttachment(100, 0); wCleanOutput.setLayoutData(fdCleanOutput); wCleanOutput.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); // Create Parent Folder? // wlCreateParentFolder = new Label(wFileComp, SWT.RIGHT); wlCreateParentFolder.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.CreateParentFolder.Label")); props.setLook(wlCreateParentFolder); fdlCreateParentFolder = new FormData(); fdlCreateParentFolder.left = new FormAttachment(0, 0); fdlCreateParentFolder.top = new FormAttachment(wCleanOutput, margin); fdlCreateParentFolder.right = new FormAttachment(middle, -margin); wlCreateParentFolder.setLayoutData(fdlCreateParentFolder); wCreateParentFolder = new Button(wFileComp, SWT.CHECK); wCreateParentFolder .setToolTipText(BaseMessages.getString(PKG, "ParquetOutputDialog.CreateParentFolder.Tooltip")); props.setLook(wCreateParentFolder); fdCreateParentFolder = new FormData(); fdCreateParentFolder.left = new FormAttachment(middle, 0); fdCreateParentFolder.top = new FormAttachment(wCleanOutput, margin); fdCreateParentFolder.right = new FormAttachment(100, 0); wCreateParentFolder.setLayoutData(fdCreateParentFolder); wCreateParentFolder.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { input.setChanged(); } }); // Create multi-part file? wlAddStepnr = new Label(wFileComp, SWT.RIGHT); wlAddStepnr.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.AddStepnr.Label")); props.setLook(wlAddStepnr); fdlAddStepnr = new FormData(); fdlAddStepnr.left = new FormAttachment(0, 0); fdlAddStepnr.top = new FormAttachment(wCreateParentFolder, 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(wCreateParentFolder, 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, "ParquetOutputDialog.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, "ParquetOutputDialog.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(); // System.out.println("wAddDate.getSelection()="+wAddDate.getSelection()); } }); // Create multi-part file? wlAddTime = new Label(wFileComp, SWT.RIGHT); wlAddTime.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.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, "ParquetOutputDialog.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, "ParquetOutputDialog.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, "ParquetOutputDialog.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 ComboVar(transMeta, 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(75, 0); wDateTimeFormat.setLayoutData(fdDateTimeFormat); String[] dats = Const.getDateFormats(); for (String dat : dats) { wDateTimeFormat.add(dat); } // Add File to the result files name wlAddToResult = new Label(wFileComp, SWT.RIGHT); wlAddToResult.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.AddFileToResult.Label")); props.setLook(wlAddToResult); fdlAddToResult = new FormData(); fdlAddToResult.left = new FormAttachment(0, 0); fdlAddToResult.top = new FormAttachment(wDateTimeFormat, 2 * margin); fdlAddToResult.right = new FormAttachment(middle, -margin); wlAddToResult.setLayoutData(fdlAddToResult); wAddToResult = new Button(wFileComp, SWT.CHECK); wAddToResult.setToolTipText(BaseMessages.getString(PKG, "ParquetOutputDialog.AddFileToResult.Tooltip")); props.setLook(wAddToResult); fdAddToResult = new FormData(); fdAddToResult.left = new FormAttachment(middle, 0); fdAddToResult.top = new FormAttachment(wDateTimeFormat, 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, "ParquetOutputDialog.ContentTab.TabTitle")); FormLayout contentLayout = new FormLayout(); contentLayout.marginWidth = Const.FORM_MARGIN; contentLayout.marginHeight = Const.FORM_MARGIN; Composite wContentComp = new Composite(wTabFolder, SWT.NONE); wContentComp.setLayout(contentLayout); props.setLook(wContentComp); // Block size Line wlBlockSize = new Label(wContentComp, SWT.RIGHT); wlBlockSize.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.BlockSize.Label")); props.setLook(wlBlockSize); fdlBlockSize = new FormData(); fdlBlockSize.left = new FormAttachment(0, 0); fdlBlockSize.right = new FormAttachment(middle, -margin); fdlBlockSize.top = new FormAttachment(0, margin); wlBlockSize.setLayoutData(fdlBlockSize); wBlockSize = new TextVar(transMeta, wContentComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wBlockSize); wBlockSize.addModifyListener(lsMod); fdBlockSize = new FormData(); fdBlockSize.left = new FormAttachment(middle, 0); fdBlockSize.top = new FormAttachment(0, margin); fdBlockSize.right = new FormAttachment(100, 0); wBlockSize.setLayoutData(fdBlockSize); wBlockSize.addModifyListener(lsMod); /* End */ // Page size Line wlPageSize = new Label(wContentComp, SWT.RIGHT); wlPageSize.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.PageSize.Label")); props.setLook(wlPageSize); fdlPageSize = new FormData(); fdlPageSize.left = new FormAttachment(0, 0); fdlPageSize.right = new FormAttachment(middle, -margin); fdlPageSize.top = new FormAttachment(wBlockSize, margin); wlPageSize.setLayoutData(fdlPageSize); wPageSize = new TextVar(transMeta, wContentComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(wPageSize); wPageSize.addModifyListener(lsMod); fdPageSize = new FormData(); fdPageSize.left = new FormAttachment(middle, 0); fdPageSize.top = new FormAttachment(wBlockSize, margin); fdPageSize.right = new FormAttachment(100, 0); wPageSize.setLayoutData(fdPageSize); wPageSize.addModifyListener(lsMod); /* End */ // Compression // // DateTimeFormat wlCompression = new Label(wContentComp, SWT.RIGHT); wlCompression.setText(BaseMessages.getString(PKG, "ParquetOutputDialog.Compression.Label")); props.setLook(wlCompression); fdlCompression = new FormData(); fdlCompression.left = new FormAttachment(0, 0); fdlCompression.top = new FormAttachment(wPageSize, margin); fdlCompression.right = new FormAttachment(middle, -margin); wlCompression.setLayoutData(fdlCompression); wCompression = new ComboVar(transMeta, wContentComp, SWT.BORDER | SWT.READ_ONLY); wCompression.setEditable(true); props.setLook(wCompression); wCompression.addModifyListener(lsMod); fdCompression = new FormData(); fdCompression.left = new FormAttachment(middle, 0); fdCompression.top = new FormAttachment(wPageSize, margin); fdCompression.right = new FormAttachment(75, 0); wCompression.setLayoutData(fdCompression); String[] compressions = ParquetOutputMeta.compressionTypes; for (String compression : compressions) { wCompression.add(compression); } // Use configured block size line wlDictionaryCompression = new Label(wContentComp, SWT.RIGHT); wlDictionaryCompression .setText(BaseMessages.getString(PKG, "ParquetOutputDialog.DictionaryCompression.Label")); props.setLook(wlDictionaryCompression); fdlDictionaryCompression = new FormData(); fdlDictionaryCompression.left = new FormAttachment(0, 0); fdlDictionaryCompression.top = new FormAttachment(wCompression, margin); fdlDictionaryCompression.right = new FormAttachment(middle, -margin); wlDictionaryCompression.setLayoutData(fdlDictionaryCompression); wDictionaryCompression = new Button(wContentComp, SWT.CHECK); wDictionaryCompression .setToolTipText(BaseMessages.getString(PKG, "ParquetOutputDialog.DictionaryCompression.Tooltip")); props.setLook(wDictionaryCompression); fdDictionaryCompression = new FormData(); fdDictionaryCompression.left = new FormAttachment(middle, 0); fdDictionaryCompression.top = new FormAttachment(wCompression, margin); fdDictionaryCompression.right = new FormAttachment(100, 0); wDictionaryCompression.setLayoutData(fdDictionaryCompression); wDictionaryCompression.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent arg0) { input.setChanged(); } }); 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, "ParquetOutputDialog.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")); fdGet = new FormData(); fdGet.right = new FormAttachment(50, -4 * margin); fdGet.bottom = new FormAttachment(100, 0); wGet.setLayoutData(fdGet); final int FieldsCols = 3; final int FieldsRows = input.getOutputFields().length; colinf = new ColumnInfo[FieldsCols]; colinf[0] = new ColumnInfo(BaseMessages.getString(PKG, "ParquetOutputDialog.StreamColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false); colinf[1] = new ColumnInfo(BaseMessages.getString(PKG, "ParquetOutputDialog.Path.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false); colinf[2] = new ColumnInfo(BaseMessages.getString(PKG, "ParquetOutputDialog.Nullable.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, YES_NO_COMBO, 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(), 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); wDevelopedBy = new Link(shell, SWT.PUSH); wDevelopedBy.setText( "Developed by Inquidia Consulting (<a href=\"http://www.inquidia.com\">www.inquidia.com</a>)"); fdDevelopedBy = new FormData(); fdDevelopedBy.right = new FormAttachment(100, margin); fdDevelopedBy.bottom = new FormAttachment(100, margin); wDevelopedBy.setLayoutData(fdDevelopedBy); wDevelopedBy.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent selectionEvent) { Program.launch("http://www.inquidia.com"); } }); // Add listeners lsOK = new Listener() { public void handleEvent(Event e) { ok(); } }; lsGet = new Listener() { public void handleEvent(Event e) { get(); } }; lsCancel = new Listener() { public void handleEvent(Event e) { cancel(); } }; wOK.addListener(SWT.Selection, lsOK); wGet.addListener(SWT.Selection, lsGet); wCancel.addListener(SWT.Selection, lsCancel); lsDef = new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent e) { ok(); } }; wStepname.addSelectionListener(lsDef); wFilename.addSelectionListener(lsDef); wBlockSize.addSelectionListener(lsDef); wPageSize.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())); } }); /* TODO: Add VFS file chooser. */ wbFilename.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { try { // Setup file type filtering String[] fileFilters = null; String[] fileFilterNames = null; fileFilters = new String[] { "*" }; fileFilterNames = new String[] { BaseMessages.getString(PKG, "System.FileType.AllFiles") }; // Get current file FileObject rootFile = null; FileObject initialFile = null; FileObject defaultInitialFile = null; if (wFilename.getText() != null) { String fileName = transMeta.environmentSubstitute(wFilename.getText()); if (fileName != null && !fileName.equals("")) { try { initialFile = KettleVFS.getFileObject(fileName); rootFile = initialFile.getFileSystem().getRoot(); defaultInitialFile = initialFile; } catch (Exception ex) { // Ignore, unable to obtain initial file, use default } } } if (rootFile == null) { defaultInitialFile = KettleVFS.getFileObject(Spoon.getInstance().getLastFileOpened()); rootFile = defaultInitialFile.getFileSystem().getRoot(); initialFile = defaultInitialFile; } 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_OR_DIRECTORY); if (selectedFile != null) { wFilename.setText(selectedFile.getURL().toString()); } } catch (KettleFileException ex) { log.logError( BaseMessages.getString(PKG, "HadoopFileInputDialog.FileBrowser.KettleFileException")); } catch (FileSystemException ex) { log.logError( BaseMessages.getString(PKG, "HadoopFileInputDialog.FileBrowser.FileSystemException")); } } }); // 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(); input.setChanged(changed); setFilenameInField(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } return stepname; }
From source file:org.pentaho.di.job.entries.unzip.JobEntryUnZip.java
private boolean unzipFile(FileObject sourceFileObject, String realTargetdirectory, String realWildcard, String realWildcardExclude, Result result, Job parentJob, FileObject fileObject, FileObject movetodir, String realMovetodirectory) { boolean retval = false; String unzipToFolder = realTargetdirectory; try {//from ww w . j a v a 2s . c o m if (log.isDetailed()) { logDetailed( BaseMessages.getString(PKG, "JobUnZip.Log.ProcessingFile", sourceFileObject.toString())); } // Do you create a root folder? // if (rootzip) { String shortSourceFilename = sourceFileObject.getName().getBaseName(); int lenstring = shortSourceFilename.length(); int lastindexOfDot = shortSourceFilename.lastIndexOf('.'); if (lastindexOfDot == -1) { lastindexOfDot = lenstring; } String foldername = realTargetdirectory + "/" + shortSourceFilename.substring(0, lastindexOfDot); FileObject rootfolder = KettleVFS.getFileObject(foldername, this); if (!rootfolder.exists()) { try { rootfolder.createFolder(); if (log.isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobUnZip.Log.RootFolderCreated", foldername)); } } catch (Exception e) { throw new Exception( BaseMessages.getString(PKG, "JobUnZip.Error.CanNotCreateRootFolder", foldername), e); } } unzipToFolder = foldername; } // Try to read the entries from the VFS object... // String zipFilename = "zip:" + sourceFileObject.getName().getFriendlyURI(); FileObject zipFile = KettleVFS.getFileObject(zipFilename, this); FileObject[] items = zipFile.findFiles(new AllFileSelector() { public boolean traverseDescendents(FileSelectInfo info) { return true; } public boolean includeFile(FileSelectInfo info) { // Never return the parent directory of a file list. if (info.getDepth() == 0) { return false; } FileObject fileObject = info.getFile(); return fileObject != null; } }); Pattern pattern = null; if (!Const.isEmpty(realWildcard)) { pattern = Pattern.compile(realWildcard); } Pattern patternexclude = null; if (!Const.isEmpty(realWildcardExclude)) { patternexclude = Pattern.compile(realWildcardExclude); } for (FileObject item : items) { if (successConditionBroken) { if (!successConditionBrokenExit) { logError(BaseMessages.getString(PKG, "JobUnZip.Error.SuccessConditionbroken", "" + NrErrors)); successConditionBrokenExit = true; } return false; } synchronized (KettleVFS.getInstance().getFileSystemManager()) { FileObject newFileObject = null; try { if (log.isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobUnZip.Log.ProcessingZipEntry", item.getName().getURI(), sourceFileObject.toString())); } // get real destination filename // String newFileName = unzipToFolder + Const.FILE_SEPARATOR + getTargetFilename(item); newFileObject = KettleVFS.getFileObject(newFileName, this); if (item.getType().equals(FileType.FOLDER)) { // Directory // if (log.isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobUnZip.CreatingDirectory.Label", newFileName)); } // Create Directory if necessary ... // if (!newFileObject.exists()) { newFileObject.createFolder(); } } else { // File // boolean getIt = true; boolean getItexclude = false; // First see if the file matches the regular expression! // if (pattern != null) { Matcher matcher = pattern.matcher(item.getName().getURI()); getIt = matcher.matches(); } if (patternexclude != null) { Matcher matcherexclude = patternexclude.matcher(item.getName().getURI()); getItexclude = matcherexclude.matches(); } boolean take = takeThisFile(item, newFileName); if (getIt && !getItexclude && take) { if (log.isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobUnZip.ExtractingEntry.Label", item.getName().getURI(), newFileName)); } if (iffileexist == IF_FILE_EXISTS_UNIQ) { // Create file with unique name int lenstring = newFileName.length(); int lastindexOfDot = newFileName.lastIndexOf('.'); if (lastindexOfDot == -1) { lastindexOfDot = lenstring; } newFileName = newFileName.substring(0, lastindexOfDot) + StringUtil.getFormattedDateTimeNow(true) + newFileName.substring(lastindexOfDot, lenstring); if (log.isDebug()) { logDebug(BaseMessages.getString(PKG, "JobUnZip.Log.CreatingUniqFile", newFileName)); } } // See if the folder to the target file exists... // if (!newFileObject.getParent().exists()) { newFileObject.getParent().createFolder(); // creates the whole path. } InputStream is = null; OutputStream os = null; try { is = KettleVFS.getInputStream(item); os = KettleVFS.getOutputStream(newFileObject, false); if (is != null) { byte[] buff = new byte[2048]; int len; while ((len = is.read(buff)) > 0) { os.write(buff, 0, len); } // Add filename to result filenames addFilenameToResultFilenames(result, parentJob, newFileName); } } finally { if (is != null) { is.close(); } if (os != null) { os.close(); } } } // end if take } } catch (Exception e) { updateErrors(); logError(BaseMessages.getString(PKG, "JobUnZip.Error.CanNotProcessZipEntry", item.getName().getURI(), sourceFileObject.toString()), e); } finally { if (newFileObject != null) { try { newFileObject.close(); if (setOriginalModificationDate) { // Change last modification date newFileObject.getContent() .setLastModifiedTime(item.getContent().getLastModifiedTime()); } } catch (Exception e) { /* Ignore */ } // ignore this } // Close file object // close() does not release resources! KettleVFS.getInstance().getFileSystemManager().closeFileSystem(item.getFileSystem()); if (items != null) { items = null; } } } // Synchronized block on KettleVFS.getInstance().getFileSystemManager() } // End for // Here gc() is explicitly called if e.g. createfile is used in the same // job for the same file. The problem is that after creating the file the // file object is not properly garbaged collected and thus the file cannot // be deleted anymore. This is a known problem in the JVM. // System.gc(); // Unzip done... if (afterunzip == 1) { // delete zip file boolean deleted = fileObject.delete(); if (!deleted) { updateErrors(); logError(BaseMessages.getString(PKG, "JobUnZip.Cant_Delete_File.Label", sourceFileObject.toString())); } // File deleted if (log.isDebug()) { logDebug(BaseMessages.getString(PKG, "JobUnZip.File_Deleted.Label", sourceFileObject.toString())); } } else if (afterunzip == 2) { FileObject destFile = null; // Move File try { String destinationFilename = movetodir + Const.FILE_SEPARATOR + fileObject.getName().getBaseName(); destFile = KettleVFS.getFileObject(destinationFilename, this); fileObject.moveTo(destFile); // File moved if (log.isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobUnZip.Log.FileMovedTo", sourceFileObject.toString(), realMovetodirectory)); } } catch (Exception e) { updateErrors(); logError(BaseMessages.getString(PKG, "JobUnZip.Cant_Move_File.Label", sourceFileObject.toString(), realMovetodirectory, e.getMessage())); } finally { if (destFile != null) { try { destFile.close(); } catch (IOException ex) { /* Ignore */ } } } } retval = true; } catch (Exception e) { updateErrors(); log.logError(BaseMessages.getString(PKG, "JobUnZip.Error.Label"), BaseMessages.getString(PKG, "JobUnZip.ErrorUnzip.Label", sourceFileObject.toString(), e.getMessage()), e); } return retval; }
From source file:org.pentaho.di.scoring.WekaScoringDialog.java
/** * Open the dialog/* w w w . ja v a2 s. c o m*/ * * @return the step name */ public String open() { // Make sure that all Weka packages have been loaded! weka.core.WekaPackageManager.loadPackages(false); Shell parent = getParent(); 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(WekaScoringMeta.PKG, "WekaScoringDialog.Shell.Title")); //$NON-NLS-1$ int middle = props.getMiddlePct(); int margin = Const.MARGIN; // Stepname line m_wlStepname = new Label(shell, SWT.RIGHT); m_wlStepname.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.StepName.Label")); //$NON-NLS-1$ props.setLook(m_wlStepname); m_fdlStepname = new FormData(); m_fdlStepname.left = new FormAttachment(0, 0); m_fdlStepname.right = new FormAttachment(middle, -margin); m_fdlStepname.top = new FormAttachment(0, margin); m_wlStepname.setLayoutData(m_fdlStepname); m_wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); m_wStepname.setText(stepname); props.setLook(m_wStepname); m_wStepname.addModifyListener(lsMod); // format the text field m_fdStepname = new FormData(); m_fdStepname.left = new FormAttachment(middle, 0); m_fdStepname.top = new FormAttachment(0, margin); m_fdStepname.right = new FormAttachment(100, 0); m_wStepname.setLayoutData(m_fdStepname); m_wTabFolder = new CTabFolder(shell, SWT.BORDER); props.setLook(m_wTabFolder, Props.WIDGET_STYLE_TAB); m_wTabFolder.setSimple(false); // Start of the file tab m_wFileTab = new CTabItem(m_wTabFolder, SWT.NONE); m_wFileTab.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileTab.TabTitle")); //$NON-NLS-1$ Composite wFileComp = new Composite(m_wTabFolder, SWT.NONE); props.setLook(wFileComp); FormLayout fileLayout = new FormLayout(); fileLayout.marginWidth = 3; fileLayout.marginHeight = 3; wFileComp.setLayout(fileLayout); // Filename line m_wlFilename = new Label(wFileComp, SWT.RIGHT); m_wlFilename.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Filename.Label")); //$NON-NLS-1$ props.setLook(m_wlFilename); m_fdlFilename = new FormData(); m_fdlFilename.left = new FormAttachment(0, 0); m_fdlFilename.top = new FormAttachment(0, margin); m_fdlFilename.right = new FormAttachment(middle, -margin); m_wlFilename.setLayoutData(m_fdlFilename); // file browse button m_wbFilename = new Button(wFileComp, SWT.PUSH | SWT.CENTER); props.setLook(m_wbFilename); m_wbFilename.setText(BaseMessages.getString(WekaScoringMeta.PKG, "System.Button.Browse")); //$NON-NLS-1$ m_fdbFilename = new FormData(); m_fdbFilename.right = new FormAttachment(100, 0); m_fdbFilename.top = new FormAttachment(0, 0); m_wbFilename.setLayoutData(m_fdbFilename); // combined text field and env variable widget m_wFilename = new TextVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(m_wFilename); m_wFilename.addModifyListener(lsMod); m_fdFilename = new FormData(); m_fdFilename.left = new FormAttachment(middle, 0); m_fdFilename.top = new FormAttachment(0, margin); m_fdFilename.right = new FormAttachment(m_wbFilename, -margin); m_wFilename.setLayoutData(m_fdFilename); // store model in meta data Label saveModelMetaLab = new Label(wFileComp, SWT.RIGHT); props.setLook(saveModelMetaLab); saveModelMetaLab .setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.SaveModelToMeta.Label")); //$NON-NLS-1$ FormData fd = new FormData(); fd.left = new FormAttachment(0, 0); fd.top = new FormAttachment(m_wFilename, margin); fd.right = new FormAttachment(middle, -margin); saveModelMetaLab.setLayoutData(fd); m_storeModelInStepMetaData = new Button(wFileComp, SWT.CHECK); props.setLook(m_storeModelInStepMetaData); fd = new FormData(); fd.left = new FormAttachment(middle, 0); fd.top = new FormAttachment(m_wFilename, margin); fd.right = new FormAttachment(100, 0); m_storeModelInStepMetaData.setLayoutData(fd); m_wUpdateModelLab = new Label(wFileComp, SWT.RIGHT); m_wUpdateModelLab .setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.UpdateModel.Label")); //$NON-NLS-1$ props.setLook(m_wUpdateModelLab); m_fdlUpdateModel = new FormData(); m_fdlUpdateModel.left = new FormAttachment(0, 0); m_fdlUpdateModel.top = new FormAttachment(m_storeModelInStepMetaData, margin); m_fdlUpdateModel.right = new FormAttachment(middle, -margin); m_wUpdateModelLab.setLayoutData(m_fdlUpdateModel); m_wUpdateModel = new Button(wFileComp, SWT.CHECK); props.setLook(m_wUpdateModel); m_fdUpdateModel = new FormData(); m_fdUpdateModel.left = new FormAttachment(middle, 0); m_fdUpdateModel.top = new FormAttachment(m_storeModelInStepMetaData, margin); m_fdUpdateModel.right = new FormAttachment(100, 0); m_wUpdateModel.setLayoutData(m_fdUpdateModel); m_wUpdateModel.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { m_currentMeta.setChanged(); m_wbSaveFilename.setEnabled(m_wUpdateModel.getSelection()); m_wSaveFilename.setEnabled(m_wUpdateModel.getSelection()); } }); // ---------------------------- // Save filename line m_wlSaveFilename = new Label(wFileComp, SWT.RIGHT); m_wlSaveFilename .setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.SaveFilename.Label")); //$NON-NLS-1$ props.setLook(m_wlSaveFilename); m_fdlSaveFilename = new FormData(); m_fdlSaveFilename.left = new FormAttachment(0, 0); m_fdlSaveFilename.top = new FormAttachment(m_wUpdateModel, margin); m_fdlSaveFilename.right = new FormAttachment(middle, -margin); m_wlSaveFilename.setLayoutData(m_fdlSaveFilename); // Save file browse button m_wbSaveFilename = new Button(wFileComp, SWT.PUSH | SWT.CENTER); props.setLook(m_wbSaveFilename); m_wbSaveFilename.setText(BaseMessages.getString(WekaScoringMeta.PKG, "System.Button.Browse")); //$NON-NLS-1$ m_fdbSaveFilename = new FormData(); m_fdbSaveFilename.right = new FormAttachment(100, 0); m_fdbSaveFilename.top = new FormAttachment(m_wUpdateModel, 0); m_wbSaveFilename.setLayoutData(m_fdbSaveFilename); m_wbSaveFilename.setEnabled(false); // combined text field and env variable widget m_wSaveFilename = new TextVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(m_wSaveFilename); m_wSaveFilename.addModifyListener(lsMod); m_fdSaveFilename = new FormData(); m_fdSaveFilename.left = new FormAttachment(middle, 0); m_fdSaveFilename.top = new FormAttachment(m_wUpdateModel, margin); m_fdSaveFilename.right = new FormAttachment(m_wbSaveFilename, -margin); m_wSaveFilename.setLayoutData(m_fdSaveFilename); m_wSaveFilename.setEnabled(false); m_fdFileComp = new FormData(); m_fdFileComp.left = new FormAttachment(0, 0); m_fdFileComp.top = new FormAttachment(0, 0); m_fdFileComp.right = new FormAttachment(100, 0); m_fdFileComp.bottom = new FormAttachment(100, 0); wFileComp.setLayoutData(m_fdFileComp); wFileComp.layout(); m_wFileTab.setControl(wFileComp); m_wAcceptFileNameFromFieldCheckLab = new Label(wFileComp, SWT.RIGHT); m_wAcceptFileNameFromFieldCheckLab.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.AcceptFileNamesFromFieldCheck.Label")); //$NON-NLS-1$ props.setLook(m_wAcceptFileNameFromFieldCheckLab); FormData fdAcceptCheckLab = new FormData(); fdAcceptCheckLab.left = new FormAttachment(0, 0); fdAcceptCheckLab.top = new FormAttachment(m_wSaveFilename, margin); fdAcceptCheckLab.right = new FormAttachment(middle, -margin); m_wAcceptFileNameFromFieldCheckLab.setLayoutData(fdAcceptCheckLab); m_wAcceptFileNameFromFieldCheckBox = new Button(wFileComp, SWT.CHECK); props.setLook(m_wAcceptFileNameFromFieldCheckBox); FormData fdAcceptCheckBox = new FormData(); fdAcceptCheckBox.left = new FormAttachment(middle, 0); fdAcceptCheckBox.top = new FormAttachment(m_wSaveFilename, margin); fdAcceptCheckBox.right = new FormAttachment(100, 0); m_wAcceptFileNameFromFieldCheckBox.setLayoutData(fdAcceptCheckBox); m_wAcceptFileNameFromFieldCheckBox.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { m_currentMeta.setChanged(); if (m_wAcceptFileNameFromFieldCheckBox.getSelection()) { m_wUpdateModel.setSelection(false); m_wUpdateModel.setEnabled(false); m_wSaveFilename.setText(""); //$NON-NLS-1$ m_wlFilename.setText( BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Default.Label")); //$NON-NLS-1$ if (!Const.isEmpty(m_wFilename.getText())) { // load - loadModel() will take care of storing it in // either the main or default model in the current meta loadModel(); } else { // try and shift the main model (if non-null) over into the // default model in current meta m_currentMeta.setDefaultModel(m_currentMeta.getModel()); m_currentMeta.setModel(null); } } else { if (!Const.isEmpty(m_wFilename.getText())) { // load - loadModel() will take care of storing it in // either the main or default model in the current meta loadModel(); } else { // try and shift the default model (if non-null) over into the // main model in current meta m_currentMeta.setModel(m_currentMeta.getDefaultModel()); m_currentMeta.setDefaultModel(null); } m_wCacheModelsCheckBox.setSelection(false); m_wlFilename.setText( BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Filename.Label")); //$NON-NLS-1$ } m_wCacheModelsCheckBox.setEnabled(m_wAcceptFileNameFromFieldCheckBox.getSelection()); m_wAcceptFileNameFromFieldText.setEnabled(m_wAcceptFileNameFromFieldCheckBox.getSelection()); m_wbSaveFilename.setEnabled( !m_wAcceptFileNameFromFieldCheckBox.getSelection() && m_wUpdateModel.getSelection()); m_wSaveFilename.setEnabled( !m_wAcceptFileNameFromFieldCheckBox.getSelection() && m_wUpdateModel.getSelection()); } }); // m_wAcceptFileNameFromFieldTextLab = new Label(wFileComp, SWT.RIGHT); m_wAcceptFileNameFromFieldTextLab.setText( BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.AcceptFileNamesFromField.Label")); //$NON-NLS-1$ props.setLook(m_wAcceptFileNameFromFieldTextLab); FormData fdAcceptLab = new FormData(); fdAcceptLab.left = new FormAttachment(0, 0); fdAcceptLab.top = new FormAttachment(m_wAcceptFileNameFromFieldCheckBox, margin); fdAcceptLab.right = new FormAttachment(middle, -margin); m_wAcceptFileNameFromFieldTextLab.setLayoutData(fdAcceptLab); m_wAcceptFileNameFromFieldText = new TextVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(m_wAcceptFileNameFromFieldText); m_wAcceptFileNameFromFieldText.addModifyListener(lsMod); FormData fdAcceptText = new FormData(); fdAcceptText.left = new FormAttachment(middle, 0); fdAcceptText.top = new FormAttachment(m_wAcceptFileNameFromFieldCheckBox, margin); fdAcceptText.right = new FormAttachment(100, 0); m_wAcceptFileNameFromFieldText.setLayoutData(fdAcceptText); m_wAcceptFileNameFromFieldText.setEnabled(false); m_wCacheModelsLab = new Label(wFileComp, SWT.RIGHT); m_wCacheModelsLab .setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.CacheModels.Label")); //$NON-NLS-1$ props.setLook(m_wCacheModelsLab); FormData fdCacheLab = new FormData(); fdCacheLab.left = new FormAttachment(0, 0); fdCacheLab.top = new FormAttachment(m_wAcceptFileNameFromFieldText, margin); fdCacheLab.right = new FormAttachment(middle, -margin); m_wCacheModelsLab.setLayoutData(fdCacheLab); // m_wCacheModelsCheckBox = new Button(wFileComp, SWT.CHECK); props.setLook(m_wCacheModelsCheckBox); FormData fdCacheCheckBox = new FormData(); fdCacheCheckBox.left = new FormAttachment(middle, 0); fdCacheCheckBox.top = new FormAttachment(m_wAcceptFileNameFromFieldText, margin); fdCacheCheckBox.right = new FormAttachment(100, 0); m_wCacheModelsCheckBox.setLayoutData(fdCacheCheckBox); m_wCacheModelsCheckBox.setEnabled(false); m_wOutputProbsLab = new Label(wFileComp, SWT.RIGHT); m_wOutputProbsLab .setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.OutputProbs.Label")); //$NON-NLS-1$ props.setLook(m_wOutputProbsLab); m_fdlOutputProbs = new FormData(); m_fdlOutputProbs.left = new FormAttachment(0, 0); m_fdlOutputProbs.top = new FormAttachment(m_wCacheModelsCheckBox, margin); m_fdlOutputProbs.right = new FormAttachment(middle, -margin); m_wOutputProbsLab.setLayoutData(m_fdlOutputProbs); m_wOutputProbs = new Button(wFileComp, SWT.CHECK); props.setLook(m_wOutputProbs); m_fdOutputProbs = new FormData(); m_fdOutputProbs.left = new FormAttachment(middle, 0); m_fdOutputProbs.top = new FormAttachment(m_wCacheModelsCheckBox, margin); m_fdOutputProbs.right = new FormAttachment(100, 0); m_wOutputProbs.setLayoutData(m_fdOutputProbs); // batch scoring size line Label batchLab = new Label(wFileComp, SWT.RIGHT); batchLab.setText("Batch scoring batch size"); //$NON-NLS-1$ props.setLook(batchLab); FormData fdd = new FormData(); fdd.left = new FormAttachment(0, 0); fdd.top = new FormAttachment(m_wOutputProbs, margin); fdd.right = new FormAttachment(middle, -margin); batchLab.setLayoutData(fdd); m_batchScoringBatchSizeText = new TextVar(transMeta, wFileComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER); props.setLook(m_batchScoringBatchSizeText); m_batchScoringBatchSizeText.addModifyListener(lsMod); fdd = new FormData(); fdd.left = new FormAttachment(middle, 0); fdd.top = new FormAttachment(m_wOutputProbs, margin); fdd.right = new FormAttachment(100, 0); m_batchScoringBatchSizeText.setLayoutData(fdd); m_batchScoringBatchSizeText.setEnabled(false); // Fields mapping tab m_wFieldsTab = new CTabItem(m_wTabFolder, SWT.NONE); m_wFieldsTab.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FieldsTab.TabTitle")); //$NON-NLS-1$ FormLayout fieldsLayout = new FormLayout(); fieldsLayout.marginWidth = 3; fieldsLayout.marginHeight = 3; Composite wFieldsComp = new Composite(m_wTabFolder, SWT.NONE); props.setLook(wFieldsComp); wFieldsComp.setLayout(fieldsLayout); // body of tab to be a scrolling text area // to display the mapping m_wMappingText = new Text(wFieldsComp, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); m_wMappingText.setEditable(false); FontData fontd = new FontData("Courier New", 12, SWT.NORMAL); //$NON-NLS-1$ m_wMappingText.setFont(new Font(getParent().getDisplay(), fontd)); props.setLook(m_wMappingText); // format the fields mapping text area m_fdMappingText = new FormData(); m_fdMappingText.left = new FormAttachment(0, 0); m_fdMappingText.top = new FormAttachment(0, margin); m_fdMappingText.right = new FormAttachment(100, 0); m_fdMappingText.bottom = new FormAttachment(100, 0); m_wMappingText.setLayoutData(m_fdMappingText); m_fdFieldsComp = new FormData(); m_fdFieldsComp.left = new FormAttachment(0, 0); m_fdFieldsComp.top = new FormAttachment(0, 0); m_fdFieldsComp.right = new FormAttachment(100, 0); m_fdFieldsComp.bottom = new FormAttachment(100, 0); wFieldsComp.setLayoutData(m_fdFieldsComp); wFieldsComp.layout(); m_wFieldsTab.setControl(wFieldsComp); // Model display tab m_wModelTab = new CTabItem(m_wTabFolder, SWT.NONE); m_wModelTab.setText(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.ModelTab.TabTitle")); //$NON-NLS-1$ FormLayout modelLayout = new FormLayout(); modelLayout.marginWidth = 3; modelLayout.marginHeight = 3; Composite wModelComp = new Composite(m_wTabFolder, SWT.NONE); props.setLook(wModelComp); wModelComp.setLayout(modelLayout); // body of tab to be a scrolling text area // to display the pre-learned model m_wModelText = new Text(wModelComp, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); m_wModelText.setEditable(false); fontd = new FontData("Courier New", 12, SWT.NORMAL); //$NON-NLS-1$ m_wModelText.setFont(new Font(getParent().getDisplay(), fontd)); props.setLook(m_wModelText); // format the model text area m_fdModelText = new FormData(); m_fdModelText.left = new FormAttachment(0, 0); m_fdModelText.top = new FormAttachment(0, margin); m_fdModelText.right = new FormAttachment(100, 0); m_fdModelText.bottom = new FormAttachment(100, 0); m_wModelText.setLayoutData(m_fdModelText); m_fdModelComp = new FormData(); m_fdModelComp.left = new FormAttachment(0, 0); m_fdModelComp.top = new FormAttachment(0, 0); m_fdModelComp.right = new FormAttachment(100, 0); m_fdModelComp.bottom = new FormAttachment(100, 0); wModelComp.setLayoutData(m_fdModelComp); wModelComp.layout(); m_wModelTab.setControl(wModelComp); m_fdTabFolder = new FormData(); m_fdTabFolder.left = new FormAttachment(0, 0); m_fdTabFolder.top = new FormAttachment(m_wStepname, margin); m_fdTabFolder.right = new FormAttachment(100, 0); m_fdTabFolder.bottom = new FormAttachment(100, -50); m_wTabFolder.setLayoutData(m_fdTabFolder); // Buttons inherited from BaseStepDialog wOK = new Button(shell, SWT.PUSH); wOK.setText(BaseMessages.getString(WekaScoringMeta.PKG, "System.Button.OK")); //$NON-NLS-1$ wCancel = new Button(shell, SWT.PUSH); wCancel.setText(BaseMessages.getString(WekaScoringMeta.PKG, "System.Button.Cancel")); //$NON-NLS-1$ 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_wStepname.addSelectionListener(lsDef); // Detect X or ALT-F4 or something that kills this window... shell.addShellListener(new ShellAdapter() { @Override public void shellClosed(ShellEvent e) { cancel(); } }); // Whenever something changes, set the tooltip to the expanded version: m_wFilename.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { m_wFilename.setToolTipText(transMeta.environmentSubstitute(m_wFilename.getText())); } }); m_wSaveFilename.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { m_wSaveFilename.setToolTipText(transMeta.environmentSubstitute(m_wSaveFilename.getText())); } }); // listen to the file name text box and try to load a model // if the user presses enter m_wFilename.addSelectionListener(new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { if (!loadModel()) { log.logError( BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Log.FileLoadingError")); //$NON-NLS-1$ } } }); m_wbFilename.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String[] extensions = null; String[] filterNames = null; if (XStream.isPresent()) { extensions = new String[4]; filterNames = new String[4]; extensions[0] = "*.model"; //$NON-NLS-1$ filterNames[0] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFileBinary"); //$NON-NLS-1$ extensions[1] = "*.xstreammodel"; //$NON-NLS-1$ filterNames[1] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFileXML"); //$NON-NLS-1$ extensions[2] = "*.xml"; //$NON-NLS-1$ filterNames[2] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFilePMML"); //$NON-NLS-1$ extensions[3] = "*"; //$NON-NLS-1$ filterNames[3] = BaseMessages.getString(WekaScoringMeta.PKG, "System.FileType.AllFiles"); //$NON-NLS-1$ } else { extensions = new String[3]; filterNames = new String[3]; extensions[0] = "*.model"; //$NON-NLS-1$ filterNames[0] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFileBinary"); //$NON-NLS-1$ extensions[1] = "*.xml"; //$NON-NLS-1$ filterNames[1] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFilePMML"); //$NON-NLS-1$ extensions[2] = "*"; //$NON-NLS-1$ filterNames[2] = BaseMessages.getString(WekaScoringMeta.PKG, "System.FileType.AllFiles"); //$NON-NLS-1$ } // get current file FileObject rootFile = null; FileObject initialFile = null; FileObject defaultInitialFile = null; try { if (m_wFilename.getText() != null) { String fname = transMeta.environmentSubstitute(m_wFilename.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:/"); //$NON-NLS-1$ } if (rootFile == null) { rootFile = defaultInitialFile.getFileSystem().getRoot(); } VfsFileChooserDialog fileChooserDialog = Spoon.getInstance().getVfsFileChooserDialog(rootFile, initialFile); fileChooserDialog.setRootFile(rootFile); fileChooserDialog.setInitialFile(initialFile); fileChooserDialog.defaultInitialFile = rootFile; String in = (!Const.isEmpty(m_wFilename.getText())) ? initialFile.getName().getPath() : null; FileObject selectedFile = fileChooserDialog.open(shell, null, "file", //$NON-NLS-1$ true, in, extensions, filterNames, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE); if (selectedFile != null) { m_wFilename.setText(selectedFile.getURL().toString()); } // try to load model file and display model if (!loadModel()) { log.logError(BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.Log.FileLoadingError")); //$NON-NLS-1$ } } catch (Exception ex) { logError("A problem occurred", ex); //$NON-NLS-1$ } } }); m_wbSaveFilename.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { FileDialog dialog = new FileDialog(shell, SWT.SAVE); String[] extensions = null; String[] filterNames = null; if (XStream.isPresent()) { extensions = new String[3]; filterNames = new String[3]; extensions[0] = "*.model"; //$NON-NLS-1$ filterNames[0] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFileBinary"); //$NON-NLS-1$ extensions[1] = "*.xstreammodel"; //$NON-NLS-1$ filterNames[1] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFileXML"); //$NON-NLS-1$ extensions[2] = "*"; //$NON-NLS-1$ filterNames[2] = BaseMessages.getString(WekaScoringMeta.PKG, "System.FileType.AllFiles"); //$NON-NLS-1$ } else { extensions = new String[2]; filterNames = new String[2]; extensions[0] = "*.model"; //$NON-NLS-1$ filterNames[0] = BaseMessages.getString(WekaScoringMeta.PKG, "WekaScoringDialog.FileType.ModelFileBinary"); //$NON-NLS-1$ extensions[1] = "*"; //$NON-NLS-1$ filterNames[1] = BaseMessages.getString(WekaScoringMeta.PKG, "System.FileType.AllFiles"); //$NON-NLS-1$ } dialog.setFilterExtensions(extensions); if (m_wSaveFilename.getText() != null) { dialog.setFileName(transMeta.environmentSubstitute(m_wSaveFilename.getText())); } dialog.setFilterNames(filterNames); if (dialog.open() != null) { m_wSaveFilename.setText( dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName()); //$NON-NLS-1$ } } }); m_wTabFolder.setSelection(0); // Set the shell size, based upon previous time... setSize(); getData(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } return stepname; }
From source file:org.pentaho.di.ui.job.AbstractJobEntryController.java
/** * Browse for a file or directory with the VFS Browser. * /*from ww w . j a v a 2 s . c om*/ * @param root * Root object * @param initial * Initial file or folder the browser should open to * @param dialogMode * Mode to open dialog in: e.g. * {@link org.pentaho.vfs.ui .VfsFileChooserDialog#VFS_DIALOG_OPEN_FILE_OR_DIRECTORY} * @param schemeRestriction * Scheme to limit the user to browsing from * @param defaultScheme * Scheme to select by default in the selection dropdown * @return The selected file object, {@code null} if no object is selected * @throws org.pentaho.di.core.exception.KettleFileException * Error accessing the root file using the initial file, when {@code root} is not provided */ protected FileObject browseVfs(FileObject root, FileObject initial, int dialogMode, String schemeRestriction, String defaultScheme, boolean showFileScheme) throws KettleFileException { if (initial == null) { initial = KettleVFS.getFileObject(Spoon.getInstance().getLastFileOpened()); } if (root == null) { try { root = initial.getFileSystem().getRoot(); } catch (FileSystemException e) { throw new KettleFileException(e); } } VfsFileChooserHelper fileChooserHelper = new VfsFileChooserHelper(getShell(), Spoon.getInstance().getVfsFileChooserDialog(root, initial), jobEntry); fileChooserHelper.setDefaultScheme(defaultScheme); fileChooserHelper.setSchemeRestriction(schemeRestriction); fileChooserHelper.setShowFileScheme(showFileScheme); try { return fileChooserHelper.browse(getFileFilters(), getFileFilterNames(), initial.getName().getURI(), dialogMode); } catch (KettleException e) { throw new KettleFileException(e); } catch (FileSystemException e) { throw new KettleFileException(e); } }
From source file:org.pentaho.di.ui.job.entries.hadoopcopyfiles.JobEntryHadoopCopyFilesDialog.java
private FileObject setSelectedFile(TextVar textVar) { FileObject selectedFile = null; try {/* w w w .jav a 2 s . c o m*/ // Get current file FileObject rootFile = null; FileObject initialFile = null; FileObject defaultInitialFile = null; if (textVar.getText() != null) { String fileName = jobMeta.environmentSubstitute(textVar.getText()); if (fileName != null && !fileName.equals("")) { initialFile = KettleVFS.getFileObject(fileName); 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, null, HadoopSpoonPlugin.HDFS_SCHEME, true, null, new String[] { "*.*" }, FILETYPES, VfsFileChooserDialog.VFS_DIALOG_OPEN_DIRECTORY); if (selectedFile != null) { textVar.setText(selectedFile.getURL().toString()); } return selectedFile; } catch (KettleFileException ex) { log.logError(BaseMessages.getString(PKG, "HadoopFileInputDialog.FileBrowser.KettleFileException")); return selectedFile; } catch (FileSystemException ex) { log.logError(BaseMessages.getString(PKG, "HadoopFileInputDialog.FileBrowser.FileSystemException")); return selectedFile; } }
From source file:org.pentaho.di.ui.spoon.Spoon.java
public void openFileVFSFile() { FileObject initialFile; FileObject rootFile;/*from ww w .j a v a2s .com*/ try { initialFile = KettleVFS.getFileObject(getLastFileOpened()); rootFile = initialFile.getFileSystem().getRoot(); } catch (Exception e) { String message = Const.getStackTracker(e); new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Error"), message, e); return; } FileObject selectedFile = getVfsFileChooserDialog(rootFile, initialFile).open(shell, null, Const.STRING_TRANS_AND_JOB_FILTER_EXT, Const.getTransformationAndJobFilterNames(), VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE); if (selectedFile != null) { setLastFileOpened(selectedFile.getName().getFriendlyURI()); openFile(selectedFile.getName().getFriendlyURI(), false); } }
From source file:org.pentaho.di.ui.trans.steps.hadoopfileinput.HadoopFileInputDialog.java
public String open() { Shell parent = getParent();/* ww w.java 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); 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(BaseMessages.getString(PKG, "HadoopFileInputDialog.DialogTitle")); middle = props.getMiddlePct(); margin = Const.MARGIN; // Stepname line wlStepname = new Label(shell, SWT.RIGHT); wlStepname.setText(BaseMessages.getString(BASE_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); addFilesTab(); addContentTab(); addErrorTab(); addFiltersTabs(); addFieldsTabs(); 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(BASE_PKG, "System.Button.OK")); wPreview = new Button(shell, SWT.PUSH); wPreview.setText(BaseMessages.getString(BASE_PKG, "TextFileInputDialog.Preview.Button")); wCancel = new Button(shell, SWT.PUSH); wCancel.setText(BaseMessages.getString(BASE_PKG, "System.Button.Cancel")); setButtonPositions(new Button[] { wOK, wPreview, wCancel }, margin, wTabFolder); // Add listeners lsOK = new Listener() { public void handleEvent(Event e) { ok(); } }; lsFirst = new Listener() { public void handleEvent(Event e) { first(false); } }; lsFirstHeader = new Listener() { public void handleEvent(Event e) { first(true); } }; lsGet = new Listener() { public void handleEvent(Event e) { get(); } }; lsPreview = new Listener() { public void handleEvent(Event e) { preview(); } }; lsCancel = new Listener() { public void handleEvent(Event e) { cancel(); } }; wOK.addListener(SWT.Selection, lsOK); wFirst.addListener(SWT.Selection, lsFirst); wFirstHeader.addListener(SWT.Selection, lsFirstHeader); wGet.addListener(SWT.Selection, lsGet); wPreview.addListener(SWT.Selection, lsPreview); wCancel.addListener(SWT.Selection, lsCancel); lsDef = new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent e) { ok(); } }; wAccFilenames.addSelectionListener(lsDef); wStepname.addSelectionListener(lsDef); // wFilename.addSelectionListener( lsDef ); wSeparator.addSelectionListener(lsDef); wLimit.addSelectionListener(lsDef); wInclRownumField.addSelectionListener(lsDef); wInclFilenameField.addSelectionListener(lsDef); wNrHeader.addSelectionListener(lsDef); wNrFooter.addSelectionListener(lsDef); wNrWraps.addSelectionListener(lsDef); wWarnDestDir.addSelectionListener(lsDef); wWarnExt.addSelectionListener(lsDef); wErrorDestDir.addSelectionListener(lsDef); wErrorExt.addSelectionListener(lsDef); wLineNrDestDir.addSelectionListener(lsDef); wLineNrExt.addSelectionListener(lsDef); wAccField.addSelectionListener(lsDef); // Add the file to the list of files... SelectionAdapter selA = new SelectionAdapter() { public void widgetSelected(SelectionEvent arg0) { wFilenameList.add(new String[] { wFilename.getText(), wFilemask.getText(), TextFileInputMeta.RequiredFilesCode[0], TextFileInputMeta.RequiredFilesCode[0] }); wFilename.setText(""); wFilemask.setText(""); wFilenameList.removeEmptyRows(); wFilenameList.setRowNums(); wFilenameList.optWidth(true); } }; wbaFilename.addSelectionListener(selA); wFilename.addSelectionListener(selA); // Delete files from the list of files... wbdFilename.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent arg0) { int[] idx = wFilenameList.getSelectionIndices(); wFilenameList.remove(idx); wFilenameList.removeEmptyRows(); wFilenameList.setRowNums(); } }); // Edit the selected file & remove from the list... wbeFilename.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent arg0) { int idx = wFilenameList.getSelectionIndex(); if (idx >= 0) { String[] string = wFilenameList.getItem(idx); wFilename.setText(string[0]); wFilemask.setText(string[1]); wFilenameList.remove(idx); } wFilenameList.removeEmptyRows(); wFilenameList.setRowNums(); } }); // Show the files that are selected at this time... wbShowFiles.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { showFiles(); } }); // Allow the insertion of tabs as separator... wbSeparator.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent se) { wSeparator.getTextWidget().insert("\t"); } }); SelectionAdapter lsFlags = new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { setFlags(); } }; // Enable/disable the right fields... wInclFilename.addSelectionListener(lsFlags); wInclRownum.addSelectionListener(lsFlags); wRownumByFile.addSelectionListener(lsFlags); wErrorIgnored.addSelectionListener(lsFlags); wHeader.addSelectionListener(lsFlags); wFooter.addSelectionListener(lsFlags); wWraps.addSelectionListener(lsFlags); wLayoutPaged.addSelectionListener(lsFlags); wAccFilenames.addSelectionListener(lsFlags); // Listen to the Browse... button wbbFilename.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { try { // Setup file type filtering String[] fileFilters = null; String[] fileFilterNames = null; if (!wCompression.getText().equals("None")) { fileFilters = new String[] { "*.zip;*.gz", "*.txt;*.csv", "*.csv", "*.txt", "*" }; fileFilterNames = new String[] { BaseMessages.getString(BASE_PKG, "System.FileType.ZIPFiles"), BaseMessages.getString(BASE_PKG, "TextFileInputDialog.FileType.TextAndCSVFiles"), BaseMessages.getString(BASE_PKG, "System.FileType.CSVFiles"), BaseMessages.getString(BASE_PKG, "System.FileType.TextFiles"), BaseMessages.getString(BASE_PKG, "System.FileType.AllFiles") }; } else { fileFilters = new String[] { "*", "*.txt;*.csv", "*.csv", "*.txt" }; fileFilterNames = new String[] { BaseMessages.getString(BASE_PKG, "System.FileType.AllFiles"), BaseMessages.getString(BASE_PKG, "TextFileInputDialog.FileType.TextAndCSVFiles"), BaseMessages.getString(BASE_PKG, "System.FileType.CSVFiles"), BaseMessages.getString(BASE_PKG, "System.FileType.TextFiles") }; } // Get current file FileObject rootFile = null; FileObject initialFile = null; FileObject defaultInitialFile = null; if (wFilename.getText() != null) { String fileName = transMeta.environmentSubstitute(wFilename.getText()); if (fileName != null && !fileName.equals("")) { try { initialFile = KettleVFS.getFileObject(fileName); rootFile = initialFile.getFileSystem().getRoot(); defaultInitialFile = initialFile; } catch (KettleFileException ex) { // Ignore, unable to obtain initial file, use default } } } if (rootFile == null) { defaultInitialFile = KettleVFS.getFileObject(Spoon.getInstance().getLastFileOpened()); rootFile = defaultInitialFile.getFileSystem().getRoot(); initialFile = defaultInitialFile; } 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_OR_DIRECTORY); if (selectedFile != null) { wFilename.setText(selectedFile.getURL().toString()); } } catch (KettleFileException ex) { log.logError( BaseMessages.getString(PKG, "HadoopFileInputDialog.FileBrowser.KettleFileException")); } catch (FileSystemException ex) { log.logError( BaseMessages.getString(PKG, "HadoopFileInputDialog.FileBrowser.FileSystemException")); } } }); // Detect X or ALT-F4 or something that kills this window... shell.addShellListener(new ShellAdapter() { public void shellClosed(ShellEvent e) { cancel(); } }); wTabFolder.setSelection(0); // Set the shell size, based upon previous time... getData(input); setSize(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } return stepname; }