2012-07-10 1 views
1

smartGWT 프로젝트의 타일 그리드에 파일 아이콘을로드하고 있습니다. Enter 키를 누르면 표시 할 파일을 열려고합니다.smartGWT TileGrid :: onKeyPress - Enter 키를 재정의하는 방법, 다른 키의 기본 처리 유지

onKeyPress 처리기를 재정의하면 작동하지만 왼쪽/오른쪽/위/아래 화살표 키를 사용하여 타일 그리드 탐색 동작이 손실됩니다.

내 질문은 .. Enter 키를 무시하면서 기본 처리 동작을 유지하는 방법입니다.

tileGrid.addKeyPressHandler (new KeyPressHandler() { 
    @Override 
    public void onKeyPress(KeyPressEvent event) { 
     if (EventHandler.getKey().equals("Enter")) { 
     //do something special here 
     } 
     else { 
     **//TODO: do the default processing..**. 
     } 
    } 
    }); 

는 편집 :

@Ras, 여기에 문제를 시뮬레이션 코드입니다.

package com.rv.gwtsample.client; 

import com.google.gwt.core.client.EntryPoint; 
import com.google.gwt.core.client.GWT; 
import com.smartgwt.client.data.Record; 
import com.smartgwt.client.widgets.events.KeyPressEvent; 
import com.smartgwt.client.widgets.events.KeyPressHandler; 
import com.smartgwt.client.widgets.tile.TileGrid; 
import com.smartgwt.client.widgets.tile.TileRecord; 

/** 
* @author rvnath 
* 
*/ 
public class MyTileGrid implements EntryPoint { 

    /* (non-Javadoc) 
    * @see com.google.gwt.core.client.EntryPoint#onModuleLoad() 
    */ 
    @Override 
    public void onModuleLoad() { 
     // TODO Auto-generated method stub 
     TileGrid grid = new TileGrid(); 
     grid.setLeft(50); 
     grid.setTop(50); 
     grid.setWidth("300"); 
     grid.setHeight("200"); 
      DetailViewerField field = new DetailViewerField("Name"); 
     grid.setFields(field); 
     grid.addKeyPressHandler(new KeyPressHandler() { 
      @Override 
      public void onKeyPress(KeyPressEvent event) { 
       if (event.getKeyName().equals("Enter")) 
        GWT.log("Enter pressed"); 
      } 
     }); 

    Record[] rec = new TileRecord[32]; 
    for (int i=0; i<32; ++i) { 
     rec[i] = new TileRecord(); 
    } 

    grid.setData(rec); 
    grid.draw(); 
} 

} 

onKeyPress 핸들러를 비활성화하면 화살표 키가 타일 격자 요소 사이를 탐색 할 수 있습니다. 활성화하면 선택 항목 변경 대신 전체 타일 격자 패널이 스크롤됩니다.

답변

0

@Mupparthy, 나는 또한 TextAreaItem에 대한 keyPressHandler()을 구현했습니다. 또한 & 백 스페이스 키만 삭제해야한다는 동일한 요구 사항이있었습니다. 내가 한 일은 , 그렇지 않으면 부분을 처리하지 마십시오. 모든 화살표 키를 포함하여 다른 키에 대한 기본 처리를 자동으로 수행했습니다. 그래서 당신을 위해 작동하지 않는 경우, 우리가 작동하도록 할 수 있도록 독립형 코드를 제공하십시오.

+0

안녕하세요 @RAS, 코드 스 니펫을 추가했습니다. 이 문제를 해결할 수 있다면 알려주십시오. 미리 감사드립니다 ... –

+0

@MupparthyRavindranath, 'else'문을 제거 해봤습니까? – RAS

+0

안녕하세요 @ 라스, 코드에 'else'문이 없습니다. "Enter"키를 처리하기위한 If. –

5

KeyPressHandler를 사용하는 대신 KeyDownHandler를 사용해보십시오.

 tileGrid.addKeyDownHandler(new KeyDownHandler() { 
      @Override 
      public void onKeyDown(KeyDownEvent event) { 
       if (EventHandler.getKey().equalsIgnoreCase("Enter")){ 
        openModal(tileGrid.getSelectedRecord()); 
       } 
      } 
     }); 

최신 3.0 smartgwt 빌드로 테스트되었습니다.

관련 문제