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 26KB

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