private void setParameterFileValue(File file) { getParameter().setValue(file, null); updateLastDir(); }
private void updateLastDir() { File file = (File) getParameter().getValue(); if (file != null) { File parentFile = file.getParentFile(); if (parentFile != null) { setLastDir(parentFile); } } }
@Override protected void invokeXEditor() { File lastDir = getLastDir(); File file = getParameterFileValue(); JFileChooser fileChooser; int fsm = getParameter().getProperties().getFileSelectionMode(); if (fsm == ParamProperties.FSM_DIRECTORIES_ONLY) { if (file == null) { fileChooser.setDialogTitle(getXEditorTitle()); final FileFilter[] choosable = getParameter().getProperties().getChoosableFileFilters(); if (choosable != null) { for (int i = choosable.length - 1; i > -1; i--) { final FileFilter current = getParameter().getProperties().getCurrentFileFilter(); if (current != null) { fileChooser.setFileFilter(current); option = fileChooser.showDialog(getEditorComponent(), _FILE_APPROVE_BUTTON_TEXT); } else if (fsm == ParamProperties.FSM_DIRECTORIES_ONLY) { option = fileChooser.showDialog(getEditorComponent(), _DIR_APPROVE_BUTTON_TEXT); } else { option = fileChooser.showDialog(getEditorComponent(), _DEFAULT_APPROVE_BUTTON_TEXT); setLastDir(fileChooser.getCurrentDirectory()); if (option == BeamFileChooser.APPROVE_OPTION) { file = fileChooser.getSelectedFile(); if (file != null) { setParameterFileValue(file);
public void testFileEditor() { final ParamProperties properties = new ParamProperties(File.class); properties.setLabel(LABEL_NAME); properties.setPhysicalUnit(UNIT_NAME); properties.setDefaultValue(new File("sabines_home")); final Parameter parameter = new Parameter(PARAM_NAME, properties); ParamEditor editor = parameter.getEditor(); assertTrue(editor instanceof FileEditor); final FileEditor fileEditor = (FileEditor) editor; final JComponent editorComponent = fileEditor.getEditorComponent(); assertEquals("theParamName.XEditor", editorComponent.getName()); assertEquals(JPanel.class.getName(), editorComponent.getClass().getSuperclass().getName()); final Component[] components = editorComponent.getComponents(); assertEquals(2, components.length); assertEquals("theParamName.Editor", components[0].getName()); assertEquals("theParamName.ButtonPanel", components[1].getName()); assertEquals(JTextField.class.getName(), components[0].getClass().getName()); assertEquals(JPanel.class.getName(), components[1].getClass().getName()); final JPanel buttonPanel = ((JPanel) components[1]); assertEquals(1, buttonPanel.getComponentCount()); assertEquals(JButton.class.getName(), buttonPanel.getComponents()[0].getClass().getName()); assertEquals("theParamName.Label", fileEditor.getLabelComponent().getName()); assertEquals(LABEL_NAME + ": ", fileEditor.getLabelComponent().getText()); assertEquals("theParamName.Unit", fileEditor.getPhysUnitLabelComponent().getName()); assertEquals(" " + UNIT_NAME, fileEditor.getPhysUnitLabelComponent().getText()); }
private File getParameterFileValue() { return (File) getParameter().getValue(); }
editor = new ColorEditor(parameter); } else if (parameter.isTypeOf(File.class)) { editor = new FileEditor(parameter); } else if (paramProps.getValueSet() != null && paramProps.getValueSet().length > 0) {
private File getLastDir() { if (getParameter().getValue() instanceof File) { File file = (File) getParameter().getValue(); final File parentDir = file.getParentFile(); if (parentDir != null && parentDir.isDirectory()) { return parentDir; } } return (File) getParameter().getProperties().getPropertyValue(ParamProperties.LAST_DIR_KEY, SystemUtils.getApplicationHomeDir()); }
private void setLastDir(final File lastDir) { getParameter().getProperties().setPropertyValue(ParamProperties.LAST_DIR_KEY, lastDir); } }