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/apichanges.xml (+20 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="ServerSideQueries">
53
        <api name="refactoring"/>
54
        <summary>Added support for Scope Providers and ExpandableTreeElements.</summary>
55
        <version major="1" minor="30"/>
56
        <date day="31" month="8" year="2012"/>
57
        <author login="ralphbenjamin"/>
58
        <compatibility addition="yes"/>
59
        <description>
60
            <p>
61
                Added an ExpandableTreeElement and a declarative way to add new scopes.
62
            </p>
63
        </description>
64
        <class package="org.netbeans.modules.refactoring.spi.ui" name="ExpandableTreeElement"/>
65
        <class package="org.netbeans.modules.refactoring.spi.ui" name="ScopeProvider"/>
66
        <class package="org.netbeans.modules.refactoring.spi.ui" name="ScopeDescription"/>
67
        <class package="org.netbeans.modules.refactoring.spi.ui" name="ScopeReference"/>
68
        <class package="org.netbeans.modules.refactoring.spi.ui" name="ScopeReferences"/>
69
        <class package="org.netbeans.modules.refactoring.spi.ui" name="ScopePanel"/>
70
        <issue number="217347"/>
71
    </change>
52
    <change id="RefactoringResultsFilters">
72
    <change id="RefactoringResultsFilters">
53
        <api name="refactoring"/>
73
        <api name="refactoring"/>
54
        <summary>Added an API to support filters of the Find Usages results.</summary>
74
        <summary>Added an API to support filters of the Find Usages results.</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.29.0
7
spec.version.base=1.30.0
8
test.config.stableBTD.includes=**/*Test.class
8
test.config.stableBTD.includes=**/*Test.class
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/ui/Bundle.properties (+1 lines)
Line 0 Link Here
1
LBL_Scope=Sco&pe:
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/ui/ExpandableTreeElement.java (+67 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.ui;
43
44
import org.openide.util.Cancellable;
45
46
/**
47
 * ExpandableTreeElements are shown in the Find Usages results.
48
 * ExpandableTreeElement allows a TreeElement to have children. It will be
49
 * iterated when the TreeElement is expanded. The iterator is allowed to block,
50
 * it will be called from outside of AWT.
51
 * 
52
 * @author Jan Lahoda
53
 * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
54
 * @see TreeElement
55
 * @since 1.30
56
 */
57
public interface ExpandableTreeElement extends TreeElement, Iterable<TreeElement>, Cancellable {
58
59
    /**
60
     * Gives an estimate of the amount of children this element has.
61
     * The estimatedChildCount will be used to give the user a rough count
62
     * of found occurrences.
63
     * @return the estimated child count
64
     */
65
    public int estimateChildCount();
66
    
67
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/ui/ScopePanel.form (+58 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
5
    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
6
    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
7
    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
8
    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
9
    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
10
    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
11
    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
12
    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
13
    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
14
  </AuxValues>
15
16
  <Layout>
17
    <DimensionLayout dim="0">
18
      <Group type="103" groupAlignment="0" attributes="0">
19
          <Group type="102" alignment="0" attributes="0">
20
              <Component id="scopeCombobox" pref="343" max="32767" attributes="0"/>
21
              <EmptySpace max="-2" attributes="0"/>
22
              <Component id="btnCustomScope" min="-2" max="-2" attributes="0"/>
23
          </Group>
24
      </Group>
25
    </DimensionLayout>
26
    <DimensionLayout dim="1">
27
      <Group type="103" groupAlignment="0" attributes="0">
28
          <Group type="103" alignment="0" groupAlignment="3" attributes="0">
29
              <Component id="btnCustomScope" alignment="3" min="-2" max="-2" attributes="0"/>
30
              <Component id="scopeCombobox" alignment="3" min="-2" max="-2" attributes="1"/>
31
          </Group>
32
      </Group>
33
    </DimensionLayout>
34
  </Layout>
35
  <SubComponents>
36
    <Component class="javax.swing.JButton" name="btnCustomScope">
37
      <Properties>
38
        <Property name="action" type="javax.swing.Action" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
39
          <Connection code="new ScopeAction(scopeCombobox)" type="code"/>
40
        </Property>
41
        <Property name="text" type="java.lang.String" value="..." noResource="true"/>
42
      </Properties>
43
    </Component>
44
    <Component class="javax.swing.JComboBox" name="scopeCombobox">
45
      <Properties>
46
        <Property name="renderer" type="javax.swing.ListCellRenderer" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
47
          <Connection code="new ScopeDescriptionRenderer()" type="code"/>
48
        </Property>
49
      </Properties>
50
      <Events>
51
        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="scopeComboboxActionPerformed"/>
52
      </Events>
53
      <AuxValues>
54
        <AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="((javax.swing.JTextField) scopeCombobox.getEditor().getEditorComponent()).setColumns(SCOPE_COMBOBOX_COLUMNS);"/>
55
      </AuxValues>
56
    </Component>
57
  </SubComponents>
58
</Form>
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/ui/ScopePanel.java (+373 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.ui;
43
44
import java.awt.Component;
45
import java.awt.event.ActionEvent;
46
import java.util.ArrayList;
47
import java.util.Collection;
48
import java.util.Collections;
49
import java.util.Comparator;
50
import java.util.List;
51
import java.util.concurrent.atomic.AtomicBoolean;
52
import java.util.prefs.Preferences;
53
import javax.swing.AbstractAction;
54
import javax.swing.ComboBoxModel;
55
import javax.swing.DefaultComboBoxModel;
56
import javax.swing.JComboBox;
57
import javax.swing.JLabel;
58
import javax.swing.JList;
59
import javax.swing.ListCellRenderer;
60
import javax.swing.SwingUtilities;
61
import javax.swing.plaf.UIResource;
62
import org.netbeans.api.annotations.common.CheckForNull;
63
import org.netbeans.api.annotations.common.NonNull;
64
import org.netbeans.modules.refactoring.api.Scope;
65
import org.netbeans.modules.refactoring.spi.impl.DelegatingCustomScopeProvider;
66
import org.netbeans.modules.refactoring.spi.impl.DelegatingScopeInformation;
67
import org.openide.util.Lookup;
68
import org.openide.util.lookup.Lookups;
69
70
/**
71
 * ScopePanel provides a component to use for scope selection. A customize
72
 * button (a JButton with ellipses) will be displayed when any of the registered
73
 * scopes is customizable.
74
 *
75
 * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
76
 * @since 1.30
77
 */
78
public final class ScopePanel extends javax.swing.JPanel {
79
80
    private static final String ELLIPSIS = "\u2026"; //NOI18N
81
    private static final int SCOPE_COMBOBOX_COLUMNS = 14;
82
    private final String id;
83
    private final Preferences preferences;
84
    private final String preferencesKey;
85
    private ArrayList<DelegatingScopeInformation> scopes;
86
87
    /**
88
     * Creates new form ScopePanel.
89
     *
90
     * @deprecated do not use this constructor. Only available for the Matisse
91
     * GUI-builder.
92
     */
93
    @Deprecated
94
    public ScopePanel() {
95
        this(null, null, null);
96
    }
97
98
    /**
99
     * Creates a new ScopePanel. The supplied id will be used to only get the
100
     * Scopes registered for a specific set of Scopes. The preferences and
101
     * preferencesKey will be used to store the user's selection.
102
     *
103
     * @param id the id for which the scopes are registered
104
     * @param preferences a preferences object to store user's selection
105
     * @param preferencesKey a key to use to store user's selection
106
     */
107
    public ScopePanel(String id, Preferences preferences, String preferencesKey) {
108
        this.id = id;
109
        this.preferences = preferences;
110
        this.preferencesKey = preferencesKey;
111
        this.scopes = new ArrayList<DelegatingScopeInformation>();
112
        initComponents();
113
    }
114
115
    /**
116
     * Initializes the Combobox and customize button of this ScopePanel. The
117
     * context will be passed to the different ScopeProviders initialize method.
118
     * This method will return false if there are no available scopes and this
119
     * panel should not be available to the user.
120
     *
121
     * @param context the Lookup to pass to the ScopeProviders
122
     * @return true if there is at least one Scope available, false otherwise
123
     */
124
    public boolean initialize(Lookup context, AtomicBoolean cancel) {
125
        scopes.clear();
126
        Collection<? extends ScopeProvider> scopeProviders = Lookups.forPath("Scopes" + "/" + id).lookupAll(ScopeProvider.class);
127
        final AtomicBoolean customizable = new AtomicBoolean();
128
        for (ScopeProvider provider : scopeProviders) {
129
            if (provider.initialize(context, new AtomicBoolean())) {
130
                scopes.add((DelegatingScopeInformation)provider);
131
                if (provider instanceof ScopeProvider.CustomScopeProvider) {
132
                    customizable.set(true);
133
                }
134
            }
135
        }
136
137
        Collections.sort(scopes, new Comparator<DelegatingScopeInformation>() {
138
            @Override
139
            public int compare(DelegatingScopeInformation o1, DelegatingScopeInformation o2) {
140
                return (o1.getPosition() < o2.getPosition() ? -1 : (o1.getPosition() == o2.getPosition() ? 0 : 1));
141
            }
142
        });
143
        if (!scopes.isEmpty()) {
144
            SwingUtilities.invokeLater(new Runnable() {
145
                @Override
146
                public void run() {
147
                    scopeCombobox.setModel(new DefaultComboBoxModel(scopes.toArray(new ScopeProvider[scopes.size()])));
148
                    for (DelegatingScopeInformation scopeProvider : scopes) {
149
                        if(scopeProvider instanceof ScopeProvider.CustomScopeProvider) {
150
                            ScopePanel.this.btnCustomScope.setVisible(false);
151
                            break;
152
                        }
153
                    }
154
                    String preselectId = preferences.get(preferencesKey, null);
155
                    if (preselectId == null) { // Needed for the old preferences of Java's Where Used Panel.
156
                        int defaultItem = (Integer) preferences.getInt(preferencesKey, -1); // NOI18N
157
                        if (defaultItem != (-1)) {
158
                            switch (defaultItem) {
159
                                case 0:
160
                                    preselectId = "all-projects";
161
                                    break;
162
                                case 1:
163
                                    preselectId = "current-project";
164
                                    break;
165
                                case 2:
166
                                    preselectId = "current-package";
167
                                    break;
168
                                case 3:
169
                                    preselectId = "current-file";
170
                                    break;
171
                                case 4:
172
                                    preselectId = "custom-scope";
173
                                    break;
174
                            }
175
                        }
176
                    }
177
                    if (preselectId != null) {
178
                        selectScopeById(preselectId);
179
                    } else {
180
                        selectPreferredScope();
181
                    }
182
                }
183
            });
184
        }
185
        return !scopes.isEmpty();
186
    }
187
188
    /**
189
     * The currently selected scope in the Combobox. This can be a predefined
190
     * scope, or a customized one.
191
     *
192
     * @return the selected Scope
193
     */
194
    @CheckForNull
195
    public Scope getSelectedScope() {
196
        return ((ScopeProvider) scopeCombobox.getSelectedItem()).getScope();
197
    }
198
199
    /**
200
     * Change the selected scope to one with the specified id. If the id does
201
     * not exist, nothing is changed. When the id is from a CustomScopeProvider
202
     * and it returns an empty scope, the preferred scope is selected.
203
     *
204
     * @see ScopeProvider.CustomScopeProvider
205
     *
206
     * @param id the id of the scope to select
207
     */
208
    public void selectScopeById(@NonNull String id) {
209
        ComboBoxModel m = scopeCombobox.getModel();
210
211
        for (int i = 0; i < m.getSize(); i++) {
212
            DelegatingScopeInformation sd = (DelegatingScopeInformation) m.getElementAt(i);
213
214
            if (sd.getId().equals(id)) {
215
                if (sd instanceof ScopeProvider.CustomScopeProvider) {
216
                    Scope s = sd.getScope();
217
                    if (s != null
218
                            && s.getFiles().isEmpty()
219
                            && s.getFolders().isEmpty()
220
                            && s.getSourceRoots().isEmpty()) {
221
                        selectPreferredScope();
222
                        return;
223
                    }
224
                }
225
                scopeCombobox.setSelectedItem(sd);
226
                return;
227
            }
228
        }
229
    }
230
231
    /**
232
     * This method is called from within the constructor to initialize the form.
233
     * WARNING: Do NOT modify this code. The content of this method is always
234
     * regenerated by the Form Editor.
235
     */
236
    @SuppressWarnings("unchecked")
237
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
238
    private void initComponents() {
239
240
        btnCustomScope = new javax.swing.JButton();
241
        scopeCombobox = new javax.swing.JComboBox();
242
243
        btnCustomScope.setAction(new ScopeAction(scopeCombobox));
244
        org.openide.awt.Mnemonics.setLocalizedText(btnCustomScope, "..."); // NOI18N
245
246
        scopeCombobox.setRenderer(new ScopeDescriptionRenderer());
247
        ((javax.swing.JTextField) scopeCombobox.getEditor().getEditorComponent()).setColumns(SCOPE_COMBOBOX_COLUMNS);
248
        scopeCombobox.addActionListener(new java.awt.event.ActionListener() {
249
            public void actionPerformed(java.awt.event.ActionEvent evt) {
250
                scopeComboboxActionPerformed(evt);
251
            }
252
        });
253
254
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
255
        this.setLayout(layout);
256
        layout.setHorizontalGroup(
257
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
258
            .addGroup(layout.createSequentialGroup()
259
                .addComponent(scopeCombobox, 0, 343, Short.MAX_VALUE)
260
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
261
                .addComponent(btnCustomScope))
262
        );
263
        layout.setVerticalGroup(
264
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
265
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
266
                .addComponent(btnCustomScope)
267
                .addComponent(scopeCombobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
268
        );
269
    }// </editor-fold>//GEN-END:initComponents
270
271
    private void scopeComboboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_scopeComboboxActionPerformed
272
        preferences.putInt(preferencesKey, scopeCombobox.getSelectedIndex());
273
    }//GEN-LAST:event_scopeComboboxActionPerformed
274
    // Variables declaration - do not modify//GEN-BEGIN:variables
275
    private javax.swing.JButton btnCustomScope;
276
    private javax.swing.JComboBox scopeCombobox;
277
    // End of variables declaration//GEN-END:variables
278
279
    private void selectPreferredScope() {
280
        ComboBoxModel m = scopeCombobox.getModel();
281
282
        for (int i = 0; i < m.getSize(); i++) {
283
            DelegatingScopeInformation sd = (DelegatingScopeInformation) m.getElementAt(i);
284
285
            if (sd.getPosition() >= 0) {
286
                scopeCombobox.setSelectedItem(sd);
287
                return;
288
            }
289
        }
290
    }
291
292
    private class ScopeAction extends AbstractAction {
293
294
        private final JComboBox scopeCombobox;
295
296
        private ScopeAction(JComboBox scopeCombobox) {
297
            this.scopeCombobox = scopeCombobox;
298
            this.putValue(NAME, ELLIPSIS);
299
        }
300
301
        @Override
302
        public void actionPerformed(ActionEvent e) {
303
            ComboBoxModel m = this.scopeCombobox.getModel();
304
            ScopeProvider selectedScope = (ScopeProvider) scopeCombobox.getSelectedItem();
305
            Scope scope = selectedScope.getScope();
306
            if (selectedScope instanceof DelegatingCustomScopeProvider) {
307
                showCustomizer((DelegatingCustomScopeProvider) selectedScope, scope);
308
            } else {
309
                for (int i = 0; i < m.getSize(); i++) {
310
                    ScopeProvider sd = (ScopeProvider) m.getElementAt(i);
311
312
                    if (sd instanceof DelegatingCustomScopeProvider) {
313
                        showCustomizer((DelegatingCustomScopeProvider) sd, scope);
314
                        break;
315
                    }
316
                }
317
            }
318
        }
319
320
        private void showCustomizer(DelegatingCustomScopeProvider csd, Scope scope) {
321
            csd.setScope(scope);
322
            if (csd.showCustomizer()) {
323
                selectScopeById(csd.getId());
324
            }
325
        }
326
    }
327
328
    private static class ScopeDescriptionRenderer extends JLabel implements ListCellRenderer, UIResource {
329
330
        public ScopeDescriptionRenderer() {
331
            setOpaque(true);
332
        }
333
334
        @Override
335
        public Component getListCellRendererComponent(
336
                JList list,
337
                Object value,
338
                int index,
339
                boolean isSelected,
340
                boolean cellHasFocus) {
341
342
            // #89393: GTK needs name to render cell renderer "natively"
343
            setName("ComboBox.listRenderer"); // NOI18N
344
            DelegatingScopeInformation scopeDescription = null;
345
            if (value instanceof DelegatingScopeInformation) {
346
                scopeDescription = (DelegatingScopeInformation) value;
347
            }
348
            if (scopeDescription != null) {
349
                String detail = scopeDescription.getDetail();
350
                String displayName = scopeDescription.getDisplayName();
351
                setText(detail == null ? displayName : displayName + " (" + detail + ")");
352
                setIcon(scopeDescription.getIcon());
353
            }
354
355
            if (isSelected) {
356
                setBackground(list.getSelectionBackground());
357
                setForeground(list.getSelectionForeground());
358
            } else {
359
                setBackground(list.getBackground());
360
                setForeground(list.getForeground());
361
            }
362
363
            return this;
364
        }
365
366
        // #89393: GTK needs name to render cell renderer "natively"
367
        @Override
368
        public String getName() {
369
            String name = super.getName();
370
            return name == null ? "ComboBox.renderer" : name;  // NOI18N
371
        }
372
    }
373
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/ui/ScopeProvider.java (+193 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.ui;
43
44
import java.lang.annotation.ElementType;
45
import java.lang.annotation.Retention;
46
import java.lang.annotation.RetentionPolicy;
47
import java.lang.annotation.Target;
48
import java.util.concurrent.atomic.AtomicBoolean;
49
import javax.swing.Icon;
50
import org.netbeans.api.annotations.common.CheckForNull;
51
import org.netbeans.api.annotations.common.NonNull;
52
import org.netbeans.api.annotations.common.NullAllowed;
53
import org.netbeans.modules.refactoring.api.Scope;
54
import org.openide.util.Lookup;
55
56
/**
57
 * ScopeProvider is used to add a scope to the {@link ScopePanel}.
58
 *
59
 * @see ScopePanel
60
 * @see ScopeDescription
61
 * @see ScopeReference
62
 *
63
 * @author Jan Lahoda
64
 * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
65
 *
66
 * @since 1.30
67
 */
68
public abstract class ScopeProvider {
69
70
    /**
71
     * Initialize this scope provider with the supplied context.
72
     *
73
     * @param context a Lookup defining the context
74
     * @param cancel set to true if initialization should be canceled
75
     * @return true if this scope is usable for the supplied context, false
76
     * otherwise
77
     */
78
    public abstract boolean initialize(@NonNull Lookup context, @NonNull AtomicBoolean cancel);
79
80
    /**
81
     * Get this provider's scope. The scope can be null if this provider is not
82
     * yet initialized, or this provider is not usable for the supplied context.
83
     *
84
     * @see ScopeProvider#initialize(org.openide.util.Lookup,
85
     * java.util.concurrent.atomic.AtomicBoolean)
86
     * @return the Scope
87
     */
88
    @CheckForNull
89
    public abstract Scope getScope();
90
91
    /**
92
     * Override this method if the icon should be different depending on the
93
     * context.
94
     *
95
     * @see ScopeProvider#initialize(org.openide.util.Lookup,
96
     * java.util.concurrent.atomic.AtomicBoolean)
97
     * @see ScopeDescription
98
     * @return an icon for the Scope, or null if the default should be used.
99
     */
100
    @CheckForNull
101
    public Icon getIcon() {
102
        return null;
103
    }
104
105
    /**
106
     * Override this method if an explaining string should be displayed behind
107
     * the scope's name. This is used for scopes like "- Current File
108
     * (Filename.java)".
109
     *
110
     * @return an explaining string, or null of nothing should be displayed.
111
     */
112
    @CheckForNull
113
    public String getDetail() {
114
        return null;
115
    }
116
117
    /**
118
     * The CustomScopeProvider extends the normal scope provider to support
119
     * scopes which can be customized by the user.
120
     *
121
     * @see ScopePanel
122
     * @see ScopeDescription
123
     * @see ScopeReference
124
     *
125
     * @author Jan Lahoda
126
     * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
127
     *
128
     * @since 1.30
129
     */
130
    public static abstract class CustomScopeProvider extends ScopeProvider {
131
132
        /**
133
         * Set the scope to be customized. This method will be called right
134
         * before the provider is asked to show the customizer, with the
135
         * currently selected scope.
136
         *
137
         * @param currentScope the Scope currently selected
138
         */
139
        public abstract void setScope(@NullAllowed Scope currentScope);
140
141
        /**
142
         * Show a Dialog to customize the scope.
143
         *
144
         * @return true if the user succesfully specified a scope, false
145
         * otherwise (ie. clicked cancel)
146
         */
147
        public abstract boolean showCustomizer();
148
    }
149
    
150
    /**
151
     * Declarative registration of a ScopeProvider implementation.
152
     * By marking the implementation class with this annotation,
153
     * you automatically register that implementation.
154
     * The class must be public and have a public constructor which takes
155
     * no arguments.
156
     * 
157
     * @author Jan Lahoda
158
     * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
159
     * @since 1.30
160
     */
161
    @Target({ElementType.TYPE})
162
    @Retention(RetentionPolicy.SOURCE)
163
    public static @interface Registration {
164
165
        /**
166
         * The unique ID of the scope description.
167
         *
168
         * @return unique id
169
         */
170
        String id();
171
172
        /**
173
         * Position in the location. Negative numbers can be used for scopes
174
         * that should be higher in the list, but not selected by default.
175
         */
176
        int position() default Integer.MAX_VALUE;
177
        
178
        /**
179
         * Display name. Usually prefixed with '#' to reference value from a
180
         * <code>Bundle.properties</code> file in the same package.
181
         *
182
         * @return display name for the scope
183
         */
184
        String displayName();
185
186
        /**
187
         * Path to image representing the scope's icon.
188
         *
189
         * @return "org/myproject/mypkg/Icon.png"
190
         */
191
        String iconBase() default "";
192
    }
193
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/ui/ScopeReference.java (+72 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.ui;
43
44
import java.lang.annotation.ElementType;
45
import java.lang.annotation.Retention;
46
import java.lang.annotation.RetentionPolicy;
47
import java.lang.annotation.Target;
48
49
/**
50
 * A reference to a Scope Description to be used by a {@link ScopePanel}
51
 *
52
 * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
53
 * @since 1.30
54
 */
55
@Target({ElementType.TYPE})
56
@Retention(RetentionPolicy.SOURCE)
57
public @interface ScopeReference {
58
59
    /**
60
     * Into which location one wants to place the reference? Translates to
61
     * {@link FileUtil#getConfigFile(java.lang.String)}.
62
     */
63
    String path();
64
65
    /**
66
     * Identification of the scope this reference shall point to. Usually this
67
     * is specified as {@link ScopeDescription} peer annotation, but in case one
68
     * was to create references to scopes defined by someone else, one can
69
     * specify the id() here.
70
     */
71
    String id() default "";
72
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/spi/ui/ScopeReferences.java (+59 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.ui;
43
44
import java.lang.annotation.ElementType;
45
import java.lang.annotation.Retention;
46
import java.lang.annotation.RetentionPolicy;
47
import java.lang.annotation.Target;
48
49
/**
50
 * Allows registration of multiple {@link ScopeReference}s for a single type.
51
 *
52
 * @author Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
53
 */
54
@Target({ElementType.TYPE})
55
@Retention(RetentionPolicy.SOURCE)
56
public @interface ScopeReferences {
57
58
    ScopeReference[] value();
59
}

Return to bug 217347