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