From 9cc82fd598ada23e9cd83f1fe9f85e168036df76 Mon Sep 17 00:00:00 2001 From: BoykoAlex Date: Fri, 21 May 2021 11:52:55 -0400 Subject: [PATCH] Filters dialog adjustments for Boot Dash --- .../dash/dialogs/ToggleFiltersDialog.java | 34 +++- .../dialogs/ToggleFiltersDialogModel.java | 23 ++- .../boot/dash/model/ToggleFiltersModel.java | 24 ++- .../boot/dash/views/BootDashTreeView.java | 8 +- .../commons/livexp/ui/ButtonSection.java | 9 +- .../livexp/ui/ChooseMultipleSection.java | 12 +- .../eclipse/commons/livexp/ui/RowSection.java | 61 +++++++ .../commons/livexp/ui/StringFieldSection.java | 47 +++-- .../livexp/ui/TrayDialogWithSections.java | 162 ++++++++++++++++++ .../commons/livexp/ui/util/SwtConnect.java | 5 +- 10 files changed, 345 insertions(+), 40 deletions(-) create mode 100644 eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/RowSection.java create mode 100644 eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/TrayDialogWithSections.java diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/dialogs/ToggleFiltersDialog.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/dialogs/ToggleFiltersDialog.java index b57259f86..43bdf05fc 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/dialogs/ToggleFiltersDialog.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/dialogs/ToggleFiltersDialog.java @@ -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 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) + ) ); } diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/dialogs/ToggleFiltersDialogModel.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/dialogs/ToggleFiltersDialogModel.java index 215dec1d2..0c84f7d3f 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/dialogs/ToggleFiltersDialogModel.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/dialogs/ToggleFiltersDialogModel.java @@ -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 selectedFilters = new LiveSet<>(); + private LiveVariable enableRegexFilter = new LiveVariable<>(); + private LiveVariable regexFilter = new LiveVariable<>(); private LiveVariable 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 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()); } } diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/ToggleFiltersModel.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/ToggleFiltersModel.java index 5ac6044db..fe8291fe4 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/ToggleFiltersModel.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/model/ToggleFiltersModel.java @@ -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>() { { dependsOn(selectedFilters); dependsOn(regexFilter); + dependsOn(enableRegexFilter); } @Override protected Filter compute() { - Filter composed = REGEX_FILTER; + Filter 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>() { public void gotValue(LiveExpression> exp, ImmutableSet 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 selectedFilters; private final LiveVariable regexFilter; + private final LiveVariable enableRegexFilter; private final LiveExpression> compositeFilter; /** @@ -263,4 +276,7 @@ public class ToggleFiltersModel { public LiveVariable getRegexFilter() { return regexFilter; } + public LiveVariable getEnableRegexFilter() { + return enableRegexFilter; + } } diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/BootDashTreeView.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/BootDashTreeView.java index 1b1b3d38e..5c45ba510 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/BootDashTreeView.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/BootDashTreeView.java @@ -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()); diff --git a/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/ButtonSection.java b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/ButtonSection.java index 9b141e449..ffb9597e5 100644 --- a/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/ButtonSection.java +++ b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/ButtonSection.java @@ -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 enabler) { diff --git a/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/ChooseMultipleSection.java b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/ChooseMultipleSection.java index eb8287b2b..680f1f15f 100644 --- a/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/ChooseMultipleSection.java +++ b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/ChooseMultipleSection.java @@ -128,17 +128,19 @@ public class ChooseMultipleSection extends WizardPageSecti }); } - if (DEBUG) { - chosen.addListener(new ValueListener>() { - public void gotValue(LiveExpression> exp, Set value) { + chosen.addListener(new ValueListener>() { + public void gotValue(LiveExpression> exp, Set value) { + Set 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"); } - }); - } + } + }); } diff --git a/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/RowSection.java b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/RowSection.java new file mode 100644 index 000000000..6403d6086 --- /dev/null +++ b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/RowSection.java @@ -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 getValidator() { + return validator; + } + +} diff --git a/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/StringFieldSection.java b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/StringFieldSection.java index 1f6aee9fb..1a7e0b049 100644 --- a/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/StringFieldSection.java +++ b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/StringFieldSection.java @@ -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 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) { diff --git a/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/TrayDialogWithSections.java b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/TrayDialogWithSections.java new file mode 100644 index 000000000..a557e275c --- /dev/null +++ b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/TrayDialogWithSections.java @@ -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 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 getSections() { + if (sections==null) { + sections = safeCreateSections(); + } + return sections; + } + + private List 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 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(); + } + +} diff --git a/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/util/SwtConnect.java b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/util/SwtConnect.java index f6a4e701b..a34bf3453 100644 --- a/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/util/SwtConnect.java +++ b/eclipse-language-servers/org.springsource.ide.eclipse.commons.livexp/src/org/springsource/ide/eclipse/commons/livexp/ui/util/SwtConnect.java @@ -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()); }