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/CallHierarchyMessages.java (-6 / +4 lines)
Lines 58-64 Link Here
58
	public static String ToggleOrientationAction_single_label;
58
	public static String ToggleOrientationAction_single_label;
59
	public static String ToggleOrientationAction_single_tooltip;
59
	public static String ToggleOrientationAction_single_tooltip;
60
	public static String ToggleOrientationAction_single_description;
60
	public static String ToggleOrientationAction_single_description;
61
	public static String ShowExpandWithConstructorsDialogAction_text;
62
	public static String ShowFilterDialogAction_text;
61
	public static String ShowFilterDialogAction_text;
63
	public static String FiltersDialog_filter;
62
	public static String FiltersDialog_filter;
64
	public static String FiltersDialog_filterOnNames;
63
	public static String FiltersDialog_filterOnNames;
Lines 74-79 Link Here
74
	public static String CallHierarchyLabelProvider_noMethodSelected;
73
	public static String CallHierarchyLabelProvider_noMethodSelected;
75
	public static String CallHierarchyLabelProvider_updatePending;
74
	public static String CallHierarchyLabelProvider_updatePending;
76
	public static String CallHierarchyLabelProvider_matches;
75
	public static String CallHierarchyLabelProvider_matches;
76
	public static String CallHierarchyPreferencePage_expand_with_constructors_title;
77
	public static String CallHierarchyPreferenceDialog_anonymousTypes_label;
77
	public static String CallHierarchyViewPart_empty;
78
	public static String CallHierarchyViewPart_empty;
78
	public static String CallHierarchyViewPart_callsToConstructors;
79
	public static String CallHierarchyViewPart_callsToConstructors;
79
	public static String CallHierarchyViewPart_callsToField;
80
	public static String CallHierarchyViewPart_callsToField;
Lines 139-153 Link Here
139
	public static String ExpandWithConstructorsAction_expandWithConstructors_text;
140
	public static String ExpandWithConstructorsAction_expandWithConstructors_text;
140
	public static String ExpandWithConstructorsAction_expandWithConstructors_description;
141
	public static String ExpandWithConstructorsAction_expandWithConstructors_description;
141
	public static String ExpandWithConstructorsAction_expandWithConstructors_tooltip;
142
	public static String ExpandWithConstructorsAction_expandWithConstructors_tooltip;
142
	public static String ExpandWithConstructorsDialog_anonymousTypes_label;
143
	public static String ExpandWithConstructorsDialog_explanation_label;
144
	public static String ExpandWithConstructorsDialog_not_a_valid_type_name;
145
	public static String ExpandWithConstructorsDialog_title;
146
	public static String ExpandWithConstructorsDialog_typeNames_label;
147
	static {
143
	static {
148
		NLS.initializeMessages(BUNDLE_NAME, CallHierarchyMessages.class);
144
		NLS.initializeMessages(BUNDLE_NAME, CallHierarchyMessages.class);
149
	}
145
	}
150
146
151
	public static String CallHierarchyViewPart_layout_menu;
147
	public static String CallHierarchyViewPart_layout_menu;
152
	public static String CallHierarchyViewPart_field_menu;
148
	public static String CallHierarchyViewPart_field_menu;
149
	public static String CallHierarchyViewPart_preferences_label;
150
153
}
151
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/ExpandWithConstructorsDialog.java (-146 lines)
Removed 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
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.callhierarchy;
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;
18
import org.eclipse.swt.widgets.Button;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Label;
22
import org.eclipse.swt.widgets.Shell;
23
24
import org.eclipse.core.runtime.IStatus;
25
26
import org.eclipse.jface.dialogs.StatusDialog;
27
28
import org.eclipse.ui.PlatformUI;
29
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;
38
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
39
40
/**
41
 * Configuration dialog for default "Expand with Constructors" behavior.
42
 * 
43
 * @since 3.5
44
 */
45
class ExpandWithConstructorsDialog extends StatusDialog {
46
47
	private static final String LINE_DELIMITER_REGEX= "\\r\\n?|\\n"; //$NON-NLS-1$
48
49
	private Button fAnonymousButton;
50
	private StyledText fDefaultTypesText;
51
	
52
	protected ExpandWithConstructorsDialog(Shell parentShell) {
53
		super(parentShell);
54
	}
55
	
56
	/*
57
	 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
58
	 */
59
	protected boolean isResizable() {
60
		return true;
61
	}
62
	
63
	/*
64
	 * @see org.eclipse.jface.dialogs.StatusDialog#configureShell(org.eclipse.swt.widgets.Shell)
65
	 */
66
	protected void configureShell(Shell newShell) {
67
		super.configureShell(newShell);
68
		newShell.setText(CallHierarchyMessages.ExpandWithConstructorsDialog_title);
69
		setHelpAvailable(false);
70
		PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.CALL_HIERARCHY_EXPAND_WITH_CONSTRUCTORS_DIALOG);
71
	}
72
73
	/*
74
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
75
	 */
76
	protected Control createDialogArea(Composite parent) {
77
		Composite composite= (Composite)super.createDialogArea(parent);
78
		((GridData)composite.getLayoutData()).widthHint= convertWidthInCharsToPixels(60);
79
		
80
		Label descriptionLabel= new Label(composite, SWT.WRAP);
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
			}
103
		});
104
		
105
		
106
		fAnonymousButton= new Button(composite, SWT.CHECK);
107
		fAnonymousButton.setText(CallHierarchyMessages.ExpandWithConstructorsDialog_anonymousTypes_label);
108
		boolean anonymousPref= PreferenceConstants.getPreferenceStore().getBoolean(CallHierarchyContentProvider.PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS);
109
		fAnonymousButton.setSelection(anonymousPref);
110
		fAnonymousButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
111
		
112
		return composite;
113
	}
114
115
	/*
116
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
117
	 */
118
	protected void okPressed() {
119
		PreferenceConstants.getPreferenceStore().setValue(CallHierarchyContentProvider.PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS, fAnonymousButton.getSelection());
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();
126
	}
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
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyContentProvider.java (-16 / +17 lines)
Lines 51-59 Link Here
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
	 * </p>
52
	 * </p>
53
	 * 
53
	 * 
54
	 * @since 3.5
54
	 * @since 3.6
55
	 */
55
	 */
56
	public static final String PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS= "CallHierarchy.defaultExpandWithConstructors"; //$NON-NLS-1$
56
	public static final String CALL_HIERARCHY_PREFERENCES= "CallHierarchy.defaultExpandWithConstructors"; //$NON-NLS-1$
57
57
58
	/**
58
	/**
59
	 * A named preference that controls whether methods from anonymous types are by default expanded
59
	 * A named preference that controls whether methods from anonymous types are by default expanded
Lines 62-68 Link Here
62
	 * Value is of type <code>Boolean</code>.
62
	 * Value is of type <code>Boolean</code>.
63
	 * </p>
63
	 * </p>
64
	 * 
64
	 * 
65
	 * @since 3.5
65
	 * @since 3.6
66
	 */
66
	 */
67
	public static final String PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS= "CallHierarchy.anonymousExpandWithConstructors"; //$NON-NLS-1$
