1 11 package org.eclipse.debug.internal.ui.views.memory; 12 13 import org.eclipse.core.runtime.IProgressMonitor; 14 import org.eclipse.core.runtime.ISafeRunnable; 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.core.runtime.SafeRunner; 17 import org.eclipse.core.runtime.Status; 18 import org.eclipse.debug.internal.ui.views.memory.renderings.ErrorRendering; 19 import org.eclipse.debug.ui.memory.IMemoryRendering; 20 import org.eclipse.jface.util.IPropertyChangeListener; 21 import org.eclipse.jface.util.PropertyChangeEvent; 22 import org.eclipse.jface.viewers.IBasicPropertyConstants; 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.events.DisposeEvent; 25 import org.eclipse.swt.events.DisposeListener; 26 import org.eclipse.swt.graphics.Image; 27 import org.eclipse.swt.widgets.Control; 28 import org.eclipse.swt.widgets.Event; 29 import org.eclipse.swt.widgets.Listener; 30 import org.eclipse.swt.widgets.TabItem; 31 import org.eclipse.ui.progress.WorkbenchJob; 32 33 38 public class MemoryViewTab implements IMemoryViewTab, IPropertyChangeListener, Listener { 39 40 private IMemoryRendering fRendering; 41 private TabItem fTabItem; 42 private DisposeListener fDisposeListener; 43 private boolean fEnabled; 44 private boolean fIsDisposed = false; 45 private Control fControl; 46 private RenderingViewPane fContainer; 47 48 49 public MemoryViewTab(TabItem tabItem, IMemoryRendering rendering, RenderingViewPane container) 50 { 51 fTabItem = tabItem; 52 fRendering = rendering; 53 fContainer = container; 54 55 59 if (container.getMemoryRenderingSite().getSynchronizationService() != null) 60 container.getMemoryRenderingSite().getSynchronizationService().setSynchronizationProvider(rendering); 61 Control control = createViewTab(); 62 63 control.addListener(SWT.Activate, this); 64 control.addListener(SWT.Deactivate, this); 65 66 fTabItem.setControl(control); 67 fTabItem.setData(this); 68 fTabItem.setText(getLabel()); 69 fTabItem.setImage(getImage()); 70 71 fTabItem.addDisposeListener(fDisposeListener = new DisposeListener() { 72 73 public void widgetDisposed(DisposeEvent e) { 74 fTabItem.removeDisposeListener(fDisposeListener); 75 dispose(); 76 }}); 77 } 78 79 private Control createViewTab() 80 { 81 ISafeRunnable safeRunnable = new ISafeRunnable() { 82 83 public void handleException(Throwable exception) { 84 ErrorRendering rendering = new ErrorRendering(fRendering.getRenderingId(), exception); 86 rendering.init(fContainer, fRendering.getMemoryBlock()); 87 88 fRendering.dispose(); 90 91 fRendering = rendering; 92 fControl = rendering.createControl(fTabItem.getParent()); 93 } 94 95 public void run() throws Exception { 96 fControl = fRendering.createControl(fTabItem.getParent()); 97 fRendering.addPropertyChangeListener(getInstance()); 98 }}; 99 100 SafeRunner.run(safeRunnable); 101 return fControl; 102 } 103 104 private String getLabel() 105 { 106 return fRendering.getLabel(); 107 } 108 109 private Image getImage() 110 { 111 return fRendering.getImage(); 112 } 113 114 117 public void dispose() { 118 119 if (fIsDisposed) 120 return; 121 122 fIsDisposed = true; 123 124 fRendering.removePropertyChangeListener(this); 125 126 if (!fControl.isDisposed()) 127 { 128 fControl.removeListener(SWT.Activate, this); 129 fControl.removeListener(SWT.Deactivate, this); 130 } 131 132 fRendering.deactivated(); 134 135 fRendering.dispose(); 136 } 137 138 public boolean isDisposed() 139 { 140 return fIsDisposed; 141 } 142 143 146 public boolean isEnabled() { 147 return fEnabled; 148 } 149 150 153 public void setEnabled(boolean enabled) { 154 fEnabled = enabled; 155 156 if (fEnabled) 157 fRendering.becomesVisible(); 158 else 159 fRendering.becomesHidden(); 160 161 } 162 163 166 public void setTabLabel(String label) { 167 fTabItem.setText(label); 168 } 169 170 173 public String getTabLabel() { 174 return fTabItem.getText(); 175 } 176 177 180 public IMemoryRendering getRendering() { 181 return fRendering; 182 } 183 184 187 public void propertyChange(final PropertyChangeEvent event) { 188 189 192 WorkbenchJob job = new WorkbenchJob("MemoryViewTab PropertyChanged") { 194 public IStatus runInUIThread(IProgressMonitor monitor) { 195 if (isDisposed()) 196 return Status.OK_STATUS; 197 198 if (event.getSource() == fRendering) 199 { 200 if (event.getProperty().equals(IBasicPropertyConstants.P_TEXT)) 201 { 202 Object value = event.getNewValue(); 203 if (value != null && value instanceof String ) 204 { 205 String label = (String )value; 206 setTabLabel(label); 207 } 208 else 209 { 210 setTabLabel(fRendering.getLabel()); 211 } 212 } 213 214 if (event.getProperty().equals(IBasicPropertyConstants.P_IMAGE)) 215 { 216 Object value = event.getNewValue(); 217 if (value != null && value instanceof Image) 218 { 219 Image image = (Image)value; 220 fTabItem.setImage(image); 221 } 222 else 223 { 224 fTabItem.setImage(fRendering.getImage()); 225 } 226 } 227 } 228 return Status.OK_STATUS; 229 } 230 }; 231 job.setSystem(true); 232 job.schedule(); 233 } 234 235 private MemoryViewTab getInstance() 236 { 237 return this; 238 } 239 240 243 public void handleEvent(Event event) { 244 if (event.type == SWT.Activate) 245 { 246 fRendering.activated(); 247 fContainer.setRenderingSelection(fRendering); 248 } 249 if (event.type == SWT.Deactivate) 250 { 251 fRendering.deactivated(); 252 } 253 } 254 } 255 | Popular Tags |