tmf: Update drag and drop to support trace folders
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / commands / OpenFileHandler.java
CommitLineData
76fccfb0
MK
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
c0c7c656 13package org.eclipse.linuxtools.internal.tmf.ui.commands;
76fccfb0
MK
14
15import org.eclipse.core.commands.AbstractHandler;
16import org.eclipse.core.commands.ExecutionEvent;
c0c7c656 17import org.eclipse.core.resources.IProject;
76fccfb0 18import org.eclipse.core.runtime.CoreException;
34c8c664 19import org.eclipse.core.runtime.NullProgressMonitor;
c0c7c656 20import org.eclipse.linuxtools.internal.tmf.ui.Activator;
b5a80fe7 21import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
76fccfb0 22import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper;
34c8c664 23import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
76fccfb0
MK
24import org.eclipse.swt.widgets.FileDialog;
25import org.eclipse.swt.widgets.Shell;
26import org.eclipse.ui.PlatformUI;
c0c7c656 27import org.eclipse.ui.handlers.HandlerUtil;
76fccfb0
MK
28
29/**
30 * Open file handler, used to open files (not directories)
31 *
32 * @author Matthew Khouzam
33 */
34public class OpenFileHandler extends AbstractHandler {
35
36 @Override
37 public Object execute(ExecutionEvent event) {
38 final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
39 FileDialog fd = new FileDialog(shell);
40 fd.setText(Messages.OpenFileHandler_SelectTraceFile);
41 String filePath = fd.open();
42 if (filePath == null) {
43 return null;
44 }
c0c7c656 45
76fccfb0
MK
46 TmfOpenTraceHelper oth = new TmfOpenTraceHelper();
47 try {
c0c7c656
MAL
48 IProject project = TmfHandlerUtil.getProjectFromSelection(HandlerUtil.getCurrentSelection(event));
49 String projectName = project != null ? project.getName() : TmfCommonConstants.DEFAULT_TRACE_PROJECT_NAME;
34c8c664
MAL
50 if (project == null) {
51 project = TmfProjectRegistry.createProject(projectName, null, new NullProgressMonitor());
52 }
53
c0c7c656 54 oth.openTraceFromPath(projectName, filePath, shell);
76fccfb0 55 } catch (CoreException e) {
c0c7c656 56 Activator.getDefault().logError(e.getMessage(), e);
76fccfb0
MK
57 }
58 return null;
59 }
60}
This page took 0.034106 seconds and 5 git commands to generate.