KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mountainminds > eclemma > internal > ui > dialogs > MergeSessionsDialog


1 /*******************************************************************************
2  * Copyright (c) 2006 Mountainminds GmbH & Co. KG
3  * This software is provided under the terms of the Eclipse Public License v1.0
4  * See http://www.eclipse.org/legal/epl-v10.html.
5  *
6  * $Id: MergeSessionsDialog.java 372 2007-07-18 18:41:10Z mtnminds $
7  ******************************************************************************/

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 /**
34  * Dialog to select session to merge and enter a description for the result.
35  *
36  * @author Marc R. Hoffmann
37  * @version $Revision: 372 $
38  */

39 public class MergeSessionsDialog extends ListSelectionDialog {
40
41   private String JavaDoc description;
42
43   private Text textdescr;
44
45   /**
46    * Creates a new dialog with the given session list and description preset.
47    *
48    * @param parent
49    * parent shell
50    * @param sessions
51    * List of session the user can select from
52    * @param description
53    * Preset value for the description
54    */

55   public MergeSessionsDialog(Shell parent, ICoverageSession[] sessions,
56       String JavaDoc 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   /**
66    * Returns the session description entered by the user.
67    *
68    * @return session description
69    */

70   public String JavaDoc 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