From e39fc2cee862c235aa208b8146359de2658b69c2 Mon Sep 17 00:00:00 2001 From: Steffen Schaefer Date: Thu, 16 Feb 2017 12:03:18 +0100 Subject: [PATCH] The regular SettingsDialog can now optionally create links --- .../gwt/client/dialog/DataEntryDialog.java | 2 +- .../components/AbstractSettingsDialog.java | 31 ++++++++++++++++++- .../shared/components/SettingsDialog.java | 18 ++++++----- .../SettingsDialogForLinkSharing.java | 21 +------------ 4 files changed, 43 insertions(+), 29 deletions(-) diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/dialog/DataEntryDialog.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/dialog/DataEntryDialog.java index aaa54871b84..62e8b466371 100755 --- a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/dialog/DataEntryDialog.java +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/dialog/DataEntryDialog.java @@ -168,12 +168,12 @@ public abstract class DataEntryDialog { if (errorMessage == null || errorMessage.isEmpty()) { getStatusLabel().setText(""); getOkButton().setEnabled(true); + onChange(result); } else { getStatusLabel().setText(errorMessage); getStatusLabel().setStyleName("errorLabel"); getOkButton().setEnabled(false); } - onChange(result); return errorMessage == null; } diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/AbstractSettingsDialog.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/AbstractSettingsDialog.java index f65efdfeb81..74693496d38 100644 --- a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/AbstractSettingsDialog.java +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/AbstractSettingsDialog.java @@ -1,5 +1,9 @@ package com.sap.sse.gwt.client.shared.components; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.user.client.ui.Anchor; import com.google.gwt.user.client.ui.FocusWidget; import com.google.gwt.user.client.ui.Widget; import com.sap.sse.common.settings.Settings; @@ -8,12 +12,37 @@ import com.sap.sse.gwt.client.dialog.DataEntryDialog; public abstract class AbstractSettingsDialog extends DataEntryDialog { private final SettingsDialogComponent settingsDialogComponent; + + private LinkWithSettingsGenerator linkWithSettingsGenerator; + private Anchor shareAnchor; protected AbstractSettingsDialog(final String shortName, SettingsDialogComponent dialogComponent, - StringMessages stringMessages, boolean animationEnabled, final DialogCallback callback) { + StringMessages stringMessages, boolean animationEnabled, LinkWithSettingsGenerator linkWithSettingsGenerator, final DialogCallback callback) { super(stringMessages.settingsForComponent(shortName), null, stringMessages.ok(), stringMessages.cancel(), dialogComponent.getValidator(), animationEnabled, callback != null ? callback : new NoOpDialogCallback()); this.settingsDialogComponent = dialogComponent; + + this.linkWithSettingsGenerator = linkWithSettingsGenerator; + if(linkWithSettingsGenerator != null) { + shareAnchor = new Anchor(stringMessages.sharedSettingsLink()); + shareAnchor.getElement().getStyle().setMargin(3, Unit.PX); + shareAnchor.ensureDebugId("ShareAnchor"); + shareAnchor.setTarget("_blank"); + getLeftButtonPannel().add(shareAnchor); + + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + onChange(getResult()); + } + }); + } + } + + @Override + protected void onChange(SettingsType result) { + String link = linkWithSettingsGenerator.createUrl(result); + shareAnchor.setHref(link); } @Override diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/SettingsDialog.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/SettingsDialog.java index 721e8d42644..4de9b5c8f5b 100755 --- a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/SettingsDialog.java +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/SettingsDialog.java @@ -11,17 +11,21 @@ import com.sap.sse.gwt.client.StringMessages; public class SettingsDialog extends AbstractSettingsDialog { public SettingsDialog(final Component component, StringMessages stringMessages) { - this(component, stringMessages, /* animationEnabled */ true); + this(component, stringMessages, /* animationEnabled */ true, null); } - + + public SettingsDialog(final Component component, StringMessages stringMessages, LinkWithSettingsGenerator linkWithSettingsGenerator) { + this(component, stringMessages, /* animationEnabled */ true, linkWithSettingsGenerator); + } + public SettingsDialog(final Component component, StringMessages stringMessages, - boolean animationEnabled) { - this(component, component.getSettingsDialogComponent(), stringMessages, animationEnabled, null); + boolean animationEnabled, LinkWithSettingsGenerator linkWithSettingsGenerator) { + this(component, component.getSettingsDialogComponent(), stringMessages, animationEnabled, linkWithSettingsGenerator, null); } public SettingsDialog(final Component component, StringMessages stringMessages, DialogCallback callback) { - this(component, component.getSettingsDialogComponent(), stringMessages, /* animationEnabled */ true, callback); + this(component, component.getSettingsDialogComponent(), stringMessages, /* animationEnabled */ true, null, callback); } /** @@ -50,8 +54,8 @@ public class SettingsDialog extends AbstractSetti */ private SettingsDialog(final Component component, SettingsDialogComponent dialogComponent, StringMessages stringMessages, - boolean animationEnabled, final DialogCallback callback) { - super(component.getLocalizedShortName(), dialogComponent, stringMessages, animationEnabled, + boolean animationEnabled, LinkWithSettingsGenerator linkWithSettingsGenerator, final DialogCallback callback) { + super(component.getLocalizedShortName(), dialogComponent, stringMessages, animationEnabled, linkWithSettingsGenerator, new DialogCallback() { @Override public void cancel() { diff --git a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/SettingsDialogForLinkSharing.java b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/SettingsDialogForLinkSharing.java index cff47d8b091..b4b4750b2c1 100644 --- a/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/SettingsDialogForLinkSharing.java +++ b/java/com.sap.sse.gwt/src/com/sap/sse/gwt/client/shared/components/SettingsDialogForLinkSharing.java @@ -1,15 +1,10 @@ package com.sap.sse.gwt.client.shared.components; -import com.google.gwt.dom.client.Style.Unit; -import com.google.gwt.user.client.ui.Anchor; import com.sap.sse.common.settings.Settings; import com.sap.sse.gwt.client.StringMessages; public class SettingsDialogForLinkSharing extends AbstractSettingsDialog { - private LinkWithSettingsGenerator linkWithSettingsGenerator; - private Anchor shareAnchor; - public SettingsDialogForLinkSharing(LinkWithSettingsGenerator linkWithSettingsGenerator, ComponentLifecycle componentLifecycle, StringMessages stringMessages) { this(linkWithSettingsGenerator, componentLifecycle, componentLifecycle.createDefaultSettings(), stringMessages, @@ -20,20 +15,6 @@ public class SettingsDialogForLinkSharing extends ComponentLifecycle componentLifecycle, SettingsType settings, StringMessages stringMessages, boolean animationEnabled, DialogCallback callback) { super(componentLifecycle.getLocalizedShortName(), componentLifecycle.getSettingsDialogComponent(settings), - stringMessages, animationEnabled, callback); - this.linkWithSettingsGenerator = linkWithSettingsGenerator; - shareAnchor = new Anchor(stringMessages.sharedSettingsLink()); - shareAnchor.getElement().getStyle().setMargin(3, Unit.PX); - shareAnchor.ensureDebugId("ShareAnchor"); - shareAnchor.setTarget("_blank"); - getLeftButtonPannel().add(shareAnchor); - // // initial link - // onChange(settings); - } - - @Override - protected void onChange(SettingsType result) { - String link = linkWithSettingsGenerator.createUrl(getResult()); - shareAnchor.setHref(link); + stringMessages, animationEnabled, linkWithSettingsGenerator, callback); } }