]> git.argeo.org Git - gpl/argeo-slc.git/blob - RefreshJcrResultTreeView.java
b7600b9e1770cab75f00c6a7803d6670b9b7aa86
[gpl/argeo-slc.git] / RefreshJcrResultTreeView.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.slc.client.ui.commands;
17
18 import java.util.Iterator;
19
20 import org.argeo.slc.client.ui.ClientUiPlugin;
21 import org.argeo.slc.client.ui.model.ResultParent;
22 import org.argeo.slc.client.ui.views.JcrResultTreeView;
23 import org.eclipse.core.commands.AbstractHandler;
24 import org.eclipse.core.commands.ExecutionEvent;
25 import org.eclipse.core.commands.ExecutionException;
26 import org.eclipse.jface.resource.ImageDescriptor;
27 import org.eclipse.jface.viewers.IStructuredSelection;
28 import org.eclipse.ui.handlers.HandlerUtil;
29
30 /**
31 * Force refresh the ResultTreeView. This command is only intended to be called
32 * by either the toolbar menu of the view or by the popup menu. Refresh due to
33 * data changes must be triggered by Observers
34 */
35 public class RefreshJcrResultTreeView extends AbstractHandler {
36 public final static String ID = ClientUiPlugin.ID
37 + ".refreshJcrResultTreeView";
38 public final static String PARAM_REFRESH_TYPE = ClientUiPlugin.ID
39 + ".param.refreshType";
40 public final static String PARAM_REFRESH_TYPE_FULL = "fullRefresh";
41 public final static ImageDescriptor DEFAULT_IMG_DESCRIPTOR = ClientUiPlugin
42 .getImageDescriptor("icons/refresh.png");
43 public final static String DEFAULT_LABEL = "Refresh selected";
44
45 public Object execute(final ExecutionEvent event) throws ExecutionException {
46 String refreshType = event.getParameter(PARAM_REFRESH_TYPE);
47 JcrResultTreeView view = (JcrResultTreeView) HandlerUtil
48 .getActiveWorkbenchWindow(event).getActivePage()
49 .getActivePart();
50
51 // force full refresh without preserving selection from the tool bar
52 if (PARAM_REFRESH_TYPE_FULL.equals(refreshType))
53 view.refresh(null);
54 else {
55 IStructuredSelection selection = (IStructuredSelection) HandlerUtil
56 .getActiveWorkbenchWindow(event).getActivePage()
57 .getSelection();
58 @SuppressWarnings("rawtypes")
59 Iterator it = selection.iterator();
60 while (it.hasNext()) {
61 Object obj = it.next();
62 if (obj instanceof ResultParent) {
63 view.refresh((ResultParent) obj);
64 }
65 }
66 }
67 return null;
68 }
69 }