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

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