From 234c29f4a7e5b9cca9cad8a2c0e4326472a9cfce Mon Sep 17 00:00:00 2001
From: Starryi <starryi@foxmail.com>
Date: Thu, 30 Sep 2021 15:12:48 +0800
Subject: [PATCH 1/3] =?UTF-8?q?REPORT-60431=20=E3=80=90=E4=B8=BB=E9=A2=98?=
 =?UTF-8?q?=E8=8E=B7=E5=8F=96=E3=80=91=E7=BB=84=E4=BB=B6=E5=8F=B3=E9=94=AE?=
 =?UTF-8?q?=E6=97=B6=EF=BC=8C=E4=B8=8B=E8=BD=BD=E6=8C=89=E9=92=AE=E4=BE=9D?=
 =?UTF-8?q?=E6=97=A7=E5=AD=98=E5=9C=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

【问题原因】
主题获取交互优化

【改动思路】
同上
---
 .../share/ui/block/OnlineWidgetBlock.java     | 35 +++++++++++++++++--
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java
index dffddc81cf..fcf22b9d84 100644
--- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java
+++ b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java
@@ -35,8 +35,11 @@ import com.fr.stable.StableUtils;
 import com.fr.stable.StringUtils;
 
 import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
 import javax.swing.SwingConstants;
 import javax.swing.SwingWorker;
+import javax.swing.event.PopupMenuEvent;
+import javax.swing.event.PopupMenuListener;
 import java.awt.AlphaComposite;
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -60,9 +63,10 @@ import java.util.concurrent.ExecutionException;
  * Created by kerry on 2020-10-19
  * 商城组件块
  */
-public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
+public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock implements PopupMenuListener {
     private boolean isMouseEnter = false;
     private boolean downloading = false;
+    private boolean popupMenuVisible = false;
     private static final Color COVER_COLOR = Color.decode("#333334");
     protected MouseEvent lastPressEvent;
     private double process = 0D;
@@ -89,6 +93,13 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
         return southPane;
     }
 
