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
.TmfTraceClosedSignal
;
20 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfTraceOpenedSignal
;
21 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfTraceParserUpdatedSignal
;
22 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfTraceSelectedSignal
;
23 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.ParserProviderManager
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsTable
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.ProjectView
;
27 import org
.eclipse
.swt
.widgets
.Composite
;
28 import org
.eclipse
.ui
.IEditorInput
;
29 import org
.eclipse
.ui
.IEditorPart
;
30 import org
.eclipse
.ui
.IEditorSite
;
31 import org
.eclipse
.ui
.IFileEditorInput
;
32 import org
.eclipse
.ui
.IPropertyListener
;
33 import org
.eclipse
.ui
.IReusableEditor
;
34 import org
.eclipse
.ui
.PartInitException
;
35 import org
.eclipse
.ui
.ide
.FileStoreEditorInput
;
38 * <b><u>TmfEventsEditor</u></b>
40 public class TmfEventsEditor
extends TmfEditor
implements ITmfTraceEditor
, IReusableEditor
, IPropertyListener
{
42 public static final String ID
= "org.eclipse.linuxtools.tmf.ui.editors.events"; //$NON-NLS-1$
44 private TmfEventsTable fEventsTable
;
45 private IResource fResource
;
46 private ITmfTrace fTrace
;
47 private Composite fParent
;
50 public void doSave(IProgressMonitor monitor
) {
54 public void doSaveAs() {
58 public void init(IEditorSite site
, IEditorInput input
) throws PartInitException
{
59 if (input
instanceof TmfEditorInput
) {
60 fResource
= ((TmfEditorInput
) input
).getResource();
61 fTrace
= ((TmfEditorInput
) input
).getTrace();
62 } else if (input
instanceof IFileEditorInput
) {
63 fResource
= ((IFileEditorInput
) input
).getFile();
64 fTrace
= ParserProviderManager
.getTrace(fResource
);
65 input
= new TmfEditorInput(fResource
, fTrace
);
66 } else if (input
instanceof FileStoreEditorInput
) {
68 FileStoreEditorInput fileStoreEditorInput
= (FileStoreEditorInput
) input
;
69 fResource
= ProjectView
.createLink(fileStoreEditorInput
.getURI());
70 fTrace
= ParserProviderManager
.getTrace(fResource
);
71 input
= new TmfEditorInput(fResource
, fTrace
);
72 } catch (CoreException e
) {
73 throw new PartInitException(e
.getMessage());
76 throw new PartInitException("Invalid IEditorInput: " + input
.getClass()); //$NON-NLS-1$
79 throw new PartInitException("Invalid IEditorInput: " + fResource
.getName()); //$NON-NLS-1$
82 super.setInput(input
);
86 public boolean isDirty() {
91 public boolean isSaveAsAllowed() {
96 public void setInput(IEditorInput input
) {
97 super.setInput(input
);
98 firePropertyChange(IEditorPart
.PROP_INPUT
);
103 public void propertyChanged(Object source
, int propId
) {
104 if (propId
== IEditorPart
.PROP_INPUT
) {
105 broadcast(new TmfTraceClosedSignal(this, fTrace
));
106 fResource
= ((TmfEditorInput
) getEditorInput()).getResource();
107 fTrace
= ((TmfEditorInput
) getEditorInput()).getTrace();
108 fEventsTable
.dispose();
109 if (fTrace
!= null) {
110 fEventsTable
= createEventsTable(fParent
, fTrace
.getCacheSize());
111 fEventsTable
.setTrace(fTrace
, true);
112 broadcast(new TmfTraceOpenedSignal(this, fTrace
));
114 fEventsTable
= new TmfEventsTable(fParent
, 0);
121 public void createPartControl(Composite parent
) {
123 setPartName(getEditorInput().getName());
124 if (fTrace
!= null) {
125 fEventsTable
= createEventsTable(parent
, fTrace
.getCacheSize());
126 fEventsTable
.setTrace(fTrace
, true);
127 broadcast(new TmfTraceOpenedSignal(this, fTrace
));
129 fEventsTable
= new TmfEventsTable(parent
, 0);
131 addPropertyListener(this);
135 public void dispose() {
136 removePropertyListener(this);
137 if (fTrace
!= null) {
138 broadcast(new TmfTraceClosedSignal(this, fTrace
));
140 if (fEventsTable
!= null) {
141 fEventsTable
.dispose();
146 protected TmfEventsTable
createEventsTable(Composite parent
, int cacheSize
) {
147 TmfEventsTable eventsTable
= ParserProviderManager
.getEventsTable(fTrace
, parent
, cacheSize
);
148 if (eventsTable
== null) {
149 eventsTable
= new TmfEventsTable(parent
, cacheSize
);
156 public ITmfTrace
getTrace() {
161 public void setFocus() {
162 fEventsTable
.setFocus();
163 if (fTrace
!= null) {
164 broadcast(new TmfTraceSelectedSignal(this, fTrace
));
168 // ------------------------------------------------------------------------
170 // ------------------------------------------------------------------------
173 public void traceParserUpdated(TmfTraceParserUpdatedSignal signal
) {
174 if (signal
.getTraceResource().equals(fResource
)) {
175 broadcast(new TmfTraceClosedSignal(this, fTrace
));
176 fTrace
= ParserProviderManager
.getTrace(fResource
);
177 fEventsTable
.dispose();
178 if (fTrace
!= null) {
179 fEventsTable
= createEventsTable(fParent
, fTrace
.getCacheSize());
180 fEventsTable
.setTrace(fTrace
, true);
181 broadcast(new TmfTraceOpenedSignal(this, fTrace
));
183 fEventsTable
= new TmfEventsTable(fParent
, 0);
190 public void traceSelected(TmfTraceSelectedSignal signal
) {
191 if (signal
.getSource() != this && signal
.getTrace().equals(fTrace
)) {
192 getSite().getPage().bringToTop(this);