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

(-)a/jumpto/apichanges.xml (-3 / +18 lines)
Lines 105-112 Link Here
105
    <!-- ACTUAL CHANGES BEGIN HERE: -->
105
    <!-- ACTUAL CHANGES BEGIN HERE: -->
106
106
107
    <changes>
107
    <changes>
108
108
        <change id="GoToFile">
109
        
109
            <api name="general"/>
110
            <summary>Added SPI for Go to File dialog</summary>
111
            <version major="1" minor="15"/>
112
            <date day="5" month="4" year="2010"/>
113
            <author login="tzezula"/>
114
            <compatibility addition="yes">
115
            </compatibility>
116
            <description>
117
                 Added SPI to allow friend modules to participate on searching files
118
                 in the Go To File dialog. The supplied FileProvider can handle file
119
                 search in recognized source groups.
120
            </description>
121
            <class package="org.netbeans.spi.jumpto.file" name="FileProviderFactory"/>
122
            <class package="org.netbeans.spi.jumpto.file" name="FileProvider"/>
123
            <issue number="182884"/>
124
        </change>
110
        <change id="GoToSymbol">
125
        <change id="GoToSymbol">
111
            <api name="general"/>
126
            <api name="general"/>
112
            <summary>Added SPI for Go to Symbol dialog</summary>
127
            <summary>Added SPI for Go to Symbol dialog</summary>
Lines 119-125 Link Here
119
                 Added SPI to provide content of the for Go to Symbol dialog.
134
                 Added SPI to provide content of the for Go to Symbol dialog.
120
            </description>
135
            </description>
121
            <issue number="138345"/>
136
            <issue number="138345"/>
122
        </change>                
137
        </change>
123
138
124
        <change id="(Provider.Result.pendingResult">
139
        <change id="(Provider.Result.pendingResult">
125
            <api name="general"/>
140
            <api name="general"/>
(-)a/jumpto/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.netbeans.modules.jumpto/1
2
OpenIDE-Module: org.netbeans.modules.jumpto/1
3
OpenIDE-Module-Layer: org/netbeans/modules/jumpto/resources/layer.xml
3
OpenIDE-Module-Layer: org/netbeans/modules/jumpto/resources/layer.xml
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jumpto/resources/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jumpto/resources/Bundle.properties
5
OpenIDE-Module-Specification-Version: 1.14
5
OpenIDE-Module-Specification-Version: 1.15
6
AutoUpdate-Show-In-Client: false
6
AutoUpdate-Show-In-Client: false
(-)a/jumpto/nbproject/project.xml (-1 / +2 lines)
Lines 215-226 Link Here
215
            </test-dependencies>
215
            </test-dependencies>
216
            <friend-packages>
216
            <friend-packages>
217
                <friend>org.netbeans.modules.cnd.gotodeclaration</friend>
217
                <friend>org.netbeans.modules.cnd.gotodeclaration</friend>
218
                <friend>org.netbeans.modules.csl.api</friend>
218
                <friend>org.netbeans.modules.gsf</friend>
219
                <friend>org.netbeans.modules.gsf</friend>
219
                <friend>org.netbeans.modules.java.sourceui</friend>
220
                <friend>org.netbeans.modules.java.sourceui</friend>
220
                <friend>org.netbeans.modules.javafx.editor</friend>
221
                <friend>org.netbeans.modules.javafx.editor</friend>
221
                <friend>org.netbeans.modules.spring.beans</friend>
222
                <friend>org.netbeans.modules.spring.beans</friend>
222
                <friend>org.netbeans.modules.csl.api</friend>
223
                <package>org.netbeans.api.jumpto.type</package>
223
                <package>org.netbeans.api.jumpto.type</package>
224
                <package>org.netbeans.spi.jumpto.file</package>
224
                <package>org.netbeans.spi.jumpto.symbol</package>
225
                <package>org.netbeans.spi.jumpto.symbol</package>
225
                <package>org.netbeans.spi.jumpto.type</package>
226
                <package>org.netbeans.spi.jumpto.type</package>
226
            </friend-packages>
227
            </friend-packages>
(-)a/jumpto/src/org/netbeans/modules/jumpto/file/FileDescription.java (-324 / +28 lines)
Lines 44-189 Link Here
44
44
45
package org.netbeans.modules.jumpto.file;
45
package org.netbeans.modules.jumpto.file;
46
46
47
import java.awt.BorderLayout;
48
import java.awt.Color;
49
import java.awt.Component;
50
import java.awt.Container;
51
import java.awt.Dimension;
52
import java.awt.Image;
47
import java.awt.Image;
53
import java.beans.BeanInfo;
48
import java.beans.BeanInfo;
54
import java.util.Comparator;
55
import javax.swing.DefaultListCellRenderer;
56
import javax.swing.Icon;
49
import javax.swing.Icon;
57
import javax.swing.ImageIcon;
50
import javax.swing.ImageIcon;
58
import javax.swing.JLabel;
59
import javax.swing.JList;
60
import javax.swing.JPanel;
61
import javax.swing.JViewport;
62
import javax.swing.SwingConstants;
63
import javax.swing.event.ChangeEvent;
64
import javax.swing.event.ChangeListener;
65
import org.netbeans.api.project.Project;
51
import org.netbeans.api.project.Project;
66
import org.netbeans.api.project.ProjectInformation;
52
import org.netbeans.api.project.ProjectInformation;
67
import org.netbeans.api.project.ProjectUtils;
53
import org.netbeans.api.project.ProjectUtils;
68
import org.openide.cookies.EditCookie;
54
import org.openide.cookies.EditCookie;
69
import org.openide.cookies.OpenCookie;
55
import org.openide.cookies.OpenCookie;
70
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileObject;
71
import org.openide.filesystems.FileUtil;
72
import org.openide.loaders.DataObject;
57
import org.openide.loaders.DataObject;
73
import org.openide.loaders.DataObjectNotFoundException;
58
import org.openide.loaders.DataObjectNotFoundException;
74
import org.openide.util.ImageUtilities;
59
import org.openide.util.ImageUtilities;
75
import org.openide.util.NbBundle;
76
60
77
/** Contains interesting information about file found in the search.
61
/** Contains interesting information about file found in the search.
78
 *
62
 *
79
 * @author Petr Hrebejk
63
 * @author Petr Hrebejk
64
 * @author Tomas Zezula
65
 * todo: SPI interface if needed. Now FileObject added to result seems to be enough
66
 * and everyone will use the default impl anyway.
80
 */
67
 */
