]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.e4/src/org/argeo/cms/e4/jcr/handlers/Refresh.java
Implement log out
[lgpl/argeo-commons.git] / org.argeo.cms.e4 / src / org / argeo / cms / e4 / jcr / handlers / Refresh.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.cms.e4.jcr.handlers;
17
18 import java.util.List;
19
20 import javax.inject.Named;
21
22 import org.argeo.cms.e4.jcr.JcrBrowserView;
23 import org.argeo.cms.ui.jcr.JcrBrowserUtils;
24 import org.argeo.eclipse.ui.TreeParent;
25 import org.eclipse.e4.core.di.annotations.Execute;
26 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
27 import org.eclipse.e4.ui.services.IServiceConstants;
28 import org.eclipse.e4.ui.workbench.modeling.EPartService;
29 import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
30
31 /**
32 * Force the selected objects of the active view to be refreshed doing the
33 * following:
34 * <ol>
35 * <li>The model objects are recomputed</li>
36 * <li>the view is refreshed</li>
37 * </ol>
38 */
39 public class Refresh {
40
41 @Execute
42 public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, EPartService partService,
43 ESelectionService selectionService) {
44
45 JcrBrowserView view = (JcrBrowserView) part.getObject();
46 List<?> selection = (List<?>) selectionService.getSelection();
47
48 if (selection != null && !selection.isEmpty()) {
49 for (Object obj : selection)
50 if (obj instanceof TreeParent) {
51 TreeParent tp = (TreeParent) obj;
52 JcrBrowserUtils.forceRefreshIfNeeded(tp);
53 view.refresh(obj);
54 }
55 } else if (view instanceof JcrBrowserView)
56 view.refresh(null); // force full refresh
57 }
58 }