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

(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/impl/Bundle.properties (-2 / +3 lines)
Lines 78-85 Link Here
78
LBL_InReadOnlyFile=Error: this occurrence is in a read-only file and cannot be refactored.
78
LBL_InReadOnlyFile=Error: this occurrence is in a read-only file and cannot be refactored.
79
LBL_CannotRefactorGuardedBlock=Read-only block of text cannot be refactored.
79
LBL_CannotRefactorGuardedBlock=Read-only block of text cannot be refactored.
80
LBL_CannotRefactorReadOnlyFile=Read-only files cannot be refactored.
80
LBL_CannotRefactorReadOnlyFile=Read-only files cannot be refactored.
81
LBL_Occurence=occurrence
81
# "There {0,choice,0#are no files|1#is one file|1<are {0,number,integer} files}."
82
LBL_Occurences=occurrences
82
LBL_Occurences={0,choice,0#no occurrences|1#1 occurrence|1<{0,number,integer} occurrences}
83
LBL_OccurencesApproximate=about {0,choice,1#1 occurrence|1<{0,number,integer} occurrences}
83
LBL_Errors=errors
84
LBL_Errors=errors
84
LBL_Hidden=filtered
85
LBL_Hidden=filtered
85
LBL_UsagesWindow=&Find Usages Results
86
LBL_UsagesWindow=&Find Usages Results
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/impl/CheckNode.java (-1 / +52 lines)
Lines 44-59 Link Here
44
package org.netbeans.modules.refactoring.spi.impl;
44
package org.netbeans.modules.refactoring.spi.impl;
45
45
46
import java.io.IOException;
46
import java.io.IOException;
47
import java.util.ArrayList;
47
import java.util.Enumeration;
48
import java.util.Enumeration;
49
import java.util.List;
48
import javax.swing.Icon;
50
import javax.swing.Icon;
51
import javax.swing.SwingUtilities;
49
import javax.swing.tree.*;
52
import javax.swing.tree.*;
50
import org.netbeans.modules.refactoring.spi.ui.TreeElement;
53
import org.netbeans.modules.refactoring.spi.ui.TreeElement;
51
import org.openide.text.PositionBounds;
54
import org.openide.text.PositionBounds;
52
import org.netbeans.modules.refactoring.api.RefactoringElement;
55
import org.netbeans.modules.refactoring.api.RefactoringElement;
56
import org.netbeans.modules.refactoring.spi.ui.ExpandableTreeElement;
53
import org.openide.filesystems.FileObject;
57
import org.openide.filesystems.FileObject;
54
import org.openide.filesystems.FileUtil;
58
import org.openide.filesystems.FileUtil;
55
import org.openide.util.ImageUtilities;
59
import org.openide.util.ImageUtilities;
56
import org.openide.util.NbBundle;
60
import org.openide.util.NbBundle;
61
import org.openide.util.NbCollections;
62
import org.openide.util.RequestProcessor;
57
63
58
/**
64
/**
59
 * @author Pavel Flaska
65
 * @author Pavel Flaska
Lines 65-70 Link Here
65
  
71
  
66
    private int selectionMode;
72
    private int selectionMode;
67
    private boolean isSelected;
73
    private boolean isSelected;
74
    private boolean isQuery;
68
75
69
    private String nodeLabel;
76
    private String nodeLabel;
70
    private Icon icon;
77
    private Icon icon;
Lines 74-82 Link Here
74
    private static Icon found = ImageUtilities.loadImageIcon("org/netbeans/modules/refactoring/api/resources/found_item_orange.png", false);
81
    private static Icon found = ImageUtilities.loadImageIcon("org/netbeans/modules/refactoring/api/resources/found_item_orange.png", false);
75
    
82
    
76
    public CheckNode(Object userObject, String nodeLabel, Icon icon, boolean isQuery) {
83
    public CheckNode(Object userObject, String nodeLabel, Icon icon, boolean isQuery) {
77
        super(userObject, !(userObject instanceof RefactoringElement));
84
        super(userObject, !(userObject instanceof RefactoringElement) || userObject instanceof ExpandableTreeElement);
78
        this.isSelected = true;
85
        this.isSelected = true;
79
        setSelectionMode(DIG_IN_SELECTION);
86
        setSelectionMode(DIG_IN_SELECTION);
87
        this.isQuery = isQuery;
80
        this.nodeLabel = nodeLabel;
88
        this.nodeLabel = nodeLabel;
81
        this.icon = icon;
89
        this.icon = icon;
82
        if (userObject instanceof TreeElement) {
90
        if (userObject instanceof TreeElement) {
Lines 108-113 Link Here
108
                }
116
                }
109
            }
117
            }
110
        }
118
        }
119
120
        if (userObject instanceof ExpandableTreeElement) {
121
            add(new CheckNode("Please wait", "Please wait...", null, isQuery));
122
        }
111
    }
123
    }
112
    
124
    
113
    String getLabel() {
125
    String getLabel() {
Lines 218-221 Link Here
218
        }
230
        }
219
        return l + ":&nbsp;&nbsp;"; //NOI18N
231
        return l + ":&nbsp;&nbsp;"; //NOI18N
220
    }
232
    }
233
    
234
    private static final RequestProcessor WORKER = new RequestProcessor(CheckNode.class.getName(), 1, true, false);
235
    private boolean childrenFilled;
236
    
237
    public synchronized void ensureChildrenFilled(final DefaultTreeModel model) {
238
        if (!childrenFilled) {
239
            childrenFilled = true;
240
241
            if (userObject instanceof ExpandableTreeElement) {
242
                WORKER.post(new Runnable() {
243
                    @Override public void run() {
244
                        final List<TreeElement> subelements = new ArrayList<TreeElement>();
245
                        
246
                        for (TreeElement el : ((ExpandableTreeElement) userObject)) {
247
                            subelements.add(el);
248
                        }
249
250
                        SwingUtilities.invokeLater(new Runnable() {
251
                            @Override public void run() {
252
                                for (TreeElement el : subelements) {
253
                                    insert(new CheckNode(el, el.getText(/*XXX:*/true), el.getIcon(), isQuery), getChildCount() - 1);
254
                                }
255
                                int[] added = new int[getChildCount() - 1];
256
                                for (int i = 0; i < added.length; i++) {
257
                                    added[i] = i;
258
                                }
259
                                model.nodesWereInserted(CheckNode.this, added);
260
                                int childCount = getChildCount();
261
                                Object last = getChildAt(childCount - 1);
262
                                int index = model.getIndexOfChild(CheckNode.this, last);
263
                                remove(index); //remove the please wait node
264
                                model.nodesWereRemoved(CheckNode.this, new int[] {index}, new Object[] {last});
265
                            }
266
                        });
267
                    }
268
                });
269
            }
270
        }
271
    }
