2016-09-15 18 views
1

1を表示しないToastbar)ConnectionRequestネットワーク接続が存在しない場合、それはIOExceptionが得られる、上記connectionRequestコードでパラメータ接続と問題

ArrayList<Map<String, Object>> responses; 
public void groupConnection(StateMachine sm, ActionListener al) { 
    ConnectionRequest connectionRequest = new ConnectionRequest() { 
     @Override 
     protected void readResponse(InputStream input) throws IOException { 
      JSONParser jSONParser = new JSONParser(); 
      Map<String, Object> parsedData = jSONParser.parseJSON(new InputStreamReader(input)); 
      responses = (ArrayList<Map<String, Object>>) parsedData.get("root"); 
      Display.getInstance().callSerially(new Runnable() { 
       @Override 
       public void run() { 
        al.actionPerformed(null); 
       } 
      }); 
     } 

     @Override 
     protected void handleException(Exception err) { 
      //System.out.println("handleException " + err); 
     } 

     @Override 
     protected void handleIOException(IOException err) { 
      //toastbar doesnt work here but dialogBox works, if showForm("Groups") is used, toastbar is also shown along with dialogbox 
      //ToastBar.showErrorMessage("Please check your network connection", 4000); 
      //sm.showForm("Groups", null); 
      Dialog.show("", "Please check your network connection", "ok", null); 
     } 
    }; 
    AllUrl allUrl = new AllUrl(); 
    connectionRequest.setUrl(allUrl.groupsMenu); 
    InfiniteProgress ip = new InfiniteProgress(); 
    Dialog d = ip.showInifiniteBlocking(); 
    connectionRequest.setDisposeOnCompletion(d); 
    NetworkManager.getInstance().addToQueue(connectionRequest); 
} 

としてActionListenerを使用して:到達不能の下handleIOException法によって処理されるが、私場合そこにダイアログボックスを使用して、それは動作します。代わりにトーストバーがそこで働くのはなぜですか? showForm( "Form"、null)をdialogBoxおよびtoastbarとともに使用すると、同じフォームが繰り返し呼び出され、複数回表示されるダイアログボックスでトーストバーも表示されます。

2)postForm

上記postForm方法において
connectionGroup = new GroupConnection(); 
connectionGroup.groupConnection(StateMachine.this, new ActionListener() { 

@Override 
public void actionPerformed(ActionEvent evt) { 
//checking connectionGroup.responses == null doesnt work since the connectionRequest gives IOException if no network.So Toastbar doesnt work here. 
    if (connectionGroup.responses == null) { 
     ToastBar.showErrorMessage("Please check your network connection", 4000); 
    } 
    if (connectionGroup.responses != null) { 
     for (Map<String, Object> element : connectionGroup.responses) { 
      String tableName = (String) element.get("name"); 
      TextArea nameLabel = new TextArea(tableName.toUpperCase()); 
      f.add(singleRowContainerr); 
     } 
    } 
    } 
} 

は、私がチェックすることにより、そこにネットワーク接続であるかどうかをチェックするために使用される(フォームF)方法:IF(connectionGroup.responses == NULL){行うなめらか...}、connectionRequestはIoExceptionを返しますので、ここではうまくいきません。&はconnectionRequest内でコードを実行しません。

この問題を解決するにはどうすればよいですか?私はtoastBarに "接続を確認する"と "no connection"というテキストを表示する必要があります。 PS connectionRequestが呼び出される前にフォームに移動する必要があるので、すべてのコンポーネントを&のconnectionRequestをpostFormに配置する必要があります。

答えて

0

ToastBarは、特定のFormに結びついていますが、Dialogは、それ自体を示すようなフォームをブロックします。

ToastBarを1つのフォームに設定してから別のFormに移行しました。