swt j face 2/3

22
JFACE 에 에에 SWT/JFace 조조조 (V0.9, 12/07/07) http://cafe.naver.com/eclips eplugin http://hangumkj.blogspot.com /

Upload: cho-hyun-jong

Post on 18-Dec-2014

1.611 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Swt J Face 2/3

JFACE 에 대해SWT/JFace

조현종 (V0.9, 12/07/07)http://cafe.naver.com/eclipsepluginhttp://hangumkj.blogspot.com/[email protected]

Page 2: Swt J Face 2/3

목 차

JFace는? Hello World 예제 Image, Font, Color Registry 소개 Action 과 Contribution 소개 Viewer 소개 LabelProvider ContentProvider TreeViewer TableViewer TreeTableViewer ListViewer Dialog, Wizard, Preference 소개 팀 회의 실습

Page 3: Swt J Face 2/3

JFace 는 ?

- 모델 기반 어뎁터 or 헬퍼 클래스- www.eclipse.org/swt

Page 4: Swt J Face 2/3

UI Framework

문제 : 구조적인 도메인 모델을 탐색 및 조작 할 수 있어야

한다 . 도메인이 바뀌어도 UI 와 싱크를 맞추어야 한다 .

Page 5: Swt J Face 2/3

HelloWorld 예제

public HelloWorldJFace() { // 2

super(null);

createActions();

addToolBar(SWT.FLAT | SWT.WRAP);

addMenuBar();

addStatusLine();

}

protected Control createContents(Composite parent) // 8 composit 생성private void createActions() // 3 명령 설정protected ToolBarManager createToolBarManager(int style) // 4 메뉴 아래에 툴바 protected MenuManager createMenuManager() // 5 최상위 메뉴 설정protected StatusLineManager createStatusLineManager() // 6 하단에 상태바public static void main(String args[]) { // 1

try {

HelloWorldJFace window = new HelloWorldJFace();

window.setBlockOnOpen(true);

window.open();

Display.getCurrent().dispose();

} catch (Exception e) {

e.printStackTrace();

}

}

protected void configureShell(Shell newShell) // 7

protected Point getInitialSize() // 9

public class HelloWorldJFace extends ApplicationWindow {

Page 6: Swt J Face 2/3

HelloWorld 예제 실행

1. SWT Designer 사용2. File -> New -> Project -> Designer ->

SWT/JFace Java Project

Page 7: Swt J Face 2/3

Viewer 소개

Viewer 는 ? Model + View + Control 을 분리 . 정렬 필터링 랜더링 ( 아이콘 , 레벨 ) Action 을 제공

종류Combo,List, Table, Tree, Text, TreeTable

Page 8: Swt J Face 2/3

Viewer 소개

Page 9: Swt J Face 2/3

ContentProvider

IStructuredContentProvider : table, list Object[] getEmement(Object)

ITreeContentProvider : tree Object[] getChildren(Object) : 자식 객체 리턴 getParent(Object) : 부모객체 리턴 hasChildren(Object) : 자식 객체 유무 getEmentnt : 최상위 부모 노드의 자식 리턴

Page 10: Swt J Face 2/3

LabelProvider ILabelProvider -> Tree, List

getImage(Object) 해당 이미지 리턴 getText(Object) 해당 텍스트 리턴

ITableLabelProvider -> Table getColumnImage(Object, int) getColumnText(Object, int)

Page 11: Swt J Face 2/3

Tree Viewer 소개

TreeViewer

setContentProvider()setLabelProvider()

ILabelProvider

getImage(Object)getText(Object)

ITreeContent-Provider

getChildren(Object)getParent(Object)inputChange(Object)

Do-main Data

사용

사용

사용

사용

Page 12: Swt J Face 2/3

Tree Viewer 소개 모델변경 – 모델변경 -> view 변경

TreeViewer

addChild()removeChild()updateNode()refresh()

MyModelContent-Provider

getChildren(Object)getParent(Object)domainChange(Object)

ITreeContent-Provider

getChildren(Object)getParent(Object)inputChange(Object)

Do-main Data

Viewer

Up-date

MyModelListener

modelChanged()Ex-tend

Ex-tend

Page 13: Swt J Face 2/3

Viewer 최적화

SWT.VIRTUAL 보이는 부분만 viewer 에 보이도록

StructuredViewer.setUseHashlookup(boolean) Hash 알고리즘으로 탐색 속도 향상

Viewer 의 DAO 에 hashCode(), equals() 를 구현합니다 .

See(EMF Databinding) http://tomsondev.bestsolution.at/2011/10/07/jface-viewer-and-

eclipse-databinding-with-10-000-objects/

Page 14: Swt J Face 2/3

Viewer 최적화

Lazy Content Provider 데이터를 보여지는 부분 처리

tableViewer.setItemCount(sourceData.size()); 뷰어의 스크롤 크기 지정

Page 15: Swt J Face 2/3

Image, Font, Color Registry 소개

JFaceResources

ImageRegistry

FontRegistry

ColorRegistry

- 자주 사용하고 여러곳에서 공유되는 것들 위주로 사용-시스템 마다 이미지를 핸들링 할수 있는 한 개가 있으므로 주의 필요

- JFace 에 대한 상수정의

Page 16: Swt J Face 2/3

Image

Page 17: Swt J Face 2/3

Action 과 Contribution 소개

View 와 Control 분리 운영체제

Event Queue

ApplicationWindow

Con-tiribu-tion

Run

메시지

Action

호출

Dis-play

public class StatusAction extends Action {

public StatusAction() { super("&Trigger@Ctrl+T", AS_PUSH_BUTTON); setToolTipText("Trigger the Action"); setImageDescriptor( ImageDescriptor.createFromFile( this.getClass(), "property.png")); }

public void run() { System.out.println("The status action has fired."); }}

Page 18: Swt J Face 2/3

Dialog 소개ErrorDialogMessageDialogInputDialogProgressMonitorDialog

ProgressBar bar = new ProgressBar(shell, SWT.S-MOOTH);bar.setBounds(10, 10, 200, 32);shell.open();for (int i = 0; i <= bar.getMaximum(); i++) {try {Thread.sleep(5);} catch (Throwable th) {}bar.setSelection(i);}

Page 19: Swt J Face 2/3

Wizard 소개// wizard page 페이지 시작TestWizard wizard = new TestWizard();WizardDialog dialog = new WizardDialog(getShell(), wizard);

// wizard 정의class TestWizard extends Wizard {// page 정의public void addPages() { addPage(new Wizard1-Page()); addPage(new Wizard2-Page());}

// 종료시 해야할 일 정의public boolean performFin-ish() {..}}

Page 20: Swt J Face 2/3

Preference 소개

Page 21: Swt J Face 2/3

실습

예제데이터 (cvs) 이름 , 나이 , 전화번호 , 주소톰 ,47,010-1234-1235,미국헐리우드제리 ,48,010-1234-1234, 한국놀부 ,500,02-1234-1231, 한국흥부 ,498,02-2345-3456, 한국

초기화면이 로드되면 아래의 예제 데이터가 로드 된다 .

이름에 값을 입력하고 검색 버튼을 누르면 이름으로 테이블에 있는 데이터를 검색하고 데이터가 있다면 선택한다

아래 선택 버튼을 클릭하면 선택팝업이 뜨면서 상세정보출력한다

Page 22: Swt J Face 2/3

참고자료

www.eclipse.org/swt http://help.eclipse.org/help32/index.jsp?topic=/org.eclip

se.emf.doc/references/overview/EMF.Edit.html http://www.ibm.com/developerworks/library/os-ecgui1/