Proposal to allow custom placeholder text in TaskProgressView

5 views
Skip to first unread message

Mark Schmieder

unread,
Apr 1, 2023, 12:12:43 AM4/1/23
to ControlsFX
I made an edit years ago to a cloned copy of ControlsFX due to not finding anyway to override or customize certain features that received strong negative feedback from my clients.

I hope I am not being too granular by posting these separately, but it seems more likely to get the right community results if I do.

The most important feature people requested was to have custom placeholder text when the Task Progress View is empty/flushed or not yet in use. Literally no one was happy with the generic "No tasks running" banner. They usually wanted domain-specific language.

This was trivial to enhance, but I never had time to propose it (learning curve at the time on too many things as I wasn't even on Git yet). The least invasive way I could find was to add a new constructor for TaskProgressView that takes a custom placeholder String, and have the original constructor call that one with null (or some safer Nullable equivalent), to get the default string, cache this locally, then pass it to the skin.

Ideally, one could set it during run-time as there may be cases where it should change dynamically, for apps that do a lot of role-switching but use consolidated task logging.

In TaskProgressView, I made these changes:

protected String placeholderText;


public TaskProgressView() {

this( null );

}


public TaskProgressView( final String pPlaceholderText ) {

getStyleClass().add( "task-progress-view" );


placeholderText = pPlaceholderText;


.

.

.


}


@Override

protected Skin< ? > createDefaultSkin() {

return new TaskProgressViewSkin<>( this, placeholderText );

}


Then, a minor modification to the TaskProgressViewerSkin constructor:

public TaskProgressViewSkin( final TaskProgressView< T > monitor,

final String placeholderText ) {


super( monitor );


final BorderPane borderPane = new BorderPane();

borderPane.getStyleClass().add( "box" );


// Use a List View for the monitored Tasks.

final ListView< T > listView = new ListView<>();

listView.setPrefSize( 500d, 400d );

final Label placeholderLabel = new Label( ( placeholderText != null )

? placeholderText

: "No tasks running" );

listView.setPlaceholder( placeholderLabel );

listView.setCellFactory( param -> new TaskCell() );

listView.setFocusTraversable( false );


Bindings.bindContent( listView.getItems(), monitor.getTasks() );

borderPane.setCenter( listView );


getChildren().add( listView );

}


I also needed to make some minor changes to taskprogressview.css, but I suppose one could just override the TaskProgressView class and then override the getUserAgentStylesheet() method to express a different one (even if only mildly altered).
Reply all
Reply to author
Forward
0 new messages