tmf: Add Open Trace file, directory under Traces folder
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / commands / OpenFileHandler.java
1 /**********************************************************************
2 * Copyright (c) 2013 Ericsson
3 *
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 *
9 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 **********************************************************************/
12
13 package org.eclipse.linuxtools.internal.tmf.ui.commands;
14
15 import org.eclipse.core.commands.AbstractHandler;
16 import org.eclipse.core.commands.ExecutionEvent;
17 import org.eclipse.core.resources.IProject;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
20 import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
21 import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper;
22 import org.eclipse.swt.widgets.FileDialog;
23 import org.eclipse.swt.widgets.Shell;
24 import org.eclipse.ui.PlatformUI;
25 import org.eclipse.ui.handlers.HandlerUtil;
26
27 /**
28 * Open file handler, used to open files (not directories)
29 *
30 * @author Matthew Khouzam
31 */
32 public class OpenFileHandler extends AbstractHandler {
33
34 @Override
35 public Object execute(ExecutionEvent event) {
36 final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
37 FileDialog fd = new FileDialog(shell);
38 fd.setText(Messages.OpenFileHandler_SelectTraceFile);
39 String filePath = fd.open();
40 if (filePath == null) {
41 return null;
42 }
43
44 TmfOpenTraceHelper oth = new TmfOpenTraceHelper();
45 try {
46 IProject project = TmfHandlerUtil.getProjectFromSelection(HandlerUtil.getCurrentSelection(event));
47 String projectName = project != null ? project.getName() : TmfCommonConstants.DEFAULT_TRACE_PROJECT_NAME;
48 oth.openTraceFromPath(projectName, filePath, shell);
49 } catch (CoreException e) {
50 Activator.getDefault().logError(e.getMessage(), e);
51 }
52 return null;
53 }
54 }
This page took 0.043332 seconds and 5 git commands to generate.