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 (-5 / +20 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 88-93 Link Here
88
	public static String CallHierarchyViewPart_callsFromMembers_3;
87
	public static String CallHierarchyViewPart_callsFromMembers_3;
89
	public static String CallHierarchyViewPart_callsFromMembers_more;
88
	public static String CallHierarchyViewPart_callsFromMembers_more;
90
	public static String CallHierarchyViewPart_callsFromMethod;
89
	public static String CallHierarchyViewPart_callsFromMethod;
90
	public static String ExpandWithConstructorsConfigurationBlock_description;
91
	public static String ExpandWithConstructorsConfigurationBlock_newType_button;
92
	public static String ExpandWithConstructorsConfigurationBlock_newMember_button;
93
	public static String ExpandWithConstructorsConfigurationBlock_edit_button;
94
	public static String ExpandWithConstructorsConfigurationBlock_remove_button;
95
	public static String ExpandWithConstructorsConfigurationBlock_restoreDefaults_button;
96
	public static String CallHierarchyTypesOrMembersDialog_member_title;
97
	public static String CallHierarchyTypesOrMembersDialog_member_labelText;
98
	public static String CallHierarchyTypesOrMembersDialog_type_title;
99
	public static String CallHierarchyTypesOrMembersDialog_type_labelText;
100
	public static String CallHierarchyTypesOrMembersDialog_browse_button;
101
	public static String CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_title;
102
	public static String CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_description;
103
	public static String CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_error_message;
104
	public static String CallHierarchyTypesOrMembersDialog_error_enterName;
105
	public static String CallHierarchyTypesOrMembersDialog_error_invalidMemberName;
106
	public static String CallHierarchyTypesOrMembersDialog_error_invalidTypeName;
107
	public static String CallHierarchyTypesOrMembersDialog_error_entryExists;
108
	public static String CallHierarchyTypesOrMembersDialog_anonymousTypes_label;
91
	public static String FocusOnSelectionAction_focusOnSelection_text;
109
	public static String FocusOnSelectionAction_focusOnSelection_text;
92
	public static String FocusOnSelectionAction_focusOnSelection_description;
110
	public static String FocusOnSelectionAction_focusOnSelection_description;
93
	public static String FocusOnSelectionAction_focusOnSelection_tooltip;
111
	public static String FocusOnSelectionAction_focusOnSelection_tooltip;
Lines 139-149 Link Here
139
	public static String ExpandWithConstructorsAction_expandWithConstructors_text;
157
	public static String ExpandWithConstructorsAction_expandWithConstructors_text;
140
	public static String ExpandWithConstructorsAction_expandWithConstructors_description;
158
	public static String ExpandWithConstructorsAction_expandWithConstructors_description;
141
	public static String ExpandWithConstructorsAction_expandWithConstructors_tooltip;
159
	public static String ExpandWithConstructorsAction_expandWithConstructors_tooltip;
142
	public static String ExpandWithConstructorsDialog_anonymousTypes_label;
160
	public static String ExpandWithConstructorsDialogAction_expandWithConstructors_label;
143
	public static String ExpandWithConstructorsDialog_explanation_label;
144
	public static String ExpandWithConstructorsDialog_not_a_valid_type_name;
145
	public static String ExpandWithConstructorsDialog_title;
161
	public static String ExpandWithConstructorsDialog_title;
146
	public static String ExpandWithConstructorsDialog_typeNames_label;
147
	static {
162
	static {
148
		NLS.initializeMessages(BUNDLE_NAME, CallHierarchyMessages.class);
163
		NLS.initializeMessages(BUNDLE_NAME, CallHierarchyMessages.class);
149
	}
164
	}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyMessages.properties (-6 / +24 lines)
Lines 55-61 Link Here
55
ToggleOrientationAction_single_tooltip=Hierarchy Only
55
ToggleOrientationAction_single_tooltip=Hierarchy Only
56
ToggleOrientationAction_single_description=Hierarchy Only
56
ToggleOrientationAction_single_description=Hierarchy 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 146-153 Link Here
146
ExpandWithConstructorsAction_expandWithConstructors_text= &Expand with Constructors
145
ExpandWithConstructorsAction_expandWithConstructors_text= &Expand with Constructors
147
ExpandWithConstructorsAction_expandWithConstructors_description= Expand with constructors
146
ExpandWithConstructorsAction_expandWithConstructors_description= Expand with constructors
148
ExpandWithConstructorsAction_expandWithConstructors_tooltip= Expand with Constructors
147
ExpandWithConstructorsAction_expandWithConstructors_tooltip= Expand with Constructors
149
ExpandWithConstructorsDialog_anonymousTypes_label=&All methods in anonymous types
148
ExpandWithConstructorsDialogAction_expandWithConstructors_label= E&xpand with Constructors...
150
ExpandWithConstructorsDialog_explanation_label=Configure the types whose instance methods are expanded with constructors by default.
149
ExpandWithConstructorsDialog_title= Expand with Constructors
151
ExpandWithConstructorsDialog_not_a_valid_type_name=''{0}'' is not a valid type name
150
152
ExpandWithConstructorsDialog_title=Expand with Constructors
151
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.
153
ExpandWithConstructorsDialog_typeNames_label=Type &names (each on a line):
152
ExpandWithConstructorsConfigurationBlock_newType_button= New &Type...
153
ExpandWithConstructorsConfigurationBlock_newMember_button= New &Member...
154
ExpandWithConstructorsConfigurationBlock_edit_button= &Edit...
155
ExpandWithConstructorsConfigurationBlock_remove_button= &Remove 
156
ExpandWithConstructorsConfigurationBlock_restoreDefaults_button= Restore &Defaults
157
158
CallHierarchyTypesOrMembersDialog_member_title= New Member for Expand With Constructors
159
CallHierarchyTypesOrMembersDialog_member_labelText= Enter a fully qualified non-static, non-constructor member (e.g. \'java.lang.Runnable.run\'): 
160
CallHierarchyTypesOrMembersDialog_type_title= New Type for Expand With Constructors
161
CallHierarchyTypesOrMembersDialog_type_labelText= Enter a fully qualified type (e.g. \'java.lang.Runnable\'):
162
CallHierarchyTypesOrMembersDialog_browse_button= &Browse...
163
CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_title= Type Selection
164
CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_description= Choose type name:
165
CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_error_message= A problem occurred while collecting types. See the error Log for details.
166
CallHierarchyTypesOrMembersDialog_error_enterName=Enter a name or prefix.
167
CallHierarchyTypesOrMembersDialog_error_invalidTypeName=Not a valid type name.
168
CallHierarchyTypesOrMembersDialog_error_invalidMemberName=Not a valid member name.
169
CallHierarchyTypesOrMembersDialog_error_entryExists=Entry already exists in list.
170
CallHierarchyTypesOrMembersDialog_anonymousTypes_label=&All methods in anonymous types
171
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/ExpandWithConstructorsDialog.java (-79 / +16 lines)
Lines 10-41 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
20
import org.eclipse.jface.dialogs.Dialog;
26
import org.eclipse.jface.dialogs.StatusDialog;
21
import org.eclipse.jface.dialogs.StatusDialog;
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.
Lines 44-54 Link Here
44
 */
32
 */
45
class ExpandWithConstructorsDialog extends StatusDialog {
33
class ExpandWithConstructorsDialog extends StatusDialog {
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/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 ExpandWithConstructorsActionGroup fExpandWithConstructorsActionGroup;
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
        fExpandWithConstructorsActionGroup= new ExpandWithConstructorsActionGroup(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, fExpandWithConstructorsActionGroup
1039
                });
1041
                });
1040
    }
1042
    }
