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 3532 - DefaultDataObject does not subclass MultiDataObject.
Summary: DefaultDataObject does not subclass MultiDataObject.
Status: CLOSED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 3.x
Hardware: All All
: P4 normal (vote)
Assignee: Jaroslav Tulach
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 1999-08-20 18:54 UTC by Jesse Glick
Modified: 2008-12-23 10:59 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Diff for DataLoaderPool (3.75 KB, patch)
2001-07-20 20:32 UTC, Petr Pisl
Details | Diff
Diff for DefaultDataObject (8.36 KB, patch)
2001-07-20 20:32 UTC, Petr Pisl
Details | Diff
Previously mentioned attachment (lost during StarTeam -> Bugzilla conversion I guess) (2.31 KB, text/x-java)
2000-08-31 16:11 UTC, Jesse Glick
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 1999-08-20 18:54:53 UTC
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.
Comment 1 Marek Grummich 2000-07-25 09:09:59 UTC
Priority is changed to P4 (normal).
Comment 2 Petr Pisl 2000-08-31 15:10:59 UTC
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) {
        }
    }
Comment 3 Jesse Glick 2000-08-31 15:21:59 UTC
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.
Comment 4 Petr Pisl 2000-08-31 16:02:59 UTC
Created attachment 123 [details]
Diff for DataLoaderPool
Comment 5 Petr Pisl 2000-08-31 16:04:59 UTC
Created attachment 124 [details]
Diff for DefaultDataObject
Comment 6 Jesse Glick 2000-08-31 16:06:59 UTC
It would be even simpler if the loader was a UniFileLoader, I think...does this
work?
Comment 7 Jesse Glick 2000-08-31 16:11:59 UTC
Created attachment 125 [details]
Previously mentioned attachment (lost during StarTeam -> Bugzilla conversion I guess)
Comment 8 Petr Pisl 2000-09-01 08:38:59 UTC
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.
Comment 9 Quality Engineering 2003-07-01 15:57:34 UTC
Resolved for 3.4.x or earlier, no new info since then -> verified
Comment 10 Quality Engineering 2003-07-01 16:16:21 UTC
Resolved for 3.4.x or earlier, no new info since then -> closing.