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

(-)a/refactoring.api/apichanges.xml (+19 lines)
Lines 49-54 Link Here
49
    <apidef name="refactoring">Refactoring API</apidef>
49
    <apidef name="refactoring">Refactoring API</apidef>
50
</apidefs>
50
</apidefs>
51
<changes>
51
<changes>
52
    <change id="RefactoringResultsFilters">
53
        <api name="refactoring"/>
54
        <summary>Added an API to support filters of the Find Usages results.</summary>
55
        <version major="1" minor="29"/>
56
        <date day="10" month="7" year="2012"/>
57
        <author login="ralphbenjamin"/>
58
        <compatibility addition="yes"/>
59
        <description>
60
            <p>
61
                This API allows refactoring plugins to add/enable filters to the
62
                results window and refactoring elements to specify if they should
63
                be included in the results.
64
            </p>
65
        </description>
66
        <class package="org.netbeans.modules.refactoring.api" name="RefactoringElement"/>
67
        <class package="org.netbeans.modules.refactoring.spi" name="FiltersManager"/>
68
        <class package="org.netbeans.modules.refactoring.spi.ui" name="FiltersDescription"/>
69
        <issue number="215361"/>
70
    </change>
52
    <change id="FinishSession">
71
    <change id="FinishSession">
53
        <api name="refactoring"/>
72
        <api name="refactoring"/>
54
        <summary>Changed access level of #finish() to public.</summary>
73
        <summary>Changed access level of #finish() to public.</summary>
(-)a/refactoring.api/nbproject/project.properties (-1 / +1 lines)
Lines 4-8 Link Here
4
javadoc.apichanges=${basedir}/apichanges.xml
4
javadoc.apichanges=${basedir}/apichanges.xml
5
javadoc.title=Refactoring API
5
javadoc.title=Refactoring API
6
6
7
spec.version.base=1.28.0
7
spec.version.base=1.29.0
8
test.config.stableBTD.includes=**/*Test.class
8
test.config.stableBTD.includes=**/*Test.class
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/api/AbstractRefactoring.java (-5 / +20 lines)
Lines 61-80 Link Here
61
import org.netbeans.modules.refactoring.spi.GuardedBlockHandlerFactory;
61
import org.netbeans.modules.refactoring.spi.GuardedBlockHandlerFactory;
62
import org.netbeans.modules.refactoring.spi.ProgressProvider;
62
import org.netbeans.modules.refactoring.spi.ProgressProvider;
63
import org.netbeans.modules.refactoring.spi.ReadOnlyFilesHandler;
63
import org.netbeans.modules.refactoring.spi.ReadOnlyFilesHandler;
64
import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
64
import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
65
import org.netbeans.modules.refactoring.spi.RefactoringPlugin;
65
import org.netbeans.modules.refactoring.spi.RefactoringPluginFactory;
66
import org.netbeans.modules.refactoring.spi.RefactoringPluginFactory;
67
import org.netbeans.modules.refactoring.spi.impl.RefactoringPanel;
66
import org.netbeans.modules.refactoring.spi.impl.Util;
68
import org.netbeans.modules.refactoring.spi.impl.Util;
69
import org.netbeans.modules.refactoring.spi.ui.FiltersDescription;
70
import org.netbeans.modules.refactoring.spi.ui.FiltersDescription.Provider;
67
import org.openide.ErrorManager;
71
import org.openide.ErrorManager;
68
import org.openide.filesystems.FileObject;
72
import org.openide.filesystems.FileObject;
69
import org.openide.filesystems.FileUtil;
70
import org.openide.loaders.DataObject;
73
import org.openide.loaders.DataObject;
71
import org.openide.loaders.DataObjectNotFoundException;
74
import org.openide.loaders.DataObjectNotFoundException;
72
import org.openide.modules.ModuleInfo;
75
import org.openide.modules.ModuleInfo;
73
import org.openide.util.Lookup;
74
import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
75
import org.netbeans.modules.refactoring.spi.impl.RefactoringPanel;
76
import org.openide.modules.Modules;
76
import org.openide.modules.Modules;
77
import org.openide.util.Exceptions;
77
import org.openide.util.Exceptions;
78
import org.openide.util.Lookup;
78
import org.openide.util.NbBundle;
79
import org.openide.util.NbBundle;
79
import org.openide.util.Parameters;
80
import org.openide.util.Parameters;
80
import org.openide.util.lookup.InstanceContent;
81
import org.openide.util.lookup.InstanceContent;
Lines 116-121 Link Here
116
    private static final int PLUGIN_STEPS = 30;
117
    private static final int PLUGIN_STEPS = 30;
117
    
118
    
118
    private ArrayList plugins;
119
    private ArrayList plugins;
120
    private FiltersDescription filtersDescription;
119
    
121
    
120
    ArrayList pluginsWithProgress;
122
    ArrayList pluginsWithProgress;
121
    
123
    
Lines 136-141 Link Here
136
        if (plugins == null) {
138
        if (plugins == null) {
137
            plugins = new ArrayList();
139
            plugins = new ArrayList();
138
            // get plugins from the lookup
140
            // get plugins from the lookup
141
            filtersDescription = new FiltersDescription();
139
            Lookup.Result result = Lookup.getDefault().lookup(new Lookup.Template(RefactoringPluginFactory.class));
142
            Lookup.Result result = Lookup.getDefault().lookup(new Lookup.Template(RefactoringPluginFactory.class));
140
            for (Iterator it = result.allInstances().iterator(); it.hasNext();) {
143
            for (Iterator it = result.allInstances().iterator(); it.hasNext();) {
141
                RefactoringPluginFactory factory = (RefactoringPluginFactory) it.next();
144
                RefactoringPluginFactory factory = (RefactoringPluginFactory) it.next();
Lines 155-166 Link Here
155
                        //  SafeDeleteRefactoringPlugin.
158
                        //  SafeDeleteRefactoringPlugin.
156
                        //  #65980
159
                        //  #65980
157
                        plugins.add(plugin);
160
                        plugins.add(plugin);
161
                        if(plugin instanceof FiltersDescription.Provider) {
162
                            FiltersDescription.Provider prov = (FiltersDescription.Provider) plugin;
163
                            prov.addFilters(filtersDescription);
164
                        }
158
                    }
165
                    }
159
                }
166
                }
160
            }
167
            }
161
        }
168
        }
162
        return plugins;
169
        return plugins;
163
    }
170
    }
171
172
    FiltersDescription getFiltersDescription() {
173
        return filtersDescription;
174
    }
164
    
175
    
165
    Collection getGBHandlers() {
176
    Collection getGBHandlers() {
166
        if (gbHandlers == null) {
177
        if (gbHandlers == null) {
Lines 427-434 Link Here
427
            } catch (Throwable t) {
438
            } catch (Throwable t) {
428
                problem =createProblemAndLog(problem, t, plugin.getClass());
439
                problem =createProblemAndLog(problem, t, plugin.getClass());
429
            }
440
            }
430
            if (problem!=null && problem.isFatal())
441
            if (problem!=null && problem.isFatal()) {
431
                return problem;
442
                return problem;
443
            } else if(plugin instanceof FiltersDescription.Provider) {
444
                Provider provider = (Provider) plugin;
445
                provider.enableFilters(filtersDescription);
446
            }
432
        }
447
        }
433
        
448
        
434
        //TODO: 
449
        //TODO: 
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/api/AccessorImpl.java (+12 lines)
Lines 49-54 Link Here
49
import org.netbeans.modules.refactoring.spi.GuardedBlockHandler;
49
import org.netbeans.modules.refactoring.spi.GuardedBlockHandler;
50
import org.netbeans.modules.refactoring.spi.ProblemDetailsImplementation;
50
import org.netbeans.modules.refactoring.spi.ProblemDetailsImplementation;
51
import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
51
import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
52
import org.netbeans.modules.refactoring.spi.ui.FiltersDescription;
52
53
53
/**
54
/**
54
 *
55
 *
Lines 96-99 Link Here
96
    public boolean hasChangesInReadOnlyFiles(RefactoringSession session) {
97
    public boolean hasChangesInReadOnlyFiles(RefactoringSession session) {
97
        return SPIAccessor.DEFAULT.hasChangesInReadOnlyFiles(session.getElementsBag());
98
        return SPIAccessor.DEFAULT.hasChangesInReadOnlyFiles(session.getElementsBag());
98
    }
99
    }
100
    
101
    @Override
102
    public FiltersDescription getFiltersDescription(AbstractRefactoring refactoring) {
103
        return refactoring.getFiltersDescription();
104
    }
105
106
    @Override
107
    public boolean isFinished(RefactoringSession session) {
108
        return session.isFinished();
109
    }
110
    
99
}
111
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/api/RefactoringElement.java (-2 / +15 lines)
Lines 44-52 Link Here
44
package org.netbeans.modules.refactoring.api;
44
package org.netbeans.modules.refactoring.api;
45
45
46
import org.netbeans.api.annotations.common.NonNull;
46
import org.netbeans.api.annotations.common.NonNull;
47
import org.netbeans.modules.refactoring.spi.FiltersManager;
48
import org.netbeans.modules.refactoring.spi.FiltersManager.Filterable;
47
import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
49
import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
48
import org.netbeans.modules.refactoring.spi.ui.TreeElement;
50
import org.netbeans.modules.refactoring.spi.ui.TreeElement;
49
import org.netbeans.modules.refactoring.spi.ui.TreeElementFactory;
50
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.FileObject;
51
import org.openide.text.PositionBounds;
52
import org.openide.text.PositionBounds;
52
import org.openide.util.Lookup;
53
import org.openide.util.Lookup;
Lines 180-184 Link Here
180
        return hash;
181
        return hash;
181
    }
182
    }
182
183
183
184
    /**
185
     * Indicates if this element should be included in the results.
186
     * @param filtersManager the FiltersManager to use
187
     * @return true if this element should be included
188
     * @since 1.29
189
     */
