相対パス
FileDialog クラスを使っていろんなパターンでファイルを選択してみたのですが、どうやらディレクトリには .. とか . は含まれないようです。
だったら、相対パスを取得するのは文字列の問題に帰着できます。
もう少しうまくかけるかもしれませんが、こんな感じに書いてみました。
private String handleBrowseButtonSelected(String[] names, String[] exts) { FileDialog dialog= new FileDialog(getShell(), SWT.MULTI); String currentPath = project.getProject().getLocation().toOSString(); dialog.setFilterPath(currentPath); dialog.setFilterExtensions(exts); dialog.setFilterNames(names); if (dialog.open() != null) { String relativeDir = dialog.getFilterPath(); int index = relativeDir.indexOf(currentPath); if (index == 0) { relativeDir = relativeDir.substring(currentPath.length()+1); return relativeDir + "/" + dialog.getFileName(); } else { MessageDialog.openWarning( getShell(), "LG3D WRPE Plug-in", "You must select a file in project work directory."); } } return ""; }
ワーキングディレクトリより上の階層のディレクトリで選択すると、ダイアログで警告を出しますが、こんな英語で通じるのだろうか? いや、通じないだろうな。