플러그인 프로젝트 선택프로젝트 이름 및 플러그인실행대상 선택기본 자바 실행버전(좀 낮게), UI 제공, RCP응용프로그램 작성여부 YesRCP 기본 템플릿 선택(3.x로 시작)패키지 기본설정RCP 기본템플릿 실행(plugin.xml선택, 개요탭에 Eclipse응용프로그램 실행)
ㅁ 기본구조 확인
기본적으로 RCP프로젝트를 생성하면 아래와 같은 기본 클래스들이 생긴다. 이 클래스들은 RCP프로그램에서 각자의 역할이 있으며, 구성하고있는 역할을 알고 있어면 훗날 개발을 진행할 때 진행이 수월하다.
Application
RCP프로그램의 main routine으로 동작 및 프로그램의 컨트롤러 역할을 한다. 또한 Workbench와 다른 Workbench Advisor라고 불리는 다른 클래스들을 연결시키는 역할한다. 이때 Workbench는 프로그램 하나를 말한다. Workbench는 Worbench Window을 포괄하는 개념이며, 예를 들어 새로운 이클립스창이 띄워졌을때 New window를 하면 하나의 창이 더 띄워진다. 이때 각각의 창은 Workbench Window이고, 2개가 존재한다. 하지만 Workbench는 창이 늘어나도 하나로 존재하게된다.
WorkbenchAdvisor
Workbench의 lifecycle에 대해 명시하고 있다. default perspective와 같은 중요한 파라미터들을 Workbench에 제공한다. 가장 중요한 점은 WorkbenchAdvisor의 메소드들은 오버라이드가 될 수 없다.
WorbenchWindowAdvisor
상태 line, 툴바. 제목. 윈도우 사이즈 등 커스터마이즈 하길 원하는 것들이 들어간다.
Perspective
view, editor, menu들의 위치와 사이즈를 갖고있음 적어도 하나의 perspective는 가지고 있어야 한다.
View
화면을 담당하는 부분이다. 곧, 뷰어들을 생성하고 초기화를 진행한다. 화면을 Viewer의 컨트롤에 요청하는 setFocus()와 모든 구성 요소들을 활성화하는 CreatePartControl(Composite) 함수가 반드시 필요하다. 이 두 함수는 처음 실행될때 호출된다. setFocus() createPartControl(Composite)는 시키기 위해 선언하는 곳이다
10가지의 플러그인 중 큰 몇가지만 설명하고자 한다.
UI Workbench: UI Workbench는 editor, view, perspective 등을 포함하고 있다.
SWT: 운영체제의 네이티브 윈도우 환경과 긴밀하게 통합된 다양한 컴포넌트와 플랫폼 독립적인 API를 제공한다. 즉, 윈도우에서 정의한 위젯에 대한 접근을 제공한다.
JFACE: 범용 UI 개념을 위한 구조와 편의기능을 제공한다. SWT를 이용하여 사용자 인터페이스를 개발할 때 해야하는 많은 공통 작업들을 간단하게 해 주는 컴포넌트와 헬퍼 유틸리티 세트를 제공 데이터 뷰, 위저드, 다이얼로그 컴포넌트 등을 제공하기 위해 SWT를 확장하는 많은 유틸리티 클래스들을 포함하고 있다.
RUNTIME: 플러그인과 페이지 로딩 및 초기화 간에 확장 포인트 모델 기반의 느슨한 결합을 정의하고 있다.
OSGi: 이클립스에서 플러그인의 발견 및 애플리케이션의 재시작 없이 플러그인을 로딩 및 언로딩하는 것을 포함하여 플러그인의 라이프사이클 관리등을 위한 프레임워크이다.
드레그 와 드롭은 일상에서 많이 사용하고 있다. 근데 개발툴에서는 많이 사용하지 않았지만 앞으로 개발툴도 이러한 기능으로 소스코딩양을 줄여주는것이 좋을것 같다.
이기능은 사용하려면 드래그 하는 곳과 드롭하는 곳에 상호작용 및 순서가 필요하다.
드래그소스->드롭타깃->드롭효과->트랜스
먼저 드레그 클래스 계층도를 살펴보자
ㅁ 드레그 소스
드레그 소스에는 여러가지 형태가 있을수 있다
가령 text, file, 워드와 같이 특정 문자에 색이나 강조등의 효과를 가지고 있는 RTP 형식 문서등이 있다.
여기서는 해당소스가 명칭을TextTransfer, FileTransfer,HTML Transfer,RTF Transfer 라 하고 각각
instance를 생성 전달하게 된다.
여기서 간단한 예제로 Label에 소스를 드레그해서 이클립스 java editer에 드롭하면 move되는 소스를 참고 하여보자
package swt.drag_drop;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class DragSourceTest {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setText("SWT DragSource Test");
// 레이블 위젯을 드래그 원본(Drag Source)으로 활성화 한다.
final Label label = new Label(shell, SWT.BORDER);
label.setText("text to be transferred");
int operations = DND.DROP_MOVE | DND.DROP_COPY;
DragSource source = new DragSource(label, operations);
// 텍스트 포맷 내에 데이터를 제공한다.
Transfer[] types = new Transfer[]{TextTransfer.getInstance()};
source.setTransfer(types);
source.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
// 레이블 내에 실제 텍스트가 있을 경우에만, 드래그를 시작한다.
if (label.getText().length() == 0) {
event.doit = false;
}
}
public void dragSetData(DragSourceEvent event) {
// 요청된 타입의 데이터를 제공한다.
if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
event.data = label.getText();
}
}
public void dragFinished(DragSourceEvent event) {
// 만약, 데이터의 이동(MOVE) 작업이 수행되었다면,
// 드래그 원본인 레이블 위젯에서 이동한 데이터를 제거한다.
if (event.detail == DND.DROP_MOVE) {
label.setText("");
}
}
});
shell.setSize(640, 480);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
구현시 처리되는동영상을 참고하세요
Drag 처리
ㅁ 드롭 타겟
다음은 드롭소스를 예제로 생성해 보았다 반대로 드레그는 이클립스에 자바소스에서 드롭은 개발된 소스에서 받는걸로 예제를 처리했다.
package swt.drag_drop;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.dnd.TransferData;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class DropTargetCopyTextFileTest {
private static void open(Text text, String filename) {
File file = new File(filename);
try {
text.setText("");
FileReader reader = new FileReader(file);
BufferedReader in = new BufferedReader(reader);
String str = null;
while ((str = in.readLine()) != null) {
text.append(str + "\n");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setText("SWT DropTarget Test");
final Text text = new Text(shell, SWT.BORDER | SWT.MULTI);
int operations = DND.DROP_DEFAULT | DND.DROP_COPY | DND.DROP_MOVE;
DropTarget target = new DropTarget(text, operations);
target.setTransfer(new Transfer[]{FileTransfer.getInstance(),
TextTransfer.getInstance()});
target.addDropListener(new DropTargetAdapter() {
FileTransfer fileTransfer = FileTransfer.getInstance();
TextTransfer textTransfer = TextTransfer.getInstance();
public void dragEnter(DropTargetEvent e) {
System.out.println("[dragEnter] e : " + e);
TransferData data[] = e.dataTypes;
for (int i = 0; i < data.length; i++) {
System.out.println("[dragEnter] data[" + i + "] : "
+ data[i]);
}
if (e.detail == DND.DROP_DEFAULT) {
e.detail = DND.DROP_COPY;
}
}
public void dragOperationChanged(DropTargetEvent e) {
if (e.detail == DND.DROP_DEFAULT) {
e.detail = DND.DROP_COPY;
}
}
public void drop(DropTargetEvent e) {
System.out.println("[drop] e : " + e);
if (fileTransfer.isSupportedType(e.currentDataType)) {
String[] files = (String[]) e.data;
if (files != null && files.length > 0) {
open(text, files[0]); // 파일을 연다
}
}
if (textTransfer.isSupportedType(e.currentDataType)) {
String str = (String) e.data;
if (str != null) {
text.setText(str); // 텍스트를 커서 위치에 삽입
}
}
}
});
// shell.setLocation(display.getBounds().width - 320,
// display.getBounds().height - 240);
shell.setSize(320, 240);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
여기도 동영상을 보면 어떻게 구현했는지를 알수 있다.
Drop
ㅁ 사용자 포멧 드레그 엔 드롭
개발하다보면 사용자 포멧에 데이터를 드레그 엔 드롭을 하고 싶을때가 있다
▶ MySimpleDragAndDrop에서 화면구성 및Drag소스를MyType으로Table에TableItem 객체로 구성