1 13 14 package org.eclipse.jface.viewers; 15 16 import org.eclipse.jface.util.Policy; 17 import org.eclipse.swt.events.DisposeEvent; 18 import org.eclipse.swt.events.DisposeListener; 19 import org.eclipse.swt.widgets.Widget; 20 21 30 public abstract class ViewerColumn { 31 32 private CellLabelProvider labelProvider; 33 34 static String COLUMN_VIEWER_KEY = Policy.JFACE + ".columnViewer"; 36 private EditingSupport editingSupport; 37 38 private ILabelProviderListener listener; 39 40 private boolean listenerRegistered = false; 41 42 51 protected ViewerColumn(final ColumnViewer viewer, Widget columnOwner) { 52 columnOwner.setData(ViewerColumn.COLUMN_VIEWER_KEY, this); 53 this.listener = new ILabelProviderListener() { 54 55 public void labelProviderChanged(LabelProviderChangedEvent event) { 56 viewer.handleLabelProviderChanged(event); 57 } 58 59 }; 60 columnOwner.addDisposeListener(new DisposeListener() { 61 public void widgetDisposed(DisposeEvent e) { 62 handleDispose(viewer); 63 } 64 }); 65 } 66 67 72 CellLabelProvider getLabelProvider() { 73 return labelProvider; 74 } 75 76 83 public void setLabelProvider(CellLabelProvider labelProvider) { 84 setLabelProvider(labelProvider, true); 85 } 86 87 91 void setLabelProvider(CellLabelProvider labelProvider, 92 boolean registerListener) { 93 if (listenerRegistered && this.labelProvider != null) { 94 this.labelProvider.removeListener(listener); 95 listenerRegistered = false; 96 } 97 98 this.labelProvider = labelProvider; 99 100 if (registerListener) { 101 this.labelProvider.addListener(listener); 102 listenerRegistered = true; 103 } 104 } 105 106 111 EditingSupport getEditingSupport() { 112 return editingSupport; 113 } 114 115 122 public void setEditingSupport(EditingSupport editingSupport) { 123 this.editingSupport = editingSupport; 124 } 125 126 134 void refresh(ViewerCell cell) { 135 getLabelProvider().update(cell); 136 } 137 138 144 protected void handleDispose() { 145 boolean disposeLabelProvider = listenerRegistered; 146 CellLabelProvider cellLabelProvider = labelProvider; 147 setLabelProvider(null, false); 148 if (disposeLabelProvider) { 149 cellLabelProvider.dispose(); 150 } 151 editingSupport = null; 152 listener = null; 153 } 154 155 private void handleDispose(ColumnViewer viewer) { 156 handleDispose(); 157 viewer.clearLegacyEditingSetup(); 158 } 159 } 160 | Popular Tags |