This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 64393 - need notification when a project file has been created
Summary: need notification when a project file has been created
Status: RESOLVED WONTFIX
Alias: None
Product: projects
Classification: Unclassified
Component: Generic Infrastructure (show other bugs)
Version: 4.x
Hardware: All All
: P4 blocker (vote)
Assignee: Tomas Stupka
URL:
Keywords: API
Depends on:
Blocks:
 
Reported: 2005-09-15 01:13 UTC by Thomas Preisler
Modified: 2016-07-07 08:39 UTC (History)
4 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Preisler 2005-09-15 01:13:49 UTC
I need a notification when a project file has been created. I need to process a
file after it has been created (File->New) but having trouble figuring out when
it happens. I need to know the full path to file and what project it was created
in. The post-creation process will add the newly created file to a logical
folder among other things.
Comment 2 Thomas Preisler 2005-09-15 17:40:23 UTC
It suspect this is too general. I need to know 1) that the file was created from
File -> New (that's how you create new project files), 2) the project name, 3)
the full path to file.

Adding a listener to the dataloader pool will give me an notification when any
new file file has been created. I also need the project.
Comment 3 Jesse Glick 2005-09-15 17:56:19 UTC
The project can easily be found using FileOwnerQuery.
Comment 4 Thomas Preisler 2005-09-15 18:42:37 UTC
Perhaps in a Java project, but not in general and that's why I need the
notification (or another way to map the file to a project). A file doesn't
belong to a project just because it gets created under a project or exist under
a project. I need to know that the file has been created from the File->New
dialog and not from any another process. The file goes into the project only if
the file has been created from the File -> New dialog. And you can still create
a file in let's say /tmp from File -> New and want it to belong to the project
you specify in the dialog. There is no way any project can claim ownership of
that file, right? How would you know what project you specified in the dialog.
Comment 5 Jesse Glick 2005-09-15 18:51:09 UTC
"A file doesn't belong to a project just because it gets created under a project
or exist under a project." - yes it does.

"I need to know that the file has been created from the File->New dialog and not
from any another process." - well that would require a new API. But I do not
think we would plan to implement such an API, since most files *are* created via
File -> New and there is little reason to believe that a realistic app would
want to behave specially when presented with a new project file created by some
other means (like what?). That is probably WONTFIX unless there is a compelling
use case given.

"And you can still create a file in let's say /tmp from File -> New and want it
to belong to the project you specify in the dialog. There is no way any project
can claim ownership of that file, right?" - wrong. The New File dialog only lets
you create files inside the selected project.
Comment 6 Thomas Preisler 2005-09-15 19:19:39 UTC
If I create a new file from File->New, I understand how I can get notified and
how I can find the project and add it to the correct logical folder in.

In our type of projects a file gets compiled only if it has been *added* to the
project, and not just because it exists under a project.

The part I don't understand is what if a file is being created under a project
by another process? Version control systems, for instance, creates additional
files and some version control systems creates even files with same suffixes as
original files. I will get notifications about these files too, right? And how
would I know which files to add to my project and which files not to add if I
only listen to data loader pool notifications?

And our IDE allows the user to create files under a project that a not part of
(should not be compiled) the project. How to handle these files if I only
listened to the data loader pool notifications?

This user model is very close to Visual Studio's model.

A notification from the File->New dialog would solve all these problems for me.
Comment 7 Jesse Glick 2005-09-15 19:26:14 UTC
I think your needs are sufficiently specialized (or more precisely, unlike the
user model used by the NetBeans IDE and its direct derivatives) that you should
just be using your own New File dialog and not try to use the one provided by
projectui - hence WONTFIX, but will leave to Honza for further evaluation.
Comment 8 Thomas Preisler 2005-09-15 19:51:03 UTC
Rewriting the File Dialog ?????

Wouldn't notifications be generally usable? And a very light-weight change too?
And would give me and others the chance to post-process files created from File
-> New.

I'm not suggesting to fix this is 5.0 but in a future release.
Comment 9 Jesse Glick 2005-09-15 20:12:20 UTC
The New File dialog is not all that complicated. Consists of a couple of
classes. (Some weird wizard code in there which I don't like much, but easy
enough to copy.) The panels after the first are all plugged in by modules.
Modifying the infrastructure (first panel + Finish handler) would enable you to
not only perform custom actions when making new files, like registering them
somewhere, but also customize other behaviors which might not be quite right for
your uses, such as the expansion and selection of newly created files.
Comment 10 Jan Lahoda 2005-09-15 20:31:10 UTC
I have a few questions/comments:
1. I suppose you want to hook into templates over which you do not have any
control (like Java module's templates). Otherwise you should probably modify the
templates themselves.
2. The FileOwnerQuery works even for files/folders that are not under the
project folder. Please see FileOwnerQuery.markExternalOwner for details. Some
features may be broken if the FileOwnerQuery does not provide correct results.
It can also cause hard to find bugs.
3. Not sure if such a change would be light-weight and easily maintainable.
Moreover, I am currently not aware about any usecase, except yours, so I do not
think it is "generally usable". I am a bit worried about abusing such an API. I
think that "post-processing templates" approach is quite dangerous, and should
be avoided if possible.

I agree with Jesse that creating a new New File dialog may be the most
appropriate approach in your case.
Comment 11 Jesse Glick 2005-09-15 20:50:56 UTC
Re. #1 - I doubt the original template code needs to be touched; a wizard should
return a set of files it has made (this is up to the wizard to implement
correctly), which the existing New File wizard infrastructure pays attention to
(in order to select them).

Re. #3 - I don't think Thomas is talking about post-processing templates as
such; just somehow adding newly created files to some kind of list.

One advantage of a custom New File wizard is that you could actually add a final
panel to every template which enumerates files that are about to be created and
lets you confirm (checkboxes) that you want to "add them to your project" (a
concept which does not exist in the NB IDE).
Comment 12 Thomas Preisler 2005-09-15 21:00:50 UTC
Re. #3 - I don't think Thomas is talking about post-processing templates as
such; just somehow adding newly created files to some kind of list.

Exactly. I want to move newly created files (from New-File only) into specific
logical folders.

If 'rewriting' the New File dialog is not that complicated, it may be the
solution for us. But I'm hesitent to duplicate code if it can be avoided and I
thought notifications would be generally useful.
Comment 13 Jesse Glick 2005-09-15 21:13:56 UTC
I can't think of any use case for New File notification in the NB IDE or its
direct derivatives. We do have code which uses OperationListener to check for
new files - for the code completion / refactoring database - but for this case
it is correct to get the same notification when a file is created by any means,
incl. a CVS update that gets new files from a team member. In NetBeans, a
project is one folder (possibly with one or two external folders added) and any
file beneath that is part of the project, regardless of how it got there. It
seems to me that the special-cased treatment of files added via the wizard would
only apply to IDEs which adopt a different concept of projects, where a project
is empty by default and its contents are enumerated, as in VS or JBuilder. Since
you have a pretty different model, I would not expect to be able to share every
bit of code or use all of the projects/projectui APIs; there may be some sharing
that makes sense but expect to implement some other things yourself where your
UI would naturally diverge.
Comment 14 Jan Lahoda 2005-09-15 21:32:03 UTC
Sorry I did not make myself clear:
1. IMO, if I would like to do something special when I instantiate my own
template, I should do it in the instatiate method. An API like this would be
necessary only to do something special for someone else's templates.
3. Yes, I understood this.

Anyway, I agree with Jesse that this is a different model that should be solved
differently.
Comment 15 Jan Lahoda 2006-01-09 10:11:18 UTC
After an offline discussion and thinking about it more, I think we should accept
this as a requirement.

Main reason is that reimplementing New File wizard is not a good option as
interoperability between projects described here and NB Java projects is desirable.

However, exact requirements needs to determined yet.
Comment 16 Antonin Nebuzelsky 2006-10-03 13:41:15 UTC
Reassigning to Milos.
Comment 17 Milos Kleint 2006-10-05 14:51:50 UTC
in offline discusson jlahoda claims that he wrote some code for c support that
uses OperationListener and works for the usecases described here. Can you confirm?
Comment 18 Thomas Preisler 2006-10-11 22:51:59 UTC
We are using Jan Lahoda's OperationListener hack (he actually wrote the code for
us), but it does only work for files created by wizards written in a certain
way. It does work for most of the files we are interested in but not for xml
file, for instance. 

My point is we cannot keep relying on hacks to get our modules to work. We need
good solid API's that will work in future releases. 
Comment 19 Jesse Glick 2006-10-12 00:33:23 UTC
Can you be more specific about which wizards cause OperationListener to not be
invoked? IMHO that would be a bug in the wizard. OperationListener is the
recommended and supported way to be notified when a file is created in general.
Comment 20 Jesse Glick 2006-10-12 00:33:40 UTC
Still missing details.
Comment 21 Thomas Preisler 2006-10-12 01:26:53 UTC
I see. If OperationListener is the recommended and supported way to get
notifications, we can live with that. We are having problems with the XML
Document wizard. 
Comment 22 Jesse Glick 2006-10-12 16:32:43 UTC
Perhaps some wizard uses the Filesystems API (not through Datasystems) to create
the new files and you are listening only to operationCreateFromTemplate, not
operationPostCreate?
Comment 23 Milos Kleint 2007-01-09 10:31:02 UTC
the xml support is indeed using filesystem apis to create the xml document from
template. why is that? reassigning for evaluation/fix.
Comment 24 Jesse Glick 2007-01-09 18:36:27 UTC
Various complex New File wizards may of course use FS API only to create files;
e.g. apisupport does this. I don't think it's a bug in the wizard; going through
DS API to create files from template is rarely appropriate for custom wizards.
Rather, the user of OperationListener needs to listen to both
operationCreateFromTemplate and operationPostCreate in order to assure complete
coverage. So I suggest this should be moved back to 'projects'. The options for
reporter are:

1. Use OL and accept files which are newly created for any reason. For the NB
IDE usage model this is the correct option, but other distinct applications may
have different usage models.

2. Write a custom New File wizard to report on the result of
InstantiatingIterator.instantiate() (and hope that this is always accurate).

3. Wait for some API from the existing New File wizard to provide the same
information as #2 to an external listener.
Comment 25 Milos Kleint 2007-01-10 07:16:45 UTC
reassigning back then
Comment 26 Thomas Preisler 2007-01-31 00:22:51 UTC
1) I believe we already do 1) and we know it doesn't work with files created
with XML wizard.
2) Is unacceptable and may not work when we have all the Java modules enabled.

I think we will just wait for 3). Please don't make it a p4 though.....
Comment 27 Jesse Glick 2007-02-02 23:28:31 UTC
"I believe we already do 1) ...." - I think you do not. I wrote "for _any_
reason", i.e. also operationPostCreate.

AFAIK #2 would work whether or not Java modules are enabled, but of course I
have not tried it.
Comment 28 Thomas Preisler 2007-02-02 23:33:28 UTC
We don't handle operationPostCreate. I will try...
Comment 29 Thomas Preisler 2007-02-06 20:02:47 UTC
I tried to listen to operationPostCreate but it doesn't work well. I get
literally hundreds of calls to operationPostCreate for just about anything I do
in the IDE that involves files like opening a project or just opening the New
File wizard (no files created). Yes, it also gets called when I create a new XML
file from the XML wizard, but I don't think there is an simple way to really
know whether a new file has been created or not so I don't think this is the
solution.
Comment 30 Antonin Nebuzelsky 2010-03-29 14:10:05 UTC
Change of default owner.
Comment 31 Milos Kleint 2012-08-31 12:37:09 UTC
is there still something to be done? the thread is long and old..
Comment 32 Martin Balin 2016-07-07 08:39:38 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss