View Javadoc
1   /**
2    * This file Copyright (c) 2013-2018 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.ui.vaadin.integration.contentconnector;
35  
36  import com.vaadin.v7.data.Item;
37  
38  /**
39   * Simple stateless component used to bridge arbitrary object by their identifier to a Vaadin {@link Item}
40   * and vice-versa.
41   */
42  public interface ContentConnector {
43  
44      /**
45       * Convert an item id (arbitrary object) to its string representation which can be
46       * appended to a URL fragment and later be used to fetch the item id back.
47       * @see ContentConnector#getItemIdByUrlFragment(java.lang.String).
48       *
49       * @param itemId id of an item to be converted to a string representation.
50       * @return string representation of an item id.
51       */
52      String getItemUrlFragment(Object itemId);
53  
54      /**
55       * Fetch item id from its string representation. Used primarily for restoring selection in views
56       * from URL fragments.
57       *
58       * @param urlFragment URL fragment that points to an item.
59       * @return item id that corresponds to the URL fragment.
60       */
61      Object getItemIdByUrlFragment(String urlFragment);
62  
63      /**
64       * Get the default item id which for instance could be used as a view selection if
65       * no actual item is selected. Most common example of such an item is a root node of
66       * the tree hierarchy.
67       *
68       * @return default item id.
69       */
70      Object getDefaultItemId();
71  
72      /**
73       * Fetch Vaadin {@link Item} by its id. Such item is not bound to any container and
74       * can eventually be used in actions for editing.
75       *
76       * @param itemId item id.
77       * @return Vaadin {@link Item} that corresponds to the id.
78       */
79      Item getItem(Object itemId);
80  
81      /**
82       * Get item id.
83       * @param item Item id of which is to be returned.
84       * @return id of an item.
85       */
86      Object getItemId(Item item);
87  
88      /**
89       * Check whether current {@link ContentConnector} is capable of fetching a Vaadin {@link Item}
90       * with a specific id.
91       *
92       * @param itemId id of a Vaadin {@link Item} to look up.
93       * @return true if such a Vaadin {@link Item} exists, false - otherwise.
94       */
95      boolean canHandleItem(Object itemId);
96  }