1 11 package org.eclipse.debug.internal.ui.actions.breakpointGroups; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.debug.internal.ui.DebugUIPlugin; 16 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 17 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 18 import org.eclipse.debug.internal.ui.SWTFactory; 19 import org.eclipse.debug.ui.DebugUITools; 20 import org.eclipse.jface.dialogs.Dialog; 21 import org.eclipse.jface.dialogs.IDialogConstants; 22 import org.eclipse.jface.dialogs.IDialogSettings; 23 import org.eclipse.jface.viewers.ArrayContentProvider; 24 import org.eclipse.jface.viewers.CheckStateChangedEvent; 25 import org.eclipse.jface.viewers.CheckboxTableViewer; 26 import org.eclipse.jface.viewers.ICheckStateListener; 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.graphics.Point; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.swt.widgets.Control; 32 import org.eclipse.swt.widgets.Shell; 33 import org.eclipse.swt.widgets.Table; 34 import org.eclipse.ui.IWorkingSet; 35 import org.eclipse.ui.PlatformUI; 36 import org.eclipse.ui.dialogs.SelectionDialog; 37 import org.eclipse.ui.model.AdaptableList; 38 39 45 public class SelectBreakpointWorkingsetDialog extends SelectionDialog { 46 47 private static final String SETTINGS_ID = DebugUIPlugin.getUniqueIdentifier() + ".DELETE_ASSOCIATED_CONFIGS_DIALOG"; private Object fInitialSelection = null; 49 private Object [] fResult = null; 50 private CheckboxTableViewer fViewer = null; 51 52 58 protected SelectBreakpointWorkingsetDialog(Shell parentShell, Object selection) { 59 super(parentShell); 60 setShellStyle(getShellStyle() | SWT.RESIZE); 61 fInitialSelection = selection; 62 } 63 64 68 private IWorkingSet[] getBreakpointWorkingSets() { 69 IWorkingSet[] ws = PlatformUI.getWorkbench().getWorkingSetManager().getAllWorkingSets(); 70 ArrayList list = new ArrayList (); 71 for(int i = 0; i < ws.length; i++) { 72 if(IInternalDebugUIConstants.ID_BREAKPOINT_WORKINGSET.equals(ws[i].getId())) { 73 list.add(ws[i]); 74 } 75 } 76 return (IWorkingSet[]) list.toArray(new IWorkingSet[list.size()]); 77 } 78 79 82 protected Control createDialogArea(Composite parent) { 83 initializeDialogUnits(parent); 84 Composite comp = (Composite) super.createDialogArea(parent); 85 SWTFactory.createLabel(comp, BreakpointGroupMessages.SelectBreakpointWorkingsetDialog_0, 2); 86 Table table = new Table(comp, SWT.BORDER | SWT.CHECK | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE); 87 fViewer = new CheckboxTableViewer(table); 88 GridData gd = new GridData(GridData.FILL_BOTH); 89 gd.horizontalSpan = 2; 90 table.setLayoutData(gd); 91 fViewer.setContentProvider(new ArrayContentProvider()); 92 fViewer.setInput(new AdaptableList(getBreakpointWorkingSets()).getChildren()); 93 fViewer.setLabelProvider(DebugUITools.newDebugModelPresentation()); 94 if(fInitialSelection != null) { 95 fViewer.setChecked(fInitialSelection, true); 96 } 97 fViewer.addCheckStateListener(new ICheckStateListener() { 98 public void checkStateChanged(CheckStateChangedEvent event) { 99 fViewer.setCheckedElements(new Object [] {event.getElement()}); 100 getButton(IDialogConstants.OK_ID).setEnabled(true); 101 } 102 }); 103 Dialog.applyDialogFont(comp); 104 PlatformUI.getWorkbench().getHelpSystem().setHelp(comp, IDebugHelpContextIds.SELECT_DEFAULT_WORKINGSET_DIALOG); 105 return comp; 106 } 107 108 111 protected Control createButtonBar(Composite parent) { 112 Control control = super.createButtonBar(parent); 113 getButton(IDialogConstants.OK_ID).setEnabled(fViewer.getCheckedElements().length > 0); 114 return control; 115 } 116 117 120 protected IDialogSettings getDialogBoundsSettings() { 121 IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings(); 122 IDialogSettings section = settings.getSection(SETTINGS_ID); 123 if (section == null) { 124 section = settings.addNewSection(SETTINGS_ID); 125 } 126 return section; 127 } 128 129 132 protected Point getInitialSize() { 133 IDialogSettings settings = getDialogBoundsSettings(); 134 if(settings != null) { 135 try { 136 int width = settings.getInt("DIALOG_WIDTH"); int height = settings.getInt("DIALOG_HEIGHT"); if(width > 0 & height > 0) { 139 return new Point(width, height); 140 } 141 } 142 catch (NumberFormatException nfe) { 143 return new Point(350, 400); 144 } 145 } 146 return new Point(350, 400); 147 } 148 149 152 public Object [] getResult() { 153 return fResult; 154 } 155 156 159 protected void okPressed() { 160 fResult = fViewer.getCheckedElements(); 161 super.okPressed(); 163 } 164 165 } 166 | Popular Tags |