]> git.argeo.org Git - lgpl/argeo-commons.git/blob - server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/Refresh.java
+ register a default command in both RAP and RCP security base apps to provide generi...
[lgpl/argeo-commons.git] / server / plugins / org.argeo.jcr.ui.explorer / src / main / java / org / argeo / jcr / ui / explorer / commands / 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.jcr.ui.explorer.commands;
17
18 import java.util.Iterator;
19
20 import org.argeo.eclipse.ui.TreeParent;
21 import org.argeo.eclipse.ui.jcr.views.AbstractJcrBrowser;
22 import org.argeo.jcr.ui.explorer.JcrExplorerPlugin;
23 import org.argeo.jcr.ui.explorer.utils.JcrUiUtils;
24 import org.argeo.jcr.ui.explorer.views.GenericJcrBrowser;
25 import org.eclipse.core.commands.AbstractHandler;
26 import org.eclipse.core.commands.ExecutionEvent;
27 import org.eclipse.core.commands.ExecutionException;
28 import org.eclipse.jface.viewers.ISelection;
29 import org.eclipse.jface.viewers.IStructuredSelection;
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 extends AbstractHandler {
40
41 public final static String ID = JcrExplorerPlugin.ID + ".refresh";
42
43 public Object execute(ExecutionEvent event) throws ExecutionException {
44
45 AbstractJcrBrowser view = (AbstractJcrBrowser) JcrExplorerPlugin
46 .getDefault().getWorkbench().getActiveWorkbenchWindow()
47 .getActivePage().getActivePart();//
48
49 ISelection selection = JcrExplorerPlugin.getDefault().getWorkbench()
50 .getActiveWorkbenchWindow().getActivePage().getSelection();
51
52 if (selection != null && selection instanceof IStructuredSelection
53 && !selection.isEmpty()) {
54 Iterator<?> it = ((IStructuredSelection) selection).iterator();
55 while (it.hasNext()) {
56 Object obj = it.next();
57 if (obj instanceof TreeParent) {
58 TreeParent tp = (TreeParent) obj;
59 JcrUiUtils.forceRefreshIfNeeded(tp);
60 view.refresh(obj);
61 }
62 }
63 } else if (view instanceof GenericJcrBrowser)
64 ((GenericJcrBrowser) view).refresh(null); // force full refresh
65
66 return null;
67 }
68 }