221
}
272
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/impl/DelegatingCustomScopeProvider.java (+146 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.refactoring.spi.impl;
43
44
import java.util.Map;
45
import java.util.concurrent.atomic.AtomicBoolean;
46
import javax.swing.Icon;
47
import org.netbeans.modules.refactoring.api.Scope;
48
import org.netbeans.modules.refactoring.spi.ui.ScopeProvider;
49
import org.openide.util.ImageUtilities;
50
import org.openide.util.Lookup;
51
52
public class DelegatingCustomScopeProvider extends ScopeProvider.CustomScopeProvider implements DelegatingScopeInformation{
53
54
    private final Map<?, ?> map;
55
    private final String id;
56
    private final String displayName;
57
    private final int position;
58
    private Icon icon;
59
    private CustomScopeProvider delegate;
60
61
    public static DelegatingCustomScopeProvider create(Map<?, ?> map) {
62
        return new DelegatingCustomScopeProvider(map);
63
    }
64
65
    public DelegatingCustomScopeProvider(CustomScopeProvider delegate, String id, String displayName, int position, Icon image) {
66
        this.icon = image;
67
        this.id = id;
68
        this.displayName = displayName;
69
        this.position = position;
70
        this.delegate = delegate;
71
        map = null;
72
    }
73
74
    private DelegatingCustomScopeProvider(Map<?, ?> map) {
75
        this.map = map;
76
        String path = (String) map.get("iconBase"); //NOI18N
77
        icon = path != null && !path.equals("") ? ImageUtilities.loadImageIcon(path, false) : null;
78
        id = (String) map.get("id"); //NOI18N
79
        displayName = (String) map.get("displayName"); //NOI18N
80
        position = (Integer) map.get("position"); //NOI18N
81
    }
82
83
    public CustomScopeProvider getDelegate() {
84
        if (delegate == null) {
85
            assert map != null;
86
            delegate = (CustomScopeProvider) map.get("delegate"); // NOI18N
87
        }
88
        return delegate;
89
    }
90
    
91
    @Override
92
    public boolean initialize(Lookup context, AtomicBoolean cancel) {
93
        ScopeProvider d = getDelegate();
94
        return d != null ? d.initialize(context, cancel) : null;
95
    }
96
97
    @Override
98
    public Scope getScope() {
99
        ScopeProvider d = getDelegate();
100
        return d != null ? d.getScope() : null;
101
    }
102
    
103
    @Override
104
    public Icon getIcon() {
105
        Icon delegateIcon = null;
106
        ScopeProvider d = getDelegate();
107
        if(d != null) {
108
            delegateIcon = d.getIcon();
109
        }
110
        return delegateIcon == null? icon : delegateIcon;
111
    }
112
113
    @Override
114
    public String getDisplayName() {
115
        String detail = null;
116
        ScopeProvider d = getDelegate();
117
        if(d != null) {
118
            detail = d.getDetail();
119
        }
120
        return detail == null? displayName : displayName + " (" + detail + ")";
121
    }
122
123
    @Override
124
    public void setScope(Scope currentScope) {
125
        CustomScopeProvider d = getDelegate();
126
        if(d != null) {
127
            d.setScope(currentScope);
128
        }
129
    }
130
131
    @Override
132
    public boolean showCustomizer() {
133
        CustomScopeProvider d = getDelegate();
134
        return d != null ? d.showCustomizer() : null;
135
    }
136
137
    @Override
138
    public int getPosition() {
139
        return position;
140
    }
141
142
    @Override
143
    public String getId() {
144
        return id;
145
    }
146
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/impl/DelegatingScopeInformation.java (+68 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.refactoring.spi.impl;
43
44
import java.util.concurrent.atomic.AtomicBoolean;
45
import javax.swing.Icon;
46
import org.netbeans.modules.refactoring.api.Scope;
47
import org.openide.util.Lookup;
48
49
/**
50
 *
51
 * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
52
 */
53
public interface DelegatingScopeInformation {
54
55
    public String getDisplayName();
56
    
57
    public int getPosition();
58
59
    public String getId();
60
61
    public String getDetail();
62
63
    public Icon getIcon();
64
65
    public boolean initialize(Lookup context, AtomicBoolean cancel);
66
67
    public Scope getScope();
68
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/impl/DelegatingScopeProvider.java (+132 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.refactoring.spi.impl;
43
44
import java.util.Map;
45
import java.util.concurrent.atomic.AtomicBoolean;
46
import javax.swing.Icon;
47
import org.netbeans.modules.refactoring.api.Scope;
48
import org.netbeans.modules.refactoring.spi.ui.ScopeProvider;
49
import org.openide.util.ImageUtilities;
50
import org.openide.util.Lookup;
51
52
public class DelegatingScopeProvider extends ScopeProvider implements DelegatingScopeInformation {
53
54
    private final Map<?, ?> map;
55
    private final String id;
56
    private final String displayName;
57
    private final int position;
58
    private Icon icon;
59
    private ScopeProvider delegate;
60
61
    public static DelegatingScopeProvider create(Map<?, ?> map) {
62
        return new DelegatingScopeProvider(map);
63
    }
64
65
    public DelegatingScopeProvider(ScopeProvider delegate, String id, String displayName, int position, Icon image) {
66
        this.icon = image;
67
        this.id = id;
68
        this.displayName = displayName;
69
        this.position = position;
70
        this.delegate = delegate;
71
        map = null;
72
    }
73
74
    private DelegatingScopeProvider(Map<?, ?> map) {
75
        this.map = map;
76
        String path = (String) map.get("iconBase"); //NOI18N
77
        icon = path != null && !path.equals("") ? ImageUtilities.loadImageIcon(path, false) : null;
78
        id = (String) map.get("id"); //NOI18N
79
        displayName = (String) map.get("displayName"); //NOI18N
80
        position = (Integer) map.get("position"); //NOI18N
81
    }
82
83
    public ScopeProvider getDelegate() {
84
        if (delegate == null) {
85
            assert map != null;
86
            delegate = (ScopeProvider) map.get("delegate"); // NOI18N
87
        }
88
        return delegate;
89
    }
90
    
91
    @Override
92
    public boolean initialize(Lookup context, AtomicBoolean cancel) {
93
        ScopeProvider d = getDelegate();
94
        return d != null ? d.initialize(context, cancel) : null;
95
    }
96
97
    @Override
98
    public Scope getScope() {
99
        ScopeProvider d = getDelegate();
100
        return d != null ? d.getScope() : null;
101
    }
102
    
103
    @Override
104
    public Icon getIcon() {
105
        Icon delegateIcon = null;
106
        ScopeProvider d = getDelegate();
107
        if(d != null) {
108
            delegateIcon = d.getIcon();
109
        }
110
        return delegateIcon == null? icon : delegateIcon;
111
    }
112
113
    @Override
114
    public String getDisplayName() {
115
        String detail = null;
116
        ScopeProvider d = getDelegate();
117
        if(d != null) {
118
            detail = d.getDetail();
119
        }
120
        return detail == null? displayName : displayName + " (" + detail + ")";
121
    }
122
123
    @Override
124
    public int getPosition() {
125
        return position;
126
    }
127
128
    @Override
129
    public String getId() {
130
        return id;
131
    }
132
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/impl/RefactoringPanel.java (-12 / +32 lines)
Lines 63-72 Link Here
63
import java.util.prefs.Preferences;
63
import java.util.prefs.Preferences;
64
import javax.swing.*;
64
import javax.swing.*;
65
import javax.swing.border.EmptyBorder;
65
import javax.swing.border.EmptyBorder;
66
import javax.swing.event.TreeExpansionEvent;
67
import javax.swing.event.TreeWillExpandListener;
66
import javax.swing.event.ChangeEvent;
68
import javax.swing.event.ChangeEvent;
67
import javax.swing.text.html.HTMLEditorKit;
69
import javax.swing.text.html.HTMLEditorKit;
68
import javax.swing.text.html.parser.ParserDelegator;
70
import javax.swing.text.html.parser.ParserDelegator;
69
import javax.swing.tree.DefaultTreeModel;
71
import javax.swing.tree.DefaultTreeModel;
72
import javax.swing.tree.ExpandVetoException;
70
import javax.swing.tree.TreeNode;
73
import javax.swing.tree.TreeNode;
71
import javax.swing.tree.TreePath;
74
import javax.swing.tree.TreePath;
72
import org.netbeans.api.progress.ProgressHandle;
75
import org.netbeans.api.progress.ProgressHandle;
Lines 75-80 Link Here
75
import org.netbeans.modules.parsing.api.indexing.IndexingManager;
78
import org.netbeans.modules.parsing.api.indexing.IndexingManager;
76
import org.netbeans.modules.refactoring.api.*;
79
import org.netbeans.modules.refactoring.api.*;
77
import org.netbeans.modules.refactoring.api.impl.APIAccessor;
80
import org.netbeans.modules.refactoring.api.impl.APIAccessor;
81
import org.netbeans.modules.refactoring.spi.ui.ExpandableTreeElement;
78
import org.netbeans.modules.refactoring.spi.ui.FiltersDescription;
82
import org.netbeans.modules.refactoring.spi.ui.FiltersDescription;
79
import org.netbeans.modules.refactoring.spi.ui.RefactoringCustomUI;
83
import org.netbeans.modules.refactoring.spi.ui.RefactoringCustomUI;
80
import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
84
import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
Lines 699-704 Link Here
699
        final RefactoringPanelContainer cont = isQuery ? RefactoringPanelContainer.getUsagesComponent() : RefactoringPanelContainer.getRefactoringComponent();
703
        final RefactoringPanelContainer cont = isQuery ? RefactoringPanelContainer.getUsagesComponent() : RefactoringPanelContainer.getRefactoringComponent();
700
        cont.makeBusy(true);
704
        cont.makeBusy(true);
701
        final AtomicInteger size = new AtomicInteger();
705
        final AtomicInteger size = new AtomicInteger();
706
        final AtomicBoolean sizeIsApproximate = new AtomicBoolean();
702
        initialize();
707
        initialize();
703
        if(showParametersPanel) {
708
        if(showParametersPanel) {
704
            updateFilters();
709
            updateFilters();
Lines 749-756 Link Here
749
                            }
754
                            }
750
                        }
755
                        }
751
                    }
756
                    }
752
                    StringBuffer errorsDesc = getErrorDesc(errorsNum, isQuery?size.get():elements.size(), 0);
757
                    StringBuffer errorsDesc = getErrorDesc(errorsNum, isQuery?size.get():elements.size(), 0, isQuery && sizeIsApproximate.get());
753
                    final CheckNode root = new CheckNode(ui, description + errorsDesc.toString() + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",ImageUtilities.loadImageIcon("org/netbeans/modules/refactoring/api/resources/" + (isQuery ? "findusages.png" : "refactoring.gif"), false), isQuery);
758
                    final CheckNode root = new CheckNode(ui, description + errorsDesc.toString() + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",ImageUtilities.loadImageIcon("org/netbeans/modules/refactoring/api/resources/" + (isQuery ? "findusages.png" : "refactoring.gif"), false), isQuery);
754
                    final Map<Object, CheckNode> nodes = new HashMap<Object, CheckNode>();
759
                    final Map<Object, CheckNode> nodes = new HashMap<Object, CheckNode>();
755
                    
760
                    
756
                    if (isQuery && showParametersPanel) {
761
                    if (isQuery && showParametersPanel) {
Lines 773-786 Link Here
773
                            // ui.getRefactoring().setClassPath();
778
                            // ui.getRefactoring().setClassPath();
774
                            for (Iterator it = elements.iterator(); it.hasNext();i++) {
779
                            for (Iterator it = elements.iterator(); it.hasNext();i++) {
775
                                final RefactoringElement e = (RefactoringElement) it.next();
780
                                final RefactoringElement e = (RefactoringElement) it.next();
781
                                TreeElement treeElement = null;
776
                                if(e.include(filtersManager)) {
782
                                if(e.include(filtersManager)) {
777
                                    createNode(TreeElementFactory.getTreeElement(e), nodes, root);
783
                                    treeElement = TreeElementFactory.getTreeElement(e);
784
                                    createNode(treeElement, nodes, root);
778
                                } else {
785
                                } else {
779
                                    hidden++;
786
                                    hidden++;
780
                                }
787
                                }
781
                                final int occurrences = i + 1;
788
                                final int occurrences = i + (treeElement instanceof ExpandableTreeElement ? ((ExpandableTreeElement) treeElement).estimateChildCount() : 1);
782
                                final int hiddenOccurrences = hidden;
789
                                final int hiddenOccurrences = hidden;
783
                                size.set(occurrences);
790
                                size.set(occurrences);
791
                                sizeIsApproximate.compareAndSet(false, treeElement instanceof ExpandableTreeElement);
784
                                if (isQuery && showParametersPanel) {
792
                                if (isQuery && showParametersPanel) {
785
                                    if (cancelRequest.get()) {
793
                                    if (cancelRequest.get()) {
786
                                        break;
794
                                        break;
Lines 791-797 Link Here
791
                                        SwingUtilities.invokeLater(new Runnable() {
799
                                        SwingUtilities.invokeLater(new Runnable() {
792
                                            @Override
800
                                            @Override
793
                                            public void run() {
801
                                            public void run() {
794
                                                root.setNodeLabel(description + getErrorDesc(0, occurrences, hiddenOccurrences));
802
                                                root.setNodeLabel(description + getErrorDesc(0, occurrences, hiddenOccurrences, isQuery && sizeIsApproximate.get()));
795
                                                if (last) {
803
                                                if (last) {
796
                                                    tree.repaint();
804
                                                    tree.repaint();
797
                                                }
805
                                                }
Lines 838-856 Link Here
838
                    }
846
                    }
839
                    
847
                    
840
                    if (!(isQuery && showParametersPanel)) {
848
                    if (!(isQuery && showParametersPanel)) {
841
                        root.setNodeLabel(description + getErrorDesc(errorsNum, isQuery ? size.get() : elements.size(), hidden).toString());
849
                        root.setNodeLabel(description + getErrorDesc(errorsNum, isQuery ? size.get() : elements.size(), hidden, isQuery && sizeIsApproximate.get()).toString());
842
                        setupTree(root, showParametersPanel, elements.size());
850
                        setupTree(root, showParametersPanel, elements.size());
843
                    }
851
                    }
844
                    
852
                    
845
                }
853
                }
846
854
847
                private StringBuffer getErrorDesc(int errorsNum, int occurencesNum, int hiddenNum) throws MissingResourceException {
855
                private StringBuffer getErrorDesc(int errorsNum, int occurencesNum, int hiddenNum, boolean occurencesNumApproximate) throws MissingResourceException {
848
                    StringBuffer errorsDesc = new StringBuffer();
856
                    StringBuffer errorsDesc = new StringBuffer();
849
                    errorsDesc.append(" [").append(occurencesNum); // NOI18N
857
                    errorsDesc.append(" ["); // NOI18N
850
                    errorsDesc.append(' ');
858
                    errorsDesc.append(occurencesNumApproximate ?
851
                    errorsDesc.append(occurencesNum == 1 ?
859
                        NbBundle.getMessage(RefactoringPanel.class, "LBL_OccurencesApproximate", occurencesNum) :
852
                        NbBundle.getMessage(RefactoringPanel.class, "LBL_Occurence") :
860
                        NbBundle.getMessage(RefactoringPanel.class, "LBL_Occurences", occurencesNum)
853
                        NbBundle.getMessage(RefactoringPanel.class, "LBL_Occurences")
854
                        );
861
                        );
855
                    if (errorsNum > 0) {
862
                    if (errorsNum > 0) {
856
                        errorsDesc.append(',');
863
                        errorsDesc.append(',');
Lines 1003-1008 Link Here
1003
            tree.setModel(new DefaultTreeModel(root));
1010
            tree.setModel(new DefaultTreeModel(root));
1004
        }
1011
        }
1005
        tree.setRowHeight((int) ((CheckRenderer) tree.getCellRenderer()).getPreferredSize().getHeight());
1012
        tree.setRowHeight((int) ((CheckRenderer) tree.getCellRenderer()).getPreferredSize().getHeight());
1013
1014
        this.tree.addTreeWillExpandListener(new TreeWillExpandListener() {
1015
            @Override public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
1016
                Object last = event.getPath().getLastPathComponent();
1017
1018
                if (last instanceof CheckNode) {
1019
                    ((CheckNode) last).ensureChildrenFilled((DefaultTreeModel) RefactoringPanel.this.tree.getModel());
1020
                }
1021
            }
1022
1023
            @Override public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { }
1024
        });
1006
    }
1025
    }
1007
1026
1008
    private void setupInstantTree(final CheckNode root, final boolean showParametersPanel) {
1027
    private void setupInstantTree(final CheckNode root, final boolean showParametersPanel) {
Lines 1236-1241 Link Here
1236
    
1255
    
1237
    protected void closeNotify() {
1256
    protected void closeNotify() {
1238
        if (fuListener!=null) {
1257
        if (fuListener!=null) {
1258
            stopSearch();
1239
            ui.getRefactoring().removeProgressListener(fuListener);
1259
            ui.getRefactoring().removeProgressListener(fuListener);
1240
        }
1260
        }
1241
        timeStamps.clear();
1261
        timeStamps.clear();
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/impl/ScopeAnnotationProcessor.java (+159 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.refactoring.spi.impl;
43
44
import java.util.Set;
45
import javax.annotation.processing.Processor;
46
import javax.annotation.processing.RoundEnvironment;
47
import javax.annotation.processing.SupportedAnnotationTypes;
48
import javax.annotation.processing.SupportedSourceVersion;
49
import javax.lang.model.SourceVersion;
50
import javax.lang.model.element.Element;
51
import javax.lang.model.element.TypeElement;
52
import javax.lang.model.type.TypeMirror;
53
import javax.lang.model.util.Types;
54
import javax.tools.Diagnostic;
55
import org.netbeans.modules.refactoring.spi.ui.ScopeProvider;
56
import org.netbeans.modules.refactoring.spi.ui.ScopeReference;
57
import org.netbeans.modules.refactoring.spi.ui.ScopeReferences;
58
import org.openide.filesystems.annotations.LayerBuilder;
59
import org.openide.filesystems.annotations.LayerGeneratingProcessor;
60
import org.openide.filesystems.annotations.LayerGenerationException;
61
import org.openide.util.lookup.ServiceProvider;
62
63
/**
64
 *
65
 * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
66
 */
67
@SupportedSourceVersion(SourceVersion.RELEASE_6)
68
@SupportedAnnotationTypes({"org.netbeans.modules.refactoring.spi.ui.ScopeDescription",
69
"org.netbeans.modules.refactoring.spi.ui.ScopeReference",
70
"org.netbeans.modules.refactoring.spi.ui.ScopeReferences"})
71
@ServiceProvider(service = Processor.class)
72
public class ScopeAnnotationProcessor extends LayerGeneratingProcessor {
73
74
    @Override
75
    protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws LayerGenerationException {
76
        if (!roundEnv.processingOver()) {
77
            generateTypeList(roundEnv);
78
        }
79
80
        return false;
81
    }
82
83
    private void generateTypeList(RoundEnvironment roundEnv) throws LayerGenerationException {
84
        TypeElement scopeRegistration = processingEnv.getElementUtils().getTypeElement("org.netbeans.modules.refactoring.spi.ui.ScopeProvider.Registration");
85
        TypeElement scopeReference = processingEnv.getElementUtils().getTypeElement("org.netbeans.modules.refactoring.spi.ui.ScopeReference");
86
        TypeElement scopeReferences = processingEnv.getElementUtils().getTypeElement("org.netbeans.modules.refactoring.spi.ui.ScopeReferences");
87
        TypeMirror customProvider = processingEnv.getElementUtils().getTypeElement("org.netbeans.modules.refactoring.spi.ui.ScopeProvider.CustomScopeProvider").asType();
88
        TypeMirror provider = processingEnv.getElementUtils().getTypeElement("org.netbeans.modules.refactoring.spi.ui.ScopeProvider").asType();
89
        if (scopeRegistration == null || scopeReference == null || scopeReferences == null) {
90
            return;
91
        }
92
        Types typeUtils = processingEnv.getTypeUtils();
93
94
        for (Element annotated : roundEnv.getElementsAnnotatedWith(scopeRegistration)) {
95
            boolean custom;
96
            if (typeUtils.isSubtype(annotated.asType(), customProvider)) {
97
                custom = true;
98
            } else if (typeUtils.isSubtype(annotated.asType(), provider)) {
99
                custom = false;
100
            } else {
101
                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, ERR_SUPER_TYPE, annotated);
102
                continue;
103
            }
104
            ScopeProvider.Registration ar = annotated.getAnnotation(ScopeProvider.Registration.class);
105
            LayerBuilder builder = layer(annotated);
106
            LayerBuilder.File f = builder.file("Scopes/ScopeDescriptions/" + ar.id() + ".instance");
107
            f.bundlevalue("displayName", ar.displayName(), ar, "displayName");
108
            f.stringvalue("id", ar.id());
109
            f.stringvalue("iconBase", ar.iconBase());
110
            f.intvalue("position", ar.position());
111
            f.newvalue("delegate", getFQN((TypeElement) annotated));
112
            
113
            if (custom) {
114
                f.stringvalue("instanceClass", "org.netbeans.modules.refactoring.spi.ui.CustomScopeProvider");
115
                f.methodvalue("instanceCreate", "org.netbeans.modules.refactoring.spi.impl.DelegatingCustomScopeProvider", "create");
116
            } else {
117
                f.stringvalue("instanceClass", "org.netbeans.modules.refactoring.spi.ui.ScopeProvider");
118
                f.methodvalue("instanceCreate", "org.netbeans.modules.refactoring.spi.impl.DelegatingScopeProvider", "create");
119
            }
120
            f.write();
121
        }
122
        for (Element annotated : roundEnv.getElementsAnnotatedWith(ScopeReferences.class)) {
123
            final LayerBuilder builder = layer(annotated);
124
            ScopeReferences refs = annotated.getAnnotation(ScopeReferences.class);
125
            if (refs == null) {
126
                continue;
127
            }
128
            for (ScopeReference ar : refs.value()) {
129
                processReference(ar, annotated, builder);
130
            }
131
        }
132
133
        for (Element annotated : roundEnv.getElementsAnnotatedWith(scopeReference)) {
134
            ScopeReference ar = annotated.getAnnotation(ScopeReference.class);
135
            processReference(ar, annotated, layer(annotated));
136
        }
137
    }
138
    private static final String ERR_SUPER_TYPE = "The class must extend org.netbeans.modules.refactoring.api.AbstractAnnotatedRefactoring";
139
    private static final String ERR_ID_NEEDED = "This annotation needs to be used together with ScopeDescription, or you need to specify the id.";
140
141
    private String getFQN(TypeElement clazz) {
142
        return processingEnv.getElementUtils().getBinaryName(clazz).toString();
143
    }
144
145
    private void processReference(ScopeReference ar, Element annotated, LayerBuilder builder) {
146
        String id = ar.id();
147
        if (id.isEmpty()) {
148
            ScopeProvider.Registration desc = annotated.getAnnotation(ScopeProvider.Registration.class);
149
            if (desc == null) {
150
                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, ERR_ID_NEEDED, annotated);
151
            } else {
152
                id = desc.id();
153
            }
154
        }
155
        LayerBuilder.File f = builder.file("Scopes/" + ar.path() + "/" + id + ".shadow");
156
        f.stringvalue("originalFile", "Scopes/ScopeDescriptions/" + id + ".instance");
157
        f.write();
158
    }
159
}
(-)a/refactoring.java/nbproject/project.xml (-1 / +1 lines)
Lines 185-191 Link Here
185
                    <build-prerequisite/>
185
                    <build-prerequisite/>
186
                    <compile-dependency/>
186
                    <compile-dependency/>
187
                    <run-dependency>
187
                    <run-dependency>
188
                        <specification-version>1.29</specification-version>
188
                        <specification-version>1.30</specification-version>
189
                    </run-dependency>
189
                    </run-dependency>
190
                </dependency>
190
                </dependency>
191
                <dependency>
191
                <dependency>
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/api/ui/JavaScopeBuilder.java (-1 / +1 lines)
Lines 45-51 Link Here
45
import java.awt.event.ActionListener;
45
import java.awt.event.ActionListener;
46
import java.util.concurrent.atomic.AtomicBoolean;
46
import java.util.concurrent.atomic.AtomicBoolean;
47
import org.netbeans.modules.refactoring.api.Scope;
47
import org.netbeans.modules.refactoring.api.Scope;
48
import org.netbeans.modules.refactoring.java.ui.CustomScopePanel;
48
import org.netbeans.modules.refactoring.java.ui.scope.CustomScopePanel;
49
import org.openide.DialogDescriptor;
49
import org.openide.DialogDescriptor;
50
import org.openide.DialogDisplayer;
50
import org.openide.DialogDisplayer;
51
import org.openide.util.HelpCtx;
51
import org.openide.util.HelpCtx;
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/Bundle.properties (-9 / +1 lines)
Lines 49-60 Link Here
49
LBL_IntroduceParameter=Introduce Parameter
49
LBL_IntroduceParameter=Introduce Parameter
50
50
51
DSC_Rename=Rename <b>{0}</b> to <b>{1}</b>
51
DSC_Rename=Rename <b>{0}</b> to <b>{1}</b>
52
LBL_CustomScope=Custom Scope...
53
DLG_CustomScope=Custom Scope
54
LBL_CurrentFile=Current File ({0})
55
LBL_CurrentPackage=Current Package ({0})
56
LBL_CurrentProject=Current Project ({0})
57
LBL_WaitNode=Please Wait...
58
52
59
LBL_EncapsulateFieldsAction=Encapsula&te Fields...
53
LBL_EncapsulateFieldsAction=Encapsula&te Fields...
60
LBL_EncapsulateFields=Encapsulate Fields
54
LBL_EncapsulateFields=Encapsulate Fields
Lines 418-426 Link Here
418
412
419
LBL_chngsigdecl=Change {0} parameters of {1}
413
LBL_chngsigdecl=Change {0} parameters of {1}
420
414
421
LBL_Scope=Sco&pe\: 
422
LBL_AllProjects=Open Projects
423
424
ExtractSuperclassPanel.nameLabel.AccessibleContext.accessibleDescription=N/A
415
ExtractSuperclassPanel.nameLabel.AccessibleContext.accessibleDescription=N/A
425
416
426
ExtractSuperclassPanel.chooseLabel.AccessibleContext.accessibleDescription=N/A
417
ExtractSuperclassPanel.chooseLabel.AccessibleContext.accessibleDescription=N/A
Lines 496-498 Link Here
496
ReplaceConstructorWithBuilder.jLabel1.text=&Builder Class Name:
487
ReplaceConstructorWithBuilder.jLabel1.text=&Builder Class Name:
497
ReplaceConstructorWithBuilderName=Replace Constructor With Builder
488
ReplaceConstructorWithBuilderName=Replace Constructor With Builder
498
ReplaceConstructorWithBuilderDescription=Replace Constructor {0} with Builder {1}
489
ReplaceConstructorWithBuilderDescription=Replace Constructor {0} with Builder {1}
490
WhereUsedPanel.jLabel1.text=Sco&pe:
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/WhereUsedPanel.form (-74 / +27 lines)
Lines 20-112 Link Here
20
  <Layout>
20
  <Layout>
21
    <DimensionLayout dim="0">
21
    <DimensionLayout dim="0">
22
      <Group type="103" groupAlignment="0" attributes="0">
22
      <Group type="103" groupAlignment="0" attributes="0">
23
          <Component id="scopePanel" max="32767" attributes="0"/>
23
          <Component id="innerPanel" max="32767" attributes="0"/>
24
          <Component id="innerPanel" pref="361" max="32767" attributes="0"/>
24
          <Group type="102" alignment="1" attributes="0">
25
              <EmptySpace max="-2" attributes="0"/>
26
              <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
27
              <EmptySpace max="-2" attributes="0"/>
28
              <Component id="scope" pref="487" max="32767" attributes="0"/>
29
              <EmptySpace max="-2" attributes="0"/>
30
          </Group>
25
      </Group>
31
      </Group>
26
    </DimensionLayout>
32
    </DimensionLayout>
27
    <DimensionLayout dim="1">
33
    <DimensionLayout dim="1">
28
      <Group type="103" groupAlignment="0" attributes="0">
34
      <Group type="103" groupAlignment="0" attributes="0">
29
          <Group type="102" alignment="0" attributes="0">
35
          <Group type="102" alignment="0" attributes="0">
30
              <Component id="innerPanel" pref="45" max="32767" attributes="0"/>
36
              <Component id="innerPanel" pref="169" max="32767" attributes="0"/>
31
              <EmptySpace min="-2" max="-2" attributes="0"/>
37
              <EmptySpace max="-2" attributes="0"/>
32
              <Component id="scopePanel" min="-2" max="-2" attributes="0"/>
38
              <Group type="103" groupAlignment="0" max="-2" attributes="0">
39
                  <Component id="scope" max="32767" attributes="0"/>
40
                  <Component id="jLabel1" max="32767" attributes="0"/>
41
              </Group>
42
              <EmptySpace max="-2" attributes="0"/>
33
          </Group>
43
          </Group>
34
      </Group>
44
      </Group>
35
    </DimensionLayout>
45
    </DimensionLayout>
36
  </Layout>
46
  </Layout>
37
  <SubComponents>
47
  <SubComponents>
38
    <Container class="javax.swing.JPanel" name="scopePanel">
39
40
      <Layout>
41
        <DimensionLayout dim="0">
42
          <Group type="103" groupAlignment="0" attributes="0">
43
              <Group type="102" alignment="0" attributes="0">
44
                  <EmptySpace max="-2" attributes="0"/>
45
                  <Component id="scopeLabel" min="-2" max="-2" attributes="0"/>
46
                  <EmptySpace max="-2" attributes="0"/>
47
                  <Component id="scope" max="32767" attributes="0"/>
48
                  <EmptySpace max="-2" attributes="0"/>
49
                  <Component id="btnCustomScope" min="-2" max="-2" attributes="0"/>
50
                  <EmptySpace max="-2" attributes="0"/>
51
              </Group>
52
          </Group>
53
        </DimensionLayout>
54
        <DimensionLayout dim="1">
55
          <Group type="103" groupAlignment="0" attributes="0">
56
              <Group type="102" alignment="0" attributes="0">
57
                  <EmptySpace max="-2" attributes="0"/>
58
                  <Group type="103" groupAlignment="0" attributes="0">
59
                      <Group type="102" alignment="0" attributes="0">
60
                          <EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
61
                          <Component id="scopeLabel" min="-2" max="-2" attributes="1"/>
62
                      </Group>
63
                      <Group type="103" groupAlignment="3" attributes="0">
64
                          <Component id="btnCustomScope" alignment="3" min="-2" max="-2" attributes="0"/>
65
                          <Component id="scope" alignment="3" min="-2" max="-2" attributes="1"/>
66
                      </Group>
67
                  </Group>
68
                  <EmptySpace min="-2" max="-2" attributes="0"/>
69
              </Group>
70
          </Group>
71
        </DimensionLayout>
72
      </Layout>
73
      <SubComponents>
74
        <Component class="javax.swing.JLabel" name="scopeLabel">
75
          <Properties>
76
            <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
77
              <ComponentRef name="scope"/>
78
            </Property>
79
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
80
              <ResourceString bundle="org/netbeans/modules/refactoring/java/ui/Bundle.properties" key="LBL_Scope" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
81
            </Property>
82
          </Properties>
83
          <AuxValues>
84
            <AuxValue name="generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
85
          </AuxValues>
86
        </Component>
87
        <Component class="javax.swing.JComboBox" name="scope">
88
          <AccessibilityProperties>
89
            <Property name="AccessibleContext.accessibleDescription" type="java.lang.String" value="N/A"/>
90
          </AccessibilityProperties>
91
          <Events>
92
            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="scopeActionPerformed"/>
93
          </Events>
94
          <AuxValues>
95
            <AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="((javax.swing.JTextField) scope.getEditor().getEditorComponent()).setColumns(SCOPE_COMBOBOX_COLUMNS);"/>
96
          </AuxValues>
97
        </Component>
98
        <Component class="javax.swing.JButton" name="btnCustomScope">
99
          <Properties>
100
            <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
101
              <Connection code="ELLIPSIS" type="code"/>
102
            </Property>
103
          </Properties>
104
        </Component>
105
      </SubComponents>
106
    </Container>
107
    <Container class="javax.swing.JPanel" name="innerPanel">
48
    <Container class="javax.swing.JPanel" name="innerPanel">
108
49
109
      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
50
      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
110
    </Container>
51
    </Container>
52
    <Component class="org.netbeans.modules.refactoring.spi.ui.ScopePanel" name="scope">
53
      <AuxValues>
54
        <AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new org.netbeans.modules.refactoring.spi.ui.ScopePanel(WhereUsedPanel.class.getCanonicalName().replace(&apos;.&apos;, &apos;-&apos;), NbPreferences.forModule(WhereUsedPanel.class), &quot;whereUsed.scope&quot;)"/>
55
      </AuxValues>
56
    </Component>
57
    <Component class="javax.swing.JLabel" name="jLabel1">
58
      <Properties>
59
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
60
          <ResourceString bundle="org/netbeans/modules/refactoring/java/ui/Bundle.properties" key="WhereUsedPanel.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
61
        </Property>
62
      </Properties>
63
    </Component>
111
  </SubComponents>
64
  </SubComponents>
112
</Form>
65
</Form>
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/WhereUsedPanel.java (-301 / +24 lines)
Lines 43-88 Link Here
43
 */
43
 */
44
package org.netbeans.modules.refactoring.java.ui;
44
package org.netbeans.modules.refactoring.java.ui;
45
45
46
import com.sun.source.tree.ExpressionTree;
47
import com.sun.source.util.TreePath;
48
import java.awt.BorderLayout;
46
import java.awt.BorderLayout;
49
import java.awt.Component;
47
import java.awt.Component;
50
import java.awt.event.ActionEvent;
51
import java.beans.BeanInfo;
52
import java.io.IOException;
48
import java.io.IOException;
53
import java.net.MalformedURLException;
54
import java.net.URL;
55
import java.util.Arrays;
49
import java.util.Arrays;
56
import java.util.LinkedList;
57
import java.util.List;
50
import java.util.List;
58
import java.util.Set;
51
import java.util.concurrent.atomic.AtomicBoolean;
59
import java.util.prefs.BackingStoreException;
60
import java.util.prefs.Preferences;
61
import javax.lang.model.element.Element;
52
import javax.lang.model.element.Element;
62
import javax.lang.model.element.ElementKind;
53
import javax.lang.model.element.ElementKind;
63
import javax.lang.model.element.Modifier;
54
import javax.lang.model.element.Modifier;
64
import javax.swing.*;
55
import javax.swing.*;
65
import javax.swing.event.ChangeListener;
56
import javax.swing.event.ChangeListener;
66
import javax.swing.plaf.UIResource;
67
import org.netbeans.api.fileinfo.NonRecursiveFolder;
68
import org.netbeans.api.java.project.JavaProjectConstants;
69
import org.netbeans.api.java.source.*;
57
import org.netbeans.api.java.source.*;
70
import org.netbeans.api.java.source.JavaSource.Phase;
58
import org.netbeans.api.java.source.JavaSource.Phase;
71
import org.netbeans.api.project.*;
72
import org.netbeans.modules.refactoring.api.Scope;
59
import org.netbeans.modules.refactoring.api.Scope;
73
import org.netbeans.modules.refactoring.java.Pair;
60
import org.netbeans.modules.refactoring.java.Pair;
74
import org.netbeans.modules.refactoring.java.RefactoringModule;
75
import org.netbeans.modules.refactoring.java.api.ui.JavaScopeBuilder;
76
import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
61
import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
77
import org.openide.filesystems.FileObject;
62
import org.openide.filesystems.FileObject;
78
import org.openide.filesystems.FileStateInvalidException;
79
import org.openide.filesystems.URLMapper;
80
import org.openide.loaders.DataObject;
81
import org.openide.loaders.DataObjectNotFoundException;
82
import org.openide.util.Exceptions;
83
import org.openide.util.ImageUtilities;
84
import org.openide.util.NbBundle;
63
import org.openide.util.NbBundle;
85
import org.openide.util.NbPreferences;
64
import org.openide.util.NbPreferences;
65
import org.openide.util.lookup.Lookups;
86
66
87
67
88
/**
68
/**
Lines 91-104 Link Here
91
 */
71
 */
92
public class WhereUsedPanel extends JPanel implements CustomRefactoringPanel {
72
public class WhereUsedPanel extends JPanel implements CustomRefactoringPanel {
93
    
73
    
94
    private static final String PREF_SCOPE = "FindUsages-Scope";
95
    private static final String PACKAGE = "org/netbeans/spi/java/project/support/ui/package.gif"; // NOI18N
96
    private final transient TreePathHandle element;
74
    private final transient TreePathHandle element;
97
    private final transient ChangeListener parent;
75
    private final transient ChangeListener parent;
98
//    private static final int MAX_NAME = 50;
99
    private static final int SCOPE_COMBOBOX_COLUMNS = 14;
100
    public static final String ELLIPSIS = "\u2026"; //NOI18N
101
    private Scope customScope;
102
    private boolean enableScope;
76
    private boolean enableScope;
103
77
104
    private final WhereUsedInnerPanel panel;
78
    private final WhereUsedInnerPanel panel;
Lines 111-117 Link Here
111
        this.enableScope = true;
85
        this.enableScope = true;
112
        this.panel = panel;
86
        this.panel = panel;
113
        initComponents();
87
        initComponents();
114
        btnCustomScope.setAction(new ScopeAction(scope));
115
    }
88
    }
116
    
89
    
117
    public static WhereUsedPanel create(String name, TreePathHandle e, ElementKind kind, List<Pair<Pair<String, Icon>, TreePathHandle>> classes, ChangeListener parent) {
90
    public static WhereUsedPanel create(String name, TreePathHandle e, ElementKind kind, List<Pair<Pair<String, Icon>, TreePathHandle>> classes, ChangeListener parent) {
Lines 145-182 Link Here
145
    
118
    
146
    public Scope getCustomScope() {
119
    public Scope getCustomScope() {
147
        FileObject file = WhereUsedPanel.this.element.getFileObject();
120
        FileObject file = WhereUsedPanel.this.element.getFileObject();
148
        Scope value = null;
149
        
121
        
150
        if(!enableScope) {
122
        if(!enableScope) {
151
            return Scope.create(null, null, Arrays.asList(file));
123
            return Scope.create(null, null, Arrays.asList(file));
152
        }
124
        }
153
125
154
        switch (scope.getSelectedIndex()) {
126
        return scope.getSelectedScope();
155
            case 1:
156
                value = Scope.create(Arrays.asList(projectSources), null, null);
157
                break;
158
            case 2:
159
                NonRecursiveFolder nonRecursiveFolder = new NonRecursiveFolder() {
160
            @Override
161
                    public FileObject getFolder() {
162
                        return packageFolder;
163
                    }
164
                };
165
                value = Scope.create(null, Arrays.asList(nonRecursiveFolder), null);
166
                break;
167
            case 3:
168
                value = Scope.create(null, null, Arrays.asList(file));
169
                break;
170
            case 4:
171
                value = WhereUsedPanel.this.customScope;
172
                break;
173
        }
174
        return value;
175
    }
127
    }
176
128
177
    private boolean initialized = false;
129
    private boolean initialized = false;
178
    private FileObject packageFolder = null;
179
    private FileObject[] projectSources = null;
180
    
130
    
181
    String getMethodDeclaringClass() {
131
    String getMethodDeclaringClass() {
182
        if(panel instanceof WhereUsedPanelMethod) {
132
        if(panel instanceof WhereUsedPanelMethod) {
Lines 192-198 Link Here
192
            return;
142
            return;
193
        }
143
        }
194
        JavaSource source = JavaSource.forFileObject(element.getFileObject());
144
        JavaSource source = JavaSource.forFileObject(element.getFileObject());
195
        final Project p = FileOwnerQuery.getOwner(element.getFileObject());
196
        CancellableTask<CompilationController> task =new CancellableTask<CompilationController>() {
145
        CancellableTask<CompilationController> task =new CancellableTask<CompilationController>() {
197
            @Override
146
            @Override
198
            public void cancel() {
147
            public void cancel() {
Lines 206-255 Link Here
206
                final Element element = WhereUsedPanel.this.element.resolveElement(info);
155
                final Element element = WhereUsedPanel.this.element.resolveElement(info);
207
                panel.initialize(element, info);
156
                panel.initialize(element, info);
208
157
209
                TreePath path = WhereUsedPanel.this.element.resolve(info);
210
                final ExpressionTree packageName1 = path.getCompilationUnit().getPackageName();
211
                final String packageName = packageName1 == null? "<default package>" : packageName1.toString(); //NOI18N
212
                if(packageName1 == null) {
213
                    packageFolder = info.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.SOURCE).findOwnerRoot(WhereUsedPanel.this.element.getFileObject());
214
                } else {
215
                    packageFolder = info.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.SOURCE).findResource(packageName.replaceAll("\\.", "/")); //NOI18N
216
                }
217
                
218
                final JLabel customScope;
219
                final JLabel currentFile;
220
                final JLabel currentPackage;
221
                final JLabel currentProject;
222
                final JLabel allProjects;
223
                if (p != null) {
224
                    ProjectInformation pi = ProjectUtils.getInformation(FileOwnerQuery.getOwner(WhereUsedPanel.this.element.getFileObject()));
225
                    
226
                    SourceGroup[] sources = ProjectUtils.getSources(pi.getProject()).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
227
                    projectSources = new FileObject[sources.length];
228
                    for (int i = 0; i < sources.length; i++) {
229
                        projectSources[i] = sources[i].getRootFolder();
230
                    }
231
                    
232
                    DataObject currentFileDo = null;
233
                    try {
234
                        currentFileDo = DataObject.find(WhereUsedPanel.this.element.getFileObject());
235
                    } catch (DataObjectNotFoundException ex) {
236
                    } // Not important, only for Icon.
237
                    customScope = new JLabel(NbBundle.getMessage(WhereUsedPanel.class, "LBL_CustomScope"), pi.getIcon(), SwingConstants.LEFT); //NOI18N
238
                    currentFile = new JLabel(NbBundle.getMessage(WhereUsedPanel.class, "LBL_CurrentFile", WhereUsedPanel.this.element.getFileObject().getNameExt()), currentFileDo != null ? new ImageIcon(currentFileDo.getNodeDelegate().getIcon(BeanInfo.ICON_COLOR_16x16)) : pi.getIcon(), SwingConstants.LEFT); //NOI18N
239
                    currentPackage = new JLabel(NbBundle.getMessage(WhereUsedPanel.class, "LBL_CurrentPackage", packageName), ImageUtilities.loadImageIcon(PACKAGE, false), SwingConstants.LEFT); //NOI18N
240
                    currentProject = new JLabel(NbBundle.getMessage(WhereUsedPanel.class, "LBL_CurrentProject", pi.getDisplayName()), pi.getIcon(), SwingConstants.LEFT); //NOI18N
241
                    allProjects = new JLabel(NbBundle.getMessage(WhereUsedPanel.class, "LBL_AllProjects"), pi.getIcon(), SwingConstants.LEFT); //NOI18N
242
                } else {
243
                    customScope = null;
244
                    currentFile = null;
245
                    currentPackage = null;
246
                    currentProject = null;
247
                    allProjects = null;
248
                }
249
250
                if((element.getKind().equals(ElementKind.LOCAL_VARIABLE) || element.getKind().equals(ElementKind.PARAMETER))
158
                if((element.getKind().equals(ElementKind.LOCAL_VARIABLE) || element.getKind().equals(ElementKind.PARAMETER))
251
                        || element.getModifiers().contains(Modifier.PRIVATE)) {
159
                        || element.getModifiers().contains(Modifier.PRIVATE)) {
252
                    enableScope = false;
160
                    enableScope = false;
161
                } else {
162
                    enableScope = scope.initialize(Lookups.fixed(WhereUsedPanel.this.element.getFileObject(), WhereUsedPanel.this.element.resolve(info)), new AtomicBoolean());
253
                }
163
                }
254
164
255
                SwingUtilities.invokeLater(new Runnable() {
165
                SwingUtilities.invokeLater(new Runnable() {
Lines 258-280 Link Here
258
                        innerPanel.removeAll();
168
                        innerPanel.removeAll();
259
                        innerPanel.add(panel, BorderLayout.CENTER);
169
                        innerPanel.add(panel, BorderLayout.CENTER);
260
                        panel.setVisible(true);
170
                        panel.setVisible(true);
261
171
                        scope.setVisible(enableScope);
262
                        if(enableScope && currentProject!=null) {
263
                            scope.setModel(new DefaultComboBoxModel(new Object[]{allProjects, currentProject, currentPackage, currentFile, customScope }));
264
                            int defaultItem = (Integer) RefactoringModule.getOption("whereUsed.scope", 0); // NOI18N
265
                            WhereUsedPanel.this.customScope = readScope();
266
                            if(defaultItem == 4 && WhereUsedPanel.this.customScope !=null &&
267
                                    WhereUsedPanel.this.customScope.getFiles().isEmpty() &&
268
                                    WhereUsedPanel.this.customScope.getFolders().isEmpty() &&
269
                                    WhereUsedPanel.this.customScope.getSourceRoots().isEmpty()) {
270
                                scope.setSelectedIndex(0);
271
                            } else {
272
                                scope.setSelectedIndex(defaultItem);
273
                            }
274
                            scope.setRenderer(new JLabelRenderer());
275
                        } else {
276
                            scopePanel.setVisible(false);
277
                        }
278
                    }
172
                    }
279
                });
173
                });
280
            }};
174
            }};
Lines 285-426 Link Here
285
            }
179
            }
286
            initialized = true;
180
            initialized = true;
287
    }
181
    }
288
    private static class JLabelRenderer extends JLabel implements ListCellRenderer, UIResource {
289
        public JLabelRenderer () {
290
            setOpaque(true);
291
        }
292
        @Override
293
        public Component getListCellRendererComponent(
294
                JList list,
295
                Object value,
296
                int index,
297
                boolean isSelected,
298
                boolean cellHasFocus) {
299
            
300
            // #89393: GTK needs name to render cell renderer "natively"
301
            setName("ComboBox.listRenderer"); // NOI18N
302
            
303
            if ( value != null ) {
304
                setText(((JLabel)value).getText());
305
                setIcon(((JLabel)value).getIcon());
306
            }
307
            
308
            if ( isSelected ) {
309
                setBackground(list.getSelectionBackground());
310
                setForeground(list.getSelectionForeground());
311
            } else {
312
                setBackground(list.getBackground());
313
                setForeground(list.getForeground());
314
            }
315
            
316
            return this;
317
        }
318
        
319
        // #89393: GTK needs name to render cell renderer "natively"
320
        @Override
321
        public String getName() {
322
            String name = super.getName();
323
            return name == null ? "ComboBox.renderer" : name;  // NOI18N
324
        }
325
    }
326
182
327
    static abstract class WhereUsedInnerPanel extends JPanel {
183
    static abstract class WhereUsedInnerPanel extends JPanel {
328
        abstract boolean isSearchInComments();
184
        abstract boolean isSearchInComments();
329
        abstract void initialize(Element element, CompilationController info);
185
        abstract void initialize(Element element, CompilationController info);
330
    }
186
    }
331
332
    private class ScopeAction extends AbstractAction {
333
        private final JComboBox scope;
334
335
        private ScopeAction(JComboBox scope) {
336
            this.scope = scope;
337
            this.putValue(NAME, ELLIPSIS);
338
        }
339
340
        @Override
341
        public void actionPerformed(ActionEvent e) {
342
            Scope customScope = getCustomScope();
343
            
344
            customScope = JavaScopeBuilder.open(NbBundle.getMessage(WhereUsedPanel.class, "DLG_CustomScope"), customScope); //NOI18N
345
            if (customScope != null) {
346
                WhereUsedPanel.this.customScope = customScope;
347
                scope.setSelectedIndex(4);
348
                storeScope(customScope);
349
            }
350
        }
351
    }
352
    
353
    private void storeScope(Scope customScope) {
354
        try {
355
            storeFileList(customScope.getSourceRoots(), "sourceRoot" ); //NOI18N
356
            storeFileList(customScope.getFolders(), "folder" ); //NOI18N
357
            storeFileList(customScope.getFiles(), "file" ); //NOI18N
358
        } catch (BackingStoreException ex) {
359
            Exceptions.printStackTrace(ex);
360
        }
361
    }
362
    
363
    private Scope readScope() {
364
        try {
365
            if (NbPreferences.forModule(JavaScopeBuilder.class).nodeExists(PREF_SCOPE)) { //NOI18N
366
                return Scope.create(
367
                        loadFileList("sourceRoot", FileObject.class), //NOI18N
368
                        loadFileList("folder", NonRecursiveFolder.class), //NOI18N
369
                        loadFileList("file", FileObject.class)); //NOI18N
370
            }
371
        } catch (BackingStoreException ex) {
372
            Exceptions.printStackTrace(ex);
373
        }
374
        return null;
375
    }
376
    
377
    private <T> List<T> loadFileList(String basekey, Class<T> type) throws BackingStoreException {
378
        Preferences pref = NbPreferences.forModule(JavaScopeBuilder.class).node(PREF_SCOPE).node(basekey);
379
        List<T> toRet = new LinkedList<T>();
380
        for (String key : pref.keys()) {
381
            final String url = pref.get(key, null);
382
            if (url != null && !url.isEmpty()) {
383
                try {
384
                    final FileObject f = URLMapper.findFileObject(new URL(url));
385
                    if (f != null && f.isValid()) {
386
                        if (type.isAssignableFrom(FileObject.class)) {
387
                            toRet.add((T) f);
388
                        } else {
389
                            toRet.add((T) new NonRecursiveFolder() {
390
391
                                @Override
392
                                public FileObject getFolder() {
393
                                    return f;
394
                                }
395
                            });
396
                        }
397
                    }
398
                } catch (MalformedURLException ex) {
399
                    Exceptions.printStackTrace(ex);
400
                }
401
            }
402
        }
403
        return toRet;
404
    }
405
    
406
    private void storeFileList(Set files, String basekey) throws BackingStoreException {
407
        Preferences pref = NbPreferences.forModule(WhereUsedPanel.class).node(PREF_SCOPE).node(basekey);
408
        assert files != null;
409
        pref.clear();
410
        int count = 0;
411
        for (Object next : files) {
412
            try {
413
                if (next instanceof FileObject) {
414
                    pref.put(basekey + count++, ((FileObject) next).getURL().toExternalForm());
415
                } else {
416
                    pref.put(basekey + count++, ((NonRecursiveFolder) next).getFolder().getURL().toExternalForm());
417
                }
418
            } catch (FileStateInvalidException ex) {
419
                Exceptions.printStackTrace(ex);
420
            }
421
        }
422
        pref.flush();
423
    }
424
    
187
    
425
//    static String getHeader(Element call, CompilationInfo info) {
188
//    static String getHeader(Element call, CompilationInfo info) {
426
//        String result = ElementHeaders.getHeader(call, info, ElementHeaders.NAME + ElementHeaders.PARAMETERS);
189
//        String result = ElementHeaders.getHeader(call, info, ElementHeaders.NAME + ElementHeaders.PARAMETERS);
Lines 452-533 Link Here
452
    private void initComponents() {
215
    private void initComponents() {
453
216
454
        buttonGroup = new javax.swing.ButtonGroup();
217
        buttonGroup = new javax.swing.ButtonGroup();
455
        scopePanel = new javax.swing.JPanel();
456
        scopeLabel = new javax.swing.JLabel();
457
        scope = new javax.swing.JComboBox();
458
        btnCustomScope = new javax.swing.JButton();
459
        innerPanel = new javax.swing.JPanel();
218
        innerPanel = new javax.swing.JPanel();
460
219
        scope = new org.netbeans.modules.refactoring.spi.ui.ScopePanel(WhereUsedPanel.class.getCanonicalName().replace('.', '-'), NbPreferences.forModule(WhereUsedPanel.class), "whereUsed.scope");
461
        scopeLabel.setLabelFor(scope);
220
        jLabel1 = new javax.swing.JLabel();
462
        org.openide.awt.Mnemonics.setLocalizedText(scopeLabel, org.openide.util.NbBundle.getMessage(WhereUsedPanel.class, "LBL_Scope")); // NOI18N
463
464
        ((javax.swing.JTextField) scope.getEditor().getEditorComponent()).setColumns(SCOPE_COMBOBOX_COLUMNS);
465
        scope.addActionListener(new java.awt.event.ActionListener() {
466
            public void actionPerformed(java.awt.event.ActionEvent evt) {
467
                scopeActionPerformed(evt);
468
            }
469
        });
470
471
        btnCustomScope.setText(ELLIPSIS);
472
473
        javax.swing.GroupLayout scopePanelLayout = new javax.swing.GroupLayout(scopePanel);
474
        scopePanel.setLayout(scopePanelLayout);
475
        scopePanelLayout.setHorizontalGroup(
476
            scopePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
477
            .addGroup(scopePanelLayout.createSequentialGroup()
478
                .addContainerGap()
479
                .addComponent(scopeLabel)
480
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
481
                .addComponent(scope, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
482
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
483
                .addComponent(btnCustomScope)
484
                .addContainerGap())
485
        );
486
        scopePanelLayout.setVerticalGroup(
487
            scopePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
488
            .addGroup(scopePanelLayout.createSequentialGroup()
489
                .addContainerGap()
490
                .addGroup(scopePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
491
                    .addGroup(scopePanelLayout.createSequentialGroup()
492
                        .addGap(6, 6, 6)
493
                        .addComponent(scopeLabel))
494
                    .addGroup(scopePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
495
                        .addComponent(btnCustomScope)
496
                        .addComponent(scope, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
497
                .addContainerGap())
498
        );
499
500
        scope.getAccessibleContext().setAccessibleDescription("N/A");
501
221
502
        innerPanel.setLayout(new java.awt.BorderLayout());
222
        innerPanel.setLayout(new java.awt.BorderLayout());
503
223
224
        jLabel1.setText(org.openide.util.NbBundle.getMessage(WhereUsedPanel.class, "WhereUsedPanel.jLabel1.text")); // NOI18N
225
504
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
226
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
505
        this.setLayout(layout);
227
        this.setLayout(layout);
506
        layout.setHorizontalGroup(
228
        layout.setHorizontalGroup(
507
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
229
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
508
            .addComponent(scopePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
230
            .addComponent(innerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
509
            .addComponent(innerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
231
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
232
                .addContainerGap()
233
                .addComponent(jLabel1)
234
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
235
                .addComponent(scope, javax.swing.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE)
236
                .addContainerGap())
510
        );
237
        );
511
        layout.setVerticalGroup(
238
        layout.setVerticalGroup(
512
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
239
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
513
            .addGroup(layout.createSequentialGroup()
240
            .addGroup(layout.createSequentialGroup()
514
                .addComponent(innerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
241
                .addComponent(innerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
515
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
242
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
516
                .addComponent(scopePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
243
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
244
                    .addComponent(scope, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
245
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
246
                .addContainerGap())
517
        );
247
        );
518
    }// </editor-fold>//GEN-END:initComponents
248
    }// </editor-fold>//GEN-END:initComponents
519
249
520
private void scopeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_scopeActionPerformed
521
    RefactoringModule.setOption("whereUsed.scope", scope.getSelectedIndex()); // NOI18N
522
}//GEN-LAST:event_scopeActionPerformed
523
524
    // Variables declaration - do not modify//GEN-BEGIN:variables
250
    // Variables declaration - do not modify//GEN-BEGIN:variables
525
    private javax.swing.JButton btnCustomScope;
526
    private javax.swing.ButtonGroup buttonGroup;
251
    private javax.swing.ButtonGroup buttonGroup;
527
    private javax.swing.JPanel innerPanel;
252
    private javax.swing.JPanel innerPanel;
528
    private javax.swing.JComboBox scope;
253
    private javax.swing.JLabel jLabel1;
529
    private javax.swing.JLabel scopeLabel;
254
    private org.netbeans.modules.refactoring.spi.ui.ScopePanel scope;
530
    private javax.swing.JPanel scopePanel;
531
    // End of variables declaration//GEN-END:variables
255
    // End of variables declaration//GEN-END:variables
532
256
533
    public boolean isMethodFromBaseClass() {
257
    public boolean isMethodFromBaseClass() {
Lines 587-590 Link Here
587
        return this;
311
        return this;
588
    }
312
    }
589
}
313
}
590
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/scope/Bundle.properties (+43 lines)
Line 0 Link Here
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 2012 Oracle and/or its affiliates. All rights reserved.
4
#
5
# Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
# Other names may be trademarks of their respective owners.
7
#
8
# The contents of this file are subject to the terms of either the GNU
9
# General Public License Version 2 only ("GPL") or the Common
10
# Development and Distribution License("CDDL") (collectively, the
11
# "License"). You may not use this file except in compliance with the
12
# License. You can obtain a copy of the License at
13
# http://www.netbeans.org/cddl-gplv2.html
14
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
15
# specific language governing permissions and limitations under the
16
# License.  When distributing the software, include this License Header
17
# Notice in each file and include the License file at
18
# nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
19
# particular file as subject to the "Classpath" exception as provided
20
# by Oracle in the GPL Version 2 section of the License file that
21
# accompanied this code. If applicable, add the following below the
22
# License Header, with the fields enclosed by brackets [] replaced by
23
# your own identifying information:
24
# "Portions Copyrighted [year] [name of copyright owner]"
25
#
26
# If you wish your version of this file to be governed by only the CDDL
27
# or only the GPL Version 2, indicate your decision by adding
28
# "[Contributor] elects to include this software in this distribution
29
# under the [CDDL or GPL Version 2] license." If you do not indicate a
30
# single choice of license, a recipient has the option to distribute
31
# your version of this file under either the CDDL, the GPL Version 2 or
32
# to extend the choice of license to its licensees as provided above.
33
# However, if you add GPL Version 2 code and therefore, elected the GPL
34
# Version 2 license, then the option applies only if the new code is
35
# made subject to such option by the copyright holder.
36
#
37
# Contributor(s):
38
#
39
# Portions Copyrighted 2012 Sun Microsystems, Inc.
40
41
ScopePanel.scopeLabel.text=Sco&pe: 
42
43
LBL_WaitNode=Please Wait...
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/scope/CurrentFileScopeProvider.java (+104 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.refactoring.java.ui.scope;
43
44
import java.beans.BeanInfo;
45
import java.util.Arrays;
46
import java.util.concurrent.atomic.AtomicBoolean;
47
import javax.swing.Icon;
48
import javax.swing.ImageIcon;
49
import org.netbeans.modules.refactoring.api.Scope;
50
import org.netbeans.modules.refactoring.spi.ui.ScopeProvider;
51
import org.netbeans.modules.refactoring.spi.ui.ScopeReference;
52
import org.openide.filesystems.FileObject;
53
import org.openide.loaders.DataObject;
54
import org.openide.loaders.DataObjectNotFoundException;
55
import org.openide.util.Lookup;
56
import org.openide.util.NbBundle.Messages;
57
58
/**
59
 *
60
 * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
61
 */
62
@ScopeProvider.Registration(displayName = "#LBL_CurrentFile", id = "current-file", position = 400, iconBase = "org/netbeans/modules/refactoring/java/resources/newFile.png")
63
@ScopeReference(path="org-netbeans-modules-refactoring-java-ui-WhereUsedPanel")
64
@Messages(value = {"# {0} - Filename", "LBL_CurrentFile=Current File"})
65
public final class CurrentFileScopeProvider extends ScopeProvider {
66
67
    private Scope scope;
68
    private ImageIcon icon;
69
    private String detail;
70
71
    @Override
72
    public boolean initialize(Lookup context, AtomicBoolean cancel) {
73
        FileObject file = context.lookup(FileObject.class);
74
        if (file == null || file.isFolder()) {
75
            return false;
76
        }
77
78
        DataObject currentFileDo = null;
79
        try {
80
            currentFileDo = DataObject.find(file);
81
        } catch (DataObjectNotFoundException ex) {
82
        } // Not important, only for Icon.
83
        icon = currentFileDo != null ? new ImageIcon(currentFileDo.getNodeDelegate().getIcon(BeanInfo.ICON_COLOR_16x16)) : null;
84
        detail = file.getNameExt();
85
        scope = Scope.create(null, null, Arrays.asList(file));
86
87
        return true;
88
    }
89
90
    @Override
91
    public Scope getScope() {
92
        return scope;
93
    }
94
95
    @Override
96
    public Icon getIcon() {
97
        return icon != null ? icon : super.getIcon();
98
    }
99
100
    @Override
101
    public String getDetail() {
102
        return detail;
103
    }
104
}
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/scope/CurrentJavaProjectScopeProvider.java (+129 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.refactoring.java.ui.scope;
43
44
import java.util.Arrays;
45
import java.util.Map;
46
import java.util.concurrent.atomic.AtomicBoolean;
47
import javax.swing.Icon;
48
import org.netbeans.api.java.classpath.ClassPath;
49
import org.netbeans.api.java.project.JavaProjectConstants;
50
import org.netbeans.api.project.FileOwnerQuery;
51
import org.netbeans.api.project.Project;
52
import org.netbeans.api.project.ProjectInformation;
53
import org.netbeans.api.project.ProjectUtils;
54
import org.netbeans.api.project.SourceGroup;
55
import org.netbeans.modules.refactoring.api.Scope;
56
import org.netbeans.modules.refactoring.spi.ui.ScopeProvider;
57
import org.netbeans.modules.refactoring.spi.ui.ScopeReference;
58
import org.openide.filesystems.FileObject;
59
import org.openide.loaders.DataFolder;
60
import org.openide.util.Lookup;
61
import org.openide.util.NbBundle.Messages;
62
63
/**
64
 *
65
 * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
66
 */
67
@ScopeProvider.Registration(id = "current-project", displayName = "#LBL_CurrentProject", position = 200)
68
@ScopeReference(path = "org-netbeans-modules-refactoring-java-ui-WhereUsedPanel")
69
@Messages({"LBL_CurrentProject=Current Project"})
70
public final class CurrentJavaProjectScopeProvider extends ScopeProvider {
71
72
    private String detail;
73
    private Scope scope;
74
    private Icon icon;
75
76
    @Override
77
    public boolean initialize(Lookup context, AtomicBoolean cancel) {
78
        FileObject file = context.lookup(FileObject.class);
79
        Project selected = null;
80
        if (file != null) {
81
            selected = FileOwnerQuery.getOwner(file);
82
        }
83
        if (selected == null) {
84
            selected = context.lookup(Project.class);
85
            if (selected == null) {
86
                SourceGroup sg = context.lookup(SourceGroup.class);
87
                if (sg != null) {
88
                    selected = FileOwnerQuery.getOwner(sg.getRootFolder());
89
                }
90
            }
91
            if (selected == null) {
92
                DataFolder df = context.lookup(DataFolder.class);
93
                if (df != null) {
94
                    selected = FileOwnerQuery.getOwner(df.getPrimaryFile());
95
                }
96
            }
97
        }
98
        if (selected == null) {
99
            return false;
100
        }
101
102
        ProjectInformation pi = ProjectUtils.getInformation(selected);
103
        final SourceGroup[] sourceGroups = ProjectUtils.getSources(pi.getProject()).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
104
        FileObject[] projectSources = new FileObject[sourceGroups.length];
105
        for (int i = 0; i < sourceGroups.length; i++) {
106
            projectSources[i] = sourceGroups[i].getRootFolder();
107
        }
108
        scope = Scope.create(Arrays.asList(projectSources), null, null);
109
110
        detail = pi.getDisplayName();
111
        icon = pi.getIcon();
112
        return true;
113
    }
114
115
    @Override
116
    public String getDetail() {
117
        return detail;
118
    }
119
120
    @Override
121
    public Icon getIcon() {
122
        return icon;
123
    }
124
125
    @Override
126
    public Scope getScope() {
127
        return scope;
128
    }
129
}
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/scope/CurrentPackageScopeProvider.java (+119 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.refactoring.java.ui.scope;
43
44
import com.sun.source.tree.ExpressionTree;
45
import com.sun.source.util.TreePath;
46
import java.util.Arrays;
47
import java.util.concurrent.atomic.AtomicBoolean;
48
import org.netbeans.api.fileinfo.NonRecursiveFolder;
49
import org.netbeans.api.java.classpath.ClassPath;
50
import org.netbeans.modules.refactoring.api.Scope;
51
import org.netbeans.modules.refactoring.spi.ui.ScopeProvider;
52
import org.netbeans.modules.refactoring.spi.ui.ScopeReference;
53
import org.openide.filesystems.FileObject;
54
import org.openide.util.Lookup;
55
import org.openide.util.NbBundle.Messages;
56
57
/**
58
 *
59
 * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
60
 */
61
@Messages({"LBL_CurrentPackage=Current Package"})
62
@ScopeProvider.Registration(id = "current-package", displayName = "#LBL_CurrentPackage", position = 300, iconBase = "org/netbeans/spi/java/project/support/ui/package.gif")
63
@ScopeReference(path="org-netbeans-modules-refactoring-java-ui-WhereUsedPanel")
64
public final class CurrentPackageScopeProvider extends ScopeProvider {
65
66
    private String detail;
67
    private Scope scope;
68
69
    @Override
70
    public boolean initialize(Lookup context, AtomicBoolean cancel) {
71
        FileObject file = context.lookup(FileObject.class);
72
        if (file == null) {
73
            return false;
74
        }
75
        final FileObject packageFolder;
76
        final String packageName;
77
        ClassPath sourceCP = ClassPath.getClassPath(file, ClassPath.SOURCE);
78
        if (sourceCP != null) {
79
            TreePath path = context.lookup(TreePath.class);
80
            if (path != null) {
81
                final ExpressionTree packageName1 = path.getCompilationUnit().getPackageName();
82
                packageName = packageName1 == null ? "<default package>" : packageName1.toString(); //NOI18N
83
                if (packageName1 == null) {
84
                    packageFolder = sourceCP.findOwnerRoot(file);
85
                } else {
86
                    packageFolder = sourceCP.findResource(packageName.replaceAll("\\.", "/")); //NOI18N
87
                }
88
            } else {
89
                packageFolder = file.isFolder()? file : file.getParent();
90
                packageName = sourceCP.getResourceName(packageFolder, '.', false);
91
            }
92
        } else {
93
            packageFolder = null;
94
            packageName = null;
95
        }
96
97
        if (packageFolder != null) {
98
            detail = packageName;
99
            scope = Scope.create(null, Arrays.<NonRecursiveFolder>asList(new NonRecursiveFolder() {
100
                @Override
101
                public FileObject getFolder() {
102
                    return packageFolder;
103
                }
104
            }), null);
105
            return true;
106
        }
107
        return false;
108
    }
109
110
    @Override
111
    public Scope getScope() {
112
        return scope;
113
    }
114
115
    @Override
116
    public String getDetail() {
117
        return detail;
118
    }
119
}
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/CustomScopePanel.java (-1 / +2 lines)
Lines 45-51 Link Here
45
 *
45
 *
46
 * Created on Jun 13, 2011, 9:51:30 AM
46
 * Created on Jun 13, 2011, 9:51:30 AM
47
 */
47
 */
48
package org.netbeans.modules.refactoring.java.ui;
48
package org.netbeans.modules.refactoring.java.ui.scope;
49
49
50
import java.awt.*;
50
import java.awt.*;
51
import java.awt.image.BufferedImage;
51
import java.awt.image.BufferedImage;
Lines 92-97 Link Here
92
 *
92
 *
93
 * @author Ralph Ruijs
93
 * @author Ralph Ruijs
94
 */
94
 */
95
@NbBundle.Messages({"DLG_CustomScope=Custom Scope"})
95
public class CustomScopePanel extends javax.swing.JPanel implements ExplorerManager.Provider {
96
public class CustomScopePanel extends javax.swing.JPanel implements ExplorerManager.Provider {
96
97
97
    private static final Image PACKAGEBADGE = ImageUtilities.loadImage("org/netbeans/spi/java/project/support/ui/packageBadge.gif"); // NOI18N
98
    private static final Image PACKAGEBADGE = ImageUtilities.loadImage("org/netbeans/spi/java/project/support/ui/packageBadge.gif"); // NOI18N
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/scope/CustomScopeProvider.java (+172 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.refactoring.java.ui.scope;
43
44
import java.net.MalformedURLException;
45
import java.net.URL;
46
import java.util.LinkedList;
47
import java.util.List;
48
import java.util.Set;
49
import java.util.concurrent.atomic.AtomicBoolean;
50
import java.util.prefs.BackingStoreException;
51
import java.util.prefs.Preferences;
52
import org.netbeans.api.fileinfo.NonRecursiveFolder;
53
import org.netbeans.modules.refactoring.api.Scope;
54
import org.netbeans.modules.refactoring.spi.ui.ScopeProvider;
55
import org.netbeans.modules.refactoring.java.api.ui.JavaScopeBuilder;
56
import org.openide.filesystems.FileObject;
57
import org.openide.filesystems.URLMapper;
58
import org.openide.util.Exceptions;
59
import org.openide.util.Lookup;
60
import org.openide.util.NbPreferences;
61
import static org.netbeans.modules.refactoring.java.ui.scope.Bundle.*;
62
import org.netbeans.modules.refactoring.spi.ui.ScopeReference;
63
import org.openide.util.NbBundle.Messages;
64
65
/**
66
 *
67
 * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
68
 */
69
@Messages("LBL_CustomScope=Custom Scope...")
70
@ScopeProvider.Registration(id = "custom-scope", displayName = "#LBL_CustomScope", position = 900, iconBase = "org/netbeans/modules/refactoring/java/resources/filter.png")
71
@ScopeReference(path="org-netbeans-modules-refactoring-java-ui-WhereUsedPanel")
72
public final class CustomScopeProvider extends ScopeProvider.CustomScopeProvider {
73
74
    private static final String PREF_SCOPE = "FindUsages-Scope";
75
    private Scope customScope;
76
77
    @Override
78
    public boolean initialize(Lookup context, AtomicBoolean cancel) {
79
        return true;
80
    }
81
82
    @Override
83
    public void setScope(Scope value) {
84
        customScope = value != null ? Scope.create(value.getSourceRoots(), value.getFolders(), value.getFiles()) : null;
85
    }
86
87
    @Override
88
    @Messages("TTL_CustomScope=Custom Scope")
89
    public boolean showCustomizer() {
90
        Scope nue = JavaScopeBuilder.open(TTL_CustomScope(), customScope); //NOI18N
91
        if (nue != null) {
92
            storeScope(customScope = nue);
93
        }
94
95
        return nue != null;
96
    }
97
98
    @Override
99
    public Scope getScope() {
100
        if (customScope == null) {
101
            customScope = readScope();
102
        }
103
        return customScope;
104
    }
105
106
    private void storeScope(Scope customScope) {
107
        try {
108
            storeFileList(customScope.getSourceRoots(), "sourceRoot"); //NOI18N
109
            storeFileList(customScope.getFolders(), "folder"); //NOI18N
110
            storeFileList(customScope.getFiles(), "file"); //NOI18N
111
        } catch (BackingStoreException ex) {
112
            Exceptions.printStackTrace(ex);
113
        }
114
    }
115
116
    private Scope readScope() {
117
        try {
118
            if (NbPreferences.forModule(JavaScopeBuilder.class).nodeExists(PREF_SCOPE)) { //NOI18N
119
                return Scope.create(
120
                        loadFileList("sourceRoot", FileObject.class), //NOI18N
121
                        loadFileList("folder", NonRecursiveFolder.class), //NOI18N
122
                        loadFileList("file", FileObject.class)); //NOI18N
123
            }
124
        } catch (BackingStoreException ex) {
125
            Exceptions.printStackTrace(ex);
126
        }
127
        return null;
128
    }
129
130
    private <T> List<T> loadFileList(String basekey, Class<T> type) throws BackingStoreException {
131
        Preferences pref = NbPreferences.forModule(JavaScopeBuilder.class).node(PREF_SCOPE).node(basekey);
132
        List<T> toRet = new LinkedList<T>();
133
        for (String key : pref.keys()) {
134
            final String url = pref.get(key, null);
135
            if (url != null && !url.isEmpty()) {
136
                try {
137
                    final FileObject f = URLMapper.findFileObject(new URL(url));
138
                    if (f != null && f.isValid()) {
139
                        if (type.isAssignableFrom(FileObject.class)) {
140
                            toRet.add((T) f);
141
                        } else {
142
                            toRet.add((T) new NonRecursiveFolder() {
143
                                @Override
144
                                public FileObject getFolder() {
145
                                    return f;
146
                                }
147
                            });
148
                        }
149
                    }
150
                } catch (MalformedURLException ex) {
151
                    Exceptions.printStackTrace(ex);
152
                }
153
            }
154
        }
155
        return toRet;
156
    }
157
158
    private void storeFileList(Set files, String basekey) throws BackingStoreException {
159
        Preferences pref = NbPreferences.forModule(CustomScopeProvider.class).node(PREF_SCOPE).node(basekey);
160
        assert files != null;
161
        pref.clear();
162
        int count = 0;
163
        for (Object next : files) {
164
            if (next instanceof FileObject) {
165
                pref.put(basekey + count++, ((FileObject) next).toURL().toExternalForm());
166
            } else {
167
                pref.put(basekey + count++, ((NonRecursiveFolder) next).getFolder().toURL().toExternalForm());
168
            }
169
        }
170
        pref.flush();
171
    }
172
}
(-)a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/scope/OpenProjectsScopeProvider.java (+86 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.refactoring.java.ui.scope;
43
44
import java.util.Collection;
45
import java.util.Collections;
46
import java.util.HashMap;
47
import java.util.HashSet;
48
import java.util.IdentityHashMap;
49
import java.util.Map;
50
import java.util.Set;
51
import java.util.concurrent.atomic.AtomicBoolean;
52
import org.netbeans.api.annotations.common.NonNull;
53
import org.netbeans.api.annotations.common.NullAllowed;
54
import org.netbeans.api.fileinfo.NonRecursiveFolder;
55
import org.netbeans.api.java.classpath.ClassPath;
56
import org.netbeans.api.java.classpath.GlobalPathRegistry;
57
import org.netbeans.api.project.FileOwnerQuery;
58
import org.netbeans.api.project.Project;
59
import org.netbeans.api.project.ui.OpenProjects;
60
import org.netbeans.modules.parsing.spi.indexing.PathRecognizer;
61
import org.netbeans.modules.refactoring.api.Scope;
62
import org.netbeans.modules.refactoring.spi.ui.ScopeProvider;
63
import org.netbeans.modules.refactoring.spi.ui.ScopeReference;
64
import org.openide.filesystems.FileObject;
65
import org.openide.util.Lookup;
66
import org.openide.util.NbBundle;
67
68
/**
69
 *
70
 * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
71
 */
72
@NbBundle.Messages("LBL_AllProjects=Open Projects")
73
@ScopeProvider.Registration(id = "all-projects", displayName = "#LBL_AllProjects", position = 100, iconBase = "org/netbeans/modules/refactoring/java/resources/all_projects.png")
74
@ScopeReference(path = "org-netbeans-modules-refactoring-java-ui-WhereUsedPanel")
75
public class OpenProjectsScopeProvider extends ScopeProvider {
76
77
    @Override
78
    public boolean initialize(Lookup context, AtomicBoolean cancel) {
79
        return true;
80
    }
81
82
    @Override
83
    public Scope getScope() {
84
        return null;
85
    }
86
}

Return to bug 217347