I have this small piece of code written in a class. I am looking for a nicer way to write this, preferably avoiding nested if statements like what I currently have:@Override  public void popupMenuWillBecomeVisible(PopupMenuEvent e)  {    TheatreListDataWrapper[] selectedOperations = getSelectedDatas();    boolean isOperationFromMulitpleSoc = TheatreListDataWrapper.operationsOfMultiplePatients(selectedOperations);    if (!isOperationFromMulitpleSoc)    {      //passing boolean literal value 'false' instead of variable 'isOperationFromMultipleSoc' since that,      //at this point it is certain that the operations selected are from a single patient      CambioAction attentionSignalAction = AttentionSignalDelegator.getAttentionSignalAction(false,selectedOperations);      if (attentionSignalAction != null)      {        if (Framework.getInstance().getActiveSubjectOfCare().id == null            || !getAcuteListTable().getTableDataByRow(getAcuteListTable().getSelectedRow()).socId.equals(Framework                .getInstance().getActiveSubjectOfCare().id))        {          attentionSignalAction.setEnabled(false);        }        else        {          attentionSignalAction.setEnabled(true);        }      }    }    if(selectedOperations != null && selectedOperations.length > 1){        listRegistraionOpenMenuItem.setEnabled(false);    }else{        listRegistraionOpenMenuItem.setEnabled(true);    }  }For me, using that last if checking seems like, I could do it in a better way, using a switch or some other control structure. Is there a way to avoid the null checks?
Conditional logic to determine if popup menu should be visible
java;swing;null
You may not need another if else to setEnabled. The expression within if returns a boolean. Just set the inverse of it to setEnabled. You can pull it into a variable in case of better readability. Updated:if (attentionSignalAction != null) {  bool isActiveRowSelected = (Framework.getInstance().getActiveSubjectOfCare().id == null||!getAcuteListTable().getTableDataByRow(getAcuteListTable().getSelectedRow()).socId.equals(Framework.getInstance().getActiveSubjectOfCare().id));  attentionSignalAction.setEnabled(!isActiveRowSelected);}Update 2if(selectedOperations != null && selectedOperations.length > 1){    listRegistraionOpenMenuItem.setEnabled(false);}else{    listRegistraionOpenMenuItem.setEnabled(true);}can also be reduced tobool operationsSelected = (selectedOperations != null && selectedOperations.length > 1);listRegistraionOpenMenuItem.setEnabled(!operationsSelected);