]> git.argeo.org Git - gpl/argeo-slc.git/blob - RefreshJcrResultTreeView.java
ecc81242a8866370da1d2b999d7823f4fecdbb04
[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 /*
19 * Copyright (C) 2007-2012 Mathieu Baudier
20 *
21 * Licensed under the Apache License, Version 2.0 (the "License");
22 * you may not use this file except in compliance with the License.
23 * You may obtain a copy of the License at
24 *
25 * http://www.apache.org/licenses/LICENSE-2.0
26 *
27 * Unless required by applicable law or agreed to in writing, software
28 * distributed under the License is distributed on an "AS IS" BASIS,
29 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 * See the License for the specific language governing permissions and
31 * limitations under the License.
32 */
33
34 import java.util.Iterator;
35
36 import org.argeo.slc.client.ui.ClientUiPlugin;
37 import org.argeo.slc.client.ui.model.ResultParent;
38 import org.argeo.slc.client.ui.views.JcrResultTreeView;
39 import org.eclipse.core.commands.AbstractHandler;
40 import org.eclipse.core.commands.ExecutionEvent;
41 import org.eclipse.core.commands.ExecutionException;
42 import org.eclipse.jface.resource.ImageDescriptor;
43 import org.eclipse.jface.viewers.IStructuredSelection;
44 import org.eclipse.ui.handlers.HandlerUtil;
45
46 /**
47 * Force refresh the ResultTreeView. This command is only intended to be called
48 * by either the toolbar menu of the view or by the popup menu. Refresh due to
49 * data changes must be triggered by Observers
50 */
51 public class RefreshJcrResultTreeView extends AbstractHandler {
52 public final static String ID = ClientUiPlugin.ID
53 + ".refreshJcrResultTreeView";
54 public final static String PARAM_REFRESH_TYPE = ClientUiPlugin.ID
55 + ".param.refreshType";
56 public final static String PARAM_REFRESH_TYPE_FULL = "fullRefresh";
57 public final static ImageDescriptor DEFAULT_IMG_DESCRIPTOR = ClientUiPlugin
58 .getImageDescriptor("icons/refresh.png");
59 public final static String DEFAULT_LABEL = "Refresh selected";
60
61 public Object execute(final ExecutionEvent event) throws ExecutionException {
62 String refreshType = event.getParameter(PARAM_REFRESH_TYPE);
63 JcrResultTreeView view = (JcrResultTreeView) HandlerUtil
64 .getActiveWorkbenchWindow(event).getActivePage()
65 .getActivePart();
66
67 // force full refresh without preserving selection from the tool bar
68 if (PARAM_REFRESH_TYPE_FULL.equals(refreshType))
69 view.refresh(null);
70 else {
71 IStructuredSelection selection = (IStructuredSelection) HandlerUtil
72 .getActiveWorkbenchWindow(event).getActivePage()
73 .getSelection();
74 @SuppressWarnings("rawtypes")
75 Iterator it = selection.iterator();
76 while (it.hasNext()) {
77 Object obj = it.next();
78 if (obj instanceof ResultParent) {
79 view.refresh((ResultParent) obj);
80 }
81 }
82 }
83 return null;
84 }
85 }