Package com.onec.ui

Class ActionSpec

java.lang.Object
com.onec.ui.ActionSpec

public final class ActionSpec extends Object
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 an ActionResult (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.