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
.tmf
.ui
.project
.model
.TmfExperimentElement
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentFolder
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfProjectModelElement
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceFolder
;
27 import org
.eclipse
.ui
.IWorkbenchPage
;
28 import org
.eclipse
.ui
.handlers
.IHandlerService
;
30 public class RefreshAction
extends Action
{
32 private static final String REFRESH_TRACE_FOLDER_COMMAND_ID
= "org.eclipse.linuxtools.tmf.ui.command.project.trace.refresh"; //$NON-NLS-1$
33 private static final String REFRESH_EXPERIMENT_FOLDER_COMMAND_ID
= "org.eclipse.linuxtools.tmf.ui.command.project.experiment_folder.refresh"; //$NON-NLS-1$
34 private static final String REFRESH_EXPERIMENT_COMMAND_ID
= "org.eclipse.linuxtools.tmf.ui.command.project.experiment.refresh"; //$NON-NLS-1$
36 private IWorkbenchPage page
;
37 private ISelectionProvider selectionProvider
;
38 private TmfProjectModelElement element
;
42 * @param page the workbench page
43 * @param selectionProvider the selection provider
45 public RefreshAction(IWorkbenchPage page
, ISelectionProvider selectionProvider
) {
47 this.selectionProvider
= selectionProvider
;
52 * @see org.eclipse.jface.action.Action#isEnabled()
55 public boolean isEnabled() {
56 ISelection selection
= selectionProvider
.getSelection();
57 if (!selection
.isEmpty()) {
58 IStructuredSelection sSelection
= (IStructuredSelection
) selection
;
59 if (sSelection
.size() == 1) {
60 if (sSelection
.getFirstElement() instanceof TmfTraceFolder
||
61 sSelection
.getFirstElement() instanceof TmfExperimentFolder
||
62 sSelection
.getFirstElement() instanceof TmfExperimentElement
) {
63 element
= (TmfProjectModelElement
) sSelection
.getFirstElement();
73 * @see org.eclipse.jface.action.Action#run()
78 IHandlerService handlerService
= (IHandlerService
) page
.getActivePart().getSite().getService(IHandlerService
.class);
79 if (element
instanceof TmfTraceFolder
) {
80 handlerService
.executeCommand(REFRESH_TRACE_FOLDER_COMMAND_ID
, null);
81 } else if (element
instanceof TmfExperimentFolder
) {
82 handlerService
.executeCommand(REFRESH_EXPERIMENT_FOLDER_COMMAND_ID
, null);
83 } else if (element
instanceof TmfExperimentElement
) {
84 handlerService
.executeCommand(REFRESH_EXPERIMENT_COMMAND_ID
, null);
86 } catch (ExecutionException e
) {
88 } catch (NotDefinedException e
) {
90 } catch (NotEnabledException e
) {
92 } catch (NotHandledException e
) {