Search code examples
javanetbeansnetbeans-8netbeans-platform

Netbeans file based Project, not Folder based


I'm trying to implement a new type of project based on this tutorial. The problem is that I want that my project be saved as a single file, with a custom extension, so all the content must reside on that file. Like project_name.cep (cep - custom extension project). I don't want to open a new type of file inside project, that file is my project, and I want to write nodes inside it.

This is an example of the ProjectFactory to use:

@ServiceProvider(service=ProjectFactory.class)
public class CustomProjectFactory implements ProjectFactory{

    public static final String PROJECT_EXT = "cep";

    //Specifies when a project is a project, i.e.,
    @Override
    public boolean isProject(FileObject projectDirectory) {
        return PROJECT_EXT.equals(projectDirectory.getExt()); //assuming that getExt() give the file extension 
    }

    //Specifies when the project will be opened, i.e., if the project exists:
    @Override
    public Project loadProject(FileObject dir, ProjectState state) throws IOException {
        return isProject(dir) ? new CustomProject(dir, state) : null;
    }

    @Override
    public void saveProject(final Project project) throws IOException, ClassCastException {
        // leave unimplemented for the moment
    }

}

The problem is that the FileChooser opened when I tried to open the project seems to be a DIRECTORIES_ONLY chooser, so a single file can't be opened.

Can be done? I really appreciate some example of how to do this and if is not to much to ask how to write nodes inside this single file and represent it in the explorer (just some advices).

The Open Project dialog is filtering folders only


Solution

  • Indeed NetBeans projects are identified on their directories.

    The only way I see is to create a custom version of the NetBeans project module which allows to select files.