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

(-)a/api.search/src/org/netbeans/modules/search/MatchingObject.java (-4 / +16 lines)
Lines 89-94 Link Here
89
    public static final String PROP_INVALIDITY_STATUS =
89
    public static final String PROP_INVALIDITY_STATUS =
90
            "invalidityStatus";                                         //NOI18N
90
            "invalidityStatus";                                         //NOI18N
91
    public static final String PROP_SELECTED = "selected";              //NOI18N
91
    public static final String PROP_SELECTED = "selected";              //NOI18N
92
    public static final String PROP_REMOVED = "removed";                //NOI18N
92
93
93
    /** */
94
    /** */
94
    private static final Logger LOG =
95
    private static final Logger LOG =
Lines 535-548 Link Here
535
536
536
        List<Node> detailNodes = new ArrayList<Node>(textDetails.size());
537
        List<Node> detailNodes = new ArrayList<Node>(textDetails.size());
537
        for (TextDetail txtDetail : textDetails) {
538
        for (TextDetail txtDetail : textDetails) {
538
            detailNodes.add(new TextDetail.DetailNode(txtDetail, false));
539
            detailNodes.add(
540
                    new TextDetail.DetailNode(txtDetail, false, resultModel));
539
        }
541
        }
540
542
541
        return detailNodes.toArray(new Node[detailNodes.size()]);
543
        return detailNodes.toArray(new Node[detailNodes.size()]);
542
    }
544
    }
543
545
544
    public Children getDetailsChildren(boolean replacing) {
546
    public Children getDetailsChildren(boolean replacing) {
545
        return new DetailsChildren(replacing);
547
        return new DetailsChildren(replacing, resultModel);
546
    }
548
    }
547
549
548
    /**
550
    /**
Lines 990-995 Link Here
990
    }
992
    }
991
993
992
    /**
994
    /**
995
     * Remove this matching object from its result model and inform listeners.
996
     */
997
    public void remove() {
998
        resultModel.remove(this);
999
        changeSupport.firePropertyChange(PROP_REMOVED, null, null);
1000
    }
1001
1002
    /**
993
     * Bridge between new API and legacy implementation, will be deleted.
1003
     * Bridge between new API and legacy implementation, will be deleted.
994
     */
1004
     */