81
public class FileDescription {
68
public class FileDescription {
82
83
//    static long time;
84
    
85
    public static final String SEARCH_IN_PROGRES = NbBundle.getMessage(FileDescription.class, "TXT_SearchingOtherProjects"); // NOI18N
86
    /**
69
    /**
87
     * The icon used if unknown project, i.e. {@code project == null}.
70
     * The icon used if unknown project, i.e. {@code project == null}.
88
     * In such case, we use {@code find.png} - "a file belongs to the find".
71
     * In such case, we use {@code find.png} - "a file belongs to the find".
89
     */
72
     */
90
    public static Icon UNKNOWN_PROJECT_ICON = ImageUtilities.loadImageIcon(
73
    public static Icon UNKNOWN_PROJECT_ICON = ImageUtilities.loadImageIcon(
91
             "org/netbeans/modules/jumpto/resources/find.gif", false); // NOI18N
74
             "org/netbeans/modules/jumpto/resources/find.gif", false); // NOI18N
92
    
93
    private final FileObject fileObject;
75
    private final FileObject fileObject;
94
    private final String relativePath;
76
    private final String ownerPath;
95
    private final Project project; // Project the file belongs to
77
    private final Project project; // Project the file belongs to
96
    
78
97
    private Icon icon;
79
    private Icon icon;
98
    private String projectName;
80
    private String projectName;
99
    private Icon projectIcon;
81
    private Icon projectIcon;
100
    private boolean prefered;
82
    private boolean prefered;
101
    
83
102
    private static final String EMPTY_STRING = ""; // NOI18N
84
    public FileDescription(FileObject file, String ownerPath,
103
    
104
    public FileDescription(FileObject file, String relativePath, 
105
                           Project project, boolean prefered) {
85
                           Project project, boolean prefered) {
106
        this.fileObject = file;
86
        this.fileObject = file;
107
        this.relativePath = relativePath;
87
        this.ownerPath = ownerPath;
108
        this.project = project;
88
        this.project = project;
109
        this.prefered = prefered;
89
        this.prefered = prefered;
110
    }
90
    }
111
       
91
112
    public String getName() {
92
    public String getFileName() {
113
        return fileObject.getNameExt(); // NOI18N
93
        return fileObject.getNameExt(); // NOI18N
114
    }
94
    }
115
    
95
116
    public synchronized Icon getIcon() {
96
    public synchronized Icon getIcon() {
117
                
118
        if ( icon == null ) {
97
        if ( icon == null ) {
119
            DataObject od = getDataObject();
98
            DataObject od = getDataObject();
120
            Image i = od.getNodeDelegate().getIcon(BeanInfo.ICON_COLOR_16x16);
99
            Image i = od.getNodeDelegate().getIcon(BeanInfo.ICON_COLOR_16x16);
121
            icon = new ImageIcon( i );
100
            icon = new ImageIcon( i );
122
        }
101
        }
123
        
124
        return icon;
102
        return icon;
125
    }
103
    }
126
    
104
127
    public String getRelativePath() {
105
    public String getOwnerPath() {
128
        return relativePath;
106
        return ownerPath;
129
    }
107
    }
130
    
108
131
    public synchronized String getProjectName() {
109
    public synchronized String getProjectName() {
132
        if ( projectName == null ) {
110
        if ( projectName == null ) {
133
            initProjectInfo();
111
            initProjectInfo();
134
        }        
112
        }
135
        return projectName;
113
        return projectName;
136
    }
114
    }
137
    
115
138
    public synchronized Icon getProjectIcon() {
116
    public synchronized Icon getProjectIcon() {
139
        if ( projectIcon == null ) {
117
        if ( projectIcon == null ) {
140
            initProjectInfo();
118
            initProjectInfo();
141
        }        
119
        }
142
        return projectIcon;
120
        return projectIcon;
143
    }
121
    }
144
    
122
145
//    public synchronized boolean isVisible() {
123
    public boolean isFromCurrentProject() {
146
//
124
        return prefered;
147
//        long t = System.currentTimeMillis();
125
    }
148
//
126
149
//        if ( fileObject == null ) {
150
//            fileObject = FileUtil.toFileObject(file);
151
//        }
152
//        boolean visible = fileObject == null ? false : VisibilityQuery.getDefault().isVisible(fileObject);
153
//        if ( !visible ) {
154
//            addTime( t );
155
//            return false;
156
//        }
157
//
158
//        // XXX PERF needs to cache parents.
159
//        while( fileObject.getParent() != null ) {
160
//            fileObject = fileObject.getParent();
161
//            if ( fileObject.equals(sourceGroup.getRootFolder() ) ) {
162
//                addTime( t );
163
//                return true;
164
//            }
165
//            if ( !VisibilityQuery.getDefault().isVisible(fileObject)  ) {
166
//                addTime( t );
167
//                return false;
168
//            }
169
//        }
170
//        addTime( t );
171
//        return true;
172
//    }
173
//
174
//    private void addTime( long t ) {
175
////        time += System.currentTimeMillis() - t;
176
////        System.out.println("isVisible time " + time);
177
//    }
178
    
179
    public void open() {
127
    public void open() {
180
        
181
        DataObject od = getDataObject();
128
        DataObject od = getDataObject();
182
        
183
        if ( od != null ) {
129
        if ( od != null ) {
184
        
185
            EditCookie ec = (EditCookie) od.getCookie(EditCookie.class);
130
            EditCookie ec = (EditCookie) od.getCookie(EditCookie.class);
186
187
            if (ec != null) {
131
            if (ec != null) {
188
                ec.edit();
132
                ec.edit();
189
            }
133
            }
Lines 196-206 Link Here
196
        }
140
        }
197
141
198
    }
142
    }
199
    
143
200
    public FileObject getFileObject() {        
144
    public FileObject getFileObject() {
201
        return fileObject;
145
        return fileObject;
202
    }
146
    }
203
    
147
204
    private DataObject getDataObject() {
148
    private DataObject getDataObject() {
205
        try     {
149
        try     {
206
            org.openide.filesystems.FileObject fo = getFileObject();
150
            org.openide.filesystems.FileObject fo = getFileObject();
Lines 210-216 Link Here
210
            return null;
154
            return null;
211
        }
155
        }
212
    }
156
    }
213
    
157
214
    private void initProjectInfo() {
158
    private void initProjectInfo() {
215
        // Issue #167198: A file may not belong to any project.
159
        // Issue #167198: A file may not belong to any project.
216
        // Hence, FileOwnerQuery.getOwner(file) can return null as a project,
160
        // Hence, FileOwnerQuery.getOwner(file) can return null as a project,
Lines 222-469 Link Here
222
            projectIcon = pi.getIcon();
166
            projectIcon = pi.getIcon();
223
        }
167
        }
224
        else {
168
        else {
225
            projectName = EMPTY_STRING;
169
            projectName = "";   //NOI18N
226
            projectIcon = UNKNOWN_PROJECT_ICON;
170
            projectIcon = UNKNOWN_PROJECT_ICON;
227
        }
171
        }
228
    }
172
    }
229
    
230
    // Innerclasses ------------------------------------------------------------
231
    
232
    public static class FDComarator implements Comparator<FileDescription> {
233
234
        private boolean usePrefered;
235
        private boolean caseSensitive;
236
                
237
        public FDComarator(boolean usePrefered, boolean caseSensitive ) {
238
            this.usePrefered = usePrefered;
239
            this.caseSensitive = caseSensitive;
240
        }
241
        
242
        public int compare(FileDescription o1, FileDescription o2) {
243
            
244
            // If prefered prefer prefered
245
            if ( usePrefered ) {
246
                if ( o1.prefered && !o2.prefered ) {
247
                    return -1;
248
                }
249
                if ( !o1.prefered && o2.prefered ) {
250
                    return 1;
251
                }
252
            }
253
            
254
            // File name
255
            int cmpr = compareStrings( o1.getName(), o2.getName(), caseSensitive );
256
            if ( cmpr != 0 ) {
257
                return cmpr;
258
            }
259
            
260
            // Project name
261
            cmpr = compareStrings( o1.getProjectName(), o2.getProjectName(), caseSensitive );            
262
            if ( cmpr != 0 ) {
263
                return cmpr;
264
            }
265
            
266
            // Relative location
267
            cmpr = compareStrings( o1.getRelativePath(), o2.getRelativePath(), caseSensitive );
268
                        
269
            return cmpr;
270
           
271
        }
272
        
273
        private int compareStrings(String s1, String s2, boolean caseSensitive) {
274
            if( s1 == null ) {
275
                s1 = EMPTY_STRING;
276
            }
277
            if ( s2 == null ) {
278
                s2 = EMPTY_STRING;
279
            }
280
            
281
            
282
            return caseSensitive ? s1.compareTo( s2 ) : s1.compareToIgnoreCase( s2 );
283
        }        
284
    }
285
286
    private static class RendererComponent extends JPanel {
287
	private FileDescription fd;
288
289
	void setDescription(FileDescription fd) {
290
	    this.fd = fd;
291
	    putClientProperty(TOOL_TIP_TEXT_KEY, null);
292
	}
293
294
	@Override
295
	public String getToolTipText() {
296
	    String text = (String) getClientProperty(TOOL_TIP_TEXT_KEY);
297
	    if( text == null ) {
298
                if( fd != null) {
299
                    text = FileUtil.getFileDisplayName(fd.getFileObject());
300
                }
301
                putClientProperty(TOOL_TIP_TEXT_KEY, text);
302
	    }
303
	    return text;
304
	}
305
    }
