1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.handlers
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.commands
.NotEnabledException
;
17 import org
.eclipse
.core
.commands
.NotHandledException
;
18 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
19 import org
.eclipse
.jface
.action
.Action
;
20 import org
.eclipse
.jface
.viewers
.ISelection
;
21 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
22 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
23 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentElement
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentFolder
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfProjectModelElement
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceFolder
;
28 import org
.eclipse
.ui
.IWorkbenchPage
;
29 import org
.eclipse
.ui
.handlers
.IHandlerService
;
32 * <b><u>RefreshAction</u></b>
34 * Implement me. Please.
37 public class RefreshAction
extends Action
{
39 private static final String REFRESH_COMMAND_ID
= "org.eclipse.ui.file.refresh"; //$NON-NLS-1$
41 private IWorkbenchPage page
;
42 private ISelectionProvider selectionProvider
;
43 private TmfProjectModelElement element
;
47 * @param page the workbench page
48 * @param selectionProvider the selection provider
50 public RefreshAction(IWorkbenchPage page
, ISelectionProvider selectionProvider
) {
52 this.selectionProvider
= selectionProvider
;
57 * @see org.eclipse.jface.action.Action#isEnabled()
60 public boolean isEnabled() {
61 ISelection selection
= selectionProvider
.getSelection();
62 if (!selection
.isEmpty()) {
63 IStructuredSelection sSelection
= (IStructuredSelection
) selection
;
64 if (sSelection
.size() == 1) {
65 if (sSelection
.getFirstElement() instanceof TmfTraceFolder
||
66 sSelection
.getFirstElement() instanceof TmfExperimentFolder
||
67 sSelection
.getFirstElement() instanceof TmfExperimentElement
) {
68 element
= (TmfProjectModelElement
) sSelection
.getFirstElement();
78 * @see org.eclipse.jface.action.Action#run()
83 IHandlerService handlerService
= (IHandlerService
) page
.getActivePart().getSite().getService(IHandlerService
.class);
84 if (element
instanceof TmfTraceFolder
|| element
instanceof TmfExperimentFolder
|| element
instanceof TmfExperimentElement
) {
85 handlerService
.executeCommand(REFRESH_COMMAND_ID
, null);
87 } catch (ExecutionException e
) {
88 Activator
.getDefault().logError("Error refreshing resource " + element
.getName(), e
); //$NON-NLS-1$
89 } catch (NotDefinedException e
) {
90 Activator
.getDefault().logError("Error refreshing resource " + element
.getName(), e
); //$NON-NLS-1$
91 } catch (NotEnabledException e
) {
92 Activator
.getDefault().logError("Error refreshing resource " + element
.getName(), e
); //$NON-NLS-1$
93 } catch (NotHandledException e
) {
94 Activator
.getDefault().logError("Error refreshing resource " + element
.getName(), e
); //$NON-NLS-1$