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.tasks;
20  
21  import org.apache.syncope.client.console.commons.DirectoryDataProvider;
22  import org.apache.syncope.client.console.commons.TaskDataProvider;
23  import org.apache.syncope.client.console.panels.AjaxDataTablePanel;
24  import org.apache.syncope.client.console.panels.DirectoryPanel;
25  import org.apache.syncope.client.console.panels.MultilevelPanel;
26  import org.apache.syncope.client.console.rest.TaskRestClient;
27  import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
28  import org.apache.syncope.client.ui.commons.panels.ModalPanel;
29  import org.apache.syncope.common.lib.to.TaskTO;
30  import org.apache.syncope.common.lib.types.TaskType;
31  import org.apache.wicket.PageReference;
32  import org.apache.wicket.ajax.AjaxRequestTarget;
33  import org.apache.wicket.event.IEvent;
34  import org.apache.wicket.model.CompoundPropertyModel;
35  import org.apache.wicket.model.IModel;
36  
37  /**
38   * Tasks {@link DirectoryPanel}.
39   *
40   * @param <T> task type.
41   */
42  public abstract class TaskDirectoryPanel<T extends TaskTO>
43          extends DirectoryPanel<T, T, TaskDataProvider<T>, TaskRestClient> implements ModalPanel {
44  
45      private static final long serialVersionUID = 4984337552918213290L;
46  
47      protected final BaseModal<?> baseModal;
48  
49      protected final MultilevelPanel multiLevelPanelRef;
50  
51      protected TaskDirectoryPanel(
52              final TaskRestClient restClient,
53              final BaseModal<?> baseModal,
54              final MultilevelPanel multiLevelPanelRef,
55              final PageReference pageRef,
56              final boolean wizardInModal) {
57  
58          this(MultilevelPanel.FIRST_LEVEL_ID, restClient, baseModal, multiLevelPanelRef, pageRef, wizardInModal);
59      }
60  
61      protected TaskDirectoryPanel(final String id, final TaskRestClient restClient, final PageReference pageRef) {
62          this(id, restClient, null, null, pageRef, false);
63      }
64  
65      protected TaskDirectoryPanel(
66              final String id,
67              final TaskRestClient restClient,
68              final BaseModal<?> baseModal,
69              final MultilevelPanel multiLevelPanelRef,
70              final PageReference pageRef,
71              final boolean wizardInModal) {
72  
73          super(id, restClient, pageRef, wizardInModal);
74          this.baseModal = baseModal;
75          this.multiLevelPanelRef = multiLevelPanelRef;
76          setShowResultPanel(false);
77      }
78  
79      @Override
80      protected void resultTableCustomChanges(final AjaxDataTablePanel.Builder<T, String> resultTableBuilder) {
81          resultTableBuilder.setMultiLevelPanel(multiLevelPanelRef);
82      }
83  
84      protected abstract void viewTaskExecs(T taskTO, AjaxRequestTarget target);
85  
86      protected abstract class TasksProvider<T extends TaskTO> extends DirectoryDataProvider<T> {
87  
88          private static final long serialVersionUID = -20112718133295756L;
89  
90          private final TaskType type;
91  
92          public TasksProvider(final int paginatorRows, final TaskType type) {
93              super(paginatorRows);
94              this.type = type;
95          }
96  
97          @Override
98          public long size() {
99              return restClient.count(type);
100         }
101 
102         @Override
103         public IModel<T> model(final T object) {
104             return new CompoundPropertyModel<>(object);
105         }
106     }
107 
108     @Override
109     public void onEvent(final IEvent<?> event) {
110         super.onEvent(event);
111         if (event.getPayload() instanceof ExitEvent) {
112             AjaxRequestTarget target = ExitEvent.class.cast(event.getPayload()).getTarget();
113             baseModal.show(false);
114             baseModal.close(target);
115         }
116     }
117 }