306
307
    public static class Renderer extends DefaultListCellRenderer implements ChangeListener {
308
        
309
        public static Icon WAIT_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/jumpto/resources/wait.gif", false); // NOI18N
310
        
311
        
312
        private RendererComponent rendererComponent;
313
        private JLabel jlName = new JLabel();
314
        private JLabel jlPath = new JLabel();
315
        private JLabel jlPrj = new JLabel();
316
        private int DARKER_COLOR_COMPONENT = 5;
317
        private int LIGHTER_COLOR_COMPONENT = 80;        
318
        private Color fgColor;
319
        private Color fgColorLighter;
320
        private Color bgColor;
321
        private Color bgColorDarker;
322
        private Color bgSelectionColor;
323
        private Color fgSelectionColor;
324
        private Color bgColorGreener;
325
        private Color bgColorDarkerGreener;
326
        
327
        private JList jList;
328
    
329
        private boolean colorPrefered;
330
        
331
        public Renderer( JList list ) {
332
            
333
            jList = list;
334
            
335
            Container container = list.getParent();
336
            if ( container instanceof JViewport ) {
337
                ((JViewport)container).addChangeListener(this);
338
                stateChanged(new ChangeEvent(container));
339
            }
340
            
341
            rendererComponent = new RendererComponent();
342
            rendererComponent.setLayout(new BorderLayout());
343
            rendererComponent.add( jlName, BorderLayout.WEST );
344
            rendererComponent.add( jlPath, BorderLayout.CENTER);
345
            rendererComponent.add( jlPrj, BorderLayout.EAST );
346
            
347
            
348
            jlName.setOpaque(false);
349
            jlPath.setOpaque(false);
350
            jlPrj.setOpaque(false);
351
            
352
            jlName.setFont(list.getFont());
353
            jlPath.setFont(list.getFont());
354
            jlPrj.setFont(list.getFont());
355
            
356
            
357
            jlPrj.setHorizontalAlignment(RIGHT);
358
            jlPrj.setHorizontalTextPosition(LEFT);
359
            
360
            // setFont( list.getFont() );            
361
            fgColor = list.getForeground();
362
            fgColorLighter = new Color( 
363
                                   Math.min( 255, fgColor.getRed() + LIGHTER_COLOR_COMPONENT),
364
                                   Math.min( 255, fgColor.getGreen() + LIGHTER_COLOR_COMPONENT),
365
                                   Math.min( 255, fgColor.getBlue() + LIGHTER_COLOR_COMPONENT)
366
                                  );
367
                            
368
            bgColor = list.getBackground();
369
            bgColorDarker = new Color(
370
                                    Math.abs(bgColor.getRed() - DARKER_COLOR_COMPONENT),
371
                                    Math.abs(bgColor.getGreen() - DARKER_COLOR_COMPONENT),
372
                                    Math.abs(bgColor.getBlue() - DARKER_COLOR_COMPONENT)
373
                            );
374
            bgSelectionColor = list.getSelectionBackground();
375
            fgSelectionColor = list.getSelectionForeground();
376
            
377
            
378
            bgColorGreener = new Color( 
379
                                    Math.abs(bgColor.getRed() - 20),
380
                                    Math.min(255, bgColor.getGreen() + 10 ),
381
                                    Math.abs(bgColor.getBlue() - 20) );
382
                    
383
                    
384
            bgColorDarkerGreener = new Color( 
385
                                    Math.abs(bgColorDarker.getRed() - 35),
386
                                    Math.min(255, bgColorDarker.getGreen() + 5 ),
387
                                    Math.abs(bgColorDarker.getBlue() - 35) );
388
        }
389
        
390
        public @Override Component getListCellRendererComponent( JList list,
391
                                                       Object value,
392
                                                       int index,
393
                                                       boolean isSelected,
394
                                                       boolean hasFocus) {
395
            
396
            // System.out.println("Renderer for index " + index );
397
            
398
            int height = list.getFixedCellHeight();
399
            int width = list.getFixedCellWidth() - 1;
400
            
401
            width = width < 200 ? 200 : width;
402
            
403
            // System.out.println("w, h " + width + ", " + height );
404
            
405
            Dimension size = new Dimension( width, height );
406
            rendererComponent.setMaximumSize(size);
407
            rendererComponent.setPreferredSize(size);
408
                        
409
            if ( isSelected ) {
410
                jlName.setForeground(fgSelectionColor);
411
                jlPath.setForeground(fgSelectionColor);
412
                jlPrj.setForeground(fgSelectionColor);
413
                rendererComponent.setBackground(bgSelectionColor);
414
            }
415
            else {
416
                jlName.setForeground(fgColor);
417
                jlPath.setForeground(fgColorLighter);
418
                jlPrj.setForeground(fgColor);                
419
                rendererComponent.setBackground( index % 2 == 0 ? bgColor : bgColorDarker );
420
            }
421
            
422
            if ( value instanceof FileDescription ) {
423
                FileDescription fd = (FileDescription)value;
424
                jlName.setIcon(fd.getIcon());
425
                jlName.setText(fd.getName());
426
                jlPath.setIcon(null);
427
                jlPath.setHorizontalAlignment(SwingConstants.LEFT);
428
                jlPath.setText(fd.getRelativePath().length() > 0 ? " (" + fd.getRelativePath() + ")" : " ()"); //NOI18N
429
                jlPrj.setText(fd.getProjectName());
430
                jlPrj.setIcon(fd.getProjectIcon());
431
                if ( !isSelected ) {
432
                    rendererComponent.setBackground( index % 2 == 0 ? 
433
                        ( fd.prefered && colorPrefered ? bgColorGreener : bgColor ) : 
434
                        ( fd.prefered && colorPrefered ? bgColorDarkerGreener : bgColorDarker ) );
435
                }
436
                rendererComponent.setDescription(fd);
437
            }
438
            else {
439
                jlName.setText( "" ); // NOI18M
440
                jlName.setIcon(null);
441
                jlPath.setIcon(Renderer.WAIT_ICON);
442
                jlPath.setHorizontalAlignment(SwingConstants.CENTER);
443
                jlPath.setText( value.toString() );
444
                jlPrj.setIcon(null);
445
                jlPrj.setText( "" ); // NOI18N
446
            }
447
            
448
            return rendererComponent;
449
        }
450
        
451
        public void stateChanged(ChangeEvent event) {
452
            
453
            JViewport jv = (JViewport)event.getSource();
454
            
455
            jlName.setText( "Sample" ); // NOI18N
456
            jlName.setIcon( new ImageIcon() );
457
            
458
            jList.setFixedCellHeight(jlName.getPreferredSize().height);
459
            jList.setFixedCellWidth(jv.getExtentSize().width);
460
        }
461
        
462
        public void setColorPrefered( boolean colorPrefered ) {
463
            this.colorPrefered = colorPrefered;
464
        }
465
466
     }
467
        
