View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.client.ui.commons.ajax.markup.html;
20  
21  import java.util.Collection;
22  import java.util.Optional;
23  import org.apache.commons.lang3.StringUtils;
24  import org.apache.wicket.markup.ComponentTag;
25  import org.apache.wicket.markup.html.basic.Label;
26  import org.springframework.util.CollectionUtils;
27  
28  public class LabelInfo extends Label {
29  
30      private static final long serialVersionUID = 4755868673082976208L;
31  
32      private final String title;
33  
34      public LabelInfo(final String id, final String title) {
35          super(id, StringUtils.EMPTY);
36          this.title = Optional.ofNullable(title).map(s -> StringUtils.abbreviate(s, 30)).orElse(StringUtils.EMPTY);
37      }
38  
39      public LabelInfo(final String id, final Collection<String> title) {
40          super(id, StringUtils.EMPTY);
41          if (CollectionUtils.isEmpty(title)) {
42              this.title = StringUtils.EMPTY;
43          } else {
44              StringBuilder titleBuilder = new StringBuilder();
45              for (String el : title) {
46                  if (titleBuilder.length() > 0) {
47                      titleBuilder.append("; ");
48                  }
49                  if (StringUtils.isNoneEmpty(el)) {
50                      titleBuilder.append(el);
51                  }
52              }
53              this.title = StringUtils.abbreviate(titleBuilder.toString(), 50);
54          }
55      }
56  
57      @Override
58      protected void onComponentTag(final ComponentTag tag) {
59          tag.put("class", "fa  fa-info-circle");
60          tag.put("style", "color:red");
61          tag.put("title", title);
62      }
63  }