190
    public boolean include(FiltersManager filtersManager) {
191
        if(impl instanceof FiltersManager.Filterable) {
192
            Filterable filterable = (Filterable) impl;
193
            return filterable.filter(filtersManager);
194
        }
195
        return true;
196
    }
184
}
197
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/api/RefactoringSession.java (+4 lines)
Lines 254-259 Link Here
254
        finished.set(true);
254
        finished.set(true);
255
    }
255
    }
256
    
256
    
257
    boolean isFinished() {
258
        return finished.get();
259
    }
260
    
257
    /**
261
    /**
258
     *  Adds progress listener to this RefactoringSession
262
     *  Adds progress listener to this RefactoringSession
259
     * @param listener to add
263
     * @param listener to add
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/api/impl/APIAccessor.java (-2 / +3 lines)
Lines 52-57 Link Here
52
import org.netbeans.modules.refactoring.spi.GuardedBlockHandler;
52
import org.netbeans.modules.refactoring.spi.GuardedBlockHandler;
53
import org.netbeans.modules.refactoring.spi.ProblemDetailsImplementation;
53
import org.netbeans.modules.refactoring.spi.ProblemDetailsImplementation;
54
import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
54
import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
55
import org.netbeans.modules.refactoring.spi.ui.FiltersDescription;
55
56
56
/**
57
/**
57
 *
58
 *
Lines 77-83 Link Here
77
    public abstract boolean hasPluginsWithProgress(AbstractRefactoring refactoring);
78
    public abstract boolean hasPluginsWithProgress(AbstractRefactoring refactoring);
78
    public abstract boolean hasChangesInGuardedBlocks(RefactoringSession session);
79
    public abstract boolean hasChangesInGuardedBlocks(RefactoringSession session);
79
    public abstract boolean hasChangesInReadOnlyFiles(RefactoringSession session);
80
    public abstract boolean hasChangesInReadOnlyFiles(RefactoringSession session);
80
81
    public abstract FiltersDescription getFiltersDescription(AbstractRefactoring refactoring);
81
82
    public abstract boolean isFinished(RefactoringSession session);
82
83
83
}
84
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/FiltersManager.java (+80 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;
43
44
import org.netbeans.modules.refactoring.api.RefactoringElement;
45
import org.netbeans.modules.refactoring.spi.ui.FiltersDescription;
46
47
/**
48
 * Handles creation and manipulation with boolean state filters.
49
 *
50
 * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
51
 * @see FiltersDescription
52
 * @since 1.29
53
 */
54
public abstract class FiltersManager {
55
56
    /**
57
     * Indicates if a filter is selected.
58
     *
59
     * @param filterName the name of the filter to check
60
     * @return Returns true when given filter is selected, false otherwise.
61
     */
62
    public abstract boolean isSelected(String filterName);
63
64
    /**
65
     * {@code RefactoringElement}s should implement this interface if they
66
     * should be filterable in the results.
67
     *
68
     * @see RefactoringElement#include
69
     */
70
    public static interface Filterable {
71
72
        /**
73
         * Indicates if this element should be included in the results.
74
         *
75
         * @param manager the FiltersManager to use
76
         * @return true if this element should be included
77
         */
78
        boolean filter(FiltersManager manager);
79
    }
80
}
(-)a/java.navigation/src/org/netbeans/modules/java/navigation/base/FiltersManager.java (-157 / +153 lines)
Lines 41-48 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
44
package org.netbeans.modules.refactoring.spi.impl;
45
package org.netbeans.modules.java.navigation.base;
46
45
47
import java.awt.Dimension;
46
import java.awt.Dimension;
48
import java.awt.Insets;
47
import java.awt.Insets;
Lines 52-157 Link Here
52
import java.util.HashMap;
51
import java.util.HashMap;
53
import java.util.List;
52
import java.util.List;
54
import java.util.Map;
53
import java.util.Map;
55
import java.util.prefs.Preferences;
56
import javax.swing.BorderFactory;
57
import javax.swing.Box;
58
import javax.swing.BoxLayout;
59
import javax.swing.Icon;
54
import javax.swing.Icon;
60
import javax.swing.JComponent;
61
import javax.swing.JToggleButton;
55
import javax.swing.JToggleButton;
62
import javax.swing.JToolBar;
56
import javax.swing.JToolBar;
63
import javax.swing.SwingUtilities;
57
import javax.swing.SwingUtilities;
64
import javax.swing.border.EmptyBorder;
65
import javax.swing.event.ChangeEvent;
58
import javax.swing.event.ChangeEvent;
66
import org.netbeans.modules.java.navigation.NoBorderToolBar;
59
import org.netbeans.modules.refactoring.spi.FiltersManager;
60
import org.netbeans.modules.refactoring.spi.ui.FiltersDescription;
67
import org.openide.util.Mutex;
61
import org.openide.util.Mutex;
68
import org.openide.util.NbPreferences;
69
62
70
/** Handles creation and manipulation with boolean state filters. 
63
/**
64
 * Handles creation and manipulation with boolean state filters.
71
 *
65
 *
72
 * @author Dafe Simomek
66
 * @author Dafe Simomek
73
 */
67
 */
74
public final class FiltersManager {
68
public final class FiltersManagerImpl extends FiltersManager {
75
    
69
76
    private FiltersComponent comp;
70
    private FiltersComponent comp;
77
    
71
78
    static FiltersManager create (FiltersDescription descr) {
72
    static FiltersManagerImpl create(FiltersDescription descr) {
79
        return new FiltersManager(descr);
73
        return new FiltersManagerImpl(descr);
80
    }
74
    }
81
    
75
82
    /** Returns true when given filter is selected, false otherwise.
76
    /**
83
     * Note that this method is thread safe, can be called from any thread
77
     * Indicates if a filter is selected.
84
     * (and usually will, as clients will call this from loadContent naturally)
78
     *
79
     * @param filterName the name of the filter to check
80
     * @return Returns true when given filter is selected, false otherwise.
85
     */
81
     */
86
    public boolean isSelected (String filterName) {
82
    @Override
83
    public boolean isSelected(String filterName) {
87
        return comp.isSelected(filterName);
84
        return comp.isSelected(filterName);
88
    }
85
    }
89
    
86
90
    /** Sets boolean value of filter with given name. True means filter is
87
    /**
91
     * selected (enabled), false otherwise. Note, must be called from AWT thread.
88
     * Sets boolean value of filter with given name. True means filter is
89
     * selected (enabled), false otherwise. Note, must be called from AWT
90
     * thread.
92
     */
91
     */
93
    public void setSelected (String filterName, boolean value) {
92
    public void setSelected(String filterName, boolean value) {
94
        comp.setFilterSelected(filterName, value);
93
        comp.setFilterSelected(filterName, value);
95
    }
94
    }
96
95
97
    /** @return component instance visually representing filters */ 
96
    /**
98
    public JComponent getComponent ( JToggleButton[] sortButtons ) {
97
     * @return component instance visually representing filters
99
        comp.addSortButtons( sortButtons );
98
     */
100
        return comp;
99
    public JToolBar getComponent(JToggleButton... additionalButtons) {
100
        if(additionalButtons != null && additionalButtons.length > 0) {
101
            comp.addAdditionalButtons(additionalButtons);
102
        }
103
        return comp.toolbar;
101
    }
104
    }
102
    
105
103
    /** @return Filters description */
106
    /**
104
    public FiltersDescription getDescription () {
107
     * @return Filters description
108
     */
109
    public FiltersDescription getDescription() {
105
        return comp.getDescription();
110
        return comp.getDescription();
106
    }
111
    }
107
112
108
    /** Assigns listener for listening to filter changes */ 
113
    /**
109
    public void hookChangeListener (FilterChangeListener l) {
114
     * Assigns listener for listening to filter changes
115
     */
116
    public void hookChangeListener(FilterChangeListener l) {
110
        comp.hookFilterChangeListener(l);
117
        comp.hookFilterChangeListener(l);
111
    }
118
    }
112
    
119
113
    /** Interface for listening to changes of filter states contained in FIltersPanel
120
    /**
121
     * Interface for listening to changes of filter states contained in
122
     * FIltersPanel
114
     */
123
     */
115
    public interface FilterChangeListener {
124
    public interface FilterChangeListener {
116
        /** Called whenever some changes in state of filters contained in
125
117
         * filters panel is triggered
126
        /**
127
         * Called whenever some changes in state of filters contained in filters
128
         * panel is triggered
118
         */
129
         */
119
        public void filterStateChanged(ChangeEvent e);
130
        public void filterStateChanged(ChangeEvent e);
120
        
121
    } // end of FilterChangeListener
131
    } // end of FilterChangeListener
