Class NbHandle
- All Implemented Interfaces:
EventListener, org.openide.filesystems.FileChangeListener, uno.anahata.asi.agi.resource.handle.ResourceHandle, uno.anahata.asi.persistence.Rebindable
FileObject.
This is the ultimate handle for the IDE environment. It leverages NetBeans VFS to handle local files, JAR entries, and remote files (via plugins) uniformly. It is reactive: it listens for IDE events and notifies the owner Resource when the content is modified or moved.
Archive Awareness: It correctly identifies JAR and Read-Only filesystems to disable writability.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.openide.filesystems.FileObjectThe live NetBeans FileObject.private StringCached path for secondary resolution.private org.openide.loaders.OperationListenerStrong reference to the operation listener adapter.private @NonNull URIThe unique identifier URI for the resource.private org.openide.filesystems.FileChangeListenerWeak listener to prevent memory leaks.private org.openide.loaders.OperationListenerWeak operation listener registered with the IDE's DataLoaderPool to monitor global file moves and lifecycle changes (such as drag-and-drop or cut-and-paste across folders) without creating memory leaks.Fields inherited from class uno.anahata.asi.agi.resource.handle.AbstractResourceHandle
owner -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCurrently unsued.voiddispose()booleanexists()voidfileAttributeChanged(org.openide.filesystems.FileAttributeEvent fe) voidfileChanged(org.openide.filesystems.FileEvent fe) voidfileDataCreated(org.openide.filesystems.FileEvent fe) voidfileDeleted(org.openide.filesystems.FileEvent fe) voidfileFolderCreated(org.openide.filesystems.FileEvent fe) voidfileRenamed(org.openide.filesystems.FileRenameEvent fe) org.openide.filesystems.FileObjectEnsures the FileObject is resolved and listeners are attached.longgetName()private voidhandleOperationMove(org.openide.loaders.OperationEvent.Move ev) Processes global file move operations fired by the IDE loaders layer.booleanbooleanbooleanlonglength()voidrebind()private voidAttaches the IDE filesystem listener.private voidRe-establishes or initializes the global operation listener.private voidAuthoritatively sets and normalizes the resource URI.voidMethods inherited from class uno.anahata.asi.agi.resource.handle.AbstractResourceHandle
getOwner, setOwnerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface uno.anahata.asi.agi.resource.handle.ResourceHandle
asBytes, asText, getHeader, getUri, isStale, isTextual
-
Field Details
-
uri
The unique identifier URI for the resource. -
path
Cached path for secondary resolution. -
fileObject
private transient org.openide.filesystems.FileObject fileObjectThe live NetBeans FileObject. -
weakListener
private transient org.openide.filesystems.FileChangeListener weakListenerWeak listener to prevent memory leaks. -
weakOpListener
private transient org.openide.loaders.OperationListener weakOpListenerWeak operation listener registered with the IDE's DataLoaderPool to monitor global file moves and lifecycle changes (such as drag-and-drop or cut-and-paste across folders) without creating memory leaks. -
strongOpListener
private transient org.openide.loaders.OperationListener strongOpListenerStrong reference to the operation listener adapter. This field anchors the listener in memory to prevent the JVM's Garbage Collector from reclaiming it while the NbHandle is alive, preserving global file-movement monitoring.
-
-
Constructor Details
-
NbHandle
Constructs a new NbHandle from a URI.- Parameters:
uri- The resource URI (file:, jar:, etc.).
-
NbHandle
public NbHandle(org.openide.filesystems.FileObject fileObject) Direct constructor for an existing FileObject.- Parameters:
fileObject- The NetBeans FileObject to wrap.
-
-
Method Details
-
setUri
Authoritatively sets and normalizes the resource URI. For local files, it forces the triple-slash (file:///) format and extracts the physical path to maintain identity consistency within the manager.- Parameters:
uri- The URI to set.
-
getFileObject
public org.openide.filesystems.FileObject getFileObject()Ensures the FileObject is resolved and listeners are attached.- Returns:
- The FileObject instance.
-
setupListener
private void setupListener()Attaches the IDE filesystem listener. -
setupOperationListener
private void setupOperationListener()Re-establishes or initializes the global operation listener.Leverages the
DataLoaderPool.createWeakOperationListener(org.openide.loaders.OperationListener, java.lang.Object)utility to bind a weak listener that automatically unloads if this resource handle is GCed. -
handleOperationMove
private void handleOperationMove(org.openide.loaders.OperationEvent.Move ev) Processes global file move operations fired by the IDE loaders layer.If the original primary file of the moved
DataObjectmatches our activeFileObject, this handle detaches its old file listeners, updates its internally managed URI and path to point to the new destination file, re-attaches new listeners, and marks the parent resource dirty.- Parameters:
ev- The IDE-fired move operation event.
-
getName
Implementation details: Resolves name via the NetBeans FileObject or the URI path component.
- Specified by:
getNamein interfaceuno.anahata.asi.agi.resource.handle.ResourceHandle
-
getHtmlDisplayName
Implementation details: Extracts the HTML display name from the IDE's DataObject delegate to show Git status or compiler errors.
- Specified by:
getHtmlDisplayNamein interfaceuno.anahata.asi.agi.resource.handle.ResourceHandle
-
getMimeType
Implementation details: Leverages NetBeans native FileObject MIME detection with a Tika fallback for unrecognized types.
- Specified by:
getMimeTypein interfaceuno.anahata.asi.agi.resource.handle.ResourceHandle
-
asTextFromEditorIfOpenInEditor
Currently unsued. Prioritizes the active NetBeans Document content if the file is open in the editor, use this to show unsaved changes to the model.- Returns:
- The text content of the active document in the editor, or file content if not open.
- Throws:
IOException- If reading the document or stream fails.
-
getLastModified
public long getLastModified()Implementation details: Retrieves the authoritative last modified timestamp from the NetBeans VFS.
- Specified by:
getLastModifiedin interfaceuno.anahata.asi.agi.resource.handle.ResourceHandle
-
isModified
public boolean isModified()Implementation details: Checks if the NetBeans DataObject associated with this FileObject is currently marked as modified in the IDE (i.e. has unsaved editor changes).
- Specified by:
isModifiedin interfaceuno.anahata.asi.agi.resource.handle.ResourceHandle
-
exists
public boolean exists()Implementation details: Checks the validity of the NetBeans FileObject.
- Specified by:
existsin interfaceuno.anahata.asi.agi.resource.handle.ResourceHandle
-
openStream
Implementation details: Opens an InputStream directly via the NetBeans FileObject.
- Specified by:
openStreamin interfaceuno.anahata.asi.agi.resource.handle.ResourceHandle- Throws:
IOException
-
isWritable
public boolean isWritable()Implementation details: Checks both filesystem read-only status (e.g., JARs) and FileObject OS-level writability.
- Specified by:
isWritablein interfaceuno.anahata.asi.agi.resource.handle.ResourceHandle
-
write
Implementation details: Writes content via the NetBeans FileObject output stream, using the handle's detected charset.
- Specified by:
writein interfaceuno.anahata.asi.agi.resource.handle.ResourceHandle- Throws:
IOException
-
isVirtual
public boolean isVirtual()Implementation details: returns
falseas this represents a physical persistent resource within the IDE.- Specified by:
isVirtualin interfaceuno.anahata.asi.agi.resource.handle.ResourceHandle
-
length
public long length()Returns the size of the NetBeans FileObject.
- Specified by:
lengthin interfaceuno.anahata.asi.agi.resource.handle.ResourceHandle
-
getCharset
Implementation details: Resolves the charset using the NetBeans
FileEncodingQueryto ensure project alignment.- Specified by:
getCharsetin interfaceuno.anahata.asi.agi.resource.handle.ResourceHandle
-
rebind
public void rebind()Implementation details: Refreshes the FileObject resolution and re-attaches listeners after deserialization.
- Specified by:
rebindin interfaceuno.anahata.asi.persistence.Rebindable- Overrides:
rebindin classuno.anahata.asi.agi.resource.handle.AbstractResourceHandle
-
dispose
public void dispose()Implementation details: Detaches the weak IDE filesystem listener to prevent leaks.
- Specified by:
disposein interfaceuno.anahata.asi.agi.resource.handle.ResourceHandle
-
fileChanged
public void fileChanged(org.openide.filesystems.FileEvent fe) Implementation details: Notifies the owner resource of content changes detected by the IDE using the new unified
markDirty()marker.- Specified by:
fileChangedin interfaceorg.openide.filesystems.FileChangeListener
-
fileRenamed
public void fileRenamed(org.openide.filesystems.FileRenameEvent fe) Implementation details: Updates internal URI/Path and notifies owner of the identity change within the IDE using the unified dirty marker.
- Specified by:
fileRenamedin interfaceorg.openide.filesystems.FileChangeListener
-
fileDataCreated
public void fileDataCreated(org.openide.filesystems.FileEvent fe) - Specified by:
fileDataCreatedin interfaceorg.openide.filesystems.FileChangeListener
-
fileFolderCreated
public void fileFolderCreated(org.openide.filesystems.FileEvent fe) - Specified by:
fileFolderCreatedin interfaceorg.openide.filesystems.FileChangeListener
-
fileDeleted
public void fileDeleted(org.openide.filesystems.FileEvent fe) Implementation details: Notifies owner that the source is gone.
- Specified by:
fileDeletedin interfaceorg.openide.filesystems.FileChangeListener
-
fileAttributeChanged
public void fileAttributeChanged(org.openide.filesystems.FileAttributeEvent fe) - Specified by:
fileAttributeChangedin interfaceorg.openide.filesystems.FileChangeListener
-

