I am writing a eclipse plugin. I am in the need of restricting a file with a specific extension (not creating more than one) in a project. Through a wizard i am creating a file with extension "file.extension". I have restricted in the wizard level as the user is not allowed to create more than one file with extension ".extension". I also need to restrict an user not allowing him to copy or drag the files into some other project of same type. Because, that project must have only one file with a specific extension (".extension"). Please help me through this.
Asked
Active
Viewed 92 times
1 Answers
1
Don't do it that way. A user can always just shutdown Eclipse, create another file in the project and restart Eclipse. You simply cannot avoid that.
Instead, create a custom builder for your project nature which verifies that there is only one file. And in case of more than 1 file have the project builder raise an error in the problems view, so the user can fix it.

Bananeweizen
- 21,797
- 8
- 68
- 88
-
Can you please elaborate ? Coz I am new to plugin development. Can you provide any reference or source ? – Logan Oct 22 '12 at 09:04
-
1[Simple builder tutorial](http://wiki.eclipse.org/FAQ_How_do_I_implement_an_incremental_project_builder%3F). Eclipse will basically call you whenever a file on disk changes (see the System.out calls in the tutorial). You can then check if there are more than 1 of your files in the project belonging to the change and raise an error on the second, third, ... file. – Bananeweizen Oct 22 '12 at 11:14
-
Ok now, when ever i start my eclipse i want my custom builder to run. How to accomplish that ? As it is not happening in the current case. – Logan Oct 25 '12 at 14:01
-
You don't need to. Eclipse recognizes if the workspace was touched in between. If so, it will rebuild (and thereby call your builder again). If not, the status of your last check is still valid. And as you created a resource marker with an error in case of problems, that error marker also still exists. – Bananeweizen Oct 25 '12 at 14:12