1 11 package org.eclipse.jdt.internal.ui.wizards; 12 13 import java.util.Iterator ; 14 import java.util.List ; 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 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 fOldContent; 55 56 70 public SuperInterfaceSelectionDialog(Shell parent, IRunnableContext context, NewTypeWizardPage page, IJavaProject p) { 71 super(parent, true, context, createSearchScope(p), IJavaSearchConstants.INTERFACE); 72 fTypeWizardPage= page; 73 fOldContent= fTypeWizardPage.getSuperInterfaces(); 75 setStatusLineAboveButtons(true); 76 } 77 78 81 protected void createButtonsForButtonBar(Composite parent) { 82 createButton(parent, ADD_ID, NewWizardMessages.SuperInterfaceSelectionDialog_addButton_label, true); 83 super.createButtonsForButtonBar(parent); 84 } 85 86 89 protected IDialogSettings getDialogBoundsSettings() { 90 return JavaPlugin.getDefault().getDialogSettingsSection("DialogBounds_SuperInterfaceSelectionDialog"); } 92 93 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 106 protected void handleShellCloseEvent() { 107 super.handleShellCloseEvent(); 108 fTypeWizardPage.setSuperInterfaces(fOldContent, true); 110 } 111 112 115 protected void cancelPressed() { 116 fTypeWizardPage.setSuperInterfaces(fOldContent, true); 117 super.cancelPressed(); 118 } 119 120 123 protected void buttonPressed(int buttonId) { 124 if (buttonId == ADD_ID) { 125 addSelectedInterfaces(); 126 } else { 127 super.buttonPressed(buttonId); 128 } 129 } 130 131 134 protected void okPressed() { 135 addSelectedInterfaces(); 136 super.okPressed(); 137 } 138 139 142 private void addSelectedInterfaces() { 143 StructuredSelection selection= getSelectedItems(); 144 if (selection == null) 145 return; 146 for (Iterator iter= selection.iterator(); iter.hasNext();) { 147 Object obj= iter.next(); 148 if (obj instanceof TypeNameMatch) { 149 accessedHistoryItem(obj); 150 TypeNameMatch type= (TypeNameMatch) obj; 151 String qualifiedName= JavaModelUtil.getFullyQualifiedName(type.getType()); 152 String 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 167 private static IJavaSearchScope createSearchScope(IJavaProject p) { 168 return SearchEngine.createJavaSearchScope(new IJavaProject[] { p }); 169 } 170 171 174 protected void handleDoubleClick() { 175 buttonPressed(ADD_ID); 176 } 177 178 181 protected void handleSelected(StructuredSelection selection) { 182 super.handleSelected(selection); 183 184 if (selection.size() == 0 && fTypeWizardPage.getSuperInterfaces().size() > fOldContent.size()) { 185 191 updateStatus(new Status(IStatus.OK, JavaPlugin.getPluginId(), IStatus.OK, "", null)); 193 getButton(ADD_ID).setEnabled(false); 194 } else { 195 getButton(ADD_ID).setEnabled(getButton(OK).isEnabled()); 198 } 199 } 200 201 202 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 |