]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/RefreshJcrResultTreeView.java
Make execution editor more robust
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / commands / RefreshJcrResultTreeView.java
1 package org.argeo.slc.client.ui.commands;
2
3 /*
4 * Copyright (C) 2007-2012 Mathieu Baudier
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 import java.util.Iterator;
20
21 import org.argeo.slc.client.ui.ClientUiPlugin;
22 import org.argeo.slc.client.ui.model.ResultParent;
23 import org.argeo.slc.client.ui.views.JcrResultTreeView;
24 import org.eclipse.core.commands.AbstractHandler;
25 import org.eclipse.core.commands.ExecutionEvent;
26 import org.eclipse.core.commands.ExecutionException;
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
42 public Object execute(final ExecutionEvent event) throws ExecutionException {
43 String refreshType = event.getParameter(PARAM_REFRESH_TYPE);
44 JcrResultTreeView view = (JcrResultTreeView) HandlerUtil
45 .getActiveWorkbenchWindow(event).getActivePage()
46 .getActivePart();
47
48 // force full refresh without preserving selection from the tool bar
49 if (PARAM_REFRESH_TYPE_FULL.equals(refreshType))
50 view.refresh(null);
51 else {
52 IStructuredSelection selection = (IStructuredSelection) HandlerUtil
53 .getActiveWorkbenchWindow(event).getActivePage()
54 .getSelection();
55 @SuppressWarnings("rawtypes")
56 Iterator it = selection.iterator();
57 while (it.hasNext()) {
58 Object obj = it.next();
59 if (obj instanceof ResultParent) {
60 view.refresh((ResultParent) obj);
61 }
62 }
63 }
64 return null;
65 }
66 }