기본 콘텐츠로 건너뛰기
검색
이 블로그 검색
불친절한자수씨
자수씨의 보물창고
페이지
홈
더보기…
공유
공유 링크 만들기
Facebook
X
Pinterest
이메일
기타 앱
태그
Eclipse
10월 12, 2010
RCP에서 Dialog 사용법
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.ColorDialog;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.FontDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
public class OpenDialog extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
// File standard dialog
FileDialog fileDialog = new FileDialog(shell);
// Set the text
fileDialog.setText("Select File");
// Set filter on .txt files
fileDialog.setFilterExtensions(new String[] { "*.txt" });
// Put in a readable name for the filter
fileDialog.setFilterNames(new String[] { "Textfiles(*.txt)" });
// Open Dialog and save result of selection
String selected = fileDialog.open();
System.out.println(selected);
// Directly standard selection
DirectoryDialog dirDialog = new DirectoryDialog(shell);
dirDialog.setText("Select your home directory");
String selectedDir = dirDialog.open();
System.out.println(selectedDir);
// Select Font
FontDialog fontDialog = new FontDialog(shell);
fontDialog.setText("Select your favorite font");
FontData selectedFont = fontDialog.open();
System.out.println(selectedFont);
// Select Color
ColorDialog colorDialog = new ColorDialog(shell);
colorDialog.setText("Select your favorite color");
RGB selectedColor = colorDialog.open();
System.out.println(selectedColor);
// Now a few messages
MessageDialog.openConfirm(shell, "Confirm", "Please confirm");
MessageDialog.openError(shell, "Error", "Error occured");
MessageDialog.openInformation(shell, "Info", "Info for you");
MessageDialog.openQuestion(shell, "Question", "Really, really?");
MessageDialog.openWarning(shell, "Warning", "I warn you");
return null;
}
}
단, AbstractHandler 에서 사용하는 경우가 아니라면 Shell 객체는 아래와 같이 참조합니다.
Shell shell = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
참고자료
http://www.vogella.de/articles/EclipseDialogs/article.html
댓글
가장 많이 본 글
1월 17, 2013
[for신규가입자] 카페 가입시 30%할인쿠폰 전원 지급!
댓글
댓글 쓰기