기은P
시간이 멈추는 장소
기은P
  • Programming (272)
    • 개발노트 (1)
    • FrontEnd (56)
      • ES&JS 문법 (14)
      • HTML&CSS (4)
      • React 기본 (18)
      • React 심화 (12)
      • React 이슈 (2)
      • Project 연습 (1)
      • Next.js (5)
    • Backend&Devops (33)
      • AWS (2)
      • Docker (9)
      • Jenkins (6)
      • Nginx (6)
      • Node.js (1)
      • ElasticSearch (5)
      • 프레임워크&아키텍처 (2)
      • 암호화 (0)
      • 기타 (2)
    • 알고리즘 (3)
    • C# (8)
      • WPF (8)
    • Java (51)
      • 순수 Java (18)
      • RDF&Jena (12)
      • RCP&GEF (9)
      • JMX (5)
      • JMapper (3)
      • 오류해결 (4)
    • Database (21)
      • RDBMS (9)
      • NoSQL (2)
      • TSDB (1)
      • GraphQL (1)
      • Hibernate (3)
      • 데이터베이스 이론 (4)
      • Redis (1)
    • 프로토콜 (11)
      • Netty (4)
      • gRPC (5)
      • 프로토콜 개념 (2)
    • Server (4)
      • Linux (4)
    • 2020 정보처리기사 필기 (43)
      • 목차 (1)
      • 기출문제 (1)
      • 1과목 - 소프트웨어 설계 (6)
      • 2과목 - 소프트웨어 개발 (7)
      • 3과목 - 데이터베이스 구축 (8)
      • 4과목 - 프로그래밍 언어 활용 (7)
      • 5과목 - 정보시스템 구축 관리 (10)
    • 2020 정보처리기사 실기 (31)
      • 목차 (4)
      • 기출예상문제 (19)
      • 실기요약 (8)
    • 빅데이터분석기사 필기 (4)
      • 목차 (0)
      • 필기 요약 (3)
    • 전기 공학 (1)
      • CIM (1)
    • 산업자동화시스템 (3)
      • SCADA (1)
      • OPC UA (2)
    • 디자인패턴 (1)
    • 휴지통 (0)

공지사항

  • 공지사항/포스팅 예정 항목

최근 댓글

최근 글

전체 방문자
오늘
어제

티스토리

hELLO · Designed By 정상우.
기은P

시간이 멈추는 장소

Eclipse RCP - plugin.xml에서 View의 데이터 다른 View로 옮기기
Java/RCP&GEF

Eclipse RCP - plugin.xml에서 View의 데이터 다른 View로 옮기기

2020. 4. 1. 16:10
반응형

Eclipse RCP - plugin.xml에서 View의 데이터 다른 View로 옮기기

 

 

먼저 https://narup.tistory.com/40의 Sample View를 기준으로 데이터를 옮기는 방법에 대해 설명한다.

 

 

1)     먼저 SampleView에서 Add 버튼을 하나 생성한다.

 

Button 생성하는 방법은 간단하기 때문에 생략한다.

Window Builder를 통해 생성하면 쉽게 만들 수 있다.

 

 

2)     SampleView의 ID와 PW데이터를 받은 새로운 View를 생성한다. Plugin.xml에서 GetSampleView를 생성해준다.

 

 

3)     GetSampleView의 구성은 SWT의 Table로 구성했다.

 

public class GetSampleView extends ViewPart {
	private Table table;
	public GetSampleView() {
		// TODO Auto-generated constructor stub
	}
	@Override
	public void createPartControl(Composite parent) {
		parent.setLayout(new GridLayout(1, false));
		
		table = new Table(parent, SWT.BORDER | SWT.FULL_SELECTION);
		table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		
		TableColumn tblclmnNewColumn = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn.setWidth(100);
		tblclmnNewColumn.setText("ID");
		
		TableColumn tblclmnNewColumn_1 = new TableColumn(table, SWT.NONE);
		tblclmnNewColumn_1.setWidth(100);
		tblclmnNewColumn_1.setText("PW");
		// TODO Auto-generated method stub
	}
	
	public void AddData(String id, String pw) {
	    TableItem item = new TableItem(table, SWT.NONE);
	    item.setText(new String[]{id,pw});
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub
	}
}

 

  AddData() 메소드를 통해서 table에 tableItem을 추가하는 코드다.

 

 

4)     다시 SampleView로 돌아가서 window builder 편집기로 소스코드를 열고 디자인 탭 클릭 - Button을 오른쪽 버튼 클릭 – Add event handler – selection – widgetSelected를 선택한다.

 

 

 

윈도우 빌더에서 이벤트 핸들러를 생성하면 아래와 같은 코드가 추가된다.

 

Button btnNewButton = new Button(parent, SWT.NONE);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
			}
		});
		btnNewButton.setText("Add");

 

버튼에 리스너를 등록하고, SelectionAdapter의 wigdetSeleted를 오버라이드해서 이벤트를 발생시키는 흐름이다.

 

 

5)     이제 widgetSeleted함수를 조금 수정한다.

 

		Button btnNewButton = new Button(parent, SWT.NONE);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				GetSampleView view = (GetSampleView) Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage()
						.findView(GetSampleView.ID);
				if (view != null) {
					view.AddData(id.getText(), pw.getText());
				}
			}
		});
		btnNewButton.setText("Add");

 

 

* GetSampleView의 view를 가져오기 위해

 Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(GetSampleView.ID);로 가져온다는 것. 가장 중요하다!!

 

 

 

6)       perspeectiveExtensions에  view를 등록해주고 실행하면 된다.

 

 

 

7)      실행 결과

 

 

 

 

  • 이처럼 RCP도 복잡하게 생각 할 것 없이 JFace 혹은 SWT의 컴포넌트를 이용해 View에 구성하고 데이터를 전달하는 흐름을 알고 있으면 데이터를 Read하고 Write하는 부분에는 큰 어려움 없이 코드를 작성할 수 있을 것이다.

 

반응형
저작자표시 변경금지 (새창열림)

'Java > RCP&GEF' 카테고리의 다른 글

[GEF] Eclipse GEF 3.11 다운로드 방법  (0) 2020.04.02
Eclipse GEF - Editor를 화면에 띄우는 방법  (0) 2020.04.02
Eclipse RCP - plugin.xml을 사용한 view 생성  (2) 2020.04.01
Eclipse RCP - plugin.xml을 사용한 Command Handler 생성  (0) 2020.04.01
[RAP] Missing Constraint: Bundle-RequiredExecutionEnvironment: JavaSE-1.8 오류 해결  (0) 2020.03.13
    'Java/RCP&GEF' 카테고리의 다른 글
    • [GEF] Eclipse GEF 3.11 다운로드 방법
    • Eclipse GEF - Editor를 화면에 띄우는 방법
    • Eclipse RCP - plugin.xml을 사용한 view 생성
    • Eclipse RCP - plugin.xml을 사용한 Command Handler 생성
    기은P
    기은P
    기은P의 블로그 일상과 개발 관련 포스팅 #React #Typescript #Next #Nest https://github.com/kimdongjang

    티스토리툴바