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.

View | Details | Raw Unified | Return to bug 27444
Collapse All | Expand All

(-)a/openide.loaders/src/org/openide/loaders/DataNode.java (-32 / +29 lines)
Lines 83-90 Link Here
83
83
84
    /** Create a data node for a given data object.
84
    /** Create a data node for a given data object.
85
    * The provided children object will be used to hold all child nodes.
85
    * The provided children object will be used to hold all child nodes.
86
    * The name is always set to the base name of the primary file;
86
    * The name is always the {@linkplain FileObject#getNameExt full name} of the primary file;
87
    * the display name may instead be set to the base name with extension.
87
    * the default display name is the same (unless {@link #setShowFileExtensions} has been turned off).
88
    * @param obj object to work with
88
    * @param obj object to work with
89
    * @param ch children container for the node
89
    * @param ch children container for the node
90
    * @param lookup the lookup to provide content of {@link #getLookup}
90
    * @param lookup the lookup to provide content of {@link #getLookup}
Lines 105-111 Link Here
105
105
106
        obj.addPropertyChangeListener (org.openide.util.WeakListeners.propertyChange (propL, obj));
106
        obj.addPropertyChangeListener (org.openide.util.WeakListeners.propertyChange (propL, obj));
107
107
108
        super.setName (obj.getName ());
108
        super.setName(obj.getPrimaryFile().getNameExt());
109
        updateDisplayName ();
109
        updateDisplayName ();
110
    }
110
    }
111
111
Lines 114-143 Link Here
114
        String newDisplayName;
114
        String newDisplayName;
115
        
115
        
116
        if (prim.isRoot()) {
116
        if (prim.isRoot()) {
117
            // Special case - getName{,Ext} will just return "".
117
            newDisplayName = FileUtil.getFileDisplayName(prim);
118
            // Used to be handled by org.netbeans.core.RootFolderNode
119
            // but might as well do it here.
120
            // XXX replace with #37549
121
            File f = FileUtil.toFile(prim);
122
            if (f == null) {
123
                // Check for a JAR root explicitly.
124
                FileObject archiveFile = FileUtil.getArchiveFile(prim);
125
                if (archiveFile != null) {
126
                    f = FileUtil.toFile(archiveFile);
127
                }
128
            }
129
            if (f != null) {
130
                // E.g. /tmp/foo or /tmp/foo.jar
131
                newDisplayName = f.getAbsolutePath();
132
            } else {
133
                try {
134
                    // E.g. http://webdavhost.nowhere.net/mystuff/
135
                    newDisplayName = prim.getURL().toExternalForm();
136
                } catch (FileStateInvalidException e) {
137
                    // Should not happen in practice.
138
                    newDisplayName = "???"; // NOI18N
139
                }
140
            }
141
        } else if (showFileExtensions || obj instanceof DataFolder || obj instanceof DefaultDataObject) {
118
        } else if (showFileExtensions || obj instanceof DataFolder || obj instanceof DefaultDataObject) {
142
            newDisplayName = prim.getNameExt();
119
            newDisplayName = prim.getNameExt();
143
        } else {
120
        } else {
Lines 158-174 Link Here
158
    }
135
    }
159
136
160
    /** Changes the name of the node and may also rename the data object.
137
    /** Changes the name of the node and may also rename the data object.
161
    * If the object is renamed and file extensions are to be shown,
138
    * The display name is also updated accordingly.
162
    * the display name is also updated accordingly.
163
    *
139
    *
164
    * @param name new name for the object
140
    * @param name new name for the primary file (should include any extension)
165
    * @param rename rename the data object?
141
    * @param rename rename the data object?
166
    * @exception IllegalArgumentException if the rename failed
142
    * @exception IllegalArgumentException if the rename failed
167
    */
143
    */
168
    public void setName (String name, boolean rename) {
144
    public void setName (String name, boolean rename) {
169
        try {
145
        try {
170
            if (rename) {
146
            if (rename) {
171
                obj.rename (name);
147
                FileObject prim = obj.getPrimaryFile();
148
                String ext = prim.getExt();
149
                if (ext.length() == 0) {
150
                    obj.rename(name);
151
                } else if (name.endsWith("." + ext)) {
152
                    obj.rename(name.substring(0, name.length() - 1 - ext.length()));
153
                } else {
154
                    if (obj.isModified()) {
155
                        // Cannot preserve any modified document in such a case.
156
                        // XXX add a localized message
157
                        throw new IllegalArgumentException();
158
                    }
159
                    int dot = name.lastIndexOf('.');
160
                    String newBase = dot == -1 ? name : name.substring(0, dot);
161
                    String newExt = dot == -1 ? "" : name.substring(dot + 1);
162
                    FileLock lock = prim.lock();
163
                    try {
164
                        obj.getPrimaryFile().rename(lock, newBase, newExt);
165
                    } finally {
166
                        lock.releaseLock();
167
                    }
168
                }
172
            }
169
            }
173
170
174
            super.setName (name);
171
            super.setName (name);
Lines 705-711 Link Here
705
                }
702
                }
706
703
707
                if (DataObject.PROP_NAME.equals(ev.getPropertyName())) {
704
                if (DataObject.PROP_NAME.equals(ev.getPropertyName())) {
708
                    DataNode.super.setName(obj.getName());
705
                    DataNode.super.setName(obj.getPrimaryFile().getNameExt());
709
                    updateDisplayName();
706
                    updateDisplayName();
710
                }
707
                }
711
                if (DataObject.PROP_COOKIE.equals(ev.getPropertyName())) {
708
                if (DataObject.PROP_COOKIE.equals(ev.getPropertyName())) {

Return to bug 27444