Filters dialog adjustments for Boot Dash

This commit is contained in:
BoykoAlex
2021-05-21 11:52:55 -04:00
parent 6945fe18fc
commit 9cc82fd598
10 changed files with 345 additions and 40 deletions

View File

@@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2015 Pivotal, Inc.
* Copyright (c) 2015, 2021 VMware, 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
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.eclipse.boot.dash.dialogs;
@@ -14,22 +14,32 @@ import java.util.Arrays;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.springsource.ide.eclipse.commons.livexp.core.Validator;
import org.springsource.ide.eclipse.commons.livexp.ui.ButtonSection;
import org.springsource.ide.eclipse.commons.livexp.ui.CheckboxSection;
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.RowSection;
import org.springsource.ide.eclipse.commons.livexp.ui.StringFieldSection;
import org.springsource.ide.eclipse.commons.livexp.ui.TrayDialogWithSections;
import org.springsource.ide.eclipse.commons.livexp.ui.WizardPageSection;
public class ToggleFiltersDialog extends DialogWithSections {
public class ToggleFiltersDialog extends TrayDialogWithSections {
private ToggleFiltersDialogModel model;
public ToggleFiltersDialog(String title, ToggleFiltersDialogModel model, Shell shell) {
super(title, model, shell);
super(shell, model);
this.model = model;
// TODO Auto-generated constructor stub
}
@Override
protected Control createContents(Composite parent) {
getShell().setText("Select Filters");
return super.createContents(parent);
}
public static void open(ToggleFiltersDialogModel model, Shell shell) {
@@ -40,14 +50,22 @@ public class ToggleFiltersDialog extends DialogWithSections {
@Override
protected List<WizardPageSection> createSections() throws CoreException {
return Arrays.asList(
new StringFieldSection(this, "Regex to match names of the elements to be shown", model.getRegExFilterLiveVar(), Validator.OK).vertical(true),
new CheckboxSection(this, model.getEnableRegexFilter(), "Name filter patterns (matching names will be hidden):"),
new StringFieldSection(this,
"Regex pattern to match names of the elements to be hidden",
model.getRegExFilterLiveVar(),
Validator.OK).labelUnder(true).setEnabler(model.getEnableRegexFilter()),
new ChooseMultipleSection<>(this,
"Filters",
model.getAvailableFilters(),
model.getSelectedFilters(),
Validator.OK,
model.getSelectedLiveVar()).vertical(true),
new DescriptionSection(this, model.getToggleFilterDescription())
new DescriptionSection(this, model.getToggleFilterDescription()),
new RowSection(this,
new ButtonSection(this, "Select All", model::selectAll),
new ButtonSection(this, "Deselect All", model::deselectAll)
)
);
}

View File

@@ -1,15 +1,18 @@
/*******************************************************************************
* Copyright (c) 2015 Pivotal, Inc.
* Copyright (c) 2015, 2021 VMware, 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
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.eclipse.boot.dash.dialogs;
import java.util.Arrays;
import java.util.Collections;
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;
@@ -35,6 +38,8 @@ public class ToggleFiltersDialogModel implements OkButtonHandler {
*/
private LiveSet<FilterChoice> selectedFilters = new LiveSet<>();
private LiveVariable<Boolean> enableRegexFilter = new LiveVariable<>();
private LiveVariable<String> regexFilter = new LiveVariable<>();
private LiveVariable<FilterChoice> selected = new LiveVariable<>();
@@ -51,6 +56,7 @@ public class ToggleFiltersDialogModel implements OkButtonHandler {
this.viewModel = viewModel;
selectedFilters.replaceAll(viewModel.getSelectedFilters().getValue());
regexFilter = new LiveVariable<>(viewModel.getRegexFilter().getValue());
enableRegexFilter = new LiveVariable<>(viewModel.getEnableRegexFilter().getValue());
}
public FilterChoice[] getAvailableFilters() {
@@ -77,9 +83,22 @@ public class ToggleFiltersDialogModel implements OkButtonHandler {
return selected;
}
public LiveVariable<Boolean> getEnableRegexFilter() {
return enableRegexFilter;
}
@Override
public void performOk() throws Exception {
viewModel.getSelectedFilters().replaceAll(selectedFilters.getValue());
viewModel.getRegexFilter().setValue(getRegexFilter());
viewModel.getEnableRegexFilter().setValue(enableRegexFilter.getValue());
}
public void selectAll() {
selectedFilters.replaceAll(Arrays.asList(getAvailableFilters()));
}
public void deselectAll() {
selectedFilters.replaceAll(Collections.emptyList());
}
}

View File

@@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2015, 2017 Pivotal, Inc.
* Copyright (c) 2015, 2021 VMware, 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
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.eclipse.boot.dash.model;
@@ -85,7 +85,7 @@ public class ToggleFiltersModel {
public boolean accept(BootDashElement t) {
String regex = regexFilter.getValue();
if (t.getName() != null && StringUtils.hasText(regex)) {
return t.getName().matches(regex);
return !t.getName().matches(regex);
}
return true;
}
@@ -128,6 +128,7 @@ public class ToggleFiltersModel {
};
private static final String REGEX_FILTER_ID = "regexFilter";
private static final String ENABLE_REGEX_FILTER = "enableRegexFilter";
private final PropertyStoreApi persistentProperties;
@@ -139,14 +140,16 @@ public class ToggleFiltersModel {
this.persistentProperties = new PropertyStoreApi(propertyStore);
this.selectedFilters = new LiveSetVariable<>(restoreFilters(), AsyncMode.SYNC);
this.regexFilter = new LiveVariable<>(persistentProperties.get(REGEX_FILTER_ID));
this.enableRegexFilter = new LiveVariable<>(persistentProperties.get(ENABLE_REGEX_FILTER, false));
this.compositeFilter = new LiveExpression<Filter<BootDashElement>>() {
{
dependsOn(selectedFilters);
dependsOn(regexFilter);
dependsOn(enableRegexFilter);
}
@Override
protected Filter<BootDashElement> compute() {
Filter<BootDashElement> composed = REGEX_FILTER;
Filter<BootDashElement> composed = enableRegexFilter.getValue().booleanValue() ? REGEX_FILTER : Filters.acceptAll();
for (FilterChoice chosen : selectedFilters.getValues()) {
composed = Filters.compose(composed, chosen.getFilter());
}
@@ -154,12 +157,21 @@ public class ToggleFiltersModel {
}
};
selectedFilters.addListener(new ValueListener<ImmutableSet<FilterChoice>>() {
public void gotValue(LiveExpression<ImmutableSet<FilterChoice>> exp, ImmutableSet<FilterChoice> value) {
saveFilters(value);
}
});
enableRegexFilter.addListener((exp, v) -> {
try {
persistentProperties.put(ENABLE_REGEX_FILTER, exp.getValue().booleanValue());
} catch (Exception e) {
Log.log(e);
}
});
regexFilter.addListener((expr, v) -> {
try {
String value = expr.getValue();
@@ -218,6 +230,7 @@ public class ToggleFiltersModel {
private final LiveSetVariable<FilterChoice> selectedFilters;
private final LiveVariable<String> regexFilter;
private final LiveVariable<Boolean> enableRegexFilter;
private final LiveExpression<Filter<BootDashElement>> compositeFilter;
/**
@@ -263,4 +276,7 @@ public class ToggleFiltersModel {
public LiveVariable<String> getRegexFilter() {
return regexFilter;
}
public LiveVariable<Boolean> getEnableRegexFilter() {
return enableRegexFilter;
}
}

View File

@@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2015, 2019 Pivotal, Inc.
* Copyright (c) 2015, 2021 VMware, 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
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.eclipse.boot.dash.views;
@@ -188,7 +188,6 @@ 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());
@@ -200,6 +199,9 @@ public class BootDashTreeView extends ViewPartWithSections implements ITabbedPro
manager.add(new Separator());
addAddRunTargetMenuActions(manager);
manager.add(new Separator());
manager.add(actions.getToggleFiltersDialogAction());
manager.add(new Separator());
manager.add(actions.getOpenBootDashPreferencesAction());

View File

@@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2016 Pivotal, Inc.
* Copyright (c) 2016, 2021 VMware, 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
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.commons.livexp.ui;
@@ -16,6 +16,7 @@ import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.springsource.ide.eclipse.commons.livexp.Activator;
@@ -84,7 +85,9 @@ public class ButtonSection extends WizardPageSection {
* method to change the layout.
*/
protected void applyLayoutData(Button button) {
GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(button);
if (button.getParent().getLayout() instanceof GridLayout) {
GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(button);
}
}
public ButtonSection setEnabler(LiveExpression<Boolean> enabler) {

View File

@@ -128,17 +128,19 @@ public class ChooseMultipleSection<T extends Ilabelable> extends WizardPageSecti
});
}
if (DEBUG) {
chosen.addListener(new ValueListener<Set<T>>() {
public void gotValue(LiveExpression<Set<T>> exp, Set<T> value) {
chosen.addListener(new ValueListener<Set<T>>() {
public void gotValue(LiveExpression<Set<T>> exp, Set<T> value) {
Set<T> values = exp.getValue();
tv.setCheckedElements(values.toArray());
if (DEBUG) {
System.out.println(">>>> starters");
for (T e : value) {
System.out.println(e.getLabel());
}
System.out.println("<<<< starters");
}
});
}
}
});
}

View File

@@ -0,0 +1,61 @@
/*******************************************************************************
* Copyright (c) 2021 VMware, 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:
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.commons.livexp.ui;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.springsource.ide.eclipse.commons.livexp.core.CompositeValidator;
import org.springsource.ide.eclipse.commons.livexp.core.LiveExpression;
import org.springsource.ide.eclipse.commons.livexp.core.ValidationResult;
public class RowSection extends WizardPageSection {
private IPageSection[] sections;
private CompositeValidator validator;
public RowSection(IPageWithSections owner, IPageSection... sections) {
super(owner);
this.sections = sections;
}
@Override
public void createContents(Composite page) {
Composite c = new Composite(page, SWT.NONE);
GridDataFactory.fillDefaults().grab(false, false).applyTo(c);
RowLayout layout = new RowLayout(SWT.HORIZONTAL);
layout.pack = false;
c.setLayout(layout);
validator = new CompositeValidator();
for (IPageSection s : sections) {
s.createContents(c);
validator.addChild(s.getValidator());
}
}
@Override
public void dispose() {
for (IPageSection s : sections) {
if (s instanceof Disposable) {
((Disposable) s).dispose();
}
}
super.dispose();
}
@Override
public LiveExpression<ValidationResult> getValidator() {
return validator;
}
}

View File

@@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2013 Pivotal Software, Inc.
* Copyright (c) 2013, 2021 VMware Software, 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 Software, Inc. - initial API and implementation
* Pivotal VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.commons.livexp.ui;
@@ -43,6 +43,8 @@ public class StringFieldSection extends WizardPageSection {
private boolean password = false;
private boolean vertical = false;
private boolean labelUnder = false;
//////////////////////////////
@@ -64,6 +66,15 @@ public class StringFieldSection extends WizardPageSection {
return this;
}
/**
* Should be called before createContents(...) is called, i.e. before SWT controls are created.
*/
public StringFieldSection labelUnder(boolean under) {
this.labelUnder = under;
this.vertical = under || this.vertical;
return this;
}
public StringFieldSection(IPageWithSections owner, FieldModel<String> f) {
this(owner, f.getLabel(), f.getVariable(), f.getValidator());
}
@@ -85,6 +96,20 @@ public class StringFieldSection extends WizardPageSection {
return this;
}
private Label createLabel(Composite projectGroup) {
Label label = new Label(projectGroup, SWT.NONE);
label.setText(labelText);
GridDataFactory.fillDefaults()
.hint(vertical ? SWT.DEFAULT : UIConstants.fieldLabelWidthHint(label), SWT.DEFAULT)
.align(SWT.BEGINNING, SWT.CENTER)
.applyTo(label);
if (tooltip!=null) {
label.setToolTipText(tooltip);
text.setToolTipText(tooltip);
}
return label;
}
@Override
public void createContents(Composite page) {
// project specification group
@@ -95,17 +120,19 @@ public class StringFieldSection extends WizardPageSection {
projectGroup.setLayout(layout);
projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label label = new Label(projectGroup, SWT.NONE);
label.setText(labelText);
GridDataFactory.fillDefaults()
.hint(vertical ? SWT.DEFAULT : UIConstants.fieldLabelWidthHint(label), SWT.DEFAULT)
.align(SWT.BEGINNING, SWT.CENTER)
.applyTo(label);
if (!labelUnder) {
createLabel(projectGroup);
}
text = new Text(projectGroup, SWT.BORDER | (password ? SWT.PASSWORD : 0));
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = UIConstants.FIELD_TEXT_AREA_WIDTH;
text.setLayoutData(data);
if (labelUnder) {
createLabel(projectGroup);
}
text.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
variable.setValue(text.getText());
@@ -125,10 +152,6 @@ public class StringFieldSection extends WizardPageSection {
enabler.addListener(UIValueListener.from((exp, enable) -> {
text.setEnabled(enable);
}));
if (tooltip!=null) {
label.setToolTipText(tooltip);
text.setToolTipText(tooltip);
}
}
public StringFieldSection tooltip(String string) {

View File

@@ -0,0 +1,162 @@
/*******************************************************************************
* Copyright (c) 2021 VMware, 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:
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.commons.livexp.ui;
import java.util.Arrays;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.TrayDialog;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.widgets.SharedScrolledComposite;
import org.eclipse.ui.progress.UIJob;
import org.springsource.ide.eclipse.commons.livexp.Activator;
import org.springsource.ide.eclipse.commons.livexp.core.Validator;
import org.springsource.ide.eclipse.commons.livexp.util.ExceptionUtil;
public class TrayDialogWithSections extends TrayDialog implements IPageWithSections, Reflowable {
private OkButtonHandler model;
private SharedScrolledComposite scroller;
private List<WizardPageSection> sections = null;
protected TrayDialogWithSections(Shell shell, OkButtonHandler model) {
super(shell);
this.model = model;
}
protected Control createDialogArea(Composite parent) {
scroller = new SharedScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL) {};
scroller.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
scroller.setExpandHorizontal(true);
scroller.setExpandVertical(true);
Composite page = new Composite(scroller, SWT.NONE);
applyDialogFont(page);
GridLayout layout = new GridLayout(1, false);
layout.marginHeight = 12;
layout.marginWidth = 12;
page.setLayout(layout);
for (PageSection section : getSections()) {
section.createContents(page);
}
page.pack(true);
scroller.setContent(page);
return parent;
}
private UIJob reflowJob;
@Override
public boolean reflow() {
if (reflowJob==null) {
reflowJob = new UIJob(Display.getDefault(), "Reflow Wizard Contents") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (scroller!=null && !scroller.isDisposed()) {
scroller.reflow(true);
}
return Status.OK_STATUS;
}
};
reflowJob.setSystem(true);
}
reflowJob.schedule();
return true;
}
protected synchronized List<WizardPageSection> getSections() {
if (sections==null) {
sections = safeCreateSections();
}
return sections;
}
private List<WizardPageSection> safeCreateSections() {
try {
return createSections();
} catch (CoreException e) {
Activator.log(e);
return Arrays.asList(
new CommentSection(this, "Dialog couldn't be created because of an unexpected error:+\n"+ExceptionUtil.getMessage(e)+"\n\n"
+ "Check the error log for details"),
new ValidatorSection(Validator.alwaysError(ExceptionUtil.getMessage(e)), this)
);
}
}
/**
* This method should be implemented to generate the contents of the page.
*/
protected List<WizardPageSection> createSections() throws CoreException {
//This default implementation is meant to be overridden
return Arrays.asList(
new CommentSection(this, "Override DialogWithSections.createSections() to provide real content."),
new ValidatorSection(Validator.alwaysError("Subclass must implement validation logic"), this)
);
}
public void dispose() {
for (WizardPageSection s : sections) {
s.dispose();
}
}
@Override
protected void cancelPressed() {
super.cancelPressed();
}
@Override
protected final void okPressed() {
super.okPressed();
try {
model.performOk();
} catch (Exception e) {
Activator.log(e);
MessageDialog.openError(getShell(), "Error", ExceptionUtil.getMessage(e));
}
}
/**
* Simulate clicking the ok button. Does nothing if ok button is not found or disabled.
*/
public boolean clickOk() {
Button button = getButton(OK);
if (button!=null && button.isEnabled()) {
okPressed();
return true;
}
return false;
}
@Override
public IRunnableContext getRunnableContext() {
return PlatformUI.getWorkbench().getProgressService();
}
}

View File

@@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2017, 2019 Pivotal, Inc.
* Copyright (c) 2017, 2021 VMware, 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
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springsource.ide.eclipse.commons.livexp.ui.util;
@@ -87,7 +87,6 @@ public class SwtConnect {
control.addDisposeListener(de -> enabler.dispose());
Disposable disconnect = enabler.onChange(UIValueListener.from((e,v) -> {
control.setEnabled(e.getValue());
System.out.println("Apply enablement changed: " + e.getValue());
}));
control.addDisposeListener(de -> disconnect.dispose());
}