diff --git a/designer-base/src/main/java/com/fr/design/mainframe/toolbar/VcsConfig.java b/designer-base/src/main/java/com/fr/design/mainframe/toolbar/VcsConfig.java deleted file mode 100644 index 8364f546f0..0000000000 --- a/designer-base/src/main/java/com/fr/design/mainframe/toolbar/VcsConfig.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.fr.design.mainframe.toolbar; - -import com.fr.design.mainframe.vcs.ui.FileVersionCellEditor; -import com.fr.design.mainframe.vcs.ui.FileVersionCellRender; -import com.fr.design.mainframe.vcs.ui.FileVersionFirstRowPanel; -import com.fr.design.mainframe.vcs.ui.FileVersionRowPanel; -import com.fr.design.mainframe.vcs.ui.FileVersionTablePanel; -import com.fr.design.mainframe.vcs.ui.FileVersionsPanel; -import com.fr.third.javax.inject.Singleton; -import com.fr.third.springframework.context.annotation.Bean; -import com.fr.third.springframework.context.annotation.ComponentScan; -import com.fr.third.springframework.context.annotation.Configuration; -import com.fr.workspace.WorkContext; -import com.fr.workspace.server.vcs.VcsOperator; -import com.fr.workspace.server.vcs.VcsOperatorImpl; -import com.fr.workspace.server.vcs.filesystem.VcsFileSystem; -import com.fr.workspace.server.vcs.git.FineGit; - - -/** - * Created by XiaXiang on 2019/4/16. - */ -@Configuration -@ComponentScan({"com.fr.workspace.server.vcs", "com.fr.design.mainframe.vcs"}) -public class VcsConfig { - @Bean - @Singleton - public FileVersionsPanel fileVersionsPanel() { - return new FileVersionsPanel(fileVersionTablePanel()); - } - - @Bean - @Singleton - public FileVersionTablePanel fileVersionTablePanel() { - return new FileVersionTablePanel(vcsOperator(), fileVersionCellEditor(), fileVersionCellRender()); - } - - @Bean - @Singleton - public FileVersionCellEditor fileVersionCellEditor() { - return new FileVersionCellEditor(fileVersionFirstRowPanel(), fileVersionRowPanel(), vcsOperator()); - } - - @Bean - @Singleton - public FileVersionFirstRowPanel fileVersionFirstRowPanel() { - return new FileVersionFirstRowPanel(); - } - - @Bean - public FileVersionRowPanel fileVersionRowPanel() { - return new FileVersionRowPanel(vcsOperator()); - } - - @Bean - @Singleton - public FileVersionCellRender fileVersionCellRender() { - return new FileVersionCellRender(fileVersionFirstRowPanel(), fileVersionRowPanel()); - } - - @Bean - @Singleton - public VcsOperator vcsOperator() { - return new VcsOperatorImpl(vcsFileSystem(), new FineGit(vcsFileSystem().getVcsHistoryPath())); - } - - @Bean - @Singleton - public VcsFileSystem vcsFileSystem() { - return new VcsFileSystem(WorkContext.getCurrent()); - } - - -} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/vcs/common/Constants.java b/designer-base/src/main/java/com/fr/design/mainframe/vcs/common/Constants.java new file mode 100644 index 0000000000..de5f54d55d --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/vcs/common/Constants.java @@ -0,0 +1,47 @@ +package com.fr.workspace.server.vcs.common; + +import com.fr.base.BaseUtils; +import com.fr.locale.InterProviderFactory; +import com.fr.workspace.WorkContext; + +import javax.swing.Icon; +import javax.swing.border.EmptyBorder; +import java.awt.Color; + +import static com.fr.stable.StableUtils.pathJoin; + + +public class Constants { + + public final static String VCS_DIR = "vcs"; + + // 如果用其他方式实现vcs,未必需要这个cache + //TODO 要不要放到其他地方 + public final static String VCS_CACHE_DIR = pathJoin(VCS_DIR, "cache"); + + public final static String CURRENT_USERSNAME = WorkContext.getCurrent().isLocal() + ? InterProviderFactory.getProvider().getLocText("本地用户") + : WorkContext.getCurrent().getConnection().getUserName(); + + public final static Color TABLE_SELECT_BACKGROUND = new Color(0xD8F2FD); + + public final static Color COPY_VERSION_BTN_COLOR = new Color(0x419BF9); + + public final static Color DELETE_VERSION_BTN_COLOR = new Color(0xEB1D1F); + + public final static EmptyBorder EMPTY_BORDER = new EmptyBorder(5, 10, 0, 10); + + public final static EmptyBorder EMPTY_BORDER_BOTTOM = new EmptyBorder(10, 10, 10, 10); + + + public final static Icon VCS_LIST_PNG = BaseUtils.readIcon("/com/fr/design/mainframe/vcs/images/vcs_list.png"); + public final static Icon VCS_BACK_PNG = BaseUtils.readIcon("/com/fr/design/mainframe/vcs/images/vcs_back.png"); + public final static Icon VCS_SAVE_PNG = BaseUtils.readIcon("/com/fr/design/mainframe/vcs/images/vcs_save.png"); + public final static Icon VCS_FILTER_PNG = BaseUtils.readIcon("/com/fr/design/mainframe/vcs/images/icon_filter@1x.png"); + public final static Icon VCS_EDIT_PNG = BaseUtils.readIcon("/com/fr/design/mainframe/vcs/images/icon_edit.png"); + public final static Icon VCS_DELETE_PNG = BaseUtils.readIcon("/com/fr/design/mainframe/vcs/images/icon_delete.png"); + public final static Icon VCS_USER_PNG = BaseUtils.readIcon("/com/fr/design/mainframe/vcs/images/icon_user@1x.png"); + public final static Icon VCS_REVERT = BaseUtils.readIcon("/com/fr/design/mainframe/vcs/images/icon_revert.png"); + + +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/vcs/proxy/VcsCacheFileNodeFileProxy.java b/designer-base/src/main/java/com/fr/design/mainframe/vcs/proxy/VcsCacheFileNodeFile.java similarity index 95% rename from designer-base/src/main/java/com/fr/design/mainframe/vcs/proxy/VcsCacheFileNodeFileProxy.java rename to designer-base/src/main/java/com/fr/design/mainframe/vcs/proxy/VcsCacheFileNodeFile.java index d2665cff46..2d59a4cebc 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/vcs/proxy/VcsCacheFileNodeFileProxy.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/vcs/proxy/VcsCacheFileNodeFile.java @@ -1,6 +1,7 @@ package com.fr.design.mainframe.vcs.proxy; import com.fr.base.io.XMLEncryptUtils; +import com.fr.design.mainframe.vcs.common.Constants; import com.fr.file.FileNodeFILE; import com.fr.file.filetree.FileNode; import com.fr.general.ComparatorUtils; @@ -8,14 +9,11 @@ import com.fr.stable.StableUtils; import com.fr.workspace.WorkContext; import com.fr.workspace.resource.WorkResource; import com.fr.workspace.resource.WorkResourceOutputStream; -import com.fr.workspace.server.vcs.common.Constants; import java.io.InputStream; import java.io.OutputStream; -/** - * Created by hzzz on 2017/12/21. - */ + public class VcsCacheFileNodeFileProxy extends FileNodeFILE { private final FileNode node; diff --git a/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/EditFileVersionDialog.java b/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/EditFileVersionDialog.java new file mode 100644 index 0000000000..b05d2ad9d4 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/EditFileVersionDialog.java @@ -0,0 +1,131 @@ +package com.fr.plugin.vcs.ui; + +import com.fr.design.dialog.UIDialog; +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.icontainer.UIScrollPane; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextarea.UITextArea; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.Inter; +import com.fr.plugin.vcs.Vcs; +import com.fr.plugin.vcs.common.proxy.VcsCacheFileNodeFileProxy; +import com.fr.stable.StringUtils; +import com.fr.third.guava.base.Preconditions; +import com.google.inject.Inject; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import static com.fr.plugin.vcs.common.CommonUtils.editingFilename; +import static com.fr.plugin.vcs.common.Constants.CURRENT_USERSNAME; + +/** + * 保存保本时候弹出的对话框,输入commit msg,点确定保存版本 + * Created by hzzz on 2017/12/11. + */ +public class SaveFileVersionDialog extends UIDialog { + + private final UITextArea msgTestArea = new UITextArea(); + private final UILabel versionLabel = new UILabel(); + private Vcs vcs; + private FileVersionTablePanel fileVersionTablePanel; + + @Inject + public SaveFileVersionDialog(FileVersionTablePanel fileVersionTablePanel, Vcs vcs) { + this(DesignerContext.getDesignerFrame()); + this.vcs = Preconditions.checkNotNull(vcs, "vcs is null"); + this.fileVersionTablePanel = Preconditions.checkNotNull(fileVersionTablePanel, "fileVersionTablePanel is null"); + } + + private SaveFileVersionDialog(Frame parent) { + super(parent); + + initComponents(); + setModal(true); + setTitle(Inter.getLocText("Plugin-VCS_Save_Version")); + setSize(300, 220); + setResizable(false); + GUICoreUtils.centerWindow(this); + + } + + private void initComponents() { + + JPanel fontPane = new JPanel(new BorderLayout()); + fontPane.add(new UILabel(" " + Inter.getLocText("Plugin-VCS_Version_Message") + ":"), BorderLayout.NORTH); + + msgTestArea.setBorder(null); + JScrollPane jScrollPane = new UIScrollPane(msgTestArea); + + Component[][] components = new Component[][]{ + new Component[]{new UILabel(" " + Inter.getLocText("Plugin-VCS_Version_Number") + ":"), versionLabel}, + new Component[]{fontPane, jScrollPane} + }; + double[] rowSizes = new double[]{25, 100}; + double[] columnSizes = new double[]{70, 200}; + + add(TableLayoutHelper.createTableLayoutPane(components, rowSizes, columnSizes), BorderLayout.CENTER); + + JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + add(buttonPane, BorderLayout.SOUTH); + + UIButton ok = new UIButton(Inter.getLocText("OK")); + UIButton cancel = new UIButton(Inter.getLocText("Cancel")); + + buttonPane.add(ok); + buttonPane.add(cancel); + + ok.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + JTemplate jt = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + jt.stopEditing(); + jt.saveTemplate(); + String filename = editingFilename(); + String versionLabelText = versionLabel.getText(); + // V.3 -> 3 + String version = versionLabelText.substring(2); + //TODO refactor + if (jt.getEditingFILE() instanceof VcsCacheFileNodeFileProxy) { + vcs.saveVersionFromCache(CURRENT_USERSNAME, filename, msgTestArea.getText(), Integer.parseInt(version)); + fileVersionTablePanel.updateModel(1); + } else { + vcs.saveVersion(CURRENT_USERSNAME, filename, msgTestArea.getText(), Integer.parseInt(version)); + } + jt.requestFocus(); + doOK(); + } + }); + + cancel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + doCancel(); + } + }); + } + + private void refresh() { + int latestFileVersion = vcs.getLatestFileVersion(editingFilename()); + versionLabel.setText("V." + String.valueOf(latestFileVersion + 1)); + msgTestArea.setText(StringUtils.EMPTY); + } + + public void showMsgInputDialog() { + refresh(); + setVisible(true); + } + + @Override + public void checkValid() throws Exception { + + } +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionTablePanel.java b/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionTable.java similarity index 99% rename from designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionTablePanel.java rename to designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionTable.java index 45b52b9ba1..a833edc733 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionTablePanel.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionTable.java @@ -30,7 +30,6 @@ public class FileVersionTablePanel extends JTable { public void updateModel(int selectedRow) { String path = DesignerFrameFileDealerPane.getInstance().getSelectedOperation().getFilePath(); - //TODO path "/" List vcsEntities = null; try { vcsEntities = vcs.getVersions(path.replaceFirst("/", ""));