You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FilesystemContainer.java 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.data.util;
  5. import java.io.File;
  6. import java.io.FilenameFilter;
  7. import java.io.IOException;
  8. import java.io.Serializable;
  9. import java.lang.reflect.Method;
  10. import java.util.ArrayList;
  11. import java.util.Arrays;
  12. import java.util.Collection;
  13. import java.util.Collections;
  14. import java.util.Date;
  15. import java.util.Iterator;
  16. import java.util.LinkedList;
  17. import java.util.List;
  18. import com.vaadin.data.Container;
  19. import com.vaadin.data.Item;
  20. import com.vaadin.data.Property;
  21. import com.vaadin.service.FileTypeResolver;
  22. import com.vaadin.terminal.Resource;
  23. /**
  24. * A hierarchical container wrapper for a filesystem.
  25. *
  26. * @author Vaadin Ltd.
  27. * @version
  28. * @VERSION@
  29. * @since 3.0
  30. */
  31. @SuppressWarnings("serial")
  32. public class FilesystemContainer implements Container.Hierarchical {
  33. /**
  34. * String identifier of a file's "name" property.
  35. */
  36. public static String PROPERTY_NAME = "Name";
  37. /**
  38. * String identifier of a file's "size" property.
  39. */
  40. public static String PROPERTY_SIZE = "Size";
  41. /**
  42. * String identifier of a file's "icon" property.
  43. */
  44. public static String PROPERTY_ICON = "Icon";
  45. /**
  46. * String identifier of a file's "last modified" property.
  47. */
  48. public static String PROPERTY_LASTMODIFIED = "Last Modified";
  49. /**
  50. * List of the string identifiers for the available properties.
  51. */
  52. public static Collection<String> FILE_PROPERTIES;
  53. private final static Method FILEITEM_LASTMODIFIED;
  54. private final static Method FILEITEM_NAME;
  55. private final static Method FILEITEM_ICON;
  56. private final static Method FILEITEM_SIZE;
  57. static {
  58. FILE_PROPERTIES = new ArrayList<String>();
  59. FILE_PROPERTIES.add(PROPERTY_NAME);
  60. FILE_PROPERTIES.add(PROPERTY_ICON);
  61. FILE_PROPERTIES.add(PROPERTY_SIZE);
  62. FILE_PROPERTIES.add(PROPERTY_LASTMODIFIED);
  63. FILE_PROPERTIES = Collections.unmodifiableCollection(FILE_PROPERTIES);
  64. try {
  65. FILEITEM_LASTMODIFIED = FileItem.class.getMethod("lastModified",
  66. new Class[] {});
  67. FILEITEM_NAME = FileItem.class.getMethod("getName", new Class[] {});
  68. FILEITEM_ICON = FileItem.class.getMethod("getIcon", new Class[] {});
  69. FILEITEM_SIZE = FileItem.class.getMethod("getSize", new Class[] {});
  70. } catch (final NoSuchMethodException e) {
  71. throw new RuntimeException(
  72. "Internal error finding methods in FilesystemContainer");
  73. }
  74. }
  75. private File[] roots = new File[] {};
  76. private FilenameFilter filter = null;
  77. private boolean recursive = true;
  78. /**
  79. * Constructs a new <code>FileSystemContainer</code> with the specified file
  80. * as the root of the filesystem. The files are included recursively.
  81. *
  82. * @param root
  83. * the root file for the new file-system container. Null values
  84. * are ignored.
  85. */
  86. public FilesystemContainer(File root) {
  87. if (root != null) {
  88. roots = new File[] { root };
  89. }
  90. }
  91. /**
  92. * Constructs a new <code>FileSystemContainer</code> with the specified file
  93. * as the root of the filesystem. The files are included recursively.
  94. *
  95. * @param root
  96. * the root file for the new file-system container.
  97. * @param recursive
  98. * should the container recursively contain subdirectories.
  99. */
  100. public FilesystemContainer(File root, boolean recursive) {
  101. this(root);
  102. setRecursive(recursive);
  103. }
  104. /**
  105. * Constructs a new <code>FileSystemContainer</code> with the specified file
  106. * as the root of the filesystem.
  107. *
  108. * @param root
  109. * the root file for the new file-system container.
  110. * @param extension
  111. * the Filename extension (w/o separator) to limit the files in
  112. * container.
  113. * @param recursive
  114. * should the container recursively contain subdirectories.
  115. */
  116. public FilesystemContainer(File root, String extension, boolean recursive) {
  117. this(root);
  118. this.setFilter(extension);
  119. setRecursive(recursive);
  120. }
  121. /**
  122. * Constructs a new <code>FileSystemContainer</code> with the specified root
  123. * and recursivity status.
  124. *
  125. * @param root
  126. * the root file for the new file-system container.
  127. * @param filter
  128. * the Filename filter to limit the files in container.
  129. * @param recursive
  130. * should the container recursively contain subdirectories.
  131. */
  132. public FilesystemContainer(File root, FilenameFilter filter,
  133. boolean recursive) {
  134. this(root);
  135. this.setFilter(filter);
  136. setRecursive(recursive);
  137. }
  138. /**
  139. * Adds new root file directory. Adds a file to be included as root file
  140. * directory in the <code>FilesystemContainer</code>.
  141. *
  142. * @param root
  143. * the File to be added as root directory. Null values are
  144. * ignored.
  145. */
  146. public void addRoot(File root) {
  147. if (root != null) {
  148. final File[] newRoots = new File[roots.length + 1];
  149. for (int i = 0; i < roots.length; i++) {
  150. newRoots[i] = roots[i];
  151. }
  152. newRoots[roots.length] = root;
  153. roots = newRoots;
  154. }
  155. }
  156. /**
  157. * Tests if the specified Item in the container may have children. Since a
  158. * <code>FileSystemContainer</code> contains files and directories, this
  159. * method returns <code>true</code> for directory Items only.
  160. *
  161. * @param itemId
  162. * the id of the item.
  163. * @return <code>true</code> if the specified Item is a directory,
  164. * <code>false</code> otherwise.
  165. */
  166. @Override
  167. public boolean areChildrenAllowed(Object itemId) {
  168. return itemId instanceof File && ((File) itemId).canRead()
  169. && ((File) itemId).isDirectory();
  170. }
  171. /*
  172. * Gets the ID's of all Items who are children of the specified Item. Don't
  173. * add a JavaDoc comment here, we use the default documentation from
  174. * implemented interface.
  175. */
  176. @Override
  177. public Collection<File> getChildren(Object itemId) {
  178. if (!(itemId instanceof File)) {
  179. return Collections.unmodifiableCollection(new LinkedList<File>());
  180. }
  181. File[] f;
  182. if (filter != null) {
  183. f = ((File) itemId).listFiles(filter);
  184. } else {
  185. f = ((File) itemId).listFiles();
  186. }
  187. if (f == null) {
  188. return Collections.unmodifiableCollection(new LinkedList<File>());
  189. }
  190. final List<File> l = Arrays.asList(f);
  191. Collections.sort(l);
  192. return Collections.unmodifiableCollection(l);
  193. }
  194. /*
  195. * Gets the parent item of the specified Item. Don't add a JavaDoc comment
  196. * here, we use the default documentation from implemented interface.
  197. */
  198. @Override
  199. public Object getParent(Object itemId) {
  200. if (!(itemId instanceof File)) {
  201. return null;
  202. }
  203. return ((File) itemId).getParentFile();
  204. }
  205. /*
  206. * Tests if the specified Item has any children. Don't add a JavaDoc comment
  207. * here, we use the default documentation from implemented interface.
  208. */
  209. @Override
  210. public boolean hasChildren(Object itemId) {
  211. if (!(itemId instanceof File)) {
  212. return false;
  213. }
  214. String[] l;
  215. if (filter != null) {
  216. l = ((File) itemId).list(filter);
  217. } else {
  218. l = ((File) itemId).list();
  219. }
  220. return (l != null) && (l.length > 0);
  221. }
  222. /*
  223. * Tests if the specified Item is the root of the filesystem. Don't add a
  224. * JavaDoc comment here, we use the default documentation from implemented
  225. * interface.
  226. */
  227. @Override
  228. public boolean isRoot(Object itemId) {
  229. if (!(itemId instanceof File)) {
  230. return false;
  231. }
  232. for (int i = 0; i < roots.length; i++) {
  233. if (roots[i].equals(itemId)) {
  234. return true;
  235. }
  236. }
  237. return false;
  238. }
  239. /*
  240. * Gets the ID's of all root Items in the container. Don't add a JavaDoc
  241. * comment here, we use the default documentation from implemented
  242. * interface.
  243. */
  244. @Override
  245. public Collection<File> rootItemIds() {
  246. File[] f;
  247. // in single root case we use children
  248. if (roots.length == 1) {
  249. if (filter != null) {
  250. f = roots[0].listFiles(filter);
  251. } else {
  252. f = roots[0].listFiles();
  253. }
  254. } else {
  255. f = roots;
  256. }
  257. if (f == null) {
  258. return Collections.unmodifiableCollection(new LinkedList<File>());
  259. }
  260. final List<File> l = Arrays.asList(f);
  261. Collections.sort(l);
  262. return Collections.unmodifiableCollection(l);
  263. }
  264. /**
  265. * Returns <code>false</code> when conversion from files to directories is
  266. * not supported.
  267. *
  268. * @param itemId
  269. * the ID of the item.
  270. * @param areChildrenAllowed
  271. * the boolean value specifying if the Item can have children or
  272. * not.
  273. * @return <code>true</code> if the operaton is successful otherwise
  274. * <code>false</code>.
  275. * @throws UnsupportedOperationException
  276. * if the setChildrenAllowed is not supported.
  277. */
  278. @Override
  279. public boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed)
  280. throws UnsupportedOperationException {
  281. throw new UnsupportedOperationException(
  282. "Conversion file to/from directory is not supported");
  283. }
  284. /**
  285. * Returns <code>false</code> when moving files around in the filesystem is
  286. * not supported.
  287. *
  288. * @param itemId
  289. * the ID of the item.
  290. * @param newParentId
  291. * the ID of the Item that's to be the new parent of the Item
  292. * identified with itemId.
  293. * @return <code>true</code> if the operation is successful otherwise
  294. * <code>false</code>.
  295. * @throws UnsupportedOperationException
  296. * if the setParent is not supported.
  297. */
  298. @Override
  299. public boolean setParent(Object itemId, Object newParentId)
  300. throws UnsupportedOperationException {
  301. throw new UnsupportedOperationException("File moving is not supported");
  302. }
  303. /*
  304. * Tests if the filesystem contains the specified Item. Don't add a JavaDoc
  305. * comment here, we use the default documentation from implemented
  306. * interface.
  307. */
  308. @Override
  309. public boolean containsId(Object itemId) {
  310. if (!(itemId instanceof File)) {
  311. return false;
  312. }
  313. boolean val = false;
  314. // Try to match all roots
  315. for (int i = 0; i < roots.length; i++) {
  316. try {
  317. val |= ((File) itemId).getCanonicalPath().startsWith(
  318. roots[i].getCanonicalPath());
  319. } catch (final IOException e) {
  320. // Exception ignored
  321. }
  322. }
  323. if (val && filter != null) {
  324. val &= filter.accept(((File) itemId).getParentFile(),
  325. ((File) itemId).getName());
  326. }
  327. return val;
  328. }
  329. /*
  330. * Gets the specified Item from the filesystem. Don't add a JavaDoc comment
  331. * here, we use the default documentation from implemented interface.
  332. */
  333. @Override
  334. public Item getItem(Object itemId) {
  335. if (!(itemId instanceof File)) {
  336. return null;
  337. }
  338. return new FileItem((File) itemId);
  339. }
  340. /**
  341. * Internal recursive method to add the files under the specified directory
  342. * to the collection.
  343. *
  344. * @param col
  345. * the collection where the found items are added
  346. * @param f
  347. * the root file where to start adding files
  348. */
  349. private void addItemIds(Collection<File> col, File f) {
  350. File[] l;
  351. if (filter != null) {
  352. l = f.listFiles(filter);
  353. } else {
  354. l = f.listFiles();
  355. }
  356. if (l == null) {
  357. // File.listFiles returns null if File does not exist or if there
  358. // was an IO error (permission denied)
  359. return;
  360. }
  361. final List<File> ll = Arrays.asList(l);
  362. Collections.sort(ll);
  363. for (final Iterator<File> i = ll.iterator(); i.hasNext();) {
  364. final File lf = i.next();
  365. col.add(lf);
  366. if (lf.isDirectory()) {
  367. addItemIds(col, lf);
  368. }
  369. }
  370. }
  371. /*
  372. * Gets the IDs of Items in the filesystem. Don't add a JavaDoc comment
  373. * here, we use the default documentation from implemented interface.
  374. */
  375. @Override
  376. public Collection<File> getItemIds() {
  377. if (recursive) {
  378. final Collection<File> col = new ArrayList<File>();
  379. for (int i = 0; i < roots.length; i++) {
  380. addItemIds(col, roots[i]);
  381. }
  382. return Collections.unmodifiableCollection(col);
  383. } else {
  384. File[] f;
  385. if (roots.length == 1) {
  386. if (filter != null) {
  387. f = roots[0].listFiles(filter);
  388. } else {
  389. f = roots[0].listFiles();
  390. }
  391. } else {
  392. f = roots;
  393. }
  394. if (f == null) {
  395. return Collections
  396. .unmodifiableCollection(new LinkedList<File>());
  397. }
  398. final List<File> l = Arrays.asList(f);
  399. Collections.sort(l);
  400. return Collections.unmodifiableCollection(l);
  401. }
  402. }
  403. /**
  404. * Gets the specified property of the specified file Item. The available
  405. * file properties are "Name", "Size" and "Last Modified". If propertyId is
  406. * not one of those, <code>null</code> is returned.
  407. *
  408. * @param itemId
  409. * the ID of the file whose property is requested.
  410. * @param propertyId
  411. * the property's ID.
  412. * @return the requested property's value, or <code>null</code>
  413. */
  414. @Override
  415. public Property<?> getContainerProperty(Object itemId, Object propertyId) {
  416. if (!(itemId instanceof File)) {
  417. return null;
  418. }
  419. if (propertyId.equals(PROPERTY_NAME)) {
  420. return new MethodProperty<Object>(getType(propertyId),
  421. new FileItem((File) itemId), FILEITEM_NAME, null);
  422. }
  423. if (propertyId.equals(PROPERTY_ICON)) {
  424. return new MethodProperty<Object>(getType(propertyId),
  425. new FileItem((File) itemId), FILEITEM_ICON, null);
  426. }
  427. if (propertyId.equals(PROPERTY_SIZE)) {
  428. return new MethodProperty<Object>(getType(propertyId),
  429. new FileItem((File) itemId), FILEITEM_SIZE, null);
  430. }
  431. if (propertyId.equals(PROPERTY_LASTMODIFIED)) {
  432. return new MethodProperty<Object>(getType(propertyId),
  433. new FileItem((File) itemId), FILEITEM_LASTMODIFIED, null);
  434. }
  435. return null;
  436. }
  437. /**
  438. * Gets the collection of available file properties.
  439. *
  440. * @return Unmodifiable collection containing all available file properties.
  441. */
  442. @Override
  443. public Collection<String> getContainerPropertyIds() {
  444. return FILE_PROPERTIES;
  445. }
  446. /**
  447. * Gets the specified property's data type. "Name" is a <code>String</code>,
  448. * "Size" is a <code>Long</code>, "Last Modified" is a <code>Date</code>. If
  449. * propertyId is not one of those, <code>null</code> is returned.
  450. *
  451. * @param propertyId
  452. * the ID of the property whose type is requested.
  453. * @return data type of the requested property, or <code>null</code>
  454. */
  455. @Override
  456. public Class<?> getType(Object propertyId) {
  457. if (propertyId.equals(PROPERTY_NAME)) {
  458. return String.class;
  459. }
  460. if (propertyId.equals(PROPERTY_ICON)) {
  461. return Resource.class;
  462. }
  463. if (propertyId.equals(PROPERTY_SIZE)) {
  464. return Long.class;
  465. }
  466. if (propertyId.equals(PROPERTY_LASTMODIFIED)) {
  467. return Date.class;
  468. }
  469. return null;
  470. }
  471. /**
  472. * Internal method to recursively calculate the number of files under a root
  473. * directory.
  474. *
  475. * @param f
  476. * the root to start counting from.
  477. */
  478. private int getFileCounts(File f) {
  479. File[] l;
  480. if (filter != null) {
  481. l = f.listFiles(filter);
  482. } else {
  483. l = f.listFiles();
  484. }
  485. if (l == null) {
  486. return 0;
  487. }
  488. int ret = l.length;
  489. for (int i = 0; i < l.length; i++) {
  490. if (l[i].isDirectory()) {
  491. ret += getFileCounts(l[i]);
  492. }
  493. }
  494. return ret;
  495. }
  496. /**
  497. * Gets the number of Items in the container. In effect, this is the
  498. * combined amount of files and directories.
  499. *
  500. * @return Number of Items in the container.
  501. */
  502. @Override
  503. public int size() {
  504. if (recursive) {
  505. int counts = 0;
  506. for (int i = 0; i < roots.length; i++) {
  507. counts += getFileCounts(roots[i]);
  508. }
  509. return counts;
  510. } else {
  511. File[] f;
  512. if (roots.length == 1) {
  513. if (filter != null) {
  514. f = roots[0].listFiles(filter);
  515. } else {
  516. f = roots[0].listFiles();
  517. }
  518. } else {
  519. f = roots;
  520. }
  521. if (f == null) {
  522. return 0;
  523. }
  524. return f.length;
  525. }
  526. }
  527. /**
  528. * A Item wrapper for files in a filesystem.
  529. *
  530. * @author Vaadin Ltd.
  531. * @version
  532. * @VERSION@
  533. * @since 3.0
  534. */
  535. public class FileItem implements Item {
  536. /**
  537. * The wrapped file.
  538. */
  539. private final File file;
  540. /**
  541. * Constructs a FileItem from a existing file.
  542. */
  543. private FileItem(File file) {
  544. this.file = file;
  545. }
  546. /*
  547. * Gets the specified property of this file. Don't add a JavaDoc comment
  548. * here, we use the default documentation from implemented interface.
  549. */
  550. @Override
  551. public Property<?> getItemProperty(Object id) {
  552. return getContainerProperty(file, id);
  553. }
  554. /*
  555. * Gets the IDs of all properties available for this item Don't add a
  556. * JavaDoc comment here, we use the default documentation from
  557. * implemented interface.
  558. */
  559. @Override
  560. public Collection<String> getItemPropertyIds() {
  561. return getContainerPropertyIds();
  562. }
  563. /**
  564. * Calculates a integer hash-code for the Property that's unique inside
  565. * the Item containing the Property. Two different Properties inside the
  566. * same Item contained in the same list always have different
  567. * hash-codes, though Properties in different Items may have identical
  568. * hash-codes.
  569. *
  570. * @return A locally unique hash-code as integer
  571. */
  572. @Override
  573. public int hashCode() {
  574. return file.hashCode() ^ FilesystemContainer.this.hashCode();
  575. }
  576. /**
  577. * Tests if the given object is the same as the this object. Two
  578. * Properties got from an Item with the same ID are equal.
  579. *
  580. * @param obj
  581. * an object to compare with this object.
  582. * @return <code>true</code> if the given object is the same as this
  583. * object, <code>false</code> if not
  584. */
  585. @Override
  586. public boolean equals(Object obj) {
  587. if (obj == null || !(obj instanceof FileItem)) {
  588. return false;
  589. }
  590. final FileItem fi = (FileItem) obj;
  591. return fi.getHost() == getHost() && fi.file.equals(file);
  592. }
  593. /**
  594. * Gets the host of this file.
  595. */
  596. private FilesystemContainer getHost() {
  597. return FilesystemContainer.this;
  598. }
  599. /**
  600. * Gets the last modified date of this file.
  601. *
  602. * @return Date
  603. */
  604. public Date lastModified() {
  605. return new Date(file.lastModified());
  606. }
  607. /**
  608. * Gets the name of this file.
  609. *
  610. * @return file name of this file.
  611. */
  612. public String getName() {
  613. return file.getName();
  614. }
  615. /**
  616. * Gets the icon of this file.
  617. *
  618. * @return the icon of this file.
  619. */
  620. public Resource getIcon() {
  621. return FileTypeResolver.getIcon(file);
  622. }
  623. /**
  624. * Gets the size of this file.
  625. *
  626. * @return size
  627. */
  628. public long getSize() {
  629. if (file.isDirectory()) {
  630. return 0;
  631. }
  632. return file.length();
  633. }
  634. /**
  635. * @see java.lang.Object#toString()
  636. */
  637. @Override
  638. public String toString() {
  639. if ("".equals(file.getName())) {
  640. return file.getAbsolutePath();
  641. }
  642. return file.getName();
  643. }
  644. /**
  645. * Filesystem container does not support adding new properties.
  646. *
  647. * @see com.vaadin.data.Item#addItemProperty(Object, Property)
  648. */
  649. @Override
  650. public boolean addItemProperty(Object id, Property property)
  651. throws UnsupportedOperationException {
  652. throw new UnsupportedOperationException("Filesystem container "
  653. + "does not support adding new properties");
  654. }
  655. /**
  656. * Filesystem container does not support removing properties.
  657. *
  658. * @see com.vaadin.data.Item#removeItemProperty(Object)
  659. */
  660. @Override
  661. public boolean removeItemProperty(Object id)
  662. throws UnsupportedOperationException {
  663. throw new UnsupportedOperationException(
  664. "Filesystem container does not support property removal");
  665. }
  666. }
  667. /**
  668. * Generic file extension filter for displaying only files having certain
  669. * extension.
  670. *
  671. * @author Vaadin Ltd.
  672. * @version
  673. * @VERSION@
  674. * @since 3.0
  675. */
  676. public class FileExtensionFilter implements FilenameFilter, Serializable {
  677. private final String filter;
  678. /**
  679. * Constructs a new FileExtensionFilter using given extension.
  680. *
  681. * @param fileExtension
  682. * the File extension without the separator (dot).
  683. */
  684. public FileExtensionFilter(String fileExtension) {
  685. filter = "." + fileExtension;
  686. }
  687. /**
  688. * Allows only files with the extension and directories.
  689. *
  690. * @see java.io.FilenameFilter#accept(File, String)
  691. */
  692. @Override
  693. public boolean accept(File dir, String name) {
  694. if (name.endsWith(filter)) {
  695. return true;
  696. }
  697. return new File(dir, name).isDirectory();
  698. }
  699. }
  700. /**
  701. * Returns the file filter used to limit the files in this container.
  702. *
  703. * @return Used filter instance or null if no filter is assigned.
  704. */
  705. public FilenameFilter getFilter() {
  706. return filter;
  707. }
  708. /**
  709. * Sets the file filter used to limit the files in this container.
  710. *
  711. * @param filter
  712. * The filter to set. <code>null</code> disables filtering.
  713. */
  714. public void setFilter(FilenameFilter filter) {
  715. this.filter = filter;
  716. }
  717. /**
  718. * Sets the file filter used to limit the files in this container.
  719. *
  720. * @param extension
  721. * the Filename extension (w/o separator) to limit the files in
  722. * container.
  723. */
  724. public void setFilter(String extension) {
  725. filter = new FileExtensionFilter(extension);
  726. }
  727. /**
  728. * Is this container recursive filesystem.
  729. *
  730. * @return <code>true</code> if container is recursive, <code>false</code>
  731. * otherwise.
  732. */
  733. public boolean isRecursive() {
  734. return recursive;
  735. }
  736. /**
  737. * Sets the container recursive property. Set this to false to limit the
  738. * files directly under the root file.
  739. * <p>
  740. * Note : This is meaningful only if the root really is a directory.
  741. * </p>
  742. *
  743. * @param recursive
  744. * the New value for recursive property.
  745. */
  746. public void setRecursive(boolean recursive) {
  747. this.recursive = recursive;
  748. }
  749. /*
  750. * (non-Javadoc)
  751. *
  752. * @see com.vaadin.data.Container#addContainerProperty(java.lang.Object,
  753. * java.lang.Class, java.lang.Object)
  754. */
  755. @Override
  756. public boolean addContainerProperty(Object propertyId, Class<?> type,
  757. Object defaultValue) throws UnsupportedOperationException {
  758. throw new UnsupportedOperationException(
  759. "File system container does not support this operation");
  760. }
  761. /*
  762. * (non-Javadoc)
  763. *
  764. * @see com.vaadin.data.Container#addItem()
  765. */
  766. @Override
  767. public Object addItem() throws UnsupportedOperationException {
  768. throw new UnsupportedOperationException(
  769. "File system container does not support this operation");
  770. }
  771. /*
  772. * (non-Javadoc)
  773. *
  774. * @see com.vaadin.data.Container#addItem(java.lang.Object)
  775. */
  776. @Override
  777. public Item addItem(Object itemId) throws UnsupportedOperationException {
  778. throw new UnsupportedOperationException(
  779. "File system container does not support this operation");
  780. }
  781. /*
  782. * (non-Javadoc)
  783. *
  784. * @see com.vaadin.data.Container#removeAllItems()
  785. */
  786. @Override
  787. public boolean removeAllItems() throws UnsupportedOperationException {
  788. throw new UnsupportedOperationException(
  789. "File system container does not support this operation");
  790. }
  791. /*
  792. * (non-Javadoc)
  793. *
  794. * @see com.vaadin.data.Container#removeItem(java.lang.Object)
  795. */
  796. @Override
  797. public boolean removeItem(Object itemId)
  798. throws UnsupportedOperationException {
  799. throw new UnsupportedOperationException(
  800. "File system container does not support this operation");
  801. }
  802. /*
  803. * (non-Javadoc)
  804. *
  805. * @see com.vaadin.data.Container#removeContainerProperty(java.lang.Object )
  806. */
  807. @Override
  808. public boolean removeContainerProperty(Object propertyId)
  809. throws UnsupportedOperationException {
  810. throw new UnsupportedOperationException(
  811. "File system container does not support this operation");
  812. }
  813. }