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

Return to bug 276466