View Javadoc
1   /**
2    * This file Copyright (c) 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.task.app.view;
35  
36  import info.magnolia.event.EventBus;
37  import info.magnolia.task.Task;
38  import info.magnolia.task.app.TasksSubApp;
39  import info.magnolia.task.event.TaskEvent;
40  import info.magnolia.task.event.TaskEventHandler;
41  import info.magnolia.ui.api.app.SubAppContext;
42  import info.magnolia.ui.api.event.AdmincentralEventBus;
43  import info.magnolia.ui.contentapp.browser.ContentViews;
44  import info.magnolia.ui.contentapp.browser.Workbench;
45  import info.magnolia.ui.ValueContext;
46  import info.magnolia.ui.contentapp.configuration.WorkbenchDefinition;
47  
48  import javax.inject.Inject;
49  import javax.inject.Named;
50  
51  /**
52   * Tasks workbench view.
53   */
54  public class TasksWorkbench extends Workbench<Task> {
55  
56      private final SubAppContext subAppContext;
57  
58      @Inject
59      public TasksWorkbench(TasksWorkbenchDefinition definition, WorkbenchContext workbenchContext,
60                            SubAppContext subAppContext, ValueContext<Task> valueContext,
61                            @Named(AdmincentralEventBus.NAME) EventBus eventBus) {
62          super(definition, workbenchContext);
63          this.subAppContext = subAppContext;
64  
65          eventBus.addHandler(TaskEvent.class, createTaskHandler());
66  
67          valueContext.observe(taskSelectedItems -> updateTitle());
68      }
69  
70      @Override
71      protected ContentViews<Task> getContentViews(WorkbenchDefinition<Task> definition) {
72          final TasksContentViewsDefinitionasksContentViewsDefinition">TasksContentViewsDefinition contentViewsDefinition = new TasksContentViewsDefinition(definition.getContentViews());
73          return create(contentViewsDefinition, definition.getExtensionViews());
74      }
75  
76      @Override
77      public void setTitle(String ignore) {
78          updateTitle();
79      }
80  
81      @Override
82      public void setTitle(String ignore, boolean isHtml) {
83          updateTitle();
84      }
85  
86      private TaskEventHandler createTaskHandler() {
87          return new TaskEventHandler() {
88              @Override
89              public void taskClaimed(TaskEvent taskEvent) {
90                  updateTitle();
91              }
92  
93              @Override
94              public void taskAdded(TaskEvent taskEvent) {
95                  updateTitle();
96  
97              }
98  
99              @Override
100             public void taskArchived(TaskEvent taskEvent) {
101                 updateTitle();
102 
103             }
104 
105             @Override
106             public void taskResolved(TaskEvent taskEvent) {
107                 updateTitle();
108 
109             }
110 
111             @Override
112             public void taskFailed(TaskEvent taskEvent) {
113                 updateTitle();
114 
115             }
116 
117             @Override
118             public void taskRemoved(TaskEvent taskEvent) {
119                 updateTitle();
120 
121             }
122 
123             @Override
124             public void taskScheduled(TaskEvent taskEvent) {
125                 updateTitle();
126 
127             }
128         };
129     }
130 
131     private void updateTitle() {
132         if (subAppContext.getSubApp() instanceof TasksSubApp) {
133             TasksSubApp./../info/magnolia/task/app/TasksSubApp.html#TasksSubApp">TasksSubApp tasksSubApp = (TasksSubApp) subAppContext.getSubApp();
134             String title = tasksSubApp.getTitle();
135             boolean isHtml = subAppContext.getAppContext().getAppDescriptor().isHtmlCaption();
136             super.setTitle(title, isHtml);
137         }
138 
139         subAppContext.getAppContext().getSubAppContexts().forEach(context ->
140                 context.getAppContext().getView().updateCaption(context.getInstanceId(), context.getSubApp().getCaption())
141         );
142     }
143 }