/*******************************************************************************
- * Copyright (c) 2009, 2010, 2011 Ericsson
+ * Copyright (c) 2009, 2013 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
-import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
import org.eclipse.linuxtools.tmf.ui.editors.TmfEditorInput;
import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
*/
public class OpenTraceHandler extends AbstractHandler {
- private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$
-
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
// Get the selection
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final IWorkbenchPart part = page.getActivePart();
+ if (part == null) {
+ return false;
+ }
final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
if (selectionProvider == null) {
return false;
return;
}
- final IResource resource = traceElement.getResource();
- IFile file = null;
- if (resource instanceof IFile) {
- file = (IFile) resource;
- } else if (resource instanceof IFolder) {
- try {
- final IFile bookmarksFile = traceElement.getProject().getTracesFolder().getResource().getFile(BOOKMARKS_HIDDEN_FILE);
- if (!bookmarksFile.exists()) {
- final InputStream source = new ByteArrayInputStream(new byte[0]);
- bookmarksFile.create(source, true, null);
- }
- bookmarksFile.setHidden(true);
-
- final IFolder folder = (IFolder) resource;
- file = folder.getFile(traceElement.getName() + '_');
- if (!file.exists()) {
- file.createLink(bookmarksFile.getLocation(), IResource.REPLACE, null);
- }
- file.setHidden(true);
- file.setPersistentProperty(TmfCommonConstants.TRACETYPE, TmfTrace.class.getCanonicalName());
- IDE.setDefaultEditor(file, editorId);
- // editor should dispose the trace on close
- } catch (final CoreException e) {
- Activator.getDefault().logError("Error opening trace " + traceElement.getName(), e); //$NON-NLS-1$
- displayErrorMsg(Messages.OpenTraceHandler_Error + "\n\n" + e.getMessage()); //$NON-NLS-1$
- trace.dispose();
- return;
- }
+ final IFile file;
+ try {
+ file = traceElement.createBookmarksFile();
+ } catch (final CoreException e) {
+ Activator.getDefault().logError("Error opening trace " + traceElement.getName(), e); //$NON-NLS-1$
+ displayErrorMsg(Messages.OpenTraceHandler_Error + "\n\n" + e.getMessage()); //$NON-NLS-1$
+ trace.dispose();
+ return;
}
- final IFile editorFile = file;
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
- final IEditorInput editorInput = new TmfEditorInput(editorFile, trace);
+ final IEditorInput editorInput = new TmfEditorInput(file, trace);
final IWorkbench wb = PlatformUI.getWorkbench();
final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
- final IEditorPart editor = activePage.findEditor(new FileEditorInput(editorFile));
+ final IEditorPart editor = activePage.findEditor(new FileEditorInput(file));
if ((editor != null) && (editor instanceof IReusableEditor)) {
activePage.reuseEditor((IReusableEditor) editor, editorInput);
activePage.activate(editor);
} else {
activePage.openEditor(editorInput, editorId);
- if (resource instanceof IFile) {
- IDE.setDefaultEditor((IFile) resource, editorId);
- }
+ IDE.setDefaultEditor(file, editorId);
+ // editor should dispose the trace on close
}
} catch (final PartInitException e) {
displayErrorMsg(Messages.OpenTraceHandler_Error + "\n\n" + e.getMessage()); //$NON-NLS-1$