开发者

Eclipse Plugin Development : How to change file attributes of selected files?

I am trying to create an eclipse plugin to change 开发者_如何学编程the selected files to read only. Created popup menu sample plugin project which when executed shows a message "New Action was executed"

I am stuck at next step.

How to get list of files selected, and change file attributes ?


I don't have the time to test the following properly, but it is probably a good starting point:

public class SetFileToROHandler extends AbstractHandler implements IHandler {
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection s = HandlerUtil.getCurrentSelectionChecked(event);
    if (!(s instanceof IStructuredSelection))
      return null;
    final IStructuredSelection ss = (IStructuredSelection) s;
    for (final Object o : ss.toArray()) {
      if (!(o instanceof IFile)) {
        continue;
      }
      IFile f = (IFile) o;
      f.setReadOnly(true);
    }
    return null;
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