1041
1043
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyContentProvider.java (-20 / +40 lines)
Lines 45-54 Link Here
45
public class CallHierarchyContentProvider implements ITreeContentProvider {
45
public class CallHierarchyContentProvider implements ITreeContentProvider {
46
46
47
	/**
47
	/**
48
	 * A named preference that holds the types whose methods are by default expanded with
48
	 * A named preference that holds the methods or types whose methods are by default expanded with
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 or method names.
52
	 * </p>
52
	 * </p>
53
	 * 
53
	 * 
54
	 * @since 3.5
54
	 * @since 3.5
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-253 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.5
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 serializedTypesAndMembers= PreferenceConstants.getPreferenceStore().getString(PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS);
229
		if (serializedTypes.length() == 0)
229
		if (serializedTypesAndMembers.length() == 0)
230
			return false;
230
			return false;
231
		
231
		String member= wrapper.getMember().getElementName();
232
		String[] defaultTypes= serializedTypes.split(";"); //$NON-NLS-1$
232
		IType declaringType= wrapper.getMember().getDeclaringType();
233
		
233
		String[] defaultTypesOrMembers= serializedTypesAndMembers.split(";"); //$NON-NLS-1$
234
		String typeName= type.getFullyQualifiedName('.');
234
235
		String declaringTypeName= declaringType.getFullyQualifiedName('.').concat(".*"); //$NON-NLS-1$;
236
		String qualifiedMemberName= declaringType.getFullyQualifiedName('.').concat(".").concat(member); //$NON-NLS-1$
235
		String superClass;
237
		String superClass;
236
		String[] superInterfaces;
238
		String[] superInterfaces;
237
		try {
239
		try {
238
			superClass= type.getSuperclassName();
240
			superClass= declaringType.getSuperclassName();
239
			superInterfaces= type.getSuperInterfaceNames();
241
			superInterfaces= declaringType.getSuperInterfaceNames();
240
		} catch (JavaModelException e) {
242
		} catch (JavaModelException e) {
241
			return false;
243
			return false;
242
		}
244
		}
243
		for (int i= 0; i < defaultTypes.length; i++) {
245
		for (int i= 0; i < defaultTypesOrMembers.length; i++) {
244
			String defaultType= defaultTypes[i];
246
			String defaultTypeOrMember= defaultTypesOrMembers[i];
245
			if (typeName.equals(defaultType) || (superClass != null && typeNameMatches(superClass, defaultType))) {
247
			if (qualifiedMemberName.equals(defaultTypeOrMember) || declaringTypeName.equals(defaultTypeOrMember)
248
					|| (typeNameMatches(member, defaultTypeOrMember) && superClass != null && defaultTypeOrMember.endsWith(superClass.concat(".").concat(member))) //$NON-NLS-1$
249
							|| checkSuperClassMatch(superClass, defaultTypeOrMember)) {
246
				return true;
250
				return true;
247
			}
251
			}
248
			if (superInterfaces.length > 0) {
252
			if (superInterfaces.length > 0) {
249
				for (int j= 0; j < superInterfaces.length; j++) {
253
				for (int j= 0; j < superInterfaces.length; j++) {
250
					if (typeNameMatches(superInterfaces[j], defaultType))
254
					if (typeNameMatches(superInterfaces[j].concat(".*"), defaultTypeOrMember)) //$NON-NLS-1$
251
						return true;
255
						return true;
252
				}
256
				}
253
			}
257
			}
Lines 256-261 Link Here
256
	}
260
	}
257
261
258
	/**
262
	/**
263
	 * Check whether the given super class name matches the given default type.
264
	 *
265
	 * @param superClass the super class name
266
	 * @param defaultTypeOrMember the default type or member from the default list
267
	 *
268
	 * @return <code>true</code> if super class matches with the given type , <code>false></code> otherwise
269
	 * @since 3.6
270
	 */
271
	private static boolean checkSuperClassMatch(String superClass, String defaultTypeOrMember) {
272
		if (defaultTypeOrMember.endsWith(".*")){ //$NON-NLS-1$
273
			defaultTypeOrMember= defaultTypeOrMember.substring(0, defaultTypeOrMember.length() - 2);
274
		}
275
		return (superClass != null && typeNameMatches(superClass, defaultTypeOrMember));
276
	}
277
278
	/**
259
	 * Checks whether the two type names match. They match if they
279
	 * 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.
280
	 * are equal, or if could be the same type but one is missing the package.
261
	 * 
281
	 * 
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/ExpandWithConstructorsConfigurationBlock.java (+626 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
		PreferenceConstants.getPreferenceStore().setValue(CallHierarchyContentProvider.PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS, serializeFavorites(fList.getElements()));
291
		PreferenceConstants.getPreferenceStore().setValue(CallHierarchyContentProvider.PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS, fIsAnonymous);
292
		return super.performOk();
293
	}
294
295
	/**
296
	 * The list label provider class.
297
	 */
298
	private static class ListLabelProvider extends LabelProvider {
299
300
		public final Image MEMBER_ICON;
301
302
		private final Image CLASS_ICON;
303
304
		/**
305
		 * Create the member and class icons.
306
		 */
307
		public ListLabelProvider() {
308
			MEMBER_ICON= JavaElementImageProvider.getDecoratedImage(JavaPluginImages.DESC_MISC_PUBLIC, 0, JavaElementImageProvider.SMALL_SIZE);
309
			CLASS_ICON= JavaElementImageProvider.getDecoratedImage(JavaPluginImages.DESC_OBJS_CLASS, 0, JavaElementImageProvider.SMALL_SIZE);
310
		}
311
312
		/*
313
		 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
314
		 */
315
		public Image getImage(Object element) {
316
			return ((String)element).endsWith(WILDCARD) ? CLASS_ICON : MEMBER_ICON;
317
		}
318
319
		/*
320
		 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
321
		 */
322
		public String getText(Object element) {
323
			return BasicElementLabels.getJavaElementName((String)element);
324
		}
325
	}
326
327
328
	/**
329
	 * The change listener for <code>ListDialogField</code>.
330
	 */
331
	private class ListAdapter implements IListAdapter, IDialogFieldListener {
332
333
		/**
334
		 * Checks if field can be edited.
335
		 *
336
		 * @param field the list dialog field
337
		 * @return <code>true</code> if it can be edited, <code>false</code> otherwise
338
		 */
339
		private boolean canEdit(ListDialogField field) {
340
			List selected= field.getSelectedElements();
341
			return selected.size() == 1;
342
		}
343
344
		/*
345
		 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#customButtonPressed(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField, int)
346
		 */
347
		public void customButtonPressed(ListDialogField field, int index) {
348
			doButtonPressed(index);
349
		}
350
351
		/*
352
		 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#selectionChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField)
353
		 */
354
		public void selectionChanged(ListDialogField field) {
355
			fList.enableButton(IDX_EDIT, canEdit(field));
356
			fList.enableButton(IDX_REMOVE, canRemove(field));
357
		}
358
359
		/**
360
		 * Checks if the field can be removed.
361
		 *
362
		 * @param field the list dialog field
363
		 * @return <code>true</code> if it can be removed, <code>false</code> otherwise
364
		 */
365
		private boolean canRemove(ListDialogField field) {
366
			List selected= field.getSelectedElements();
367
			return selected.size() != 0;
368
		}
369
370
		/* )
371
		 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
372
		 */
373
		public void dialogFieldChanged(DialogField field) {
374
			doDialogFieldChanged(field);
375
		}
376
377
		/*
378
		 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#doubleClicked(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField)
379
		 */
380
		public void doubleClicked(ListDialogField field) {
381
			if (canEdit(field)) {
382
				doButtonPressed(IDX_EDIT);
383
			}
384
		}
385
	}
386
387
	private static final String WILDCARD= ".*"; //$NON-NLS-1$
388
389
	private static final int IDX_NEW_TYPE= 0;
390
	private static final int IDX_NEW_MEMBER= 1;
391
	private static final int IDX_EDIT= 2;
392
	private static final int IDX_REMOVE= 3;
393
	private static final int IDX_RESTORE_DEFAULTS= 4;
394
395
	private ListDialogField fList;
396
397
	/**
398
	 * The array of types for default expand with constructors.
399
	 */
400
	String[] defaultTypes= { "java.lang.Runnable.*", "java.util.concurrent.Callable.*", "org.eclipse.swt.widgets.Listener.*" }; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
401
402
	private Button fAnonymousButton;
403
404
	protected boolean fIsAnonymous;
405
406
	/**
407
	 * A key that holds the list of methods or types whose methods are by default expanded with constructors.
408
	 */
409
	private static Key DEFAULT_EXPAND_WITH_CONSTRUCTORS= getJDTUIKey(PreferenceConstants.getPreferenceStore().getString(CallHierarchyContentProvider.PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS));
410
411
	/**
412
	 * Returns all the key values.
413
	 *
414
	 * @return array of keys
415
	 */
416
	public static Key[] getAllKeys() {
417
		return new Key[] {DEFAULT_EXPAND_WITH_CONSTRUCTORS};
418
	}
419
420
421
	/**
422
	 * Creates the call hierarchy preferences configuration block.
423
	 *
424
	 * @param context the status
425
	 * @param container the preference container
426
	 */
427
	public ExpandWithConstructorsConfigurationBlock(IStatusChangeListener context, IWorkbenchPreferenceContainer container) {
428
		super(context, null, getAllKeys(), container);
429
	}
430
431
	/*
432
	 * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#createContents(org.eclipse.swt.widgets.Composite)
433
	 */
434
	protected Control createContents(Composite parent) {
435
		Composite control= new Composite(parent, SWT.NONE);
436
		GridLayout layout= new GridLayout();
437
		layout.numColumns= 2;
438
		layout.marginWidth= 10;
439
		layout.marginHeight= 10;
440
		control.setLayout(layout);
441
442
		createPreferenceList(control);
443
444
		fAnonymousButton= new Button(control, SWT.CHECK);
445
		fAnonymousButton.setText(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_anonymousTypes_label);
446
		boolean anonymousPref= PreferenceConstants.getPreferenceStore().getBoolean(CallHierarchyContentProvider.PREF_ANONYMOUS_EXPAND_WITH_CONSTRUCTORS);
447
		fAnonymousButton.setSelection(anonymousPref);
448
		fAnonymousButton.setLayoutData(new GridData(SWT.LEAD, SWT.TOP, false, false));
449
		fAnonymousButton.addSelectionListener(new SelectionAdapter() {
450
			public void widgetSelected(SelectionEvent e) {
451
				fIsAnonymous= fAnonymousButton.getSelection();
452
			}
453
454
		});
455
456
		initialize();
457
458
		Dialog.applyDialogFont(control);
459
460
		return control;
461
	}
462
463
	/**
464
	 * Create a list dialog field.
465
	 *
466
	 * @param parent the composite
467
	 */
468
	private void createPreferenceList(Composite parent) {
469
		String[] buttonLabels= new String[] {
470
				CallHierarchyMessages.ExpandWithConstructorsConfigurationBlock_newType_button,
471
				CallHierarchyMessages.ExpandWithConstructorsConfigurationBlock_newMember_button,
472
				CallHierarchyMessages.ExpandWithConstructorsConfigurationBlock_edit_button,
473
				CallHierarchyMessages.ExpandWithConstructorsConfigurationBlock_remove_button,
474
				CallHierarchyMessages.ExpandWithConstructorsConfigurationBlock_restoreDefaults_button
475
		};
476
477
		ListAdapter adapter= new ListAdapter();
478
479
		fList= new ListDialogField(adapter, buttonLabels, new ListLabelProvider());
480
		fList.setDialogFieldListener(adapter);
481
		fList.setLabelText(CallHierarchyMessages.ExpandWithConstructorsConfigurationBlock_description);
482
		fList.setRemoveButtonIndex(IDX_REMOVE);
483
		fList.enableButton(IDX_EDIT, false);
484
		fList.setViewerComparator(new ViewerComparator());
485
486
		PixelConverter pixelConverter= new PixelConverter(parent);
487
488
		fList.doFillIntoGrid(parent, 3);
489
		LayoutUtil.setHorizontalSpan(fList.getLabelControl(null), 2);
490
		LayoutUtil.setWidthHint(fList.getLabelControl(null), pixelConverter.convertWidthInCharsToPixels(60));
491
		LayoutUtil.setHorizontalGrabbing(fList.getListControl(null));
492
493
		Control listControl= fList.getListControl(null);
494
		GridData gd= (GridData)listControl.getLayoutData();
495
		gd.verticalAlignment= GridData.BEGINNING;
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(getExpandWithConstructorsKey()));
512
		fList.setElements(storedPreference);
513
	}
514
515
	/*
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
	/*
524
	 * @see org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock#getFullBuildDialogStrings(boolean)
525
	 */
526
	protected String[] getFullBuildDialogStrings(boolean workspaceSettings) {
527
		return null;
528
	}
529
530
	/*
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, and 'Restore Defaults' button by restoring to default values for the list 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
			CallHierarchyTypesOrMembersDialog dialog= new CallHierarchyTypesOrMembersDialog(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
			CallHierarchyTypesOrMembersDialog dialog= new CallHierarchyTypesOrMembersDialog(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
		} else if (index == IDX_RESTORE_DEFAULTS){
570
			performDefaults();
571
		}
572
	}
573
574
	/**
575
	 * Update the key on dialog field change.
576
	 *
577
	 * @param field the dialog field
578
	 */
579
	protected final void doDialogFieldChanged(DialogField field) {
580
		// set values in working copy
581
		if (field == fList) {
582
			setValue(DEFAULT_EXPAND_WITH_CONSTRUCTORS, serializeFavorites(fList.getElements()));
583
		}
584
	}
585
586
	/**
587
	 * Returns the key that holds the user preferences for default expand with constructors.
588
	 *
589
	 * @return the call hierarchy expand with constructors key
590
	 */
591
	private String[] getExpandWithConstructorsKey() {
592
		setValue(DEFAULT_EXPAND_WITH_CONSTRUCTORS, PreferenceConstants.getPreferenceStore().getString(CallHierarchyContentProvider.PREF_DEFAULT_EXPAND_WITH_CONSTRUCTORS));
593
		String str= getValue(DEFAULT_EXPAND_WITH_CONSTRUCTORS);
594
		if (str != null && str.length() > 0)
595
			return deserializeFavorites(str);
596
		return new String[0];
597
	}
598
599
	/**
600
	 * Return the array of types and/or members after splitting the stored preference string.
601
	 *
602
	 * @param str the input string
603
	 * @return the array of types and/or members
604
	 */
605
	private static String[] deserializeFavorites(String str) {
606
		return str.split(";"); //$NON-NLS-1$
607
	}
608
609
	/**
610
	 * Creates a single output string from the list of strings using a delimiter.
611
	 *
612
	 * @param str the input string
613
	 * @return the single output string from the list of strings using a delimiter
614
	 */
615
	private static String serializeFavorites(List str) {
616
		int size= str.size();
617
		StringBuffer buf= new StringBuffer();
618
		for (int i= 0; i < size; i++) {
619
			buf.append((String)str.get(i));
620
			if (i < size - 1)
621
				buf.append(';');
622
		}
623
		return buf.toString();
624
	}
625
626
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/ExpandWithConstructorsActionGroup.java (+81 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.Shell;
13
14
import org.eclipse.jface.action.Action;
15
import org.eclipse.jface.action.IMenuManager;
16
import org.eclipse.jface.action.Separator;
17
18
import org.eclipse.ui.IActionBars;
19
import org.eclipse.ui.actions.ActionGroup;
20
21
/**
22
 * Call Hierarchy expand with constructors action group.
23
 *
24
 * @since 3.6
25
 *
26
 */
27
public class ExpandWithConstructorsActionGroup extends ActionGroup {
28
	private CallHierarchyViewPart fPart;
29
30
	/**
31
	 * Creates the expand with constructors action group.
32
	 *
33
	 * @param part the call hierarchy view part
34
	 */
35
	public ExpandWithConstructorsActionGroup(CallHierarchyViewPart part) {
36
		fPart= part;
37
	}
38
39
	/**
40
	 * Call hierarchy expand with constructors action class.
41
	 *
42
	 */
43
	public class ExpandWithConstructorsDialogAction extends Action {
44
45
		/**
46
		 * Creates the call hierarchy expand with constructors action.
47
		 */
48
		public ExpandWithConstructorsDialogAction() {
49
			setText(CallHierarchyMessages.ExpandWithConstructorsDialogAction_expandWithConstructors_label);
50
		}
51
52
		/*
53
		 * @see org.eclipse.jface.action.Action#run()
54
		 */
55
		public void run() {
56
			Shell shell= fPart.getViewSite().getShell();
57
			ExpandWithConstructorsDialog dialog= new ExpandWithConstructorsDialog(shell);
58
			dialog.open();
59
		}
60
	}
61
62
63
	/*
64
	 * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
65
	 */
66
	public void fillActionBars(IActionBars actionBars) {
67
		fillViewMenu(actionBars.getMenuManager());
68
	}
69
70
71
	/**
72
	 * Fills the action to the view menu.
73
	 * @param viewMenu the menu manager
74
	 */
75
	private void fillViewMenu(IMenuManager viewMenu) {
76
		viewMenu.add(new Separator("expandWithConstructors")); //$NON-NLS-1$
77
		viewMenu.add(new ExpandWithConstructorsDialogAction());
78
	}
79
80
81
}

Return to bug 276466