995
    public static class Def {
1005
    public static class Def {
Lines 1032-1046 Link Here
1032
    private class DetailsChildren extends Children.Keys<TextDetail> {
1042
    private class DetailsChildren extends Children.Keys<TextDetail> {
1033
1043
1034
        private boolean replacing;
1044
        private boolean replacing;
1045
        private final ResultModel model;
1035
1046
1036
        public DetailsChildren(boolean replacing) {
1047
        public DetailsChildren(boolean replacing, ResultModel model) {
1037
            this.replacing = replacing;
1048
            this.replacing = replacing;
1038
            setKeys(getTextDetails());
1049
            setKeys(getTextDetails());
1050
            this.model = model;
1039
        }
1051
        }
1040
1052
1041
        @Override
1053
        @Override
1042
        protected Node[] createNodes(TextDetail key) {
1054
        protected Node[] createNodes(TextDetail key) {
1043
            return new Node[]{new TextDetail.DetailNode(key, replacing)};
1055
            return new Node[]{new TextDetail.DetailNode(key, replacing, model)};
1044
        }
1056
        }
1045
    }
1057
    }
1046
1058
(-)a/api.search/src/org/netbeans/modules/search/ResultModel.java (-1 / +57 lines)
Lines 48-54 Link Here
48
import java.beans.PropertyChangeListener;
48
import java.beans.PropertyChangeListener;
49
import java.beans.PropertyChangeSupport;
49
import java.beans.PropertyChangeSupport;
50
import java.nio.charset.Charset;
50
import java.nio.charset.Charset;
51
import java.util.Arrays;
51
import java.util.List;
52
import java.util.List;
53
import java.util.logging.Level;
54
import java.util.logging.Logger;
52
import javax.swing.event.ChangeEvent;
55
import javax.swing.event.ChangeEvent;
53
import javax.swing.event.ChangeListener;
56
import javax.swing.event.ChangeListener;
54
import org.netbeans.modules.search.Constants.Limit;
57
import org.netbeans.modules.search.Constants.Limit;
Lines 64-70 Link Here
64
 * @author  Marian Petras
67
 * @author  Marian Petras
65
 */
68
 */
66
public final class ResultModel {
69
public final class ResultModel {
67
70
    private static final Logger LOG =
71
            Logger.getLogger(ResultModel.class.getName());
72
    public static final String PROP_REMOVED = "remove";                 //NOI18N
73
    public static final String PROP_REMOVEDDETAIL = "removeDetail";     //NOI18N
68
    public static final String PROP_SELECTION = "selection";            //NOI18N
74
    public static final String PROP_SELECTION = "selection";            //NOI18N
69
    public static final String PROP_VALID = "valid";                    //NOI18N
75
    public static final String PROP_VALID = "valid";                    //NOI18N
70
    public static final String PROP_MATCHING_OBJECTS =
76
    public static final String PROP_MATCHING_OBJECTS =
Lines 115-120 Link Here
115
	isFullText = (basicCriteria != null) && basicCriteria.isFullText();        
121
	isFullText = (basicCriteria != null) && basicCriteria.isFullText();        
116
        startTime = -1;
122
        startTime = -1;
117
    }
123
    }
124
125
    /**
126
     * Remove the {@link MatchingObject} from the model and informs the
127
     * listeners.
128
     *
129
     * @param mo Matching object to remove.
130
     */
131
    public synchronized void remove(MatchingObject mo) {
132
        if (matchingObjects.remove(mo)) {
133
            totalDetailsCount -= getDetailsCount(mo);
134
            int deselected = 0;
135
            if (mo.getTextDetails() != null) {
136
                for (TextDetail td : mo.getTextDetails()) {
137
                    deselected += td.isSelected() ? -1 : 0;
138
                }
139
            }
140
            mo.cleanup();
141
            // inform listeners, old object contains removed object
142
            propertyChangeSupport.firePropertyChange(PROP_REMOVED,
143
                    Arrays.asList(mo), null);
144
            if (deselected < 0) {
145
                updateSelected(deselected);
146
            }
147
        }
148
    }
149
150
    public void removeDetailMatch(TextDetail txtDetail) {
151
        MatchingObject found = getMatchingObjectFor(txtDetail);
152
        LOG.log(Level.FINE, "Found {0}", found);                        //NOI18N
153
        if (null != found && found.textDetails.remove(txtDetail)) {
154
            totalDetailsCount--;
155
            if (found.textDetails.isEmpty()) {
156
                remove(found);
157
            } else {
158
                propertyChangeSupport.firePropertyChange(PROP_REMOVEDDETAIL,
159
                        Arrays.asList(txtDetail), null);
160
            }
161
        }
162
    }
163
164
    private MatchingObject getMatchingObjectFor(TextDetail txtDetail) {
165
        for (MatchingObject mo : matchingObjects) {
166
            for (TextDetail textDetail : mo.getTextDetails()) {
167
                if (textDetail == txtDetail) {
168
                    return mo;
169
                }
170
            }
171
        }
172
        return null;
173
    }
118
    
174
    
119
    /**
175
    /**
120
     */
176
     */
(-)a/api.search/src/org/netbeans/modules/search/TextDetail.java (-2 / +17 lines)
Lines 50-55 Link Here
50
import java.awt.datatransfer.Transferable;
50
import java.awt.datatransfer.Transferable;
51
import java.awt.event.ActionEvent;
51
import java.awt.event.ActionEvent;
52
import java.io.CharConversionException;
52
import java.io.CharConversionException;
53
import java.io.IOException;
53
import java.util.List;
54
import java.util.List;
54
import java.util.logging.Level;
55
import java.util.logging.Level;
55
import java.util.logging.Logger;
56
import java.util.logging.Logger;
Lines 451-456 Link Here
451
        /** Cached toString value. */
452
        /** Cached toString value. */
452
        private String name;
453
        private String name;
453
        private String htmlDisplayName;
454
        private String htmlDisplayName;
455
        private final ResultModel model;
454
        
456
        
455
        /**
457
        /**
456
         * Constructs a node representing the specified information about
458
         * Constructs a node representing the specified information about
Lines 458-468 Link Here
458
         *
460
         *
459
         * @param txtDetail  information to be represented by this node
461
         * @param txtDetail  information to be represented by this node
460
         */
462
         */
461
        public DetailNode(TextDetail txtDetail, boolean replacing) {
463
        public DetailNode(TextDetail txtDetail, boolean replacing,
464
                ResultModel model) {
462
            super(Children.LEAF, Lookups.fixed(txtDetail,
465
            super(Children.LEAF, Lookups.fixed(txtDetail,
463
                    new ReplaceCheckableNode(txtDetail, replacing)));
466
                    new ReplaceCheckableNode(txtDetail, replacing)));
464
            
467
            
465
            this.txtDetail = txtDetail;
468
            this.txtDetail = txtDetail;
469
            this.model = model;
466
            
470
            
467
            setValue(SearchDisplayer.ATTR_OUTPUT_LINE,
471
            setValue(SearchDisplayer.ATTR_OUTPUT_LINE,
468
                     DetailNode.getFullDesc(txtDetail));
472
                     DetailNode.getFullDesc(txtDetail));
Lines 475-481 Link Here
475
                @Override
479
                @Override
476
                public void stateChanged(ChangeEvent e) {
480
                public void stateChanged(ChangeEvent e) {
477
                    fireIconChange();
481
                    fireIconChange();
478
                    ResultsOutlineSupport.toggleParentSelected(DetailNode.this);
482
                    ResultsOutlineSupport.toggleParentSelected(
483
                            DetailNode.this.getParentNode());
479
                }
484
                }
480
            });
485
            });