122
    
123
132
124
    /** Private, creation managed by factory method 'create' */
133
    /**
125
    private FiltersManager (FiltersDescription descr) {
134
     * Private, creation managed by factory method 'create'
135
     */
136
    private FiltersManagerImpl(FiltersDescription descr) {
126
        comp = new FiltersComponent(descr);
137
        comp = new FiltersComponent(descr);
127
    }
138
    }
128
    
139
129
    /** Swing component representing filters in panel filled with toggle buttons.
140
    /**
141
     * Swing component representing filters in panel filled with toggle buttons.
130
     * Provides thread safe access to the states of filters by copying states
142
     * Provides thread safe access to the states of filters by copying states
131
     * into private map, properly sync'ed.
143
     * into private map, properly sync'ed.
132
     */
144
     */
133
    private class FiltersComponent extends Box implements ActionListener {
145
    private class FiltersComponent implements ActionListener {
134
        
146
135
        /** list of <JToggleButton> visually representing filters */
147
        /**
148
         * list of <JToggleButton> visually representing filters
149
         */
136
        private List<JToggleButton> toggles;
150
        private List<JToggleButton> toggles;
137
        /** description of filters */
151
        /**
152
         * description of filters
153
         */
138
        private final FiltersDescription filtersDesc;
154
        private final FiltersDescription filtersDesc;
139
 
155
        /**
140
        /** lock for listener */
156
         * lock for listener
141
        private Object L_LOCK = new Object();
157
         */
142
        /** listener */
158
        private final Object L_LOCK = new Object();
159
        /**
160
         * listener
161
         */
143
        private FilterChangeListener clientL;
162
        private FilterChangeListener clientL;
144
163
        /**
145
        /** lock for map of filter states */
164
         * lock for map of filter states
146
        private Object STATES_LOCK = new Object();
165
         */
147
        /** copy of filter states for accessing outside AWT */
166
        private final Object STATES_LOCK = new Object();
148
        private Map<String,Boolean> filterStates;
167
        /**
149
        
168
         * copy of filter states for accessing outside AWT
169
         */
170
        private Map<String, Boolean> filterStates;
150
        private JToolBar toolbar;
171
        private JToolBar toolbar;
151
172
152
        /** Returns selected state of given filter, thread safe.
173
        /**
174
         * Returns selected state of given filter, thread safe.
153
         */
175
         */
154
        public boolean isSelected (String filterName) {
176
        public boolean isSelected(String filterName) {
155
            Boolean result;
177
            Boolean result;
156
            synchronized (STATES_LOCK) {
178
            synchronized (STATES_LOCK) {
157
                if (filterStates == null) {
179
                if (filterStates == null) {
Lines 165-181 Link Here
165
                }
187
                }
166
                result = filterStates.get(filterName);
188
                result = filterStates.get(filterName);
167
            }
189
            }
168
            
190
169
            if (result == null) {
191
            if (result == null) {
170
                throw new IllegalArgumentException("Filter " + filterName + " not found.");
192
                throw new IllegalArgumentException("Filter " + filterName + " not found.");
171
            }
193
            }
172
            return result.booleanValue();
194
            return result.booleanValue();
173
        }
195
        }
174
        
196
175
        /** Sets filter value, AWT only */
197
        /**
176
        public void setFilterSelected (String filterName, boolean value) {
198
         * Sets filter value, AWT only
199
         */
200
        public void setFilterSelected(String filterName, boolean value) {
177
            assert SwingUtilities.isEventDispatchThread();
201
            assert SwingUtilities.isEventDispatchThread();
178
            
202
179
            int index = filterIndexForName(filterName);
203
            int index = filterIndexForName(filterName);
180
            if (index < 0) {
204
            if (index < 0) {
181
                throw new IllegalArgumentException("Filter " + filterName + " not found.");
205
                throw new IllegalArgumentException("Filter " + filterName + " not found.");
Lines 188-299 Link Here
188
            // notify
212
            // notify
189
            fireChange();
213
            fireChange();
190
        }
214
        }
191
        
215
192
        public void hookFilterChangeListener (FilterChangeListener l) {
216
        public void hookFilterChangeListener(FilterChangeListener l) {
193
            synchronized (L_LOCK) {
217
            synchronized (L_LOCK) {
194
                clientL = l;
218
                clientL = l;
195
            }
219
            }
196
        }
220
        }
197
        
221
198
        public FiltersDescription getDescription () {
222
        public FiltersDescription getDescription() {
199
            return filtersDesc;
223
            return filtersDesc;
200
        }
224
        }
201
    
225
202
        /** Not public, instances created using factory method createPanel */
226
        /**
227
         * Not public, instances created using factory method createPanel
228
         */
203
        FiltersComponent(FiltersDescription descr) {
229
        FiltersComponent(FiltersDescription descr) {
204
            super(BoxLayout.X_AXIS);
205
            this.filtersDesc = descr;
230
            this.filtersDesc = descr;
206
            // always create swing content in AWT thread
231
            // always create swing content in AWT thread
207
            Mutex.EVENT.readAccess(new Runnable () {
232
            Mutex.EVENT.readAccess(new Runnable() {
208
                public void run () {
233
                @Override
209
                    initPanel();                        
234
                public void run() {
235
                    initPanel();
210
                }
236
                }
211
            });
237
            });
212
        }
238
        }
213
239
214
        /** Called only from AWT */
240
        /**
215
        private void initPanel () {
241
         * Called only from AWT
216
            setBorder(new EmptyBorder(1, 2, 3, 5));
242
         */
217
243
        private void initPanel() {
218
            // configure toolbar
244
            // configure toolbar
219
            toolbar = new NoBorderToolBar(JToolBar.HORIZONTAL);
245
            toolbar = new JToolBar(JToolBar.VERTICAL);
220
            toolbar.setFloatable(false);
246
            toolbar.setFloatable(false);
221
            toolbar.setRollover(true);
247
            toolbar.setRollover(true);
222
            toolbar.setBorderPainted(false);
248
            toolbar.setBorderPainted(true);
223
            toolbar.setBorder(BorderFactory.createEmptyBorder());
249
            toolbar.setBorder(
250
                    javax.swing.BorderFactory.createCompoundBorder(
251
                    javax.swing.BorderFactory.createMatteBorder(0, 1, 0, 0,
252
                    javax.swing.UIManager.getDefaults().getColor("Separator.foreground")), //NOI18N
253
                    javax.swing.BorderFactory.createEmptyBorder(0, 1, 0, 0)));
224
            toolbar.setOpaque(false);
254
            toolbar.setOpaque(false);
225
            toolbar.setFocusable(false);
255
            toolbar.setFocusable(false);
226
            // create toggle buttons
256
            // create toggle buttons
227
            int filterCount = filtersDesc.getFilterCount();
257
            int filterCount = filtersDesc.getFilterCount();
228
            toggles = new ArrayList<JToggleButton>(filterCount);
258
            toggles = new ArrayList<JToggleButton>(filterCount);
229
            JToggleButton toggleButton = null;
259
            JToggleButton toggleButton;
230
            
260
231
            Map<String,Boolean> fStates = new HashMap<String, Boolean>(filterCount * 2);
261
            Map<String, Boolean> fStates = new HashMap<String, Boolean>(filterCount * 2);
232
262
233
            for (int i = 0; i < filterCount; i++) {
263
            for (int i = 0; i < filterCount; i++) {
234
                toggleButton = createToggle(fStates, i);
264
                toggleButton = createToggle(fStates, i);
235
                toggles.add(toggleButton);
265
                toggles.add(toggleButton);
236
            }
266
            }
237
            
267
238
            // add toggle buttons
268
            // add toggle buttons
239
            JToggleButton curToggle;
269
            JToggleButton curToggle;
240
            for (int i = 0; i < toggles.size(); i++) {
270
            for (int i = 0; i < toggles.size(); i++) {
241
                curToggle = toggles.get(i);
271
                curToggle = toggles.get(i);
242
                curToggle.addActionListener(this);
272
                curToggle.addActionListener(this);
243
                toolbar.add(curToggle);
273
                toolbar.add(curToggle);
244
                if (i != toggles.size() - 1) {
245
                    toolbar.add(new Space());
246
                }
247
            }
274
            }
248
            
275
249
            add(toolbar);
250
            
251
            // initialize member states map
276
            // initialize member states map
252
            synchronized (STATES_LOCK) {
277
            synchronized (STATES_LOCK) {
253
                filterStates = fStates;
278
                filterStates = fStates;
254
            }
279
            }
255
        }
280
        }
256
        
281
257
        private void addSortButtons( JToggleButton[] sortButtons ) {
282
        private void addAdditionalButtons(JToggleButton[] sortButtons) {
258
            Dimension space = new Dimension(3, 0);
283
            Dimension space = new Dimension(3, 0);
259
            for( JToggleButton button : sortButtons ) {
284
            for (JToggleButton button : sortButtons) {
260
                Icon icon = button.getIcon();
285
                Dimension size = new Dimension(21, 21); // 3 less than other buttons
261
                Dimension size = new Dimension(icon.getIconWidth() + 6, icon.getIconHeight() + 4);
286
                button.setMaximumSize(size);
287
                button.setMinimumSize(size);
262
                button.setPreferredSize(size);
288
                button.setPreferredSize(size);
263
                button.setMargin(new Insets(2,3,2,3));
289
//                button.setMargin(new Insets(2, 3, 2, 3));
264
                toolbar.addSeparator(space);
290
                toolbar.addSeparator(space);
265
                toolbar.add( button );
291
                toolbar.add(button);
266
            }
292
            }
267
        }
293
        }
268
        
294
269
        private Preferences getPreferences() {
295
        private JToggleButton createToggle(Map<String, Boolean> fStates, int index) {
270
            return NbPreferences.forModule( FiltersManager.class );
296
            boolean isSelected = filtersDesc.isSelected(index);
271
        }
297
            Icon icon = filtersDesc.getIcon(index);
272
        
273
        private JToggleButton createToggle (Map<String,Boolean> fStates, int index) {
274
            boolean isSelected = getPreferences().getBoolean( filtersDesc.getName(index), filtersDesc.isSelected(index) );
275
            Icon icon = filtersDesc.getSelectedIcon(index);
276
            // ensure small size, just for the icon
298
            // ensure small size, just for the icon
277
            JToggleButton result = new JToggleButton(icon, isSelected);
299
            JToggleButton result = new JToggleButton(icon, isSelected);
278
            Dimension size = new Dimension(icon.getIconWidth() + 6, icon.getIconHeight() + 4);
300
            Dimension size = new Dimension(21, 21); // 3 less than other buttons
301
            result.setMaximumSize(size);
302
            result.setMinimumSize(size);
279
            result.setPreferredSize(size);
303
            result.setPreferredSize(size);
280
            result.setMargin(new Insets(2,3,2,3));
304
            result.setBorderPainted(false);
305
//            result.setMargin(new Insets(2, 3, 2, 3));
281
            result.setToolTipText(filtersDesc.getTooltip(index));
306
            result.setToolTipText(filtersDesc.getTooltip(index));
282
            result.setFocusable(false);
307
            result.setEnabled(filtersDesc.isEnabled(index));
283
            
308
            fStates.put(filtersDesc.getKey(index), Boolean.valueOf(isSelected));
284
            fStates.put(filtersDesc.getName(index), Boolean.valueOf(isSelected));
309
285
            
286
            return result;
310
            return result;
287
        }
311
        }
288
312
289
        /** Finds and returns index of filter with given name or -1 if no
313
        /**
290
         * such filter exists.
314
         * Finds and returns index of filter with given name or -1 if no such
315
         * filter exists.
291
         */
316
         */
292
        private int filterIndexForName (String filterName) {
317
        private int filterIndexForName(String filterName) {
293
            int filterCount = filtersDesc.getFilterCount();
318
            int filterCount = filtersDesc.getFilterCount();
294
            String curName;
319
            String curName;
295
            for (int i = 0; i < filterCount; i++) {
320
            for (int i = 0; i < filterCount; i++) {
296
                curName = filtersDesc.getName(i);
321
                curName = filtersDesc.getKey(i);
297
                if (filterName.equals(curName)) {
322
                if (filterName.equals(curName)) {
298
                    return i;
323
                    return i;
299
                }
324
                }
Lines 301-320 Link Here
301
            return -1;
326
            return -1;
302
        }
327
        }
303
328
304
        /** Reactions to toggle button click,  */
329
        /**
330
         * Reactions to toggle button click,
331
         */
332
        @Override
305
        public void actionPerformed(ActionEvent e) {
333
        public void actionPerformed(ActionEvent e) {
306
            // copy changed state first
334
            // copy changed state first
307
            JToggleButton toggle = (JToggleButton)e.getSource();
335
            JToggleButton toggle = (JToggleButton) e.getSource();
308
            int index = toggles.indexOf(e.getSource());
336
            int index = toggles.indexOf(e.getSource());
309
            synchronized (STATES_LOCK) {
337
            synchronized (STATES_LOCK) {
310
                filterStates.put(filtersDesc.getName(index),
338
                filterStates.put(filtersDesc.getKey(index),
311
                                Boolean.valueOf(toggle.isSelected()));
339
                        Boolean.valueOf(toggle.isSelected()));
312
            }
340
            }
313
            // notify
341
            // notify
314
            fireChange();
342
            fireChange();
315
        }
343
        }
316
        
344
317
        private void fireChange () {
345
        private void fireChange() {
318
            FilterChangeListener lCopy;
346
            FilterChangeListener lCopy;
319
            synchronized (L_LOCK) {
347
            synchronized (L_LOCK) {
320
                // no listener = no notification
348
                // no listener = no notification
Lines 323-363 Link Here
323
                }
351
                }
324
                lCopy = clientL;
352
                lCopy = clientL;
325
            }
353
            }
326
            
354
327
            // notify listener
355
            // notify listener
328
            lCopy.filterStateChanged(new ChangeEvent(FiltersManager.this));
356
            lCopy.filterStateChanged(new ChangeEvent(FiltersManagerImpl.this));
329
        }
357
        }
330
331
        @Override
332
        public void removeNotify() {
333
            //remember filter settings
334
            if( null != filterStates ) {
335
                Preferences prefs = getPreferences();
336
                for( String filterName : filterStates.keySet() ) {
337
                    prefs.putBoolean( filterName, filterStates.get( filterName ) );
338
                }
339
            }
340
            super.removeNotify();
341
        }
342
    
343
    } // end of FiltersComponent
358
    } // end of FiltersComponent
