• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ide.eclipse.gltrace;
18 
19 import org.eclipse.core.filesystem.EFS;
20 import org.eclipse.core.filesystem.IFileStore;
21 import org.eclipse.core.runtime.Path;
22 import org.eclipse.jface.action.IAction;
23 import org.eclipse.jface.dialogs.MessageDialog;
24 import org.eclipse.jface.viewers.ISelection;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.widgets.Display;
27 import org.eclipse.swt.widgets.FileDialog;
28 import org.eclipse.swt.widgets.Shell;
29 import org.eclipse.ui.IWorkbenchPage;
30 import org.eclipse.ui.IWorkbenchWindow;
31 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
32 import org.eclipse.ui.PartInitException;
33 import org.eclipse.ui.PlatformUI;
34 import org.eclipse.ui.ide.IDE;
35 
36 import java.io.File;
37 
38 public class OpenGLTraceAction implements IWorkbenchWindowActionDelegate {
39     private static String sLoadFromFolder = System.getProperty("user.home");
40 
41     @Override
run(IAction action)42     public void run(IAction action) {
43         openTrace();
44     }
45 
46     @Override
selectionChanged(IAction action, ISelection selection)47     public void selectionChanged(IAction action, ISelection selection) {
48     }
49 
50     @Override
dispose()51     public void dispose() {
52     }
53 
54     @Override
init(IWorkbenchWindow window)55     public void init(IWorkbenchWindow window) {
56     }
57 
openTrace()58     private void openTrace() {
59         Shell shell = Display.getDefault().getActiveShell();
60         FileDialog fd = new FileDialog(shell, SWT.OPEN);
61 
62         fd.setText("Open Trace File");
63         fd.setFilterPath(sLoadFromFolder);
64         fd.setFilterExtensions(new String[] { "*.gltrace" });
65 
66         String fname = fd.open();
67         if (fname == null || fname.trim().length() == 0) {
68             return;
69         }
70 
71         sLoadFromFolder = new File(fname).getParent().toString();
72 
73         openEditorFor(fname);
74     }
75 
openEditorFor(String fname)76     private void openEditorFor(String fname) {
77         IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(fname));
78         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
79 
80         try {
81             IDE.openEditorOnFileStore( page, fileStore );
82         } catch (PartInitException e) {
83             MessageDialog.openError(Display.getDefault().getActiveShell(),
84                     "Error opening GL Trace File",
85                     "Unexpected error while opening GL Trace file: " + e.getMessage());
86         }
87     }
88 }
89