+    @Override
+    public JPopupMenu createRightClickPopupMenu() {
+        JPopupMenu popupMenu = super.createRightClickPopupMenu();
+        popupMenu.addPopupMenuListener(this);
+        return popupMenu;
+    }
+
     @Override
     public void mouseEntered(MouseEvent e) {
         super.mouseEntered(e);
@@ -113,7 +124,7 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
     public void mouseClicked(MouseEvent e) {
         super.mouseClicked(e);
         boolean isLeftClickDownloadIcon = e.getButton() != MouseEvent.BUTTON3 && getDownloadIconRec().contains(e.getX(), e.getY());
-        if (isLeftClickDownloadIcon && !checkWidgetInstalled()) {
+        if (!popupMenuVisible && isLeftClickDownloadIcon && !checkWidgetInstalled()) {
             downLoadWidget();
         }
     }
@@ -270,7 +281,7 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
             return;
         }
         //如果鼠标移动到布局内且布局不可编辑,画出编辑蒙层
-        if (isMouseEnter || downloading) {
+        if (!popupMenuVisible && (isMouseEnter || downloading)) {
             Graphics2D g2d = (Graphics2D) g;
             Composite oldComposite = g2d.getComposite();
             //画白色的编辑层
@@ -299,6 +310,24 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
         }
     }
 
+    @Override
+    public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
+        this.popupMenuVisible = true;
+        repaint();
+    }
+
+    @Override
+    public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
+        this.popupMenuVisible = false;
+        repaint();
+    }
+
+    @Override
+    public void popupMenuCanceled(PopupMenuEvent e) {
+        this.popupMenuVisible = false;
+        repaint();
+    }
+
 
     class WidgetDownloadProcess implements com.fr.design.extra.Process<Double> {
 

From bcb00232b1c8fb9a926c7ce910a709839ca2e21e Mon Sep 17 00:00:00 2001
From: Starryi <starryi@foxmail.com>
Date: Thu, 30 Sep 2021 16:09:00 +0800
Subject: [PATCH 2/3] =?UTF-8?q?REPORT-60437=20=E3=80=90=E4=B8=BB=E9=A2=98?=
 =?UTF-8?q?=E8=8E=B7=E5=8F=96=E3=80=91=E8=8E=B7=E5=8F=96=E4=B8=BB=E9=A2=98?=
 =?UTF-8?q?=E6=97=B6=EF=BC=8C=E6=B2=A1=E6=9C=89=E5=BC=B9=E5=87=BA=E6=A8=A1?=
 =?UTF-8?q?=E6=9D=BF=E4=B8=BB=E9=A2=98=E5=88=97=E8=A1=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

【问题原因】
主题获取交互优化

【改动思路】
同上
---
 .../actions/DownloadSuitableThemeAction.java  | 118 +++++++++++-------
 1 file changed, 76 insertions(+), 42 deletions(-)

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
index d1a175b946..be05db9d61 100644
--- 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
@@ -14,6 +14,7 @@ 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.design.mainframe.theme.dialog.TemplateThemeUsingDialog;
 import com.fr.stable.StringUtils;
 import com.fr.transaction.CallBackAdaptor;
 import com.fr.workspace.WorkContext;
@@ -21,7 +22,11 @@ import com.fr.workspace.WorkContext;
 import javax.swing.Action;
 import javax.swing.JOptionPane;
 import javax.swing.SwingWorker;
+import java.awt.Window;
 import java.awt.event.ActionEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.concurrent.ExecutionException;
 
 /**
  * @author Starryi
@@ -31,6 +36,7 @@ import java.awt.event.ActionEvent;
 public class DownloadSuitableThemeAction extends UpdateAction {
     private final String themePath;
     private boolean downloading = false;
+    private JTemplate<?, ?> currentTemplate;
 
     public DownloadSuitableThemeAction(String themePath) {
         this.themePath = themePath;
@@ -40,9 +46,8 @@ public class DownloadSuitableThemeAction extends UpdateAction {
 
     @Override
     public void actionPerformed(ActionEvent e) {
-        if (checkAuthority()) {
-            saveTheme();
-        }
+        currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
+        fetchTheme();
     }
 
     private boolean checkAuthority() {
@@ -63,43 +68,43 @@ public class DownloadSuitableThemeAction extends UpdateAction {
         return true;
     }
 
-    private void saveTheme() {
+    private void fetchTheme() {
+        if (!checkAuthority()) {
+            onThemeFetched(null);
+            return;
+        }
         if (downloading) {
             return;
         }
         downloading = true;
 
-        final JTemplate<?,?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
-        new SwingWorker<Boolean, Void>() {
+        new SwingWorker<FormTheme, Void>() {
 
             @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;
-
+            protected FormTheme doInBackground() {
+                return DownloadUtils.downloadThemeFile(themePath);
             }
 
             @Override
             protected void done() {
+                FormTheme theme = null;
+                try {
+                    theme = get();
+                } catch (InterruptedException | ExecutionException e) {
+                    e.printStackTrace();
+                }
+
+                onThemeFetched(theme);
                 downloading = false;
             }
         }.execute();
     }
 
-    private FormTheme fetchRemoteTheme() {
-        return DownloadUtils.downloadThemeFile(themePath);
+    public void onThemeFetched(FormTheme theme) {
+        if (theme == null) {
+            return;
+        }
+        saveTheme(theme);
     }
 
     private FormTheme ensureThemeHasUniqueName(FormTheme theme, String expectedName) {
@@ -118,36 +123,65 @@ public class DownloadSuitableThemeAction extends UpdateAction {
         }
     }
 
-    private void saveThemeToConfig(final FormTheme theme, CallBackAdaptor callback) {
-        FormThemeConfig.getInstance().addTheme(theme, true, callback);
+    private void saveTheme(FormTheme theme) {
+        final FormTheme uniqueNamedTheme = ensureThemeHasUniqueName(theme, theme.getName());
+        if (uniqueNamedTheme != null) {
+            FormThemeConfig.getInstance().addTheme(theme, true, new CallBackAdaptor() {
+                @Override
+                public void afterCommit() {
+                    super.afterCommit();
+                    onThemeSaved(uniqueNamedTheme);
+                }
+
+                @Override
+                public void afterRollback() {
+                    super.afterRollback();
+                    onThemeSaved(null);
+                }
+            });
+        } else {
+            onThemeSaved(null);
+        }
+    }
+
+    public void onThemeSaved(FormTheme theme) {
+        if (theme == null) {
+            return;
+        }
+
+        Window designerFrame = DesignerContext.getDesignerFrame();
+        TemplateThemeUsingDialog<FormTheme> dialog = new TemplateThemeUsingDialog<>(designerFrame, currentTemplate, FormThemeConfig.getInstance());
+        dialog.addWindowListener(new UsingDialogAdapter(theme));
+        dialog.setVisible(true);
+    }
+
+    public void applyTheme(JTemplate<?, ?> template, final String name, Window dialog) {
+        TemplateThemeConfig<? extends TemplateTheme> config = template.getUsingTemplateThemeConfig();
+        TemplateTheme theme = config.cachedFetch(name);
+        template.setTemplateTheme(theme);
+        dialog.repaint();
     }
 
-    public static class SaveToThemeConfigCallback extends CallBackAdaptor {
-        private final JTemplate<?,?> template;
-        private final String themeName;
+    private class UsingDialogAdapter extends WindowAdapter {
+        private final FormTheme theme;
 
-        public SaveToThemeConfigCallback(JTemplate<?, ?> template, String themeName) {
-            this.template = template;
-            this.themeName = themeName;
+        public UsingDialogAdapter(FormTheme theme) {
+            this.theme = theme;
         }
 
         @Override
-        public void afterCommit() {
-            super.afterCommit();
+        public void windowOpened(WindowEvent e) {
+            super.windowOpened(e);
+            Window window = e.getWindow();
             int returnVal = FineJOptionPane.showConfirmDialog(
-                    DesignerContext.getDesignerFrame(),
+                    window,
                     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);
+                applyTheme(currentTemplate, theme.getName(), window);
             }
-        }
-
-        private void applyTheme(JTemplate<?,?> template, final String name) {
-            TemplateThemeConfig<? extends TemplateTheme> config = template.getUsingTemplateThemeConfig();
-            TemplateTheme theme = config.cachedFetch(name);
-            template.setTemplateTheme(theme);
+            window.removeWindowListener(this);
         }
     }
 }

From b06cfadd2becfe64cd7e2d211f31d54418408bb4 Mon Sep 17 00:00:00 2001
From: Starryi <starryi@foxmail.com>
Date: Thu, 30 Sep 2021 16:59:04 +0800
Subject: [PATCH 3/3] =?UTF-8?q?REPORT-60403=20=E3=80=90=E4=B8=BB=E9=A2=98?=
 =?UTF-8?q?=E8=8E=B7=E5=8F=96=E3=80=91=E5=85=BC=E5=AE=B9=E4=B8=BB=E9=A2=98?=
 =?UTF-8?q?=E4=B8=8B=E7=94=9F=E6=88=90=E7=9A=84=E7=BB=84=E4=BB=B6=EF=BC=8C?=
 =?UTF-8?q?=E7=9B=AE=E5=89=8D=E8=BF=98=E6=98=AF=E5=AD=98=E4=BA=86=E4=B8=BB?=
 =?UTF-8?q?=E9=A2=98=E4=BF=A1=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

【问题原因】
若生成共享组件时使用的时兼容主题,则共享组件那的样式应当时自定义状态

【改动思路】
同上
---
 .../share/generate/task/ComponentCreator.java         | 11 +++++++++--
 .../mainframe/share/util/ShareComponentUtils.java     |  5 ++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentCreator.java b/designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentCreator.java
index 126660665a..ed1c2a91db 100644
--- a/designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentCreator.java
+++ b/designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentCreator.java
@@ -4,6 +4,7 @@ import com.fr.base.TableData;
 import com.fr.base.iofile.attr.ExtendSharableAttrMark;
 import com.fr.base.iofile.attr.SharableAttrMark;
 import com.fr.base.theme.TemplateTheme;
+import com.fr.base.theme.TemplateThemeConfig;
 import com.fr.design.i18n.Toolkit;
 import com.fr.design.mainframe.JTemplate;
 import com.fr.design.mainframe.share.generate.impl.AbstractComponentCreatorProcessor;
@@ -18,6 +19,7 @@ import com.fr.form.share.utils.ShareUtils;
 import com.fr.form.ui.AbstractBorderStyleWidget;
 import com.fr.form.ui.Widget;
 import com.fr.log.FineLoggerFactory;
+import com.fr.stable.StringUtils;
 import com.fr.stable.fun.IOFileAttrMark;
 import com.fr.workspace.WorkContext;
 import org.jetbrains.annotations.NotNull;
@@ -61,8 +63,13 @@ public class ComponentCreator extends AbstractComponentCreatorProcessor {
 
     private void setSuitableTemplateThemeName(JTemplate<?, ?> jt, DefaultSharableWidget info) {
         TemplateTheme theme = jt.getTemplateTheme();
-        if (theme != null) {
-            info.setSuitableTemplateThemeName(theme.getName());
+        if (theme != null ) {
+            String name = theme.getName();
+            TemplateThemeConfig<? extends TemplateTheme> config = jt.getUsingTemplateThemeConfig();
+            String name4LegacyTemplate = config.getThemeName4LegacyTemplate();
+            if (!StringUtils.equals(name, name4LegacyTemplate)) {
+                info.setSuitableTemplateThemeName(name);
+            }
         }
     }
 
diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/util/ShareComponentUtils.java b/designer-form/src/main/java/com/fr/design/mainframe/share/util/ShareComponentUtils.java
index 0dd613975e..c9da573914 100644
--- a/designer-form/src/main/java/com/fr/design/mainframe/share/util/ShareComponentUtils.java
+++ b/designer-form/src/main/java/com/fr/design/mainframe/share/util/ShareComponentUtils.java
@@ -3,6 +3,7 @@ package com.fr.design.mainframe.share.util;
 import com.fr.base.io.IOFile;
 import com.fr.base.iofile.attr.ExtendSharableAttrMark;
 import com.fr.base.theme.FormTheme;
+import com.fr.base.theme.FormThemeConfig;
 import com.fr.base.theme.TemplateTheme;
 import com.fr.base.theme.TemplateThemeCompatible;
 import com.fr.design.designer.creator.XCreator;
@@ -58,9 +59,11 @@ public class ShareComponentUtils {
         JTemplate<?,?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
         TemplateTheme theme = template.getTemplateTheme();
         if (theme instanceof FormTheme) {
+            String themeName4LegacyTemplate = FormThemeConfig.getInstance().getThemeName4LegacyTemplate();
             boolean isCurrentUsingThemeSuitSharedComponent = StringUtils.isNotEmpty(theme.getName()) &&
                     StringUtils.isNotEmpty(suitableTemplateThemeName) &&
-                    StringUtils.equals(theme.getName(), suitableTemplateThemeName);
+                    StringUtils.equals(theme.getName(), suitableTemplateThemeName) &&
+                    !StringUtils.equals(theme.getName(), themeName4LegacyTemplate);
             XCreatorUtils.setupTemplateTheme(creator, false, (FormTheme) theme, isCurrentUsingThemeSuitSharedComponent ? TemplateThemeCompatible.NONE : TemplateThemeCompatible.ABSENT);
         }
         return creator;