Eclipse RCP Tutorial 9

작성일: 2010. 10. 27.

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

필드 어시스트와 레이블 데코레이터

필드 어시스트는 텍스트 필드나 콤보 박스와 같이 단순 필드의 가능한 입력과 상태에 대한 정보를 제공하는데 사용될 수 있다. org.eclipse.jface.fieldassist 패키지는 ControlDecorations 와 Content Proposals 두 가지 방법으로 도움을 제공한다.

콘트롤 장식은 콘트롤에 대한 부가적인 정보를 보여주기 위해 SWT 컨트롤에 이미지 장식을 두도록 한다. 이 장식은 사용자가 마우스를 올려 놓았을때 한번 보여지는 내용을 가지고 있을 수 있다. 화면 배치 중에 이 장식들을 보여주기 위한 충반한 공간이 있다고 확신해야 한다.

컨텐트 제안은 필드에 사용자 입력에 대해 가능한 선택을 도와주도록 한다.

de.vogella.rcp.intro.fieldassist 로 새 프로젝트를 생성한다. 예제로 RCP application with a view 를 사용한다. 예제에서 컨텐트 제안은 Cntrl+Space 키 조합으로 특정 키(., #)를 통해 활성화된다.

다음으로 View.java를 바꾼다.

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package de.vogella.rcp.intro.fieldassist;
import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.jface.bindings.keys.ParseException;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
import org.eclipse.jface.fieldassist.TextContentAdapter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
public class View extends ViewPart {
public static final String ID = "de.vogella.rcp.intro.fieldassist.view";
public void createPartControl(Composite parent) {
GridLayout layout = new GridLayout(2,false);
parent.setLayout(layout);
Label label = new Label(parent, SWT.NONE);
label.setText("Please select a value: ");
Text text = new Text(parent, SWT.BORDER);
createDeco(text, "Use CNTL + SPACE to see possible values");
GridData data = new GridData(GridData.FILL_HORIZONTAL);
text.setLayoutData(data);
ControlDecoration deco = new ControlDecoration(text, SWT.LEFT);
deco.setDescriptionText("Use CNTL + SPACE to see possible values");
deco.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
deco.setShowOnlyOnFocus(false);
// Help the user with the possible inputs
// "." and "#" will also activate the content proposals
char[] autoActivationCharacters = new char[] { '.', '#' };
KeyStroke keyStroke;
try {
//
keyStroke = KeyStroke.getInstance("Ctrl+Space");
// assume that myTextControl has already been created in some way
ContentProposalAdapter adapter = new ContentProposalAdapter(text,
new TextContentAdapter(),
new SimpleContentProposalProvider(new String[] {
"ProposalOne", "ProposalTwo", "ProposalThree" }),
keyStroke, autoActivationCharacters);
} catch (ParseException e) {
e.printStackTrace();
}
}
public void setFocus() {
}
private void createDeco(Text text, String s){
}
}

애플리케이션을 실행하고 콘트롤 장식과 컨텐트 제안이 작동하는지 확인한다.

Share Comments