开发者

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

开发者 https://www.devze.com 2023-03-15 03:56 出处:网络
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 execut

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

精彩评论

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