481
            setIconBaseWithExtension(ICON);
486
            setIconBaseWithExtension(ICON);
Lines 823-828 Link Here
823
        protected void createPasteTypes(Transferable t, List<PasteType> s) {
828
        protected void createPasteTypes(Transferable t, List<PasteType> s) {
824
        }
829
        }
825
        
830
        
831
        @Override
832
        public boolean canDestroy() {
833
            return true;
834
        }
835
836
        @Override
837
        public void destroy() throws IOException {
838
            this.model.removeDetailMatch(txtDetail);
839
//            super.destroy();
840
        }
826
    } // End of DetailNode class.
841
    } // End of DetailNode class.
827
842
828
    /**
843
    /**
(-)a/api.search/src/org/netbeans/modules/search/ui/AbstractSearchResultsPanel.java (+6 lines)
Lines 126-131 Link Here
126
        this.searchProviderPresenter = searchProviderPresenter;
126
        this.searchProviderPresenter = searchProviderPresenter;
127
        initComponents();
127
        initComponents();
128
        explorerManager = new ExplorerManager();
128
        explorerManager = new ExplorerManager();
129
130
        ActionMap map = this.getActionMap();
131
        // map delete key to delete action
132
        map.put("delete", //NOI18N
133
                ExplorerUtils.actionDelete(explorerManager, false));
134
129
        lookup = ExplorerUtils.createLookup(explorerManager,
135
        lookup = ExplorerUtils.createLookup(explorerManager,
130
                ResultView.getInstance().getActionMap());
136
                ResultView.getInstance().getActionMap());
131
        initActions();
137
        initActions();
(-)a/api.search/src/org/netbeans/modules/search/ui/BasicAbstractResultsPanel.java (-1 / +10 lines)
Lines 45-50 Link Here
45
import java.awt.EventQueue;
45
import java.awt.EventQueue;
46
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionListener;
47
import java.awt.event.ActionListener;
48
import java.beans.PropertyChangeEvent;
49
import java.beans.PropertyChangeListener;
48
import java.beans.PropertyVetoException;
50
import java.beans.PropertyVetoException;
49
import java.util.ResourceBundle;
51
import java.util.ResourceBundle;
50
import javax.accessibility.AccessibleContext;
52
import javax.accessibility.AccessibleContext;
Lines 74-80 Link Here
74
 * @author jhavlin
76
 * @author jhavlin
75
 */
77
 */
76
public abstract class BasicAbstractResultsPanel
78
public abstract class BasicAbstractResultsPanel
77
        extends AbstractSearchResultsPanel {
79
        extends AbstractSearchResultsPanel implements PropertyChangeListener {
78
80
79
    @StaticResource
81
    @StaticResource
80
    private static final String SHOW_DETAILS_ICON =
82
    private static final String SHOW_DETAILS_ICON =
Lines 120-127 Link Here
120
        setRootDisplayName(NbBundle.getMessage(ResultView.class,
122
        setRootDisplayName(NbBundle.getMessage(ResultView.class,
121
                "TEXT_SEARCHING___"));                                  //NOI18N
123
                "TEXT_SEARCHING___"));                                  //NOI18N
122
        initAccessibility();
124
        initAccessibility();
125
        this.resultModel.addPropertyChangeListener(
126
                ResultModel.PROP_REMOVED, this);
123
    }
127
    }
