KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > launchConfigurations > AbstractDebugCheckboxSelectionDialog


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.launchConfigurations;
12
13 import java.util.Arrays JavaDoc;
14
15 import org.eclipse.jface.dialogs.IDialogConstants;
16 import org.eclipse.jface.viewers.CheckStateChangedEvent;
17 import org.eclipse.jface.viewers.CheckboxTableViewer;
18 import org.eclipse.jface.viewers.ICheckStateListener;
19 import org.eclipse.jface.viewers.StructuredViewer;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Shell;
24 import org.eclipse.swt.widgets.Table;
25
26 /**
27  * This class provides selection dialog using a checkbox table viewer.
28  *
29  * @since 3.3
30  */

31 public abstract class AbstractDebugCheckboxSelectionDialog extends AbstractDebugSelectionDialog {
32     
33     /**
34      * Constructor
35      * @param parentShell
36      */

37     public AbstractDebugCheckboxSelectionDialog(Shell parentShell) {
38         super(parentShell);
39         setShellStyle(getShellStyle() | SWT.RESIZE);
40     }
41     
42     /**
43      * Returns the viewer cast to the correct instance
44      * @return
45      */

46     protected CheckboxTableViewer getCheckBoxTableViewer() {
47         return (CheckboxTableViewer) fViewer;
48     }
49     
50     /**
51      * Create and return a viewer to use in this dialog.
52      *
53      * @param parent the composite the viewer should be created in
54      * @return the viewer to use in the dialog
55      */

56     protected StructuredViewer createViewer(Composite parent){
57         //by default return a checkbox table viewer
58
Table table = new Table(parent, SWT.BORDER | SWT.SINGLE | SWT.CHECK);
59         table.setLayoutData(new GridData(GridData.FILL_BOTH));
60         return new CheckboxTableViewer(table);
61     }
62
63     /* (non-Javadoc)
64      * @see org.eclipse.debug.internal.ui.launchConfigurations.AbstractDebugSelectionDialog#addViewerListeners(org.eclipse.jface.viewers.StructuredViewer)
65      */

66     protected void addViewerListeners(StructuredViewer viewer) {
67         getCheckBoxTableViewer().addCheckStateListener(new DefaultCheckboxListener());
68     }
69     
70     /**
71      * A checkbox state listener that ensures that exactly one element is checked
72      * and enables the OK button when this is the case.
73      *
74      */

75     private class DefaultCheckboxListener implements ICheckStateListener{
76         public void checkStateChanged(CheckStateChangedEvent event) {
77             getButton(IDialogConstants.OK_ID).setEnabled(getCheckBoxTableViewer().getCheckedElements().length > 0);
78         }
79     }
80
81     /* (non-Javadoc)
82      * @see org.eclipse.ui.dialogs.SelectionDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
83      */

84     protected void createButtonsForButtonBar(Composite parent) {
85         super.createButtonsForButtonBar(parent);
86         getButton(IDialogConstants.OK_ID).setEnabled(false);
87     }
88     
89     /* (non-Javadoc)
90      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
91      */

92     protected void okPressed() {
93         Object JavaDoc[] elements = getCheckBoxTableViewer().getCheckedElements();
94         setResult(Arrays.asList(elements));
95         super.okPressed();
96     }
97         
98 }
99
Popular Tags