From ace14386607b3b6043b71c08d8f2f3afed744e76 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Fri, 26 Apr 2019 13:49:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85vcsconfigmanager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/DesignerEnvManager.java | 55 ++++---------- .../design/actions/file/PreferencePane.java | 21 ++--- .../DesignerFrameFileDealerPane.java | 2 +- .../com/fr/design/mainframe/JTemplate.java | 2 +- .../mainframe/vcs/VcsConfigManager.java | 76 +++++++++++++++++++ .../mainframe/vcs/common/VcsHelper.java | 6 +- 6 files changed, 110 insertions(+), 52 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/mainframe/vcs/VcsConfigManager.java diff --git a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java index 2c028670e..bd464d77e 100644 --- a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java +++ b/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.RemoteDesignerWorkspaceInfo; import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.mainframe.vcs.VcsConfigManager; import com.fr.design.update.push.DesignerPushUpdateConfigManager; import com.fr.design.style.color.ColorSelectConfigManager; import com.fr.design.utils.DesignUtils; @@ -130,12 +131,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { private int westRegionContainerWidth = 240; private String encryptionKey; private String jdkHome; - private boolean vcsEnable; - private boolean saveCommit; - private boolean useInterval; - private int saveInterval; - - //上一次登录弹窗的时间, 为了控制一天只弹一次窗口 private String lastShowBBSTime; @@ -155,6 +150,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { private DesignerPushUpdateConfigManager designerPushUpdateConfigManager = DesignerPushUpdateConfigManager.getInstance(); + private VcsConfigManager vcsConfigManager = VcsConfigManager.getInstance(); + public static final String CAS_CERTIFICATE_PATH = "certificatePath"; public static final String CAS_CERTIFICATE_PASSWORD = "certificatePass"; @@ -1502,6 +1499,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { readOpenDebug(reader); } else if (name.equals(DesignerPushUpdateConfigManager.XML_TAG)) { readDesignerPushUpdateAttr(reader); + } else if (name.equals(vcsConfigManager.XML_TAG)) { + readVcsAttr(reader); } else { readLayout(reader, name); } @@ -1608,10 +1607,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { this.setDragPermited(reader.getAttrAsBoolean("isDragPermited", false)); this.setUndoLimit(reader.getAttrAsInt("undoLimit", 5)); this.setDefaultStringToFormula(reader.getAttrAsBoolean("defaultStringToFormula", false)); - this.setVcsEnable(reader.getAttrAsBoolean("supportVcs", true)); - this.setSaveCommit(reader.getAttrAsBoolean("saveCommit", true)); - this.setUseInterval(reader.getAttrAsBoolean("userInterval", true)); - this.setSaveInterval(reader.getAttrAsInt("saveInterval", 60)); if ((tmpVal = reader.getAttrAsString("gridLineColor", null)) != null) { this.setGridLineColor(new Color(Integer.parseInt(tmpVal))); } @@ -1692,6 +1687,10 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { reader.readXMLObject(designerPushUpdateConfigManager); } + private void readVcsAttr(XMLableReader reader) { + reader.readXMLObject(vcsConfigManager); + } + /** * Write XML.
* The method will be invoked when save data to XML file.
@@ -1716,6 +1715,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { writeRecentColor(writer); writeOpenDebug(writer); writeDesignerPushUpdateAttr(writer); + writeVcsAttr(writer); writer.end(); } @@ -1947,10 +1947,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { .attr("verticalScrollBarVisible", this.isVerticalScrollBarVisible()) .attr("horizontalScrollBarVisible", this.isHorizontalScrollBarVisible()) .attr("supportCellEditorDef", this.isSupportCellEditorDef()) - .attr("supportVcs", this.isVcsEnable()) - .attr("saveInterval", this.getSaveInterval()) - .attr("userInterval", this.isUseInterval()) - .attr("saveCommit", this.isSaveCommit()) .attr("isDragPermited", this.isDragPermited()) .attr("gridLineColor", this.getGridLineColor().getRGB()) .attr("paginationLineColor", this.getPaginationLineColor().getRGB()) @@ -1962,35 +1958,16 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { this.designerPushUpdateConfigManager.writeXML(writer); } - public boolean isVcsEnable() { - return vcsEnable; - } - - public void setVcsEnable(boolean vcsEnable) { - this.vcsEnable = vcsEnable; + private void writeVcsAttr(XMLPrintWriter writer) { + this.vcsConfigManager.writeXML(writer); } - public boolean isSaveCommit() { - return saveCommit; - } - - public void setSaveCommit(boolean saveCommit) { - this.saveCommit = saveCommit; - } - - public int getSaveInterval() { - return saveInterval; - } - - public void setSaveInterval(int saveInterval) { - this.saveInterval = saveInterval; - } - public boolean isUseInterval() { - return useInterval; + public VcsConfigManager getVcsConfigManager() { + return vcsConfigManager; } - public void setUseInterval(boolean useInterval) { - this.useInterval = useInterval; + public void setVcsConfigManager(VcsConfigManager vcsConfigManager) { + this.vcsConfigManager = vcsConfigManager; } } diff --git a/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java b/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java index da5d381c3..1686613cd 100644 --- a/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java +++ b/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java @@ -23,6 +23,7 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.vcs.VcsConfigManager; import com.fr.design.mainframe.vcs.common.VcsHelper; import com.fr.design.update.push.DesignerPushUpdateManager; import com.fr.design.utils.gui.GUICoreUtils; @@ -209,7 +210,7 @@ public class PreferencePane extends BasicPane { JPanel vcsPane = FRGUIPaneFactory.createVerticalTitledBorderPane(Toolkit.i18nText("Fine-Design_Vcs_Title")); generalPane.add(vcsPane); remindVcsLabel = new UILabel("Fine-Design_Vcs_Remind"); - remindVcsLabel.setVisible(!VcsHelper.needInit()); +// remindVcsLabel.setVisible(!VcsHelper.needInit()); vcsEnableCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Vcs_SaveAuto")); saveCommitCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Vcs_No_Delete")); saveIntervalEditor = new IntegerEditor(30); @@ -593,8 +594,9 @@ public class PreferencePane extends BasicPane { defaultStringToFormulaBox.setEnabled(false); defaultStringToFormulaBox.setSelected(false); } + VcsConfigManager vcsConfigManager = designerEnvManager.getVcsConfigManager(); if (VcsHelper.needInit()) { - vcsEnableCheckBox.setSelected(designerEnvManager.isVcsEnable()); + vcsEnableCheckBox.setSelected(vcsConfigManager.isVcsEnable()); } else { vcsEnableCheckBox.setEnabled(false); vcsEnableCheckBox.setSelected(false); @@ -605,9 +607,9 @@ public class PreferencePane extends BasicPane { useIntervalCheckBox.setEnabled(false); } - saveIntervalEditor.setValue(designerEnvManager.getSaveInterval()); - saveCommitCheckBox.setSelected(designerEnvManager.isSaveCommit()); - useIntervalCheckBox.setSelected(designerEnvManager.isUseInterval()); + saveIntervalEditor.setValue(vcsConfigManager.getSaveInterval()); + saveCommitCheckBox.setSelected(vcsConfigManager.isSaveCommit()); + useIntervalCheckBox.setSelected(vcsConfigManager.isUseInterval()); supportCellEditorDefCheckBox.setSelected(designerEnvManager.isSupportCellEditorDef()); @@ -697,10 +699,11 @@ public class PreferencePane extends BasicPane { designerEnvManager.setOracleSystemSpace(this.oracleSpace.isSelected()); designerEnvManager.setCachingTemplateLimit((int) this.cachingTemplateSpinner.getValue()); designerEnvManager.setJoinProductImprove(this.joinProductImproveCheckBox.isSelected()); - designerEnvManager.setSaveInterval(this.saveIntervalEditor.getValue()); - designerEnvManager.setVcsEnable(this.vcsEnableCheckBox.isSelected()); - designerEnvManager.setSaveCommit(this.saveCommitCheckBox.isSelected()); - designerEnvManager.setUseInterval(this.useIntervalCheckBox.isSelected()); + VcsConfigManager vcsConfigManager = designerEnvManager.getVcsConfigManager(); + vcsConfigManager.setSaveInterval(this.saveIntervalEditor.getValue()); + vcsConfigManager.setVcsEnable(this.vcsEnableCheckBox.isSelected()); + vcsConfigManager.setSaveCommit(this.saveCommitCheckBox.isSelected()); + vcsConfigManager.setUseInterval(this.useIntervalCheckBox.isSelected()); if (this.autoPushUpdateCheckBox != null) { designerEnvManager.setAutoPushUpdateEnabled(this.autoPushUpdateCheckBox.isSelected()); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java index 87966c6c1..265e7dfe6 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java @@ -464,7 +464,7 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt } private void handleVcsAction() { - if (!DesignerEnvManager.getEnvManager().isVcsEnable() || VcsHelper.isUnSelectedTemplate()) { + if (!DesignerEnvManager.getEnvManager().getVcsConfigManager().isVcsEnable() || VcsHelper.isUnSelectedTemplate()) { vcsAction.setEnabled(false); return; } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index 99273ec5b..87d0f9d35 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -543,7 +543,7 @@ public abstract class JTemplate> return false; } collectInfo(); - if (DesignerEnvManager.getEnvManager().isVcsEnable()) { + if (DesignerEnvManager.getEnvManager().getVcsConfigManager().isVcsEnable()) { VcsHelper.dealWithVcs(this); } return this.saveFile(); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/vcs/VcsConfigManager.java b/designer-base/src/main/java/com/fr/design/mainframe/vcs/VcsConfigManager.java new file mode 100644 index 000000000..8c94ac3d4 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/vcs/VcsConfigManager.java @@ -0,0 +1,76 @@ +package com.fr.design.mainframe.vcs; + +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 XiaXiang on 2019/4/26. + */ +public class VcsConfigManager implements XMLReadable, XMLWriter { + public static final String XML_TAG = "VcsConfigManager"; + private static volatile VcsConfigManager instance = new VcsConfigManager(); + + public static VcsConfigManager getInstance() { + return instance; + } + + private boolean vcsEnable; + + public boolean isVcsEnable() { + return vcsEnable; + } + + public void setVcsEnable(boolean vcsEnable) { + this.vcsEnable = vcsEnable; + } + + public boolean isSaveCommit() { + return saveCommit; + } + + public void setSaveCommit(boolean saveCommit) { + this.saveCommit = saveCommit; + } + + public boolean isUseInterval() { + return useInterval; + } + + public void setUseInterval(boolean useInterval) { + this.useInterval = useInterval; + } + + public int getSaveInterval() { + return saveInterval; + } + + public void setSaveInterval(int saveInterval) { + this.saveInterval = saveInterval; + } + + private boolean saveCommit; + private boolean useInterval; + private int saveInterval; + + @Override + public void readXML(XMLableReader reader) { + if (reader.isAttr()) { + this.setSaveCommit(reader.getAttrAsBoolean("saveCommit", true)); + this.setSaveInterval(reader.getAttrAsInt("saveInterval", 60)); + this.setUseInterval(reader.getAttrAsBoolean("useInterval", true)); + this.setVcsEnable(reader.getAttrAsBoolean("vcsEnable", true)); + } + } + + @Override + public void writeXML(XMLPrintWriter writer) { + writer.startTAG(XML_TAG); + writer.attr("saveCommit", this.isSaveCommit()); + writer.attr("saveInterval", this.getSaveInterval()); + writer.attr("useInterval", this.isUseInterval()); + writer.attr("vcsEnable", this.isVcsEnable()); + writer.end(); + } +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/vcs/common/VcsHelper.java b/designer-base/src/main/java/com/fr/design/mainframe/vcs/common/VcsHelper.java index ec88800a7..4fc99731a 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/vcs/common/VcsHelper.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/vcs/common/VcsHelper.java @@ -7,6 +7,7 @@ import com.fr.design.gui.itree.filetree.TemplateFileTree; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerFrameFileDealerPane; import com.fr.design.mainframe.JTemplate; +import com.fr.design.mainframe.vcs.VcsConfigManager; import com.fr.design.mainframe.vcs.ui.FileVersionTable; import com.fr.general.IOUtils; import com.fr.plugin.context.PluginContext; @@ -98,10 +99,10 @@ public class VcsHelper { } public static boolean needDeleteVersion(VcsEntity entity) { - if (entity == null || !DesignerEnvManager.getEnvManager().isUseInterval()) { + if (entity == null || !DesignerEnvManager.getEnvManager().getVcsConfigManager().isUseInterval()) { return false; } - return new Date().getTime() - entity.getTime().getTime() < DesignerEnvManager.getEnvManager().getSaveInterval() * MINUTE && StringUtils.isBlank(entity.getCommitMsg()); + return new Date().getTime() - entity.getTime().getTime() < DesignerEnvManager.getEnvManager().getVcsConfigManager().getSaveInterval() * MINUTE && StringUtils.isBlank(entity.getCommitMsg()); } public static boolean needInit() { @@ -117,6 +118,7 @@ public class VcsHelper { new Thread(new Runnable() { @Override public void run() { + String fileName = VcsHelper.getEditingFilename(); VcsOperator operator = WorkContext.getCurrent().get(VcsOperator.class); VcsEntity entity = operator.getFileVersionByIndex(fileName, 0);