View Javadoc
1   /**
2    * This file Copyright (c) 2012-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.splitfeed;
35  
36  import java.util.Iterator;
37  
38  import com.vaadin.ui.Component;
39  import com.vaadin.ui.CssLayout;
40  import com.vaadin.ui.HorizontalSplitPanel;
41  import com.vaadin.ui.NativeButton;
42  import com.vaadin.v7.ui.Label;
43  import com.vaadin.v7.ui.themes.BaseTheme;
44  
45  /**
46   * Split panel that displays two column feed.
47   */
48  public class SplitFeed extends HorizontalSplitPanel {
49  
50      private final FeedSection leftContainer = new FeedSection();
51  
52      private final FeedSection rightContainer = new FeedSection();
53  
54      public SplitFeed() {
55          super();
56          addStyleName("v-split-feed");
57          setSizeFull();
58          setSplitPosition(50);
59          setLocked(true);
60          construct();
61      }
62  
63      private void construct() {
64          leftContainer.setSizeFull();
65          rightContainer.setSizeFull();
66          // leftContainer.setMargin(true);
67          // rightContainer.setMargin(true);
68          setFirstComponent(leftContainer);
69          setSecondComponent(rightContainer);
70      }
71  
72      public FeedSection getLeftContainer() {
73          return leftContainer;
74      }
75  
76      public FeedSection getRightContainer() {
77          return rightContainer;
78      }
79  
80      /**
81       * Title for the feed section.
82       */
83      public static class FeedTitle extends Label {
84  
85          public FeedTitle(final String caption) {
86              super();
87              addStyleName("v-feed-title");
88              setContentMode(Label.CONTENT_XHTML);
89              setValue(caption);
90          }
91      }
92  
93      /**
94       * Feed section (column).
95       */
96      public static class FeedSection extends CssLayout {
97  
98          private final NativeButton link = new NativeButton();
99  
100         public FeedSection() {
101             super();
102             setSizeFull();
103             addStyleName("v-feed-section");
104             link.setStyleName(BaseTheme.BUTTON_LINK);
105             link.addStyleName("icon-rssfeed");
106         }
107 
108         public void setTitleLinkEnabled(boolean enabled) {
109             if (!enabled) {
110                 removeComponent(link);
111             } else {
112                 addComponent(link);
113             }
114         }
115 
116         @Override
117         public void addComponent(Component component) {
118             if (component instanceof FeedTitle) {
119                 final Iterator<Component> it = getComponentIterator();
120                 while (it.hasNext()) {
121                     final Component c = it.next();
122                     if (c instanceof FeedTitle) {
123                         removeComponent(c);
124                         break;
125                     }
126                 }
127             }
128             super.addComponent(component);
129         }
130 
131         public void setTitle(final String caption) {
132             addComponentAsFirst(new FeedTitle(caption));
133         }
134     }
135 }