1 11 package org.eclipse.debug.internal.ui.actions; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 import java.util.Map ; 18 19 import org.eclipse.debug.internal.ui.DebugUIPlugin; 20 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 21 import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentation; 22 import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer; 23 import org.eclipse.jface.action.Action; 24 import org.eclipse.jface.resource.ImageDescriptor; 25 import org.eclipse.jface.viewers.IStructuredContentProvider; 26 import org.eclipse.jface.viewers.LabelProvider; 27 import org.eclipse.jface.viewers.Viewer; 28 import org.eclipse.jface.window.Window; 29 import org.eclipse.swt.graphics.Image; 30 import org.eclipse.ui.PlatformUI; 31 import org.eclipse.ui.dialogs.ListSelectionDialog; 32 import org.eclipse.ui.texteditor.IUpdate; 33 34 39 public class ConfigureColumnsAction extends Action implements IUpdate { 40 41 private TreeModelViewer fViewer; 42 43 class ColumnContentProvider implements IStructuredContentProvider { 44 45 48 public Object [] getElements(Object inputElement) { 49 return ((IColumnPresentation)inputElement).getAvailableColumns(); 50 } 51 52 55 public void dispose() { 56 } 57 58 61 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 62 } 63 64 } 65 66 class ColumnLabelProvider extends LabelProvider { 67 68 private Map fImages = new HashMap (); 69 70 public Image getImage(Object element) { 71 ImageDescriptor imageDescriptor = fViewer.getColumnPresentation().getImageDescriptor((String )element); 72 if (imageDescriptor != null) { 73 Image image = (Image) fImages.get(imageDescriptor); 74 if (image == null) { 75 image = imageDescriptor.createImage(); 76 fImages.put(imageDescriptor, image); 77 } 78 return image; 79 } 80 return null; 81 } 82 83 public String getText(Object element) { 84 return fViewer.getColumnPresentation().getHeader((String )element); 85 } 86 87 public void dispose() { 88 super.dispose(); 89 Iterator iterator = fImages.values().iterator(); 90 while (iterator.hasNext()) { 91 Image image = (Image) iterator.next(); 92 image.dispose(); 93 } 94 fImages.clear(); 95 } 96 97 98 99 } 100 101 public ConfigureColumnsAction(TreeModelViewer viewer) { 102 setText(ActionMessages.ConfigureColumnsAction_0); 103 setId(DebugUIPlugin.getUniqueIdentifier() + ".ConfigureColumnsAction"); PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.CONFIGURE_COLUMNS_ACTION); 105 fViewer = viewer; 106 } 107 108 111 public void update() { 112 setEnabled(fViewer.isShowColumns()); 113 } 114 115 118 public void run() { 119 ListSelectionDialog dialog = new ListSelectionDialog( 120 fViewer.getControl().getShell(), 121 fViewer.getColumnPresentation(), 122 new ColumnContentProvider(), 123 new ColumnLabelProvider(), 124 ActionMessages.ConfigureColumnsAction_1); 125 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.CONFIGURE_COLUMNS_DIALOG); 126 String [] visibleColumns = fViewer.getVisibleColumns(); 127 List initialSelection = new ArrayList (visibleColumns.length); 128 for (int i = 0; i < visibleColumns.length; i++) { 129 initialSelection.add(visibleColumns[i]); 130 } 131 dialog.setTitle(ActionMessages.ConfigureColumnsAction_2); 132 dialog.setInitialElementSelections(initialSelection); 133 if (dialog.open() == Window.OK) { 134 Object [] result = dialog.getResult(); 135 if (result.length == 0) { 136 fViewer.setShowColumns(false); 137 } else { 138 String [] ids = new String [result.length]; 139 System.arraycopy(result, 0, ids, 0, result.length); 140 fViewer.resetColumnSizes(ids); 141 fViewer.setVisibleColumns(ids); 142 } 143 } 144 145 } 146 147 } 148 | Popular Tags |