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 164996
Collapse All | Expand All

(-)a/favorites/nbproject/project.xml (-1 / +4 lines)
Lines 257-263 Link Here
257
                    </test-dependency>
257
                    </test-dependency>
258
                </test-type>
258
                </test-type>
259
            </test-dependencies>
259
            </test-dependencies>
260
            <public-packages/>
260
            <friend-packages>
261
                <friend>org.netbeans.modules.kenai.ui</friend>
262
                <package>org.netbeans.modules.favorites.api</package>
263
            </friend-packages>
261
        </data>
264
        </data>
262
    </configuration>
265
    </configuration>
263
</project>
266
</project>
(-)a/favorites/src/org/netbeans/modules/favorites/Actions.java (-32 / +21 lines)
Lines 56-61 Link Here
56
import javax.swing.JFileChooser;
56
import javax.swing.JFileChooser;
57
import javax.swing.JMenuItem;
57
import javax.swing.JMenuItem;
58
import javax.swing.SwingUtilities;
58
import javax.swing.SwingUtilities;
59
import org.netbeans.modules.favorites.api.Favorites;
59
import org.openide.DialogDisplayer;
60
import org.openide.DialogDisplayer;
60
import org.openide.NotifyDescriptor;
61
import org.openide.NotifyDescriptor;
61
import org.openide.filesystems.FileObject;
62
import org.openide.filesystems.FileObject;
Lines 147-160 Link Here
147
            Tab proj = Tab.findDefault();
148
            Tab proj = Tab.findDefault();
148
            proj.open();
149
            proj.open();
149
            proj.requestActive();
150
            proj.requestActive();
150
            proj.doSelectNode((DataObject)activatedNodes[0].getCookie(DataObject.class));
151
            proj.doSelectNode(activatedNodes[0].getCookie(DataObject.class));
151
        }
152
        }
152
153
153
        protected boolean enable(Node[] activatedNodes) {
154
        protected boolean enable(Node[] activatedNodes) {
154
            if (activatedNodes.length != 1) {
155
            if (activatedNodes.length != 1) {
155
                return false;
156
                return false;
156
            }
157
            }
157
            DataObject dobj = (DataObject)activatedNodes[0].getCookie(DataObject.class);
158
            DataObject dobj = activatedNodes[0].getCookie(DataObject.class);
158
            if (dobj == null) {
159
            if (dobj == null) {
159
                return false;
160
                return false;
160
            }
161
            }
Lines 167-178 Link Here
167
        }
168
        }
168
169
169
        /** Overriden to have different title in popup menu, works but ugly a bit */
170
        /** Overriden to have different title in popup menu, works but ugly a bit */
171
        @Override
170
        public JMenuItem getPopupPresenter() {
172
        public JMenuItem getPopupPresenter() {
171
            JMenuItem mi = super.getPopupPresenter();
173
            JMenuItem mi = super.getPopupPresenter();
172
            mi.setText(NbBundle.getMessage(Select.class, "ACT_Select")); // NOI18N
174
            mi.setText(NbBundle.getMessage(Select.class, "ACT_Select")); // NOI18N
173
            return mi;
175
            return mi;
174
        }
176
        }
175
177
178
        @Override
176
        protected String iconResource() {
179
        protected String iconResource() {
177
            return "org/netbeans/modules/favorites/resources/actionSelect.png"; // NOI18N
180
            return "org/netbeans/modules/favorites/resources/actionSelect.png"; // NOI18N
178
        }
181
        }
Lines 181-186 Link Here
181
            return null;
184
            return null;
182
        }
185
        }
183
186
187
        @Override
184
        protected boolean asynchronous() {
188
        protected boolean asynchronous() {
185
            return false;
189
            return false;
186
        }
190
        }
Lines 207-215 Link Here
207
            if ((arr == null) || (arr.length == 0)) return false;
211
            if ((arr == null) || (arr.length == 0)) return false;
208
212
209
            for (int i = 0; i < arr.length; i++) {
213
            for (int i = 0; i < arr.length; i++) {
210
                DataObject shad = (DataObject) arr[i].getCookie (DataObject.class);
214
                DataObject shad = arr[i].getCookie(DataObject.class);
211
                //Disable when node is not shadow in Favorites folder.
215
                //Disable when node is not shadow in Favorites folder.
212
                if (shad == null || shad.getFolder() != Favorites.getFolder()) {
216
                if (shad == null || shad.getFolder() != FavoritesNode.getFolder()) {
213
                    return false;
217
                    return false;
214
                }
218
                }
215
            }
219
            }
