KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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 org.eclipse.jface.dialogs.IDialogConstants;
14 import org.eclipse.jface.viewers.DoubleClickEvent;
15 import org.eclipse.jface.viewers.IDoubleClickListener;
16 import org.eclipse.jface.viewers.ISelection;
17 import org.eclipse.jface.viewers.ISelectionChangedListener;
18 import org.eclipse.jface.viewers.IStructuredSelection;
19 import org.eclipse.jface.viewers.SelectionChangedEvent;
20 import org.eclipse.jface.viewers.StructuredViewer;
21 import org.eclipse.jface.viewers.TableViewer;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Shell;
26
27 /**
28  * This class provides a simple selection dialog displaying items in a table.
29  *
30  * @since 3.3
31  */

32 public abstract class AbstractDebugListSelectionDialog extends AbstractDebugSelectionDialog {
33
34     protected TableViewer fListViewer;
35     
36     /**
37      * Constructor
38      * @param parentShell
39      */

40     public AbstractDebugListSelectionDialog(Shell parentShell) {
41         super(parentShell);
42         setShellStyle(getShellStyle() | SWT.RESIZE);
43     }
44     
45     /**
46      * Create and return a viewer to use in this dialog.
47      *
48      * @param parent the composite the viewer should be created in
49      * @return the viewer to use in the dialog
50      */

51     protected StructuredViewer createViewer(Composite parent){
52         //by default return a table viewer
53
fListViewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
54         fListViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
55         return fListViewer;
56     }
57     
58     /* (non-Javadoc)
59      * @see org.eclipse.debug.internal.ui.launchConfigurations.AbstractDebugSelectionDialog#addViewerListeners(org.eclipse.jface.viewers.StructuredViewer)
60      */

61     protected void addViewerListeners(StructuredViewer viewer) {
62         viewer.addSelectionChangedListener(new ISelectionChangedListener(){
63             public void selectionChanged(SelectionChangedEvent event) {
64                 getButton(IDialogConstants.OK_ID).setEnabled(false);
65                 ISelection selection = fListViewer.getSelection();
66                 if (selection instanceof IStructuredSelection){
67                     if (((IStructuredSelection)selection).size() == 1){
68                         getButton(IDialogConstants.OK_ID).setEnabled(true);
69                     }
70                 }
71             }
72         });
73         viewer.addDoubleClickListener(new IDoubleClickListener(){
74             public void doubleClick(DoubleClickEvent event) {
75                 if (getButton(IDialogConstants.OK_ID).isEnabled()){
76                     okPressed();
77                 }
78             }
79         });
80     }
81     
82     /* (non-Javadoc)
83      * @see org.eclipse.ui.dialogs.SelectionDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
84      */

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

93     protected void okPressed() {
94         ISelection selection = fViewer.getSelection();
95         if (selection instanceof IStructuredSelection) {
96             setResult(((IStructuredSelection) selection).toList());
97         }
98         super.okPressed();
99     }
100     
101 }
102
Popular Tags