1 /*******************************************************************************
2 * Copyright (c) 2015, 2016 EfficiOS Inc., Philippe Proulx
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
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.ui
.handler
;
12 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
14 import java
.io
.IOException
;
15 import java
.nio
.file
.Path
;
17 import org
.eclipse
.core
.commands
.AbstractHandler
;
18 import org
.eclipse
.core
.commands
.ExecutionEvent
;
19 import org
.eclipse
.core
.commands
.ExecutionException
;
20 import org
.eclipse
.jdt
.annotation
.Nullable
;
21 import org
.eclipse
.jface
.dialogs
.IInputValidator
;
22 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
23 import org
.eclipse
.jface
.window
.Window
;
24 import org
.eclipse
.swt
.widgets
.Display
;
25 import org
.eclipse
.swt
.widgets
.Shell
;
26 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.LamiConfigUtils
;
27 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.module
.LamiAnalysis
;
28 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.module
.LamiAnalysisFactoryException
;
29 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.module
.LamiAnalysisFactoryFromConfigFile
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.ondemand
.OnDemandAnalysisManager
;
31 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.handlers
.HandlerUtils
;
32 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfOnDemandAnalysesElement
;
33 import org
.eclipse
.ui
.PlatformUI
;
36 * The command handler for the "Add External Analysis" menu option.
38 * @author Philippe Proulx
40 public class AddAnalysisHandler
extends AbstractHandler
{
42 private static void showErrorBox(@Nullable Shell shell
, Throwable e
) {
43 Display
.getDefault().asyncExec(() -> {
44 MessageDialog
.openError(shell
,
45 Messages
.AddAnalysisDialog_ErrorBoxTitle
,
46 Messages
.AddAnalysisDialog_ErrorBoxMessage
+ ":\n" + e
.toString()); //$NON-NLS-1$
51 public @Nullable Object
execute(@Nullable ExecutionEvent event
) throws ExecutionException
{
52 final Shell shell
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell();
53 final AddAnalysisDialog dialog
= new AddAnalysisDialog(shell
, Messages
.AddAnalysisDialog_Title
,
54 NAME_INPUT_VALIDATOR
, COMMAND_INPUT_VALIDATOR
);
56 if (dialog
.open() != Window
.OK
) {
57 // User clicked Cancel, cancel the add operation
64 configFilePath
= LamiConfigUtils
.createConfigFile(checkNotNull(dialog
.getName().trim()),
65 checkNotNull(dialog
.getCommand().trim()));
66 } catch (IOException e
) {
67 showErrorBox(shell
, e
);
72 final LamiAnalysis analysis
= LamiAnalysisFactoryFromConfigFile
.buildFromConfigFile(configFilePath
, true, trace
-> true);
73 OnDemandAnalysisManager
.getInstance().registerAnalysis(analysis
);
74 } catch (LamiAnalysisFactoryException e
) {
75 showErrorBox(shell
, e
);
79 final Object elem
= HandlerUtils
.getSelectedModelElement();
81 if (elem
!= null && elem
instanceof TmfOnDemandAnalysesElement
) {
82 final TmfOnDemandAnalysesElement analysesElem
= (TmfOnDemandAnalysesElement
) elem
;
83 analysesElem
.refresh();
89 private static final IInputValidator NAME_INPUT_VALIDATOR
= text
-> {
90 if (text
.trim().isEmpty()) {
91 return Messages
.AddAnalysisDialog_NameEmptyErrorMessage
;
97 private static final IInputValidator COMMAND_INPUT_VALIDATOR
= text
-> {
98 if (text
.trim().isEmpty()) {
99 return Messages
.AddAnalysisDialog_CommandEmptyErrorMessage
;