2017-09-08 11 views
0

DialogSelectionListener으로 닫는 방법은 무엇입니까? 현재 내 SelectionListener은 다음과 같습니다SelectionListener의 JFace 닫기 대화 상자

public void widgetSelected(SelectionEvent e) { 
    ICommandService commandService = (ICommandService) PlatformUI.getWorkbench() 
      .getService(ICommandService.class); 
    IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench() 
      .getService(IHandlerService.class); 

    Command command = commandService 
      .getCommand("com.mainfirst.backoffice.gui.accounting.command.createBookingReversal"); 

    Map<String, String> params = new HashMap<String, String>(); 
    params.put("com.mainfirst.backoffice.gui.accounting.reversalCodeParameter", 
      String.valueOf(model.getVal().getCode())); 

    ParameterizedCommand paraCommand = ParameterizedCommand.generateCommand(command, params); 

    try { 
     handlerService.executeCommand(paraCommand, null); 
    } catch (Exception ex) { 
     Status status = new Status(IStatus.ERROR, AccountingActivator.PLUGIN_ID, 
       "Error opening reversal wizard", ex); 
     StatusManager.getManager().handle(status, StatusManager.SHOW); 
     throw new RuntimeException(ex); 
    } 
    close(); 
} 

당신은 내가 close(); 부르지 볼 수 있지만, Dialog은 결국 계속 열려있게 않기 때문에. 전화를 finally 블록으로 이동해도 도움이되지 않습니다. 내 명령은 Dialog 앞에 새 Wizard을 엽니 다. Wizard이 열리기 전에 Dialog을 종료해야합니까?

+0

@ greg-449이 (가) 질문을 편집했습니다. [여기] (https://stackoverflow.com/questions/46113246/jface-disable-finish-button-in-wizard) 내 두 번째 질문입니다 – XtremeBaumer

+0

명령은 무엇을합니까? 명령이 끝나기 전에 대화 상자가 닫히기를 기대하십니까? –

+0

명령이 핸들러를 호출하면 마법사가 열립니다. 단추를 클릭하자마자 대화 상자가 닫히지 만 명령은 여전히 ​​실행되어야합니다. – XtremeBaumer

답변

1

실행중인 명령이 완료되기 전에 대화 상자를 닫으려면 비동기 적으로 명령을 실행해야합니다. 이 경우 Display.asyncExec을 사용하십시오.

public void widgetSelected(SelectionEvent e) { 

    Display.getDefault().asyncExec(() -> 
     { 
      ... code to call command 
     }); 

    close(); 
} 

(자바 8 가정, 자바 7 이전에 대한 Runnable 사용) : 같은 것을 사용합니다.