]> git.argeo.org Git - gpl/argeo-slc.git/blob - commands/Refresh.java
Prepare next development cycle
[gpl/argeo-slc.git] / commands / Refresh.java
1 package org.argeo.cms.ui.workbench.internal.jcr.commands;
2
3 import java.util.Iterator;
4
5 import org.argeo.cms.ui.jcr.JcrBrowserUtils;
6 import org.argeo.cms.ui.workbench.WorkbenchUiPlugin;
7 import org.argeo.cms.ui.workbench.jcr.JcrBrowserView;
8 import org.argeo.eclipse.ui.TreeParent;
9 import org.eclipse.core.commands.AbstractHandler;
10 import org.eclipse.core.commands.ExecutionEvent;
11 import org.eclipse.core.commands.ExecutionException;
12 import org.eclipse.jface.viewers.ISelection;
13 import org.eclipse.jface.viewers.IStructuredSelection;
14
15 /**
16 * Force the selected objects of the active view to be refreshed doing the
17 * following:
18 * <ol>
19 * <li>The model objects are recomputed</li>
20 * <li>the view is refreshed</li>
21 * </ol>
22 */
23 public class Refresh extends AbstractHandler {
24
25 public final static String ID = WorkbenchUiPlugin.PLUGIN_ID + ".refresh";
26
27 public Object execute(ExecutionEvent event) throws ExecutionException {
28
29 JcrBrowserView view = (JcrBrowserView) WorkbenchUiPlugin.getDefault()
30 .getWorkbench().getActiveWorkbenchWindow().getActivePage()
31 .getActivePart();//
32
33 ISelection selection = WorkbenchUiPlugin.getDefault().getWorkbench()
34 .getActiveWorkbenchWindow().getActivePage().getSelection();
35
36 if (selection != null && selection instanceof IStructuredSelection
37 && !selection.isEmpty()) {
38 Iterator<?> it = ((IStructuredSelection) selection).iterator();
39 while (it.hasNext()) {
40 Object obj = it.next();
41 if (obj instanceof TreeParent) {
42 TreeParent tp = (TreeParent) obj;
43 JcrBrowserUtils.forceRefreshIfNeeded(tp);
44 view.refresh(obj);
45 }
46 }
47 } else if (view instanceof JcrBrowserView)
48 ((JcrBrowserView) view).refresh(null); // force full refresh
49
50 return null;
51 }
52 }