Skip to content

Commit

Permalink
Filter menu in callHierarchy #1731
Browse files Browse the repository at this point in the history
The filter button in the Call Hierarchy now has the option to expand a
menu where one can switch between the filters

#1731
  • Loading branch information
jannisCode committed Nov 4, 2024
1 parent 324bdfd commit daa1742
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ public boolean isShowAll() {
public boolean isHideTestCode() {
return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_HIDE_TEST_CODE, null));
}
public String getActiveFilter() {
if(isShowAll()) {
return PREF_SHOW_ALL_CODE;
} else if(isHideTestCode()) {
return PREF_HIDE_TEST_CODE;
} else {
return PREF_SHOW_TEST_CODE_ONLY;
}
}

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

return true;
}

public String getCurrentSelection() {
if(isShowAll()) {
return PREF_SHOW_ALL_CODE;
} else if(isHideTestCode()) {
return PREF_HIDE_TEST_CODE;
} else {
return PREF_SHOW_TEST_CODE_ONLY;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import org.eclipse.jdt.core.search.IJavaSearchScope;

import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy;
import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore;
import org.eclipse.jdt.internal.corext.callhierarchy.CallLocation;
import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
import org.eclipse.jdt.internal.corext.callhierarchy.RealCallers;
Expand Down Expand Up @@ -227,6 +228,7 @@ protected void open(ISelection selection, boolean activate) {
private SelectFieldModeAction[] fToggleFieldModeActions;
private CallHierarchyFiltersActionGroup fFiltersActionGroup;
private HistoryDropDownAction fHistoryDropDownAction;
private FilterDropDownAction fFilterDropDownAction;
private RefreshElementAction fRefreshSingleElementAction;
private RefreshViewAction fRefreshViewAction;
private OpenLocationAction fOpenLocationAction;
Expand Down Expand Up @@ -395,6 +397,40 @@ void setFieldMode(int mode) {
}
}

void setFilterMode(String mode) {

if(mode == CallHierarchyCore.getDefault().getCurrentSelection()) {
return;
}


switch(mode) {
case CallHierarchyCore.PREF_SHOW_ALL_CODE:
CallHierarchy.getDefault().setShowAll(true);
CallHierarchy.getDefault().setHideTestCode(false);
CallHierarchy.getDefault().setShowTestCode(false);

break;

case CallHierarchyCore.PREF_HIDE_TEST_CODE:
CallHierarchy.getDefault().setShowAll(false);
CallHierarchy.getDefault().setHideTestCode(true);
CallHierarchy.getDefault().setShowTestCode(false);
break;

case CallHierarchyCore.PREF_SHOW_TEST_CODE_ONLY:
CallHierarchy.getDefault().setShowAll(false);
CallHierarchy.getDefault().setHideTestCode(false);
CallHierarchy.getDefault().setShowTestCode(true);
break;
}
fFilterDropDownAction.setActiveFilterString();

// CallHierarchy.getDefault().
updateView();
refresh();
}

/**
* Fetches the search scope with the appropriate include mask.
*
Expand Down Expand Up @@ -926,6 +962,10 @@ private MethodWrapper[] getCallerRoots() {
return fCallerRoots;
}

void updateFilters() {

}

/**
* Adds the entry if new. Inserted at the beginning of the history entries list.
* @param entry the entry to add
Expand Down Expand Up @@ -1025,7 +1065,8 @@ private void fillActionBars() {
}
toolBar.add(fHistoryDropDownAction);
toolBar.add(fPinViewAction);
toolBar.add(fFiltersAction);
// toolBar.add(fFiltersAction);
toolBar.add(fFilterDropDownAction);
}

private void makeActions() {
Expand All @@ -1044,6 +1085,7 @@ private void makeActions() {
fFiltersActionGroup = new CallHierarchyFiltersActionGroup(this,
fCallHierarchyViewer);
fHistoryDropDownAction = new HistoryDropDownAction(this);
fFilterDropDownAction = new FilterDropDownAction(this);
fHistoryDropDownAction.setEnabled(false);
fCancelSearchAction = new CancelSearchAction(this);
setCancelEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*******************************************************************************
* Copyright (c) 2000, 2011 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Jesper Kamstrup Linnet ([email protected]) - initial API and implementation
* (report 36180: Callers/Callees view)
* Stephan Herrmann ([email protected]):
* - bug 75800: [call hierarchy] should allow searches for fields
*******************************************************************************/
package org.eclipse.jdt.internal.ui.callhierarchy;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IMenuCreator;
import org.eclipse.jface.window.Window;

import org.eclipse.jdt.core.IMember;

import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy;
import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore;

import org.eclipse.jdt.internal.ui.JavaPluginImages;


class FilterDropDownAction extends Action implements IMenuCreator {

private CallHierarchyViewPart fView;
private Menu fMenu;
private String activeFilterString;

public FilterDropDownAction(CallHierarchyViewPart view) {
fView = view;
fMenu = null;


updateFilterString();
setToolTipText(activeFilterString);
setImageDescriptor(JavaPluginImages.DESC_ELCL_FILTER);

setText(CallHierarchyMessages.ShowFilterDialogAction_text);

setMenuCreator(this);
}

@Override
public Menu getMenu(Menu parent) {
return null;
}

public void setActiveFilterString() {
updateFilterString();
}

private void updateFilterString() {
activeFilterString = getString(CallHierarchyCore.getDefault().getCurrentSelection());
setToolTipText(activeFilterString);
}

private String getString(String s) {
if(s == CallHierarchyCore.PREF_SHOW_ALL_CODE) {
return "Show All Code"; //$NON-NLS-1$
} else if(s == CallHierarchyCore.PREF_HIDE_TEST_CODE) {
return "Hide Test Code"; //$NON-NLS-1$
} else {
return "Test Code Only"; //$NON-NLS-1$
}
}
@Override
public Menu getMenu(Control parent) {
if (fMenu != null) {
fMenu.dispose();
}
fMenu= new Menu(parent);
IMember[][] elements= fView.getHistoryEntries();

Check warning on line 86 in org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/FilterDropDownAction.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Unnecessary Code

NORMAL: The value of the local variable elements is not used
addEntries(fMenu);
return fMenu;
}

@Override
public void dispose() {
fView = null;

if (fMenu != null) {
fMenu.dispose();
fMenu = null;
}
}

protected void addActionsToMenu(Menu parent, Action action) {
ActionContributionItem item = new ActionContributionItem(action);
item.fill(parent, -1);
}

private boolean addEntries(Menu menu) {
boolean checked = false;

FiltersAction action = new FiltersAction(fView, CallHierarchyCore.PREF_SHOW_ALL_CODE);
addActionsToMenu(menu, action);
action.setChecked(CallHierarchy.getDefault().isShowAll());

FiltersAction actionTwo = new FiltersAction(fView, CallHierarchyCore.PREF_HIDE_TEST_CODE);
addActionsToMenu(menu, actionTwo);
actionTwo.setChecked(CallHierarchy.getDefault().isHideTestCode());


FiltersAction actionThree = new FiltersAction(fView, CallHierarchyCore.PREF_SHOW_TEST_CODE_ONLY);
addActionsToMenu(menu, actionThree);
actionThree.setChecked(CallHierarchy.getDefault().isShowTestCode());

new MenuItem(menu, SWT.SEPARATOR);
addActionsToMenu(menu, new ShowCallHierarchyFilterDialogAction(fView, "Filters")); //$NON-NLS-1$



return checked;

}

@Override
public void run() {
openFiltersDialog();
updateFilterString();
// activeFilterString = CallHierarchyCore.getDefault().getActiveFilter();
// setToolTipText(activeFilterString);
}

private void openFiltersDialog() {
FiltersDialog dialog = new FiltersDialog(fView.getViewSite().getShell());
if (Window.OK == dialog.open()) {
fView.refresh();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright (c) 2023 Vector Informatik GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Vector Informatik GmbH - initial API and implementation
*******************************************************************************/

package org.eclipse.jdt.internal.ui.callhierarchy;

import org.eclipse.jface.action.Action;

import org.eclipse.jdt.core.IMember;

import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore;

/**
*
*/
public class FiltersAction extends Action {

private CallHierarchyViewPart fView;
private IMember[] fMembers;

Check warning on line 29 in org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/FiltersAction.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Unnecessary Code

NORMAL: The value of the field FiltersAction.fMembers is not used
String typeString;

public FiltersAction(CallHierarchyViewPart viewPart, String type) {
super("", AS_RADIO_BUTTON); //$NON-NLS-1$
fView = viewPart;
typeString = type;
switch(type) {
case CallHierarchyCore.PREF_SHOW_ALL_CODE:
setText(CallHierarchyMessages.FiltersDialog_ShowAllCode);

break;
case CallHierarchyCore.PREF_HIDE_TEST_CODE:
setText(CallHierarchyMessages.FiltersDialog_HideTestCode);

break;

case CallHierarchyCore.PREF_SHOW_TEST_CODE_ONLY:
setText(CallHierarchyMessages.FiltersDialog_TestCodeOnly);

break;
}

}

@Override
public void run() {
fView.setFilterMode(typeString);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public Menu getMenu(Control parent) {
}
fMenu= new Menu(parent);
IMember[][] elements= fView.getHistoryEntries();

addEntries(fMenu, elements);
new MenuItem(fMenu, SWT.SEPARATOR);
addActionToMenu(fMenu, new HistoryListAction(fView));
Expand Down

0 comments on commit daa1742

Please sign in to comment.