2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.lang
.ant
.config
.impl
;
18 import com
.intellij
.openapi
.fileChooser
.FileChooser
;
19 import com
.intellij
.openapi
.fileChooser
.FileChooserDescriptor
;
20 import com
.intellij
.openapi
.roots
.ui
.util
.CellAppearanceUtils
;
21 import com
.intellij
.openapi
.roots
.ui
.util
.CompositeAppearance
;
22 import com
.intellij
.openapi
.util
.Factory
;
23 import com
.intellij
.openapi
.util
.IconLoader
;
24 import com
.intellij
.openapi
.util
.WriteExternalException
;
25 import com
.intellij
.openapi
.vfs
.LocalFileSystem
;
26 import com
.intellij
.openapi
.vfs
.VirtualFile
;
27 import com
.intellij
.openapi
.vfs
.VirtualFileManager
;
28 import com
.intellij
.util
.Function
;
29 import com
.intellij
.util
.containers
.ContainerUtil
;
30 import org
.jdom
.Element
;
31 import org
.jetbrains
.annotations
.NonNls
;
35 import java
.io
.FileFilter
;
36 import java
.util
.Arrays
;
37 import java
.util
.List
;
39 public class AllJarsUnderDirEntry
implements AntClasspathEntry
{
40 private static final Icon ALL_JARS_IN_DIR_ICON
= IconLoader
.getIcon("/ant/allJarsInDir.png");
41 private final File myDir
;
42 @NonNls static final String DIR
= "dir";
43 private static final Function
<VirtualFile
, AntClasspathEntry
> CREATE_FROM_VIRTUAL_FILE
= new Function
<VirtualFile
, AntClasspathEntry
>() {
44 public AntClasspathEntry
fun(VirtualFile file
) {
45 return fromVirtualFile(file
);
48 @NonNls public static final String JAR_SUFFIX
= ".jar";
50 public AllJarsUnderDirEntry(final File dir
) {
54 public AllJarsUnderDirEntry(final String osPath
) {
55 this(new File(osPath
));
58 public String
getPresentablePath() {
59 return myDir
.getAbsolutePath();
62 public void writeExternal(final Element dataElement
) throws WriteExternalException
{
63 String url
= VirtualFileManager
.constructUrl(LocalFileSystem
.PROTOCOL
, myDir
.getAbsolutePath().replace(File
.separatorChar
, '/'));
64 dataElement
.setAttribute(DIR
, url
);
67 public void addFilesTo(final List
<File
> files
) {
68 File
[] children
= myDir
.listFiles(new FileFilter() {
69 public boolean accept(File pathname
) {
70 return pathname
.getName().endsWith(JAR_SUFFIX
) && pathname
.isFile();
73 if (children
!= null) files
.addAll(Arrays
.asList(children
));
76 public CompositeAppearance
getAppearance() {
77 CompositeAppearance appearance
= CellAppearanceUtils
.forFile(myDir
);
78 appearance
.setIcon(ALL_JARS_IN_DIR_ICON
);
82 private static AntClasspathEntry
fromVirtualFile(final VirtualFile file
) {
83 return new AllJarsUnderDirEntry(file
.getPath());
86 public static class AddEntriesFactory
implements Factory
<List
<AntClasspathEntry
>> {
87 private final JComponent myParentComponent
;
89 public AddEntriesFactory(final JComponent component
) {
90 myParentComponent
= component
;
93 public List
<AntClasspathEntry
> create() {
94 VirtualFile
[] files
= FileChooser
.chooseFiles(myParentComponent
, new FileChooserDescriptor(false, true, false, false, false, true));
95 if (files
.length
== 0) return null;
96 return ContainerUtil
.map(files
, CREATE_FROM_VIRTUAL_FILE
);