344
345
    private static class Space extends JComponent {
346
347
        private static final Dimension SPACE = new Dimension(3, 3);
348
349
        @Override
350
        public Dimension getPreferredSize() {
351
            return getMinimumSize();
352
        }
353
        @Override
354
        public Dimension getMaximumSize() {
355
            return getMinimumSize();
356
        }
357
        @Override
358
        public Dimension getMinimumSize() {
359
            return SPACE;
360
        }
361
    }
362
    
363
}
359
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/impl/RefactoringPanel.java (-101 / +159 lines)
Lines 57-68 Link Here
57
import java.lang.ref.WeakReference;
57
import java.lang.ref.WeakReference;
58
import java.lang.reflect.InvocationTargetException;
58
import java.lang.reflect.InvocationTargetException;
59
import java.util.*;
59
import java.util.*;
60
import java.util.Collection;
60
import java.util.Map.Entry;
61
import java.util.concurrent.atomic.AtomicBoolean;
61
import java.util.concurrent.atomic.AtomicBoolean;
62
import java.util.Map.Entry;
63
import java.util.prefs.Preferences;
62
import java.util.prefs.Preferences;
64
import javax.swing.*;
63
import javax.swing.*;
65
import javax.swing.border.EmptyBorder;
64
import javax.swing.border.EmptyBorder;
65
import javax.swing.event.ChangeEvent;
66
import javax.swing.text.html.HTMLEditorKit;
66
import javax.swing.text.html.HTMLEditorKit;
67
import javax.swing.text.html.parser.ParserDelegator;
67
import javax.swing.text.html.parser.ParserDelegator;
68
import javax.swing.tree.DefaultTreeModel;
68
import javax.swing.tree.DefaultTreeModel;
Lines 73-78 Link Here
73
import org.netbeans.api.project.*;
73
import org.netbeans.api.project.*;
74
import org.netbeans.modules.parsing.api.indexing.IndexingManager;
74
import org.netbeans.modules.parsing.api.indexing.IndexingManager;
75
import org.netbeans.modules.refactoring.api.*;
75
import org.netbeans.modules.refactoring.api.*;
76
import org.netbeans.modules.refactoring.api.impl.APIAccessor;
77
import org.netbeans.modules.refactoring.spi.ui.FiltersDescription;
76
import org.netbeans.modules.refactoring.spi.ui.RefactoringCustomUI;
78
import org.netbeans.modules.refactoring.spi.ui.RefactoringCustomUI;
77
import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
79
import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
78
import org.netbeans.modules.refactoring.spi.ui.TreeElement;
80
import org.netbeans.modules.refactoring.spi.ui.TreeElement;
Lines 85-92 Link Here
85
import org.openide.awt.Mnemonics;
87
import org.openide.awt.Mnemonics;
86
import org.openide.filesystems.FileObject;
88
import org.openide.filesystems.FileObject;
87
import org.openide.loaders.DataObject;
89
import org.openide.loaders.DataObject;
88
import org.openide.text.CloneableEditorSupport;
89
import org.openide.text.PositionBounds;
90
import org.openide.util.*;
90
import org.openide.util.*;
91
import org.openide.windows.TopComponent;
91
import org.openide.windows.TopComponent;
92
92
Lines 95-101 Link Here
95
 *
95
 *
96
 * @author  Pavel Flaska, Martin Matula
96
 * @author  Pavel Flaska, Martin Matula
97
 */
97
 */
