Example usage for org.apache.commons.lang3 StringUtils abbreviateMiddle

List of usage examples for org.apache.commons.lang3 StringUtils abbreviateMiddle

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils abbreviateMiddle.

Prototype

public static String abbreviateMiddle(final String str, final String middle, final int length) 

Source Link

Document

Abbreviates a String to the length passed, replacing the middle characters with the supplied replacement String.

This abbreviation only occurs if the following criteria is met:

  • Neither the String for abbreviation nor the replacement String are null or empty
  • The length to truncate to is less than the length of the supplied String
  • The length to truncate to is greater than 0
  • The abbreviated String will have enough room for the length supplied replacement String and the first and last characters of the supplied String for abbreviation

Otherwise, the returned String will be the same as the supplied String for abbreviation.

Usage

From source file:org.sleuthkit.autopsy.timeline.ShowInTimelineDialog.java

/**
 * Constructor for file based dialog. Allows the user to choose an event
 * (MAC time) derived from the given file
 *
 * @param controller The controller for this Dialog.
 * @param file       The AbstractFile to configure this dialog for.
 *//*from  w ww.ja v  a2 s  . c o m*/
@NbBundle.Messages({ "# {0} - file path", "ShowInTimelineDialog.fileTitle=View {0} in timeline.",
        "ShowInTimelineDialog.eventSelectionValidator.message=You must select an event." })
ShowInTimelineDialog(TimeLineController controller, AbstractFile file) {
    this(controller, controller.getEventsModel().getEventIDsForFile(file, false));

    /*
     * since ValidationSupport does not support list selection, we will
     * manually apply and remove decoration in response to selection
     * property changes.
     */
    eventTable.getSelectionModel().selectedItemProperty().isNull()
            .addListener((selectedItemNullProperty, wasNull, isNull) -> {
                if (isNull) {
                    validationSupport.getValidationDecorator().applyValidationDecoration(ValidationMessage
                            .error(eventTable, Bundle.ShowInTimelineDialog_eventSelectionValidator_message()));
                } else {
                    validationSupport.getValidationDecorator().removeDecorations(eventTable);
                }
            });

    //require selection and validation of ammount spinner to enable show button
    getDialogPane().lookupButton(SHOW).disableProperty().bind(Bindings.or(validationSupport.invalidProperty(),
            eventTable.getSelectionModel().selectedItemProperty().isNull()));

    //set result converter that uses selection.
    setResultConverter(buttonType -> (buttonType == SHOW)
            ? makeEventInTimeRange(eventTable.getSelectionModel().getSelectedItem())
            : null);

    setTitle(Bundle.ShowInTimelineDialog_fileTitle(
            StringUtils.abbreviateMiddle(getContentPathSafe(file), " ... ", 50)));
}