vendredi 1 mars 2019

ListChangeListener, AddListener to ListView or Boolean Checkboxes in ListView

I have a java program I didn´t code that I am reversing/updating in order to add some much needed functionality.

This program generates two ListViews, list1:NameEntry & list2:GroupEntry based on some csv files found in /input.

NameEntry contains a list of user names with respective checkboxes. GroupEntry contains a long list of user roles with its checkboxes.

My current task was to add a 'Select All Roles' checkbox to the GUI that sets all the GroupEntry role items to 'true'. This was accomplished successfully.

My issue is adding an onChanged() listener to either the ListView or the individual checkbox items in order to disable the 'Set All Roles' toggle in the case that one or more of the roles is manually unchecked.

@FXML
  public void setAllRoles()
  {
    ObservableList<GroupEntry> groups = this.list2.getItems();
    if (this.allRoles) {
      this.allRoles = false;
      for (GroupEntry item : groups) {
      item.setSelected(new SimpleBooleanProperty(false));
      this.list2.refresh();
      }
    } else {
      this.allRoles = true;
      for (GroupEntry item : groups) {
      item.setSelected(new SimpleBooleanProperty(true));
      item.addListener(new ListChangeListener<GroupEntry>() {
           public abstract onChanged(ObservableValue<? extends GroupEntry> ov,
             Boolean old_val, Boolean new_val) {
                 //System.out.println(item.isSelected());
                 allRoles = false;
             }
      });
      }
      this.list2.refresh();
    }
  }

When trying to compile the controller .class file I receive the below error:

invalid method declaration; return type required
           public abstract onChanged(ObservableValue<? extends GroupEntry> ov,
                           ^

I´ve also tried without the abstract but compiler returns the same error.

This is all javafx. Does anyone have any idea what the issue could be or have any clear examples/guidelines? I´ve read countless documentation pages but cannot seem to wrap my head around this simple error. I am fairly new to Java but not coding.

Many thanks ahead of time!




Aucun commentaire:

Enregistrer un commentaire