98
public class RefactoringPanel extends JPanel {
98
public class RefactoringPanel extends JPanel implements FiltersManagerImpl.FilterChangeListener {
99
    private static final RequestProcessor RP = new RequestProcessor(RefactoringPanel.class.getName(), 1, false, false);
99
    private static final RequestProcessor RP = new RequestProcessor(RefactoringPanel.class.getName(), 1, false, false);
100
    
100
    
101
    // PRIVATE FIELDS
101
    // PRIVATE FIELDS
Lines 105-111 Link Here
105
    private transient JButton refreshButton = null;
105
    private transient JButton refreshButton = null;
106
    /* button lying in the toolbar allows expansion of all nodes in a tree */
106
    /* button lying in the toolbar allows expansion of all nodes in a tree */
107
    private transient JToggleButton expandButton = null;
107
    private transient JToggleButton expandButton = null;
108
    private JToolBar toolBar = null;
109
108
110
    private transient JButton refactorButton = null;
109
    private transient JButton refactorButton = null;
111
    private transient JButton cancelButton = null;
110
    private transient JButton cancelButton = null;
Lines 118-124 Link Here
118
    private transient boolean isVisible = false;
117
    private transient boolean isVisible = false;
119
    private transient RefactoringSession session = null;
118
    private transient RefactoringSession session = null;
120
    private transient ParametersPanel parametersPanel = null;
119
    private transient ParametersPanel parametersPanel = null;
121
    private transient JScrollPane scrollPane = null; 
120
    private transient JScrollPane scrollPane = null;
122
    private transient JPanel southPanel;
121
    private transient JPanel southPanel;
123
    public JSplitPane splitPane;
122
    public JSplitPane splitPane;
124
    private JPanel left;
123
    private JPanel left;
Lines 141-158 Link Here
141
    private Component customComponent;
140
    private Component customComponent;
142
    private AtomicBoolean cancelRequest = new AtomicBoolean();
141
    private AtomicBoolean cancelRequest = new AtomicBoolean();
143
    private int size = 0;
142
    private int size = 0;
144
145
146
    
143
    
147
    static Image PACKAGE_BADGE = ImageUtilities.loadImage( "org/netbeans/spi/java/project/support/ui/packageBadge.gif" ); // NOI18N
144
    static Image PACKAGE_BADGE = ImageUtilities.loadImage( "org/netbeans/spi/java/project/support/ui/packageBadge.gif" ); // NOI18N
145
    private FiltersManagerImpl filtersManager;
146
    private JComponent filterBar;
147
    private JPanel toolbars;
148
    
148
    
149
    public RefactoringPanel(RefactoringUI ui) {
149
    public RefactoringPanel(RefactoringUI ui) {
150
        this(ui,null);
150
        this(ui,null);
151
    }
151
    }
152
    
152
    
153
    public RefactoringPanel(RefactoringUI ui, TopComponent caller) {
153
    public RefactoringPanel(RefactoringUI ui, TopComponent caller) {
154
        if (caller!=null)
154
        if (caller!=null) {
155
            refCallerTC = new WeakReference<TopComponent>(caller);
155
            refCallerTC = new WeakReference<TopComponent>(caller);
156
        }
156
        this.ui = ui;
157
        this.ui = ui;
157
        this.isQuery = ui.isQuery();
158
        this.isQuery = ui.isQuery();
158
        if (isQuery) {
159
        if (isQuery) {
Lines 170-175 Link Here
170
            ui.getRefactoring().addProgressListener(fuListener = new FUListener());
171
            ui.getRefactoring().addProgressListener(fuListener = new FUListener());
171
        }
172
        }
172
        initialize();
173
        initialize();
174
        updateFilters();
173
        refresh(false);
175
        refresh(false);
174
    }
176
    }
175
    
177
    
Lines 181-188 Link Here
181
    
183
    
182
    /* initializes all the ui */
184
    /* initializes all the ui */
183
    private void initialize() {
185
    private void initialize() {
184
        if (inited)
186
        if (inited) {
185
            return ;
187
            return ;
188
        }
186
        checkEventThread();
189
        checkEventThread();
187
        setFocusCycleRoot(true);
190
        setFocusCycleRoot(true);
188
        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
191
        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
Lines 197-232 Link Here
197
        splitPane.setBorder(null);
200
        splitPane.setBorder(null);
198
        // add panel with buttons
201
        // add panel with buttons
199
        JButton[] buttons = getButtons();
202
        JButton[] buttons = getButtons();
200
        //if (buttons.length != 0) {
203
        // there will be at least one button on panel
201
            // there will be at least one button on panel
204
        southPanel = new JPanel(new GridBagLayout());
202
            southPanel = new JPanel(new GridBagLayout());
205
        for (int i = 0; i < buttons.length; i++) {
203
            for (int i = 0; i < buttons.length; i++) {
204
                GridBagConstraints c = new GridBagConstraints();
205
                c.gridy = 0;
206
                c.insets = new Insets(5, 5, 5, 0);
207
                southPanel.add(buttons[i], c);
208
            }
209
            JPanel pp = new JPanel(new BorderLayout());
210
            GridBagConstraints c = new GridBagConstraints();
206
            GridBagConstraints c = new GridBagConstraints();
211
            c.gridy = 0;
207
            c.gridy = 0;
212
            c.insets = new Insets(5, 5, 5, 5);
208
            c.insets = new Insets(5, 5, 5, 0);
213
            c.weightx = 1;
209
            southPanel.add(buttons[i], c);
214
            c.fill = GridBagConstraints.HORIZONTAL;
210
        }
215
            southPanel.add(pp, c);
211
        JPanel pp = new JPanel(new BorderLayout());
216
            
212
        GridBagConstraints c = new GridBagConstraints();
217
            if (!isQuery|| callback != null) {
213
        c.gridy = 0;
218
                left.add(southPanel, BorderLayout.SOUTH);
214
        c.insets = new Insets(5, 5, 5, 5);
219
            }
215
        c.weightx = 1;
220
        //}
216
        c.fill = GridBagConstraints.HORIZONTAL;
217
        southPanel.add(pp, c);
218
219
        if (!isQuery|| callback != null) {
220
            left.add(southPanel, BorderLayout.SOUTH);
221
        }
222
        if ("Aqua".equals(UIManager.getLookAndFeel().getID())) { //NOI18N
223
            southPanel.setBackground(UIManager.getColor("NbExplorerView.background"));
224
        }
221
        // put the toolbar to the panel. If the getToolBar() returns null,
225
        // put the toolbar to the panel. If the getToolBar() returns null,
222
        // suppose the toolbar does not exist.
226
        // suppose the toolbar does not exist.
223
        JToolBar toolBar = getToolBar();
227
        JToolBar toolbar = getToolBar();
224
        if ("Aqua".equals(UIManager.getLookAndFeel().getID())) { //NOI18N
228
        if (toolbar != null) {
225
            toolBar.setBackground(UIManager.getColor("NbExplorerView.background"));
229
            if ("Aqua".equals(UIManager.getLookAndFeel().getID())) { //NOI18N
226
            southPanel.setBackground(UIManager.getColor("NbExplorerView.background"));
230
                toolbar.setBackground(UIManager.getColor("NbExplorerView.background"));
231
            }
232
            toolbars = new JPanel(new BorderLayout());
233
            toolbars.add(toolbar, BorderLayout.WEST);
234
            left.add(toolbars, BorderLayout.WEST);
227
        }
235
        }
228
        if (toolBar != null)
229
            left.add(toolBar, BorderLayout.WEST);
230
        validate();
236
        validate();
231
        inited=true;
237
        inited=true;
232
    }
238
    }
Lines 267-275 Link Here
267
        );
273
        );
268
        expandButton.setBorderPainted(false);
274
        expandButton.setBorderPainted(false);
269
        expandButton.addActionListener(getButtonListener());
275
        expandButton.addActionListener(getButtonListener());
270
        // create toolbar
271
        toolBar = new JToolBar(JToolBar.VERTICAL);
272
        toolBar.setFloatable(false); 
273
        
276
        
274
        logicalViewButton = new JToggleButton(
277
        logicalViewButton = new JToggleButton(
275
            ImageUtilities.loadImageIcon("org/netbeans/modules/refactoring/api/resources/logical_view.png", false));
278
            ImageUtilities.loadImageIcon("org/netbeans/modules/refactoring/api/resources/logical_view.png", false));
Lines 360-378 Link Here
360
        stopButton.setBorderPainted(false);
363
        stopButton.setBorderPainted(false);
361
        stopButton.addActionListener(getButtonListener());
364
        stopButton.addActionListener(getButtonListener());
362
        
365
        
363
        
366
        // create toolbar
364
        toolBar.add(refreshButton);
367
        JToolBar toolbar = new JToolBar(JToolBar.VERTICAL);
365
        toolBar.add(prevMatch);
368
        toolbar.setFloatable(false);
366
        toolBar.add(nextMatch);
369
367
        toolBar.add(logicalViewButton);
370
        toolbar.add(refreshButton);
368
        toolBar.add(physicalViewButton);
371
        toolbar.add(stopButton);
369
        toolBar.add(expandButton);
372
        toolbar.add(prevMatch);
373
        toolbar.add(nextMatch);
374
        toolbar.add(logicalViewButton);
375
        toolbar.add(physicalViewButton);
376
        toolbar.add(expandButton);
