Eclipse RCP Tutorial 12

작성일: 2010. 10. 27.

원문: http://www.vogella.de/articles/EclipseRCP/article.html Version 5.1

퍼스펙티브

퍼스펙티브는 특정 작업과 관련된 UI 요소들을 함께 묶고 조직화한다. 이클립스 RCP 는 어플리케이션에 퍼스펙티브를 추가할 수 있도록 한다. 다음 예제를 보자.

어플리케이션에 퍼스펙티브 추가하기

de.vogella.rcp.intro.perspective 라는 이름으로 RCP 프로젝트를 생성한다. 템플릿은 RCP application with a view 를 사용한다. plugin.xmlorg.eclipse.ui.perspective 확장점을 추가한다. 퍼스펙티브의 id 에 de.vogella.rcp.intro.perspective.perspective 를, 이름에 vogella.de Perspective 를 적는다. 클래스 이름은 de.vogella.rcp.intro.perspective.Perspective 로 변경한다.

class* 링크를 눌러 클래스를 생성한다.

새 클래스의 createInitialLayout() 메소드는 새로운 퍼스펙티브를 생성을 책임진다. 기존의 뷰의 코드를 재사용한다. 다음 단계에서 퍼스펙티브는 정의되지만 어플리케이션에서 사용할 수 없다.

1
2
3
4
5
6
7
8
9
10
11
12
13
package de.vogella.rcp.intro.perspective;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;
public class Perspective implements IPerspectiveFactory {
public void createInitialLayout(IPageLayout layout) {
String editorArea = layout.getEditorArea();
layout.setEditorAreaVisible(false);
layout.setFixed(true);
layout.addStandaloneView(View.ID, false, IPageLayout.LEFT, 1.0f, editorArea);
}
}

퍼스펙티브 선택하기

툴바/쿨바를 통해 퍼스펙티브 선택하기

ApplicationWorkbenchWindowAdvisor 클래스의 preWindowOpen() 메소드 내에 configurer.setShowPerspectiveBar(true); 를 통해 퍼스펙티브간의 변경을 활성화 할 수 있다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package perspectivetest;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IWorkbenchPreferenceConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
public ApplicationWorkbenchWindowAdvisor(
IWorkbenchWindowConfigurer configurer) {
super(configurer);
}
public ActionBarAdvisor createActionBarAdvisor(
IActionBarConfigurer configurer) {
return new ApplicationActionBarAdvisor(configurer);
}
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(400, 300));
configurer.setShowCoolBar(false);
configurer.setShowStatusLine(false);
configurer.setTitle("RCP Application");
configurer.setShowPerspectiveBar(true);
// Set the preference toolbar to the left place
// If other menus exists then this will be on the left of them
IPreferenceStore apiStore = PlatformUI.getPreferenceStore();
apiStore.setValue(IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR, "TOP_LEFT");
}
}

이제 퍼스펙티브를 즉각적으로 변경할 수 있다.

메뉴를 통해 퍼스펙티브 선택하기

이클립스 퍼스펙티브를 바꾸는 것은 메뉴의 표준 명령인 org.eclipse.ui.perspectives.showPerspective 를 통해 재사용할 수 있다. 이클립스 커맨드 을 참고하라.

Share Comments