1 11 package org.eclipse.debug.internal.ui.launchConfigurations; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.debug.core.ILaunchConfiguration; 18 import org.eclipse.debug.internal.ui.DebugUIPlugin; 19 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 20 import org.eclipse.debug.internal.ui.SWTUtil; 21 import org.eclipse.debug.ui.DebugUITools; 22 import org.eclipse.jface.dialogs.Dialog; 23 import org.eclipse.jface.dialogs.IDialogConstants; 24 import org.eclipse.jface.dialogs.IDialogSettings; 25 import org.eclipse.jface.dialogs.MessageDialogWithToggle; 26 import org.eclipse.jface.preference.IPreferenceStore; 27 import org.eclipse.jface.viewers.CheckboxTreeViewer; 28 import org.eclipse.jface.viewers.ITreeContentProvider; 29 import org.eclipse.jface.viewers.Viewer; 30 import org.eclipse.swt.SWT; 31 import org.eclipse.swt.events.SelectionEvent; 32 import org.eclipse.swt.events.SelectionListener; 33 import org.eclipse.swt.layout.GridData; 34 import org.eclipse.swt.layout.GridLayout; 35 import org.eclipse.swt.widgets.Button; 36 import org.eclipse.swt.widgets.Composite; 37 import org.eclipse.swt.widgets.Control; 38 import org.eclipse.swt.widgets.Shell; 39 import org.eclipse.swt.widgets.Tree; 40 import org.eclipse.swt.widgets.TreeItem; 41 import org.eclipse.ui.dialogs.SelectionDialog; 42 import org.eclipse.ui.model.AdaptableList; 43 44 49 public class DeleteAssociatedLaunchConfigurationsDialog extends SelectionDialog { 50 53 class DeleteContentProvider implements ITreeContentProvider { 54 55 private HashMap fInputMap = new HashMap (); 56 57 public DeleteContentProvider(HashMap map) { 58 if(map != null) { 59 fInputMap = map; 60 } 61 } 62 63 public Object [] getChildren(Object parentElement) { 64 if(parentElement instanceof IProject) { 65 return ((ArrayList )fInputMap.get(parentElement)).toArray(); 66 } 67 if(parentElement instanceof AdaptableList) { 68 return fInputMap.keySet().toArray(); 69 } 70 return new Object [0]; 71 } 72 73 public Object getParent(Object element) {return null;} 74 75 public boolean hasChildren(Object element) { 76 if(element instanceof IProject) { 77 return true; 78 } 79 return false; 80 } 81 82 public Object [] getElements(Object inputElement) { 83 return getChildren(inputElement); 84 } 85 86 public void dispose() { 87 fInputMap.clear(); 88 fInputMap = null; 89 } 90 91 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} 92 93 } 94 95 98 class LCViewer extends CheckboxTreeViewer { 99 100 105 public LCViewer(Composite parent, int style) { 106 super(parent, style); 107 } 108 109 112 public Object [] getCheckedElements() { 113 Object [] items = super.getCheckedElements(); 114 ArrayList list = new ArrayList (); 116 for (int i = 0; i < items.length; i++) { 117 if(items[i] instanceof ILaunchConfiguration) { 118 list.add(items[i]); 119 } 120 } 121 return list.toArray(); 122 } 123 124 127 protected void handleSelect(SelectionEvent event) { 128 if(event.detail == SWT.CHECK) { 129 updateCheckedState((TreeItem)event.item); 130 } 131 } 132 133 138 public void updateCheckedState(TreeItem item) { 139 Object element = item.getData(); 140 if (element instanceof ILaunchConfiguration) { 141 TreeItem parent = item.getParentItem(); 142 TreeItem[] children = parent.getItems(); 143 int checked = 0; 144 for (int i = 0; i < children.length; i++) { 145 if(children[i].getChecked()) { 146 checked++; 147 } 148 } 149 if(checked == 0) { 150 setGrayChecked(parent.getData(), false); 151 } 152 else if(checked == children.length) { 153 parent.setGrayed(false); 154 parent.setChecked(true); 155 } 156 else { 157 setGrayChecked(parent.getData(), true); 158 } 159 } 160 else if (element instanceof IProject) { 161 item.setGrayed(false); 162 TreeItem[] children = item.getItems(); 163 for (int i = 0; i < children.length; i++) { 164 setChecked(children[i].getData(), item.getChecked()); 165 } 166 } 167 } 168 } 169 170 private static final String SETTINGS_ID = ".DELETE_ASSOCIATED_CONFIGS_DIALOG"; private HashMap fMap = null; 172 private Object fInput = null; 173 private Button fPrefButton = null; 174 private LCViewer fViewer = null; 175 private Object [] fResult = null; 176 177 184 public DeleteAssociatedLaunchConfigurationsDialog(Shell parentShell, Object input, String message, HashMap map) { 185 super(parentShell); 186 super.setMessage(message); 187 setShellStyle(getShellStyle() | SWT.RESIZE); 188 fMap = map; 189 fInput = input; 190 } 191 192 195 protected IDialogSettings getDialogBoundsSettings() { 196 IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings(); 197 IDialogSettings section = settings.getSection(SETTINGS_ID); 198 if (section == null) { 199 section = settings.addNewSection(SETTINGS_ID); 200 } 201 return section; 202 } 203 204 207 protected Control createDialogArea(Composite parent) { 208 initializeDialogUnits(parent); 209 Composite comp = (Composite) super.createDialogArea(parent); 210 SWTUtil.createLabel(comp, LaunchConfigurationsMessages.DeleteAssociatedLaunchConfigurationsDialog_0, 2); 211 fViewer = new LCViewer(comp, SWT.BORDER); 212 Tree tree = fViewer.getTree(); 213 GridData gd = new GridData(GridData.FILL_BOTH); 214 gd.horizontalSpan = 2; 215 tree.setLayoutData(gd); 216 fViewer.setContentProvider(new DeleteContentProvider(fMap)); 217 fViewer.setInput(fInput); 218 fViewer.setLabelProvider(DebugUITools.newDebugModelPresentation()); 219 fViewer.expandAll(); 220 Composite butcomp = new Composite(comp, SWT.NONE); 221 GridLayout layout = new GridLayout(2, false); 222 layout.marginHeight = 0; 223 layout.marginWidth = 0; 224 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 225 butcomp.setLayout(layout); 226 gd = new GridData(GridData.FILL_HORIZONTAL); 227 gd.horizontalSpan = 2; 228 butcomp.setLayoutData(gd); 229 Button sall = SWTUtil.createPushButton(butcomp, LaunchConfigurationsMessages.DeleteAssociatedLaunchConfigurationsDialog_1, null); 230 sall.addSelectionListener(new SelectionListener() { 231 public void widgetDefaultSelected(SelectionEvent e) {} 232 public void widgetSelected(SelectionEvent e) { 233 fViewer.setGrayedElements(new Object [0]); 234 fViewer.setAllChecked(true); 235 } 236 }); 237 Button dsall = SWTUtil.createPushButton(butcomp, LaunchConfigurationsMessages.DeleteAssociatedLaunchConfigurationsDialog_2, null); 238 dsall.addSelectionListener(new SelectionListener() { 239 public void widgetDefaultSelected(SelectionEvent e) {} 240 public void widgetSelected(SelectionEvent e) { 241 fViewer.setAllChecked(false); 242 } 243 }); 244 fPrefButton = new Button(comp, SWT.CHECK); 245 fPrefButton.setText(LaunchConfigurationsMessages.DeleteAssociatedLaunchConfigurationsDialog_3); 246 Dialog.applyDialogFont(comp); 247 return comp; 248 } 249 250 253 public Object [] getResult() { 254 return fResult; 255 } 256 257 260 protected void okPressed() { 261 fResult = fViewer.getCheckedElements(); 262 boolean pref = fPrefButton.getSelection(); 264 if(pref) { 265 IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); 266 store.setValue(IInternalDebugUIConstants.PREF_DELETE_CONFIGS_ON_PROJECT_DELETE, MessageDialogWithToggle.ALWAYS); 267 } 268 super.okPressed(); 269 } 270 } 271 | Popular Tags |