Skip to content

Commit 4b7d072

Browse files
committed
Filter menu in callHierarchy changes applied
1 parent 074c7dc commit 4b7d072

5 files changed

Lines changed: 267 additions & 1 deletion

File tree

org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallHierarchyCore.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ public boolean isShowAll() {
8282
public boolean isHideTestCode() {
8383
return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_HIDE_TEST_CODE, null));
8484
}
85+
public String getActiveFilter() {
86+
if(isShowAll()) {
87+
return PREF_SHOW_ALL_CODE;
88+
} else if(isHideTestCode()) {
89+
return PREF_HIDE_TEST_CODE;
90+
} else {
91+
return PREF_SHOW_TEST_CODE_ONLY;
92+
}
93+
}
8594

8695
public Collection<IJavaElement> getImplementingMethods(IMethod method) {
8796
if (isSearchUsingImplementorsEnabled()) {
@@ -328,4 +337,14 @@ public static boolean isPossibleInputElement(Object element){
328337

329338
return true;
330339
}
340+
341+
public String getCurrentSelection() {
342+
if(isShowAll()) {
343+
return PREF_SHOW_ALL_CODE;
344+
} else if(isHideTestCode()) {
345+
return PREF_HIDE_TEST_CODE;
346+
} else {
347+
return PREF_SHOW_TEST_CODE_ONLY;
348+
}
349+
}
331350
}

org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyViewPart.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
import org.eclipse.jdt.core.search.IJavaSearchScope;
9999

100100
import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy;
101+
import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore;
101102
import org.eclipse.jdt.internal.corext.callhierarchy.CallLocation;
102103
import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
103104
import org.eclipse.jdt.internal.corext.callhierarchy.RealCallers;
@@ -227,6 +228,7 @@ protected void open(ISelection selection, boolean activate) {
227228
private SelectFieldModeAction[] fToggleFieldModeActions;
228229
private CallHierarchyFiltersActionGroup fFiltersActionGroup;
229230
private HistoryDropDownAction fHistoryDropDownAction;
231+
private FilterDropDownAction fFilterDropDownAction;
230232
private RefreshElementAction fRefreshSingleElementAction;
231233
private RefreshViewAction fRefreshViewAction;
232234
private OpenLocationAction fOpenLocationAction;
@@ -395,6 +397,40 @@ void setFieldMode(int mode) {
395397
}
396398
}
397399

400+
void setFilterMode(String mode) {
401+
402+
if(mode == CallHierarchyCore.getDefault().getCurrentSelection()) {
403+
return;
404+
}
405+
406+
407+
switch(mode) {
408+
case CallHierarchyCore.PREF_SHOW_ALL_CODE:
409+
CallHierarchy.getDefault().setShowAll(true);
410+
CallHierarchy.getDefault().setHideTestCode(false);
411+
CallHierarchy.getDefault().setShowTestCode(false);
412+
413+
break;
414+
415+
case CallHierarchyCore.PREF_HIDE_TEST_CODE:
416+
CallHierarchy.getDefault().setShowAll(false);
417+
CallHierarchy.getDefault().setHideTestCode(true);
418+
CallHierarchy.getDefault().setShowTestCode(false);
419+
break;
420+
421+
case CallHierarchyCore.PREF_SHOW_TEST_CODE_ONLY:
422+
CallHierarchy.getDefault().setShowAll(false);
423+
CallHierarchy.getDefault().setHideTestCode(false);
424+
CallHierarchy.getDefault().setShowTestCode(true);
425+
break;
426+
}
427+
fFilterDropDownAction.setActiveFilterString();
428+
429+
// CallHierarchy.getDefault().
430+
updateView();
431+
refresh();
432+
}
433+
398434
/**
399435
* Fetches the search scope with the appropriate include mask.
400436
*
@@ -926,6 +962,10 @@ private MethodWrapper[] getCallerRoots() {
926962
return fCallerRoots;
927963
}
928964

965+
void updateFilters() {
966+
967+
}
968+
929969
/**
930970
* Adds the entry if new. Inserted at the beginning of the history entries list.
931971
* @param entry the entry to add
@@ -1025,7 +1065,8 @@ private void fillActionBars() {
10251065
}
10261066
toolBar.add(fHistoryDropDownAction);
10271067
toolBar.add(fPinViewAction);
1028-
toolBar.add(fFiltersAction);
1068+
// toolBar.add(fFiltersAction);
1069+
toolBar.add(fFilterDropDownAction);
10291070
}
10301071

10311072
private void makeActions() {
@@ -1044,6 +1085,7 @@ private void makeActions() {
10441085
fFiltersActionGroup = new CallHierarchyFiltersActionGroup(this,
10451086
fCallHierarchyViewer);
10461087
fHistoryDropDownAction = new HistoryDropDownAction(this);
1088+
fFilterDropDownAction = new FilterDropDownAction(this);
10471089
fHistoryDropDownAction.setEnabled(false);
10481090
fCancelSearchAction = new CancelSearchAction(this);
10491091
setCancelEnabled(false);
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2000, 2011 IBM Corporation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Jesper Kamstrup Linnet (eclipse@kamstrup-linnet.dk) - initial API and implementation
13+
* (report 36180: Callers/Callees view)
14+
* Stephan Herrmann (stephan@cs.tu-berlin.de):
15+
* - bug 75800: [call hierarchy] should allow searches for fields
16+
*******************************************************************************/
17+
package org.eclipse.jdt.internal.ui.callhierarchy;
18+
19+
import org.eclipse.swt.SWT;
20+
import org.eclipse.swt.widgets.Control;
21+
import org.eclipse.swt.widgets.Menu;
22+
import org.eclipse.swt.widgets.MenuItem;
23+
24+
import org.eclipse.jface.action.Action;
25+
import org.eclipse.jface.action.ActionContributionItem;
26+
import org.eclipse.jface.action.IMenuCreator;
27+
import org.eclipse.jface.window.Window;
28+
29+
import org.eclipse.jdt.core.IMember;
30+
31+
import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy;
32+
import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore;
33+
34+
import org.eclipse.jdt.internal.ui.JavaPluginImages;
35+
36+
37+
class FilterDropDownAction extends Action implements IMenuCreator {
38+
39+
private CallHierarchyViewPart fView;
40+
private Menu fMenu;
41+
private String activeFilterString;
42+
43+
public FilterDropDownAction(CallHierarchyViewPart view) {
44+
fView = view;
45+
fMenu = null;
46+
47+
48+
updateFilterString();
49+
setToolTipText(activeFilterString);
50+
setImageDescriptor(JavaPluginImages.DESC_ELCL_FILTER);
51+
52+
setText(CallHierarchyMessages.ShowFilterDialogAction_text);
53+
54+
setMenuCreator(this);
55+
}
56+
57+
@Override
58+
public Menu getMenu(Menu parent) {
59+
return null;
60+
}
61+
62+
public void setActiveFilterString() {
63+
updateFilterString();
64+
}
65+
66+
private void updateFilterString() {
67+
activeFilterString = getString(CallHierarchyCore.getDefault().getCurrentSelection());
68+
setToolTipText(activeFilterString);
69+
}
70+
71+
private String getString(String s) {
72+
if(s == CallHierarchyCore.PREF_SHOW_ALL_CODE) {
73+
return "Show All Code"; //$NON-NLS-1$
74+
} else if(s == CallHierarchyCore.PREF_HIDE_TEST_CODE) {
75+
return "Hide Test Code"; //$NON-NLS-1$
76+
} else {
77+
return "Test Code Only"; //$NON-NLS-1$
78+
}
79+
}
80+
@Override
81+
public Menu getMenu(Control parent) {
82+
if (fMenu != null) {
83+
fMenu.dispose();
84+
}
85+
fMenu= new Menu(parent);
86+
IMember[][] elements= fView.getHistoryEntries();
87+
addEntries(fMenu);
88+
return fMenu;
89+
}
90+
91+
@Override
92+
public void dispose() {
93+
fView = null;
94+
95+
if (fMenu != null) {
96+
fMenu.dispose();
97+
fMenu = null;
98+
}
99+
}
100+
101+
protected void addActionsToMenu(Menu parent, Action action) {
102+
ActionContributionItem item = new ActionContributionItem(action);
103+
item.fill(parent, -1);
104+
}
105+
106+
private boolean addEntries(Menu menu) {
107+
boolean checked = false;
108+
109+
FiltersAction action = new FiltersAction(fView, CallHierarchyCore.PREF_SHOW_ALL_CODE);
110+
addActionsToMenu(menu, action);
111+
action.setChecked(CallHierarchy.getDefault().isShowAll());
112+
113+
FiltersAction actionTwo = new FiltersAction(fView, CallHierarchyCore.PREF_HIDE_TEST_CODE);
114+
addActionsToMenu(menu, actionTwo);
115+
actionTwo.setChecked(CallHierarchy.getDefault().isHideTestCode());
116+
117+
118+
FiltersAction actionThree = new FiltersAction(fView, CallHierarchyCore.PREF_SHOW_TEST_CODE_ONLY);
119+
addActionsToMenu(menu, actionThree);
120+
actionThree.setChecked(CallHierarchy.getDefault().isShowTestCode());
121+
122+
new MenuItem(menu, SWT.SEPARATOR);
123+
addActionsToMenu(menu, new ShowCallHierarchyFilterDialogAction(fView, "Filters")); //$NON-NLS-1$
124+
125+
126+
127+
return checked;
128+
129+
}
130+
131+
@Override
132+
public void run() {
133+
openFiltersDialog();
134+
updateFilterString();
135+
// activeFilterString = CallHierarchyCore.getDefault().getActiveFilter();
136+
// setToolTipText(activeFilterString);
137+
}
138+
139+
private void openFiltersDialog() {
140+
FiltersDialog dialog = new FiltersDialog(fView.getViewSite().getShell());
141+
if (Window.OK == dialog.open()) {
142+
fView.refresh();
143+
}
144+
}
145+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Vector Informatik GmbH and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Vector Informatik GmbH - initial API and implementation
13+
*******************************************************************************/
14+
15+
package org.eclipse.jdt.internal.ui.callhierarchy;
16+
17+
import org.eclipse.jface.action.Action;
18+
19+
import org.eclipse.jdt.core.IMember;
20+
21+
import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore;
22+
23+
/**
24+
*
25+
*/
26+
public class FiltersAction extends Action {
27+
28+
private CallHierarchyViewPart fView;
29+
private IMember[] fMembers;
30+
String typeString;
31+
32+
public FiltersAction(CallHierarchyViewPart viewPart, String type) {
33+
super("", AS_RADIO_BUTTON); //$NON-NLS-1$
34+
fView = viewPart;
35+
typeString = type;
36+
switch(type) {
37+
case CallHierarchyCore.PREF_SHOW_ALL_CODE:
38+
setText(CallHierarchyMessages.FiltersDialog_ShowAllCode);
39+
40+
break;
41+
case CallHierarchyCore.PREF_HIDE_TEST_CODE:
42+
setText(CallHierarchyMessages.FiltersDialog_HideTestCode);
43+
44+
break;
45+
46+
case CallHierarchyCore.PREF_SHOW_TEST_CODE_ONLY:
47+
setText(CallHierarchyMessages.FiltersDialog_TestCodeOnly);
48+
49+
break;
50+
}
51+
52+
}
53+
54+
@Override
55+
public void run() {
56+
fView.setFilterMode(typeString);
57+
}
58+
59+
}

org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/HistoryDropDownAction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public Menu getMenu(Control parent) {
8181
}
8282
fMenu= new Menu(parent);
8383
IMember[][] elements= fView.getHistoryEntries();
84+
8485
addEntries(fMenu, elements);
8586
new MenuItem(fMenu, SWT.SEPARATOR);
8687
addActionToMenu(fMenu, new HistoryListAction(fView));

0 commit comments

Comments
 (0)