Browse Source

REPORT-14865 更新日志推送=>持久化,重构

research/10.0
plough 6 years ago
parent
commit
c9f4d2ae97
  1. 42
      designer-base/src/main/java/com/fr/design/DesignerEnvManager.java
  2. 18
      designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java
  3. 61
      designer-base/src/main/java/com/fr/design/onlineupdate/push/DesignerPushUpdateConfigManager.java
  4. 39
      designer-base/src/main/java/com/fr/design/onlineupdate/push/DesignerPushUpdateManager.java
  5. 72
      designer-base/src/test/java/com/fr/design/onlineupdate/push/DesignerPushUpdateConfigManagerTest.java

42
designer-base/src/main/java/com/fr/design/DesignerEnvManager.java

@ -14,6 +14,7 @@ import com.fr.design.env.DesignerWorkspaceType;
import com.fr.design.env.LocalDesignerWorkspaceInfo; import com.fr.design.env.LocalDesignerWorkspaceInfo;
import com.fr.design.env.RemoteDesignerWorkspaceInfo; import com.fr.design.env.RemoteDesignerWorkspaceInfo;
import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.onlineupdate.push.DesignerPushUpdateConfigManager;
import com.fr.design.style.color.ColorSelectConfigManager; import com.fr.design.style.color.ColorSelectConfigManager;
import com.fr.design.utils.DesignUtils; import com.fr.design.utils.DesignUtils;
import com.fr.file.FILEFactory; import com.fr.file.FILEFactory;
@ -139,7 +140,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
//记录当前激活码的在线激活状态. //记录当前激活码的在线激活状态.
private int activeKeyStatus = -1; private int activeKeyStatus = -1;
private boolean joinProductImprove = true; private boolean joinProductImprove = true;
private boolean automaticPushUpdate = true;
//最近使用的颜色 //最近使用的颜色
private ColorSelectConfigManager configManager = new ColorSelectConfigManager(); private ColorSelectConfigManager configManager = new ColorSelectConfigManager();
/** /**
@ -147,6 +147,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
*/ */
private AlphaFineConfigManager alphaFineConfigManager = new AlphaFineConfigManager(); private AlphaFineConfigManager alphaFineConfigManager = new AlphaFineConfigManager();
private DesignerPushUpdateConfigManager designerPushUpdateConfigManager = DesignerPushUpdateConfigManager.getInstance();
public static final String CAS_CERTIFICATE_PATH = "certificatePath"; public static final String CAS_CERTIFICATE_PATH = "certificatePath";
@ -690,28 +691,12 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
this.joinProductImprove = joinProductImprove; this.joinProductImprove = joinProductImprove;
} }
/** public boolean isAutoPushUpdateEnabled() {
* 是否开启自动更新推送 return designerPushUpdateConfigManager.isAutoPushUpdateEnabled();
*
* @return 是否开启自动更新推送
*/
public boolean isAutomaticPushUpdate() {
return automaticPushUpdate;
}
/**
* 设置开启/关闭自动更新推送
*/
public void setAutomaticPushUpdate(boolean automaticPushUpdate) {
this.automaticPushUpdate = automaticPushUpdate;
} }
/** public void setAutoPushUpdateEnabled(boolean autoPushUpdateEnabled) {
* @return "自动更新推送"选项是否生效 designerPushUpdateConfigManager.setAutoPushUpdateEnabled(autoPushUpdateEnabled);
*/
public boolean isAutomaticPushUpdateValid() {
// 远程设计和非中文环境,都不生效
return WorkContext.getCurrent().isLocal() && GeneralContext.isChineseEnv();
} }
/** /**
@ -1489,6 +1474,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
readAlphaFineAttr(reader); readAlphaFineAttr(reader);
} else if (name.equals("RecentColors")) { } else if (name.equals("RecentColors")) {
readRecentColor(reader); readRecentColor(reader);
} else if (name.equals(DesignerPushUpdateConfigManager.XML_TAG)) {
readDesignerPushUpdateAttr(reader);
} else { } else {
readLayout(reader, name); readLayout(reader, name);
} }
@ -1559,7 +1546,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
this.setOracleSystemSpace(reader.getAttrAsBoolean("useOracleSystemSpace", true)); this.setOracleSystemSpace(reader.getAttrAsBoolean("useOracleSystemSpace", true));
this.setCachingTemplateLimit(reader.getAttrAsInt("cachingTemplateLimit", CACHINGTEMPLATE_LIMIT)); this.setCachingTemplateLimit(reader.getAttrAsInt("cachingTemplateLimit", CACHINGTEMPLATE_LIMIT));
this.setJoinProductImprove(reader.getAttrAsBoolean("joinProductImprove", true)); this.setJoinProductImprove(reader.getAttrAsBoolean("joinProductImprove", true));
this.setAutomaticPushUpdate(reader.getAttrAsBoolean("automaticPushUpdate", true));
this.setImageCompress(reader.getAttrAsBoolean("imageCompress", true)); this.setImageCompress(reader.getAttrAsBoolean("imageCompress", true));
this.setAutoBackUp(reader.getAttrAsBoolean("autoBackUp", true)); this.setAutoBackUp(reader.getAttrAsBoolean("autoBackUp", true));
this.setTemplateTreePaneExpanded(reader.getAttrAsBoolean("templateTreePaneExpanded", false)); this.setTemplateTreePaneExpanded(reader.getAttrAsBoolean("templateTreePaneExpanded", false));
@ -1672,6 +1658,10 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
checkRecentOpenedFileNum(); checkRecentOpenedFileNum();
} }
private void readDesignerPushUpdateAttr(XMLableReader reader) {
reader.readXMLObject(designerPushUpdateConfigManager);
}
/** /**
* Write XML.<br> * Write XML.<br>
* The method will be invoked when save data to XML file.<br> * The method will be invoked when save data to XML file.<br>
@ -1694,6 +1684,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
writeHttpsParas(writer); writeHttpsParas(writer);
writeAlphaFineAttr(writer); writeAlphaFineAttr(writer);
writeRecentColor(writer); writeRecentColor(writer);
writeDesignerPushUpdateAttr(writer);
writer.end(); writer.end();
} }
@ -1797,9 +1788,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
if (!this.isJoinProductImprove()) { if (!this.isJoinProductImprove()) {
writer.attr("joinProductImprove", this.isJoinProductImprove()); writer.attr("joinProductImprove", this.isJoinProductImprove());
} }
if (!this.isAutomaticPushUpdate()) {
writer.attr("automaticPushUpdate", this.isAutomaticPushUpdate());
}
if (!this.isImageCompress()) { if (!this.isImageCompress()) {
writer.attr("imageCompress", this.isImageCompress()); writer.attr("imageCompress", this.isImageCompress());
} }
@ -1927,4 +1915,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
.attr("undoLimit", this.getUndoLimit()) .attr("undoLimit", this.getUndoLimit())
.end(); .end();
} }
private void writeDesignerPushUpdateAttr(XMLPrintWriter writer) {
this.designerPushUpdateConfigManager.writeXML(writer);
}
} }

18
designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java

@ -22,6 +22,7 @@ import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.onlineupdate.push.DesignerPushUpdateManager;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.design.widget.FRWidgetFactory; import com.fr.design.widget.FRWidgetFactory;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
@ -116,7 +117,6 @@ public class PreferencePane extends BasicPane {
private KeyStroke shortCutKeyStore = null; private KeyStroke shortCutKeyStore = null;
private UIColorButton gridLineColorTBButton; private UIColorButton gridLineColorTBButton;
private UIColorButton paginationLineColorTBButton; private UIColorButton paginationLineColorTBButton;
private UICheckBox supportCellEditorDefCheckBox; private UICheckBox supportCellEditorDefCheckBox;
@ -131,7 +131,7 @@ public class PreferencePane extends BasicPane {
private UICheckBox oracleSpace; private UICheckBox oracleSpace;
private UISpinner cachingTemplateSpinner; private UISpinner cachingTemplateSpinner;
private UICheckBox joinProductImprove; private UICheckBox joinProductImprove;
private UICheckBox automaticPushUpdate; private UICheckBox autoPushUpdate;
public PreferencePane() { public PreferencePane() {
this.initComponents(); this.initComponents();
@ -174,9 +174,9 @@ public class PreferencePane extends BasicPane {
joinProductImprove = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Join_Product_Improve")); joinProductImprove = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Join_Product_Improve"));
improvePane.add(joinProductImprove); improvePane.add(joinProductImprove);
if (DesignerEnvManager.getEnvManager().isAutomaticPushUpdateValid()) { if (DesignerPushUpdateManager.getInstance().isAutoPushUpdateSupported()) {
automaticPushUpdate = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Automatic_Push_Update")); autoPushUpdate = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Automatic_Push_Update"));
improvePane.add(automaticPushUpdate); improvePane.add(autoPushUpdate);
} }
JPanel spaceUpPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); JPanel spaceUpPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
@ -558,8 +558,8 @@ public class PreferencePane extends BasicPane {
this.cachingTemplateSpinner.setValue(designerEnvManager.getCachingTemplateLimit()); this.cachingTemplateSpinner.setValue(designerEnvManager.getCachingTemplateLimit());
this.joinProductImprove.setSelected(designerEnvManager.isJoinProductImprove()); this.joinProductImprove.setSelected(designerEnvManager.isJoinProductImprove());
if (designerEnvManager.isAutomaticPushUpdateValid()) { if (this.autoPushUpdate != null) {
this.automaticPushUpdate.setSelected(designerEnvManager.isAutomaticPushUpdate()); this.autoPushUpdate.setSelected(designerEnvManager.isAutoPushUpdateEnabled());
} }
} }
@ -620,8 +620,8 @@ public class PreferencePane extends BasicPane {
designerEnvManager.setOracleSystemSpace(this.oracleSpace.isSelected()); designerEnvManager.setOracleSystemSpace(this.oracleSpace.isSelected());
designerEnvManager.setCachingTemplateLimit((int) this.cachingTemplateSpinner.getValue()); designerEnvManager.setCachingTemplateLimit((int) this.cachingTemplateSpinner.getValue());
designerEnvManager.setJoinProductImprove(this.joinProductImprove.isSelected()); designerEnvManager.setJoinProductImprove(this.joinProductImprove.isSelected());
if (designerEnvManager.isAutomaticPushUpdateValid()) { if (this.autoPushUpdate != null) {
designerEnvManager.setAutomaticPushUpdate(this.automaticPushUpdate.isSelected()); designerEnvManager.setAutoPushUpdateEnabled(this.autoPushUpdate.isSelected());
} }
designerEnvManager.setUndoLimit(maxUndoLimit.getSelectedIndex() * SELECTED_INDEX_5); designerEnvManager.setUndoLimit(maxUndoLimit.getSelectedIndex() * SELECTED_INDEX_5);

61
designer-base/src/main/java/com/fr/design/onlineupdate/push/DesignerPushUpdateConfigManager.java

@ -0,0 +1,61 @@
package com.fr.design.onlineupdate.push;
import com.fr.stable.StringUtils;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLReadable;
import com.fr.stable.xml.XMLWriter;
import com.fr.stable.xml.XMLableReader;
/**
* 持久化与设计器自动推送更新相关的配置
* Created by plough on 2019/4/8.
*/
public class DesignerPushUpdateConfigManager implements XMLReadable, XMLWriter {
public static final String XML_TAG = "DesignerPushUpdateConfigManager";
private static DesignerPushUpdateConfigManager singleton;
private boolean autoPushUpdateEnabled = true; // 是否开启自动推送更新
private String lastIgnoredVersion = StringUtils.EMPTY; // 最近一次跳过的更新版本
private DesignerPushUpdateConfigManager() {
}
public static DesignerPushUpdateConfigManager getInstance() {
if (singleton == null) {
singleton = new DesignerPushUpdateConfigManager();
}
return singleton;
}
@Override
public void readXML(XMLableReader reader) {
if (reader.isAttr()) {
this.setAutoPushUpdateEnabled(reader.getAttrAsBoolean("autoPushUpdateEnabled", true));
this.setLastIgnoredVersion(reader.getAttrAsString("lastIgnoredVersion", StringUtils.EMPTY));
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
writer.startTAG(XML_TAG);
writer.attr("autoPushUpdateEnabled", autoPushUpdateEnabled);
writer.attr("lastIgnoredVersion", lastIgnoredVersion);
writer.end();
}
public boolean isAutoPushUpdateEnabled() {
return autoPushUpdateEnabled;
}
public void setAutoPushUpdateEnabled(boolean autoPushUpdateEnabled) {
this.autoPushUpdateEnabled = autoPushUpdateEnabled;
}
public String getLastIgnoredVersion() {
return lastIgnoredVersion;
}
public void setLastIgnoredVersion(String lastIgnoredVersion) {
this.lastIgnoredVersion = lastIgnoredVersion;
}
}

39
designer-base/src/main/java/com/fr/design/onlineupdate/push/DesignerPushUpdateManager.java

@ -0,0 +1,39 @@
package com.fr.design.onlineupdate.push;
import com.fr.general.GeneralContext;
import com.fr.workspace.WorkContext;
/**
* Created by plough on 2019/4/8.
*/
public class DesignerPushUpdateManager {
private static DesignerPushUpdateManager singleton;
// private DesignerUpdateInfo updateInfo;
private DesignerPushUpdateManager() {
}
public static DesignerPushUpdateManager getInstance() {
if (singleton == null) {
singleton = new DesignerPushUpdateManager();
}
return singleton;
}
/**
* "自动更新推送"选项是否生效
*/
public boolean isAutoPushUpdateSupported() {
// 远程设计和非中文环境,都不生效
return WorkContext.getCurrent().isLocal() && GeneralContext.isChineseEnv();
}
/**
* 检查更新如果有合适的更新版本则弹窗
*/
// public void checkAndPop() {
// updateInfo.
// }
}

72
designer-base/src/test/java/com/fr/design/onlineupdate/push/DesignerPushUpdateConfigManagerTest.java

@ -0,0 +1,72 @@
package com.fr.design.onlineupdate.push;
import com.fr.stable.StringUtils;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLableReader;
import com.fr.third.javax.xml.stream.XMLStreamException;
import org.junit.Test;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* Created by plough on 2019/4/8.
*/
public class DesignerPushUpdateConfigManagerTest {
@Test
public void testSingleton() {
DesignerPushUpdateConfigManager m1 = DesignerPushUpdateConfigManager.getInstance();
DesignerPushUpdateConfigManager m2 = DesignerPushUpdateConfigManager.getInstance();
assertSame(m1, m2);
}
@Test
public void testDefaultValue() throws XMLStreamException {
DesignerPushUpdateConfigManager configManager = DesignerPushUpdateConfigManager.getInstance();
XMLableReader xmlReader = XMLableReader.createXMLableReader(new StringReader("<xml></xml>"));
xmlReader.readXMLObject(configManager);
assertEquals(StringUtils.EMPTY, configManager.getLastIgnoredVersion());
assertTrue(configManager.isAutoPushUpdateEnabled());
}
@Test
public void testReadAndWrite() throws XMLStreamException {
final String initLastIngnoredVersion = "1.1.2";
final boolean initAutoPushEnabled = false;
DesignerPushUpdateConfigManager configManager = DesignerPushUpdateConfigManager.getInstance();
configManager.setLastIgnoredVersion(initLastIngnoredVersion);
configManager.setAutoPushUpdateEnabled(initAutoPushEnabled);
// 写入 xml
StringWriter sw = new StringWriter();
XMLPrintWriter writer = XMLPrintWriter.create(new PrintWriter(sw));
configManager.writeXML(writer);
writer.flush();
writer.close();
String xml_str = sw.getBuffer().toString();
// 临时修改配置
configManager.setAutoPushUpdateEnabled(true);
configManager.setLastIgnoredVersion("0.20.1");
// 从 xml 中读取
StringReader sr = new StringReader(xml_str);
XMLableReader xmlReader = XMLableReader.createXMLableReader(sr);
xmlReader.readXMLObject(configManager);
// 验证:与写入时的配置一致
assertEquals(initLastIngnoredVersion, configManager.getLastIgnoredVersion());
assertEquals(initAutoPushEnabled, configManager.isAutoPushUpdateEnabled());
}
}
Loading…
Cancel
Save