1 11 package org.eclipse.debug.internal.ui.views.memory; 12 13 import java.util.ArrayList ; 14 import org.eclipse.debug.core.model.IMemoryBlock; 15 import org.eclipse.debug.internal.core.memory.IExtendedMemoryBlock; 16 import org.eclipse.debug.internal.core.memory.IMemoryRendering; 17 import org.eclipse.debug.internal.ui.DebugUIPlugin; 18 import org.eclipse.jface.action.MenuManager; 19 import org.eclipse.swt.widgets.TabItem; 20 21 32 abstract public class AbstractMemoryViewTab implements IMemoryViewTab { 33 34 protected IMemoryBlock fMemoryBlock; 35 protected TabItem fTabItem; 36 protected MenuManager fMenuMgr; 37 protected IMemoryRendering fRendering; 38 protected String fRenderingId; 39 40 public AbstractMemoryViewTab(IMemoryBlock newMemory, TabItem newTab, MenuManager menuMgr, IMemoryRendering rendering) 41 { 42 fMemoryBlock = newMemory; 43 fTabItem = newTab; 44 fMenuMgr = menuMgr; 45 fRendering = rendering; 46 fRenderingId = rendering.getRenderingId(); 47 48 fTabItem.setData(this); 49 50 maintainRefAndEnablement(true); 54 } 55 56 59 public void setEnabled(boolean enabled) { 60 maintainRefAndEnablement(enabled); 61 } 62 63 72 protected void maintainRefAndEnablement(boolean addReference) 73 { 74 if (addReference) 76 { 77 if (getMemoryBlock() instanceof IExtendedMemoryBlock) 78 { 79 ArrayList references = addReferenceToSynchronizer(); 81 82 if (references.size() == 1 && !((IExtendedMemoryBlock)getMemoryBlock()).isEnabled() ) 85 ((IExtendedMemoryBlock)getMemoryBlock()).enable(); 86 } 87 } 88 else if (!addReference){ 90 if (getMemoryBlock() instanceof IExtendedMemoryBlock) 91 { 92 ArrayList references = removeReferenceFromSynchronizer(); 93 94 if (references == null) 95 return; 96 97 if (references.size() == 0 && ((IExtendedMemoryBlock)getMemoryBlock()).isEnabled()) 100 ((IExtendedMemoryBlock)getMemoryBlock()).disable(); 101 } 102 } 103 } 104 105 117 protected ArrayList addReferenceToSynchronizer() { 118 119 ArrayList references = (ArrayList )DebugUIPlugin.getDefault().getMemoryBlockViewSynchronizer().getSynchronizedProperty(getMemoryBlock(), IMemoryViewConstants.PROPERTY_ENABLED_REFERENCES); 120 121 if (references == null) 123 { 124 references = new ArrayList (); 125 } 126 127 if (!references.contains(this)) 129 { 130 references.add(this); 131 } 132 133 DebugUIPlugin.getDefault().getMemoryBlockViewSynchronizer().setSynchronizedProperty(getMemoryBlock(), IMemoryViewConstants.PROPERTY_ENABLED_REFERENCES, references); 134 return references; 135 } 136 137 140 protected ArrayList removeReferenceFromSynchronizer() 141 { 142 ArrayList references = (ArrayList )DebugUIPlugin.getDefault().getMemoryBlockViewSynchronizer().getSynchronizedProperty(getMemoryBlock(), IMemoryViewConstants.PROPERTY_ENABLED_REFERENCES); 143 144 if (references == null) 147 { 148 return null; 149 } 150 151 if (references.contains(this)) 153 { 154 references.remove(this); 155 } 156 157 DebugUIPlugin.getDefault().getMemoryBlockViewSynchronizer().setSynchronizedProperty(getMemoryBlock(), IMemoryViewConstants.PROPERTY_ENABLED_REFERENCES, references); 158 return references; 159 } 160 161 164 public void dispose() { 165 166 maintainRefAndEnablement(false); 169 } 170 171 174 public IMemoryBlock getMemoryBlock() { 175 return fMemoryBlock; 176 } 177 178 181 public String getRenderingId() { 182 return fRendering.getRenderingId(); 183 } 184 185 188 public IMemoryRendering getRendering() 189 { 190 return fRendering; 191 } 192 193 } 194 | Popular Tags |