1 8 package com.mountainminds.eclemma.internal.ui.dialogs; 9 10 import org.eclipse.jface.dialogs.IDialogConstants; 11 import org.eclipse.jface.viewers.ArrayContentProvider; 12 import org.eclipse.jface.viewers.CheckStateChangedEvent; 13 import org.eclipse.jface.viewers.ICheckStateListener; 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.events.ModifyEvent; 16 import org.eclipse.swt.events.ModifyListener; 17 import org.eclipse.swt.events.SelectionAdapter; 18 import org.eclipse.swt.events.SelectionEvent; 19 import org.eclipse.swt.layout.GridData; 20 import org.eclipse.swt.widgets.Button; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.Control; 23 import org.eclipse.swt.widgets.Label; 24 import org.eclipse.swt.widgets.Shell; 25 import org.eclipse.swt.widgets.Text; 26 import org.eclipse.ui.dialogs.ListSelectionDialog; 27 import org.eclipse.ui.model.WorkbenchLabelProvider; 28 29 import com.mountainminds.eclemma.core.ICoverageSession; 30 import com.mountainminds.eclemma.internal.ui.ContextHelp; 31 import com.mountainminds.eclemma.internal.ui.UIMessages; 32 33 39 public class MergeSessionsDialog extends ListSelectionDialog { 40 41 private String description; 42 43 private Text textdescr; 44 45 55 public MergeSessionsDialog(Shell parent, ICoverageSession[] sessions, 56 String description) { 57 super(parent, sessions, new ArrayContentProvider(), 58 new WorkbenchLabelProvider(), 59 UIMessages.MergeSessionsDialogSelection_label); 60 setTitle(UIMessages.MergeSessionsDialog_title); 61 setInitialSelections(sessions); 62 this.description = description; 63 } 64 65 70 public String getDescription() { 71 return description; 72 } 73 74 protected void configureShell(Shell shell) { 75 super.configureShell(shell); 76 ContextHelp.setHelp(shell, ContextHelp.MERGE_SESSIONS); 77 } 78 79 protected Label createMessageArea(Composite composite) { 80 Label l = new Label(composite, SWT.NONE); 81 l.setFont(composite.getFont()); 82 l.setText(UIMessages.MergeSessionsDialogDescription_label); 83 84 textdescr = new Text(composite, SWT.BORDER); 85 textdescr.setFont(composite.getFont()); 86 textdescr.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 87 textdescr.setText(description); 88 textdescr.addModifyListener(new ModifyListener() { 89 public void modifyText(ModifyEvent e) { 90 updateButtonsEnableState(); 91 } 92 }); 93 94 return super.createMessageArea(composite); 95 } 96 97 protected Control createDialogArea(Composite parent) { 98 Control c = super.createDialogArea(parent); 99 getViewer().addCheckStateListener(new ICheckStateListener() { 100 public void checkStateChanged(CheckStateChangedEvent event) { 101 updateButtonsEnableState(); 102 } 103 }); 104 Button b1 = getButton(IDialogConstants.SELECT_ALL_ID); 105 b1.addSelectionListener(new SelectionAdapter() { 106 public void widgetSelected(SelectionEvent e) { 107 updateButtonsEnableState(); 108 } 109 }); 110 Button b2 = getButton(IDialogConstants.DESELECT_ALL_ID); 111 b2.addSelectionListener(new SelectionAdapter() { 112 public void widgetSelected(SelectionEvent e) { 113 updateButtonsEnableState(); 114 } 115 }); 116 return c; 117 } 118 119 protected void okPressed() { 120 description = textdescr.getText().trim(); 121 super.okPressed(); 122 } 123 124 protected void updateButtonsEnableState() { 125 Button okButton = getOkButton(); 126 if (okButton != null && !okButton.isDisposed()) { 127 okButton.setEnabled(getViewer().getCheckedElements().length > 1 128 && textdescr.getText().trim().length() > 0); 129 } 130 } 131 132 } 133 | Popular Tags |