Lines 239-247 Link Here
239
        */
243
        */
240
        protected void performAction (Node[] arr) {
244
        protected void performAction (Node[] arr) {
241
            for (int i = 0; i < arr.length; i++) {
245
            for (int i = 0; i < arr.length; i++) {
242
                DataObject shad = (DataObject) arr[i].getCookie(DataObject.class);
246
                DataObject shad = arr[i].getCookie(DataObject.class);
243
247
244
                if (shad != null && shad.getFolder() == Favorites.getFolder()) {
248
                if (shad != null && shad.getFolder() == FavoritesNode.getFolder()) {
245
                    try {
249
                    try {
246
                        shad.delete();
250
                        shad.delete();
247
                    } catch (IOException ex) {
251
                    } catch (IOException ex) {
Lines 251-256 Link Here
251
            }
255
            }
252
        }
256
        }
253
257
258
        @Override
254
        protected boolean asynchronous() {
259
        protected boolean asynchronous() {
255
            return false;
260
            return false;
256
        }
261
        }
Lines 280-291 Link Here
280
        */
285
        */
281
        public boolean enable (Node[] arr) {
286
        public boolean enable (Node[] arr) {
282
            if ((arr == null) || (arr.length == 0)) return false;
287
            if ((arr == null) || (arr.length == 0)) return false;
283
            if (arr.length == 1 && arr[0] instanceof Favorites) return true;
288
            if (arr.length == 1 && arr[0] instanceof FavoritesNode) return true;
284
                
289
                
285
            
290
            
286
291
287
            for (int i = 0; i < arr.length; i++) {
292
            for (int i = 0; i < arr.length; i++) {
288
                DataObject dataObject = (DataObject) arr[i].getCookie (DataObject.class);
293
                DataObject dataObject = arr[i].getCookie(DataObject.class);
289
                //Action is disabled for root folder eg:"/" on Linux or "C:" on Win
294
                //Action is disabled for root folder eg:"/" on Linux or "C:" on Win
290
                if (dataObject == null) {
295
                if (dataObject == null) {
291
                    return false;
296
                    return false;
Lines 297-303 Link Here
297
                        return false;
302
                        return false;
298
                    }
303
                    }
299
                    //Allow to link only once
304
                    //Allow to link only once
300
                    if (isInFavorites(fo)) {
305
                    if (Favorites.getDefault().isInFavorites(fo)) {
301
                        return false;
306
                        return false;
302
                    }
307
                    }
303
                    //Check if it is root.
308
                    //Check if it is root.
Lines 322-344 Link Here
322
            return true;
327
            return true;
323
        }
328
        }
324
        
329
        
325
        /** Check if given fileobject is already linked in favorites
326
         * @return true if given fileobject is already linked
327
         */
328
        private boolean isInFavorites (FileObject fo) {
329
            DataFolder f = Favorites.getFolder();
330
            
331
            DataObject [] arr = f.getChildren();
332
            for (int i = 0; i < arr.length; i++) {
333
                if (arr[i] instanceof DataShadow) {
334
                    if (fo.equals(((DataShadow) arr[i]).getOriginal().getPrimaryFile())) {
335
                        return true;
336
                    }
337
                }
338
            }
339
            return false;
340
        }
341
        
342
        /** Human presentable name of the action. This should be
330
        /** Human presentable name of the action. This should be
343
        * presented as an item in a menu.
331
        * presented as an item in a menu.
344
        * @return the name of the action
332
        * @return the name of the action
Lines 361-367 Link Here
361
        * @param activatedNodes gives array of actually activated nodes.
349
        * @param activatedNodes gives array of actually activated nodes.
362
        */
350
        */
363
        protected void performAction (final Node[] activatedNodes) {
351
        protected void performAction (final Node[] activatedNodes) {
364
            final DataFolder f = Favorites.getFolder();            
352
            final DataFolder f = FavoritesNode.getFolder();
365
            final DataObject [] arr = f.getChildren();
353
            final DataObject [] arr = f.getChildren();
366
            final List<DataObject> listAdd = new ArrayList<DataObject>();
354
            final List<DataObject> listAdd = new ArrayList<DataObject>();
367
            
355
            
Lines 369-375 Link Here
369
            Node[] toShadows = activatedNodes; 
357
            Node[] toShadows = activatedNodes; 
370
358
371
            try {
359
            try {
372
                if (activatedNodes.length == 1 && activatedNodes[0] instanceof Favorites) {
360
                if (activatedNodes.length == 1 && activatedNodes[0] instanceof FavoritesNode) {
373
                    // show JFileChooser
361
                    // show JFileChooser
374
                    FileObject fo = chooseFileObject();
362
                    FileObject fo = chooseFileObject();
375
                    if (fo == null) return;
363
                    if (fo == null) return;
Lines 430-442 Link Here
430
            return retVal;
418
            return retVal;
431
        }
419
        }
432
        
420
        
433
        static void selectAfterAddition(final DataObject createdDO) {
421
        public static void selectAfterAddition(final DataObject createdDO) {
434
            final Tab projectsTab = Tab.findDefault();
422
            final Tab projectsTab = Tab.findDefault();
435
            projectsTab.open();
423
            projectsTab.open();
436
            projectsTab.requestActive();
424
            projectsTab.requestActive();
437
            //Try to locate newly added node and select it
425
            //Try to locate newly added node and select it
438
            if (createdDO != null) {
426
            if (createdDO != null) {
439
                Node n = Favorites.getNode();
440
                Node [] nodes = projectsTab.getExplorerManager().getRootContext().getChildren().getNodes(true);
427
                Node [] nodes = projectsTab.getExplorerManager().getRootContext().getChildren().getNodes(true);
441
                final Node [] toSelect = new Node[1];
428
                final Node [] toSelect = new Node[1];
442
                boolean setSelected = false;
429
                boolean setSelected = false;
Lines 464-470 Link Here
464
        static DataObject createShadows(final DataFolder favourities, final Node[] activatedNodes, final List<DataObject> listAdd) {
451
        static DataObject createShadows(final DataFolder favourities, final Node[] activatedNodes, final List<DataObject> listAdd) {
465
            DataObject createdDO = null;
452
            DataObject createdDO = null;
466
            for (int i = 0; i < activatedNodes.length; i++) {
453
            for (int i = 0; i < activatedNodes.length; i++) {
467
                DataObject obj = (DataObject) activatedNodes[i].getCookie(DataObject.class);
454
                DataObject obj = activatedNodes[i].getCookie(DataObject.class);
468
455
469
                if (obj != null) {
456
                if (obj != null) {
470
                    try {
457
                    try {
Lines 483-489 Link Here
483
            return createdDO;
470
            return createdDO;
484
        }
471
        }
485
472
486
        static void reorderAfterAddition(final DataFolder favourities, final DataObject[] children, final List<DataObject> listAdd) {
473
        public static void reorderAfterAddition(final DataFolder favourities, final DataObject[] children, final List<? extends DataObject> listAdd) {
487
            List<DataObject> listDest = new ArrayList<DataObject>();
474
            List<DataObject> listDest = new ArrayList<DataObject>();
488
            if (listAdd.size() > 0) {
475
            if (listAdd.size() > 0) {
489
                //Insert new nodes just before last (root) node
476
                //Insert new nodes just before last (root) node
Lines 520-525 Link Here
520
            }
507
            }
521
        }
508
        }
522
509
510
        @Override
523
        protected boolean asynchronous() {
511
        protected boolean asynchronous() {
524
            return false;
512
            return false;
525
        }
513
        }
Lines 543-548 Link Here
543
        * presented as an item in a menu.
531
        * presented as an item in a menu.
544
        * @return the name of the action
532
        * @return the name of the action
545
        */
533
        */
534
        @Override
546
        public String getName() {
535
        public String getName() {
547
            return NbBundle.getMessage (
536
            return NbBundle.getMessage (
548
                    Actions.class, "ACT_AddOnFavoritesNode"); // NOI18N
537
                    Actions.class, "ACT_AddOnFavoritesNode"); // NOI18N
(-)a/favorites/src/org/netbeans/modules/favorites/Favorites.java (-10 / +10 lines)
Lines 78-91 Link Here
78
 *
78
 *
79
 * @author  Jaroslav Tulach
79
 * @author  Jaroslav Tulach
80
 */
80
 */
81
final class Favorites extends FilterNode implements Index {
81
public final class FavoritesNode extends FilterNode implements Index {
82
    /** default node */
82
    /** default node */
83
    private static Node node;
83
    private static Node node;
84
    /** node that represents root of filesystems */
84
    /** node that represents root of filesystems */
85
    private static Node root;
85
    private static Node root;
86
86
87
    /** Creates new ProjectRootFilterNode. */
87
    /** Creates new ProjectRootFilterNode. */
88
    private Favorites(Node node) {
88
    private FavoritesNode(Node node) {
89
        super(node, new Chldrn (node, false));
89
        super(node, new Chldrn (node, false));
90
    }
90
    }
91
91
Lines 125-132 Link Here
125
    public int indexOf(final Node node) {
125
    public int indexOf(final Node node) {
126
        Index ind = getOriginal().getCookie(Index.class);
126
        Index ind = getOriginal().getCookie(Index.class);
127
        if (ind != null) {
127
        if (ind != null) {
128
            if (node instanceof Favorites.ProjectFilterNode) {
128
            if (node instanceof FavoritesNode.ProjectFilterNode) {
129
                Favorites.ProjectFilterNode fn = (Favorites.ProjectFilterNode) node;
129
                FavoritesNode.ProjectFilterNode fn = (FavoritesNode.ProjectFilterNode) node;
130
                int i = ind.indexOf(fn.getOriginal());
130
                int i = ind.indexOf(fn.getOriginal());
131
                return i;
131
                return i;
132
            } else {
132
            } else {
Lines 238-244 Link Here
238
     */
238
     */
239
    public static synchronized Node getNode () {
239
    public static synchronized Node getNode () {
240
        if (node == null) {
240
        if (node == null) {
241
            node = new Favorites (getFolder().getNodeDelegate ());
241
            node = new FavoritesNode (getFolder().getNodeDelegate ());
242
        }
242
        }
243
        return node;
243
        return node;
244
    }
244
    }
Lines 282-288 Link Here
282
        /** Return a node for the current project.
282
        /** Return a node for the current project.
283
        */
283
        */
284
        public Node getNode () {
284
        public Node getNode () {
285
            return Favorites.getNode ();
285
            return FavoritesNode.getNode ();
286
        }
286
        }
287
    }
287
    }
288
288
Lines 368-374 Link Here
368
        @Override
368
        @Override
369
        public void setName(String name) {
369
        public void setName(String name) {
370
            // #113859 - keep order of children in favorites folder after rename
370
            // #113859 - keep order of children in favorites folder after rename
371
            final DataFolder favoritesFolder = Favorites.getFolder();
371
            final DataFolder favoritesFolder = FavoritesNode.getFolder();
372
            final DataObject[] children = favoritesFolder.getChildren();
372
            final DataObject[] children = favoritesFolder.getChildren();
373
            super.setName(name);
373
            super.setName(name);
374
            try {
374
            try {
Lines 381-392 Link Here
381
        @Override
381
        @Override
382
        public String getDisplayName () {
382
        public String getDisplayName () {
383
            //Change display name only for favorite nodes (links) under Favorites node.
383
            //Change display name only for favorite nodes (links) under Favorites node.
384
            if (Favorites.getNode().equals(this.getParentNode())) {
384
            if (FavoritesNode.getNode().equals(this.getParentNode())) {
385
                DataShadow ds = getCookie(DataShadow.class);
385
                DataShadow ds = getCookie(DataShadow.class);
386
                if (ds != null) {
386
                if (ds != null) {
387
                    String name = ds.getName();
387
                    String name = ds.getName();
388
                    String path = FileUtil.getFileDisplayName(ds.getOriginal().getPrimaryFile());
388
                    String path = FileUtil.getFileDisplayName(ds.getOriginal().getPrimaryFile());
389
                    return NbBundle.getMessage(Favorites.class, "CTL_DisplayNameTemplate", name, path);
389
                    return NbBundle.getMessage(FavoritesNode.class, "CTL_DisplayNameTemplate", name, path);
390
                } else {
390
                } else {
391
                    return super.getDisplayName();
391
                    return super.getDisplayName();
392
                }
392
                }
Lines 462-468 Link Here
462
            if (isRoot) {
462
            if (isRoot) {
463
                return createActionsForRoot(arr);
463
                return createActionsForRoot(arr);
464
            } else {
464
            } else {
465
                if (Favorites.getNode().equals(this.getParentNode())) {
465
                if (FavoritesNode.getNode().equals(this.getParentNode())) {
466
                    DataShadow ds = getCookie(DataShadow.class);
466
                    DataShadow ds = getCookie(DataShadow.class);
467
                    if (ds != null) {
467
                    if (ds != null) {
468
                        if (ds.getOriginal().getPrimaryFile().isFolder()) {
468
                        if (ds.getOriginal().getPrimaryFile().isFolder()) {
(-)a/favorites/src/org/netbeans/modules/favorites/Tab.java (-2 / +2 lines)
Lines 485-491 Link Here
485
    /** Exchanges deserialized root context to projects root context
485
    /** Exchanges deserialized root context to projects root context
486
    * to keep the uniquennes. */
486
    * to keep the uniquennes. */
487
    protected void validateRootContext () {
487
    protected void validateRootContext () {
488
        Node projectsRc = Favorites.getNode ();
488
        Node projectsRc = FavoritesNode.getNode ();
489
        setRootContext(projectsRc);
489
        setRootContext(projectsRc);
490
    }
490
    }
491
    
491
    
Lines 514-520 Link Here
514
514
515
            try {
515
            try {
516
                Node[] toShadows = new Node[] {DataObject.find(file).getNodeDelegate()};
516
                Node[] toShadows = new Node[] {DataObject.find(file).getNodeDelegate()};
517
                final DataFolder f = Favorites.getFolder();
517
                final DataFolder f = FavoritesNode.getFolder();
518
                final DataObject [] arr = f.getChildren();
518
                final DataObject [] arr = f.getChildren();
519
                final List<DataObject> listAdd = new ArrayList<DataObject>();
519
                final List<DataObject> listAdd = new ArrayList<DataObject>();
520
                DataObject createdDO = null;
520
                DataObject createdDO = null;
(-)a/favorites/src/org/netbeans/modules/favorites/api/Favorites.java (+223 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.favorites.api;
41
42
import java.io.IOException;
43
import java.util.ArrayList;
44
import java.util.Arrays;
45
import java.util.List;
46
import java.util.logging.Level;
47
import java.util.logging.Logger;
48
import org.netbeans.modules.favorites.Actions;
49
import org.netbeans.modules.favorites.FavoritesNode;
50
import org.openide.filesystems.FileObject;
51
import org.openide.loaders.DataFolder;
52
import org.openide.loaders.DataObject;
53
import org.openide.loaders.DataObjectNotFoundException;
54
import org.openide.loaders.DataShadow;
55
56
// TODO tests
57
/**
58
 * Singleton for access to Favorites.
59
 *
60
 * @author Richard Michalsky
61
 */
62
public final class Favorites {
63
    private static Favorites INSTANCE;
64
    private static Logger LOG = Logger.getLogger(Favorites.class.getName());
65
66
    /**
67
     * Returns a default instance of Favorites.
68
     * @return
69
     */
70
    public static Favorites getDefault() {
71
        if (INSTANCE == null)
72
            INSTANCE = new Favorites();
73
        return INSTANCE;
74
    }
75
76
    /**
77
     * Adds new files to Favorites.
78
     * File objects already present are silently ignored.
79
     * @param toAdd an array of file objects to be added to Favorites. May be empty, but not <code>null</code>.
80
     * @throws NullPointerException When <code>toAdd</code> array is <code>null</code> or contains <code>null</code> values.
81
     * @throws DataObjectNotFoundException When corresponding <code>DataObject</code> to one of the file objects could not be found.
82
     */
83
    public void addAll(FileObject[] toAdd)
84
            throws NullPointerException, DataObjectNotFoundException {
85
        if (toAdd.length == 0)
86
            return;
87
        add(toAdd);
88
    }
89
90
    /**
91
     * Adds new file to Favorites.
92
     * Does nothing if file is already present as root. When adding multiple
93
     * files at once, use {@link #addAll(FileObject[])}, which is more effective.
94
     * @param fo file objects to be added to Favorites
95
     * @return <code>true</code> when file was added, <code>false</code> otherwise.
96
     * @throws NullPointerException When parameter is <code>null</code>
97
     * @throws DataObjectNotFoundException When corresponding <code>DataObject</code> to the file object could not be found.
98
     * @see #selectWithAddition(org.openide.filesystems.FileObject)
99
     */
100
    public boolean add(FileObject fo) throws DataObjectNotFoundException, NullPointerException {
101
        return add(new FileObject[] { fo }).length == 1;
102
    }
103
104
    /**
105
     * Selects given file in Favorites view, adds it as root first if it is not already present.
106
     * @param fo file object to be selected and/or added if needed
107
     * @return <code>true</code> when file was also added, <code>false</code> when only selected.
108
     * @throws DataObjectNotFoundException When corresponding <code>DataObject</code> to the file object could not be found.
109
     * @see #add(org.openide.filesystems.FileObject)
110
     * @see #isInFavorites(org.openide.filesystems.FileObject)
111
     */
112
    public boolean selectWithAddition(FileObject fo) throws DataObjectNotFoundException {
113
        DataShadow obj = findShadow(fo);
114
        boolean result = false;
115
        if (obj == null) {
116
            obj = (add(new FileObject[] { fo }))[0];
117
            result = true;
118
        }
119
        Actions.Add.selectAfterAddition(obj);
120
        return result;
121
    }
122
123
    /**
124
     * Returns <code>true</code> if given file object is already in Favorites <b>as a root</b>,
125
     * i.e. descendants of root don't count.
126
     * @param fo File object to query.
127
     * @return
128
     */
129
    public boolean isInFavorites (FileObject fo) {
130
        return findShadow(fo) != null;
131
    }
132
133
    private DataShadow findShadow(FileObject fo) {
134
        DataFolder f = FavoritesNode.getFolder();
135
        DataObject [] arr = f.getChildren();
136
        for (int i = 0; i < arr.length; i++) {
137
            if (arr[i] instanceof DataShadow) {
138
                DataShadow obj = (DataShadow) arr[i];
139
                if (fo.equals(obj.getOriginal().getPrimaryFile())) {
140
                    return obj;
141
                }
142
            }
143
        }
144
        return null;
145
    }
146
147
    /**
148
     * Returns list of current root file objects in Favorites.
149
     * @return
150
     */
151
    public List<FileObject> getFavoriteRoots() {
152
        DataFolder f = FavoritesNode.getFolder();
153
        DataObject [] arr = f.getChildren();
154
        List<FileObject> ret = new ArrayList<FileObject>(arr.length);
155
156
        for (DataObject obj : arr) {
157
            if (obj instanceof DataShadow) {
158
                ret.add(((DataShadow) obj).getOriginal().getPrimaryFile());
159
            }
160
        }
161
        return ret;
162
    }
163
164
    /**
165
     * Removes given file objects from Favorites if they are found as roots.
166
     * @param toRemove An array of file objects to be removed.
167
     * @throws IOException When corresponding entry in userdir could not be deleted
168
     * @throws NullPointerException When <code>toRemove</code> is <code>null</code>
169
     */
170
    public void removeAll(FileObject[] toRemove) throws IOException, NullPointerException {
171
        DataFolder f = FavoritesNode.getFolder();
172
        DataObject [] arr = f.getChildren();
173
        for (DataObject obj : arr) {
174
            if (obj instanceof DataShadow) {
175
                FileObject root = ((DataShadow) obj).getOriginal().getPrimaryFile();
176
                for (FileObject rem : toRemove) {
177
                    if (rem.equals(root)) {
178
                        obj.delete();
179
                    }
180
                }
181
            }
182
        }
183
    }
184
185
    /**
186
     * Removes given file object from Favorites if it is present as root.
187
     * @param fo File object to be removed.
188
     * @throws IOException When corresponding entry in userdir could not be deleted
189
     * @throws NullPointerException When <code>fo</code> is <code>null</code>
190
     *
191
     */
192
    public void remove(FileObject fo) throws IOException, NullPointerException {
193
        if (fo == null)
194
            throw new NullPointerException("Parameter 'fo' is null.");
195
        removeAll(new FileObject[] { fo });
196
    }
197
198
    private DataShadow[] add(FileObject[] toAdd) throws DataObjectNotFoundException {
199
        final DataFolder f = FavoritesNode.getFolder();
200
        DataShadow[] createdDOs = createShadows(f, toAdd);
201
        //This is done to set desired order of nodes in view
202
        Actions.Add.reorderAfterAddition(f, f.getChildren(), Arrays.asList(createdDOs));
203
        return createdDOs;
204
    }
205
206
    private DataShadow[] createShadows(final DataFolder favorites, final FileObject[] toAdd) throws DataObjectNotFoundException, IllegalArgumentException {
207
        List<DataShadow> createdDO = new ArrayList<DataShadow>(toAdd.length);
208
        for (int i = 0; i < toAdd.length; i++) {
209
            if (!isInFavorites(toAdd[i])) {
210
                DataObject obj = DataObject.find(toAdd[i]);
211
                if (obj != null) {
212
                    try {
213
                        createdDO.add(obj.createShadow(favorites));
214
                    } catch (IOException ex) {
215
                        LOG.log(Level.WARNING, null, ex);
216
                    }
217
                }
218
            }
219
        }
220
        return createdDO.toArray(new DataShadow[createdDO.size()]);
221
    }
222
223
}
(-)a/favorites/src/org/netbeans/modules/favorites/resources/layer.xml (-1 / +1 lines)
Lines 105-111 Link Here
105
    <folder name="Favorites">
105
    <folder name="Favorites">
106
        <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.favorites.Bundle"/>
106
        <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.favorites.Bundle"/>
107
        <file name="Home.shadow">
107
        <file name="Home.shadow">
108
            <attr name="originalFile" methodvalue="org.netbeans.modules.favorites.Favorites.getHome"/>
108
            <attr name="originalFile" methodvalue="org.netbeans.modules.favorites.FavoritesNode.getHome"/>
109
            <attr name="originalFileSystem" stringvalue="org.netbeans.modules.masterfs.MasterFileSystem"/>
109
            <attr name="originalFileSystem" stringvalue="org.netbeans.modules.masterfs.MasterFileSystem"/>
110
        </file>
110
        </file>
111
    </folder>
111
    </folder>
(-)a/favorites/test/unit/src/org/netbeans/modules/favorites/IndexTest.java (-3 / +3 lines)
Lines 68-74 Link Here
68
    }
68
    }
69
    
69
    
70
    /**
70
    /**
71
     * Test basic functionality of Index on Favorites node.
71
     * Test basic functionality of Index on FavoritesNode node.
72
     */
72
     */
73
    public void testReorder () throws Exception {
73
    public void testReorder () throws Exception {
74
        FileObject folder = FileUtil.createFolder (
74
        FileObject folder = FileUtil.createFolder (
Lines 81-92 Link Here
81
        DataObject dObj1 = DataObject.find(fo1);
81
        DataObject dObj1 = DataObject.find(fo1);
82
        DataObject dObj2 = DataObject.find(fo2);
82
        DataObject dObj2 = DataObject.find(fo2);
83
        
83
        
84
        DataFolder favorites = Favorites.getFolder();
84
        DataFolder favorites = FavoritesNode.getFolder();
85
        
85
        
86
        dObj1.createShadow(favorites);
86
        dObj1.createShadow(favorites);
87
        dObj2.createShadow(favorites);
87
        dObj2.createShadow(favorites);
88
        
88
        
89
        Node n = Favorites.getNode();
89
        Node n = FavoritesNode.getNode();
90
        
90
        
91
        Node n1 = n.getChildren().findChild("Test1");
91
        Node n1 = n.getChildren().findChild("Test1");
92
        assertNotNull("Node must exist", n1);
92
        assertNotNull("Node must exist", n1);
(-)a/favorites/test/unit/src/org/netbeans/modules/favorites/NodesTest.java (-2 / +2 lines)
Lines 74-80 Link Here
74
    }
74
    }
75
    
75
    
76
    public void testNoneOfTheNodesHaveShadowLinks () throws Exception {
76
    public void testNoneOfTheNodesHaveShadowLinks () throws Exception {
77
        doCheckDepth (Favorites.getNode (), 1);
77
        doCheckDepth (FavoritesNode.getNode (), 1);
78
    }
78
    }
79
    
79
    
80
    private void doCheckDepth (Node node, int depth) throws Exception {
80
    private void doCheckDepth (Node node, int depth) throws Exception {
Lines 87-93 Link Here
87
        Action remove = Actions.remove();
87
        Action remove = Actions.remove();
88
        
88
        
89
        for (int i = 0; i < arr.length; i++) {
89
        for (int i = 0; i < arr.length; i++) {
90
            File f = Favorites.fileForNode(arr[i]);
90
            File f = FavoritesNode.fileForNode(arr[i]);
91
            //First level (link) has action remove
91
            //First level (link) has action remove
92
            //Further level has action add
92
            //Further level has action add
93
            Collection set = Arrays.asList (arr[i].getActions(false));
93
            Collection set = Arrays.asList (arr[i].getActions(false));
(-)a/favorites/test/unit/src/org/netbeans/modules/favorites/RootsTest.java (-6 / +6 lines)
Lines 100-109 Link Here
100
            }
100
            }
101
        }
101
        }
102
        
102
        
103
        Node[] arr = Favorites.getNode ().getChildren ().getNodes (true);
103
        Node[] arr = FavoritesNode.getNode ().getChildren ().getNodes (true);
104
        
104
        
105
        for (int i = 0; i < arr.length; i++) {
105
        for (int i = 0; i < arr.length; i++) {
106
            File f = Favorites.fileForNode (arr[i]);
106
            File f = FavoritesNode.fileForNode (arr[i]);
107
            if (f != null) {
107
            if (f != null) {
108
                roots.remove (f);
108
                roots.remove (f);
109
            }
109
            }
Lines 120-126 Link Here
120
    }*/
120
    }*/
121
    
121
    
122
    public void testLinkToHomeDirIsThere () throws Exception {
122
    public void testLinkToHomeDirIsThere () throws Exception {
123
        Node[] arr = Favorites.getNode ().getChildren ().getNodes (true);
123
        Node[] arr = FavoritesNode.getNode ().getChildren ().getNodes (true);
124
        
124
        
125
        File home = new File (System.getProperty("user.home")).getCanonicalFile();
125
        File home = new File (System.getProperty("user.home")).getCanonicalFile();
126
126
Lines 150-163 Link Here
150
    public void testNodesUnderRootRepresentTheirFiles () throws Exception {
150
    public void testNodesUnderRootRepresentTheirFiles () throws Exception {
151
        HashSet<File> roots = new HashSet<File>(Arrays.asList (File.listRoots()));
151
        HashSet<File> roots = new HashSet<File>(Arrays.asList (File.listRoots()));
152
        
152
        
153
        Node[] arr = Favorites.getNode ().getChildren ().getNodes (true);
153
        Node[] arr = FavoritesNode.getNode ().getChildren ().getNodes (true);
154
        
154
        
155
        for (int i = 0; i < arr.length; i++) {
155
        for (int i = 0; i < arr.length; i++) {
156
            File f = Favorites.fileForNode (arr[i]);
156
            File f = FavoritesNode.fileForNode (arr[i]);
157
            if (roots.remove (f)) {
157
            if (roots.remove (f)) {
158
                Node[] nexts = arr[i].getChildren().getNodes (true);
158
                Node[] nexts = arr[i].getChildren().getNodes (true);
159
                for (int j = 0; j < nexts.length; j++) {
159
                for (int j = 0; j < nexts.length; j++) {
160
                    File file = Favorites.fileForNode (nexts[i]);
160
                    File file = FavoritesNode.fileForNode (nexts[i]);
161
                    assertNotNull ("For node: " + nexts[i] + " there has to be file", file);
161
                    assertNotNull ("For node: " + nexts[i] + " there has to be file", file);
162
                    assertEquals ("Correct parent for " + nexts[i], f, file.getParentFile());
162
                    assertEquals ("Correct parent for " + nexts[i], f, file.getParentFile());
163
                }
163
                }
(-)a/favorites/test/unit/src/org/netbeans/modules/favorites/VisibilityQueryWorksTest.java (-3 / +3 lines)
Lines 164-176 Link Here
164
    }
164
    }
165
    
165
    
166
    public void testLinksAreVisibleAllTheTime() throws Exception {
166
    public void testLinksAreVisibleAllTheTime() throws Exception {
167
        Node[] arr = Favorites.getNode().getChildren().getNodes(true);
167
        Node[] arr = FavoritesNode.getNode().getChildren().getNodes(true);
168
        assertNodeForDataObject("hidden object is there", hiddenDO, true, arr);
168
        assertNodeForDataObject("hidden object is there", hiddenDO, true, arr);
169
        assertNodeForDataObject("folder as well", folderDO, true, arr);
169
        assertNodeForDataObject("folder as well", folderDO, true, arr);
170
    }
170
    }
171
171
172
    public void testHiddenFilesInFoldersAreHidden() throws Exception {
172
    public void testHiddenFilesInFoldersAreHidden() throws Exception {
173
        Node[] arr = Favorites.getNode().getChildren().getNodes(true);
173
        Node[] arr = FavoritesNode.getNode().getChildren().getNodes(true);
174
        Node f = assertNodeForDataObject("folder as well", folderDO, true, arr);
174
        Node f = assertNodeForDataObject("folder as well", folderDO, true, arr);
175
        
175
        
176
        arr = f.getChildren().getNodes(true);
176
        arr = f.getChildren().getNodes(true);
Lines 201-207 Link Here
201
    }
201
    }
202
    
202
    
203
    private void doCopyOrCut(boolean copy) throws Exception {
203
    private void doCopyOrCut(boolean copy) throws Exception {
204
        Node[] arr = Favorites.getNode().getChildren().getNodes(true);
204
        Node[] arr = FavoritesNode.getNode().getChildren().getNodes(true);
205
        Node f = assertNodeForDataObject("folder is there ", rootDO, true, arr);
205
        Node f = assertNodeForDataObject("folder is there ", rootDO, true, arr);
206
        arr = f.getChildren().getNodes(true);
206
        arr = f.getChildren().getNodes(true);
207
        f = assertNodeForDataObject("folder is there ", folderDO, true, arr);
207
        f = assertNodeForDataObject("folder is there ", folderDO, true, arr);

Return to bug 164996