468
469
}
173
}
(-)a/jumpto/src/org/netbeans/modules/jumpto/file/FileProviderAccessor.java (+82 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.jumpto.file;
41
42
import java.util.List;
43
import org.netbeans.api.project.Project;
44
import org.netbeans.spi.jumpto.file.FileProvider;
45
import org.netbeans.spi.jumpto.type.SearchType;
46
import org.openide.filesystems.FileObject;
47
import org.openide.util.Exceptions;
48
49
/**
50
 *
51
 * @author Tomas Zezula
52
 */
53
public abstract class FileProviderAccessor {
54
55
    private static volatile FileProviderAccessor instance;
56
57
    public static synchronized FileProviderAccessor getInstance() {
58
        if (instance == null) {
59
            try {
60
                Class.forName(FileProvider.Context.class.getName(), true, FileProviderAccessor.class.getClassLoader());
61
                assert instance != null;
62
            } catch (ClassNotFoundException cnf) {
63
                Exceptions.printStackTrace(cnf);
64
            }
65
        }
66
        assert instance != null;
67
        return instance;
68
    }
69
70
    public static void setInstance(final FileProviderAccessor theInstance) {
71
        assert theInstance != null;
72
        instance = theInstance;
73
    }
74
75
    public abstract FileProvider.Context createContext(String text, SearchType searchType, Project currentProject);
76
77
    public abstract void setRoot(FileProvider.Context ctx, FileObject root);
78
79
    public abstract FileProvider.Result createResult(List<? super FileDescription> result, String[] message, FileProvider.Context ctx);
80
81
    public abstract int getRetry(FileProvider.Result result);
82
}
(-)a/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java (-85 / +348 lines)
Lines 45-50 Link Here
45
45
46
package org.netbeans.modules.jumpto.file;
46
package org.netbeans.modules.jumpto.file;
47
47
48
import java.awt.BorderLayout;
49
import java.awt.Color;
50
import java.awt.Component;
51
import java.awt.Container;
48
import java.awt.Dialog;
52
import java.awt.Dialog;
49
import java.awt.Dimension;
53
import java.awt.Dimension;
50
import java.awt.Rectangle;
54
import java.awt.Rectangle;
Lines 56-62 Link Here
56
import java.util.ArrayList;
60
import java.util.ArrayList;
57
import java.util.Collection;
61
import java.util.Collection;
58
import java.util.Collections;
62
import java.util.Collections;
63
import java.util.Comparator;
59
import java.util.Enumeration;
64
import java.util.Enumeration;
65
import java.util.LinkedList;
60
import java.util.List;
66
import java.util.List;
61
import java.util.logging.Level;
67
import java.util.logging.Level;
62
import java.util.logging.Logger;
68
import java.util.logging.Logger;
Lines 64-75 Link Here
64
import java.util.regex.Pattern;
70
import java.util.regex.Pattern;
65
import java.util.regex.PatternSyntaxException;
71
import java.util.regex.PatternSyntaxException;
66
import javax.swing.AbstractAction;
72
import javax.swing.AbstractAction;
73
import javax.swing.DefaultListCellRenderer;
67
import javax.swing.DefaultListModel;
74
import javax.swing.DefaultListModel;
75
import javax.swing.Icon;
76
import javax.swing.ImageIcon;
68
import javax.swing.JButton;
77
import javax.swing.JButton;
78
import javax.swing.JLabel;
69
import javax.swing.JList;
79
import javax.swing.JList;
80
import javax.swing.JPanel;
81
import javax.swing.JViewport;
70
import javax.swing.ListCellRenderer;
82
import javax.swing.ListCellRenderer;
71
import javax.swing.ListModel;
83
import javax.swing.ListModel;
84
import javax.swing.SwingConstants;
72
import javax.swing.SwingUtilities;
85
import javax.swing.SwingUtilities;
86
import javax.swing.event.ChangeEvent;
87
import javax.swing.event.ChangeListener;
73
import org.netbeans.api.project.FileOwnerQuery;
88
import org.netbeans.api.project.FileOwnerQuery;
74
import org.netbeans.api.project.Project;
89
import org.netbeans.api.project.Project;
75
import org.netbeans.api.project.ProjectUtils;
90
import org.netbeans.api.project.ProjectUtils;
Lines 80-85 Link Here
80
import org.netbeans.modules.jumpto.type.Models;
95
import org.netbeans.modules.jumpto.type.Models;
81
import org.netbeans.modules.parsing.spi.indexing.support.IndexResult;
96
import org.netbeans.modules.parsing.spi.indexing.support.IndexResult;
82
import org.netbeans.modules.parsing.spi.indexing.support.QuerySupport;
97
import org.netbeans.modules.parsing.spi.indexing.support.QuerySupport;
98
import org.netbeans.spi.jumpto.file.FileProvider;
99
import org.netbeans.spi.jumpto.file.FileProviderFactory;
100
import org.netbeans.spi.jumpto.type.SearchType;
83
import org.openide.DialogDescriptor;
101
import org.openide.DialogDescriptor;
84
import org.openide.DialogDisplayer;
102
import org.openide.DialogDisplayer;
85
import org.openide.awt.Mnemonics;
103
import org.openide.awt.Mnemonics;
Lines 87-92 Link Here
87
import org.openide.filesystems.FileUtil;
105
import org.openide.filesystems.FileUtil;
88
import org.openide.loaders.DataObject;
106
import org.openide.loaders.DataObject;
89
import org.openide.util.HelpCtx;
107
import org.openide.util.HelpCtx;
108
import org.openide.util.ImageUtilities;
90
import org.openide.util.Lookup;
109
import org.openide.util.Lookup;
91
import org.openide.util.NbBundle;
110
import org.openide.util.NbBundle;
92
import org.openide.util.RequestProcessor;
111
import org.openide.util.RequestProcessor;
Lines 109-114 Link Here
109
    private JButton openBtn;
128
    private JButton openBtn;
110
    private FileSearchPanel panel;
129
    private FileSearchPanel panel;
111
    private Dimension initialDimension;
130
    private Dimension initialDimension;
131
    private Iterable<? extends FileProvider> providers;
112
    
132
    
113
    public FileSearchAction() {
133
    public FileSearchAction() {
114
        super( NbBundle.getMessage(FileSearchAction.class, "CTL_FileSearchAction") );
134
        super( NbBundle.getMessage(FileSearchAction.class, "CTL_FileSearchAction") );
Lines 135-141 Link Here
135
155
136
156
137
    public ListCellRenderer getListCellRenderer( JList list ) {
157
    public ListCellRenderer getListCellRenderer( JList list ) {
138
        return new FileDescription.Renderer( list );
158
        return new Renderer( list );
139
    }
159
    }
140
160
141
161
Lines 205-235 Link Here
205
225
206
    private FileDescription[] getSelectedFiles() {
226
    private FileDescription[] getSelectedFiles() {
207
        FileDescription[] result = null;
227
        FileDescription[] result = null;
208
//        try {
228
        panel = new FileSearchPanel(this, findCurrentProject());
209
            panel = new FileSearchPanel(this, findCurrentProject());
229
        dialog = createDialog(panel);
210
            dialog = createDialog(panel);
230
        dialog.setVisible(true);
211
231
        result = panel.getSelectedFiles();
212
//            Node[] arr = TopComponent.getRegistry ().getActivatedNodes();
213
//            String initSearchText = null;
214
//            if (arr.length > 0) {
215
//                EditorCookie ec = arr[0].getCookie (EditorCookie.class);
216
//                if (ec != null) {
217
//                    JEditorPane[] openedPanes = ec.getOpenedPanes ();
218
//                    if (openedPanes != null) {
219
//                        initSearchText = org.netbeans.editor.Utilities.getSelectionOrIdentifier(openedPanes [0]);
220
//                        if (initSearchText != null && org.openide.util.Utilities.isJavaIdentifier(initSearchText)) {
221
//                            panel.setInitialText(initSearchText);
222
//                        }
223
//                    }
224
//                }
225
//            }
226
227
            dialog.setVisible(true);
228
            result = panel.getSelectedFiles();
229
230
//        } catch (IOException ex) {
231
//            ErrorManager.getDefault().notify(ex);
232
//        }
233
        return result;
232
        return result;
234
    }
233
    }
235
234
Lines 306-316 Link Here
306
//    }
305
//    }
307
306
308
    private void cleanup() {
307
    private void cleanup() {
309
        //System.out.println("CLEANUP");
310
        //Thread.dumpStack();
311
308
312
        if ( dialog != null ) { // Closing event for some reson sent twice
309
        if ( dialog != null ) { // Closing event for some reson sent twice
313
310
            //Free SPI
311
            synchronized (this) {
312
                providers = null;
313
            }
314
            // Save dialog size only when changed
314
            // Save dialog size only when changed
315
            final int currentWidth = dialog.getWidth();
315
            final int currentWidth = dialog.getWidth();
316
            final int currentHeight = dialog.getHeight();
316
            final int currentHeight = dialog.getHeight();
Lines 323-330 Link Here
323
            dialog.dispose();
323
            dialog.dispose();
324
            this.dialog = null;
324
            this.dialog = null;
325
            //GoToTypeAction.this.cache = null;
325
            //GoToTypeAction.this.cache = null;
326
            
327
            FileSearchOptions.flush();
326
            FileSearchOptions.flush();
327
        }
328
    }
329
330
    private Iterable<? extends FileProvider> getProviders() {
331
        synchronized (this) {
332
            if (providers != null) {
333
                return providers;
334
            }
335
        }
336
        final List<FileProvider> result = new LinkedList<FileProvider>();
337
        for (FileProviderFactory fpf : Lookup.getDefault().lookupAll(FileProviderFactory.class)) {
338
            result.add(fpf.createFileProvider());
339
        }
340
        synchronized (this) {
341
            if (providers == null) {
342
                providers = Collections.unmodifiableList(result);
343
            }
344
            return providers;
328
        }
345
        }
329
    }
346
    }
330
347
Lines 339-344 Link Here
339
    private class Worker implements Runnable {
356
    private class Worker implements Runnable {
340
357
341
        private volatile boolean isCanceled = false;
358
        private volatile boolean isCanceled = false;
359
        private volatile FileProvider currentProvider;
342
360
343
        private final String text;
361
        private final String text;
344
        private final QuerySupport.Kind searchType;
362
        private final QuerySupport.Kind searchType;
Lines 391-398 Link Here
391
            if ( panel.time != -1 ) {
409
            if ( panel.time != -1 ) {
392
                LOGGER.fine( "Worker for text " + text + " canceled after " + ( System.currentTimeMillis() - createTime ) + " ms."  );
410
                LOGGER.fine( "Worker for text " + text + " canceled after " + ( System.currentTimeMillis() - createTime ) + " ms."  );
393
            }
411
            }
412
            FileProvider provider;
394
            synchronized (this) {
413
            synchronized (this) {
395
                isCanceled = true;
414
                isCanceled = true;
415
                provider = currentProvider;
416
            }
417
            if (provider != null) {
418
                    provider.cancel();
396
            }
419
            }
397
        }
420
        }
398
421
Lines 402-413 Link Here
402
                case CASE_INSENSITIVE_PREFIX:
425
                case CASE_INSENSITIVE_PREFIX:
403
                case CASE_INSENSITIVE_REGEXP:
426
                case CASE_INSENSITIVE_REGEXP:
404
                    searchField = FileIndexer.FIELD_CASE_INSENSITIVE_NAME; break;
427
                    searchField = FileIndexer.FIELD_CASE_INSENSITIVE_NAME; break;
405
                    
406
                default:
428
                default:
407
                    searchField = FileIndexer.FIELD_NAME; break;
429
                    searchField = FileIndexer.FIELD_NAME; break;
408
            }
430
            }
409
431
410
            Collection<? extends FileObject> roots = QuerySupport.findRoots((Project) null, null, Collections.<String>emptyList(), Collections.<String>emptyList());
432
            final Collection<FileObject> roots = new ArrayList<FileObject>(QuerySupport.findRoots((Project) null, null, Collections.<String>emptyList(), Collections.<String>emptyList()));
411
            try {
433
            try {
412
                QuerySupport q = QuerySupport.forRoots(FileIndexer.ID, FileIndexer.VERSION, roots.toArray(new FileObject [roots.size()]));
434
                QuerySupport q = QuerySupport.forRoots(FileIndexer.ID, FileIndexer.VERSION, roots.toArray(new FileObject [roots.size()]));
413
                Collection<? extends IndexResult> results = q.query(searchField, text, searchType);
435
                Collection<? extends IndexResult> results = q.query(searchField, text, searchType);
Lines 430-447 Link Here
430
                    files.add(fd);
452
                    files.add(fd);
431
                    LOGGER.finer("Found: " + file.getPath() + ", project=" + project + ", currentProject=" + currentProject + ", preferred=" + preferred);
453
                    LOGGER.finer("Found: " + file.getPath() + ", project=" + project + ", currentProject=" + currentProject + ", preferred=" + preferred);
432
                }
454
                }
455
                if (isCanceled) {
456
                    return files;
457
                }
458
459
                final Project[] projects = OpenProjects.getDefault().getOpenProjects();
460
                final List<FileObject> sgRoots = new LinkedList<FileObject>();
461
                for (Project p : projects) {
462
                    for (SourceGroup group: ProjectUtils.getSources(p).getSourceGroups(Sources.TYPE_GENERIC)) {
463
                        sgRoots.add(group.getRootFolder());
464
                    }
465
                }
466
                //Ask GTF providers
467
                final FileProvider.Context ctx = FileProviderAccessor.getInstance().createContext(text, toJumpToSearchType(searchType), currentProject);
468
                final FileProvider.Result fpR = FileProviderAccessor.getInstance().createResult(files,new String[1], ctx);
469
                for (FileProvider provider : getProviders()) {
470
                    currentProvider = provider;
471
                    try {
472
                        for (FileObject root : sgRoots) {
473
                            FileProviderAccessor.getInstance().setRoot(ctx, root);
474
                            boolean recognized = provider.computeFiles(ctx, fpR);
475
                            if (recognized) {
476
                                roots.add(root);
477
                            }
478
                        }
479
                    } finally {
480
                        currentProvider = null;
481
                        if (isCanceled) {
482
                            return files;
483
                        }
484
                    }
485
                }
486
433
                //PENDING Now we have to search folders which not included in Search API
487
                //PENDING Now we have to search folders which not included in Search API
434
                Project[] projects = OpenProjects.getDefault().getOpenProjects();
488
                Collection <FileObject> allFolders = new ArrayList<FileObject>();
435
                Enumeration <? extends FileObject> projectFolders;
436
                Collection <? extends FileObject> allFolders = new ArrayList<FileObject>();
437
                final FileObjectFilter[] filters = new FileObjectFilter[]{SearchInfoFactory.VISIBILITY_FILTER, SearchInfoFactory.SHARABILITY_FILTER};
489
                final FileObjectFilter[] filters = new FileObjectFilter[]{SearchInfoFactory.VISIBILITY_FILTER, SearchInfoFactory.SHARABILITY_FILTER};
438
                for (Project p : projects) {
490
                for (FileObject root : sgRoots) {
439
                    Sources s  = ProjectUtils.getSources(p);
491
                    allFolders = searchSources(root, allFolders, roots, filters);
440
                    SourceGroup[] groups = s.getSourceGroups(Sources.TYPE_GENERIC);
441
                    for (SourceGroup group: groups) {
442
                        FileObject root = group.getRootFolder();
443
                          allFolders = searchSources(root, allFolders, roots, filters);
444
                    }
445
                }
492
                }
446
                //Looking for matching files in all found folders
493
                //Looking for matching files in all found folders
447
                for (FileObject folder: allFolders) {
494
                for (FileObject folder: allFolders) {
Lines 467-473 Link Here
467
                        }
514
                        }
468
                    }