67
	public static final String PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS= "CallHierarchy.anonymousExpandWithConstructors"; //$NON-NLS-1$
68
68
Lines 182-188 Link Here
182
						boolean anonymousPref= PreferenceConstants.getPreferenceStore().getBoolean(PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS);
182
						boolean anonymousPref= PreferenceConstants.getPreferenceStore().getBoolean(PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS);
183
						if (anonymousPref && type.isAnonymous()) {
183
						if (anonymousPref && type.isAnonymous()) {
184
							withConstructors= true;
184
							withConstructors= true;
185
						} else if (isInTheDefaultExpandWithConstructorList(type)) {
185
						} else if (isInTheDefaultExpandWithConstructorList(wrapper)) {
186
							withConstructors= true;
186
							withConstructors= true;
187
						}
187
						}
188
					}
188
					}
Lines 217-237 Link Here
217
	}
217
	}
218
	
218
	
219
	/**
219
	/**
220
	 * Checks if declaring type matches the pre-defined array of types for default expand with
220
	 * Checks if the member or its declaring type matches the pre-defined array of members and types
221
	 * constructors.
221
	 * for default expand with constructors.
222
	 * 
222
	 * 
223
	 * @param type the declaring type of the caller method wrapper
223
	 * @param wrapper caller method wrapper
224
	 * @return <code>true</code> if type matches the pre-defined list, <code>false</code> otherwise
224
	 * @return <code>true</code> if method or type matches the pre-defined list, <code>false</code> otherwise
225
	 * @since 3.5
225
	 * @since 3.6
226
	 */
226
	 */
227
	static boolean isInTheDefaultExpandWithConstructorList(IType type) {
227
	static boolean isInTheDefaultExpandWithConstructorList(CallerMethodWrapper wrapper) {
228
		String serializedTypes= PreferenceConstants.getPreferenceStore().getString(PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS);
228
		String serializedTypes= PreferenceConstants.getPreferenceStore().getString(CALL_HIERARCHY_PREFERENCES);
229
		if (serializedTypes.length() == 0)
229
		if (serializedTypes.length() == 0)
230
			return false;
230
			return false;
231
		
231
		String member= wrapper.getMember().getElementName();
232
		IType type= wrapper.getMember().getDeclaringType();
232
		String[] defaultTypes= serializedTypes.split(";"); //$NON-NLS-1$
233
		String[] defaultTypes= serializedTypes.split(";"); //$NON-NLS-1$
233
		
234
234
		String typeName= type.getFullyQualifiedName('.');
235
		String typeName= type.getFullyQualifiedName('.').concat(".*"); //$NON-NLS-1$;
235
		String superClass;
236
		String superClass;
236
		String[] superInterfaces;
237
		String[] superInterfaces;
237
		try {
238
		try {
Lines 242-253 Link Here
242
		}
243
		}
243
		for (int i= 0; i < defaultTypes.length; i++) {
244
		for (int i= 0; i < defaultTypes.length; i++) {
244
			String defaultType= defaultTypes[i];
245
			String defaultType= defaultTypes[i];
245
			if (typeName.equals(defaultType) || (superClass != null && typeNameMatches(superClass, defaultType))) {
246
			if (typeNameMatches(member, defaultType) || typeName.equals(defaultType) || (superClass != null && typeNameMatches(superClass.concat(".*"), defaultType))) { //$NON-NLS-1$
246
				return true;
247
				return true;
247
			}
248
			}
248
			if (superInterfaces.length > 0) {
249
			if (superInterfaces.length > 0) {
249
				for (int j= 0; j < superInterfaces.length; j++) {
250
				for (int j= 0; j < superInterfaces.length; j++) {
250
					if (typeNameMatches(superInterfaces[j], defaultType))
251
					if (typeNameMatches(superInterfaces[j].concat(".*"), defaultType)) //$NON-NLS-1$
251
						return true;
252
						return true;
252
				}
253
				}
253
			}
254
			}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyMessages.properties (-7 / +5 lines)
Lines 55-61 Link Here
55
ToggleOrientationAction_single_tooltip=Hierarchy View Only
55
ToggleOrientationAction_single_tooltip=Hierarchy View Only
56
ToggleOrientationAction_single_description=Hierarchy View Only
56
ToggleOrientationAction_single_description=Hierarchy View Only
57
57
58
ShowExpandWithConstructorsDialogAction_text=E&xpand with Constructors...
59
ShowFilterDialogAction_text= &Filters...
58
ShowFilterDialogAction_text= &Filters...
60
FiltersDialog_filter= Filter Calls
59
FiltersDialog_filter= Filter Calls
61
FiltersDialog_filterOnNames= &Name filter patterns (matching names will be hidden):
60
FiltersDialog_filterOnNames= &Name filter patterns (matching names will be hidden):
Lines 71-76 Link Here
71
CallHierarchyLabelProvider_noMethodSelected=- no method selected -
70
CallHierarchyLabelProvider_noMethodSelected=- no method selected -
72
CallHierarchyLabelProvider_updatePending=...
71
CallHierarchyLabelProvider_updatePending=...
73
CallHierarchyLabelProvider_matches={0} ({1} matches)
72
CallHierarchyLabelProvider_matches={0} ({1} matches)
73
CallHierarchyPreferencePage_expand_with_constructors_title=Expand With Constructors
74
CallHierarchyPreferenceDialog_anonymousTypes_label=&All methods in anonymous types
74
CallHierarchyViewPart_empty=To display the call hierarchy, select one or more methods, classes, fields, or initializers, and select the \'Open Call Hierarchy\' menu option. Alternatively, you can drag and drop the member or members onto this view.
75
CallHierarchyViewPart_empty=To display the call hierarchy, select one or more methods, classes, fields, or initializers, and select the \'Open Call Hierarchy\' menu option. Alternatively, you can drag and drop the member or members onto this view.
75
CallHierarchyViewPart_callsToConstructors=Members calling constructors of ''{0}'' - in {1}
76
CallHierarchyViewPart_callsToConstructors=Members calling constructors of ''{0}'' - in {1}
76
CallHierarchyViewPart_callsToField=Members accessing ''{0}'' - in {1}
77
CallHierarchyViewPart_callsToField=Members accessing ''{0}'' - in {1}
Lines 86-91 Link Here
86
CallHierarchyViewPart_callsFromMembers_3=Calls from ''{0}'', ''{1}'', ''{2}'' - in {3}
87
CallHierarchyViewPart_callsFromMembers_3=Calls from ''{0}'', ''{1}'', ''{2}'' - in {3}
87
CallHierarchyViewPart_callsFromMembers_more=Calls from ''{0}'', ''{1}'', ''{2}'', ... - in {3}
88
CallHierarchyViewPart_callsFromMembers_more=Calls from ''{0}'', ''{1}'', ''{2}'', ... - in {3}
88
CallHierarchyViewPart_callsFromMethod=Calls from ''{0}'' - in {1}
89
CallHierarchyViewPart_callsFromMethod=Calls from ''{0}'' - in {1}
90
CallHierarchyViewPart_preferences_label= Preferences...
91
89
FocusOnSelectionAction_focusOnSelection_text=Fo&cus On Selection
92
FocusOnSelectionAction_focusOnSelection_text=Fo&cus On Selection
90
FocusOnSelectionAction_focusOnSelection_description=Focus On Selection
93
FocusOnSelectionAction_focusOnSelection_description=Focus On Selection
91
FocusOnSelectionAction_focusOnSelection_tooltip=Focus On Selection
94
FocusOnSelectionAction_focusOnSelection_tooltip=Focus On Selection
Lines 145-153 Link Here
145
RemoveFromViewAction_removeFromView_tooltip= Remove from View
148
RemoveFromViewAction_removeFromView_tooltip= Remove from View
146
ExpandWithConstructorsAction_expandWithConstructors_text= &Expand with Constructors
149
ExpandWithConstructorsAction_expandWithConstructors_text= &Expand with Constructors
147
ExpandWithConstructorsAction_expandWithConstructors_description= Expand with constructors
150
ExpandWithConstructorsAction_expandWithConstructors_description= Expand with constructors
148
ExpandWithConstructorsAction_expandWithConstructors_tooltip= Expand with Constructors
151
ExpandWithConstructorsAction_expandWithConstructors_tooltip= Expand with Constructors
149
ExpandWithConstructorsDialog_anonymousTypes_label=&All methods in anonymous types
150
ExpandWithConstructorsDialog_explanation_label=Configure the types whose instance methods are expanded with constructors by default.
151
ExpandWithConstructorsDialog_not_a_valid_type_name=''{0}'' is not a valid type name
152
ExpandWithConstructorsDialog_title=Expand with Constructors
153
ExpandWithConstructorsDialog_typeNames_label=Type &names (each on a line):
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyFiltersActionGroup.java (-19 / +1 lines)
Lines 11-18 Link Here
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.jdt.internal.ui.callhierarchy;
12
package org.eclipse.jdt.internal.ui.callhierarchy;
13
13
14
import org.eclipse.swt.widgets.Shell;
15
16
import org.eclipse.core.runtime.Assert;
14
import org.eclipse.core.runtime.Assert;
17
15
18
import org.eclipse.jface.action.Action;
16
import org.eclipse.jface.action.Action;
Lines 46-62 Link Here
46
            openFiltersDialog();
44
            openFiltersDialog();
47
        }
45
        }
48
    }
46
    }
