2010-10-26 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug309042
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / editors / TmfEventsEditor.java
1 /*******************************************************************************
2 * Copyright (c) 2010 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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.editors;
14
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;
36
37 /**
38 * <b><u>TmfEventsEditor</u></b>
39 */
40 public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReusableEditor, IPropertyListener {
41
42 public static final String ID = "org.eclipse.linuxtools.tmf.ui.editors.events";
43
44 private TmfEventsTable fEventsTable;
45 private IResource fResource;
46 private ITmfTrace fTrace;
47 private Composite fParent;
48
49 @Override
50 public void doSave(IProgressMonitor monitor) {
51 }
52
53 @Override
54 public void doSaveAs() {
55 }
56
57 @Override
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) {
67 try {
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());
74 }
75 } else {
76 throw new PartInitException("Invalid IEditorInput: " + input.getClass());
77 }
78 if (fTrace == null) {
79 throw new PartInitException("Invalid IEditorInput: " + fResource.getName());
80 }
81 super.setSite(site);
82 super.setInput(input);
83 }
84
85 @Override
86 public boolean isDirty() {
87 return false;
88 }
89
90 @Override
91 public boolean isSaveAsAllowed() {
92 return false;
93 }
94
95 @Override
96 public void setInput(IEditorInput input) {
97 super.setInput(input);
98 firePropertyChange(IEditorPart.PROP_INPUT);
99 }
100
101 // @Override
102 @Override
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));
113 } else {
114 fEventsTable = new TmfEventsTable(fParent, 0);
115 }
116 fParent.layout();
117 }
118 }
119
120 @Override
121 public void createPartControl(Composite parent) {
122 fParent = 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));
128 } else {
129 fEventsTable = new TmfEventsTable(parent, 0);
130 }
131 addPropertyListener(this);
132 }
133
134 @Override
135 public void dispose() {
136 removePropertyListener(this);
137 if (fTrace != null) {
138 broadcast(new TmfTraceClosedSignal(this, fTrace));
139 }
140 if (fEventsTable != null) {
141 fEventsTable.dispose();
142 }
143 super.dispose();
144 }
145
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);
150 }
151 return eventsTable;
152 }
153
154 // @Override
155 @Override
156 public ITmfTrace getTrace() {
157 return fTrace;
158 }
159
160 @Override
161 public void setFocus() {
162 fEventsTable.setFocus();
163 if (fTrace != null) {
164 broadcast(new TmfTraceSelectedSignal(this, fTrace));
165 }
166 }
167
168 // ------------------------------------------------------------------------
169 // Signal handlers
170 // ------------------------------------------------------------------------
171
172 @TmfSignalHandler
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));
182 } else {
183 fEventsTable = new TmfEventsTable(fParent, 0);
184 }
185 fParent.layout();
186 }
187 }
188
189 @TmfSignalHandler
190 public void traceSelected(TmfTraceSelectedSignal signal) {
191 if (signal.getSource() != this && signal.getTrace().equals(fTrace)) {
192 getSite().getPage().bringToTop(this);
193 }
194 }
195
196 }
This page took 0.035407 seconds and 6 git commands to generate.