private boolean hasStyle(ModuleItem<?> item, String style) { String widgetStyle = item.getWidgetStyle(); if (widgetStyle == null) return false; return Arrays.asList(widgetStyle.trim().split("\\s*,\\s*")) .contains(style); } }
@Override public boolean isStyle(final String style) { final String widgetStyle = getItem().getWidgetStyle(); if (widgetStyle == null) return style == null; for (final String s : widgetStyle.split(",")) { if (s.equals(style)) return true; } return false; }
@Override public boolean isStyle(final String style) { final String widgetStyle = getItem().getWidgetStyle(); if (widgetStyle == null) return style == null; for (final String s : widgetStyle.split(",")) { if (s.equals(style)) return true; } return false; }
private boolean excludedFromRecording(final ModuleItem<?> input) { // Skip parameters of insufficient visibility. final ItemVisibility visibility = input.getVisibility(); if (visibility == ItemVisibility.INVISIBLE) return true; if (visibility == ItemVisibility.MESSAGE) return true; // Skip password parameters. final String style = input.getWidgetStyle(); if (style != null) { for (final String s : style.split(",")) { if (s.equals(TextWidget.PASSWORD_STYLE)) return true; } } return false; }
@Override public String getTargetWidgetStyle(ModuleItem<?> item) { ArrayList<String> targetStyles = new ArrayList<>(); if (hasStyle(item, FileWidget.DIRECTORY_STYLE)) { targetStyles.add(FileListWidget.DIRECTORIES_ONLY); } else { targetStyles.add(FileListWidget.FILES_ONLY); } // extensions? String widgetStyle = item.getWidgetStyle(); if (widgetStyle != null) { String[] styles = widgetStyle.trim().split("\\s*,\\s*"); for (String s : styles) { if (s.startsWith("extensions")) { // TODO: use new constant from FileListWidget targetStyles.add(s); } } } return String.join(",", targetStyles); }
private List<File> getFilesFromFolder(File inputFolder) { // get files in folder and add to listModel List<File> fileList = new ArrayList<>(); final WidgetModel widgetModel = get(); final String widgetStyle = widgetModel.getItem().getWidgetStyle(); FileFilter filter = SwingFileWidget.createFileFilter(widgetStyle); try { fileList = Arrays .asList((Files.walk(inputFolder.toPath()) .filter(path -> filter.accept(path.toFile()))) .map(path -> path.toFile()) .toArray(File[]::new)); } catch (IOException exc) { logService .error("Error when trying to retrieve file list", exc); } return fileList; }
private int getBoxAxis(final WidgetModel model) { if (model.isStyle(ChoiceWidget.RADIO_BUTTON_HORIZONTAL_STYLE)) { return BoxLayout.X_AXIS; } if (model.isStyle(ChoiceWidget.RADIO_BUTTON_VERTICAL_STYLE)) { return BoxLayout.Y_AXIS; } throw new IllegalStateException("Invalid widget style: " + model.getItem().getWidgetStyle()); }
@Override public void set(final WidgetModel model) { super.set(model); path = new JTextField(16); path.setDragEnabled(true); final String style = model.getItem().getWidgetStyle(); path.setTransferHandler(new FileTransferHandler(style)); setToolTip(path); getComponent().add(path); path.getDocument().addDocumentListener(this); getComponent().add(Box.createHorizontalStrut(3)); browse = new JButton("Browse"); setToolTip(browse); getComponent().add(browse); browse.addActionListener(this); refreshWidget(); }
@Override public void actionPerformed(final ActionEvent e) { File file = new File(path.getText()); if (!file.isDirectory()) { file = file.getParentFile(); } // display file chooser in appropriate mode final String style = get().getItem().getWidgetStyle(); final FileDialog fileDialog = new FileDialog((Frame) null); if (FileWidget.SAVE_STYLE.equals(style)) { fileDialog.setMode(FileDialog.SAVE); } else { // default behavior fileDialog.setMode(FileDialog.LOAD); } fileDialog.setDirectory(file.getAbsolutePath()); fileDialog.setVisible(true); final String filename = fileDialog.getFile(); fileDialog.dispose(); if (filename == null) return; path.setText(filename); }
final String style = model.getItem().getWidgetStyle(); paths.setTransferHandler(new FileListTransferHandler(style)); JScrollPane scrollPane = new JScrollPane(paths);
final String widgetStyle = widgetModel.getItem().getWidgetStyle(); FileFilter filter = SwingFileWidget.createFileFilter(widgetStyle);
@Override public void process(final Module module) { if (uiService == null) return; final ModuleItem<File> fileInput = getFileInput(module); if (fileInput == null) return; final File file = fileInput.getValue(module); final String style = fileInput.getWidgetStyle(); // show file chooser dialog box final File result = uiService.chooseFile(file, style); if (result == null) { cancel(""); return; } fileInput.setValue(module, result); module.resolveInput(fileInput.getName()); }
@Override public void process(final Module module) { if (uiService == null) return; final ModuleItem<File[]> fileInput = getFilesInput(module); if (fileInput == null) return; final File[] files = fileInput.getValue(module); // show file chooser dialog box // TODO decide how to create filter from style attributes // TODO retrieve parent folder?? final File[] result = uiService.chooseFiles(null, files, null, fileInput.getWidgetStyle()); if (result == null) { cancel(""); return; } fileInput.setValue(module, result); module.resolveInput(fileInput.getName()); }
@Override public void process(final Module module) { if (uiService == null) return; final ModuleItem<File> fileInput = getFileInput(module); if (fileInput == null) return; final File file = fileInput.getValue(module); final String style = fileInput.getWidgetStyle(); // show file chooser dialog box final File result = uiService.chooseFile(file, style); if (result == null) { cancel(""); return; } fileInput.setValue(module, result); module.resolveInput(fileInput.getName()); }
@Override public void process(final Module module) { if (uiService == null) return; final ModuleItem<File[]> fileInput = getFilesInput(module); if (fileInput == null) return; final File[] files = fileInput.getValue(module); // show file chooser dialog box // TODO decide how to create filter from style attributes // TODO retrieve parent folder?? final File[] result = uiService.chooseFiles(null, files, null, fileInput.getWidgetStyle()); if (result == null) { cancel(""); return; } fileInput.setValue(module, result); module.resolveInput(fileInput.getName()); }
/** Creates a new module item with the same values as the given item. */ public DefaultMutableModuleItem(final ModuleInfo info, final ModuleItem<T> item) { super(info); name = item.getName(); type = item.getType(); genericType = item.getGenericType(); ioType = item.getIOType(); visibility = item.getVisibility(); required = item.isRequired(); persisted = item.isPersisted(); persistKey = item.getPersistKey(); initializer = item.getInitializer(); validater = item.getValidater(); callback = item.getCallback(); widgetStyle = item.getWidgetStyle(); minimumValue = item.getMinimumValue(); maximumValue = item.getMaximumValue(); softMinimum = item.getSoftMinimum(); softMaximum = item.getSoftMaximum(); stepSize = item.getStepSize(); columnCount = item.getColumnCount(); final List<T> itemChoices = item.getChoices(); if (itemChoices != null) choices.addAll(itemChoices); label = item.getLabel(); description = item.getDescription(); }
/** Creates a new module item with the same values as the given item. */ public DefaultMutableModuleItem(final ModuleInfo info, final ModuleItem<T> item) { super(info); name = item.getName(); type = item.getType(); genericType = item.getGenericType(); ioType = item.getIOType(); visibility = item.getVisibility(); required = item.isRequired(); persisted = item.isPersisted(); persistKey = item.getPersistKey(); initializer = item.getInitializer(); validater = item.getValidater(); callback = item.getCallback(); widgetStyle = item.getWidgetStyle(); minimumValue = item.getMinimumValue(); maximumValue = item.getMaximumValue(); softMinimum = item.getSoftMinimum(); softMaximum = item.getSoftMaximum(); stepSize = item.getStepSize(); columnCount = item.getColumnCount(); final List<T> itemChoices = item.getChoices(); if (itemChoices != null) choices.addAll(itemChoices); label = item.getLabel(); description = item.getDescription(); }
private void assertItem(final String name, final Class<?> type, final String label, final ItemIO ioType, final boolean required, final boolean persist, final String persistKey, final String style, final Object value, final Object min, final Object max, final Object softMin, final Object softMax, final Number stepSize, final List<?> choices, final ModuleItem<?> item) { assertEquals(name, item.getName()); assertSame(type, item.getType()); assertEquals(label, item.getLabel()); assertSame(ioType, item.getIOType()); assertEquals(required, item.isRequired()); assertEquals(persist, item.isPersisted()); assertEquals(persistKey, item.getPersistKey()); assertEquals(style, item.getWidgetStyle()); assertEquals(value, item.getDefaultValue()); assertEquals(min, item.getMinimumValue()); assertEquals(max, item.getMaximumValue()); assertEquals(softMin, item.getSoftMinimum()); assertEquals(softMax, item.getSoftMaximum()); assertEquals(stepSize, item.getStepSize()); assertEquals(choices, item.getChoices()); }