1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.editors
;
15 import org
.eclipse
.core
.resources
.IResource
;
16 import org
.eclipse
.core
.runtime
.CoreException
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalHandler
;
19 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfTraceSelectedSignal
;
20 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.ParserProviderManager
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.signal
.TmfTraceClosedSignal
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.signal
.TmfTraceParserUpdatedSignal
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsTable
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.ProjectView
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.ui
.IEditorInput
;
28 import org
.eclipse
.ui
.IEditorPart
;
29 import org
.eclipse
.ui
.IEditorSite
;
30 import org
.eclipse
.ui
.IFileEditorInput
;
31 import org
.eclipse
.ui
.IPropertyListener
;
32 import org
.eclipse
.ui
.IReusableEditor
;
33 import org
.eclipse
.ui
.PartInitException
;
34 import org
.eclipse
.ui
.ide
.FileStoreEditorInput
;
37 * <b><u>TmfEventsEditor</u></b>
39 public class TmfEventsEditor
extends TmfEditor
implements ITmfTraceEditor
, IReusableEditor
, IPropertyListener
{
41 public static final String ID
= "org.eclipse.linuxtools.tmf.ui.editors.events"; //$NON-NLS-1$
43 private TmfEventsTable fEventsTable
;
44 private IResource fResource
;
45 private ITmfTrace fTrace
;
46 private Composite fParent
;
49 public void doSave(IProgressMonitor monitor
) {
53 public void doSaveAs() {
57 public void init(IEditorSite site
, IEditorInput input
) throws PartInitException
{
58 if (input
instanceof TmfEditorInput
) {
59 fResource
= ((TmfEditorInput
) input
).getResource();
60 fTrace
= ((TmfEditorInput
) input
).getTrace();
61 } else if (input
instanceof IFileEditorInput
) {
62 fResource
= ((IFileEditorInput
) input
).getFile();
63 fTrace
= ParserProviderManager
.getTrace(fResource
);
64 input
= new TmfEditorInput(fResource
, fTrace
);
65 } else if (input
instanceof FileStoreEditorInput
) {
67 FileStoreEditorInput fileStoreEditorInput
= (FileStoreEditorInput
) input
;
68 fResource
= ProjectView
.createLink(fileStoreEditorInput
.getURI());
69 fTrace
= ParserProviderManager
.getTrace(fResource
);
70 input
= new TmfEditorInput(fResource
, fTrace
);
71 } catch (CoreException e
) {
72 throw new PartInitException(e
.getMessage());
75 throw new PartInitException("Invalid IEditorInput: " + input
.getClass()); //$NON-NLS-1$
78 throw new PartInitException("Invalid IEditorInput: " + fResource
.getName()); //$NON-NLS-1$
81 super.setInput(input
);
85 public boolean isDirty() {
90 public boolean isSaveAsAllowed() {
95 public void setInput(IEditorInput input
) {
96 super.setInput(input
);
97 firePropertyChange(IEditorPart
.PROP_INPUT
);
102 public void propertyChanged(Object source
, int propId
) {
103 if (propId
== IEditorPart
.PROP_INPUT
) {
104 broadcast(new TmfTraceClosedSignal(this, fTrace
));
105 fResource
= ((TmfEditorInput
) getEditorInput()).getResource();
106 fTrace
= ((TmfEditorInput
) getEditorInput()).getTrace();
107 fEventsTable
.dispose();
108 if (fTrace
!= null) {
109 fEventsTable
= createEventsTable(fParent
, fTrace
.getCacheSize());
110 fEventsTable
.setTrace(fTrace
, true);
111 // FIXME: broadcast(new TmfTraceOpenedSignal(this, fTrace));
113 fEventsTable
= new TmfEventsTable(fParent
, 0);
120 public void createPartControl(Composite parent
) {
122 setPartName(getEditorInput().getName());
123 if (fTrace
!= null) {
124 fEventsTable
= createEventsTable(parent
, fTrace
.getCacheSize());
125 fEventsTable
.setTrace(fTrace
, true);
126 // FIXME: broadcast(new TmfTraceOpenedSignal(this, fTrace));
128 fEventsTable
= new TmfEventsTable(parent
, 0);
130 addPropertyListener(this);
134 public void dispose() {
135 removePropertyListener(this);
136 if (fTrace
!= null) {
137 broadcast(new TmfTraceClosedSignal(this, fTrace
));
139 if (fEventsTable
!= null) {
140 fEventsTable
.dispose();
145 protected TmfEventsTable
createEventsTable(Composite parent
, int cacheSize
) {
146 TmfEventsTable eventsTable
= ParserProviderManager
.getEventsTable(fTrace
, parent
, cacheSize
);
147 if (eventsTable
== null) {
148 eventsTable
= new TmfEventsTable(parent
, cacheSize
);
155 public ITmfTrace
getTrace() {
160 public void setFocus() {
161 fEventsTable
.setFocus();
162 if (fTrace
!= null) {
163 broadcast(new TmfTraceSelectedSignal(this, fTrace
));
167 // ------------------------------------------------------------------------
169 // ------------------------------------------------------------------------
172 public void traceParserUpdated(TmfTraceParserUpdatedSignal signal
) {
173 if (signal
.getTraceResource().equals(fResource
)) {
174 broadcast(new TmfTraceClosedSignal(this, fTrace
));
175 fTrace
= ParserProviderManager
.getTrace(fResource
);
176 fEventsTable
.dispose();
177 if (fTrace
!= null) {
178 fEventsTable
= createEventsTable(fParent
, fTrace
.getCacheSize());
179 fEventsTable
.setTrace(fTrace
, true);
180 // FIXME:broadcast(new TmfTraceOpenedSignal(this, fTrace, fResource, fEventsTable));
182 fEventsTable
= new TmfEventsTable(fParent
, 0);
189 public void traceSelected(TmfTraceSelectedSignal signal
) {
190 if (signal
.getSource() != this && signal
.getTrace().equals(fTrace
)) {
191 getSite().getPage().bringToTop(this);