Typically, a project layout is that src/main/java contains the .java files and src/main/resources contains the resources. Thus, the *.form files should to into resources. However, NetBeans does not find them.
Is it possible to have NetBeans load the corresponding .form file from a different folder?
Maybe, I understood src/main/java wrong and .form should also go in there?!
Same folder
Different folders
What is the .form file
From faq:
The .form file is an XML file that the visual editor uses to store the information about the GUI form. It is much more reliable than reading the information from the source code. You do not need to distribute the .form file with your application; it's only used by the IDE. However, if you want to open your form again in the form editor, you should keep the file
Directory Layout
Indeed the standard directory layout for a maven project consists of src/main/java for java files and src/main/resources for resources. But it is only true for maven projects.
The ant-based project uses a different layout and usually places properties files and other files withing source directories but could use any custom locations for resources including sub-directories within a package.
Use a different folder for .forms files
Unfortunately, it's impossible to separate them from the relevant so caled "brother" files, see below. They are too tightly coupled together. For example, if you look at the project tree view NetBeans hides the .form files if there are relevant java files within the same directory.
Let's see the source code, precisely a method findPrimaryFile that is used for finding a primary file:
protected FileObject findPrimaryFile(FileObject fo) {
if (fo.isFolder()) return null;
String ext = fo.getExt();
if (ext.equals(FORM_EXTENSION))
return FileUtil.findBrother(fo, JAVA_EXTENSION);
FileObject javaFile = findJavaPrimaryFile(fo);
return javaFile != null
&& FileUtil.findBrother(javaFile, FORM_EXTENSION) != null ?
javaFile : null;
}
It calls findBrother method that looks for appropriate .form or java files and it always looks for the "brother" file within the same directory:
public static FileObject findBrother(FileObject fo, String ext) {
if (fo == null) {
return null;
}
FileObject parent = fo.getParent();
if (parent == null) {
return null;
}
return parent.getFileObject(fo.getName(), ext);
}
Related
In a project I have some internal files that are just JSON files but with specific well known filenames. I would like to add file associations for these files from my visual studio code plugin so they automatically get recognized as JSON and highlighted accordingly but cannot see a way to do this from the plugin. Does anyone know a way to do this?
It turns out you can just add the necessary associations to the workspace settings
// add file associations for our configurations files
let conf = vscode.workspace.getConfiguration('files');
let assocs = conf.get<{}>('associations');
assocs['special.info'] = 'json';
conf.update('associations', assocs, ConfigurationTarget.Workspace);
I m trying to create a virtual folder inside a folder in eclipse. I want to link some files to this virtual folder but I m not able to link.
Below is the sample code:
IFolder folder = modelFolder.getFolder("Script_include");
folder.create(IResource.VIRTUAL, false, null);
IPath newLocation = new Path("/Users/dinesh.lodhi");
folder.createLink(newLocation, IResource.NONE, null);
What I exactly want is to create some virtual folders inside one of the folder at the startup of my plugin and want to link some of resources into it.
The given path must be either an absolute file system path, or a relative path whose first segment is the name of a workspace path variable.
I was mistakenly using folder.getFullPath() for getting location.
and one more thing there is no need to
folder.create(IResource.VIRTUAL, false, null);
as createLink() method itself Creates a new file/folder resource as a member of this handle's parent resource.
Thanks
In the Eclipse plugins we're developing, we've defined a custom content type, using the org.eclipse.core.contenttype.contentTypes extension point. We're successfully using the content type to enable or disable UI components, based on, e.g., whether the user is editing a file of that type.
I'd like to take this ones step further and also use it to filter files in a file selection dialog, such that it only shows files that match the content type.
I have found that filtering a JFace Viewer this way is possible, so for files in the workspace, we could use an ElementTreeSelectionDialog and add a ViewerFilter.
Is there a way to do the same for a file selection dialog of the entire file system (instead of filtering by file extension)? Or is this impossible because it's restricted to the OS's filtering?
The standard SWT FileDialog can only be filtered by file extension and cannot be extended.
You could write your own file selection dialog using the normal Java File or Path APIs with a tree viewer and a viewer filter.
Because the files are outside of the workspace you can't use any of the IResource, IFile, IFolder APIs. However you can still use the IContentTypeManager interface which gives you access to your content types.
IContentTypeManager manager = Platform.getContentTypeManager();
If the file extension is enough to distinguish the files you can just use:
IContentType contentType = manager.findContentTypeFor("the file name");
If you need to use the content describers use:
InputStream stream = ... new FileInputStream(....
IContentType contentType = manager.findContentTypeFor(stream, "the file name");
stream.close();
I am developing a component which generates code based on templates inside java class. The project use clearcase as SCM. After the code update, the files are in read-only state. If i am adding anything to any java class, i have to make it hijack and paste the source code templates inside the class. Let's suppose the jAutoDoc plugin which is used for adding comment. If user select a class, click on generate comment. The comment will not paste if the file is not in write mode.
Clearcase Plugin Vendor : IBM Rational.
Eclipse Version : 3.5
Please help. Is there any way to do hijack a file from java code?
Thanks in advance..
Thanks VonC.
For making a java file in write mode through eclipse JDT API. This method will set the preference "read only" of the resource to "false".
private static void setCompilationUnitWriteMode(ICompilationUnit cu) throws CoreException {
ResourceAttributes resourceAttributes = cu.getResource().getResourceAttributes();
if (resourceAttributes != null) {
// Setting Writemode true
resourceAttributes.setReadOnly(false);
cu.getResource().setResourceAttributes(resourceAttributes);
}
}
For Non Java Resource
First create the IFile object, set the preference "read only" of the resource to "false".
IFile file = path.getFile()
file.getFile().getResourceAttributes();
if (resourceAttributes != null) {
resourceAttributes.setReadOnly(false);
file.setResourceAttributes(resourceAttributes);
}
Hijacking files only means making them read - write through an OS-based operation. (for snapshot view only, not dynamic ones)
The question is though: do you need to version your classes completed by your plugin?
Because in that case, a cleartool checkout is more appropriate.
Otherwise, read write is enough, changing file attribute through java.
I have some problems updating an "old" Eclipse plugin. Here is what I would like to do and what the original plugin did:
(parse compiler output on console with file name and error information --> still works)
--> set link to the location within the file
--> set marker to location in the file
What I did in the past was to get the IFile from the path String of the file and generated link and marker from it:
IFile ifile;
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPath path = new Path(fileName);
IFiles[] files = workspace.getRoot().findFilesForLocation(path);
...
ifile = iFiles[0];
Map attributes = new HashMap();
attributes.put(IMarker.SEVERITY, new Integer (severity));
MarkerUtilities.setLineNumber(attributes, lineNumber);
MarkerUtilities.setMessage(attributes, message);
MarkerUtilities.createMarker(ifile, attributes,
IMarker
Since findFilesForLocation is deprecated, I tried to find another way but I am not succeeding whatsoever. Using the changed code to get the IFile always results in a exception: org.eclipse.core.internal.resources.ResourceException: Resource '/path/to/file.c' does not exist.
Is it possible that this relates to the fact that the source file is only linked into the project, and not physically within the project?
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPath location = new Path(fileName);
IFile ifile = workspace.getRoot().getFile(location);
Can anyone help?
Thank you!
I am guessing that fileName is the fully qualified path to the file you want to get. I'm also guessing that the file that you are looking for is already in the workspace, even if it is linked (if not, then this won't work. You will first need to add the file to a project before getting the IFile for it).
You need to do something like this:
IFiles[] files = workspace.getRoot().findFilesForLocationURI("file:" + fileName);
Then this will find all files in the workspace that correspond to the file in the file system.
The reason why your attempt above is giving you a ResourceException is that you are trying to pass in a file system path to get an IFile object from the workspace. The Eclipse workspace is an abstraction over the underlying filesystem and cannot directly work with absolute paths.
For the Resources APIs, Paths usually means a path in the workspace and Location usually refers to a place in the filesystem or outside the workspace. If you already have a workspace path to start with, just ask the IWorkspaceRoot for the IFile and get on with what you're doing.