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.console.panels;
20  
21  import de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.Iterator;
25  import java.util.List;
26  import org.apache.syncope.client.console.commons.DirectoryDataProvider;
27  import org.apache.syncope.client.console.commons.SortableDataProviderComparator;
28  import org.apache.syncope.client.console.panels.AttrListDirectoryPanel.AttrListProvider;
29  import org.apache.syncope.client.console.rest.BaseRestClient;
30  import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
31  import org.apache.syncope.common.lib.Attr;
32  import org.apache.wicket.AttributeModifier;
33  import org.apache.wicket.PageReference;
34  import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
35  import org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder;
36  import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
37  import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
38  import org.apache.wicket.markup.html.basic.Label;
39  import org.apache.wicket.markup.repeater.Item;
40  import org.apache.wicket.model.CompoundPropertyModel;
41  import org.apache.wicket.model.IModel;
42  import org.apache.wicket.model.ResourceModel;
43  
44  public abstract class AttrListDirectoryPanel
45          extends DirectoryPanel<Attr, Attr, AttrListProvider, BaseRestClient> {
46  
47      private static final long serialVersionUID = -9098924321080135095L;
48  
49      protected AttrListDirectoryPanel(
50              final String id,
51              final BaseRestClient restClient,
52              final PageReference pageRef,
53              final boolean wizardInModal) {
54  
55          super(id, restClient, pageRef, wizardInModal);
56  
57          itemKeyFieldName = "schema";
58          disableCheckBoxes();
59  
60          modal.size(Modal.Size.Default);
61      }
62  
63      @Override
64      protected Collection<ActionLink.ActionType> getBatches() {
65          return List.of();
66      }
67  
68      @Override
69      protected List<IColumn<Attr, String>> getColumns() {
70          final List<IColumn<Attr, String>> columns = new ArrayList<>();
71          columns.add(new PropertyColumn<>(new ResourceModel("schema"), "schema"));
72          columns.add(new PropertyColumn<>(new ResourceModel("values"), "values") {
73  
74              private static final long serialVersionUID = -1822504503325964706L;
75  
76              @Override
77              public void populateItem(
78                      final Item<ICellPopulator<Attr>> item,
79                      final String componentId,
80                      final IModel<Attr> rowModel) {
81  
82                  if (rowModel.getObject().getValues().toString().length() > 96) {
83                      item.add(new Label(componentId, getString("tooLong")).
84                              add(new AttributeModifier("style", "font-style:italic")));
85                  } else {
86                      super.populateItem(item, componentId, rowModel);
87                  }
88              }
89          });
90          return columns;
91      }
92  
93      protected abstract static class AttrListProvider extends DirectoryDataProvider<Attr> {
94  
95          private static final long serialVersionUID = -185944053385660794L;
96  
97          private final SortableDataProviderComparator<Attr> comparator;
98  
99          protected AttrListProvider(final int paginatorRows) {
100             super(paginatorRows);
101             setSort("schema", SortOrder.ASCENDING);
102             comparator = new SortableDataProviderComparator<>(this);
103         }
104 
105         protected abstract List<Attr> list();
106 
107         @Override
108         public Iterator<Attr> iterator(final long first, final long count) {
109             List<Attr> result = list();
110             result.sort(comparator);
111             return result.subList((int) first, (int) first + (int) count).iterator();
112         }
113 
114         @Override
115         public long size() {
116             return list().size();
117         }
118 
119         @Override
120         public IModel<Attr> model(final Attr object) {
121             return new CompoundPropertyModel<>(object);
122         }
123     }
124 }