49
47
 
50
    class ShowExpandWithConstructorsDialogAction extends Action {
51
    	ShowExpandWithConstructorsDialogAction() {
52
    		setText(CallHierarchyMessages.ShowExpandWithConstructorsDialogAction_text);
53
    	}
54
    	
55
    	public void run() {
56
    		openExpandWithConstructorsDialog();
57
    	}
58
    }
59
    
60
    private IViewPart fPart;
48
    private IViewPart fPart;
61
49
62
    /**
50
    /**
Lines 81-87 Link Here
81
    private void fillViewMenu(IMenuManager viewMenu) {
69
    private void fillViewMenu(IMenuManager viewMenu) {
82
        viewMenu.add(new Separator("filters")); //$NON-NLS-1$
70
        viewMenu.add(new Separator("filters")); //$NON-NLS-1$
83
        viewMenu.add(new ShowFilterDialogAction());
71
        viewMenu.add(new ShowFilterDialogAction());
84
        viewMenu.add(new ShowExpandWithConstructorsDialogAction());
85
    }
72
    }
86
73
87
    /* (non-Javadoc)
74
    /* (non-Javadoc)
Lines 99-107 Link Here
99
86
100
        dialog.open();
87
        dialog.open();
101
    }
88
    }
102
    
103
    private void openExpandWithConstructorsDialog() {
104
    	Shell parentShell= fPart.getViewSite().getShell();
105
		new ExpandWithConstructorsDialog(parentShell).open();
106
    }
107
}
89
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyViewPart.java (-1 / +3 lines)
Lines 237-242 Link Here
237
    private boolean fShowCallDetails;
237
    private boolean fShowCallDetails;
238
	protected Composite fParent;
238
	protected Composite fParent;
239
	private IPartListener2 fPartListener;
239
	private IPartListener2 fPartListener;
240
	private PreferencesActionGroup fPreferences;
240
241
241
242
242
    public CallHierarchyViewPart() {
243
    public CallHierarchyViewPart() {
Lines 1007-1012 Link Here
1007
        fSearchScopeActions = new SearchScopeActionGroup(this, fDialogSettings);
1008
        fSearchScopeActions = new SearchScopeActionGroup(this, fDialogSettings);
1008
        fFiltersActionGroup = new CallHierarchyFiltersActionGroup(this,
1009
        fFiltersActionGroup = new CallHierarchyFiltersActionGroup(this,
1009
                fCallHierarchyViewer);
1010
                fCallHierarchyViewer);
1011
        fPreferences= new PreferencesActionGroup(this);
1010
        fHistoryDropDownAction = new HistoryDropDownAction(this);
1012
        fHistoryDropDownAction = new HistoryDropDownAction(this);
1011
        fHistoryDropDownAction.setEnabled(false);
1013
        fHistoryDropDownAction.setEnabled(false);
1012
        fCancelSearchAction = new CancelSearchAction(this);
1014
        fCancelSearchAction = new CancelSearchAction(this);
Lines 1035-1041 Link Here
1035
                    new GenerateActionGroup(this),
1037
                    new GenerateActionGroup(this),
1036
                    new RefactorActionGroup(this),
1038
                    new RefactorActionGroup(this),
1037
                    new JavaSearchActionGroup(this),
1039
                    new JavaSearchActionGroup(this),
1038
                    fSearchScopeActions, fFiltersActionGroup
1040
                    fSearchScopeActions, fFiltersActionGroup, fPreferences
1039
                });
1041
                });
1040
    }
1042
    }
1041
1043
(-)ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties (+19 lines)
Lines 923-928 Link Here
923
CodeAssistStaticMembersConfigurationBlock_edit_button= &Edit...
923
CodeAssistStaticMembersConfigurationBlock_edit_button= &Edit...
924
CodeAssistStaticMembersConfigurationBlock_remove_button= &Remove
924
CodeAssistStaticMembersConfigurationBlock_remove_button= &Remove
925
925
926
CallHierarchyPreferencesConfigurationBlock_description= De&fine a list of members or types with their fully qualified names.Call Hierarchy for these types/members will "Expand With Constructors" by default.
927
CallHierarchyPreferencesConfigurationBlock_newType_button= New &Type...
928
CallHierarchyPreferencesConfigurationBlock_newMember_button= New &Member...
929
CallHierarchyPreferencesConfigurationBlock_edit_button= &Edit
930
CallHierarchyPreferencesConfigurationBlock_remove_button= &Remove 
931
932
CallHierarchyPreferencesDialog_member_title= New Member for Expand With Constructors
933
CallHierarchyPreferencesDialog_member_labelText= Enter a fully qualified static member (e.g. \'java.lang.Math.sqrt\'): 
934
CallHierarchyPreferencesDialog_type_title= New Type for Expand With Constructors
935
CallHierarchyPreferencesDialog_type_labelText= Enter a fully qualified type (e.g. \'java.lang.Math\'):
936
CallHierarchyPreferencesDialog_browse_button= &Browse...
937
CallHierarchyPreferencesDialog_ChooseTypeDialog_title= Type Selection
938
CallHierarchyPreferencesDialog_ChooseTypeDialog_description= Choose type name:
939
CallHierarchyPreferencesDialog_ChooseTypeDialog_error_message= A problem occurred while collecting types. See the error Log for details.
940
CallHierarchyPreferencesDialog_error_enterName=Enter a name or prefix.
941
CallHierarchyPreferencesDialog_error_invalidTypeName=Not a valid type name.
942
CallHierarchyPreferencesDialog_error_invalidMemberName=Not a valid member name.
943
CallHierarchyPreferencesDialog_error_entryExists=Entry already exists in list.
944
926
FavoriteStaticMemberInputDialog_member_title= New Member Favorite
945
FavoriteStaticMemberInputDialog_member_title= New Member Favorite
927
FavoriteStaticMemberInputDialog_member_labelText= Enter a fully qualified static member (e.g. \'java.lang.Math.sqrt\'): 
946
FavoriteStaticMemberInputDialog_member_labelText= Enter a fully qualified static member (e.g. \'java.lang.Math.sqrt\'): 
928
FavoriteStaticMemberInputDialog_type_title= New Type Favorite 
947
FavoriteStaticMemberInputDialog_type_title= New Type Favorite 
(-)ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java (+19 lines)
Lines 808-813 Link Here
808
	public static String CodeAssistStaticMembersConfigurationBlock_edit_button;
808
	public static String CodeAssistStaticMembersConfigurationBlock_edit_button;
809
	public static String CodeAssistStaticMembersConfigurationBlock_remove_button;
809
	public static String CodeAssistStaticMembersConfigurationBlock_remove_button;
810
810
811
	public static String CallHierarchyPreferencesConfigurationBlock_description;
812
	public static String CallHierarchyPreferencesConfigurationBlock_newType_button;
813
	public static String CallHierarchyPreferencesConfigurationBlock_newMember_button;
814
	public static String CallHierarchyPreferencesConfigurationBlock_edit_button;
815
	public static String CallHierarchyPreferencesConfigurationBlock_remove_button;
816
811
	public static String FavoriteStaticMemberInputDialog_member_title;
817
	public static String FavoriteStaticMemberInputDialog_member_title;
812
	public static String FavoriteStaticMemberInputDialog_member_labelText;
818
	public static String FavoriteStaticMemberInputDialog_member_labelText;
813
	public static String FavoriteStaticMemberInputDialog_type_title;
819
	public static String FavoriteStaticMemberInputDialog_type_title;
Lines 821-824 Link Here
821
	public static String FavoriteStaticMemberInputDialog_error_invalidTypeName;
827
	public static String FavoriteStaticMemberInputDialog_error_invalidTypeName;
822
	public static String FavoriteStaticMemberInputDialog_error_entryExists;
828
	public static String FavoriteStaticMemberInputDialog_error_entryExists;
823
829
830
	public static String CallHierarchyPreferencesDialog_member_title;
831
	public static String CallHierarchyPreferencesDialog_member_labelText;
832
	public static String CallHierarchyPreferencesDialog_type_title;
833
	public static String CallHierarchyPreferencesDialog_type_labelText;
834
	public static String CallHierarchyPreferencesDialog_browse_button;
835
	public static String CallHierarchyPreferencesDialog_ChooseTypeDialog_title;
836
	public static String CallHierarchyPreferencesDialog_ChooseTypeDialog_description;
837
	public static String CallHierarchyPreferencesDialog_ChooseTypeDialog_error_message;
838
	public static String CallHierarchyPreferencesDialog_error_enterName;
839
	public static String CallHierarchyPreferencesDialog_error_invalidMemberName;
840
	public static String CallHierarchyPreferencesDialog_error_invalidTypeName;
841
	public static String CallHierarchyPreferencesDialog_error_entryExists;
842
824
}
843
}
(-)ui/org/eclipse/jdt/ui/PreferenceConstants.java (-3 / +10 lines)
Lines 64-70 Link Here
64
 *
64
 *
65
 * @noinstantiate This class is not intended to be instantiated by clients.
65
 * @noinstantiate This class is not intended to be instantiated by clients.
66
 * @noextend This class is not intended to be subclassed by clients.
66
 * @noextend This class is not intended to be subclassed by clients.
67
  */
