1 11 package org.eclipse.debug.internal.ui.launchConfigurations; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.debug.core.DebugPlugin; 18 import org.eclipse.debug.core.ILaunchConfiguration; 19 import org.eclipse.debug.internal.ui.DebugUIPlugin; 20 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 21 import org.eclipse.debug.internal.ui.SWTFactory; 22 import org.eclipse.debug.ui.IDebugUIConstants; 23 import org.eclipse.jface.viewers.IContentProvider; 24 import org.eclipse.jface.viewers.IStructuredContentProvider; 25 import org.eclipse.jface.viewers.Viewer; 26 import org.eclipse.jface.viewers.ViewerFilter; 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.events.SelectionAdapter; 29 import org.eclipse.swt.events.SelectionEvent; 30 import org.eclipse.swt.layout.GridData; 31 import org.eclipse.swt.widgets.Button; 32 import org.eclipse.swt.widgets.Composite; 33 import org.eclipse.swt.widgets.Shell; 34 import org.eclipse.ui.model.WorkbenchViewerComparator; 35 36 import com.ibm.icu.text.MessageFormat; 37 38 43 public class SelectFavoritesDialog extends AbstractDebugCheckboxSelectionDialog { 44 45 48 protected class LaunchConfigurationContentProvider implements IStructuredContentProvider { 49 public Object [] getElements(Object inputElement) { 50 ILaunchConfiguration[] all = null; 51 try { 52 all = LaunchConfigurationManager.filterConfigs(DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations()); 53 } catch (CoreException e) { 54 DebugUIPlugin.log(e); 55 return new ILaunchConfiguration[0]; 56 } 57 List list = new ArrayList (all.length); 58 ViewerFilter filter = new LaunchGroupFilter(fHistory.getLaunchGroup()); 59 for (int i = 0; i < all.length; i++) { 60 if (filter.select(null, null, all[i])) { 61 list.add(all[i]); 62 } 63 } 64 list.removeAll(fCurrentFavoriteSet); 65 Object [] objs = list.toArray(); 66 new WorkbenchViewerComparator().sort(getCheckBoxTableViewer(), objs); 67 return objs; 68 } 69 70 public void dispose() {} 71 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} 72 } 73 74 private LaunchHistory fHistory; 75 private List fCurrentFavoriteSet; 76 77 83 public SelectFavoritesDialog(Shell parentShell, LaunchHistory history, List favorites) { 84 super(parentShell); 85 fHistory = history; 86 fCurrentFavoriteSet = favorites; 87 setTitle(MessageFormat.format(LaunchConfigurationsMessages.FavoritesDialog_0, new String []{getModeLabel()})); 88 } 89 90 95 private String getModeLabel() { 96 return DebugUIPlugin.removeAccelerators(fHistory.getLaunchGroup().getLabel()); 97 } 98 99 102 protected String getDialogSettingsId() { 103 return IDebugUIConstants.PLUGIN_ID + ".SELECT_FAVORITESS_DIALOG"; } 105 106 109 protected Object getViewerInput() { 110 return fHistory.getLaunchGroup().getMode(); 111 } 112 113 116 protected IContentProvider getContentProvider() { 117 return new LaunchConfigurationContentProvider(); 118 } 119 120 123 protected String getHelpContextId() { 124 return IDebugHelpContextIds.SELECT_FAVORITES_DIALOG; 125 } 126 127 130 protected String getViewerLabel() { 131 return LaunchConfigurationsMessages.FavoritesDialog_7; 132 } 133 134 137 protected void addCustomFooterControls(Composite parent) { 138 Composite comp = SWTFactory.createComposite(parent, 2, 1, GridData.FILL_HORIZONTAL); 139 GridData gd = (GridData) comp.getLayoutData(); 140 gd.horizontalAlignment = SWT.END; 141 Button button = SWTFactory.createPushButton(comp, LaunchConfigurationsMessages.SelectFavoritesDialog_0, null); 142 button.addSelectionListener(new SelectionAdapter() { 143 public void widgetSelected(SelectionEvent e) { 144 getCheckBoxTableViewer().setAllChecked(true); 145 getOkButton().setEnabled(true); 146 } 147 }); 148 button = SWTFactory.createPushButton(comp, LaunchConfigurationsMessages.SelectFavoritesDialog_1, null); 149 button.addSelectionListener(new SelectionAdapter() { 150 public void widgetSelected(SelectionEvent e) { 151 getCheckBoxTableViewer().setAllChecked(false); 152 getOkButton().setEnabled(false); 153 } 154 }); 155 } 156 } 157 | Popular Tags |