KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > wizards > SuperInterfaceSelectionDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jdt.internal.ui.wizards;
12
13 import java.util.Iterator JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18
19 import org.eclipse.swt.widgets.Button;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Shell;
22
23 import org.eclipse.jface.dialogs.IDialogConstants;
24 import org.eclipse.jface.dialogs.IDialogSettings;
25 import org.eclipse.jface.operation.IRunnableContext;
26 import org.eclipse.jface.viewers.StructuredSelection;
27
28 import org.eclipse.ui.PlatformUI;
29
30 import org.eclipse.jdt.core.IJavaProject;
31 import org.eclipse.jdt.core.search.IJavaSearchConstants;
32 import org.eclipse.jdt.core.search.IJavaSearchScope;
33 import org.eclipse.jdt.core.search.SearchEngine;
34 import org.eclipse.jdt.core.search.TypeNameMatch;
35
36 import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
37 import org.eclipse.jdt.internal.corext.util.Messages;
38
39 import org.eclipse.jdt.ui.wizards.NewTypeWizardPage;
40
41 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
42 import org.eclipse.jdt.internal.ui.JavaPlugin;
43 import org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog;
44 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
45
46 /**
47  * A type selection dialog providing means to open interface(s).
48  */

49 public class SuperInterfaceSelectionDialog extends OpenTypeSelectionDialog {
50
51     private static final int ADD_ID= IDialogConstants.CLIENT_ID + 1;
52
53     private NewTypeWizardPage fTypeWizardPage;
54     private List JavaDoc fOldContent;
55
56     /**
57      * Creates new instance of SuperInterfaceSelectionDialog
58      *
59      * @param parent
60      * shell to parent the dialog on
61      * @param context
62      * context used to execute long-running operations associated
63      * with this dialog
64      * @param page
65      * page that opened this dialog
66      * @param p
67      * the java project which will be considered when searching for
68      * interfaces
69      */

70     public SuperInterfaceSelectionDialog(Shell parent, IRunnableContext context, NewTypeWizardPage page, IJavaProject p) {
71         super(parent, true, context, createSearchScope(p), IJavaSearchConstants.INTERFACE);
72         fTypeWizardPage= page;
73         // to restore the content of the dialog field if the dialog is canceled
74
fOldContent= fTypeWizardPage.getSuperInterfaces();
75         setStatusLineAboveButtons(true);
76     }
77
78     /* (non-Javadoc)
79      * @see org.eclipse.ui.dialogs.SelectionDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
80      */

81     protected void createButtonsForButtonBar(Composite parent) {
82         createButton(parent, ADD_ID, NewWizardMessages.SuperInterfaceSelectionDialog_addButton_label, true);
83         super.createButtonsForButtonBar(parent);
84     }
85
86     /* (non-Javadoc)
87      * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings()
88      */

89     protected IDialogSettings getDialogBoundsSettings() {
90         return JavaPlugin.getDefault().getDialogSettingsSection("DialogBounds_SuperInterfaceSelectionDialog"); //$NON-NLS-1$
91
}
92
93     /* (non-Javadoc)
94      * @see org.eclipse.ui.dialogs.SelectionStatusDialog#updateButtonsEnableState(org.eclipse.core.runtime.IStatus)
95      */

96     protected void updateButtonsEnableState(IStatus status) {
97         super.updateButtonsEnableState(status);
98         Button addButton= getButton(ADD_ID);
99         if (addButton != null && !addButton.isDisposed())
100             addButton.setEnabled(!status.matches(IStatus.ERROR));
101     }
102
103     /* (non-Javadoc)
104      * @see org.eclipse.jface.window.Window#handleShellCloseEvent()
105      */

106     protected void handleShellCloseEvent() {
107         super.handleShellCloseEvent();
108         // Handle the closing of the shell by selecting the close icon
109
fTypeWizardPage.setSuperInterfaces(fOldContent, true);
110     }
111
112     /* (non-Javadoc)
113      * @see org.eclipse.jface.dialogs.Dialog#cancelPressed()
114      */

115     protected void cancelPressed() {
116         fTypeWizardPage.setSuperInterfaces(fOldContent, true);
117         super.cancelPressed();
118     }
119
120     /* (non-Javadoc)
121      * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
122      */

123     protected void buttonPressed(int buttonId) {
124         if (buttonId == ADD_ID) {
125             addSelectedInterfaces();
126         } else {
127             super.buttonPressed(buttonId);
128         }
129     }
130
131     /* (non-Javadoc)
132      * @see org.eclipse.ui.dialogs.SelectionStatusDialog#okPressed()
133      */

134     protected void okPressed() {
135         addSelectedInterfaces();
136         super.okPressed();
137     }
138
139     /*
140      * Adds selected interfaces to the list.
141      */

142     private void addSelectedInterfaces() {
143         StructuredSelection selection= getSelectedItems();
144         if (selection == null)
145             return;
146         for (Iterator JavaDoc iter= selection.iterator(); iter.hasNext();) {
147             Object JavaDoc obj= iter.next();
148             if (obj instanceof TypeNameMatch) {
149                 accessedHistoryItem(obj);
150                 TypeNameMatch type= (TypeNameMatch) obj;
151                 String JavaDoc qualifiedName= JavaModelUtil.getFullyQualifiedName(type.getType());
152                 String JavaDoc message;
153
154                 if (fTypeWizardPage.addSuperInterface(qualifiedName)) {
155                     message= Messages.format(NewWizardMessages.SuperInterfaceSelectionDialog_interfaceadded_info, qualifiedName);
156                 } else {
157                     message= Messages.format(NewWizardMessages.SuperInterfaceSelectionDialog_interfacealreadyadded_info, qualifiedName);
158                 }
159                 updateStatus(new StatusInfo(IStatus.INFO, message));
160             }
161         }
162     }
163
164     /*
165      * Creates a searching scope including only one project.
166      */

167     private static IJavaSearchScope createSearchScope(IJavaProject p) {
168         return SearchEngine.createJavaSearchScope(new IJavaProject[] { p });
169     }
170
171     /*(non-Javadoc)
172      * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#handleDoubleClick()
173      */

174     protected void handleDoubleClick() {
175         buttonPressed(ADD_ID);
176     }
177
178     /* (non-Javadoc)
179      * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#handleSelected(org.eclipse.jface.viewers.StructuredSelection)
180      */

181     protected void handleSelected(StructuredSelection selection) {
182         super.handleSelected(selection);
183
184         if (selection.size() == 0 && fTypeWizardPage.getSuperInterfaces().size() > fOldContent.size()) {
185             // overrides updateStatus() from handleSelected() if
186
// list of super interfaces was modified
187
// the <code>super.handleSelected(selection)</code> has to be
188
// called, because superclass implementation of this class updates
189
// state of the table.
190

191             updateStatus(new Status(IStatus.OK, JavaPlugin.getPluginId(), IStatus.OK, "", null)); //$NON-NLS-1$
192

193             getButton(ADD_ID).setEnabled(false);
194         } else {
195             // if selection isn't empty, the add button should be enabled in
196
// exactly the same scenarios as the OK button
197
getButton(ADD_ID).setEnabled(getButton(OK).isEnabled());
198         }
199     }
200
201     
202     /* (non-Javadoc)
203      * @see org.eclipse.jdt.internal.ui.dialogs.OpenTypeSelectionDialog2#configureShell(org.eclipse.swt.widgets.Shell)
204      */

205     protected void configureShell(Shell newShell) {
206         super.configureShell(newShell);
207         PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.SUPER_INTERFACE_SELECTION_DIALOG);
208     }
209 }
210
Popular Tags