posted by 희정냥★ 2008. 11. 17. 17:52

런타임 상태에서의 현재 이클립스 플러그인의 위치 절대 경로를 알 수 있다.


  URL installLocation = Activator.getDefault().getBundle().getEntry("/");
  URL local = null;
  try {
   local = FileLocator.toFileURL(installLocation);
  } catch (IOException e) {
   e.printStackTrace();
  }
  String resourceRoot = new File(local.getPath()).getAbsolutePath(); 


댓글을 달아 주세요

posted by 희정냥★ 2008. 11. 14. 11:14

 

File cutewebiDirectory = new File("cutewebi"); // cutewebi가 폴더명

if(!cutewebiDirectory.exists()){ 

    cutewebiDirectory.mkdirs();
    System.out.println("cutewebi 디렉토리를 생성했습니다.");

}else{

    // cutewebi 폴더가 존재하면 폴더 내 기존 파일 다 삭제
    File[] cutewebiFiles = cutewebiDirectory.listFiles();

    for (File file : cutewebiFiles) {
     file.delete();

    }

    System.out.println("cutewebi 폴더내의 기존 파일을 모두 삭제하였습니다.");
    
}

댓글을 달아 주세요

  1. BlogIcon 자수씨 2008.11.15 02:00 신고  Addr  Edit/Del  Reply

    commons-io 에 FileUtils 도 함 보삼~

  2. BlogIcon 문성학 2009.11.01 20:04  Addr  Edit/Del  Reply

    퍼갑니다~

posted by 희정냥★ 2008. 11. 14. 10:09

Plug-in Project에서는
MessageDialog.openInformation(shell, "Error", "에러 ㅡ_ㅡ");
이렇게 했을때 MessageDialog가 잘 됐는데

Java Project로 바꾸고 나니 이 부분에서 에러가 나더구요..

아래 소스처럼 하면 됩니다~
(관련 jar 파일을 추가하세요.)

결과 :






import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

public class MsgBox {
	public MsgBox() {

	}

	public static void confirmMessageBox(Shell parentShell, String title,
			String message) {
		MessageBox box = new MessageBox(parentShell, SWT.OK | SWT.ICON_ERROR);
		box.setText(title);
		box.setMessage(message);
		int result = box.open();

	}

	public static boolean questionMessageBox(Shell parentShell, String title,
			String message) {
		MessageBox box = new MessageBox(parentShell, SWT.YES | SWT.NO
				| SWT.ICON_QUESTION);
		box.setText(title);
		box.setMessage(message);
		int result = box.open();
		return (result == SWT.YES);
	}
	
	public static void main(String args[]){
		Display display = new Display();
		Shell shell = new Shell(display);
		
		confirmMessageBox(shell, "확인","중복입니다.");
		questionMessageBox(shell, "저장","저장하시겠습니까?");
	}

}


댓글을 달아 주세요

posted by 희정냥★ 2008. 11. 14. 10:00


이렇게 생긴거입니다 ㅋ

SWT 관련 jar를 추가시켜줘야 합니다.

- Java Project


import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**
 * This class demonstrates how to create your own dialog classes. It allows
 * users to input a String
 */
public class InputDialog extends Dialog {

	// dialog 결과값
	boolean result = false;

	private String fileName = "";
	private String title = "";
	private String description = "";

	private Text fileNameText;
	private Text titleText;
	private Text descriptionText;

	
	Shell shell;
	// /////////////////////////////////////////////////////

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	// /////////////////////////////////////////////////////

	public InputDialog(Shell parent) {
		this(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
	}

	public InputDialog(Shell parent, int style) {
		super(parent, style);
	}

	public boolean open() {
		shell = new Shell(getParent(), getStyle());
		shell.setText(getText());
		createContents(shell);
		shell.pack();
		shell.open();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	private void createContents(final Shell shell) {

		shell.setText("Input Box");
		shell.setLayout(new GridLayout(2, true));

		// //////////////////////////////
		// fileName
		Label fileNameLabel = new Label(shell, SWT.NONE);
		fileNameLabel.setText("File Name");
		fileNameLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		fileNameText = new Text(shell, SWT.BORDER);
		fileNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		((GridData) fileNameText.getLayoutData()).widthHint = 100;

		// //////////////////////////////
		// title
		Label titleLabel = new Label(shell, SWT.NONE);
		titleLabel.setText("Title");
		titleLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		titleText = new Text(shell, SWT.BORDER);
		titleText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		// ////////////////////////////
		// Description
		Label descriptionLabel = new Label(shell, SWT.NONE);
		descriptionLabel.setText("Description");
		descriptionLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		descriptionText = new Text(shell, SWT.BORDER);
		descriptionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		// //////////////////////////////

		Button ok = new Button(shell, SWT.PUSH);
		ok.setText("OK");
		ok.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		ok.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent event) {
				result = true;
				fileName = fileNameText.getText();
				title = titleText.getText();
				description = descriptionText.getText();
				shell.close();
			}
		});

		Button cancel = new Button(shell, SWT.PUSH);
		cancel.setText("Cancel");
		cancel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		cancel.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent event) {
				result = false;

				shell.close();
			}
		});

		shell.setDefaultButton(ok);

	}

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);

		InputDialog dlg = new InputDialog(shell);

		if (dlg.open()) {
			System.out.println("ok");
			System.out.println(dlg.getFileName());
			System.out.println(dlg.getTitle());
			System.out.println(dlg.getDescription());

		} else {
			System.out.println("cancel");
		}
	}

}

댓글을 달아 주세요

  1. cremazer 2010.05.11 13:20  Addr  Edit/Del  Reply

    좋은정보 감사합니다 ^^ 다이얼로그 2개를 연동하여 메시징 처리를 하고 있었는데 데이터 호출하는 부분에서 막혔었는데, 올려주신 소스 보고 힌트를 얻어서 해결했습니다ㅋ