124
128
129
    @Override
130
    public void propertyChange (PropertyChangeEvent evt) {
131
        // update the root node after change in model
132
        setFinalRootNodeText();
133
    }
125
134
126
    public void update() {
135
    public void update() {
127
        if (details && btnExpand.isVisible() && !btnExpand.isEnabled()) {
136
        if (details && btnExpand.isVisible() && !btnExpand.isEnabled()) {
(-)a/api.search/src/org/netbeans/modules/search/ui/HideResultAction.java (+79 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.search.ui;
43
44
import java.awt.event.ActionEvent;
45
import org.openide.actions.DeleteAction;
46
import org.openide.util.HelpCtx;
47
import org.openide.util.NbBundle;
48
import org.openide.util.actions.CallbackSystemAction;
49
import org.openide.util.actions.SystemAction;
50
51
/**
52
 *
53
 * @author jhavlin
54
 */
55
@NbBundle.Messages({"HideResultAction.displayName=Hide"})
56
public class HideResultAction extends CallbackSystemAction {
57
58
    CallbackSystemAction delegate = SystemAction.get(DeleteAction.class);
59
60
    @Override
61
    public void actionPerformed(ActionEvent e) {
62
        delegate.actionPerformed(e);
63
    }
64
65
    @Override
66
    public String getName() {
67
        return Bundle.HideResultAction_displayName();
68
    }
69
70
    @Override
71
    public HelpCtx getHelpCtx() {
72
        return delegate.getHelpCtx();
73
    }
74
75
    @Override
76
    public boolean isEnabled() {
77
        return true;
78
    }
79
}
(-)a/api.search/src/org/netbeans/modules/search/ui/MatchingObjectNode.java (-7 / +14 lines)
Lines 59-64 Link Here
59
import org.netbeans.api.annotations.common.StaticResource;
59
import org.netbeans.api.annotations.common.StaticResource;
60
import org.netbeans.modules.search.MatchingObject;
60
import org.netbeans.modules.search.MatchingObject;
61
import org.netbeans.modules.search.MatchingObject.InvalidityStatus;
61
import org.netbeans.modules.search.MatchingObject.InvalidityStatus;
62
import org.openide.actions.DeleteAction;
62
import org.openide.filesystems.FileObject;
63
import org.openide.filesystems.FileObject;
63
import org.openide.filesystems.FileUtil;
64
import org.openide.filesystems.FileUtil;
64
import org.openide.loaders.DataObject;
65
import org.openide.loaders.DataObject;
Lines 103-110 Link Here
103
    PropertySet[] propertySets;
104
    PropertySet[] propertySets;
104
105
105
    public MatchingObjectNode(Node original,
106
    public MatchingObjectNode(Node original,
106
            org.openide.nodes.Children children,
107
            org.openide.nodes.Children children, MatchingObject matchingObject,
107
            MatchingObject matchingObject, final boolean replacing) {
108
            final boolean replacing) {
108
        this(original, children, matchingObject,
109
        this(original, children, matchingObject,
109
                new ReplaceCheckableNode(matchingObject, replacing));
110
                new ReplaceCheckableNode(matchingObject, replacing));
110
    }
111
    }
Lines 130-137 Link Here
130
                MatchingObject.PROP_INVALIDITY_STATUS,
131
                MatchingObject.PROP_INVALIDITY_STATUS,
131
                validityListener);
132
                validityListener);
132
        selectionListener = new SelectionListener();
133
        selectionListener = new SelectionListener();
133
        matchingObject.addPropertyChangeListener(MatchingObject.PROP_SELECTED,
134
        matchingObject.addPropertyChangeListener(selectionListener);
134
                selectionListener);
135
    }
135
    }
136
136
137
    @Override
137
    @Override
Lines 165-171 Link Here
165
        if (!context) {
165
        if (!context) {
166
            return new Action[]{
166
            return new Action[]{
167
                        SystemAction.get(OpenMatchingObjectsAction.class),
167
                        SystemAction.get(OpenMatchingObjectsAction.class),
168
                        new CopyPathAction()
168
                        new CopyPathAction(),
169
                        SystemAction.get(HideResultAction.class)
169
                    };
170
                    };
170
        } else {
171
        } else {
171
            return new Action[0];
172
            return new Action[0];
Lines 234-240 Link Here
234
235
235
    @Override
236
    @Override
236
    public boolean canDestroy() {
237
    public boolean canDestroy() {
237
        return false;
238
        return true;
238
    }
239
    }
239
240
240
    public void clean() {
241
    public void clean() {
Lines 274-279 Link Here
274
        return propertySets;
275
        return propertySets;
275
    }
276
    }
276
277
278
    @Override
279
    public void destroy () throws IOException {
280
        // when removing the node, the node's content is removed from model
281
        this.matchingObject.remove();
282
    }
283
277
    /**
284
    /**
278
     * Check whether the file object is valid and a valid data object can be
285
     * Check whether the file object is valid and a valid data object can be
279
     * found for it. It should be checked after original node is destroyed. It
286
     * found for it. It should be checked after original node is destroyed. It
Lines 443-449 Link Here
443
450
444
            fireIconChange();
451
            fireIconChange();
445
            ResultsOutlineSupport.toggleParentSelected(
452
            ResultsOutlineSupport.toggleParentSelected(
446
                    MatchingObjectNode.this);
453
                    MatchingObjectNode.this.getParentNode());
447
        }
454
        }
448
    }
455
    }
449
}
456
}
(-)a/api.search/src/org/netbeans/modules/search/ui/ResultsOutlineSupport.java (-16 / +81 lines)
Lines 88-93 Link Here
88
import org.openide.nodes.Node;
88
import org.openide.nodes.Node;
89
import org.openide.util.Exceptions;
89
import org.openide.util.Exceptions;
90
import org.openide.util.ImageUtilities;
90
import org.openide.util.ImageUtilities;
91
import org.openide.util.actions.SystemAction;
91
import org.openide.util.datatransfer.PasteType;
92
import org.openide.util.datatransfer.PasteType;
92
import org.openide.util.lookup.Lookups;
93
import org.openide.util.lookup.Lookups;
93
94
Lines 125-131 Link Here
125
        this.details = details;
126
        this.details = details;
126
        this.resultModel = resultModel;
127
        this.resultModel = resultModel;
127
        this.basicComposition = basicComposition;
128
        this.basicComposition = basicComposition;
128
        this.resultsNode = new ResultsNode();
129
        this.resultsNode = new ResultsNode(resultModel);
129
        this.infoNode = infoNode;
130
        this.infoNode = infoNode;
130
        this.invisibleRoot = new RootNode(resultsNode, infoNode);
131
        this.invisibleRoot = new RootNode(resultsNode, infoNode);
131
        this.matchingObjectNodes = new LinkedList<MatchingObjectNode>();
132
        this.matchingObjectNodes = new LinkedList<MatchingObjectNode>();
Lines 312-321 Link Here
312
        private FolderTreeChildren folderTreeChildren;
313
        private FolderTreeChildren folderTreeChildren;
313
        private String htmlDisplayName = null;
314
        private String htmlDisplayName = null;
314
315
315
        public ResultsNode() {
316
        public ResultsNode(ResultModel model) {
316
            super(new FlatChildren());
317
            super(new FlatChildren());
317
            this.flatChildren = (FlatChildren) this.getChildren();
318
            this.flatChildren = (FlatChildren) this.getChildren();
318
            this.folderTreeChildren = new FolderTreeChildren(rootPathItem);
319
            this.folderTreeChildren =
320
                    new FolderTreeChildren(rootPathItem);
319
        }
321
        }
320
322
321
        void update() {
323
        void update() {
Lines 387-392 Link Here
387
     */
389
     */
388
    private class FlatChildren extends Children.Keys<MatchingObject> {
390
    private class FlatChildren extends Children.Keys<MatchingObject> {
389
391
392
        public FlatChildren() {
393
            resultModel.addPropertyChangeListener(ResultModel.PROP_REMOVED,
394
                    new PropertyChangeListener() {
395
                @Override
396
                public void propertyChange(PropertyChangeEvent evt) {
397
                    update();
398
                }
399
            });
400
        }
401
390
        @Override
402
        @Override
391
        protected Node[] createNodes(MatchingObject key) {
403
        protected Node[] createNodes(MatchingObject key) {
392
            return new Node[]{createNodeForMatchingObject(key)};
404
            return new Node[]{createNodeForMatchingObject(key)};
Lines 412-419 Link Here
412
        } else {
424
        } else {
413
            children = key.getDetailsChildren(replacing);
425
            children = key.getDetailsChildren(replacing);
414
        }
426
        }
415
        MatchingObjectNode mon =
427
        MatchingObjectNode mon = new MatchingObjectNode(
416
                new MatchingObjectNode(delegate, children, key, replacing);
428
                delegate, children, key, replacing);
417
        synchronized (this) {
429
        synchronized (this) {
418
            if (!closed) {
430
            if (!closed) {
419
                matchingObjectNodes.add(mon);
431
                matchingObjectNodes.add(mon);
Lines 479-489 Link Here
479
                    return;
491
                    return;
480
                }
492
                }
481
            }
493
            }
482
            parentItem.addChild(new FolderTreeItem(matchingObject));
494
            parentItem.addChild(new FolderTreeItem(matchingObject, parentItem));
483
        } else {
495
        } else {
484
            try {
496
            try {
485
                FolderTreeItem newChild = new FolderTreeItem(
497
                FolderTreeItem newChild = new FolderTreeItem(
486
                        DataObject.find(path.get(0)));
498
                        DataObject.find(path.get(0)), parentItem);
487
                parentItem.addChild(newChild);
499
                parentItem.addChild(newChild);
488
                createInTreeView(newChild, path.subList(1, path.size()),
500
                createInTreeView(newChild, path.subList(1, path.size()),
489
                        matchingObject);
501
                        matchingObject);
Lines 497-516 Link Here
497
509
498
        private static final String PROP_SELECTED = "selected";         //NOI18N
510
        private static final String PROP_SELECTED = "selected";         //NOI18N
499
        private static final String PROP_CHILDREN = "children";         //NOI18N
511
        private static final String PROP_CHILDREN = "children";         //NOI18N
512
        private FolderTreeItem parent;
500
        private DataObject folder = null;
513
        private DataObject folder = null;
501
        private MatchingObject matchingObject = null;
514
        private MatchingObject matchingObject = null;
502
        private List<FolderTreeItem> children =
515
        private List<FolderTreeItem> children =
503
                new LinkedList<FolderTreeItem>();
516
                new LinkedList<FolderTreeItem>();
504
        private boolean selected = true;
517
        private boolean selected = true;
518
        private boolean removed = false;
505
        PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
519
        PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
506
520
507
        /**
521
        /**
508
         * Constructor for root node
522
         * Constructor for root node
509
         */
523
         */
510
        public FolderTreeItem() {
524
        public FolderTreeItem() {
525
            this.parent = null;
511
        }
526
        }
512
527
513
        public FolderTreeItem(MatchingObject matchingObject) {
528
        public FolderTreeItem(MatchingObject matchingObject,
529
                FolderTreeItem parent) {
530
            this.parent = parent;
514
            this.matchingObject = matchingObject;
531
            this.matchingObject = matchingObject;
515
            matchingObject.addPropertyChangeListener(
532
            matchingObject.addPropertyChangeListener(
516
                    new PropertyChangeListener() {
533
                    new PropertyChangeListener() {
Lines 520-535 Link Here
520
                    if (pn.equals(MatchingObject.PROP_SELECTED)) {
537
                    if (pn.equals(MatchingObject.PROP_SELECTED)) {
521
                        setSelected(FolderTreeItem.this.matchingObject
538
                        setSelected(FolderTreeItem.this.matchingObject
522
                                .isSelected());
539
                                .isSelected());
540
                    } else if (pn.equals(MatchingObject.PROP_REMOVED)) {
541
                        remove();
523
                    }
542
                    }
524
                }
543
                }
525
            });
544
            });
526
        }
545
        }
527
546
528
        public FolderTreeItem(DataObject file) {
547
        public FolderTreeItem(DataObject file, FolderTreeItem parent) {
548
            this.parent = parent;
529
            this.folder = file;
549
            this.folder = file;
530
        }
550
        }
531
551
532
        void addChild(FolderTreeItem pathItem) {
552
        synchronized void addChild(FolderTreeItem pathItem) {
533
            children.add(pathItem);
553
            children.add(pathItem);
534
            firePropertyChange(PROP_CHILDREN, null, null);
554
            firePropertyChange(PROP_CHILDREN, null, null);
535
        }
555
        }
Lines 538-545 Link Here
538
            return folder;
558
            return folder;
539
        }
559
        }
540
560
541
        public List<FolderTreeItem> getChildren() {
561
        public synchronized List<FolderTreeItem> getChildren() {
542
            return children;
562
            return new ArrayList<FolderTreeItem>(children);
563
        }
564
565
        public synchronized void remove() {
566
            removed = true;
567
            for (FolderTreeItem fti : children) {
568
                if (fti.isPathLeaf()) {
569
                    fti.getMatchingObject().remove();
570
                } else {
571
                    fti.remove();
572
                }
573
            }
574
            if (parent != null) {
575
                parent.removeChild(this);
576
            }
577
        }
578
579
        private synchronized boolean removeChild(FolderTreeItem child) {
580
            if (!removed) { // needed to prevent ConcurrentModificationException
581
                boolean result = children.remove(child);
582
                if (children.isEmpty() && parent != null) {
583
                    remove();
584
                } else {
585
                    firePropertyChange(PROP_CHILDREN, null, null);
586
                }
587
                return result;
588
            } else {
589
                return false;
590
            }
543
        }
591
        }
544
592
545
        public MatchingObject getMatchingObject() {
593
        public MatchingObject getMatchingObject() {
Lines 607-613 Link Here
607
                @Override
655
                @Override
608
                public void propertyChange(PropertyChangeEvent evt) {
656
                public void propertyChange(PropertyChangeEvent evt) {
609
                    fireIconChange();
657
                    fireIconChange();
610
                    toggleParentSelected(FolderTreeNode.this);
658
                    String prop = evt.getPropertyName();
659
                    if (prop.equals(FolderTreeItem.PROP_SELECTED)) {
660
                        toggleParentSelected(
661
                                FolderTreeNode.this.getParentNode());
662
                    } else if (prop.equals(FolderTreeItem.PROP_CHILDREN)) {
663
                        toggleParentSelected(FolderTreeNode.this);
664
                    }
611
                }
665
                }
612
            });
666
            });
613
            if (!pathItem.isPathLeaf()) {
667
            if (!pathItem.isPathLeaf()) {
Lines 627-639 Link Here
627
        }
681
        }
628
682
629
        @Override
683
        @Override
684
        public boolean canDestroy () {
685
            return true;
686
        }
687
688
        @Override
689
        public void destroy () throws IOException {
690
            FolderTreeItem folder =
691
                    this.getLookup().lookup(FolderTreeItem.class);
692
            folder.remove();
693
        }
694
695
        @Override
630
        public Transferable drag() throws IOException {
696
        public Transferable drag() throws IOException {
631
            return UiUtils.DISABLE_TRANSFER;
697
            return UiUtils.DISABLE_TRANSFER;
632
        }
698
        }
633
699
634
        @Override
700
        @Override
635
        public Action[] getActions(boolean context) {
701
        public Action[] getActions(boolean context) {
636
            return new Action[0];
702
            return new Action[]{SystemAction.get(HideResultAction.class)};
637
        }
703
        }
638
    }
