1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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
;
56 public boolean isEnabled() {
57 ISelection selection
= selectionProvider
.getSelection();
58 if (!selection
.isEmpty()) {
59 IStructuredSelection sSelection
= (IStructuredSelection
) selection
;
60 if (sSelection
.size() == 1) {
61 if (sSelection
.getFirstElement() instanceof TmfTraceFolder
||
62 sSelection
.getFirstElement() instanceof TmfExperimentFolder
||
63 sSelection
.getFirstElement() instanceof TmfExperimentElement
) {
64 element
= (TmfProjectModelElement
) sSelection
.getFirstElement();
75 IHandlerService handlerService
= (IHandlerService
) page
.getActivePart().getSite().getService(IHandlerService
.class);
76 if (element
instanceof TmfTraceFolder
|| element
instanceof TmfExperimentFolder
|| element
instanceof TmfExperimentElement
) {
77 handlerService
.executeCommand(REFRESH_COMMAND_ID
, null);
79 } catch (ExecutionException e
) {
80 Activator
.getDefault().logError("Error refreshing resource " + element
.getName(), e
); //$NON-NLS-1$
81 } catch (NotDefinedException e
) {
82 Activator
.getDefault().logError("Error refreshing resource " + element
.getName(), e
); //$NON-NLS-1$
83 } catch (NotEnabledException e
) {
84 Activator
.getDefault().logError("Error refreshing resource " + element
.getName(), e
); //$NON-NLS-1$
85 } catch (NotHandledException e
) {
86 Activator
.getDefault().logError("Error refreshing resource " + element
.getName(), e
); //$NON-NLS-1$