1 11 package org.eclipse.pde.internal.ui.launcher; 12 import java.util.ArrayList ; 13 import java.util.Enumeration ; 14 import java.util.Hashtable ; 15 import java.util.Map ; 16 import java.util.Properties ; 17 import java.util.StringTokenizer ; 18 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.debug.core.ILaunchConfiguration; 21 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 22 import org.eclipse.jface.dialogs.Dialog; 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.jface.viewers.ISelectionChangedListener; 28 import org.eclipse.jface.viewers.IStructuredSelection; 29 import org.eclipse.jface.viewers.SelectionChangedEvent; 30 import org.eclipse.jface.viewers.StructuredSelection; 31 import org.eclipse.pde.core.plugin.IPluginModelBase; 32 import org.eclipse.pde.internal.core.ModelEntry; 33 import org.eclipse.pde.internal.core.PDECore; 34 import org.eclipse.pde.internal.core.PluginModelManager; 35 import org.eclipse.pde.internal.core.TracingOptionsManager; 36 import org.eclipse.pde.internal.ui.IHelpContextIds; 37 import org.eclipse.pde.internal.ui.PDEPlugin; 38 import org.eclipse.pde.internal.ui.PDEPluginImages; 39 import org.eclipse.pde.internal.ui.PDEUIMessages; 40 import org.eclipse.pde.internal.ui.util.SWTUtil; 41 import org.eclipse.pde.internal.ui.wizards.ListUtil; 42 import org.eclipse.swt.SWT; 43 import org.eclipse.swt.custom.SashForm; 44 import org.eclipse.swt.events.SelectionAdapter; 45 import org.eclipse.swt.events.SelectionEvent; 46 import org.eclipse.swt.graphics.Image; 47 import org.eclipse.swt.layout.FillLayout; 48 import org.eclipse.swt.layout.GridData; 49 import org.eclipse.swt.layout.GridLayout; 50 import org.eclipse.swt.widgets.Button; 51 import org.eclipse.swt.widgets.Composite; 52 import org.eclipse.swt.widgets.Control; 53 import org.eclipse.swt.widgets.Label; 54 import org.eclipse.ui.PlatformUI; 55 import org.eclipse.ui.forms.widgets.FormToolkit; 56 import org.eclipse.ui.forms.widgets.ScrolledPageBook; 57 public class TracingLauncherTab extends AbstractLauncherTab 58 implements 59 ILauncherSettings { 60 private Button fTracingCheck; 61 private CheckboxTableViewer fPluginViewer; 62 private IPluginModelBase[] fTraceableModels; 63 private Properties fMasterOptions = new Properties (); 64 private Hashtable fPropertySources = new Hashtable (); 65 private FormToolkit fToolkit; 66 private ScrolledPageBook fPageBook; 67 private Label fPropertyLabel; 68 private Image fImage; 69 private Button fSelectAllButton; 70 private Button fDeselectAllButton; 71 public TracingLauncherTab() { 72 PDEPlugin.getDefault().getLabelProvider().connect(this); 73 fImage = PDEPluginImages.DESC_DOC_SECTION_OBJ.createImage(); 74 } 75 public void createControl(Composite parent) { 76 Composite container = new Composite(parent, SWT.NULL); 77 container.setLayout(new GridLayout()); 78 createEnableTracingButton(container); 79 Label separator = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL); 80 separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 81 createSashSection(container); 82 createButtonSection(container); 83 setControl(container); 84 Dialog.applyDialogFont(container); 85 PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.LAUNCHER_TRACING); 86 } 87 private void createButtonSection(Composite parent) { 88 Composite container = new Composite(parent, SWT.NONE); 89 GridLayout layout = new GridLayout(); 90 layout.numColumns = 2; 91 container.setLayout(layout); 92 fSelectAllButton = new Button(container, SWT.PUSH); 93 fSelectAllButton.setText(PDEUIMessages.TracingLauncherTab_selectAll); fSelectAllButton.setLayoutData(new GridData( 95 GridData.HORIZONTAL_ALIGN_BEGINNING)); 96 SWTUtil.setButtonDimensionHint(fSelectAllButton); 97 fSelectAllButton.addSelectionListener(new SelectionAdapter() { 98 public void widgetSelected(SelectionEvent e) { 99 fPluginViewer.setAllChecked(true); 100 updateLaunchConfigurationDialog(); 101 } 102 }); 103 fDeselectAllButton = new Button(container, SWT.PUSH); 104 fDeselectAllButton.setText(PDEUIMessages.TracinglauncherTab_deselectAll); fDeselectAllButton.setLayoutData(new GridData( 106 GridData.HORIZONTAL_ALIGN_BEGINNING)); 107 SWTUtil.setButtonDimensionHint(fDeselectAllButton); 108 fDeselectAllButton.addSelectionListener(new SelectionAdapter() { 109 public void widgetSelected(SelectionEvent e) { 110 fPluginViewer.setAllChecked(false); 111 updateLaunchConfigurationDialog(); 112 } 113 }); 114 } 115 private void createEnableTracingButton(Composite container) { 116 fTracingCheck = new Button(container, SWT.CHECK); 117 fTracingCheck.setText(PDEUIMessages.TracingLauncherTab_tracing); fTracingCheck.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 119 fTracingCheck.addSelectionListener(new SelectionAdapter() { 120 public void widgetSelected(SelectionEvent e) { 121 masterCheckChanged(true); 122 updateLaunchConfigurationDialog(); 123 } 124 }); 125 } 126 private void createSashSection(Composite container) { 127 SashForm sashForm = new SashForm(container, SWT.HORIZONTAL); 128 sashForm.setLayoutData(new GridData(GridData.FILL_BOTH)); 129 createPluginViewer(sashForm); 130 createPropertySheetClient(sashForm); 131 } 132 private void createPluginViewer(Composite sashForm) { 133 Composite composite = new Composite(sashForm, SWT.NULL); 134 GridLayout layout = new GridLayout(); 135 layout.marginWidth = layout.marginHeight = 1; 136 composite.setLayout(layout); 137 Label label = new Label(composite, SWT.NULL); 138 label 139 .setText(PDEUIMessages.TracingLauncherTab_plugins); fPluginViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER); 141 fPluginViewer.setContentProvider(new ArrayContentProvider()); 142 fPluginViewer.setLabelProvider(PDEPlugin.getDefault() 143 .getLabelProvider()); 144 fPluginViewer.setSorter(new ListUtil.PluginSorter()); 145 fPluginViewer 146 .addSelectionChangedListener(new ISelectionChangedListener() { 147 public void selectionChanged(SelectionChangedEvent e) { 148 pluginSelected(getSelectedModel()); 149 } 150 }); 151 fPluginViewer.addCheckStateListener(new ICheckStateListener() { 152 public void checkStateChanged(CheckStateChangedEvent event) { 153 updateLaunchConfigurationDialog(); 154 } 155 }); 156 GridData gd = new GridData(GridData.FILL_BOTH); 157 gd.widthHint = 125; 158 gd.heightHint = 100; 159 fPluginViewer.getTable().setLayoutData(gd); 160 fPluginViewer.setInput(getTraceableModels()); 161 } 162 private void createPropertySheetClient(Composite sashForm) { 163 Composite tableChild = new Composite(sashForm, SWT.NULL); 164 GridLayout layout = new GridLayout(); 165 layout.marginHeight = layout.marginWidth = 0; 166 tableChild.setLayout(layout); 167 fPropertyLabel = new Label(tableChild, SWT.NULL); 168 fPropertyLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 169 updatePropertyLabel(null); 170 int margin = createPropertySheet(tableChild); 171 layout.marginWidth = layout.marginHeight = margin; 172 } 173 protected int createPropertySheet(Composite parent) { 174 fToolkit = new FormToolkit(parent.getDisplay()); 175 int toolkitBorderStyle = fToolkit.getBorderStyle(); 176 int style = toolkitBorderStyle == SWT.BORDER ? SWT.NULL : SWT.BORDER; 177 178 Composite container = new Composite(parent, style); 179 FillLayout flayout = new FillLayout(); 180 flayout.marginWidth = 1; 181 flayout.marginHeight = 1; 182 container.setLayout(flayout); 183 container.setLayoutData(new GridData(GridData.FILL_BOTH)); 184 185 fPageBook = new ScrolledPageBook(container, style | SWT.V_SCROLL | SWT.H_SCROLL); 186 fToolkit.adapt(fPageBook, false, false); 187 188 if (style == SWT.NULL) { 189 fPageBook.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER); 190 fToolkit.paintBordersFor(container); 191 } 192 return style == SWT.NULL ? 2 : 0; 193 } 194 public void activated(ILaunchConfigurationWorkingCopy workingCopy) { 195 fPageBook.getParent().getParent().layout(true); 196 } 197 public void dispose() { 198 if (fToolkit != null) 199 fToolkit.dispose(); 200 if (fImage != null) 201 fImage.dispose(); 202 PDEPlugin.getDefault().getLabelProvider().disconnect(this); 203 super.dispose(); 204 } 205 public FormToolkit getToolkit() { 206 return fToolkit; 207 } 208 private IPluginModelBase[] getTraceableModels() { 209 if (fTraceableModels == null) { 210 PluginModelManager manager = PDECore.getDefault().getModelManager(); 211 IPluginModelBase[] models = manager.getPlugins(); 212 ArrayList result = new ArrayList (); 213 for (int i = 0; i < models.length; i++) { 214 if (TracingOptionsManager.isTraceable(models[i])) 215 result.add(models[i]); 216 } 217 fTraceableModels = (IPluginModelBase[]) result 218 .toArray(new IPluginModelBase[result.size()]); 219 } 220 return fTraceableModels; 221 } 222 private TracingPropertySource getPropertySource(IPluginModelBase model) { 223 if (model == null) 224 return null; 225 TracingPropertySource source = (TracingPropertySource) fPropertySources 226 .get(model); 227 if (source == null) { 228 String id = model.getPluginBase().getId(); 229 Hashtable defaults = PDECore.getDefault() 230 .getTracingOptionsManager().getTemplateTable(id); 231 source = new TracingPropertySource(model, fMasterOptions, 232 defaults, this); 233 fPropertySources.put(model, source); 234 } 235 return source; 236 } 237 private void masterCheckChanged(boolean userChange) { 238 boolean enabled = fTracingCheck.getSelection(); 239 fPluginViewer.getTable().setEnabled(enabled); 240 Control currentPage = fPageBook.getCurrentPage(); 241 if (currentPage != null) 242 currentPage.setEnabled(enabled); 243 fSelectAllButton.setEnabled(enabled); 244 fDeselectAllButton.setEnabled(enabled); 245 } 246 private void disposePropertySources() { 247 for (Enumeration elements = fPropertySources.elements(); elements 248 .hasMoreElements();) { 249 TracingPropertySource source = (TracingPropertySource) elements 250 .nextElement(); 251 fPageBook.removePage(source.getModel()); 252 } 253 fPropertySources.clear(); 254 } 255 256 public void initializeFrom(ILaunchConfiguration config) { 257 fMasterOptions.clear(); 258 disposePropertySources(); 259 try { 260 fTracingCheck.setSelection(config.getAttribute(TRACING, false)); 261 Map options = config.getAttribute(TRACING_OPTIONS, (Map ) null); 262 if (options == null) 263 options = PDECore.getDefault().getTracingOptionsManager() 264 .getTracingTemplateCopy(); 265 else 266 options = PDECore.getDefault().getTracingOptionsManager() 267 .getTracingOptions(options); 268 fMasterOptions.putAll(options); 269 masterCheckChanged(false); 270 IPluginModelBase model = getLastSelectedPlugin(config); 271 if (model != null) { 272 fPluginViewer.setSelection(new StructuredSelection(model)); 273 } else { 274 pluginSelected(null); 275 } 276 String checked = config 277 .getAttribute(TRACING_CHECKED, (String ) null); 278 if (checked == null) { 279 fPluginViewer.setAllChecked(true); 280 } else if (checked.equals(TRACING_NONE)) { 281 fPluginViewer.setAllChecked(false); 282 } else { 283 StringTokenizer tokenizer = new StringTokenizer (checked, ","); ArrayList list = new ArrayList (); 285 PluginModelManager manager = PDECore.getDefault() 286 .getModelManager(); 287 while (tokenizer.hasMoreTokens()) { 288 String id = tokenizer.nextToken(); 289 ModelEntry entry = manager.findEntry(id); 290 if (entry != null) { 291 list.add(entry.getActiveModel()); 292 } 293 } 294 fPluginViewer.setCheckedElements(list.toArray()); 295 } 296 } catch (CoreException e) { 297 PDEPlugin.logException(e); 298 } 299 } 300 private IPluginModelBase getLastSelectedPlugin(ILaunchConfiguration config) 301 throws CoreException { 302 String pluginID = config.getAttribute(TRACING_SELECTED_PLUGIN, 303 (String ) null); 304 if (pluginID != null) { 305 ModelEntry entry = PDECore.getDefault().getModelManager() 306 .findEntry(pluginID); 307 return (entry == null) ? null : entry.getActiveModel(); 308 } 309 return null; 310 } 311 public void performApply(ILaunchConfigurationWorkingCopy config) { 312 boolean tracingEnabled = fTracingCheck.getSelection(); 313 config.setAttribute(TRACING, tracingEnabled); 314 if (tracingEnabled) { 315 IPluginModelBase model = getSelectedModel(); 316 String id = (model == null) ? null : model.getPluginBase().getId(); 317 config.setAttribute(TRACING_SELECTED_PLUGIN, id); 318 boolean changes = false; 319 for (Enumeration elements = fPropertySources.elements(); elements 320 .hasMoreElements();) { 321 TracingPropertySource source = (TracingPropertySource) elements 322 .nextElement(); 323 if (source.isModified()) { 324 changes = true; 325 source.save(); 326 } 327 } 328 if (changes) 329 config.setAttribute(TRACING_OPTIONS, fMasterOptions); 330 } else { 331 config.setAttribute(TRACING_SELECTED_PLUGIN, (String ) null); 332 } 333 Object [] checked = fPluginViewer.getCheckedElements(); 334 if (checked.length == fPluginViewer.getTable().getItemCount()) { 335 config.setAttribute(TRACING_CHECKED, (String ) null); 336 } else if (checked.length == 0) { 337 config.setAttribute(TRACING_CHECKED, TRACING_NONE); 338 } else { 339 StringBuffer buffer = new StringBuffer (); 340 for (int i = 0; i < checked.length; i++) { 341 IPluginModelBase model = (IPluginModelBase) checked[i]; 342 buffer.append(model.getPluginBase().getId()); 343 if (i < checked.length - 1) 344 buffer.append(','); 345 } 346 config.setAttribute(TRACING_CHECKED, buffer.toString()); 347 } 348 } 349 public void setDefaults(ILaunchConfigurationWorkingCopy config) { 350 config.setAttribute(TRACING, false); 351 config.setAttribute(TRACING_CHECKED, TRACING_NONE); 352 } 353 private void updatePropertyLabel(IPluginModelBase model) { 354 String text = (model == null) ? PDEUIMessages.TracingLauncherTab_options : PDEPlugin .getDefault().getLabelProvider().getText(model); 356 fPropertyLabel.setText(text); 357 } 358 private void pluginSelected(IPluginModelBase model) { 359 TracingPropertySource source = getPropertySource(model); 360 if (source==null) 361 fPageBook.showEmptyPage(); 362 else { 363 if (!fPageBook.hasPage(model)) { 364 Composite parent = fPageBook.createPage(model); 365 source.createContents(parent); 366 } 367 fPageBook.showPage(model); 368 } 369 updatePropertyLabel(model); 370 } 371 public String getName() { 372 return PDEUIMessages.TracingLauncherTab_name; } 374 public Image getImage() { 375 return fImage; 376 } 377 private IPluginModelBase getSelectedModel() { 378 if (fTracingCheck.isEnabled()) { 379 Object item = ((IStructuredSelection) fPluginViewer.getSelection()) 380 .getFirstElement(); 381 if (item instanceof IPluginModelBase) 382 return ((IPluginModelBase) item); 383 } 384 return null; 385 } 386 } 387 | Popular Tags |