515
                    }
469
                }
516
                }
470
                Collections.sort(files, new FileDescription.FDComarator(panel.isPreferedProject(), panel.isCaseSensitive()));
517
                Collections.sort(files, new FDComarator(panel.isPreferedProject(), panel.isCaseSensitive()));
471
                return files;
518
                return files;
472
            } catch (PatternSyntaxException pse) {
519
            } catch (PatternSyntaxException pse) {
473
                return Collections.<FileDescription>emptyList();
520
                return Collections.<FileDescription>emptyList();
Lines 475-528 Link Here
475
                LOGGER.log(Level.WARNING, null, ioe);
522
                LOGGER.log(Level.WARNING, null, ioe);
476
                return Collections.<FileDescription>emptyList();
523
                return Collections.<FileDescription>emptyList();
477
            }
524
            }
525
        }
478
526
479
527
        private SearchType toJumpToSearchType(final QuerySupport.Kind searchType) {
480
//            // TODO: Search twice, first for current project, then for all projects
528
            switch (searchType) {
481
//            List<TypeDescriptor> items;
529
                case CAMEL_CASE:
482
//            // Multiple providers: merge results
530
                case CASE_INSENSITIVE_CAMEL_CASE:
483
//            items = new ArrayList<TypeDescriptor>(128);
531
                    return org.netbeans.spi.jumpto.type.SearchType.CAMEL_CASE;
484
//            String[] message = new String[1];
532
                case CASE_INSENSITIVE_PREFIX:
485
//            TypeProvider.Context context = TypeProviderAccessor.DEFAULT.createContext(null, text, nameKind);
533
                    return org.netbeans.spi.jumpto.type.SearchType.CASE_INSENSITIVE_PREFIX;
486
//            TypeProvider.Result result = TypeProviderAccessor.DEFAULT.createResult(items, message);
534
                case CASE_INSENSITIVE_REGEXP:
487
//            if (typeProviders == null) {
535
                    return org.netbeans.spi.jumpto.type.SearchType.CASE_INSENSITIVE_REGEXP;
488
//                typeProviders = Lookup.getDefault().lookupAll(TypeProvider.class);
536
                case EXACT:
489
//            }
537
                    return org.netbeans.spi.jumpto.type.SearchType.EXACT_NAME;
490
//            for (TypeProvider provider : typeProviders) {
538
                case PREFIX:
491
//                if (isCanceled) {
539
                    return org.netbeans.spi.jumpto.type.SearchType.PREFIX;
492
//                    return null;
540
                case REGEXP:
493
//                }
541
                    return org.netbeans.spi.jumpto.type.SearchType.REGEXP;
494
//                current = provider;
542
                default:
495
//                long start = System.currentTimeMillis();
543
                    throw new IllegalArgumentException();
496
//                try {
544
            }
497
//                    LOGGER.fine("Calling TypeProvider: " + provider);
498
//                    provider.computeTypeNames(context, result);
499
//                } finally {
500
//                    current = null;
501
//                }
502
//                long delta = System.currentTimeMillis() - start;
503
//                LOGGER.fine("Provider '" + provider.getDisplayName() + "' took " + delta + " ms.");
504
//
505
//            }
506
//            if ( !isCanceled ) {
507
//                //time = System.currentTimeMillis();
508
//                Collections.sort(items, new TypeComparator());
509
//                panel.setWarning(message[0]);
510
//                //sort += System.currentTimeMillis() - time;
511
//                //LOGGER.fine("PERF - " + " GSS:  " + gss + " GSB " + gsb + " CP: " + cp + " SFB: " + sfb + " GTN: " + gtn + "  ADD: " + add + "  SORT: " + sort );
512
//                return items;
513
//            }
514
//            else {
515
//                return null;
516
//            }
517
        }
545
        }
518
    } // End of Worker class
546
    } // End of Worker class
519
547
520
    private Collection<? extends FileObject> searchSources(FileObject root, Collection<? extends FileObject> result, Collection<? extends FileObject> exclude, FileObjectFilter[] filters) {
548
    private Collection<FileObject> searchSources(FileObject root, Collection<FileObject> result, Collection<? extends FileObject> exclude, FileObjectFilter[] filters) {
521
        if (root.getChildren().length == 0 || exclude.contains(root) || !checkAgainstFilters(root, filters)) {
549
        if (root.getChildren().length == 0 || exclude.contains(root) || !checkAgainstFilters(root, filters)) {
522
            return result;
550
            return result;
523
        } else {
551
        } else {
524
//            if (!exclude.contains(root)) {
552
//            if (!exclude.contains(root)) {
525
                ((Collection<FileObject>)result).add(root);
553
                result.add(root);
526
                Enumeration<? extends FileObject> subFolders = root.getFolders(false);
554
                Enumeration<? extends FileObject> subFolders = root.getFolders(false);
527
                while (subFolders.hasMoreElements()) {
555
                while (subFolders.hasMoreElements()) {
528
                    searchSources(subFolders.nextElement(), result, exclude, filters);
556
                    searchSources(subFolders.nextElement(), result, exclude, filters);
Lines 681-687 Link Here
681
                panel.setSelectedFile();
709
                panel.setSelectedFile();
682
            }
710
            }
683
        }
711
        }
684
        
685
    }
712
    }
