Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 276466 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyContentProvider.java (-36 / +94 lines)
Lines 49-70 Link Here
49
	 * constructors in the Call Hierarchy.
49
	 * constructors in the Call Hierarchy.
50
	 * <p>
50
	 * <p>
51
	 * Value is of type <code>String</code>: semicolon separated list of fully qualified type names.
51
	 * Value is of type <code>String</code>: semicolon separated list of fully qualified type names.
52
	 * <strong> It has been replaced in 3.6 by API:
53
	 * {@link PreferenceConstants#PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS_MEMBERS}</strong>
52
	 * </p>
54
	 * </p>
53
	 * 
55
	 * 
54
	 * @since 3.5
56
	 * @since 3.5
55
	 */
57
	 */
56
	public static final String PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS= "CallHierarchy.defaultExpandWithConstructors"; //$NON-NLS-1$
58
	public static final String OLD_PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS= "CallHierarchy.defaultExpandWithConstructors"; //$NON-NLS-1$
57
58
	/**
59
	 * A named preference that controls whether methods from anonymous types are by default expanded
60
	 * with constructors in the Call Hierarchy.
61
	 * <p>
62
	 * Value is of type <code>Boolean</code>.
63
	 * </p>
64
	 * 
65
	 * @since 3.5
66
	 */
67
	public static final String PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS= "CallHierarchy.anonymousExpandWithConstructors"; //$NON-NLS-1$
68
59
69
	private final static Object[] EMPTY_ARRAY= new Object[0];
60
	private final static Object[] EMPTY_ARRAY= new Object[0];
70
61
Lines 175-188 Link Here
175
166
176
		if (!wrapper.isExpandWithConstructorsSet()) {
167
		if (!wrapper.isExpandWithConstructorsSet()) {
177
			if (CallHierarchyContentProvider.canExpandWithConstructors(wrapper)) {
168
			if (CallHierarchyContentProvider.canExpandWithConstructors(wrapper)) {
178
				IType type= wrapper.getMember().getDeclaringType();
169
				IMethod method= (IMethod)wrapper.getMember();
170
				IType type= method.getDeclaringType();
179
				try {
171
				try {
180
					boolean withConstructors= false;
172
					boolean withConstructors= false;
181
					if (type != null) {
173
					if (type != null) {
182
						boolean anonymousPref= PreferenceConstants.getPreferenceStore().getBoolean(PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS);
174
						boolean anonymousPref= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS);
183
						if (anonymousPref && type.isAnonymous()) {
175
						if (anonymousPref && type.isAnonymous()) {
184
							withConstructors= true;
176
							withConstructors= true;
185
						} else if (isInTheDefaultExpandWithConstructorList(type)) {
177
						} else if (isInTheDefaultExpandWithConstructorList(method)) {
186
							withConstructors= true;
178
							withConstructors= true;
187
						}
179
						}
188
					}
180
					}
Lines 217-253 Link Here
217
	}
209
	}
218
	
210
	
219
	/**
211
	/**
220
	 * Checks if declaring type matches the pre-defined array of types for default expand with
212
	 * Checks if the method or its declaring type matches the pre-defined array of methods and types
221
	 * constructors.
213
	 * for default expand with constructors.
214
	 * 
215
	 * @param method the wrapped method
216
	 * @return <code>true</code> if method or type matches the pre-defined list, <code>false</code>
217
	 *         otherwise
222
	 * 
218
	 * 
223
	 * @param type the declaring type of the caller method wrapper
224
	 * @return <code>true</code> if type matches the pre-defined list, <code>false</code> otherwise
225
	 * @since 3.5
219
	 * @since 3.5
226
	 */
220
	 */
227
	static boolean isInTheDefaultExpandWithConstructorList(IType type) {
221
	static boolean isInTheDefaultExpandWithConstructorList(IMethod method) {
228
		String serializedTypes= PreferenceConstants.getPreferenceStore().getString(PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS);
222
		String serializedMembers= PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS_MEMBERS);
229
		if (serializedTypes.length() == 0)
223
		if (serializedMembers.length() == 0)
230
			return false;
224
			return false;
231
		
225
		String methodName= method.getElementName();
232
		String[] defaultTypes= serializedTypes.split(";"); //$NON-NLS-1$
226
		IType declaringType= method.getDeclaringType();
233
		
227
		String[] defaultMemberNames= serializedMembers.split(";"); //$NON-NLS-1$
234
		String typeName= type.getFullyQualifiedName('.');
228
235
		String superClass;
229
		String declaringTypeName= declaringType.getFullyQualifiedName('.') + ".*"; //$NON-NLS-1$;
236
		String[] superInterfaces;
230
		String qualifiedMethodName= declaringType.getFullyQualifiedName('.') + '.' + methodName;
231
		String superClassName;
232
		String[] superInterfaceNames;
237
		try {
233
		try {
238
			superClass= type.getSuperclassName();
234
			superClassName= declaringType.getSuperclassName();
239
			superInterfaces= type.getSuperInterfaceNames();
235
			if (superClassName != null) {
236
				if (superClassName.contains("<")) { //$NON-NLS-1$
237
					superClassName= stripParametersFromSuperType(superClassName);
238
				}
239
			}
240
			superInterfaceNames= declaringType.getSuperInterfaceNames();
240
		} catch (JavaModelException e) {
241
		} catch (JavaModelException e) {
241
			return false;
242
			return false;
242
		}
243
		}
243
		for (int i= 0; i < defaultTypes.length; i++) {
244
		for (int i= 0; i < defaultMemberNames.length; i++) {
244
			String defaultType= defaultTypes[i];
245
			String defaultMemberName= defaultMemberNames[i];
245
			if (typeName.equals(defaultType) || (superClass != null && typeNameMatches(superClass, defaultType))) {
246
			if (qualifiedMethodName.equals(defaultMemberName) || declaringTypeName.equals(defaultMemberName) || checkSuperTypeMatch(superClassName, defaultMemberName)
247
					|| (checkMethodInSuperType(methodName, superClassName, defaultMemberName))) {
246
				return true;
248
				return true;
247
			}
249
			}
248
			if (superInterfaces.length > 0) {
250
			if (superInterfaceNames.length > 0) {
249
				for (int j= 0; j < superInterfaces.length; j++) {
251
				for (int j= 0; j < superInterfaceNames.length; j++) {
250
					if (typeNameMatches(superInterfaces[j], defaultType))
252
					if (superInterfaceNames[j].contains("<")) { //$NON-NLS-1$
253
						superInterfaceNames[j]= stripParametersFromSuperType(superInterfaceNames[j]);
254
					}
255
					if (checkSuperTypeMatch(superInterfaceNames[j], defaultMemberName) || checkMethodInSuperType(methodName, superInterfaceNames[j], defaultMemberName))
251
						return true;
256
						return true;
252
				}
257
				}
253
			}
258
			}
Lines 256-261 Link Here
256
	}
261
	}
257
262
258
	/**
263
	/**
264
	 * Strips parameters from the given super type name and returns the substring containing only
265
	 * the type name.
266
	 * 
267
	 * @param superTypeName the super type name
268
	 * @return the substring containing only the type name without the parameters
269
	 * 
270
	 * @since 3.6
271
	 */
272
	private static String stripParametersFromSuperType(String superTypeName) {
273
		int pos= superTypeName.indexOf('<');//strip the parameters
274
		return superTypeName.substring(0, pos);
275
	}
276
277
	/**
278
	 * Check if the method in the super type matches the default member.
279
	 * 
280
	 * @param methodName the method name
281
	 * @param superTypeName the super type name
282
	 * @param defaultMemberName the member in the default list
283
	 * 
284
	 * @return <code>true</code> if the method in the super type matches the default member,
285
	 *         <code>false</code> otherwise
286
	 * 
287
	 * @since 3.6
288
	 */
289
	private static boolean checkMethodInSuperType(String methodName, String superTypeName, String defaultMemberName) {
290
		if (superTypeName != null && typeNameMatches(methodName, defaultMemberName)) {
291
			int pos= defaultMemberName.lastIndexOf('.');
292
			String defaultTypeName= defaultMemberName.substring(0, pos);
293
			return typeNameMatches(superTypeName, defaultTypeName);
294
		}
295
		return false;
296
	}
297
298
	/**
299
	 * Check whether the given super type name matches the given default type.
300
	 * 
301
	 * @param superType the super type name
302
	 * @param defaultMemberName the default member from the default list
303
	 * 
304
	 * @return <code>true</code> if super type matches with the given type in the default list,
305
	 *         <code>false></code> otherwise
306
	 * 
307
	 * @since 3.6
308
	 */
309
	private static boolean checkSuperTypeMatch(String superType, String defaultMemberName) {
310
		if (defaultMemberName.endsWith(".*")) { //$NON-NLS-1$
311
			defaultMemberName= defaultMemberName.substring(0, defaultMemberName.length() - 2);
312
		}
313
		return (superType != null && typeNameMatches(superType, defaultMemberName));
314
	}
315
316
	/**
259
	 * Checks whether the two type names match. They match if they
317
	 * Checks whether the two type names match. They match if they
260
	 * are equal, or if could be the same type but one is missing the package.
318
	 * are equal, or if could be the same type but one is missing the package.
261
	 * 
319
	 * 
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyMessages.java (-4 / +19 lines)
Lines 88-93 Link Here
88
	public static String CallHierarchyViewPart_callsFromMembers_3;
88
	public static String CallHierarchyViewPart_callsFromMembers_3;
89
	public static String CallHierarchyViewPart_callsFromMembers_more;
89
	public static String CallHierarchyViewPart_callsFromMembers_more;
90
	public static String CallHierarchyViewPart_callsFromMethod;
90
	public static String CallHierarchyViewPart_callsFromMethod;
91
	public static String ExpandWithConstructorsConfigurationBlock_description;
92
	public static String ExpandWithConstructorsConfigurationBlock_newType_button;
93
	public static String ExpandWithConstructorsConfigurationBlock_newMember_button;
94
	public static String ExpandWithConstructorsConfigurationBlock_edit_button;
95
	public static String ExpandWithConstructorsConfigurationBlock_remove_button;
96
	public static String ExpandWithConstructorsConfigurationBlock_restoreDefaults_button;
97
	public static String CallHierarchyTypesOrMembersDialog_member_title;
98
	public static String CallHierarchyTypesOrMembersDialog_member_labelText;
99
	public static String CallHierarchyTypesOrMembersDialog_type_title;
100
	public static String CallHierarchyTypesOrMembersDialog_type_labelText;
101
	public static String CallHierarchyTypesOrMembersDialog_browse_button;
102
	public static String CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_title;
103
	public static String CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_description;
104
	public static String CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_error_message;
105
	public static String CallHierarchyTypesOrMembersDialog_error_enterName;
106
	public static String CallHierarchyTypesOrMembersDialog_error_invalidMemberName;
107
	public static String CallHierarchyTypesOrMembersDialog_error_invalidTypeName;
108
	public static String CallHierarchyTypesOrMembersDialog_error_entryExists;
109
	public static String CallHierarchyTypesOrMembersDialog_anonymousTypes_label;
91
	public static String FocusOnSelectionAction_focusOnSelection_text;
110
	public static String FocusOnSelectionAction_focusOnSelection_text;
92
	public static String FocusOnSelectionAction_focusOnSelection_description;
111
	public static String FocusOnSelectionAction_focusOnSelection_description;
93
	public static String FocusOnSelectionAction_focusOnSelection_tooltip;
112
	public static String FocusOnSelectionAction_focusOnSelection_tooltip;
Lines 142-152 Link Here
142
	public static String ExpandWithConstructorsAction_expandWithConstructors_text;
161
	public static String ExpandWithConstructorsAction_expandWithConstructors_text;
143
	public static String ExpandWithConstructorsAction_expandWithConstructors_description;
162
	public static String ExpandWithConstructorsAction_expandWithConstructors_description;
144
	public static String ExpandWithConstructorsAction_expandWithConstructors_tooltip;
163
	public static String ExpandWithConstructorsAction_expandWithConstructors_tooltip;
145
	public static String ExpandWithConstructorsDialog_anonymousTypes_label;
146
	public static String ExpandWithConstructorsDialog_explanation_label;
147
	public static String ExpandWithConstructorsDialog_not_a_valid_type_name;
148
	public static String ExpandWithConstructorsDialog_title;
164
	public static String ExpandWithConstructorsDialog_title;
149
	public static String ExpandWithConstructorsDialog_typeNames_label;
150
	static {
165
	static {
151
		NLS.initializeMessages(BUNDLE_NAME, CallHierarchyMessages.class);
166
		NLS.initializeMessages(BUNDLE_NAME, CallHierarchyMessages.class);
152
	}
167
	}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyMessages.properties (-5 / +23 lines)
Lines 149-156 Link Here
149
ExpandWithConstructorsAction_expandWithConstructors_text= &Expand with Constructors
149
ExpandWithConstructorsAction_expandWithConstructors_text= &Expand with Constructors
150
ExpandWithConstructorsAction_expandWithConstructors_description= Expand with constructors
150
ExpandWithConstructorsAction_expandWithConstructors_description= Expand with constructors
151
ExpandWithConstructorsAction_expandWithConstructors_tooltip= Expand with Constructors
151
ExpandWithConstructorsAction_expandWithConstructors_tooltip= Expand with Constructors
152
ExpandWithConstructorsDialog_anonymousTypes_label=&All methods in anonymous types
152
ExpandWithConstructorsDialog_title= Expand with Constructors
153
ExpandWithConstructorsDialog_explanation_label=Configure the types whose instance methods are expanded with constructors by default.
153
154
ExpandWithConstructorsDialog_not_a_valid_type_name=''{0}'' is not a valid type name
154
ExpandWithConstructorsConfigurationBlock_description= De&fine a list of members or types with their fully qualified names. The call hierarchy for these members or members of the types will be expanded with constructors by default.
155
ExpandWithConstructorsDialog_title=Expand with Constructors
155
ExpandWithConstructorsConfigurationBlock_newType_button= New &Type...
156
ExpandWithConstructorsDialog_typeNames_label=Type &names (each on a line):
156
ExpandWithConstructorsConfigurationBlock_newMember_button= New &Member...
157
ExpandWithConstructorsConfigurationBlock_edit_button= &Edit...
158
ExpandWithConstructorsConfigurationBlock_remove_button= &Remove 
159
ExpandWithConstructorsConfigurationBlock_restoreDefaults_button= Restore &Defaults
160
161
CallHierarchyTypesOrMembersDialog_member_title= New Member for Expand With Constructors
162
CallHierarchyTypesOrMembersDialog_member_labelText= Enter a fully qualified non-static, non-constructor member (e.g. \'java.lang.Runnable.run\'): 
163
CallHierarchyTypesOrMembersDialog_type_title= New Type for Expand With Constructors
164
CallHierarchyTypesOrMembersDialog_type_labelText= Enter a fully qualified type (e.g. \'java.lang.Runnable\'):
165
CallHierarchyTypesOrMembersDialog_browse_button= &Browse...
166
CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_title= Type Selection
167
CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_description= Choose type name:
168
CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_error_message= A problem occurred while collecting types. See the error Log for details.
169
CallHierarchyTypesOrMembersDialog_error_enterName=Enter a name or prefix.
170
CallHierarchyTypesOrMembersDialog_error_invalidTypeName=Not a valid type name.
171
CallHierarchyTypesOrMembersDialog_error_invalidMemberName=Not a valid member name.
172
CallHierarchyTypesOrMembersDialog_error_entryExists=Entry already exists in list.
173
CallHierarchyTypesOrMembersDialog_anonymousTypes_label=&All methods in anonymous types
174
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/ExpandWithConstructorsConfigurationBlock.java (+619 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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
 *******************************************************************************/
9
10
package org.eclipse.jdt.internal.ui.callhierarchy;
11
12
import java.util.Arrays;
13
import java.util.List;
14
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.events.SelectionAdapter;
17
import org.eclipse.swt.events.SelectionEvent;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.layout.GridLayout;
21
import org.eclipse.swt.widgets.Button;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Control;
24
import org.eclipse.swt.widgets.Shell;
25
import org.eclipse.swt.widgets.Text;
26
27
import org.eclipse.core.runtime.Assert;
28
import org.eclipse.core.runtime.IStatus;
29
30
import org.eclipse.jface.dialogs.Dialog;
31
import org.eclipse.jface.dialogs.StatusDialog;
32
import org.eclipse.jface.layout.PixelConverter;
33
import org.eclipse.jface.operation.IRunnableContext;
34
import org.eclipse.jface.viewers.LabelProvider;
35
import org.eclipse.jface.viewers.ViewerComparator;
36
import org.eclipse.jface.window.Window;
37
38
import org.eclipse.ui.PlatformUI;
39
import org.eclipse.ui.dialogs.SelectionDialog;
40
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
41
42
import org.eclipse.jdt.core.IType;
43
import org.eclipse.jdt.core.JavaConventions;
44
import org.eclipse.jdt.core.JavaCore;
45
import org.eclipse.jdt.core.JavaModelException;
46
import org.eclipse.jdt.core.search.IJavaSearchScope;
47
import org.eclipse.jdt.core.search.SearchEngine;
48
49
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
50
import org.eclipse.jdt.ui.JavaUI;
51
import org.eclipse.jdt.ui.PreferenceConstants;
52
53
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
54
import org.eclipse.jdt.internal.ui.JavaPluginImages;
55
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
56
import org.eclipse.jdt.internal.ui.dialogs.TextFieldNavigationHandler;
57
import org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock;
58
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
59
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
60
import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
61
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
62
import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
63
import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
64
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
65
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter;
66
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
67
import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
68
import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField;
69
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
70
71
/**
72
 * Call hierarchy expand with constructors configuration block.
73
 *
74
 * @since 3.6
75
 */
76
public class ExpandWithConstructorsConfigurationBlock extends OptionsConfigurationBlock {
77
78
	/**
79
	 * Call hierarchy expand with constructors dialog for types and members.
80
	 */
81
	private static class CallHierarchyTypesOrMembersDialog extends StatusDialog {
82
83
		/**
84
		 * The change listener class for the dialog field and the string button dialog field.
85
		 *
86
		 */
87
		private class StringButtonAdapter implements IDialogFieldListener, IStringButtonAdapter {
88
			/*
89
			 * @see IDialogFieldListener#dialogFieldChanged(DialogField)
90
			 */
91
			public void dialogFieldChanged(DialogField field) {
92
				doValidation();
93
			}
94
95
			/*
96
			 * @see IStringButtonAdapter#changeControlPressed(DialogField)
97
			 */
98
			public void changeControlPressed(DialogField field) {
99
				doBrowseTypes();
100
			}
101
		}
102
103
		/**
104
		 * The name dialog field to hold the default expand with constructors list.
105
		 */
106
		private StringButtonDialogField fNameDialogField;
107
108
		/**
109
		 * The list of previously existing entries.
110
		 */
111
		private List fExistingEntries;
112
113
		/**
114
		 * Tells whether it is an member or type.
115
		 */
116
		private final boolean fIsEditingMember;
117
118
		/**
119
		 * Creates a call hierarchy preference dialog for members or types.
120
		 *
121
		 * @param parent the parent shell
122
		 * @param existingEntries the existing list of types and members
123
		 * @param isEditingMember <code>true</code if its a member, <code>false</code> otherwise
124
		 */
125
		public CallHierarchyTypesOrMembersDialog(Shell parent, List existingEntries, boolean isEditingMember) {
126
			super(parent);
127
			fIsEditingMember= isEditingMember;
128
			fExistingEntries= existingEntries;
129
130
			String label, title;
131
			if (isEditingMember) {
132
				title= CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_member_title;
133
				label= CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_member_labelText;
134
			} else {
135
				title= CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_type_title;
136
				label= CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_type_labelText;
137
			}
138
			setTitle(title);
139
140
			StringButtonAdapter adapter= new StringButtonAdapter();
141
142
			fNameDialogField= new StringButtonDialogField(adapter);
143
			fNameDialogField.setLabelText(label);
144
			fNameDialogField.setButtonLabel(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_browse_button);
145
			fNameDialogField.setDialogFieldListener(adapter);
146
			fNameDialogField.setText(""); //$NON-NLS-1$
147
		}
148
149
		/*
150
		 * @see org.eclipse.jface.dialogs.Dialog#isResizable()		 *
151
		 */
152
		protected boolean isResizable() {
153
			return true;
154
		}
155
156
		/**
157
		 * Sets the initial selection in the name dialog field.
158
		 *
159
		 * @param editedEntry the edited entry
160
		 */
161
		public void setInitialSelection(String editedEntry) {
162
			Assert.isNotNull(editedEntry);
163
			if (editedEntry.length() == 0)
164
				fNameDialogField.setText(""); //$NON-NLS-1$
165
			else
166
				fNameDialogField.setText(editedEntry);
167
		}
168
169
		/**
170
		 * Returns the resulting text from the name dialog field.
171
		 *
172
		 * @return the resulting text from the name dialog field
173
		 */
174
		public String getResult() {
175
			String val= fNameDialogField.getText();
176
			if (!fIsEditingMember)
177
				val= val + WILDCARD;
178
			return val;
179
		}
180
181
		/*
182
		 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
183
		 */
184
		protected Control createDialogArea(Composite parent) {
185
			Composite composite= (Composite)super.createDialogArea(parent);
186
			initializeDialogUnits(composite);
187
188
			GridLayout layout= (GridLayout)composite.getLayout();
189
			layout.numColumns= 2;
190
191
			fNameDialogField.doFillIntoGrid(composite, 3);
192
193
			fNameDialogField.getChangeControl(null).setVisible(!fIsEditingMember);
194
195
			LayoutUtil.setHorizontalSpan(fNameDialogField.getLabelControl(null), 2);
196
197
			int fieldWidthHint= convertWidthInCharsToPixels(60);
198
			Text text= fNameDialogField.getTextControl(null);
199
			LayoutUtil.setWidthHint(text, fieldWidthHint);
200
			LayoutUtil.setHorizontalGrabbing(text);
201
			LayoutUtil.setHorizontalSpan(text, fIsEditingMember ? 2 : 1);
202
			TextFieldNavigationHandler.install(text);
203
204
			DialogField.createEmptySpace(composite, 1);
205
206
			fNameDialogField.postSetFocusOnDialogField(parent.getDisplay());
207
208
			applyDialogFont(composite);
209
			return composite;
210
		}
211
212
		/**
213
		 * Creates the type hierarchy for type selection.
214
		 */
215
		private void doBrowseTypes() {
216
			IRunnableContext context= new BusyIndicatorRunnableContext();
217
			IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
218
			int style= IJavaElementSearchConstants.CONSIDER_ALL_TYPES;
219
			try {
220
				SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), context, scope, style, false, fNameDialogField.getText());
221
				dialog.setTitle(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_title);
222
				dialog.setMessage(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_description);
223
				if (dialog.open() == Window.OK) {
224
					IType res= (IType)dialog.getResult()[0];
225
					fNameDialogField.setText(res.getFullyQualifiedName('.'));
226
				}
227
			} catch (JavaModelException e) {
228
				ExceptionHandler.handle(e, getShell(), CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_title,
229
						CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_error_message);
230
			}
231
		}
232
233
		/**
234
		 * Validates the entered type or member and updates the status.
235
		 */
236
		private void doValidation() {
237
			StatusInfo status= new StatusInfo();
238
			String newText= fNameDialogField.getText();
239
			if (newText.length() == 0) {
240
				status.setError(""); //$NON-NLS-1$
241
			} else {
242
				IStatus val= JavaConventions.validateJavaTypeName(newText, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
243
				if (val.matches(IStatus.ERROR)) {
244
					if (fIsEditingMember)
245
						status.setError(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_error_invalidMemberName);
246
					else
247
						status.setError(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_error_invalidTypeName);
248
				} else {
249
					if (doesExist(newText)) {
250
						status.setError(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_error_entryExists);
251
					}
252
				}
253
			}
254
			updateStatus(status);
255
		}
256
257
		/**
258
		 * Checks if the entry already exists.
259
		 *
260
		 * @param name the type or member name
261
		 * @return <code>true</code> if it already exists in the list of types and members,
262
		 *         <code>false</code> otherwise
263
		 */
264
		private boolean doesExist(String name) {
265
			for (int i= 0; i < fExistingEntries.size(); i++) {
266
				String entry= (String)fExistingEntries.get(i);
267
				if (name.equals(entry)) {
268
					return true;
269
				}
270
			}
271
			return false;
272
		}
273
274
275
		/*
276
		 * @see org.eclipse.jface.window.Window#configureShell(Shell)
277
		 */
278
		protected void configureShell(Shell newShell) {
279
			super.configureShell(newShell);
280
			PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.CALL_HIERARCHY_EXPAND_WITH_CONSTRUCTORS_DIALOG);
281
		}
282
283
	}
284
285
	/*
286
	 * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performOk()
287
	 */
288
	public boolean performOk() {
289
		setValue(ANONYMOUS_EXPAND_WITH_CONSTRUCTORS, fIsAnonymous);
290
		return super.performOk();
291
	}
292
293
	/**
294
	 * The list label provider class.
295
	 */
296
	private static class ListLabelProvider extends LabelProvider {
297
298
		public final Image MEMBER_ICON;
299
300
		private final Image CLASS_ICON;
301
302
		/**
303
		 * Create the member and class icons.
304
		 */
305
		public ListLabelProvider() {
306
			MEMBER_ICON= JavaElementImageProvider.getDecoratedImage(JavaPluginImages.DESC_MISC_PUBLIC, 0, JavaElementImageProvider.SMALL_SIZE);
307
			CLASS_ICON= JavaElementImageProvider.getDecoratedImage(JavaPluginImages.DESC_OBJS_CLASS, 0, JavaElementImageProvider.SMALL_SIZE);
308
		}
309
310
		/*
311
		 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
312
		 */
313
		public Image getImage(Object element) {
314
			return ((String)element).endsWith(WILDCARD) ? CLASS_ICON : MEMBER_ICON;
315
		}
316
317
		/*
318
		 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
319
		 */
320
		public String getText(Object element) {
321
			return BasicElementLabels.getJavaElementName((String)element);
322
		}
323
	}
324
325
326
	/**
327
	 * The change listener for <code>ListDialogField</code>.
328
	 */
329
	private class ListAdapter implements IListAdapter, IDialogFieldListener {
330
331
		/**
332
		 * Checks if field can be edited.
333
		 *
334
		 * @param field the list dialog field
335
		 * @return <code>true</code> if it can be edited, <code>false</code> otherwise
336
		 */
337
		private boolean canEdit(ListDialogField field) {
338
			List selected= field.getSelectedElements();
339
			return selected.size() == 1;
340
		}
341
342
		/*
343
		 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#customButtonPressed(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField, int)
344
		 */
345
		public void customButtonPressed(ListDialogField field, int index) {
346
			doButtonPressed(index);
347
		}
348
349
		/*
350
		 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#selectionChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField)
351
		 */
352
		public void selectionChanged(ListDialogField field) {
353
			fList.enableButton(IDX_EDIT, canEdit(field));
354
			fList.enableButton(IDX_REMOVE, canRemove(field));
355
		}
356
357
		/**
358
		 * Checks if the field can be removed.
359
		 *
360
		 * @param field the list dialog field
361
		 * @return <code>true</code> if it can be removed, <code>false</code> otherwise
362
		 */
363
		private boolean canRemove(ListDialogField field) {
364
			List selected= field.getSelectedElements();
365
			return selected.size() != 0;
366
		}
367
368
		/* )
369
		 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
370
		 */
371
		public void dialogFieldChanged(DialogField field) {
372
			doDialogFieldChanged(field);
373
		}
374
375
		/*
376
		 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#doubleClicked(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField)
377
		 */
378
		public void doubleClicked(ListDialogField field) {
379
			if (canEdit(field)) {
380
				doButtonPressed(IDX_EDIT);
381
			}
382
		}
383
	}
384
385
	private static final String WILDCARD= ".*"; //$NON-NLS-1$
386
387
	private static final int IDX_NEW_TYPE= 0;
388
	private static final int IDX_NEW_MEMBER= 1;
389
	private static final int IDX_EDIT= 2;
390
	private static final int IDX_REMOVE= 3;
391
	private static final int IDX_RESTORE_DEFAULTS= 4;
392
393
	private ListDialogField fList;
394
395
	private Button fAnonymousButton;
396
397
	protected boolean fIsAnonymous;
398
399
	/**
400
	 * A key that holds the list of methods or types whose methods are by default expanded with constructors in the Call Hierarchy.
401
	 */
402
	private static Key DEFAULT_EXPAND_WITH_CONSTRUCTORS_MEMBERS= getJDTUIKey(PreferenceConstants.PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS_MEMBERS);
403
404
	/**
405
	 * A key that controls whether the methods from anonymous types are by default expanded with constructors in the Call Hierarchy.
406
	 */
407
	private static Key ANONYMOUS_EXPAND_WITH_CONSTRUCTORS= getJDTUIKey(PreferenceConstants.PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS);
408
409
	/**
410
	 * Returns all the key values.
411
	 *
412
	 * @return array of keys
413
	 */
414
	public static Key[] getAllKeys() {
415
		return new Key[] { DEFAULT_EXPAND_WITH_CONSTRUCTORS_MEMBERS, ANONYMOUS_EXPAND_WITH_CONSTRUCTORS };
416
	}
417
418
419
	/**
420
	 * Creates the call hierarchy preferences configuration block.
421
	 *
422
	 * @param context the status
423
	 * @param container the preference container
424
	 */
425
	public ExpandWithConstructorsConfigurationBlock(IStatusChangeListener context, IWorkbenchPreferenceContainer container) {
426
		super(context, null, getAllKeys(), container);
427
	}
428
429
	/*
430
	 * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#createContents(org.eclipse.swt.widgets.Composite)
431
	 */
432
	protected Control createContents(Composite parent) {
433
		Composite control= new Composite(parent, SWT.NONE);
434
		GridLayout layout= new GridLayout();
435
		layout.numColumns= 2;
436
		layout.marginWidth= 10;
437
		layout.marginHeight= 10;
438
		control.setLayout(layout);
439
440
		createPreferenceList(control);
441
442
		fAnonymousButton= new Button(control, SWT.CHECK);
443
		fAnonymousButton.setText(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_anonymousTypes_label);
444
		fIsAnonymous= getBooleanValue(ANONYMOUS_EXPAND_WITH_CONSTRUCTORS);
445
		fAnonymousButton.setSelection(fIsAnonymous);
446
		fAnonymousButton.setLayoutData(new GridData(SWT.LEAD, SWT.TOP, false, false));
447
		fAnonymousButton.addSelectionListener(new SelectionAdapter() {
448
			public void widgetSelected(SelectionEvent e) {
449
				fIsAnonymous= fAnonymousButton.getSelection();
450
			}
451
452
		});
453
454
		initialize();
455
456
		Dialog.applyDialogFont(control);
457
458
		return control;
459
	}
460
461
	/**
462
	 * Create a list dialog field.
463
	 *
464
	 * @param parent the composite
465
	 */
466
	private void createPreferenceList(Composite parent) {
467
		String[] buttonLabels= new String[] {
468
				CallHierarchyMessages.ExpandWithConstructorsConfigurationBlock_newType_button,
469
				CallHierarchyMessages.ExpandWithConstructorsConfigurationBlock_newMember_button,
470
				CallHierarchyMessages.ExpandWithConstructorsConfigurationBlock_edit_button,
471
				CallHierarchyMessages.ExpandWithConstructorsConfigurationBlock_remove_button,
472
				CallHierarchyMessages.ExpandWithConstructorsConfigurationBlock_restoreDefaults_button
473
		};
474
475
		ListAdapter adapter= new ListAdapter();
476
477
		fList= new ListDialogField(adapter, buttonLabels, new ListLabelProvider());
478
		fList.setDialogFieldListener(adapter);
479
		fList.setLabelText(CallHierarchyMessages.ExpandWithConstructorsConfigurationBlock_description);
480
		fList.setRemoveButtonIndex(IDX_REMOVE);
481
		fList.enableButton(IDX_EDIT, false);
482
		fList.setViewerComparator(new ViewerComparator());
483
484
		PixelConverter pixelConverter= new PixelConverter(parent);
485
486
		fList.doFillIntoGrid(parent, 3);
487
		LayoutUtil.setHorizontalSpan(fList.getLabelControl(null), 2);
488
		LayoutUtil.setWidthHint(fList.getLabelControl(null), pixelConverter.convertWidthInCharsToPixels(60));
489
		LayoutUtil.setHorizontalGrabbing(fList.getListControl(null));
490
491
		Control listControl= fList.getListControl(null);
492
		GridData gd= (GridData)listControl.getLayoutData();
493
		gd.verticalAlignment= GridData.FILL;
494
		gd.grabExcessVerticalSpace= true;
495
		gd.heightHint= pixelConverter.convertHeightInCharsToPixels(10);
496
	}
497
498
	/**
499
	 * Initialize the elements of the list dialog field.
500
	 */
501
	public void initialize() {
502
		fList.setElements(Arrays.asList(getDefaultExpandWithConstructorsMembers()));
503
	}
504
505
	/*
506
	 * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performDefaults()
507
	 */
508
	public void performDefaults() {
509
		String str= PreferenceConstants.getPreferenceStore().getDefaultString(PreferenceConstants.PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS_MEMBERS);
510
		fList.setElements(Arrays.asList(deserializeMembers(str)));
511
		fIsAnonymous= PreferenceConstants.getPreferenceStore().getDefaultBoolean(PreferenceConstants.PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS);
512
		fAnonymousButton.setSelection(fIsAnonymous);
513
		super.performDefaults();
514
	}
515
516
	/*
517
	 * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#getFullBuildDialogStrings(boolean)
518
	 */
519
	protected String[] getFullBuildDialogStrings(boolean workspaceSettings) {
520
		return null;
521
	}
522
523
	/*
524
	 * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#validateSettings(org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock.Key, java.lang.String, java.lang.String)
525
	 */
526
	protected void validateSettings(Key changedKey, String oldValue, String newValue) {
527
528
	}
529
530
	/**
531
	 * Perform the 'New' and 'Edit' button operations by opening the respective call hierarchy
532
	 * preferences dialog, and 'Restore Defaults' button by restoring to default values for the list dialog.
533
	 *
534
	 * @param index the index of the button
535
	 */
536
	private void doButtonPressed(int index) {
537
		if (index == IDX_NEW_TYPE || index == IDX_NEW_MEMBER) { // add new
538
			List existing= fList.getElements();
539
			CallHierarchyTypesOrMembersDialog dialog= new CallHierarchyTypesOrMembersDialog(getShell(), existing, index == IDX_NEW_MEMBER);
540
			if (dialog.open() == Window.OK) {
541
				fList.addElement(dialog.getResult());
542
			}
543
		} else if (index == IDX_EDIT) { // edit
544
			List selected= fList.getSelectedElements();
545
			if (selected.isEmpty())
546
				return;
547
548
			String editedEntry= (String)selected.get(0);
549
550
			List existing= fList.getElements();
551
			existing.remove(editedEntry);
552
			boolean isType= editedEntry.endsWith(WILDCARD);
553
			CallHierarchyTypesOrMembersDialog dialog= new CallHierarchyTypesOrMembersDialog(getShell(), existing, !isType);
554
			if (isType)
555
				dialog.setInitialSelection(editedEntry.substring(0, editedEntry.length() - 2));
556
			else
557
				dialog.setInitialSelection(editedEntry);
558
559
			if (dialog.open() == Window.OK) {
560
				fList.replaceElement(editedEntry, dialog.getResult());
561
			}
562
		} else if (index == IDX_RESTORE_DEFAULTS){
563
			performDefaults();
564
		}
565
	}
566
567
	/**
568
	 * Update the key on dialog field change.
569
	 *
570
	 * @param field the dialog field
571
	 */
572
	protected final void doDialogFieldChanged(DialogField field) {
573
		// set values in working copy
574
		if (field == fList) {
575
			setValue(DEFAULT_EXPAND_WITH_CONSTRUCTORS_MEMBERS, serializeMembers(fList.getElements()));
576
		}
577
	}
578
579
	/**
580
	 * Returns the array of strings containing the types or methods for default expand with constructors.
581
	 *
582
	 * @return the array of strings containing the types or methods for default expand with constructors
583
	 */
584
	private String[] getDefaultExpandWithConstructorsMembers() {
585
		String str= getValue(DEFAULT_EXPAND_WITH_CONSTRUCTORS_MEMBERS);
586
		if (str != null && str.length() > 0) {
587
			return deserializeMembers(str);
588
		}
589
		return new String[0];
590
	}
591
592
	/**
593
	 * Return the array of types and/or methods after splitting the stored preference string.
594
	 *
595
	 * @param str the input string
596
	 * @return the array of types and/or methods
597
	 */
598
	private static String[] deserializeMembers(String str) {
599
		return str.split(";"); //$NON-NLS-1$
600
	}
601
602
	/**
603
	 * Creates a single output string from the list of strings using a delimiter.
604
	 * 
605
	 * @param list the input list of types and/or methods
606
	 * @return the single output string from the list of strings using a delimiter
607
	 */
608
	public static String serializeMembers(List list) {
609
		int size= list.size();
610
		StringBuffer buf= new StringBuffer();
611
		for (int i= 0; i < size; i++) {
612
			buf.append((String)list.get(i));
613
			if (i < size - 1)
614
				buf.append(';');
615
		}
616
		return buf.toString();
617
	}
618
619
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/ExpandWithConstructorsDialog.java (-81 / +18 lines)
Lines 10-54 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.callhierarchy;
11
package org.eclipse.jdt.internal.ui.callhierarchy;
12
12
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.custom.StyledText;
15
import org.eclipse.swt.events.ModifyEvent;
16
import org.eclipse.swt.events.ModifyListener;
17
import org.eclipse.swt.layout.GridData;
13
import org.eclipse.swt.layout.GridData;
18
import org.eclipse.swt.widgets.Button;
19
import org.eclipse.swt.widgets.Composite;
14
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Control;
15
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Label;
22
import org.eclipse.swt.widgets.Shell;
16
import org.eclipse.swt.widgets.Shell;
23
17
24
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.IStatus;
25
19
26
import org.eclipse.jface.dialogs.StatusDialog;
20
import org.eclipse.jface.dialogs.Dialog;
21
import org.eclipse.jface.dialogs.TrayDialog;
27
22
28
import org.eclipse.ui.PlatformUI;
23
import org.eclipse.ui.PlatformUI;
29
24
30
import org.eclipse.jdt.core.JavaConventions;
31
import org.eclipse.jdt.core.JavaCore;
32
33
import org.eclipse.jdt.internal.corext.util.Messages;
34
35
import org.eclipse.jdt.ui.PreferenceConstants;
36
37
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
25
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
38
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
26
import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
39
27
40
/**
28
/**
41
 * Configuration dialog for default "Expand with Constructors" behavior.
29
 * Configuration dialog for default "Expand with Constructors" behavior.
42
 * 
30
 * 
43
 * @since 3.5
31
 * @since 3.5
44
 */
32
 */
45
class ExpandWithConstructorsDialog extends StatusDialog {
33
class ExpandWithConstructorsDialog extends TrayDialog {
46
34
47
	private static final String LINE_DELIMITER_REGEX= "\\r\\n?|\\n"; //$NON-NLS-1$
35
	private Control fConfigurationBlockControl;
36
	private ExpandWithConstructorsConfigurationBlock fConfigurationBlock;
48
37
49
	private Button fAnonymousButton;
50
	private StyledText fDefaultTypesText;
51
	
52
	protected ExpandWithConstructorsDialog(Shell parentShell) {
38
	protected ExpandWithConstructorsDialog(Shell parentShell) {
53
		super(parentShell);
39
		super(parentShell);
54
	}
40
	}
Lines 66-114 Link Here
66
	protected void configureShell(Shell newShell) {
52
	protected void configureShell(Shell newShell) {
67
		super.configureShell(newShell);
53
		super.configureShell(newShell);
68
		newShell.setText(CallHierarchyMessages.ExpandWithConstructorsDialog_title);
54
		newShell.setText(CallHierarchyMessages.ExpandWithConstructorsDialog_title);
69
		setHelpAvailable(false);
70
		PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.CALL_HIERARCHY_EXPAND_WITH_CONSTRUCTORS_DIALOG);
55
		PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.CALL_HIERARCHY_EXPAND_WITH_CONSTRUCTORS_DIALOG);
71
	}
56
	}
72
57
73
	/*
58
	/*
74
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
59
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
75
	 */
60
	 */
76
	protected Control createDialogArea(Composite parent) {
61
	protected Control createDialogArea(Composite composite) {
77
		Composite composite= (Composite)super.createDialogArea(parent);
62
		fConfigurationBlock= new ExpandWithConstructorsConfigurationBlock(new IStatusChangeListener() {
78
		((GridData)composite.getLayoutData()).widthHint= convertWidthInCharsToPixels(60);
63
			public void statusChanged(IStatus status) {
79
		
64
				//Do nothing
80
		Label descriptionLabel= new Label(composite, SWT.WRAP);
65
81
		descriptionLabel.setText(CallHierarchyMessages.ExpandWithConstructorsDialog_explanation_label);
82
		descriptionLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
83
		
84
		
85
		Label typesLabel= new Label(composite, SWT.WRAP);
86
		typesLabel.setText(CallHierarchyMessages.ExpandWithConstructorsDialog_typeNames_label);
87
		typesLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
88
		
89
		fDefaultTypesText= new StyledText(composite, SWT.BORDER | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL);
90
		GridData gd= new GridData(SWT.FILL, SWT.FILL, true, true);
91
		gd.heightHint= convertHeightInCharsToPixels(10);
92
		fDefaultTypesText.setLayoutData(gd);
93
		
94
		String defaultTypesPref= PreferenceConstants.getPreferenceStore().getString(CallHierarchyContentProvider.PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS);
95
		String defaultTypesText= defaultTypesPref.replace(';', '\n');
96
		fDefaultTypesText.setText(defaultTypesText);
97
		fDefaultTypesText.setSelection(fDefaultTypesText.getCharCount());
98
		
99
		fDefaultTypesText.addModifyListener(new ModifyListener() {
100
			public void modifyText(ModifyEvent e) {
101
				validateInput();
102
			}
66
			}
103
		});
67
		}, null);
104
		
68
		GridData data= new GridData(GridData.FILL, GridData.FILL, true, true);
105
		
69
		fConfigurationBlockControl= fConfigurationBlock.createContents(composite);
106
		fAnonymousButton= new Button(composite, SWT.CHECK);
70
		fConfigurationBlockControl.setLayoutData(data);
107
		fAnonymousButton.setText(CallHierarchyMessages.ExpandWithConstructorsDialog_anonymousTypes_label);
71
108
		boolean anonymousPref= PreferenceConstants.getPreferenceStore().getBoolean(CallHierarchyContentProvider.PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS);
72
		Dialog.applyDialogFont(composite);
109
		fAnonymousButton.setSelection(anonymousPref);
110
		fAnonymousButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
111
		
112
		return composite;
73
		return composite;
113
	}
74
	}
114
75
Lines 116-146 Link Here
116
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
77
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
117
	 */
78
	 */
118
	protected void okPressed() {
79
	protected void okPressed() {
119
		PreferenceConstants.getPreferenceStore().setValue(CallHierarchyContentProvider.PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS, fAnonymousButton.getSelection());
80
		fConfigurationBlock.performOk();
120
		
121
		String defaultTypes= fDefaultTypesText.getText().trim();
122
		String defaultTypesPref= defaultTypes.replaceAll(LINE_DELIMITER_REGEX, ";"); //$NON-NLS-1$
123
		PreferenceConstants.getPreferenceStore().setValue(CallHierarchyContentProvider.PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS, defaultTypesPref);
124
		
125
		super.okPressed();
81
		super.okPressed();
126
	}
82
	}
127
128
	private void validateInput() {
129
		StatusInfo status= new StatusInfo();
130
		
131
		String[] defaultTypes= fDefaultTypesText.getText().split(LINE_DELIMITER_REGEX);
132
		for (int i= 0; i < defaultTypes.length; i++) {
133
			String type= defaultTypes[i];
134
			if (type.length() == 0)
135
				continue;
136
			
137
			IStatus typeNameStatus= JavaConventions.validateJavaTypeName(type, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
138
			if (typeNameStatus.getSeverity() == IStatus.ERROR) {
139
				status.setError(Messages.format(CallHierarchyMessages.ExpandWithConstructorsDialog_not_a_valid_type_name, type));
140
				break;
141
			}
142
		}
143
		
144
		updateStatus(status);
145
	}
146
}
83
}
(-)ui/org/eclipse/jdt/ui/PreferenceConstants.java (-3 / +38 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.ui;
11
package org.eclipse.jdt.ui;
12
12
13
import java.util.Arrays;
13
import java.util.Locale;
14
import java.util.Locale;
14
import java.util.StringTokenizer;
15
import java.util.StringTokenizer;
15
16
Lines 44-49 Link Here
44
import org.eclipse.jdt.internal.ui.JavaPlugin;
45
import org.eclipse.jdt.internal.ui.JavaPlugin;
45
import org.eclipse.jdt.internal.ui.JavaUIPreferenceInitializer;
46
import org.eclipse.jdt.internal.ui.JavaUIPreferenceInitializer;
46
import org.eclipse.jdt.internal.ui.callhierarchy.CallHierarchyContentProvider;
47
import org.eclipse.jdt.internal.ui.callhierarchy.CallHierarchyContentProvider;
48
import org.eclipse.jdt.internal.ui.callhierarchy.ExpandWithConstructorsConfigurationBlock;
47
import org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightings;
49
import org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightings;
48
import org.eclipse.jdt.internal.ui.preferences.NewJavaProjectPreferencePage;
50
import org.eclipse.jdt.internal.ui.preferences.NewJavaProjectPreferencePage;
49
import org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileManager;
51
import org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileManager;
Lines 3233-3238 Link Here
3233
	 */
3235
	 */
3234
	public static final String EDITOR_FOLDING_HEADERS= "editor_folding_default_headers"; //$NON-NLS-1$
3236
	public static final String EDITOR_FOLDING_HEADERS= "editor_folding_default_headers"; //$NON-NLS-1$
3235
3237
3238
	/**
3239
	 * A named preference that holds the methods or types whose methods are by default expanded with
3240
	 * constructors in the Call Hierarchy.
3241
	 * <p>
3242
	 * Value is of type <code>String</code>: semicolon separated list of fully qualified type names
3243
	 * appended with ".*" or "." + method name.
3244
	 * </p>
3245
	 * 
3246
	 * @since 3.6
3247
	 */
3248
	public static final String PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS_MEMBERS= "CallHierarchy.defaultExpandWithConstructorsMembers"; //$NON-NLS-1$
3249
3250
	/**
3251
	 * A named preference that controls whether methods from anonymous types are by default expanded
3252
	 * with constructors in the Call Hierarchy.
3253
	 * <p>
3254
	 * Value is of type <code>Boolean</code>.
3255
	 * </p>
3256
	 * 
3257
	 * @since 3.6
3258
	 */
3259
	public static final String PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS= "CallHierarchy.anonymousExpandWithConstructors"; //$NON-NLS-1$
3260
3236
3261
3237
	//---------- Properties File Editor ----------
3262
	//---------- Properties File Editor ----------
3238
3263
Lines 3875-3883 Link Here
3875
3900
3876
		// Colors that are set by the current theme
3901
		// Colors that are set by the current theme
3877
		JavaUIPreferenceInitializer.setThemeBasedPreferences(store, false);
3902
		JavaUIPreferenceInitializer.setThemeBasedPreferences(store, false);
3878
		
3903
3879
		store.setDefault(CallHierarchyContentProvider.PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS, true);
3904
		store.setDefault(PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS, true);
3880
		store.setDefault(CallHierarchyContentProvider.PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS, "java.lang.Runnable;java.util.concurrent.Callable;org.eclipse.swt.widgets.Listener"); //$NON-NLS-1$
3905
		store.setDefault(PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS_MEMBERS, "java.lang.Runnable.run;java.util.concurrent.Callable.call;org.eclipse.swt.widgets.Listener.handleEvent"); //$NON-NLS-1$
3906
		// compatibility code
3907
		String str= store.getString(CallHierarchyContentProvider.OLD_PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS);
3908
		if (str.length() > 0) {
3909
			String[] oldPrefStr= str.split(";"); //$NON-NLS-1$
3910
			for (int i= 0; i < oldPrefStr.length; i++) {
3911
				oldPrefStr[i]= oldPrefStr[i] + (".*"); //$NON-NLS-1$				
3912
			}
3913
			store.setValue(PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS_MEMBERS, ExpandWithConstructorsConfigurationBlock.serializeMembers(Arrays.asList(oldPrefStr)));
3914
			store.setToDefault(CallHierarchyContentProvider.OLD_PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS);
3915
		}
3881
	}
3916
	}
3882
3917
3883
	/**
3918
	/**

Return to bug 276466