KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.debug.internal.ui.DebugUIPlugin;
14 import org.eclipse.debug.internal.ui.DefaultLabelProvider;
15 import org.eclipse.debug.internal.ui.SWTFactory;
16 import org.eclipse.jface.dialogs.Dialog;
17 import org.eclipse.jface.dialogs.IDialogSettings;
18 import org.eclipse.jface.viewers.ArrayContentProvider;
19 import org.eclipse.jface.viewers.IBaseLabelProvider;
20 import org.eclipse.jface.viewers.IContentProvider;
21 import org.eclipse.jface.viewers.StructuredViewer;
22 import org.eclipse.swt.graphics.Point;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Control;
25 import org.eclipse.swt.widgets.Shell;
26 import org.eclipse.ui.PlatformUI;
27 import org.eclipse.ui.dialogs.SelectionDialog;
28
29 /**
30  * This class provides the framework for general selection dialog class.
31  *
32  * TODO Use this abstract class hierarchy instead of the SelectionDialog for dialogs in the debug plugin
33  *
34  * @see AbstractDebugListSelectionDialog
35  * @see AbstractDebugCheckboxSelectionDialog
36  *
37  * @since 3.3
38  */

39 public abstract class AbstractDebugSelectionDialog extends SelectionDialog {
40
41     protected StructuredViewer fViewer = null;
42     
43     /**
44      * Constructor
45      * @param parentShell
46      */

47     public AbstractDebugSelectionDialog(Shell parentShell) {
48         super(parentShell);
49     }
50     
51     /**
52      * returns the dialog settings area id
53      * @return the id of the dialog settings area
54      */

55     protected abstract String JavaDoc getDialogSettingsId();
56     
57     /**
58      * Returns the object to use as input for the viewer
59      * @return the object to use as input for the viewer
60      */

61     protected abstract Object JavaDoc getViewerInput();
62     
63     /**
64      * Create and return a viewer to use in this dialog.
65      *
66      * @param parent the composite the viewer should be created in
67      * @return the viewer to use in the dialog
68      */

69     protected abstract StructuredViewer createViewer(Composite parent);
70     
71     /**
72      * Returns the content provider for the viewer
73      * @return the content provider for the viewer
74      */

75     protected IContentProvider getContentProvider() {
76         //by default return a simple array content provider
77
return new ArrayContentProvider();
78     }
79     
80     /**
81      * Returns the label provider used by the viewer
82      * @return the label provider used in the viewer
83      */

84     protected IBaseLabelProvider getLabelProvider() {
85         return new DefaultLabelProvider();
86     }
87     
88     /**
89      * Returns the help context id for this dialog
90      * @return the help context id for this dialog
91      */

92     abstract protected String JavaDoc getHelpContextId();
93     
94     /**
95      * This method allows listeners to be added to the viewer after it
96      * is created.
97      */

98     /**
99      * This method allows listeners to be added to the viewer. Called
100      * after the viewer has been created and its input set.
101      *
102      * @param viewer the viewer returned by createViewer()
103      */

104     protected void addViewerListeners(StructuredViewer viewer){
105         //do nothing by default
106
}
107     
108     /**
109      * This method allows custom controls to be added before the viewer
110      * @param parent the parent composite to add these custom controls to
111      */

112     protected void addCustomHeaderControls(Composite parent) {
113         //do nothing by default
114
}
115     
116     /**
117      * This method allows custom controls to be added after the viewer
118      * @param parent the parent composite to add these controls to
119      */

120     protected void addCustomFooterControls(Composite parent) {
121         //do nothing by default
122
}
123     
124     /**
125      * This method allows the newly created controls to be initialized, with this method being called from
126      * the createDialogArea method
127      */

128     protected void initializeControls() {
129         //do nothing by default
130
}
131     
132     /* (non-Javadoc)
133      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
134      */

135     protected Control createDialogArea(Composite parent) {
136         initializeDialogUnits(parent);
137         Composite comp = (Composite) super.createDialogArea(parent);
138         addCustomHeaderControls(comp);
139         String JavaDoc label = getMessage();
140         if(label != null && !"".equals(label)) { //$NON-NLS-1$
141
SWTFactory.createWrapLabel(comp, label, 1);
142         }
143         label = getViewerLabel();
144         if(label != null && !"".equals(label)) { //$NON-NLS-1$
145
SWTFactory.createLabel(comp, label, 1);
146         }
147         fViewer = createViewer(comp);
148         fViewer.setLabelProvider(getLabelProvider());
149         fViewer.setContentProvider(getContentProvider());
150         fViewer.setInput(getViewerInput());
151         addViewerListeners(fViewer);
152         addCustomFooterControls(comp);
153         initializeControls();
154         Dialog.applyDialogFont(comp);
155         String JavaDoc help = getHelpContextId();
156         if(help != null) {
157             PlatformUI.getWorkbench().getHelpSystem().setHelp(comp, help);
158         }
159         return comp;
160     }
161     
162     /**
163      * This method returns the label describing what to do with the viewer. Typically this label
164      * will include the key accelerator to get to the viewer via the keyboard
165      * @return the label for the viewer
166      */

167     abstract protected String JavaDoc getViewerLabel();
168     
169     /* (non-Javadoc)
170      * @see org.eclipse.ui.dialogs.SelectionDialog#getDialogBoundsSettings()
171      */

172     protected IDialogSettings getDialogBoundsSettings() {
173         IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings();
174         IDialogSettings section = settings.getSection(getDialogSettingsId());
175         if (section == null) {
176             section = settings.addNewSection(getDialogSettingsId());
177         }
178         return section;
179     }
180
181     /* (non-Javadoc)
182      * @see org.eclipse.jface.dialogs.Dialog#getInitialSize()
183      */

184     protected Point getInitialSize() {
185         IDialogSettings settings = getDialogBoundsSettings();
186         if(settings != null) {
187             try {
188                 int width = settings.getInt("DIALOG_WIDTH"); //$NON-NLS-1$
189
int height = settings.getInt("DIALOG_HEIGHT"); //$NON-NLS-1$
190
if(width > 0 & height > 0) {
191                     return new Point(width, height);
192                 }
193             }
194             catch (NumberFormatException JavaDoc nfe) {
195                 return new Point(300, 350);
196             }
197         }
198         return new Point(300, 350);
199     }
200     
201 }
202
Popular Tags