686
    
713
714
    //Inner classes
715
    public static class FDComarator implements Comparator<FileDescription> {
716
717
        private boolean usePrefered;
718
        private boolean caseSensitive;
719
720
        public FDComarator(boolean usePrefered, boolean caseSensitive ) {
721
            this.usePrefered = usePrefered;
722
            this.caseSensitive = caseSensitive;
723
        }
724
725
        public int compare(FileDescription o1, FileDescription o2) {
726
727
            // If prefered prefer prefered
728
            if ( usePrefered ) {
729
                if ( o1.isFromCurrentProject() && !o2.isFromCurrentProject()) {
730
                    return -1;
731
                }
732
                if ( !o1.isFromCurrentProject() && o2.isFromCurrentProject()) {
733
                    return 1;
734
                }
735
            }
736
737
            // File name
738
            int cmpr = compareStrings( o1.getFileName(), o2.getFileName(), caseSensitive );
739
            if ( cmpr != 0 ) {
740
                return cmpr;
741
            }
742
743
            // Project name
744
            cmpr = compareStrings( o1.getProjectName(), o2.getProjectName(), caseSensitive );
745
            if ( cmpr != 0 ) {
746
                return cmpr;
747
            }
748
749
            // Relative location
750
            cmpr = compareStrings( o1.getOwnerPath(), o2.getOwnerPath(), caseSensitive );
751
752
            return cmpr;
753
754
        }
755
756
        private int compareStrings(String s1, String s2, boolean caseSensitive) {
757
            if( s1 == null ) {
758
                s1 = "";    //NOI18N
759
            }
760
            if ( s2 == null ) {
761
                s2 = "";    //NOI18N
762
            }
763
764
765
            return caseSensitive ? s1.compareTo( s2 ) : s1.compareToIgnoreCase( s2 );
766
        }
767
    }
768
769
    private static class RendererComponent extends JPanel {
770
	private FileDescription fd;
771
772
	void setDescription(FileDescription fd) {
773
	    this.fd = fd;
774
	    putClientProperty(TOOL_TIP_TEXT_KEY, null);
775
	}
776
777
	@Override
778
	public String getToolTipText() {
779
	    String text = (String) getClientProperty(TOOL_TIP_TEXT_KEY);
780
	    if( text == null ) {
781
                if( fd != null) {
782
                    text = FileUtil.getFileDisplayName(fd.getFileObject());
783
                }
784
                putClientProperty(TOOL_TIP_TEXT_KEY, text);
785
	    }
786
	    return text;
787
	}
788
    }
789
790
    public static class Renderer extends DefaultListCellRenderer implements ChangeListener {
791
792
        public  static Icon WAIT_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/jumpto/resources/wait.gif", false); // NOI18N
793
794
        private RendererComponent rendererComponent;
795
        private JLabel jlName = new JLabel();
796
        private JLabel jlPath = new JLabel();
797
        private JLabel jlPrj = new JLabel();
798
        private int DARKER_COLOR_COMPONENT = 5;
799
        private int LIGHTER_COLOR_COMPONENT = 80;
800
        private Color fgColor;
801
        private Color fgColorLighter;
802
        private Color bgColor;
803
        private Color bgColorDarker;
804
        private Color bgSelectionColor;
805
        private Color fgSelectionColor;
806
        private Color bgColorGreener;
807
        private Color bgColorDarkerGreener;
808
809
        private JList jList;
810
811
        private boolean colorPrefered;
812
813
        public Renderer( JList list ) {
814
815
            jList = list;
816
817
            Container container = list.getParent();
818
            if ( container instanceof JViewport ) {
819
                ((JViewport)container).addChangeListener(this);
820
                stateChanged(new ChangeEvent(container));
821
            }
822
823
            rendererComponent = new RendererComponent();
824
            rendererComponent.setLayout(new BorderLayout());
825
            rendererComponent.add( jlName, BorderLayout.WEST );
826
            rendererComponent.add( jlPath, BorderLayout.CENTER);
827
            rendererComponent.add( jlPrj, BorderLayout.EAST );
828
829
830
            jlName.setOpaque(false);
831
            jlPath.setOpaque(false);
832
            jlPrj.setOpaque(false);
833
834
            jlName.setFont(list.getFont());
835
            jlPath.setFont(list.getFont());
836
            jlPrj.setFont(list.getFont());
837
838
839
            jlPrj.setHorizontalAlignment(RIGHT);
840
            jlPrj.setHorizontalTextPosition(LEFT);
841
842
            // setFont( list.getFont() );
843
            fgColor = list.getForeground();
844
            fgColorLighter = new Color(
845
                                   Math.min( 255, fgColor.getRed() + LIGHTER_COLOR_COMPONENT),
846
                                   Math.min( 255, fgColor.getGreen() + LIGHTER_COLOR_COMPONENT),
847
                                   Math.min( 255, fgColor.getBlue() + LIGHTER_COLOR_COMPONENT)
848
                                  );
849
850
            bgColor = list.getBackground();
851
            bgColorDarker = new Color(
852
                                    Math.abs(bgColor.getRed() - DARKER_COLOR_COMPONENT),
853
                                    Math.abs(bgColor.getGreen() - DARKER_COLOR_COMPONENT),
854
                                    Math.abs(bgColor.getBlue() - DARKER_COLOR_COMPONENT)
855
                            );
856
            bgSelectionColor = list.getSelectionBackground();
857
            fgSelectionColor = list.getSelectionForeground();
858
859
860
            bgColorGreener = new Color(
861
                                    Math.abs(bgColor.getRed() - 20),
862
                                    Math.min(255, bgColor.getGreen() + 10 ),
863
                                    Math.abs(bgColor.getBlue() - 20) );
864
865
866
            bgColorDarkerGreener = new Color(
867
                                    Math.abs(bgColorDarker.getRed() - 35),
868
                                    Math.min(255, bgColorDarker.getGreen() + 5 ),
869
                                    Math.abs(bgColorDarker.getBlue() - 35) );
870
        }
871
872
        public @Override Component getListCellRendererComponent( JList list,
873
                                                       Object value,
874
                                                       int index,
875
                                                       boolean isSelected,
876
                                                       boolean hasFocus) {
877
878
            // System.out.println("Renderer for index " + index );
879
880
            int height = list.getFixedCellHeight();
881
            int width = list.getFixedCellWidth() - 1;
882
883
            width = width < 200 ? 200 : width;
884
885
            // System.out.println("w, h " + width + ", " + height );
886
887
            Dimension size = new Dimension( width, height );
888
            rendererComponent.setMaximumSize(size);
889
            rendererComponent.setPreferredSize(size);
890
891
            if ( isSelected ) {
892
                jlName.setForeground(fgSelectionColor);
893
                jlPath.setForeground(fgSelectionColor);
894
                jlPrj.setForeground(fgSelectionColor);
895
                rendererComponent.setBackground(bgSelectionColor);
896
            }
897
            else {
898
                jlName.setForeground(fgColor);
899
                jlPath.setForeground(fgColorLighter);
900
                jlPrj.setForeground(fgColor);
901
                rendererComponent.setBackground( index % 2 == 0 ? bgColor : bgColorDarker );
902
            }
903
904
            if ( value instanceof FileDescription ) {
905
                FileDescription fd = (FileDescription)value;
906
                jlName.setIcon(fd.getIcon());
907
                jlName.setText(fd.getFileName());
908
                jlPath.setIcon(null);
909
                jlPath.setHorizontalAlignment(SwingConstants.LEFT);
910
                jlPath.setText(fd.getOwnerPath().length() > 0 ? " (" + fd.getOwnerPath() + ")" : " ()"); //NOI18N
911
                jlPrj.setText(fd.getProjectName());
912
                jlPrj.setIcon(fd.getProjectIcon());
913
                if ( !isSelected ) {
914
                    rendererComponent.setBackground( index % 2 == 0 ?
915
                        ( fd.isFromCurrentProject() && colorPrefered ? bgColorGreener : bgColor ) :
916
                        ( fd.isFromCurrentProject() && colorPrefered ? bgColorDarkerGreener : bgColorDarker ) );
917
                }
918
                rendererComponent.setDescription(fd);
919
            }
920
            else {
921
                jlName.setText( "" ); // NOI18M
922
                jlName.setIcon(null);
923
                jlPath.setIcon(Renderer.WAIT_ICON);
924
                jlPath.setHorizontalAlignment(SwingConstants.CENTER);
925
                jlPath.setText( value.toString() );
926
                jlPrj.setIcon(null);
927
                jlPrj.setText( "" ); // NOI18N
928
            }
929
930
            return rendererComponent;
931
        }
932
933
        @Override
934
        public void stateChanged(ChangeEvent event) {
935
936
            JViewport jv = (JViewport)event.getSource();
937
938
            jlName.setText( "Sample" ); // NOI18N
939
            jlName.setIcon( new ImageIcon() );
940
941
            jList.setFixedCellHeight(jlName.getPreferredSize().height);
942
            jList.setFixedCellWidth(jv.getExtentSize().width);
943
        }
944
945
        public void setColorPrefered( boolean colorPrefered ) {
946
            this.colorPrefered = colorPrefered;
947
        }
948
949
     }