704
    }
639
705
Lines 675-682 Link Here
675
        }
741
        }
676
    }
742
    }
677
743
678
    public static void toggleParentSelected(Node node) {
744
    public static void toggleParentSelected(Node parent) {
679
        Node parent = node.getParentNode();
680
        if (parent == null) {
745
        if (parent == null) {
681
            return;
746
            return;
682
        }
747
        }
(-)a/api.search/test/unit/src/org/netbeans/modules/search/TextDetailTest.java (-1 / +1 lines)
Lines 144-150 Link Here
144
144
145
    public String createHtmlDisplayName(String line, String match) {
145
    public String createHtmlDisplayName(String line, String match) {
146
        TextDetail td = createMockTextDetail(line, match);
146
        TextDetail td = createMockTextDetail(line, match);
147
        DetailNode detailNode = new TextDetail.DetailNode(td, false);
147
        DetailNode detailNode = new TextDetail.DetailNode(td, false, null);
148
        String htmlDisplayName = detailNode.getHtmlDisplayName();
148
        String htmlDisplayName = detailNode.getHtmlDisplayName();
149
        Pattern p = Pattern.compile("(<html><font .*>\\s*\\d+: </font>)(.*?)(\\s+<font .*>\\[.*\\]</font></html>)");
149
        Pattern p = Pattern.compile("(<html><font .*>\\s*\\d+: </font>)(.*?)(\\s+<font .*>\\[.*\\]</font></html>)");
150
        Matcher m = p.matcher(htmlDisplayName);
150
        Matcher m = p.matcher(htmlDisplayName);

Return to bug 200020