Package com.onec.ui
Class ActionSpec
java.lang.Object
com.onec.ui.ActionSpec
Declares custom action buttons for an entity, from
EntityView.actions(ActionSpec).
Each action is a labelled, icon'd button placed on the list (toolbar or per-row) or the record detail. It does one of two things when clicked:
- a server handler —
.handler(ctx -> ...)runs arbitrary backend logic and returns anActionResult(toast / refresh / navigate); or - a navigation —
.navigate("onec://...")just routes the client (a{id}placeholder is filled with the row/record id).
public void actions(ActionSpec a) {
a.action("archive").label("Archive").icon("archive").scope(ActionScope.ROW)
.handler(ctx -> { repo.archive(ctx.id()); return ActionResult.refresh("Archived"); });
a.action("report").label("Open report").icon("file-text").scope(ActionScope.TOOLBAR)
.navigate("onec://reports/occupancy");
}
A row action's icon, label, visibility and enabled state may be a function of the row
instead of fixed, so one control adapts to each record (a pause "Suspend" on a running
row, a play "Resume" on a stopped one; a button shown only where it applies). Pass a
ActionRow-taking function/predicate; it's evaluated per row as the list renders:
a.action("suspend").scope(ActionScope.ROW)
.icon(row -> row.enumValue("status", Status.class) == Status.STOPPED ? "play" : "pause")
.label(row -> row.enumValue("status", Status.class) == Status.STOPPED ? "Resume" : "Suspend")
.visibleWhen(row -> row.enumValue("status", Status.class) != Status.ARCHIVED)
.handler(ctx -> { service.toggle(ctx.id()); return ActionResult.refresh(); });
The per-row functions apply to ActionScope.ROW actions only (toolbar/detail buttons
have no row context); on other scopes they're ignored in favour of the fixed icon/label.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA resolved action button.static final classFluent builder for one action; setters may be called in any order. -
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
ActionSpec
public ActionSpec()
-
-
Method Details
-
action
Start declaring an action with the given unique key. -
actions
-