Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter top menu #1731

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
private SelectFieldModeAction[] fToggleFieldModeActions;
private CallHierarchyFiltersActionGroup fFiltersActionGroup;
private HistoryDropDownAction fHistoryDropDownAction;
private FilterDropDownAction fFilterDropDownAction;
private RefreshElementAction fRefreshSingleElementAction;
private RefreshViewAction fRefreshViewAction;
private OpenLocationAction fOpenLocationAction;
Expand All @@ -244,7 +246,7 @@
private IPartListener2 fPartListener;
private boolean fIsPinned;
private PinCallHierarchyViewAction fPinViewAction;
private ShowCallHierarchyFilterDialogAction fFiltersAction;

Check warning on line 249 in org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyViewPart.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Unnecessary Code

NORMAL: The value of the field CallHierarchyViewPart.fFiltersAction is not used


public CallHierarchyViewPart() {
Expand Down Expand Up @@ -395,6 +397,40 @@
}
}

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 @@
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 @@
}
toolBar.add(fHistoryDropDownAction);
toolBar.add(fPinViewAction);
toolBar.add(fFiltersAction);
// toolBar.add(fFiltersAction);
toolBar.add(fFilterDropDownAction);
}

private void makeActions() {
Expand All @@ -1044,6 +1085,7 @@
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
Loading