2013-10-04 2 views
2

Navison 조회를 수행하고 ObservableList 또는 Null을 반환하는 작업이 있습니다.
조회가 성공하고 목록이 채워지 든간에 작업이 항상 failed()를 호출하고 succeeded()!을 호출하지 않아도 상관 없습니다!
이것이 어떤 이유입니까?
여기 내 작업이다.
JavaFx 2 작업 성공/실패

다음
public class LoadLocsTask extends Task<Void>{ 
    Button button; 
    @Override protected Void call() throws Exception { 

      ObservableList<String> list = application.getValidator().getLocList(button.getText()); 
      if(list != null){ 
       locationList.setItems(list); 
      }else{ 
       Dialogs.showErrorDialog(application.getPrimaryStage(),"An error occured while retrieving the loaction list from navision.", "Please contact IS department", "Unable To Populate Location List"); 
       locationList.setItems(null); 
      } 
     return null;  
    } 

    @Override protected void succeeded() { 
     super.succeeded(); 
     selectProgressIndicator.setVisible(false); 
     disableSelected(button); 

    } 
    @Override protected void failed() { 
     super.failed(); 
     selectProgressIndicator.setVisible(false); 
     disableSelected(button); 

    } 
    @Override protected void scheduled() { 
     super.scheduled(); 
     locationList.getSelectionModel().clearSelection(); 
     locationList.setItems(null); 
     selectProgressIndicator.setVisible(true); 
     disableAll(); 

    } 
    @Override protected void cancelled() { 
     super.cancelled(); 
     logger.info("Cancelled"); 
     locationList.setItems(null); 
     selectProgressIndicator.setVisible(true); 

    } 

이 application.getValidator()이다 getLocList (button.getText())

public ObservableList<String> getLocList(String selectedLoc) { 
    ObservableList<String> binsOL = null; 
    String warehouseCode = null; 
    if (selectedLoc.equalsIgnoreCase("location1")) { 
     warehouseCode = "LOCATION1"; 
    } else if (selectedLoc.equalsIgnoreCase("location2")) { 
     warehouseCode = "LOCATION2"; 
    } else if (selectedLoc.equalsIgnoreCase("location3")) { 
     warehouseCode = "LOCATION3"; 
    } else if (selectedLoc.equalsIgnoreCase("location4")) { 
     warehouseCode = "LOCATION4"; 
    } else if (selectedLoc.equalsIgnoreCase("location5")) { 
     warehouseCode = "LOCATION5"; 
    } 

    if (warehouseCode != null) { 
     try { 
      binsOL = FXCollections.observableArrayList(); 
      Bins[] bins = navWebservice.getBinsList(warehouseCode); 
      for (Bins bin : bins) { 
       binsOL.add(bin.getCode()); 
      } 
     } catch (RemoteException e) { 
      logger.error("LocationSelectionController - processLocButton(): Could not generate list for " + warehouseCode + " button", e); 
      Dialogs.showErrorDialog(parentApp.getPrimaryStage(), e.getMessage(), "Please contact IS department", "Unable To Populate Location List"); 

     } 
    } 
    return binsOL; 

} 
사전에

감사합니다!

+0

@jewelsea은 왜 그렇게 두지 않는 답변으로? – ConquerorsHaki

답변

1

코드가 스레드 안전하지 않기 때문에 작업 호출 방법의 목록보기에서 대화 상자를 표시하고 항목을 업데이트하지 말고 해당 작업을 Platform.runLater에 래핑하지 않아야합니다. Platform.runLater 및 자바 FX 동시성에 대한 더 많은 정보 검색 유래를 들어

는 :