@NotNull public static Text createOutputFolderChooser( final Composite parent, @Nullable String label, @Nullable ModifyListener changeListener) { UIUtils.createControlLabel( parent, label != null ? label : CoreMessages.data_transfer_wizard_output_label_directory); Composite chooserPlaceholder = UIUtils.createPlaceholder(parent, 2); chooserPlaceholder.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final Text directoryText = new Text(chooserPlaceholder, SWT.BORDER); directoryText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); if (changeListener != null) { directoryText.addModifyListener(changeListener); } final Runnable folderChooser = new Runnable() { @Override public void run() { DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.NONE); dialog.setMessage(CoreMessages.data_transfer_wizard_output_dialog_directory_message); dialog.setText(CoreMessages.data_transfer_wizard_output_dialog_directory_text); String directory = directoryText.getText(); if (!CommonUtils.isEmpty(directory)) { dialog.setFilterPath(directory); } directory = dialog.open(); if (directory != null) { directoryText.setText(directory); } } }; directoryText.addMouseListener( new MouseAdapter() { @Override public void mouseUp(MouseEvent e) { folderChooser.run(); } }); Button openFolder = new Button(chooserPlaceholder, SWT.PUSH | SWT.FLAT); openFolder.setImage(DBeaverIcons.getImage(DBIcon.TREE_FOLDER)); openFolder.setLayoutData( new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.HORIZONTAL_ALIGN_CENTER)); openFolder.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { folderChooser.run(); } }); return directoryText; }
@NotNull public static Text createLabelText( @NotNull Composite parent, @NotNull String label, @Nullable String value, int style, @Nullable Object layoutData) { createControlLabel(parent, label); Text text = new Text(parent, style); if (value != null) { text.setText(value); } if (layoutData != null) { text.setLayoutData(layoutData); } return text; }
@Nullable public static Integer getTextInteger(Text text) { String str = text.getText(); str = str.trim(); if (str.length() == 0) { return null; } try { return Integer.valueOf(str); } catch (NumberFormatException e) { log.debug(e); return null; } }