Boot Dash filters UI rework

This commit is contained in:
BoykoAlex
2021-05-11 13:56:30 -04:00
parent a8abea0cb0
commit 5a4eea4d2b
13 changed files with 173 additions and 142 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 655 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 582 B

View File

@@ -15,10 +15,11 @@ import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.widgets.Shell;
import org.springframework.ide.eclipse.boot.dash.model.ToggleFiltersModel.FilterChoice;
import org.springsource.ide.eclipse.commons.livexp.core.Validator;
import org.springsource.ide.eclipse.commons.livexp.ui.ChooseMultipleSection;
import org.springsource.ide.eclipse.commons.livexp.ui.DescriptionSection;
import org.springsource.ide.eclipse.commons.livexp.ui.DialogWithSections;
import org.springsource.ide.eclipse.commons.livexp.ui.StringFieldSection;
import org.springsource.ide.eclipse.commons.livexp.ui.WizardPageSection;
public class ToggleFiltersDialog extends DialogWithSections {
@@ -38,13 +39,16 @@ public class ToggleFiltersDialog extends DialogWithSections {
@Override
protected List<WizardPageSection> createSections() throws CoreException {
ChooseMultipleSection<FilterChoice> chooseFilters =
new ChooseMultipleSection<FilterChoice>(this,
return Arrays.asList(
new StringFieldSection(this, "Regex to match names of the elements to be shown", model.getRegExFilterLiveVar(), Validator.OK).vertical(true),
new ChooseMultipleSection<>(this,
"Filters",
model.getAvailableFilters(),
model.getSelectedFilters(),
Validator.OK);
return Arrays.asList((WizardPageSection)chooseFilters);
Validator.OK,
model.getSelectedLiveVar()).vertical(true),
new DescriptionSection(this, model.getToggleFilterDescription())
);
}
}

View File

@@ -12,7 +12,9 @@ package org.springframework.ide.eclipse.boot.dash.dialogs;
import org.springframework.ide.eclipse.boot.dash.model.ToggleFiltersModel;
import org.springframework.ide.eclipse.boot.dash.model.ToggleFiltersModel.FilterChoice;
import org.springsource.ide.eclipse.commons.livexp.core.LiveExpression;
import org.springsource.ide.eclipse.commons.livexp.core.LiveSet;
import org.springsource.ide.eclipse.commons.livexp.core.LiveVariable;
import org.springsource.ide.eclipse.commons.livexp.ui.OkButtonHandler;
/**
@@ -31,11 +33,24 @@ public class ToggleFiltersDialogModel implements OkButtonHandler {
/**
* Filters in the dialog (these get copied to the view when user pressed 'ok').
*/
private LiveSet<FilterChoice> selectedFilters = new LiveSet<FilterChoice>();
private LiveSet<FilterChoice> selectedFilters = new LiveSet<>();
private LiveVariable<String> regexFilter = new LiveVariable<>();
private LiveVariable<FilterChoice> selected = new LiveVariable<>();
private LiveExpression<String> toggleFilterDescription = selected.apply(selected -> {
if (selected == null) {
return "Select a filter to see the description";
} else {
return selected.getDescription();
}
});
public ToggleFiltersDialogModel(ToggleFiltersModel viewModel) {
this.viewModel = viewModel;
selectedFilters.replaceAll(viewModel.getSelectedFilters().getValue());
regexFilter = new LiveVariable<>(viewModel.getRegexFilter().getValue());
}
public FilterChoice[] getAvailableFilters() {
@@ -46,8 +61,25 @@ public class ToggleFiltersDialogModel implements OkButtonHandler {
return selectedFilters;
}
public LiveVariable<String> getRegExFilterLiveVar() {
return regexFilter;
}
public String getRegexFilter() {
return regexFilter.getValue();
}
public LiveExpression<String> getToggleFilterDescription() {
return toggleFilterDescription;
}
public LiveVariable<FilterChoice> getSelectedLiveVar() {
return selected;
}
@Override
public void performOk() throws Exception {
viewModel.getSelectedFilters().replaceAll(selectedFilters.getValue());
viewModel.getRegexFilter().setValue(getRegexFilter());
}
}

View File

@@ -17,9 +17,11 @@ import org.eclipse.core.resources.IProject;
import org.springsource.ide.eclipse.commons.core.pstore.IPropertyStore;
import org.springsource.ide.eclipse.commons.core.pstore.PropertyStoreApi;
import org.springsource.ide.eclipse.commons.core.pstore.PropertyStores;
import org.springsource.ide.eclipse.commons.frameworks.core.util.StringUtils;
import org.springsource.ide.eclipse.commons.livexp.core.AsyncLiveExpression.AsyncMode;
import org.springsource.ide.eclipse.commons.livexp.core.LiveExpression;
import org.springsource.ide.eclipse.commons.livexp.core.LiveSetVariable;
import org.springsource.ide.eclipse.commons.livexp.core.LiveVariable;
import org.springsource.ide.eclipse.commons.livexp.core.ValueListener;
import org.springsource.ide.eclipse.commons.livexp.ui.Ilabelable;
import org.springsource.ide.eclipse.commons.livexp.util.Filter;
@@ -77,14 +79,45 @@ public class ToggleFiltersModel {
}
};
public static final FilterChoice FILTER_CHOICE_HIDE_NON_WORKSPACE_ELEMENTS = new FilterChoice("hide.non-workspace",
"Hide non-workspace elements", HIDE_NON_WORKSPACE_ELEMENTS);
public static final FilterChoice FILTER_CHOICE_HIDE_SOLITARY_CONFS = new FilterChoice("hide.solitary-launch-config",
"Hide solitary launch configs", HIDE_SOLITARY_CONFS, true);
public static final FilterChoice FILTER_CHOICE_HIDE_LOCAL_SERVICES = new FilterChoice("hide.local-cloud-services",
"Hide local cloud services", HIDE_LOCAL_SERVICES, true);
public static final FilterChoice FILTER_CHOICE_HIDE_NOT_RUNNABLE_APPS = new FilterChoice("hide.not-runnable-apps",
"Hide local non-runnable apps", HIDE_LOCAL_NOT_RUNNABLE_APPS, true);
private final Filter<BootDashElement> REGEX_FILTER = new Filter<BootDashElement>() {
@Override
public boolean accept(BootDashElement t) {
String regex = regexFilter.getValue();
if (t.getName() != null && StringUtils.hasText(regex)) {
return t.getName().matches(regex);
}
return true;
}
};
public static final FilterChoice FILTER_CHOICE_HIDE_NON_WORKSPACE_ELEMENTS = new FilterChoice(
"hide.non-workspace",
"Hide non-workspace elements",
"Elements not backed by a project in the workspaces will be not shown. For example elements fetched from Cloud Foundry instance.",
HIDE_NON_WORKSPACE_ELEMENTS);
public static final FilterChoice FILTER_CHOICE_HIDE_SOLITARY_CONFS = new FilterChoice(
"hide.solitary-launch-config",
"Hide solitary launch configs",
"Launch configurations will not be shown if it the one and only configuration that exist for a Boot project or any other Boot Dashboard top level element",
HIDE_SOLITARY_CONFS,
true);
public static final FilterChoice FILTER_CHOICE_HIDE_LOCAL_SERVICES = new FilterChoice(
"hide.local-cloud-services",
"Hide local cloud services",
"Local Spring Cloud Service coming from Spring Cloud CLI instance pointed to from STS preferences will not be shown",
HIDE_LOCAL_SERVICES,
true);
public static final FilterChoice FILTER_CHOICE_HIDE_NOT_RUNNABLE_APPS = new FilterChoice(
"hide.not-runnable-apps",
"Hide local non-runnable apps",
"Spring Boot projects that cannot be laucnhed such as Spring Boot library projects not having a main method will not be shown",
HIDE_LOCAL_NOT_RUNNABLE_APPS,
true);
private static final String STORE_ID = "toggle-filters";
private static final FilterChoice[] FILTERS = {
@@ -94,6 +127,8 @@ public class ToggleFiltersModel {
FILTER_CHOICE_HIDE_NOT_RUNNABLE_APPS
};
private static final String REGEX_FILTER_ID = "regexFilter";
private final PropertyStoreApi persistentProperties;
public ToggleFiltersModel(BootDashModelContext context) {
@@ -103,13 +138,15 @@ public class ToggleFiltersModel {
public ToggleFiltersModel(IPropertyStore propertyStore) {
this.persistentProperties = new PropertyStoreApi(propertyStore);
this.selectedFilters = new LiveSetVariable<>(restoreFilters(), AsyncMode.SYNC);
this.regexFilter = new LiveVariable<>(persistentProperties.get(REGEX_FILTER_ID));
this.compositeFilter = new LiveExpression<Filter<BootDashElement>>() {
{
dependsOn(selectedFilters);
dependsOn(regexFilter);
}
@Override
protected Filter<BootDashElement> compute() {
Filter<BootDashElement> composed = Filters.acceptAll();
Filter<BootDashElement> composed = REGEX_FILTER;
for (FilterChoice chosen : selectedFilters.getValues()) {
composed = Filters.compose(composed, chosen.getFilter());
}
@@ -122,21 +159,36 @@ public class ToggleFiltersModel {
saveFilters(value);
}
});
regexFilter.addListener((expr, v) -> {
try {
String value = expr.getValue();
if (StringUtils.hasText(value)) {
persistentProperties.put(REGEX_FILTER_ID, value);
} else {
persistentProperties.put(REGEX_FILTER_ID, (String) null);
}
} catch (Exception e) {
Log.log(e);
}
});
}
public static class FilterChoice implements Ilabelable {
private final String id;
private final String label;
private final String description;
private final Filter<BootDashElement> filter;
private final boolean defaultEnable;
public FilterChoice(String id, String label, Filter<BootDashElement> filter) {
this(id, label, filter, false);
public FilterChoice(String id, String label, String description, Filter<BootDashElement> filter) {
this(id, label, description, filter, false);
}
public FilterChoice(String id, String label, Filter<BootDashElement> filter, boolean defaultEnable) {
public FilterChoice(String id, String label, String description, Filter<BootDashElement> filter, boolean defaultEnable) {
this.id = id;
this.label = label;
this.description = description;
this.filter = filter;
this.defaultEnable = defaultEnable;
}
@@ -151,6 +203,10 @@ public class ToggleFiltersModel {
return label;
}
public String getDescription() {
return description;
}
public Filter<BootDashElement> getFilter() {
return filter;
}
@@ -161,6 +217,7 @@ public class ToggleFiltersModel {
}
private final LiveSetVariable<FilterChoice> selectedFilters;
private final LiveVariable<String> regexFilter;
private final LiveExpression<Filter<BootDashElement>> compositeFilter;
/**
@@ -203,4 +260,7 @@ public class ToggleFiltersModel {
public LiveSetVariable<FilterChoice> getSelectedFilters() {
return selectedFilters;
}
public LiveVariable<String> getRegexFilter() {
return regexFilter;
}
}

View File

@@ -31,7 +31,6 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IAction;
import org.springframework.ide.eclipse.boot.core.BootActivator;
import org.springframework.ide.eclipse.boot.core.BootPreferences;
import org.springframework.ide.eclipse.boot.dash.BootDashActivator;
import org.springframework.ide.eclipse.boot.dash.api.RunTargetType;
import org.springframework.ide.eclipse.boot.dash.cloudfoundry.deployment.DeployToRemoteTargetAction;
@@ -86,7 +85,6 @@ public class BootDashActions {
private ExposeAppAction exposeRunAppAction;
private ExposeAppAction exposeDebugAppAction;
private OpenPreferencesAction openFilterPreferencesAction;
private OpenPreferencesAction openBootDashPreferencesAction;
private DuplicateConfigAction duplicateConfigAction;
@@ -95,7 +93,6 @@ public class BootDashActions {
private DeleteElementsAction<LocalRunTargetType> deleteConfigsAction;
private OpenToggleFiltersDialogAction toggleFiltersDialogAction;
private ToggleFilterAction[] toggleFilterActions;
private CustmomizeTargetLabelAction customizeTargetLabelAction;
private DisposingFactory<RunTarget, AbstractBootDashAction> debugOnTargetActions;
@@ -296,10 +293,6 @@ public class BootDashActions {
showPropertiesViewAction = new ShowViewAction(PROPERTIES_VIEW_ID);
toggleFiltersDialogAction = new OpenToggleFiltersDialogAction(model.getToggleFilters(), elementsSelection, context);
toggleFilterActions = new ToggleFilterAction[model.getToggleFilters().getAvailableFilters().length];
for (int i = 0; i < toggleFilterActions.length; i++) {
toggleFilterActions[i] = new ToggleFilterAction(model, model.getToggleFilters().getAvailableFilters()[i], context);
}
exposeRunAppAction = new ExposeAppAction(defaultActionParams(), RunState.RUNNING, NGROKInstallManager.getInstance());
exposeRunAppAction.setText("(Re)start and Expose via ngrok");
@@ -318,10 +311,6 @@ public class BootDashActions {
debugOnTargetActions = createDeployOnTargetActions(RunState.DEBUGGING);
runOnTargetActions = createDeployOnTargetActions(RunState.RUNNING);
openFilterPreferencesAction = new OpenPreferencesAction(context, BootPreferences.BOOT_PREFERENCE_PAGE_ID,
"Boot Projects Filters Preferences...",
"Open Preferences for Spring Boot projects filters"
);
openBootDashPreferencesAction = new OpenPreferencesAction(context, BootDashPrefsPage.class.getName(),
"Boot Dash UI Preferences...",
"Open Preferences for Boot Dash"
@@ -560,12 +549,6 @@ public class BootDashActions {
duplicateConfigAction.dispose();
duplicateConfigAction = null;
}
if (toggleFilterActions!=null) {
for (ToggleFilterAction a : toggleFilterActions) {
a.dispose();
}
toggleFilterActions = null;
}
debugOnTargetActions.dispose();
runOnTargetActions.dispose();
liveDataConnectionManagement.dispose();
@@ -579,10 +562,6 @@ public class BootDashActions {
return duplicateConfigAction;
}
public ToggleFilterAction[] getToggleFilterActions() {
return toggleFilterActions;
}
public CustmomizeTargetLabelAction getCustomizeTargetLabelAction() {
return customizeTargetLabelAction;
}
@@ -594,10 +573,6 @@ public class BootDashActions {
return getDeployAndStartOnTargetActions(runOnTargetActions);
}
public OpenPreferencesAction getOpenFilterPreferencesAction() {
return openFilterPreferencesAction;
}
public IAction getOpenBootDashPreferencesAction() {
return this.openBootDashPreferencesAction;
}

View File

@@ -16,7 +16,6 @@ import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuCreator;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
@@ -189,8 +188,11 @@ public class BootDashTreeView extends ViewPartWithSections implements ITabbedPro
manager.add(actions.getOpenInPackageExplorerAction());
manager.add(actions.getOpenConfigAction());
manager.add(actions.getShowPropertiesViewAction());
manager.add(actions.getToggleFiltersDialogAction());
MenuUtil.addDynamicSubmenu(manager, actions.getLiveDataConnectionManagement());
manager.add(new Separator());
manager.add(actions.getExposeRunAppAction());
manager.add(actions.getExposeDebugAppAction());
@@ -199,13 +201,6 @@ public class BootDashTreeView extends ViewPartWithSections implements ITabbedPro
addAddRunTargetMenuActions(manager);
manager.add(new Separator());
//manager.add(actions.getToggleFiltersDialogAction());
for (ToggleFilterAction a : actions.getToggleFilterActions()) {
manager.add(a);
}
manager.add(new Separator());
manager.add(actions.getOpenFilterPreferencesAction());
manager.add(actions.getOpenBootDashPreferencesAction());
// manager.add(refreshAction);

View File

@@ -10,17 +10,17 @@
*******************************************************************************/
package org.springframework.ide.eclipse.boot.dash.views;
import org.springframework.ide.eclipse.boot.dash.BootDashActivator;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
import org.springframework.ide.eclipse.boot.dash.di.SimpleDIContext;
import org.springframework.ide.eclipse.boot.dash.dialogs.ToggleFiltersDialogModel;
import org.springframework.ide.eclipse.boot.dash.livexp.MultiSelection;
import org.springframework.ide.eclipse.boot.dash.model.BootDashElement;
import org.springframework.ide.eclipse.boot.dash.model.ToggleFiltersModel;
import org.springframework.ide.eclipse.boot.dash.model.UserInteractions;
/**
* @author Kris De Volder
*/
@SuppressWarnings("restriction")
public class OpenToggleFiltersDialogAction extends AbstractBootDashAction {
/**
@@ -32,8 +32,8 @@ public class OpenToggleFiltersDialogAction extends AbstractBootDashAction {
super(ui);
this.viewModel = model;
setText("Filters...");
setImageDescriptor(BootDashActivator.getImageDescriptor("icons/filter.png"));
setDisabledImageDescriptor(BootDashActivator.getImageDescriptor("icons/filter_disabled.png"));
setImageDescriptor(JavaPluginImages.DESC_ELCL_FILTER);
setDisabledImageDescriptor(JavaPluginImages.DESC_DLCL_FILTER);
}
@Override

View File

@@ -1,78 +0,0 @@
/*******************************************************************************
* Copyright (c) 2016 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.eclipse.boot.dash.views;
import org.eclipse.jface.action.IAction;
import org.springframework.ide.eclipse.boot.dash.di.SimpleDIContext;
import org.springframework.ide.eclipse.boot.dash.model.BootDashViewModel;
import org.springframework.ide.eclipse.boot.dash.model.ToggleFiltersModel;
import org.springframework.ide.eclipse.boot.dash.model.ToggleFiltersModel.FilterChoice;
import org.springframework.ide.eclipse.boot.dash.model.UserInteractions;
import org.springsource.ide.eclipse.commons.livexp.core.LiveExpression;
import org.springsource.ide.eclipse.commons.livexp.core.LiveSetVariable;
import org.springsource.ide.eclipse.commons.livexp.core.ValueListener;
import com.google.common.collect.ImmutableSet;
/**
* A checkbox-style menu action that enables / disables
* a particular 'toggle filter'.
*
* @author Kris De Volder
*/
public class ToggleFilterAction extends AbstractBootDashAction {
private ToggleFiltersModel toggleFilters;
private ValueListener<ImmutableSet<FilterChoice>> selectedFilterListener;
final private FilterChoice filter;
public ToggleFilterAction(BootDashViewModel model, FilterChoice filter, SimpleDIContext context) {
super(context, IAction.AS_CHECK_BOX);
this.filter = filter;
this.toggleFilters = model.getToggleFilters();
this.setText(filter.getLabel());
model.getToggleFilters().getSelectedFilters().addListener(selectedFilterListener=new ValueListener<ImmutableSet<FilterChoice>>() {
public void gotValue(LiveExpression<ImmutableSet<FilterChoice>> exp, ImmutableSet<FilterChoice> value) {
updateCheckedState();
}
});
}
protected void updateCheckedState() {
setChecked(getModelCheckedState());
}
protected boolean getModelCheckedState() {
return toggleFilters.getSelectedFilters().getValues().contains(filter);
}
protected void setModelCheckedState(boolean checked) {
LiveSetVariable<FilterChoice> activeFilters = toggleFilters.getSelectedFilters();
if (checked) {
activeFilters.add(filter);
} else {
activeFilters.remove(filter);
}
}
@Override
public void run() {
setModelCheckedState(!getModelCheckedState());
}
@Override
public void dispose() {
if (selectedFilterListener!=null) {
toggleFilters.getSelectedFilters().removeListener(selectedFilterListener);
}
super.dispose();
}
}