kuangshuai
3 years ago
10 changed files with 418 additions and 58 deletions
@ -1,22 +1,287 @@ |
|||||||
package com.fr.design.mainframe.guide.creator.theme; |
package com.fr.design.mainframe.guide.creator.theme; |
||||||
|
|
||||||
|
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.dialog.FineJOptionPane; |
||||||
|
import com.fr.design.file.HistoryTemplateListCache; |
||||||
|
import com.fr.design.gui.ibutton.UIButton; |
||||||
|
import com.fr.design.gui.ibutton.UITabGroup; |
||||||
import com.fr.design.i18n.Toolkit; |
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.mainframe.DesignerContext; |
||||||
|
import com.fr.design.mainframe.EastRegionContainerPane; |
||||||
|
import com.fr.design.mainframe.FormWidgetDetailPane; |
||||||
|
import com.fr.design.mainframe.JTemplate; |
||||||
import com.fr.design.mainframe.guide.GuideIds; |
import com.fr.design.mainframe.guide.GuideIds; |
||||||
import com.fr.design.mainframe.guide.base.Guide; |
import com.fr.design.mainframe.guide.base.Guide; |
||||||
import com.fr.design.mainframe.guide.base.GuideBuilder; |
import com.fr.design.mainframe.guide.base.GuideBuilder; |
||||||
import com.fr.design.mainframe.guide.base.GuideLifecycleAdaptor; |
import com.fr.design.mainframe.guide.base.GuideLifecycleAdaptor; |
||||||
|
import com.fr.design.mainframe.guide.base.GuideManager; |
||||||
|
import com.fr.design.mainframe.guide.creator.GuideCreateUtils; |
||||||
|
import com.fr.design.mainframe.guide.creator.GuideSceneHelper; |
||||||
|
import com.fr.design.mainframe.guide.scene.ClickScene; |
||||||
|
import com.fr.design.mainframe.guide.scene.DisplayScene; |
||||||
|
import com.fr.design.mainframe.guide.scene.GuideScene; |
||||||
|
import com.fr.design.mainframe.guide.scene.GuideSceneLifecycleAdaptor; |
||||||
|
import com.fr.design.mainframe.guide.tip.GuideTip; |
||||||
|
import com.fr.design.mainframe.share.ui.block.OnlineWidgetPackageBlock; |
||||||
|
import com.fr.design.mainframe.share.ui.online.OnlineWidgetRepoPane; |
||||||
|
import com.fr.design.mainframe.share.ui.online.OnlineWidgetTabPane; |
||||||
|
import com.fr.design.mainframe.share.util.DownloadUtils; |
||||||
|
import com.fr.design.utils.ComponentUtils; |
||||||
|
import com.fr.form.share.utils.ShareUtils; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import com.fr.workspace.WorkContext; |
||||||
|
|
||||||
|
import javax.swing.JComponent; |
||||||
|
import javax.swing.JDialog; |
||||||
|
import javax.swing.JOptionPane; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import javax.swing.JPopupMenu; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Point; |
||||||
|
import java.awt.event.ContainerAdapter; |
||||||
|
import java.awt.event.ContainerEvent; |
||||||
|
import java.util.TimerTask; |
||||||
|
import java.util.UUID; |
||||||
|
|
||||||
public class DownloadComponentPackageGuide { |
public class DownloadComponentPackageGuide { |
||||||
|
private static String filePath; |
||||||
|
private static OnlineWidgetPackageBlock onlineWidgetPackageBlock; |
||||||
|
private static String downloadThemeName; |
||||||
|
private static JDialog themeConfirmDialog; |
||||||
|
|
||||||
public static Guide createGuide() { |
public static Guide createGuide() { |
||||||
|
GuideScene scene = createScene(); |
||||||
|
scene.nextScene(createScene2()) |
||||||
|
.nextScene(createScene3()) |
||||||
|
.nextScene(createScene4()) |
||||||
|
.nextScene(createScene5()) |
||||||
|
.nextScene(createScene6()) |
||||||
|
.nextScene(GuideSceneHelper.createFormDesignerBodyDisplayScene()); |
||||||
|
|
||||||
Guide guide = GuideBuilder.newInstance() |
Guide guide = GuideBuilder.newInstance() |
||||||
.setID(GuideIds.Guide.F002002) |
.setID(GuideIds.Guide.F002002) |
||||||
.setName(Toolkit.i18nText("Fine-Design_Guide_Scene_F002002_Name")) |
.setName(Toolkit.i18nText("Fine-Design_Guide_Scene_F002002_Name")) |
||||||
.setDescription(Toolkit.i18nText("Fine-Design_Guide_Scene_F002002_Description")) |
.setDescription(Toolkit.i18nText("Fine-Design_Guide_Scene_F002002_Description")) |
||||||
|
.setCompleteMessage(Toolkit.i18nText("Fine-Design_Guide_Scene_F002002_Complete_Message")) |
||||||
|
.addScene(scene) |
||||||
.registerLifecycle(new GuideLifecycleAdaptor() { |
.registerLifecycle(new GuideLifecycleAdaptor() { |
||||||
|
@Override |
||||||
|
public boolean prepared() { |
||||||
|
String userName = DesignerEnvManager.getEnvManager().getDesignerLoginUsername(); |
||||||
|
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; |
||||||
|
} else if (StringUtils.isEmpty(userName)) { |
||||||
|
GuideCreateUtils.showUnLoginAlert(); |
||||||
|
GuideManager.getInstance().getCurrentGuide().end(); |
||||||
|
return false; |
||||||
|
} else if (!ShareUtils.testConnection()) { |
||||||
|
GuideCreateUtils.showNoNetworkAlert(); |
||||||
|
GuideManager.getInstance().getCurrentGuide().end(); |
||||||
|
return false; |
||||||
|
} |
||||||
|
boolean loadWidgetSuccess = OnlineWidgetRepoPane.loadWidgets(); |
||||||
|
if (loadWidgetSuccess) { |
||||||
|
filePath = GuideCreateUtils.openGuideFile("/com/fr/report/guide/template", "layout_recommend", ".frm"); |
||||||
|
EastRegionContainerPane.getInstance().switchTabTo(EastRegionContainerPane.KEY_WIDGET_SETTINGS); |
||||||
|
OnlineWidgetRepoPane onlineWidgetRepoPane = OnlineWidgetRepoPane.getInstance(); |
||||||
|
OnlineWidgetTabPane tabPane = (OnlineWidgetTabPane) ComponentUtils.findComponentByClass(onlineWidgetRepoPane, OnlineWidgetTabPane.class); |
||||||
|
UITabGroup tabGroup = (UITabGroup) ComponentUtils.findComponentByClass(tabPane, UITabGroup.class); |
||||||
|
JPanel centerPane = (JPanel) tabPane.getComponent(1); |
||||||
|
if (centerPane.getComponentCount() > 0) { |
||||||
|
GuideManager.getInstance().getCurrentGuide().start(); |
||||||
|
} else { |
||||||
|
centerPane.addContainerListener(new ContainerAdapter() { |
||||||
|
@Override |
||||||
|
public void componentAdded(ContainerEvent e) { |
||||||
|
GuideManager.getInstance().getCurrentGuide().start(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
tabGroup.setSelectedIndex(1); |
||||||
|
tabGroup.tabChanged(1); |
||||||
|
} else { |
||||||
|
GuideCreateUtils.showNoNetworkAlert(); |
||||||
|
GuideManager.getInstance().getCurrentGuide().end(); |
||||||
|
return false; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onEnd() { |
||||||
|
closeConfirmDialog(); |
||||||
|
GuideCreateUtils.deleteGuideFile(filePath); |
||||||
|
FormThemeConfig.getInstance().removeTheme(downloadThemeName); |
||||||
|
filePath = null; |
||||||
|
onlineWidgetPackageBlock = null; |
||||||
|
downloadThemeName = null; |
||||||
|
themeConfirmDialog = null; |
||||||
|
} |
||||||
}) |
}) |
||||||
.getGuide(); |
.getGuide(); |
||||||
|
|
||||||
return guide; |
return guide; |
||||||
} |
} |
||||||
|
|
||||||
|
private static void downLoadTheme() { |
||||||
|
String themePath = onlineWidgetPackageBlock.getWidget().getThemePath(); |
||||||
|
FormTheme theme = DownloadUtils.downloadThemeFile(themePath); |
||||||
|
if (theme == null) { |
||||||
|
GuideCreateUtils.showNoNetworkAlert(); |
||||||
|
GuideManager.getInstance().getCurrentGuide().terminate(); |
||||||
|
} |
||||||
|
downloadThemeName = theme.getName() + UUID.randomUUID().toString(); |
||||||
|
theme.setName(downloadThemeName); |
||||||
|
FormThemeConfig.getInstance().addTheme(theme, true); |
||||||
|
} |
||||||
|
|
||||||
|
private static GuideScene createScene() { |
||||||
|
ClickScene scene = new ClickScene(); |
||||||
|
scene.registerLifecycle(new GuideSceneLifecycleAdaptor() { |
||||||
|
@Override |
||||||
|
public boolean prepared() { |
||||||
|
Component button = ComponentUtils.findComponentByName(EastRegionContainerPane.getInstance().getLeftPane(), EastRegionContainerPane.KEY_WIDGET_LIB); |
||||||
|
if (button instanceof UIButton) { |
||||||
|
scene.addClickTarget(button, ClickScene.ClickType.LEFT, true); |
||||||
|
scene.addBubbleTip(Toolkit.i18nText("Fine-Design_Guide_Scene_F002002_Tip_Click_Widget_Lib"), GuideTip.Direction.BOTTOM); |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onComplete() { |
||||||
|
FormWidgetDetailPane.getInstance().swich2Online(); |
||||||
|
} |
||||||
|
}); |
||||||
|
return scene; |
||||||
|
} |
||||||
|
|
||||||
|
private static GuideScene createScene2() { |
||||||
|
ClickScene scene = new ClickScene(); |
||||||
|
scene.registerLifecycle(new GuideSceneLifecycleAdaptor() { |
||||||
|
@Override |
||||||
|
public boolean prepared() { |
||||||
|
onlineWidgetPackageBlock = (OnlineWidgetPackageBlock) ComponentUtils.findComponentByClass(EastRegionContainerPane.getInstance(), OnlineWidgetPackageBlock.class); |
||||||
|
if (onlineWidgetPackageBlock != null) { |
||||||
|
scene.addClickTarget(onlineWidgetPackageBlock, ClickScene.ClickType.RIGHT); |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
}); |
||||||
|
return scene; |
||||||
|
} |
||||||
|
|
||||||
|
private static GuideScene createScene3() { |
||||||
|
DisplayScene scene = new DisplayScene(); |
||||||
|
scene.registerLifecycle(new GuideSceneLifecycleAdaptor() { |
||||||
|
@Override |
||||||
|
public boolean prepared() { |
||||||
|
scene.addTarget(onlineWidgetPackageBlock); |
||||||
|
JPopupMenu popupMenu = onlineWidgetPackageBlock.getComponentPopupMenu(); |
||||||
|
Point location = getPopupMenuLocation(); |
||||||
|
scene.addCustomTarget( |
||||||
|
GuideCreateUtils.createTarget(popupMenu), |
||||||
|
GuideCreateUtils.getRelativeBounds(popupMenu, onlineWidgetPackageBlock, location.x, location.y) |
||||||
|
); |
||||||
|
return true; |
||||||
|
} |
||||||
|
}); |
||||||
|
return scene; |
||||||
|
} |
||||||
|
|
||||||
|
private static GuideScene createScene4() { |
||||||
|
ClickScene scene = new ClickScene(); |
||||||
|
scene.registerLifecycle(new GuideSceneLifecycleAdaptor() { |
||||||
|
@Override |
||||||
|
public boolean prepared() { |
||||||
|
JPopupMenu popupMenu = onlineWidgetPackageBlock.getComponentPopupMenu(); |
||||||
|
Point location = getPopupMenuLocation(); |
||||||
|
scene.addCustomTarget( |
||||||
|
GuideCreateUtils.createModalTarget(popupMenu), |
||||||
|
GuideCreateUtils.getRelativeBounds(popupMenu, onlineWidgetPackageBlock, location.x, location.y) |
||||||
|
); |
||||||
|
scene.addCustomClickTarget( |
||||||
|
GuideCreateUtils.createTarget((JComponent)popupMenu.getComponent(0)), |
||||||
|
GuideCreateUtils.getRelativeBounds(popupMenu.getComponent(0), onlineWidgetPackageBlock, location.x, location.y), |
||||||
|
ClickScene.ClickType.LEFT |
||||||
|
); |
||||||
|
scene.addClickTarget(popupMenu.getComponent(0), ClickScene.ClickType.LEFT, true); |
||||||
|
popupMenu.setVisible(false); |
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onComplete() { |
||||||
|
downLoadTheme(); |
||||||
|
GuideCreateUtils.showConfirmDialog( |
||||||
|
DesignerContext.getDesignerFrame(), |
||||||
|
Toolkit.i18nText("Fine-Design_Share_Apply_Suitable_Theme_Tip"), |
||||||
|
Toolkit.i18nText("Fine-Design_Basic_Confirm"), |
||||||
|
FineJOptionPane.OK_CANCEL_OPTION); |
||||||
|
} |
||||||
|
}); |
||||||
|
return scene; |
||||||
|
} |
||||||
|
|
||||||
|
private static GuideScene createScene5() { |
||||||
|
DisplayScene scene = new DisplayScene(); |
||||||
|
scene.registerLifecycle(new GuideSceneLifecycleAdaptor() { |
||||||
|
@Override |
||||||
|
public boolean prepared() { |
||||||
|
GuideCreateUtils.TIMER.schedule(new TimerTask() { |
||||||
|
@Override |
||||||
|
public void run() { |
||||||
|
scene.addTarget(themeConfirmDialog); |
||||||
|
scene.showScene(); |
||||||
|
GuideCreateUtils.TIMER.purge(); |
||||||
|
} |
||||||
|
}, 300); |
||||||
|
return false; |
||||||
|
} |
||||||
|
}); |
||||||
|
return scene; |
||||||
|
} |
||||||
|
|
||||||
|
private static GuideScene createScene6() { |
||||||
|
ClickScene scene = new ClickScene(); |
||||||
|
scene.registerLifecycle(new GuideSceneLifecycleAdaptor() { |
||||||
|
@Override |
||||||
|
public boolean prepared() { |
||||||
|
Component target = ComponentUtils.findComponentByClass(themeConfirmDialog.getContentPane(), UIButton.class); |
||||||
|
scene.addClickTarget(target, ClickScene.ClickType.LEFT); |
||||||
|
scene.addBubbleTip(Toolkit.i18nText("Fine-Design_Guide_Scene_Base_Tip_Click_Confirm"), GuideTip.Direction.BOTTOM); |
||||||
|
return super.prepared(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void onComplete() { |
||||||
|
closeConfirmDialog(); |
||||||
|
JTemplate<?,?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
||||||
|
TemplateThemeConfig<? extends TemplateTheme> config = template.getUsingTemplateThemeConfig(); |
||||||
|
TemplateTheme theme = config.cachedFetch(downloadThemeName); |
||||||
|
template.setTemplateTheme(theme); |
||||||
|
} |
||||||
|
}); |
||||||
|
return scene; |
||||||
|
} |
||||||
|
|
||||||
|
private static Point getPopupMenuLocation() { |
||||||
|
JPopupMenu popupMenu = onlineWidgetPackageBlock.getComponentPopupMenu(); |
||||||
|
return new Point((onlineWidgetPackageBlock.getWidth() - popupMenu.getWidth()) / 2, (onlineWidgetPackageBlock.getHeight()- popupMenu.getHeight()) / 2); |
||||||
|
} |
||||||
|
|
||||||
|
private static void closeConfirmDialog() { |
||||||
|
if (themeConfirmDialog != null) { |
||||||
|
themeConfirmDialog.dispose(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
} |
} |
||||||
|
Loading…
Reference in new issue