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.
IMHO, DefaultDataLoader should be a UniFileLoader so that DefaultDataObject can be a MultiDataObject. Just use a regular FileEntry, I guess. This would permit its primary entry to be used in e.g. an EditorSupport. Currently it is impossible to attach text editing support to default data objects explicitly from a module, since there is no MultiDataObject.Entry to use for the editing support. (Well, not impossibl e but unreasonably difficult without EditorSupport.) Attaching sample tools-action module demonstrating the problem. If problem were fixed, you should be able to right-click on any default object node, Tools | Edit as Text, and get a plain-text view of it.
Priority is changed to P4 (normal).
I offer proposal of rewriting class DefaultDataObject, which is stored in org.openide.loaders.DefaultDataObject.java and DefaultLoader, which is stored in org.openide.loaders.DataLoaderPool.java. This overwriting is attached. The class DefaultNode was deleted. It is not now necessary, because it only rewrote the method getDisplayName, which returned name of file with extension. Now DefaulDataObject.getName() returns this. Overwriting of DefaultDataObject corrects the bug #4466 (renaming a DefaultDataObject). package org.openide.loaders; import java.io.*; import java.util.HashSet; import org.openide.filesystems.*; import org.openide.util.HelpCtx; import org.openide.nodes.Node; /** An implementation of a data object which consumes file objects not recognized by any other loaders. * * @author Ian Formanek */ class DefaultDataObject extends MultiDataObject { static final long serialVersionUID =-4936309935667095746L; /** generated Serialized Version UID */ // static final long serialVersionUID = 6305590675982925167L; /** Constructs new data shadow for given primary file and referenced original. * @param fo the primary file * @param original original data object */ DefaultDataObject (FileObject fo, MultiFileLoader loader) throws DataObjectExistsException { super (fo, loader); } /* Creates node delegate. */ protected Node createNodeDelegate () { return new DataNode (this, org.openide.nodes.Children.LEAF); } /** Get the name of the data object. * <p>The implementation uses the name of the primary file and its exten. * @return the name */ public String getName() { return getPrimaryFile ().getName () + "." + getPrimaryFile ().getExt (); } /* Help context for this object. * @return help context */ public HelpCtx getHelpCtx () { return new HelpCtx (DefaultDataObject.class); } /* Handles renaming of the object. * Must be overriden in children. * * @param name name to rename the object to * @return new primary file of the object * @exception IOException if an error occures */ protected FileObject handleRename (String name) throws IOException { FileLock lock = getPrimaryFile ().lock (); int pos = name.lastIndexOf('.'); try { if (pos == 0){ getPrimaryFile ().rename (lock, name, getPrimaryFile ().getExt ()); } else { if (!name.equals(getPrimaryFile ().getName() + "." + getPrimaryFile ().getExt ())){ getPrimaryFile ().rename (lock, name.substring(0, pos), name.substring(pos+1, name.length())); HashSet s = new HashSet (); s.add(getPrimaryFile()); DataObjectPool.POOL.revalidate(s); } } } finally { lock.releaseLock (); } return getPrimaryFile (); } } /** Loader for file objsects not recognized by any other loader */ private static class DefaultLoader extends MultiFileLoader { /** Default set of actions on the DefaultDataObject. */ private static SystemAction[] defaultDataActions = new SystemAction[] { SystemAction.get (org.openide.actions.FileSystemAction.class), null, SystemAction.get (org.openide.actions.CutAction.class), SystemAction.get (org.openide.actions.CopyAction.class), SystemAction.get (org.openide.actions.PasteAction.class), null, SystemAction.get (org.openide.actions.DeleteAction.class), SystemAction.get (org.openide.actions.RenameAction.class), null, SystemAction.get (org.openide.actions.ToolsAction.class), SystemAction.get (org.openide.actions.PropertiesAction.class) }; static final long serialVersionUID =-6761887227412396555L; /* Representation class is DataFolder */ private DefaultLoader () { super (DefaultDataObject.class); } protected void initialize () { setDisplayName (NbBundle.getBundle (DataLoaderPool.class).getString ("LBL_default_loader_display_name")); setActions (defaultDataActions); } /** Get the primary file. * @param fo the file to find the primary file for * * @return the primary file */ protected FileObject findPrimaryFile (FileObject fo) { // never recognize folders if (fo.isFolder()) return null; return fo; } /* Creates the right data object for given primary file. * It is guaranteed that the provided file is realy primary file * returned from the method findPrimaryFile. * * @param primaryFile the primary file * @return the data object for this file * @exception DataObjectExistsException if the primary file already has data object */ protected MultiDataObject createMultiObject (FileObject primaryFile) throws DataObjectExistsException, java.io.IOException { return new DefaultDataObject(primaryFile, this); } /* Creates the right primary entry for given primary file. * * @param obj requesting object * @param primaryFile primary file recognized by this loader * @return primary entry for that file */ protected MultiDataObject.Entry createPrimaryEntry (MultiDataObject obj, FileObject primaryFile) { return new FileEntry (obj, primaryFile); } /** Do not create a seconday entry. * * @param obj ignored * @param secondaryFile ignored * @return never returns * @exception UnsupportedOperationException because this loader supports only a primary file object */ protected MultiDataObject.Entry createSecondaryEntry (MultiDataObject obj, FileObject secondaryFile) { throw new UnsupportedOperationException (); } /** Does nothing because this loader works only with objects * with one file => primary file so it is not necessary to search * for anything else. * * @param obj the object to test */ void checkFiles (MultiDataObject obj) { } }
Just a comment about including source code in the bug report: it is much better to include a diff (cvs diff -c, for example), and add it as a Bugzilla attachment. Reasons: (1) including it inline means that lines are broken at right margin, and they have to be corrected manually; (2) there is no way to see exactly what changed, therefore whether it is safe; (3) a diff can usually be applied to the file even if someone has made changes in the meantime, whereas checking in a whole new file based on an older version will quietly destroy that other person's changes. Please attach a context (-c) diff for what you want to change.
Created attachment 123 [details] Diff for DataLoaderPool
Created attachment 124 [details] Diff for DefaultDataObject
It would be even simpler if the loader was a UniFileLoader, I think...does this work?
Created attachment 125 [details] Previously mentioned attachment (lost during StarTeam -> Bugzilla conversion I guess)
I created small module EditAsText. I tested my new source code of DefaultDataObject and DefaultLoader. It worked correctly. The item menu "Edit as Text" was displayed in the speed menu Tools for DefaultDataObjects. I did not choose a UniFileLoader as superclass for DefaultLoader, because the DefaultLoader does not need to extensions, but DefaultLoader is very similar to UniFileLoader.
Resolved for 3.4.x or earlier, no new info since then -> verified
Resolved for 3.4.x or earlier, no new info since then -> closing.