1 11 12 package org.eclipse.debug.internal.ui.elements.adapters; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.debug.core.DebugException; 19 import org.eclipse.debug.core.DebugPlugin; 20 import org.eclipse.debug.core.ILogicalStructureType; 21 import org.eclipse.debug.core.model.IDebugElement; 22 import org.eclipse.debug.core.model.IIndexedValue; 23 import org.eclipse.debug.core.model.IValue; 24 import org.eclipse.debug.core.model.IVariable; 25 import org.eclipse.debug.internal.ui.viewers.provisional.AsynchronousContentAdapter; 26 import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext; 27 import org.eclipse.debug.internal.ui.views.variables.IndexedVariablePartition; 28 import org.eclipse.debug.internal.ui.views.variables.VariablesView; 29 import org.eclipse.debug.ui.IDebugUIConstants; 30 import org.eclipse.ui.IWorkbenchPart; 31 32 public class VariableContentAdapter extends AsynchronousContentAdapter { 33 34 protected Object [] getChildren(Object parent, IPresentationContext context) throws CoreException { 35 IVariable variable = (IVariable) parent; 36 IValue value = variable.getValue(); 37 if (value != null) { 38 return getValueChildren(variable, value, context); 39 } 40 return EMPTY; 41 } 42 43 protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { 44 IValue value = ((IVariable)element).getValue(); 45 return value.hasVariables(); 46 } 47 48 59 protected Object [] getValueChildren(IDebugElement parent, IValue value, IPresentationContext context) throws CoreException { 60 if (value == null) { 61 return EMPTY; 62 } 63 IValue logicalValue = getLogicalValue(value, context); 64 if (logicalValue instanceof IIndexedValue) { 65 IIndexedValue indexedValue = (IIndexedValue) logicalValue; 66 int partitionSize = computeParitionSize(indexedValue); 67 if (partitionSize > 1) { 68 int offset = indexedValue.getInitialOffset(); 69 int length = indexedValue.getSize(); 70 int numPartitions = length / partitionSize; 71 int remainder = length % partitionSize; 72 if (remainder > 0) { 73 numPartitions++; 74 } 75 IVariable[] partitions = new IVariable[numPartitions]; 76 for (int i = 0; i < (numPartitions - 1); i++) { 77 partitions[i] = new IndexedVariablePartition(parent, indexedValue, offset, partitionSize); 78 offset = offset + partitionSize; 79 } 80 if (remainder == 0) { 81 remainder = partitionSize; 82 } 83 partitions[numPartitions - 1] = new IndexedVariablePartition(parent, indexedValue, offset, remainder); 84 return partitions; 85 } 86 } 87 if (logicalValue == null) { 88 logicalValue = value; 90 } 91 return logicalValue.getVariables(); 92 } 93 94 104 protected int computeParitionSize(IIndexedValue value) { 105 int partitionSize = 1; 106 try { 107 int length = value.getSize(); 108 int partitionDepth = 0; 109 int preferredSize = getArrayPartitionSize(); 110 int remainder = length % preferredSize; 111 length = length / preferredSize; 112 while (length > 0) { 113 if (remainder == 0 && length == 1) { 114 break; 115 } 116 partitionDepth++; 117 remainder = length % preferredSize; 118 length = length / preferredSize; 119 } 120 for (int i = 0; i < partitionDepth; i++) { 121 partitionSize = partitionSize * preferredSize; 122 } 123 } catch (DebugException e) { 124 } 125 return partitionSize; 126 } 127 128 135 protected IValue getLogicalValue(IValue value, IPresentationContext context) { 136 return getLogicalValue(value, new ArrayList (), context); 137 } 138 139 151 protected IValue getLogicalValue(IValue value, List previousStructureIds, IPresentationContext context) { 152 if (isShowLogicalStructure(context)) { 153 ILogicalStructureType[] types = DebugPlugin.getLogicalStructureTypes(value); 154 if (types.length > 0) { 155 ILogicalStructureType type = DebugPlugin.getDefaultStructureType(types); 156 if (type != null && !previousStructureIds.contains(type.getId())) { 157 try { 158 value = type.getLogicalStructure(value); 159 previousStructureIds.add(type.getId()); 160 return getLogicalValue(value, previousStructureIds, context); 161 } catch (CoreException e) { 162 } 164 } 165 } 166 } 167 return value; 168 } 169 170 177 protected boolean isShowLogicalStructure(IPresentationContext context) { 178 IWorkbenchPart part = context.getPart(); 179 if (part instanceof VariablesView) { 180 return ((VariablesView) part).isShowLogicalStructure(); 181 } 182 return false; 183 } 184 185 192 protected int getArrayPartitionSize() { 193 return 100; 195 } 196 197 protected boolean supportsPartId(String id) { 198 return id.equals(IDebugUIConstants.ID_EXPRESSION_VIEW) || id.equals(IDebugUIConstants.ID_VARIABLE_VIEW) || id.equals(IDebugUIConstants.ID_REGISTER_VIEW); 199 } 200 } 201 | Popular Tags |