2012-03-13 40 views
5

Code:Eclipse StatusManager không hiển thị chi tiết

Job job = new Job("Connect to Database") { 
      @Override 
      protected IStatus run(IProgressMonitor monitor) { 
       // 即使是在正常的情况下,某些版本的DB2的连接建立时间也比较长。。。 
       monitor.beginTask("正在建立到数据库的连接 ...", 100); 
       try { 
        Thread.sleep(3000); 
        database = new Database(cp.getName(), cp.getConnection()); 
       } catch (Exception e) { 
        e.printStackTrace(); 
        IStatus sqlErrorStatus = new Status(IStatus.ERROR, "amarsoft.dbmp", e.getMessage(), null); 
        StatusManager.getManager().handle(sqlErrorStatus, StatusManager.SHOW); 
       } 
       monitor.done(); 
       return Status.OK_STATUS; 
      } 
     }; 

enter image description here

Làm thế nào tôi có thể làm cho nó hiển thị stack trace của ngoại lệ khi người dùng nhấp vào nút 'Chi tiết'?

Trả lời

6

Hộp thoại trạng thái chi tiết mặc định không không hiển thị dấu vết ngăn xếp ngoại lệ.

Nếu bạn có Eclipse product của riêng mình thì bạn có thể tùy chỉnh chi tiết và vùng hỗ trợ của hộp thoại trạng thái bằng cách sử dụng org.eclipse.ui.statusHandlers điểm mở rộng. Bạn sẽ cần phải mở rộng WorkbenchErrorHandler và ghi đè configureStatusDialog(...) phương pháp:

void configureStatusDialog(WorkbenchStatusDialogManager statusDialog) { 
    statusDialog.enableDefaultSupportArea(true); 
    statusDialog.setDetailsAreaProvider(new CustomStatusAreaProvider()); 
} 

class CustomStatusAreaProvider extends AbstractStatusAreaProvider { 
    Control createSupportArea(Composite parent, StatusAdapter statusAdapter) { 
     //Create and return details area 
    } 
} 



By đi qua các ngoại lệ-Status thay vì null bạn thực hiện các vết đống sẵn cho hộp thoại chi tiết về lỗi xem log .

+0

không hoạt động. nó chỉ hiển thị thông báo (chuỗi được trả về bởi # exception.getMessage) hai lần trong vùng chi tiết. – CaiNiaoCoder

+0

@CaiNiaoCoder Bạn đúng, tôi nên kiểm tra nó trước! Đã cập nhật câu trả lời của tôi. –

Các vấn đề liên quan