370
        if (ui instanceof RefactoringCustomUI) {
377
        if (ui instanceof RefactoringCustomUI) {
371
            toolBar.add(customViewButton);
378
            toolbar.add(customViewButton);
372
        }
379
        }
373
        toolBar.add(stopButton);
380
        return toolbar;
374
        
375
        return toolBar;
376
    }
381
    }
377
    
382
    
378
    /**
383
    /**
Lines 381-387 Link Here
381
     * if you want to provide any other buttons with different action to be 
386
     * if you want to provide any other buttons with different action to be 
382
     * performed.
387
     * performed.
383
     *
388
     *
384
     * @return  array of avasilable buttons.
389
     * @return  array of available buttons.
385
     */
390
     */
386
    private JButton[] getButtons() {
391
    private JButton[] getButtons() {
387
        checkEventThread();
392
        checkEventThread();
Lines 416-423 Link Here
416
421
417
    void switchToLogicalView() {
422
    void switchToLogicalView() {
418
        logicalViewButton.setSelected(true);
423
        logicalViewButton.setSelected(true);
419
        if (currentView == LOGICAL)
424
        if (currentView == LOGICAL) {
420
            return ;
425
            return ;
426
        }
421
        currentView = LOGICAL;
427
        currentView = LOGICAL;
422
        physicalViewButton.setSelected(false);
428
        physicalViewButton.setSelected(false);
423
        if (customViewButton!=null) {
429
        if (customViewButton!=null) {
Lines 432-439 Link Here
432
    
438
    
433
    void switchToPhysicalView() {
439
    void switchToPhysicalView() {
434
        physicalViewButton.setSelected(true);
440
        physicalViewButton.setSelected(true);
435
        if (currentView == PHYSICAL)
441
        if (currentView == PHYSICAL) {
436
            return ;
442
            return ;
443
        }
437
        currentView = PHYSICAL;
444
        currentView = PHYSICAL;
438
        logicalViewButton.setSelected(false);
445
        logicalViewButton.setSelected(false);
439
        if (customViewButton!=null) {
446
        if (customViewButton!=null) {
Lines 448-455 Link Here
448
455
449
    void switchToCustomView() {
456
    void switchToCustomView() {
450
        customViewButton.setSelected(true);
457
        customViewButton.setSelected(true);
451
        if (currentView == GRAPHICAL)
458
        if (currentView == GRAPHICAL) {
452
            return ;
459
            return ;
460
        }
453
        currentView = GRAPHICAL;
461
        currentView = GRAPHICAL;
454
        logicalViewButton.setSelected(false);
462
        logicalViewButton.setSelected(false);
455
        physicalViewButton.setSelected(false);
463
        physicalViewButton.setSelected(false);
Lines 512-527 Link Here
512
        return node;
520
        return node;
513
    }
521
    }
514
    
522
    
515
    private static final String getString(String key) {
516
        return NbBundle.getMessage(RefactoringPanel.class, key);
517
    }
518
    
519
    /**
520
     * Overrides default ExplorerPanel behaviour. Does nothing now.
521
     */
522
    protected void updateTitle() {
523
    }
524
    
525
    /**
523
    /**
526
     * Method is responsible for making changes in sources.
524
     * Method is responsible for making changes in sources.
527
     */
525
     */
Lines 699-715 Link Here
699
        final RefactoringPanelContainer cont = isQuery ? RefactoringPanelContainer.getUsagesComponent() : RefactoringPanelContainer.getRefactoringComponent();
697
        final RefactoringPanelContainer cont = isQuery ? RefactoringPanelContainer.getUsagesComponent() : RefactoringPanelContainer.getRefactoringComponent();
700
        cont.makeBusy(true);
698
        cont.makeBusy(true);
701
        initialize();
699
        initialize();
700
        if(showParametersPanel) {
701
            updateFilters();
702
        }
702
703
703
        cancelRequest.set(false);
704
        cancelRequest.set(false);
704
        stopButton.setVisible(isQuery);
705
        stopButton.setVisible(isQuery && showParametersPanel);
706
        refreshButton.setVisible(!isQuery || !showParametersPanel);
705
        stopButton.setEnabled(showParametersPanel);
707
        stopButton.setEnabled(showParametersPanel);
706
        final String description = ui.getDescription();
708
        final String description = ui.getDescription();
707
        setToolTipText("<html>" + description + "</html>"); // NOI18N
709
        setToolTipText("<html>" + description + "</html>"); // NOI18N
708
        final Collection<RefactoringElement> elements = session.getRefactoringElements();
710
        final Collection<RefactoringElement> elements = session.getRefactoringElements();
709
        setName(ui.getName());
711
        setName(ui.getName());
710
        if (ui instanceof RefactoringCustomUI) {
712
        if (ui instanceof RefactoringCustomUI) {
711
            if (customComponent==null)
713
            if (customComponent==null) {
712
                customComponent = ((RefactoringCustomUI) ui).getCustomComponent(elements);
714
                customComponent = ((RefactoringCustomUI) ui).getCustomComponent(elements);
715
            }
713
            this.left.remove(customComponent);
716
            this.left.remove(customComponent);
714
        }
717
        }
715
        final ProgressHandle progressHandle = ProgressHandleFactory.createHandle(NbBundle.getMessage(RefactoringPanel.class, isQuery ? "LBL_PreparingUsagesTree":"LBL_PreparingRefactoringTree"));
718
        final ProgressHandle progressHandle = ProgressHandleFactory.createHandle(NbBundle.getMessage(RefactoringPanel.class, isQuery ? "LBL_PreparingUsagesTree":"LBL_PreparingRefactoringTree"));
Lines 727-733 Link Here
727
            RP.post(new Runnable() {
730
            RP.post(new Runnable() {
728
                @Override
731
                @Override
729
                public void run() {
732
                public void run() {
730
                    setTreeControlsEnabled(false);
733
                    SwingUtilities.invokeLater(new Runnable() {
734
                        @Override
735
                        public void run() {
736
                            setTreeControlsEnabled(false);
737
                        }
738
                    });
731
                    Set<FileObject> fileObjects = new HashSet<FileObject>();
739
                    Set<FileObject> fileObjects = new HashSet<FileObject>();
732
                    int errorsNum = 0;
740
                    int errorsNum = 0;
733
                    if (!isQuery) {
741
                    if (!isQuery) {
Lines 738-744 Link Here
738
                            }
746
                            }
739
                        }
747
                        }
740
                    }
748
                    }
741
                    StringBuffer errorsDesc = getErrorDesc(errorsNum, isQuery?size:elements.size());
749
                    StringBuffer errorsDesc = getErrorDesc(errorsNum, isQuery?size:elements.size(), 0);
742
                    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);
750
                    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);
743
                    final Map<Object, CheckNode> nodes = new HashMap<Object, CheckNode>();
751
                    final Map<Object, CheckNode> nodes = new HashMap<Object, CheckNode>();
744
                    
752
                    
Lines 755-768 Link Here
755
                    }
763
                    }
756
764
757
                    int i=0;
765
                    int i=0;
766
                    int hidden = 0;
758
                    try {
767
                    try {
759
                        //[retouche]                    JavaModel.getJavaRepository().beginTrans(false);
768
                        //[retouche]                    JavaModel.getJavaRepository().beginTrans(false);
760
                        try {
769
                        try {
761
                            // ui.getRefactoring().setClassPath();
770
                            // ui.getRefactoring().setClassPath();
762
                            for (Iterator it = elements.iterator(); it.hasNext();i++) {
771
                            for (Iterator it = elements.iterator(); it.hasNext();i++) {
763
                                final RefactoringElement e = (RefactoringElement) it.next();
772
                                final RefactoringElement e = (RefactoringElement) it.next();
764
                                createNode(TreeElementFactory.getTreeElement(e), nodes, root);
773
                                if(e.include(filtersManager)) {
765
                                
774
                                    createNode(TreeElementFactory.getTreeElement(e), nodes, root);
775
                                } else {
776
                                    hidden++;
777
                                }
766
                                if (isQuery && showParametersPanel) {
778
                                if (isQuery && showParametersPanel) {
767
                                    if (cancelRequest.get()) {
779
                                    if (cancelRequest.get()) {
768
                                        break;
780
                                        break;
Lines 770-782 Link Here
770
782
771
                                    final boolean last = !it.hasNext();
783
                                    final boolean last = !it.hasNext();
772
                                    final int occurrences = i + 1;
784
                                    final int occurrences = i + 1;
785
                                    final int hiddenOccurrences = hidden;
773
                                    size = occurrences;
786
                                    size = occurrences;
774
                                    if (occurrences % 10 == 0 || last) {
787
                                    boolean finished = APIAccessor.DEFAULT.isFinished(session);
788
                                    if ((occurrences % 10 == 0 && !finished) || last) {
775
                                        SwingUtilities.invokeLater(new Runnable() {
789
                                        SwingUtilities.invokeLater(new Runnable() {
776
790
777
                                            @Override
791
                                            @Override
778
                                            public void run() {
792
                                            public void run() {
779
                                                root.setNodeLabel(description + getErrorDesc(0, occurrences));
793
                                                root.setNodeLabel(description + getErrorDesc(0, occurrences, hiddenOccurrences));
780
                                                if (last) {
794
                                                if (last) {
781
                                                    tree.repaint();
795
                                                    tree.repaint();
782
                                                }
796
                                                }
Lines 784-790 Link Here
784
                                        });
798
                                        });
785
                                    }
799
                                    }
786
                                }
800
                                }
787
                                PositionBounds pb = e.getPosition();
801
//                                PositionBounds pb = e.getPosition();
788
                                fileObjects.add(e.getParentFile());
802
                                fileObjects.add(e.getParentFile());
789
                                
803
                                
790
                                if (!isQuery) {
804
                                if (!isQuery) {
Lines 808-829 Link Here
808
                    } finally {
822
                    } finally {
809
                        progressHandle.finish();
823
                        progressHandle.finish();
810
                        cont.makeBusy(false);
824
                        cont.makeBusy(false);
811
                        setTreeControlsEnabled(true);
812
                        SwingUtilities.invokeLater(new Runnable() {
825
                        SwingUtilities.invokeLater(new Runnable() {
813
                            @Override
826
                            @Override
814
                            public void run() {
827
                            public void run() {
828
                                setTreeControlsEnabled(true);
815
                                stopButton.setEnabled(false);
829
                                stopButton.setEnabled(false);
830
                                stopButton.setVisible(false);
831
                                refreshButton.setVisible(true);
832
                                if(showParametersPanel) {
833
                                    updateFilters();
834
                                }
816
                            }
835
                            }
817
                        });
836
                        });
818
                    }
837
                    }
819
                    
838
                    
820
                    if (!(isQuery && showParametersPanel)) {
839
                    if (!(isQuery && showParametersPanel)) {
840
                        root.setNodeLabel(description + getErrorDesc(errorsNum, isQuery?size:elements.size(), hidden).toString());
821
                        setupTree(root, showParametersPanel, elements.size());
841
                        setupTree(root, showParametersPanel, elements.size());
822
                    }
842
                    }
823
                    
843
                    
824
                }
844
                }
825
845
826
                private StringBuffer getErrorDesc(int errorsNum, int occurencesNum) throws MissingResourceException {
846
                private StringBuffer getErrorDesc(int errorsNum, int occurencesNum, int hiddenNum) throws MissingResourceException {
827
                    StringBuffer errorsDesc = new StringBuffer();
847
                    StringBuffer errorsDesc = new StringBuffer();
828
                    errorsDesc.append(" [").append(occurencesNum); // NOI18N
848
                    errorsDesc.append(" [").append(occurencesNum); // NOI18N
829
                    errorsDesc.append(' ');
849
                    errorsDesc.append(' ');
Lines 842-847 Link Here
842
                            );
862
                            );
843
                        errorsDesc.append("</font>"); // NOI18N
863
                        errorsDesc.append("</font>"); // NOI18N
844
                    }
864
                    }
865
                    if (hiddenNum > 0) {
866
                        errorsDesc.append(',');
867
                        errorsDesc.append(' ');
868
                        errorsDesc.append("<font color=#CC0000>").append(hiddenNum); // NOI18N
869
                        errorsDesc.append(' ');
870
                        errorsDesc.append(NbBundle.getMessage(RefactoringPanel.class, "LBL_Hidden"));
871
                        errorsDesc.append("</font>"); // NOI18N
872
                    }
845
                    errorsDesc.append(']');
873
                    errorsDesc.append(']');
846
                    return errorsDesc;
874
                    return errorsDesc;
847
                }
875
                }
Lines 858-879 Link Here
858
            cont.addPanel(this);
886
            cont.addPanel(this);
859
            isVisible = true;
887
            isVisible = true;
860
        }
888
        }
861
        if (!isQuery)
889
        if (!isQuery) {
862
            setRefactoringEnabled(false, true);
890
            setRefactoringEnabled(false, true);
891
        }
863
    }
892
    }
864
    
893
    
865
    private void setTreeControlsEnabled(final boolean b) {
894
    private void setTreeControlsEnabled(final boolean b) {
866
        SwingUtilities.invokeLater(new Runnable() {
895
        expandButton.setEnabled(b);
867
896
        logicalViewButton.setEnabled(b);
868
            @Override
897
        physicalViewButton.setEnabled(b);
869
            public void run() {
898
        if (customViewButton != null) {
870
                expandButton.setEnabled(b);
899
            customViewButton.setEnabled(b);
871
                logicalViewButton.setEnabled(b);
900
        }
872
                physicalViewButton.setEnabled(b);
873
                if (customViewButton != null)
874
                    customViewButton.setEnabled(b);
875
            }
876
        });
877
    }
901
    }
878
    
902
    
879
    
903
    
Lines 924-944 Link Here
924
         }
948
         }
925
     }
949
     }
926
     
950
     
927
     /**
951
    /**
928
      * @return true if timestamps are OK
952
     * @return true if timestamps are OK
929
      */
953
     */
930
     private boolean checkTimeStamps() {
954
    private boolean checkTimeStamps() {
931
         Set<FileObject> modified = getModifiedFileObjects();
955
        Set<FileObject> modified = getModifiedFileObjects();
932
         for (Entry<FileObject, Long> entry: timeStamps.entrySet()) {
956
         for (Entry<FileObject, Long> entry: timeStamps.entrySet()) {
933
             if (modified.contains(entry.getKey()))
957
             if (modified.contains(entry.getKey()))
934
                 return false;
958
                return false;
935
             if (!entry.getKey().isValid())
959
             if (!entry.getKey().isValid())
936
                 return false;
960
                 return false;
937
             if (entry.getKey().lastModified().getTime() != entry.getValue())
961
             if (entry.getKey().lastModified().getTime() != entry.getValue())
938
                 return false;
962
                 return false;
939
         }
963
            }
940
         return true;
964
        return true;
941
     }
965
    }
942
     
966
     
943
     private Set<FileObject> getModifiedFileObjects() {
967
     private Set<FileObject> getModifiedFileObjects() {
944
         Set<FileObject> result = new HashSet();
968
         Set<FileObject> result = new HashSet();
Lines 998-1005 Link Here
998
        if (refactorButton != null) {
1022
        if (refactorButton != null) {
999
            refactorButton.requestFocus();
1023
            refactorButton.requestFocus();
1000
        } else {
1024
        } else {
1001
            if (tree!=null)
1025
            if (tree!=null) {
1002
                tree.requestFocus();
1026
                tree.requestFocus();
1027
            }
1003
        }
1028
        }
1004
    }
1029
    }
1005
    
1030
    
Lines 1047-1059 Link Here
1047
    
1072
    
1048
    private int location;
1073
    private int location;
1049
    public void storeDividerLocation() {
1074
    public void storeDividerLocation() {
1050
        if (splitPane.getRightComponent()!=null)
1075
        if (splitPane.getRightComponent()!=null) {
1051
            location = splitPane.getDividerLocation();
1076
            location = splitPane.getDividerLocation();
1077
        }
1052
    }
1078
    }
1053
    
1079
    
1054
    public void restoreDeviderLocation() {
1080
    public void restoreDeviderLocation() {
1055
        if (splitPane.getRightComponent()!=null)
1081
        if (splitPane.getRightComponent()!=null) {
1056
            splitPane.setDividerLocation(location);
1082
            splitPane.setDividerLocation(location);
1083
        }
1057
    }
1084
    }
1058
1085
1059
    private byte getPrefViewType() {
1086
    private byte getPrefViewType() {
Lines 1067-1072 Link Here
1067
        prefs.putInt(PREF_VIEW_TYPE, currentView);
1094
        prefs.putInt(PREF_VIEW_TYPE, currentView);
1068
    }
1095
    }
1069
1096
1097
    private void updateFilters() {
1098
        if(!ui.isQuery()) {
1099
            if(filterBar != null) {
1100
                toolbars.remove(filterBar);
1101
                filterBar = null;
1102
                filtersManager = null;
1103
            }
1104
            return;
1105
        }
1106
1107
        if(filtersManager != null) {
1108
            toolbars.remove(filterBar);
1109
            filterBar = null;
1110
            filtersManager = null;
1111
        }
1112
        final FiltersDescription desc = APIAccessor.DEFAULT.getFiltersDescription(ui.getRefactoring());
1113
        filtersManager = FiltersManagerImpl.create(desc == null? new FiltersDescription() : desc);
1114
        filterBar = filtersManager.getComponent();
1115
        toolbars.add(filterBar, BorderLayout.EAST);
1116
        filtersManager.hookChangeListener(this);
1117
        toolbars.validate();
1118
    }
1119
1120
    @Override
1121
    public void filterStateChanged(ChangeEvent e) {
1122
        refresh(false);
1123
    }
1124
1070
    ////////////////////////////////////////////////////////////////////////////
1125
    ////////////////////////////////////////////////////////////////////////////
1071
    // INNER CLASSES
1126
    // INNER CLASSES
1072
    ////////////////////////////////////////////////////////////////////////////
1127
    ////////////////////////////////////////////////////////////////////////////
Lines 1086-1095 Link Here
1086
            }
1141
            }
1087
            // expandAll button selected/deselected
1142
            // expandAll button selected/deselected
1088
            else if (o == expandButton && tree != null) {
1143
            else if (o == expandButton && tree != null) {
1089
                if (expandButton.isSelected())
1144
                if (expandButton.isSelected()) {
1090
                    expandAll();
1145
                    expandAll();
1091
                else
1146
                } else {
1092
                    collapseAll();
1147
                    collapseAll();
1148
                }
1093
            } else if (o == refreshButton) {
1149
            } else if (o == refreshButton) {
1094
                if (callback!=null) {
1150
                if (callback!=null) {
1095
                    close();
1151
                    close();
Lines 1117-1122 Link Here
1117
1173
1118
    private void stopSearch() {
1174
    private void stopSearch() {
1119
        stopButton.setEnabled(false);
1175
        stopButton.setEnabled(false);
1176
        stopButton.setVisible(false);
1177
        refreshButton.setVisible(true);
1120
        cancelRequest.set(true);
1178
        cancelRequest.set(true);
1121
        ui.getRefactoring().cancelRequest();
1179
        ui.getRefactoring().cancelRequest();
1122
    }
1180
    }
(-)a/java.navigation/src/org/netbeans/modules/java/navigation/base/FiltersDescription.java (-51 / +154 lines)
Lines 41-123 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
44
package org.netbeans.modules.refactoring.spi.ui;
45
package org.netbeans.modules.java.navigation.base;
46
45
47
import java.util.ArrayList;
46
import java.util.ArrayList;
48
import java.util.List;
47
import java.util.List;
49
import javax.swing.Icon;
48
import javax.swing.Icon;
49
import org.netbeans.api.annotations.common.NonNull;
50
50
51
/**
51
/**
52
 * @author Dafe Simonek
52
 * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
53
 * @since 1.29
53
 */
54
 */
54
public final class FiltersDescription {
55
public final class FiltersDescription {
55
56
56
    public static FiltersManager createManager (FiltersDescription descr) {
57
    /**
57
        return FiltersManager.create(descr);
58
     * List of {@code FilterItem}s describing filters properties
58
    }
59
     */
59
60
    /** List of <FilterItem> describing filters properties */
61
    private List<FilterItem> filters;
60
    private List<FilterItem> filters;
62
61
63
    /** Creates a new instance of FiltersDescription */
62
    /**
63
     * Creates a new instance of FiltersDescription
64
     */
64
    public FiltersDescription() {
65
    public FiltersDescription() {
65
        filters = new ArrayList<FilterItem>();
66
        filters = new ArrayList<FilterItem>();
66
    }
67
    }
67
    
68
68
    public void addFilter (String name, String displayName, String tooltip,
69
    /**
69
            boolean isSelected, Icon selectedIcon, Icon unselectedIcon) {
70
     * Add a new filter to the FiltersDescription. Filters are by default
70
        FilterItem newItem = new FilterItem(name, displayName, tooltip, 
71
     * disabled. {@code FiltersDescription.Provider}s should enable them when
71
                isSelected, selectedIcon, unselectedIcon);
72
     * used.
73
     *
74
     * @param key identifier for the filter
75
     * @param tooltip text to display in the tooltip of the filter button
76
     * @param selected true if the filter should be selected
77
     * @param icon icon to use for the filter button
78
     */
79
    public void addFilter(@NonNull String key, @NonNull String tooltip,
80
            boolean selected, @NonNull Icon icon) {
81
        FilterItem newItem = new FilterItem(key, tooltip, selected, icon);
72
        filters.add(newItem);
82
        filters.add(newItem);
73
    }
83
    }
74
    
84
75
    public int getFilterCount () {
85
    /**
86
     * Returns the number of filters in this description.
87
     *
88
     * @return the number of filters in this description
89
     */
90
    public int getFilterCount() {
76
        return filters.size();
91
        return filters.size();
77
    }
92
    }
78
    
93
79
    public String getName (int index) {
94
    /**
80
        return filters.get(index).name;
95
     * Returns the key of the filter at the supplied index.
96
     *
97
     * @param index the index of the filter
98
     * @return the key
99
     * @throws IndexOutOfBoundsException if the index is out of range
100
     * ({@code index < 0 || index >= size()})
101
     */
102
    public @NonNull
103
    String getKey(int index) {
104
        return filters.get(index).key;
81
    }
105
    }
82
    
106
83
    public String getDisplayName (int index) {
107
    /**
84
        return filters.get(index).displayName;
108
     * Returns the tooltip of the filter at the supplied index.
85
    }
109
     *
86
    
110
     * @param index the index of the filter
87
    public String getTooltip (int index) {
111
     * @return the tooltip
112
     * @throws IndexOutOfBoundsException if the index is out of range
113
     * ({@code index < 0 || index >= size()})
114
     */
115
    public @NonNull
116
    String getTooltip(int index) {
88
        return filters.get(index).tooltip;
117
        return filters.get(index).tooltip;
89
    }
118
    }
90
    
119
91
    public Icon getSelectedIcon (int index) {
120
    /**
92
        return filters.get(index).selectedIcon;
121
     * Returns the icon of the filter at the supplied index.
122
     *
123
     * @param index the index of the filter
124
     * @return the icon
125
     * @throws IndexOutOfBoundsException if the index is out of range
126
     * ({@code index < 0 || index >= size()})
127
     */
128
    public @NonNull
129
    Icon getIcon(int index) {
130
        return filters.get(index).icon;
93
    }
131
    }
94
    
132
95
    public Icon getUnselectedIcon (int index) {
133
    /**
96
        return filters.get(index).unselectedIcon;
134
     * Returns true if the filter at the supplied index is selected.
135
     *
136
     * @param index the index of the filter
137
     * @return true if the filter is selected.
138
     * @throws IndexOutOfBoundsException if the index is out of range
139
     * ({@code index < 0 || index >= size()})
140
     */
141
    public boolean isSelected(int index) {
142
        return filters.get(index).selected;
97
    }
143
    }
98
    
144
99
    public boolean isSelected (int index) {
145
    /**
100
        return filters.get(index).isSelected;
146
     * Enable the filter at the supplied index.
147
     *
148
     * @param index the index of the filter
149
     * @throws IndexOutOfBoundsException if the index is out of range
150
     * ({@code index < 0 || index >= size()})
151
     */
152
    public void enable(int index) {
153
        filters.get(index).enabled = true;
101
    }
154
    }
102
    
155
103
    static class FilterItem {
156
    /**
104
        String name;
157
     * Enable the filter with the supplied key. If there is no filter with the
105
        String displayName;
158
     * supplied key, nothing will change.
159
     *
160
     * @param key the key of a filter
161
     */
162
    public void enable(@NonNull String key) {
163
        for (FilterItem filterItem : filters) {
164
            if (filterItem.key.contentEquals(key)) {
165
                filterItem.enabled = true;
166
                break;
167
            }
168
        }
169
    }
170
171
    /**
172
     * Returns true if the filter at the supplied index is enabled.
173
     *
174
     * @param index the index of the filter
175
     * @return true if the filter is enabled.
176
     * @throws IndexOutOfBoundsException if the index is out of range
177
     * ({@code index < 0 || index >= size()})
178
     */
179
    public boolean isEnabled(int index) {
180
        return filters.get(index).enabled;
181
    }
182
183
    private static class FilterItem {
184
185
        String key;
106
        String tooltip;
186
        String tooltip;
107
        Icon selectedIcon;
187
        Icon icon;
108
        Icon unselectedIcon;
188
        boolean selected;
109
        boolean isSelected;
189
        boolean enabled;
110
        
190
111
        FilterItem (String name, String displayName, String tooltip,
191
        FilterItem(String key, String tooltip,
112
                boolean isSelected, Icon selectedIcon, Icon unselectedIcon) {
192
                boolean selected, Icon icon) {
113
            this.name = name;
193
            this.key = key;
114
            this.displayName = displayName;
115
            this.tooltip = tooltip;
194
            this.tooltip = tooltip;
116
            this.selectedIcon = selectedIcon;
195
            this.icon = icon;
117
            this.unselectedIcon = unselectedIcon;
196
            this.selected = selected;
118
            this.isSelected = isSelected;
197
            this.enabled = false;
119
        }
198
        }
120
        
121
    }
199
    }
122
    
200
201
    /**
202
     * {@code RefactoringPlugin}s can implement this interface if they want to
203
     * supply new filters, or enable existing filters.
204
     */
205
    public static interface Provider {
206
207
        /**
208
         * Add filters to the supplied {@code FiltersDescription}. This method
209
         * will be called after the plugin is received from the
210
         * {@code RefactoringPluginFactory}.
211
         *
212
         * @param filtersDescription the {@code FiltersDescription} to add filters to
213
         * @see FiltersDescription#addFilter
214
         */
215
        void addFilters(FiltersDescription filtersDescription);
216
217
        /**
218
         * Enable filters in the supplied {@code FiltersDescription}. This method
219
         * will be called after the plugins {@code RefactoringPlugin#prepare} method is called.
220
         *
221
         * @param filtersDescription the {@code FiltersDescription} to enable filters from
222
         * @see FiltersDescription#enable
223
         */
224
        void enableFilters(FiltersDescription filtersDescription);
225
    }
123
}
226
}

Return to bug 215361