67
 */
68
public class PreferenceConstants {
68
public class PreferenceConstants {
69
69
70
	private PreferenceConstants() {
70
	private PreferenceConstants() {
Lines 2977-2982 Link Here
2977
	 */
2977
	 */
2978
	public final static String CODEASSIST_FAVORITE_STATIC_MEMBERS= "content_assist_favorite_static_members"; //$NON-NLS-1$
2978
	public final static String CODEASSIST_FAVORITE_STATIC_MEMBERS= "content_assist_favorite_static_members"; //$NON-NLS-1$
2979
2979
2980
	/**
2981
	 * A named preference that holds the types/members which expand with
2982
	 * constructors by default.
2983
	 * 
2984
	 * @since 3.6
2985
	 */
2986
	public static final String CALL_HIERARCHY_PREFERENCES= "call_hierarchy_preferences_page"; //$NON-NLS-1$
2980
2987
2981
	/**
2988
	/**
2982
	 * A named preference that controls the behavior of the refactoring wizard for showing the error page.
2989
	 * A named preference that controls the behavior of the refactoring wizard for showing the error page.
Lines 3833-3838 Link Here
3833
3840
3834
		store.setDefault(PreferenceConstants.PROPERTIES_FILE_COLORING_COMMENT_BOLD, false);
3841
		store.setDefault(PreferenceConstants.PROPERTIES_FILE_COLORING_COMMENT_BOLD, false);
3835
		store.setDefault(PreferenceConstants.PROPERTIES_FILE_COLORING_COMMENT_ITALIC, false);
3842
		store.setDefault(PreferenceConstants.PROPERTIES_FILE_COLORING_COMMENT_ITALIC, false);
3843
		store.setDefault(CallHierarchyContentProvider.CALL_HIERARCHY_PREFERENCES, "java.lang.Runnable;java.util.concurrent.Callable;org.eclipse.swt.widgets.Listener"); //$NON-NLS-1$
3836
3844
3837
		// semantic highlighting
3845
		// semantic highlighting
3838
		SemanticHighlightings.initDefaults(store);
3846
		SemanticHighlightings.initDefaults(store);
Lines 3876-3883 Link Here
3876
		// Colors that are set by the current theme
3884
		// Colors that are set by the current theme
3877
		JavaUIPreferenceInitializer.setThemeBasedPreferences(store, false);
3885
		JavaUIPreferenceInitializer.setThemeBasedPreferences(store, false);
3878
		
3886
		
3879
		store.setDefault(CallHierarchyContentProvider.PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS, true);
3887
		store.setDefault(CallHierarchyContentProvider.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$
3881
	}
3888
	}
3882
3889
3883
	/**
3890
	/**
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/PreferencesActionGroup.java (+82 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 org.eclipse.jface.action.Action;
13
import org.eclipse.jface.action.IMenuManager;
14
import org.eclipse.jface.action.Separator;
15
import org.eclipse.jface.preference.IPreferenceNode;
16
import org.eclipse.jface.preference.PreferenceDialog;
17
import org.eclipse.jface.preference.PreferenceManager;
18
import org.eclipse.jface.preference.PreferenceNode;
19
20
import org.eclipse.ui.IActionBars;
21
import org.eclipse.ui.actions.ActionGroup;
22
23
/**
24
 * Call Hierarchy preferences action group.
25
 * 
26
 * @since 3.6
27
 * 
28
 */
29
public class PreferencesActionGroup extends ActionGroup {
30
	private CallHierarchyViewPart fPart;
31
32
	public PreferencesActionGroup(CallHierarchyViewPart part) {
33
		fPart= part;
34
	}
35
36
	/**
37
	 * Call hierarchy preferences action class.
38
	 * 
39
	 * @since 3.6
40
	 * 
41
	 */
42
	public class CallHierarchyPreferencesAction extends Action {
43
44
		/**
45
		 * Creates the call hierarchy preference action.
46
		 */
47
		public CallHierarchyPreferencesAction() {
48
			setText(CallHierarchyMessages.CallHierarchyViewPart_preferences_label);
49
		}
50
51
		/* (non-Javadoc)
52
		 * @see org.eclipse.jface.action.Action#run()
53
		 */
54
		public void run() {
55
			CallHierarchyPreferencePage page= new CallHierarchyPreferencePage();
56
			IPreferenceNode targetNode= new PreferenceNode("org.eclipse.jdt.ui.preferences.CallHierarchyPreferencePage", page); //$NON-NLS-1$
57
			PreferenceManager manager= new PreferenceManager();
58
			manager.addToRoot(targetNode);
59
			PreferenceDialog dialog= new PreferenceDialog(fPart.getSite().getShell(), manager);
60
			dialog.create();
61
			dialog.open();
62
		}
63
	}
64
65
66
	/* (non-Javadoc)
67
	 * Method declared on ActionGroup.
68
	 */
69
	public void fillActionBars(IActionBars actionBars) {
70
		fillViewMenu(actionBars.getMenuManager());
71
	}
72
73
	/* (non-Javadoc)
74
	 * Method declared on ActionGroup.
75
	 */
76
	private void fillViewMenu(IMenuManager viewMenu) {
77
		viewMenu.add(new Separator("preferences")); //$NON-NLS-1$
78
		viewMenu.add(new CallHierarchyPreferencesAction());
79
	}
80
81
82
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyPreferencesConfigurationBlock.java (+624 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.graphics.Point;
21
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.layout.GridLayout;
23
import org.eclipse.swt.widgets.Button;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Shell;
27
import org.eclipse.swt.widgets.Text;
28
29
import org.eclipse.core.runtime.Assert;
30
import org.eclipse.core.runtime.IStatus;
31
32
import org.eclipse.jface.dialogs.Dialog;
33
import org.eclipse.jface.dialogs.StatusDialog;
34
import org.eclipse.jface.layout.PixelConverter;
35
import org.eclipse.jface.operation.IRunnableContext;
36
import org.eclipse.jface.viewers.LabelProvider;
37
import org.eclipse.jface.viewers.ViewerComparator;
38
import org.eclipse.jface.window.Window;
39
40
import org.eclipse.ui.PlatformUI;
41
import org.eclipse.ui.dialogs.SelectionDialog;
42
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
43
44
import org.eclipse.jdt.core.IType;
45
import org.eclipse.jdt.core.JavaConventions;
46
import org.eclipse.jdt.core.JavaCore;
47
import org.eclipse.jdt.core.JavaModelException;
48
import org.eclipse.jdt.core.search.IJavaSearchScope;
49
import org.eclipse.jdt.core.search.SearchEngine;
50
51
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
52
import org.eclipse.jdt.ui.JavaUI;
53
import org.eclipse.jdt.ui.PreferenceConstants;
54
55
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
56
import org.eclipse.jdt.internal.ui.JavaPluginImages;
57
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
58
import org.eclipse.jdt.internal.ui.dialogs.TextFieldNavigationHandler;
59
import org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock;
60
import org.eclipse.jdt.internal.ui.preferences.PreferencesMessages;
61
import org.eclipse.jdt.internal.ui.preferences.ScrolledPageContent;
62
import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
63
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
64
import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
65
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
66
import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
67
import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
68
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
69
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter;
70
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
71
import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
72
import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField;
73
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
74
75
/**
76
 * Call hierarchy preferences page configuration block.
77
 * 
78
 * @since 3.6
79
 */
80
public class CallHierarchyPreferencesConfigurationBlock extends OptionsConfigurationBlock {
81
82
	/**
83
	 * Call hierarchy preferences dialog for types and members.
84
	 */
85
	private static class CallHierarchyPreferencesDialog extends StatusDialog {
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
		private StringButtonDialogField fNameDialogField;
104
105
		private List fExistingEntries;
106
107
		private final boolean fIsEditingMember;
108
109
		/**
110
		 * Creates a call hierarchy preference dialog for members or types.
111
		 * 
112
		 * @param parent the parent shell
113
		 * @param existingEntries the existing list of types and members
114
		 * @param isEditingMember <code>true</code if its a member, <code>false</code> otherwise
115
		 */
116
		public CallHierarchyPreferencesDialog(Shell parent, List existingEntries, boolean isEditingMember) {
117
			super(parent);
118
			fIsEditingMember= isEditingMember;
119
			fExistingEntries= existingEntries;
120
121
			String label, title;
122
			if (isEditingMember) {
123
				title= PreferencesMessages.CallHierarchyPreferencesDialog_member_title;
124
				label= PreferencesMessages.CallHierarchyPreferencesDialog_member_labelText;
125
			} else {
126
				title= PreferencesMessages.CallHierarchyPreferencesDialog_type_title;
127
				label= PreferencesMessages.CallHierarchyPreferencesDialog_type_labelText;
128
			}
129
			setTitle(title);
130
131
			StringButtonAdapter adapter= new StringButtonAdapter();
132
133
			fNameDialogField= new StringButtonDialogField(adapter);
134
			fNameDialogField.setLabelText(label);
135
			fNameDialogField.setButtonLabel(PreferencesMessages.CallHierarchyPreferencesDialog_browse_button);
136
			fNameDialogField.setDialogFieldListener(adapter);
137
			fNameDialogField.setText(""); //$NON-NLS-1$
138
		}
139
140
		/*
141
		 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
142
		 * @since 3.4
143
		 */
144
		protected boolean isResizable() {
145
			return true;
146
		}
147
148
		/**
149
		 * Sets the initial selection in the name dialog field.
150
		 * 
151
		 * @param editedEntry the edited entry
152
		 */
153
		public void setInitialSelection(String editedEntry) {
154
			Assert.isNotNull(editedEntry);
155
			if (editedEntry.length() == 0)
156
				fNameDialogField.setText(""); //$NON-NLS-1$
157
			else
158
				fNameDialogField.setText(editedEntry);
159
		}
160
161
		public String getResult() {
162
			String val= fNameDialogField.getText();
163
			if (!fIsEditingMember)
164
				val= val + WILDCARD;
165
			return val;
166
		}
167
168
		/* (non-Javadoc)
169
		 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
170
		 */
171
		protected Control createDialogArea(Composite parent) {
172
			Composite composite= (Composite)super.createDialogArea(parent);
173
			initializeDialogUnits(parent);
174
175
			GridLayout layout= (GridLayout)composite.getLayout();
176
			layout.numColumns= 2;
177
178
			fNameDialogField.doFillIntoGrid(composite, 3);
179
180
			fNameDialogField.getChangeControl(null).setVisible(!fIsEditingMember);
181
182
			LayoutUtil.setHorizontalSpan(fNameDialogField.getLabelControl(null), 2);
183
184
			int fieldWidthHint= convertWidthInCharsToPixels(60);
185
			Text text= fNameDialogField.getTextControl(null);
186
			LayoutUtil.setWidthHint(text, fieldWidthHint);
187
			LayoutUtil.setHorizontalGrabbing(text);
188
			LayoutUtil.setHorizontalSpan(text, fIsEditingMember ? 2 : 1);
189
			TextFieldNavigationHandler.install(text);
190
191
			DialogField.createEmptySpace(composite, 1);
192
193
			fNameDialogField.postSetFocusOnDialogField(parent.getDisplay());
194
195
			applyDialogFont(composite);
196
			return composite;
197
		}
198
199
		/**
200
		 * Creates the type hierarchy for type selection.
201
		 */
202
		private void doBrowseTypes() {
203
			IRunnableContext context= new BusyIndicatorRunnableContext();
204
			IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
205
			int style= IJavaElementSearchConstants.CONSIDER_ALL_TYPES;
206
			try {
207
				SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), context, scope, style, false, fNameDialogField.getText());
208
				dialog.setTitle(PreferencesMessages.CallHierarchyPreferencesDialog_ChooseTypeDialog_title);
209
				dialog.setMessage(PreferencesMessages.CallHierarchyPreferencesDialog_ChooseTypeDialog_description);
210
				if (dialog.open() == Window.OK) {
211
					IType res= (IType)dialog.getResult()[0];
212
					fNameDialogField.setText(res.getFullyQualifiedName('.'));
213
				}
214
			} catch (JavaModelException e) {
215
				ExceptionHandler.handle(e, getShell(), PreferencesMessages.CallHierarchyPreferencesDialog_ChooseTypeDialog_title,
216
						PreferencesMessages.CallHierarchyPreferencesDialog_ChooseTypeDialog_error_message);
217
			}
218
		}
219
220
		/**
221
		 * Validates the entered type or member and updates the status.
222
		 */
223
		private void doValidation() {
224
			StatusInfo status= new StatusInfo();
225
			String newText= fNameDialogField.getText();
226
			if (newText.length() == 0) {
227
				status.setError(""); //$NON-NLS-1$
228
			} else {
229
				IStatus val= JavaConventions.validateJavaTypeName(newText, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
230
				if (val.matches(IStatus.ERROR)) {
231
					if (fIsEditingMember)
232
						status.setError(PreferencesMessages.CallHierarchyPreferencesDialog_error_invalidMemberName);
233
					else
234
						status.setError(PreferencesMessages.CallHierarchyPreferencesDialog_error_invalidTypeName);
235
				} else {
236
					if (doesExist(newText)) {
237
						status.setError(PreferencesMessages.CallHierarchyPreferencesDialog_error_entryExists);
238
					}
239
				}
240
			}
241
			updateStatus(status);
242
		}
243
244
		/**
245
		 * Checks if the entry already exists.
246
		 * 
247
		 * @param name the type or member name
248
		 * @return <code>true</code> if it already exists in the list of types and members,
249
		 *         <code>false</code> otherwise
250
		 */
251
		private boolean doesExist(String name) {
252
			for (int i= 0; i < fExistingEntries.size(); i++) {
253
				String entry= (String)fExistingEntries.get(i);
254
				if (name.equals(entry)) {
255
					return true;
256
				}
257
			}
258
			return false;
259
		}
260
261
262
		/*
263
		 * @see org.eclipse.jface.window.Window#configureShell(Shell)
264
		 */
265
		protected void configureShell(Shell newShell) {
266
			super.configureShell(newShell);
267
			PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.JAVA_EDITOR_PREFERENCE_PAGE);
268
		}
269
270
	}
271
272
	/* (non-Javadoc)
273
	 * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performOk()
274
	 */
275
	public boolean performOk() {
276
		PreferenceConstants.getPreferenceStore().setValue(CallHierarchyContentProvider.PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS, fIsAnonymous);
277
		return super.performOk();
278
	}
279
280
	/**
281
	 * The list label provider class.
282
	 */
283
	private static class ListLabelProvider extends LabelProvider {
284
285
		public final Image MEMBER_ICON;
286
287
		private final Image CLASS_ICON;
288
289
		public ListLabelProvider() {
290
			MEMBER_ICON= JavaElementImageProvider.getDecoratedImage(JavaPluginImages.DESC_MISC_PUBLIC, 0, JavaElementImageProvider.SMALL_SIZE);
291
			CLASS_ICON= JavaElementImageProvider.getDecoratedImage(JavaPluginImages.DESC_OBJS_CLASS, 0, JavaElementImageProvider.SMALL_SIZE);
292
		}
293
294
		/* (non-Javadoc)
295
		 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
296
		 */
297
		public Image getImage(Object element) {
298
			return ((String)element).endsWith(WILDCARD) ? CLASS_ICON : MEMBER_ICON;
299
		}
300
301
		/* (non-Javadoc)
302
		 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
303
		 */
304
		public String getText(Object element) {
305
			return BasicElementLabels.getJavaElementName((String)element);
306
		}
307
	}
308
309
310
	/**
311
	 * The change listener for <code>ListDialogField</code>.
312
	 */
313
	private class ListAdapter implements IListAdapter, IDialogFieldListener {
314
315
		/**
316
		 * Checks if field can be edited.
317
		 * 
318
		 * @param field the list dialog field
319
		 * @return <code>true</code> if it can be edited, <code>false</code> otherwise
320
		 */
321
		private boolean canEdit(ListDialogField field) {
322
			List selected= field.getSelectedElements();
323
			return selected.size() == 1 && canRemove(field);
324
		}
325
326
		/* (non-Javadoc)
327
		 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#customButtonPressed(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField, int)
328
		 */
329
		public void customButtonPressed(ListDialogField field, int index) {
330
			doButtonPressed(index);
331
		}
332
333
		/* (non-Javadoc)
334
		 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#selectionChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField)
335
		 */
336
		public void selectionChanged(ListDialogField field) {
337
			fList.enableButton(IDX_EDIT, canEdit(field));
338
			fList.enableButton(IDX_REMOVE, canRemove(field));
339
		}
340
341
		/**
342
		 * Checks if the field can be removed.
343
		 * 
344
		 * @param field the list dialog field
345
		 * @return <code>true</code> if it can be removed, <code>false</code> otherwise
346
		 */
347
		private boolean canRemove(ListDialogField field) {
348
			List selected= field.getSelectedElements();
349
			for (int j= 0; j < defaultTypes.length; j++) {
350
				if (selected.contains(defaultTypes[j]))
351
					return false;
352
			}
353
			return true;
354
		}
355
356
		/* (non-Javadoc)
357
		 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
358
		 */
359
		public void dialogFieldChanged(DialogField field) {
360
			doDialogFieldChanged(field);
361
		}
362
363
		/* (non-Javadoc)
364
		 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#doubleClicked(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField)
365
		 */
366
		public void doubleClicked(ListDialogField field) {
367
			if (canEdit(field)) {
368
				doButtonPressed(IDX_EDIT);
369
			}
370
		}
371
	}
372
373
	/**
374
	 * A named preference key that holds the types whose methods are by default expanded with
375
	 * constructors in the Call Hierarchy.
376
	 * 
377
	 * @since 3.6
378
	 */
379
	public static final Key CALL_HIERARCHY_PREFERENCES= getJDTUIKey(PreferenceConstants.CALL_HIERARCHY_PREFERENCES);
380
381
	private static final String WILDCARD= ".*"; //$NON-NLS-1$
382
383
	private static final int IDX_NEW_TYPE= 0;
384
	private static final int IDX_NEW_MEMBER= 1;
385
	private static final int IDX_EDIT= 2;
386
	private static final int IDX_REMOVE= 3;
387
388
	private ListDialogField fList;
389
390
	/**
391
	 * The array of types for default expand with constructors.
392
	 */
393
	String[] defaultTypes= { "java.lang.Runnable.*", "java.util.concurrent.Callable.*", "org.eclipse.swt.widgets.Listener.*" }; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
394
395
	private Button fAnonymousButton;
396
397
	protected boolean fIsAnonymous;
398
399
	/**
400
	 * Returns all the key values.
401
	 * 
402
	 * @return array of keys
403
	 */
404
	public static Key[] getAllKeys() {
405
		return new Key[] { CALL_HIERARCHY_PREFERENCES };
406
	}
407
408
409
	/**
410
	 * Creates the call hierarchy preferences configuration block.
411
	 * 
412
	 * @param context the status
413
	 * @param container the preference container
414
	 */
415
	public CallHierarchyPreferencesConfigurationBlock(IStatusChangeListener context, IWorkbenchPreferenceContainer container) {
416
		super(context, null, getAllKeys(), container);
417
	}
418
419
	/* (non-Javadoc)
420
	 * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#createContents(org.eclipse.swt.widgets.Composite)
421
	 */
422
	protected Control createContents(Composite parent) {
423
		ScrolledPageContent scrolled= new ScrolledPageContent(parent, SWT.H_SCROLL | SWT.V_SCROLL);
424
		scrolled.setExpandHorizontal(true);
425
		scrolled.setExpandVertical(true);
426
427
		Composite control= new Composite(scrolled, SWT.NONE);
428
		GridLayout layout= new GridLayout();
429
		layout.numColumns= 2;
430
		layout.marginWidth= 0;
431
		layout.marginHeight= 0;
432
		control.setLayout(layout);
433
434
		createPreferenceList(control);
435
436
		fAnonymousButton= new Button(parent, SWT.CHECK);
437
		fAnonymousButton.setText(CallHierarchyMessages.CallHierarchyPreferenceDialog_anonymousTypes_label);
438
		boolean anonymousPref= PreferenceConstants.getPreferenceStore().getBoolean(CallHierarchyContentProvider.PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS);
439
		fAnonymousButton.setSelection(anonymousPref);
440
		fAnonymousButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
441
		fAnonymousButton.addSelectionListener(new SelectionAdapter() {
442
			public void widgetSelected(SelectionEvent e) {
443
				fIsAnonymous= fAnonymousButton.getSelection();
444
445
			}
446
447
		});
448
449
		initialize();
450
451
		scrolled.setContent(control);
452
		final Point size= control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
453
		scrolled.setMinSize(size.x, size.y);
454
455
		Dialog.applyDialogFont(scrolled);
456
457
		return scrolled;
458
	}
459
460
	/**
461
	 * Create a list dialog field.
462
	 * 
463
	 * @param parent the composite
464
	 */
465
	private void createPreferenceList(Composite parent) {
466
		String[] buttonLabels= new String[] {
467
				PreferencesMessages.CallHierarchyPreferencesConfigurationBlock_newType_button,
468
				PreferencesMessages.CallHierarchyPreferencesConfigurationBlock_newMember_button,
469
				PreferencesMessages.CallHierarchyPreferencesConfigurationBlock_edit_button,
470
				PreferencesMessages.CallHierarchyPreferencesConfigurationBlock_remove_button
471
		};
472
473
		ListAdapter adapter= new ListAdapter();
474
475
		fList= new ListDialogField(adapter, buttonLabels, new ListLabelProvider());
476
		fList.setDialogFieldListener(adapter);
477
		fList.setLabelText(PreferencesMessages.CallHierarchyPreferencesConfigurationBlock_description);
478
		fList.setRemoveButtonIndex(IDX_REMOVE);
479
		fList.enableButton(IDX_EDIT, false);
480
		fList.setViewerComparator(new ViewerComparator());
481
482
		PixelConverter pixelConverter= new PixelConverter(parent);
483
484
		fList.doFillIntoGrid(parent, 3);
485
		LayoutUtil.setHorizontalSpan(fList.getLabelControl(null), 2);
486
		LayoutUtil.setWidthHint(fList.getLabelControl(null), pixelConverter.convertWidthInCharsToPixels(60));
487
		LayoutUtil.setHorizontalGrabbing(fList.getListControl(null));
488
489
		Control listControl= fList.getListControl(null);
490
		GridData gd= (GridData)listControl.getLayoutData();
491
		gd.verticalAlignment= GridData.BEGINNING;
492
		gd.heightHint= pixelConverter.convertHeightInCharsToPixels(7);
493
494
	}
495
496
	/**
497
	 * Initialize the elements of the list dialog field.
498
	 */
499
	public void initialize() {
500
		initializeFields();
501
	}
502
503
	/**
504
	 * Initialize the elements of the list dialog field.
505
	 */
506
	private void initializeFields() {
507
		List storedPreference= new ArrayList();
508
		storedPreference.addAll(Arrays.asList(getCallHierarchyPreferences()));
509
		if (!storedPreference.contains(defaultTypes[0])) {
510
			storedPreference.addAll(Arrays.asList(defaultTypes));
511
		}
512
		fList.setElements(storedPreference);
513
	}
514
515
	/* (non-Javadoc)
516
	 * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#performDefaults()
517
	 */
518
	public void performDefaults() {
519
		super.performDefaults();
520
		fList.setElements(Arrays.asList(defaultTypes));
521
	}
522
523
	/* (non-Javadoc)
524
	 * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#getFullBuildDialogStrings(boolean)
525
	 */
526
	protected String[] getFullBuildDialogStrings(boolean workspaceSettings) {
527
		return null;
528
	}
529
530
	/* (non-Javadoc)
531
	 * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#validateSettings(org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock.Key, java.lang.String, java.lang.String)
532
	 */
533
	protected void validateSettings(Key changedKey, String oldValue, String newValue) {
534
535
	}
536
537
	/**
538
	 * Perform the 'New' and 'Edit' button operations by opening the respective call hierarchy
539
	 * preferences dialog.
540
	 * 
541
	 * @param index the index of the button
542
	 */
543
	private void doButtonPressed(int index) {
544
		if (index == IDX_NEW_TYPE || index == IDX_NEW_MEMBER) { // add new
545
			List existing= fList.getElements();
546
			CallHierarchyPreferencesDialog dialog= new CallHierarchyPreferencesDialog(getShell(), existing, index == IDX_NEW_MEMBER);
547
			if (dialog.open() == Window.OK) {
548
				fList.addElement(dialog.getResult());
549
			}
550
		} else if (index == IDX_EDIT) { // edit
551
			List selected= fList.getSelectedElements();
552
			if (selected.isEmpty())
553
				return;
554
555
			String editedEntry= (String)selected.get(0);
556
557
			List existing= fList.getElements();
558
			existing.remove(editedEntry);
559
			boolean isType= editedEntry.endsWith(WILDCARD);
560
			CallHierarchyPreferencesDialog dialog= new CallHierarchyPreferencesDialog(getShell(), existing, !isType);
561
			if (isType)
562
				dialog.setInitialSelection(editedEntry.substring(0, editedEntry.length() - 2));
563
			else
564
				dialog.setInitialSelection(editedEntry);
565
566
			if (dialog.open() == Window.OK) {
567
				fList.replaceElement(editedEntry, dialog.getResult());
568
			}
569
		}
570
	}
571
572
	/**
573
	 * Update the preference keys and constants.
574
	 * 
575
	 * @param field the dialog field
576
	 */
577
	protected final void doDialogFieldChanged(DialogField field) {
578
		// set values in working copy
579
		if (field == fList) {
580
			setValue(CALL_HIERARCHY_PREFERENCES, serializeFavorites(fList.getElements()));
581
			PreferenceConstants.getPreferenceStore().setValue(CallHierarchyContentProvider.CALL_HIERARCHY_PREFERENCES, serializeFavorites(fList.getElements()));
582
		}
583
	}
584
585
	/**
586
	 * Returns the call hierarchy preferences.
587
	 * 
588
	 * @return the call hierarchy preferences
589
	 */
590
	private String[] getCallHierarchyPreferences() {
591
		String str= getValue(CALL_HIERARCHY_PREFERENCES);
592
		if (str != null && str.length() > 0)
593
			return deserializeFavorites(str);
594
		return new String[0];
595
	}
596
597
	/**
598
	 * Return the array of types and/or members after splitting the stored preference string.
599
	 * 
600
	 * @param str the input string
601
	 * @return the array of types and/or members
602
	 */
603
	private static String[] deserializeFavorites(String str) {
604
		return str.split(";"); //$NON-NLS-1$
605
	}
606
607
	/**
608
	 * Creates a single output string from the list of strings using a delimiter.
609
	 * 
610
	 * @param str the input string
611
	 * @return the single output string from the list of strings using a delimiter
612
	 */
613
	private static String serializeFavorites(List str) {
614
		int size= str.size();
615
		StringBuffer buf= new StringBuffer();
616
		for (int i= 0; i < size; i++) {
617
			buf.append((String)str.get(i));
618
			if (i < size - 1)
619
				buf.append(';');
620
		}
621
		return buf.toString();
622
	}
623
624
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyPreferencePage.java (+119 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 org.eclipse.swt.widgets.Composite;
13
import org.eclipse.swt.widgets.Control;
14
15
import org.eclipse.core.resources.IProject;
16
17
import org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage;
18
19
/**
20
 * Call Hierarchy view menu preference page.
21
 * 
22
 * @since 3.6
23
 * 
24
 */
25
public class CallHierarchyPreferencePage extends PropertyAndPreferencePage {
26
27
	private CallHierarchyPreferencesConfigurationBlock fConfigurationBlock;
28
29
	/**
30
	 * Creates a call hierarchy preference page and sets the title.
31
	 */
32
	public CallHierarchyPreferencePage() {
33
		super();
34
		setTitle(CallHierarchyMessages.CallHierarchyPreferencePage_expand_with_constructors_title);
35
	}
36
37
	/* (non-Javadoc)
38
	 * @see org.eclipse.jface.preference.PreferencePage#createControl(org.eclipse.swt.widgets.Composite)
39
	 */
40
	public void createControl(Composite parent) {
41
		//IWorkbenchPreferenceContainer container= (IWorkbenchPreferenceContainer)getContainer();
42
		fConfigurationBlock= new CallHierarchyPreferencesConfigurationBlock(getNewStatusChangedListener(), null);
43
		super.createControl(parent);
44
		//PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.JAVA_EDITOR_PREFERENCE_PAGE);
45
	}
46
47
	/* (non-Javadoc)
48
	 * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#createPreferenceContent(org.eclipse.swt.widgets.Composite)
49
	 */
50
	protected Control createPreferenceContent(Composite composite) {
51
		return fConfigurationBlock.createContents(composite);
52
	}
53
54
	/* (non-Javadoc)
55
	 * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#getPreferencePageID()
56
	 */
57
	protected String getPreferencePageID() {
58
		return "org.eclipse.jdt.ui.preferences.CallHierarchyPreferencePage"; //$NON-NLS-1$
59
	}
60
61
	/* (non-Javadoc)
62
	 * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#getPropertyPageID()
63
	 */
64
	protected String getPropertyPageID() {
65
		return null;
66
	}
67
68
	/* (non-Javadoc)
69
	 * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#hasProjectSpecificOptions(org.eclipse.core.resources.IProject)
70
	 */
71
	protected boolean hasProjectSpecificOptions(IProject project) {
72
		return false;
73
	}
74
75
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
78
	 */
79
	public void dispose() {
80
		if (fConfigurationBlock != null) {
81
			fConfigurationBlock.dispose();
82
		}
83
		super.dispose();
84
	}
85
86
87
	/* (non-Javadoc)
88
	 * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#performDefaults()
89
	 */
90
	protected void performDefaults() {
91
		super.performDefaults();
92
		if (fConfigurationBlock != null) {
93
			fConfigurationBlock.performDefaults();
94
		}
95
	}
96
97
98
	/* (non-Javadoc)
99
	 * @see org.eclipse.jface.preference.PreferencePage#performOk()
100
	 */
101
	public boolean performOk() {
102
		if (fConfigurationBlock != null && !fConfigurationBlock.performOk()) {
103
			return false;
104
		}
105
		return super.performOk();
106
	}
107
108
109
	/* (non-Javadoc)
110
	 * @see org.eclipse.jface.preference.PreferencePage#performApply()
111
	 */
112
	public void performApply() {
113
		if (fConfigurationBlock != null) {
114
			fConfigurationBlock.performApply();
115
		}
116
	}
117
118
119
}

Return to bug 276466