From 407df3dd184fd8625717f17a88443d5f77f844c7 Mon Sep 17 00:00:00 2001 From: Starryi Date: Tue, 28 Sep 2021 18:54:40 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-57806=20=E4=B8=BB=E9=A2=98=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 把弹窗按钮交互分离出来 【改动思路】 同上 --- .../actions/DownloadSuitableThemeAction.java | 153 ++++++++++++++++ .../share/ui/actions/Jump2DetailAction.java | 41 +++++ .../ui/block/AbstractOnlineWidgetBlock.java | 163 +----------------- 3 files changed, 197 insertions(+), 160 deletions(-) create mode 100644 designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/DownloadSuitableThemeAction.java create mode 100644 designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/Jump2DetailAction.java diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/DownloadSuitableThemeAction.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/DownloadSuitableThemeAction.java new file mode 100644 index 000000000..d1a175b94 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/DownloadSuitableThemeAction.java @@ -0,0 +1,153 @@ +package com.fr.design.mainframe.share.ui.actions; + +import com.fr.base.theme.FormTheme; +import com.fr.base.theme.FormThemeConfig; +import com.fr.base.theme.TemplateTheme; +import com.fr.base.theme.TemplateThemeConfig; +import com.fr.design.DesignerEnvManager; +import com.fr.design.actions.UpdateAction; +import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.i18n.Toolkit; +import com.fr.design.login.DesignerLoginHelper; +import com.fr.design.login.DesignerLoginSource; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.mainframe.share.util.DownloadUtils; +import com.fr.stable.StringUtils; +import com.fr.transaction.CallBackAdaptor; +import com.fr.workspace.WorkContext; + +import javax.swing.Action; +import javax.swing.JOptionPane; +import javax.swing.SwingWorker; +import java.awt.event.ActionEvent; + +/** + * @author Starryi + * @version 1.0 + * Created by Starryi on 2021/9/28 + */ +public class DownloadSuitableThemeAction extends UpdateAction { + private final String themePath; + private boolean downloading = false; + + public DownloadSuitableThemeAction(String themePath) { + this.themePath = themePath; + this.putValue(Action.SMALL_ICON, null); + this.setName(Toolkit.i18nText("Fine-Design_Share_Download_Suitable_Theme")); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (checkAuthority()) { + saveTheme(); + } + } + + private boolean checkAuthority() { + if (!WorkContext.getCurrent().isRoot()) { + FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Share_Download_Suitable_Theme_No_Authority_Tip_Message"), + Toolkit.i18nText("Fine-Design_Share_Download_Suitable_Theme_No_Authority_Tip_Title"), + JOptionPane.WARNING_MESSAGE); + return false; + } + + String userName = DesignerEnvManager.getEnvManager().getDesignerLoginUsername(); + if (StringUtils.isEmpty(userName)) { + DesignerLoginHelper.showLoginDialog(DesignerLoginSource.NORMAL); + return false; + } + + return true; + } + + private void saveTheme() { + if (downloading) { + return; + } + downloading = true; + + final JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + new SwingWorker() { + + @Override + protected Boolean doInBackground() { + FormTheme theme = fetchRemoteTheme(); + if (theme == null) { + return false; + } + + theme = ensureThemeHasUniqueName(theme, theme.getName()); + if (theme == null) { + return false; + } + + String themeName = theme.getName(); + saveThemeToConfig(theme, new SaveToThemeConfigCallback(template, themeName)); + + return true; + + } + + @Override + protected void done() { + downloading = false; + } + }.execute(); + } + + private FormTheme fetchRemoteTheme() { + return DownloadUtils.downloadThemeFile(themePath); + } + + private FormTheme ensureThemeHasUniqueName(FormTheme theme, String expectedName) { + if (!FormThemeConfig.getInstance().contains(expectedName)) { + theme.setName(expectedName); + return theme; + } else { + String newName = (String) FineJOptionPane.showInputDialog( + DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Share_Rename_Suitable_Theme_Tip"), + Toolkit.i18nText("Fine-Design_Basic_Rename"), + FineJOptionPane.QUESTION_MESSAGE, null, null, + expectedName); + + return StringUtils.isEmpty(newName) ? null : ensureThemeHasUniqueName(theme, newName); + } + } + + private void saveThemeToConfig(final FormTheme theme, CallBackAdaptor callback) { + FormThemeConfig.getInstance().addTheme(theme, true, callback); + } + + public static class SaveToThemeConfigCallback extends CallBackAdaptor { + private final JTemplate template; + private final String themeName; + + public SaveToThemeConfigCallback(JTemplate template, String themeName) { + this.template = template; + this.themeName = themeName; + } + + @Override + public void afterCommit() { + super.afterCommit(); + int returnVal = FineJOptionPane.showConfirmDialog( + DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Share_Apply_Suitable_Theme_Tip"), + Toolkit.i18nText("Fine-Design_Basic_Confirm"), + FineJOptionPane.OK_CANCEL_OPTION); + if (returnVal == JOptionPane.YES_OPTION) { + applyTheme(template, themeName); + } + } + + private void applyTheme(JTemplate template, final String name) { + TemplateThemeConfig config = template.getUsingTemplateThemeConfig(); + TemplateTheme theme = config.cachedFetch(name); + template.setTemplateTheme(theme); + } + } +} diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/Jump2DetailAction.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/Jump2DetailAction.java new file mode 100644 index 000000000..73a91fc87 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/Jump2DetailAction.java @@ -0,0 +1,41 @@ +package com.fr.design.mainframe.share.ui.actions; + +import com.fr.design.actions.UpdateAction; +import com.fr.design.i18n.Toolkit; +import com.fr.form.share.bean.OnlineShareWidget; +import com.fr.stable.StringUtils; + +import javax.swing.Action; +import java.awt.Desktop; +import java.awt.event.ActionEvent; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +/** + * @author Starryi + * @version 1.0 + * Created by Starryi on 2021/9/28 + */ +public class Jump2DetailAction extends UpdateAction { + private static final String ONLINE_WIDGET_DETAIL_FORMATTED_URL = "https://market.fanruan.com/reuse/%s"; + private final String id; + + public Jump2DetailAction(String id) { + this.id = id; + this.putValue(Action.SMALL_ICON, null); + this.setName(Toolkit.i18nText("Fine-Design_Share_Jump_To_Detail")); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (StringUtils.isNotEmpty(id)) { + Desktop desktop = Desktop.getDesktop(); + try { + desktop.browse(new URI(String.format(ONLINE_WIDGET_DETAIL_FORMATTED_URL, id))); + } catch (IOException | URISyntaxException ioException) { + ioException.printStackTrace(); + } + } + } +} diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/AbstractOnlineWidgetBlock.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/AbstractOnlineWidgetBlock.java index 404c319db..98e84dcd1 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/AbstractOnlineWidgetBlock.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/AbstractOnlineWidgetBlock.java @@ -1,25 +1,13 @@ package com.fr.design.mainframe.share.ui.block; -import com.fr.base.theme.FormTheme; -import com.fr.base.theme.FormThemeConfig; -import com.fr.base.theme.TemplateTheme; -import com.fr.base.theme.TemplateThemeConfig; -import com.fr.design.DesignerEnvManager; -import com.fr.design.actions.UpdateAction; import com.fr.design.constants.UIConstants; -import com.fr.design.dialog.FineJOptionPane; -import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.imenu.UIPopupMenu; -import com.fr.design.i18n.Toolkit; -import com.fr.design.login.DesignerLoginHelper; -import com.fr.design.login.DesignerLoginSource; -import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.JTemplate; +import com.fr.design.mainframe.share.ui.actions.DownloadSuitableThemeAction; +import com.fr.design.mainframe.share.ui.actions.Jump2DetailAction; import com.fr.design.mainframe.share.ui.online.OnlineResourceManager; import com.fr.design.mainframe.share.ui.online.OnlineWidgetSelectPane; import com.fr.design.mainframe.share.ui.online.ResourceLoader; -import com.fr.design.mainframe.share.util.DownloadUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.form.share.bean.OnlineShareWidget; import com.fr.form.share.constants.ShareComponentConstants; @@ -27,31 +15,21 @@ import com.fr.log.FineLoggerFactory; import com.fr.stable.EncodeConstants; import com.fr.stable.StringUtils; import com.fr.third.springframework.web.util.UriUtils; -import com.fr.transaction.CallBackAdaptor; -import com.fr.workspace.WorkContext; import org.jetbrains.annotations.NotNull; import javax.imageio.ImageIO; -import javax.swing.Action; import javax.swing.ImageIcon; -import javax.swing.JOptionPane; import javax.swing.JPopupMenu; -import javax.swing.SwingWorker; -import java.awt.Desktop; import java.awt.Dimension; import java.awt.Image; -import java.awt.event.ActionEvent; import java.awt.event.MouseEvent; import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; /** * Created by kerry on 2020-11-22 */ public abstract class AbstractOnlineWidgetBlock extends PreviewWidgetBlock implements ResourceLoader { - private static final String ONLINE_WIDGET_DETAIL_FORMATTED_URL = "https://market.fanruan.com/reuse/%s"; private final OnlineWidgetSelectPane parentPane; private UILabel coverLabel; @@ -145,144 +123,9 @@ public abstract class AbstractOnlineWidgetBlock extends PreviewWidgetBlock template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - new SwingWorker() { - - @Override - protected Boolean doInBackground() { - FormTheme theme = fetchRemoteTheme(); - if (theme == null) { - return false; - } - - theme = ensureThemeHasUniqueName(theme, theme.getName()); - if (theme == null) { - return false; - } - - String themeName = theme.getName(); - saveThemeToConfig(theme, new CallBackAdaptor() { - @Override - public void afterCommit() { - super.afterCommit(); - int returnVal = FineJOptionPane.showConfirmDialog( - DesignerContext.getDesignerFrame(), - Toolkit.i18nText("Fine-Design_Share_Apply_Suitable_Theme_Tip"), - Toolkit.i18nText("Fine-Design_Basic_Confirm"), - FineJOptionPane.OK_CANCEL_OPTION); - if (returnVal == JOptionPane.YES_OPTION) { - applyTheme(template, themeName); - } - } - }); - - return true; - - } - - @Override - protected void done() { - downloading = false; - } - }.execute(); - } - - private FormTheme fetchRemoteTheme() { - return DownloadUtils.downloadThemeFile(themePath); - } - - private FormTheme ensureThemeHasUniqueName(FormTheme theme, String expectedName) { - if (!FormThemeConfig.getInstance().contains(expectedName)) { - theme.setName(expectedName); - return theme; - } else { - String newName = (String) FineJOptionPane.showInputDialog( - DesignerContext.getDesignerFrame(), - Toolkit.i18nText("Fine-Design_Share_Rename_Suitable_Theme_Tip"), - Toolkit.i18nText("Fine-Design_Basic_Rename"), - FineJOptionPane.QUESTION_MESSAGE, null, null, - expectedName); - - return StringUtils.isEmpty(newName) ? null : ensureThemeHasUniqueName(theme, newName); - } - } - - private void saveThemeToConfig(final FormTheme theme, CallBackAdaptor callback) { - FormThemeConfig.getInstance().addTheme(theme, true, callback); - } - - private void applyTheme(JTemplate template, final String name) { - TemplateThemeConfig config = template.getUsingTemplateThemeConfig(); - TemplateTheme theme = config.cachedFetch(name); - template.setTemplateTheme(theme); - } - } - - private class Jump2DetailAction extends UpdateAction { - public Jump2DetailAction() { - this.putValue(Action.SMALL_ICON, null); - this.setName(Toolkit.i18nText("Fine-Design_Share_Jump_To_Detail")); - } - - @Override - public void actionPerformed(ActionEvent e) { - OnlineShareWidget widget = getWidget(); - String id = widget.getId(); - if (StringUtils.isNotEmpty(id)) { - Desktop desktop = Desktop.getDesktop(); - try { - desktop.browse(new URI(String.format(ONLINE_WIDGET_DETAIL_FORMATTED_URL, id))); - } catch (IOException | URISyntaxException ioException) { - ioException.printStackTrace(); - } - } - } - } - }