687
}
950
}
(-)a/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchPanel.java (-7 / +8 lines)
Lines 75-82 Link Here
75
 * @author  Petr Hrebejk, Andrei Badea
75
 * @author  Petr Hrebejk, Andrei Badea
76
 */
76
 */
77
public class FileSearchPanel extends javax.swing.JPanel implements ActionListener {
77
public class FileSearchPanel extends javax.swing.JPanel implements ActionListener {
78
    
78
79
    private static final int BRIGHTER_COLOR_COMPONENT = 10;    
79
    public static final String SEARCH_IN_PROGRES = NbBundle.getMessage(FileSearchPanel.class, "TXT_SearchingOtherProjects"); // NOI18N
80
    private static final int BRIGHTER_COLOR_COMPONENT = 10;
80
    private final ContentProvider contentProvider;
81
    private final ContentProvider contentProvider;
81
    private final Project currentProject;
82
    private final Project currentProject;
82
    private boolean containsScrollPane;
83
    private boolean containsScrollPane;
Lines 160-166 Link Here
160
               if (model.getSize() > 0 || getText() == null || getText().trim().length() == 0 ) {
161
               if (model.getSize() > 0 || getText() == null || getText().trim().length() == 0 ) {
161
                   resultList.setModel(model);
162
                   resultList.setModel(model);
162
                   resultList.setSelectedIndex(0);
163
                   resultList.setSelectedIndex(0);
163
                   ((FileDescription.Renderer) resultList.getCellRenderer()).setColorPrefered(isPreferedProject());
164
                   ((FileSearchAction.Renderer) resultList.getCellRenderer()).setColorPrefered(isPreferedProject());
164
                   setListPanelContent(null,false);
165
                   setListPanelContent(null,false);
165
                   if ( time != -1 ) {
166
                   if ( time != -1 ) {
166
                       FileSearchAction.LOGGER.fine("Real search time " + (System.currentTimeMillis() - time) + " ms.");
167
                       FileSearchAction.LOGGER.fine("Real search time " + (System.currentTimeMillis() - time) + " ms.");
Lines 219-225 Link Here
219
        else if ( message != null ) { 
220
        else if ( message != null ) { 
220
           jTextFieldLocation.setText(""); 
221
           jTextFieldLocation.setText(""); 
221
           messageLabel.setText(message);
222
           messageLabel.setText(message);
222
           messageLabel.setIcon( waitIcon ? FileDescription.Renderer.WAIT_ICON : null);
223
           messageLabel.setIcon( waitIcon ? FileSearchAction.Renderer.WAIT_ICON : null);
223
           if ( containsScrollPane ) {
224
           if ( containsScrollPane ) {
224
               listPanel.remove( resultScrollPane );
225
               listPanel.remove( resultScrollPane );
225
               listPanel.add( messageLabel );
226
               listPanel.add( messageLabel );
Lines 445-451 Link Here
445
        if ( "selectNextRow".equals(actionKey) && 
446
        if ( "selectNextRow".equals(actionKey) && 
446
              ( selectedIndex == modelSize - 1 ||
447
              ( selectedIndex == modelSize - 1 ||
447
                ( selectedIndex == modelSize - 2 && 
448
                ( selectedIndex == modelSize - 2 && 
448
                  model.getElementAt(modelSize - 1) == FileDescription.SEARCH_IN_PROGRES )
449
                  model.getElementAt(modelSize - 1) == SEARCH_IN_PROGRES )
449
             ) ) {
450
             ) ) {
450
            resultList.setSelectedIndex(0);
451
            resultList.setSelectedIndex(0);
451
            resultList.ensureIndexIsVisible(0);
452
            resultList.ensureIndexIsVisible(0);
Lines 455-461 Link Here
455
                   selectedIndex == 0 ) {
456
                   selectedIndex == 0 ) {
456
            int last = modelSize - 1;
457
            int last = modelSize - 1;
457
            
458
            
458
            if ( model.getElementAt(last) == FileDescription.SEARCH_IN_PROGRES ) {
459
            if ( model.getElementAt(last) == SEARCH_IN_PROGRES ) {
459
                last--;
460
                last--;
460
            } 
461
            } 
461
            
462
            
Lines 513-519 Link Here
513
    }        
514
    }        
514
    
515
    
515
    public void setSelectedFile() {
516
    public void setSelectedFile() {
516
        List<FileDescription> list = new ArrayList(Arrays.asList(resultList.getSelectedValues()));
517
        List<FileDescription> list = new ArrayList<FileDescription>(Arrays.asList((FileDescription[])resultList.getSelectedValues()));
517
        selectedFile = list.toArray(new FileDescription[0]);
518
        selectedFile = list.toArray(new FileDescription[0]);
518
    }
519
    }
519
520
(-)a/jumpto/src/org/netbeans/spi/jumpto/file/FileProvider.java (+246 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.jumpto.file;
41
42
import java.util.List;
43
import org.netbeans.api.project.FileOwnerQuery;
44
import org.netbeans.api.project.Project;
45
import org.netbeans.api.project.SourceGroup;
46
import org.netbeans.modules.jumpto.file.FileDescription;
47
import org.netbeans.modules.jumpto.file.FileProviderAccessor;
48
import org.netbeans.spi.jumpto.type.SearchType;
49
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileUtil;
51
import org.openide.util.Lookup;
52
import org.openide.util.Parameters;
53
54
/**
55
 * A FileProvider participates in the Goto File dialog by providing matched files
56
 * for given {@link SourceGroup}.
57
 * The FileProviders are registered in global {@link Lookup}
58
 *
59
 * @since 1.15
60
 * @author Tomas Zezula
61
 */
62
public interface FileProvider {
63
64
    /**
65
     * Compute a list of files that match the given search text for the given
66
     * search type. This might be a slow operation, and the infrastructure may end
67
     * up calling {@link #cancel} on the file provider during the operation, in which
68
     * case the method can return incomplete results.
69
     * <p>
70
     * Note that a useful performance optimization is for the FileProvider to cache
71
     * a few of its most recent search results, and if the next search (e.g. more user
72
     * keystrokes) is a simple narrowing of the search, just filter the previous search
73
     * result. The same {@link FileProvider} instance is used during the GoTo File session and
74
     * it's freed when the GoTo File dialog is closed.
75
     *
76
     * @param context search context containg search text, type, project and {@link SourceGroup} root
77
     * @param result  filled with files and optional message
78
     * @return returns true if the root was handled by this FileProvider. When false
79
     * next provider is used.
80
     */
81
    boolean computeFiles(Context context, Result result);
82
83
    /**
84
     * Cancel the current operation, if possible. This might be called if the user
85
     * has typed something (including the backspace key) which makes the current
86
     * search obsolete and a new one should be initiated.
87
     */
88
    void cancel();
89
90
    /**
91
     * Represents search context.
92
     * Contains search type (such as prefix, regexp), search text,
93
     * {@link SourceGroup} root and project where to search.
94
     *
95
     */
96
    public static final class Context {
97
98
        //<editor-fold defaultstate="collapsed" desc="Private data">
99
        private final String text;
100
        private final SearchType type;
101
        private final Project currentProject;
102
        private FileObject sourceGroupRoot;
103
        private Project project;
104
        //</editor-fold>
105
106
        /**
107
         * Returns project owning the {@link SourceGroup} root
108
         * @return project to search in.
109
         */
110
        public Project getProject() {
111
            if (project == null) {
112
                project = FileOwnerQuery.getOwner(this.sourceGroupRoot);
113
            }
114
            return project;
115
        }
116
117
        /**
118
         * Returns the {@link SourceGroup} root to search files in.
119
         * @return root to search in.
120
         */
121
        public FileObject getRoot() { return sourceGroupRoot;}
122
123
        /**
124
          * Return the text used for search.
125
          *
126
          * @return The text used for the search; e.g. when getSearchType() == SearchType.PREFIX,
127
          *   text is the prefix that all returned types should start with.
128
          */
129
        public String getText() { return text; }
130
131
        /**
132
         * Return the type of search.
133
         *
134
         * @return Type of search performed, such as prefix, regexp or camel case.
135
         */
136
        public SearchType getSearchType() { return type; }
137
138
        //<editor-fold defaultstate="collapsed" desc="Private methods">
139
        private Context(String text, SearchType type, Project currentProject) {
140
            Parameters.notNull("text", text);   //NOI18N
141
            Parameters.notNull("type", type);   //NOI18N
142
            this.text = text;
143
            this.type = type;
144
            this.currentProject = currentProject;
145
        }
146
147
        private Project getCurrentProject() {
148
            return currentProject;
149
        }
150
151
        static {
152
            FileProviderAccessor.setInstance(new FileProviderAccessor() {
153
                @Override
154
                public Context createContext(String text, SearchType searchType, Project currentProject) {
155
                    return new Context(text, searchType,currentProject);
156
                }
157
                @Override
158
                public Result createResult(List<? super FileDescription> result, String[] message, Context ctx) {
159
                    return new Result(result, message, ctx);
160
                }
161
                @Override
162
                public int getRetry(Result result) {
163
                    return result.retry;
164
                }
165
166
                @Override
167
                public void setRoot(Context ctx, FileObject root) {
168
                    ctx.sourceGroupRoot = root;
169
                    ctx.project = null;
170
                }
171
            });
172
        }
173
        //</editor-fold>
174
    }
175
176
    /**
177
     * Represents a collection of files that match
178
     * the given search criteria. Moreover, it can contain message
179
     * for the user, such as an incomplete search result.
180
     *
181
     */
182
    public static final class Result {
183
184
        //<editor-fold defaultstate="collapsed" desc="Private data">
185
        private final List<? super FileDescription> result;
186
        private final String[] message;
187
        private final Context ctx;
188
        private int retry;
189
        //</editor-fold>
190
191
        /**
192
         * Optional message. It can inform the user about result, e.g.
193
         * that result can be incomplete etc.
194
         *
195
         * @param  msg  message
196
         */
197
        public void setMessage(String msg) {
198
            message[0] = msg;
199
        }
200
201
        /**
202
         * Adds a file into the result
203
         * When the file is under processed {@link  SourceGroup} relative path
204
         * is displayed in the dialog. If the file is not under
205
         * {@link SourceGroup} absolute path is used. Never add a file owned by
206
         * other {@link SourceGroup}.
207
         * @param file The file to be added into result
208
         */
209
        public void addFile (final FileObject file) {
210
            Parameters.notNull("file", file);   //NOI18N
211
212
            String path = FileUtil.getRelativePath(ctx.getRoot(), file);
213
            if (path == null) {
214
                path = FileUtil.getFileDisplayName(file);
215
            }
216
            final Project prj = ctx.getProject();
217
            final Project curPrj = ctx.getCurrentProject();
218
            result.add(new FileDescription(file, path, prj,
219
                curPrj != null && prj != null && curPrj.getProjectDirectory() == prj.getProjectDirectory()));
220
        }
221
222
        /**
223
         * Notify caller that a provider should be called again because
224
         * of incomplete or inaccurate results.
225
         *
226
         * Method can be used when long running task blocks the provider
227
         * to complete the data.
228
         *
229
         */
230
        public void pendingResult() {
231
            retry = 2000;
232
        }
233
234
        //<editor-fold defaultstate="collapsed" desc="Private constructor">
235
        private Result(final List<? super FileDescription> result, final String[] message, final Context ctx) {
236
            Parameters.notNull("result", result);   //NOI18N
237
            Parameters.notNull("message", message); //NOI18N
238
            Parameters.notNull("ctx", ctx);
239
            this.result = result;
240
            this.message = message;
241
            this.ctx = ctx;
242
        }
243
        //</editor-fold>
244
    }
245
246
}
(-)a/jumpto/src/org/netbeans/spi/jumpto/file/FileProviderFactory.java (+69 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.jumpto.file;
41
42
/**
43
 * Factory to create {@link FileProvider}s
44
 * @since 1.15
45
 * @author Tomas Zezula
46
 */
47
public interface FileProviderFactory {
48
    /**
49
     * Describe this provider with an internal name, used by logging.
50
     * @return An internal String uniquely identifying {@link FileProvider}, such as
51
     * "java"
52
     */
53
    String name();
54
55
    /**
56
     * Describe this provider for the user, used by logging.
57
     * @return A display name describing the {@link FileProvider}
58
     */
59
    String getDisplayName();
60
61
62
    /**
63
     * Reurns a {@link FileProvider} used in one session of Go To File action.
64
     * The returned provider is freed when the Go To File dialog is closed.
65
     * The {@link FileProvider} may cache some data to improve performance.
66
     * @return a new {@link FileProvider}
67
     */
68
    FileProvider createFileProvider();
69
}
(-)a/jumpto/test/unit/src/org/netbeans/spi/jumpto/file/FileProviderTest.java (+110 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.jumpto.file;
41
42
43
import java.io.File;
44
import java.util.LinkedList;
45
import java.util.List;
46
import org.netbeans.junit.NbTestCase;
47
import org.netbeans.modules.jumpto.file.FileDescription;
48
import org.netbeans.modules.jumpto.file.FileProviderAccessor;
49
import org.netbeans.spi.jumpto.type.SearchType;
50
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.FileUtil;
52
53
/**
54
 *
55
 * @author Tomas Zezula
56
 */
57
public class FileProviderTest extends NbTestCase {
58
59
    private FileObject root;
60
    private FileObject dataFile;
61
    private FileObject externalDataFile;
62
63
    public FileProviderTest(final String name) {
64
        super(name);
65
    }
66
67
    @Override
68
    protected void setUp() throws Exception {
69
        super.setUp();
70
        clearWorkDir();
71
        final File cwd = getWorkDir();
72
        root = FileUtil.createFolder(new File(cwd,"test"));     //NOI18N
73
        dataFile = FileUtil.createData(root, "foo/test.txt");   //NOI18N
74
        externalDataFile = FileUtil.createData(FileUtil.toFileObject(cwd), "external.txt");   //NOI18N
75
    }
76
77
    public void testFileInSourceGroup() {
78
        final FileProvider.Context ctx = FileProviderAccessor.getInstance().createContext("foo", SearchType.EXACT_NAME, null);  //NOI18N
79
        final List<FileDescription> data = new LinkedList<FileDescription>();
80
        final String[] msg = new String[1];
81
        final FileProvider.Result result = FileProviderAccessor.getInstance().createResult(data, msg, ctx);
82
        FileProviderAccessor.getInstance().setRoot(ctx, root);
83
        final String testMsg = "Test Message";  //NOI18N
84
        result.addFile(dataFile);
85
        result.setMessage(testMsg);
86
        assertEquals(1, data.size());
87
        assertEquals(dataFile, data.iterator().next().getFileObject());
88
        assertEquals(dataFile.getNameExt(), data.iterator().next().getFileName());
89
        assertEquals(FileUtil.getRelativePath(root, dataFile), data.iterator().next().getOwnerPath());
90
        assertEquals(testMsg, msg[0]);
91
92
    }
93
94
    public void testExtenralFile() {
95
        final FileProvider.Context ctx = FileProviderAccessor.getInstance().createContext("foo", SearchType.EXACT_NAME, null);  //NOI18N
96
        final List<FileDescription> data = new LinkedList<FileDescription>();
97
        final String[] msg = new String[1];
98
        final FileProvider.Result result = FileProviderAccessor.getInstance().createResult(data, msg, ctx);
99
        FileProviderAccessor.getInstance().setRoot(ctx, root);
100
        final String testMsg = "Test Message";  //NOI18N
101
        result.addFile(externalDataFile);
102
        result.setMessage(testMsg);
103
        assertEquals(1, data.size());
104
        assertEquals(externalDataFile, data.iterator().next().getFileObject());
105
        assertEquals(externalDataFile.getNameExt(), data.iterator().next().getFileName());
106
        assertEquals(FileUtil.getFileDisplayName(externalDataFile), data.iterator().next().getOwnerPath());
107
        assertEquals(testMsg, msg[0]);
108
    }
109
110
}

Return to bug 183344