Destiny.Lin
1 year ago
7 changed files with 691 additions and 14 deletions
@ -0,0 +1,375 @@
|
||||
package com.fr.design.mainframe.vcs.ui; |
||||
|
||||
|
||||
import com.fr.base.svg.IconUtils; |
||||
import com.fr.design.dialog.BasicDialog; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.dialog.DialogActionAdapter; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.ibutton.UIRadioButton; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.iprogressbar.ModernUIProgressBarUI; |
||||
import com.fr.design.gui.ispinner.UISpinner; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.layout.VerticalFlowLayout; |
||||
import com.fr.design.mainframe.vcs.common.VcsHelper; |
||||
import com.fr.design.utils.DesignUtils; |
||||
import com.fr.design.widget.FRWidgetFactory; |
||||
import com.fr.general.FRFont; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.transaction.Configurations; |
||||
import com.fr.transaction.WorkerAdaptor; |
||||
import com.fr.workspace.server.vcs.VcsConfig; |
||||
import com.fr.workspace.server.vcs.VcsManager; |
||||
import com.fr.workspace.server.vcs.v2.move.VcsMoveService; |
||||
import com.fr.workspace.server.vcs.v2.move.VcsMoveStrategy; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import java.util.List; |
||||
import java.util.concurrent.ExecutionException; |
||||
|
||||
|
||||
/** |
||||
* 迁移面板 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @since 11.0 |
||||
* Created on 2023/6/13 |
||||
*/ |
||||
public class VcsMovePanel extends BasicPane { |
||||
private static final FRFont FONT = DesignUtils |
||||
.getDefaultGUIFont() |
||||
.applySize(14) |
||||
.applyStyle(FRFont.BOLD); |
||||
|
||||
private static final Color BACK_GROUND_COLOR = new Color(202,232,255); |
||||
|
||||
//提示字体的颜色,直接模仿其他面板的写法
|
||||
private static final Color TIP_COLOR = new Color(51, 51, 52, (int)Math.round(0.5 * 255)); |
||||
|
||||
private static final Color LABEL_COLOR = new Color(34,149,233); |
||||
|
||||
private static final int MIN_VALUE = 1; |
||||
|
||||
private static final int MAX_VALUE = 999; |
||||
|
||||
private static final int STEP = 1; |
||||
|
||||
private static final int DEFAULT_VALUE = 5; |
||||
|
||||
public static final String SETTING = "SETTING"; |
||||
|
||||
public static final String PROCESS = "PROCESS"; |
||||
|
||||
public static final String SUCCESS = "SUCCESS"; |
||||
|
||||
public static final String FAILED = "FAILED"; |
||||
|
||||
public static boolean moving = false; |
||||
private UILabel vcsUpdateExistLabel; |
||||
private UILabel vcsUpdateFireLabel; |
||||
private BasicPane choosePane; |
||||
private CardLayout parentCard; |
||||
private JPanel parentPane; |
||||
private static final JProgressBar progressBar = new JProgressBar(); |
||||
|
||||
private JPanel progressPanel; |
||||
private UILabel tipLabel; |
||||
private UIButton successButton; |
||||
private UILabel iconLabel; |
||||
private UILabel successLabel; |
||||
private UILabel successTipLabel; |
||||
private UIButton failedButton; |
||||
private UILabel failedIconLabel; |
||||
private UILabel failedLabel; |
||||
private UILabel failedTipLabel; |
||||
|
||||
//保留全部
|
||||
private UIRadioButton moveAllButton; |
||||
//默认选项,保留部分
|
||||
private UIRadioButton moveDefaultButton; |
||||
//全部放弃
|
||||
private UIRadioButton moveNothingButton; |
||||
|
||||
private UISpinner spinner; |
||||
|
||||
|
||||
public VcsMovePanel(CardLayout cardLayout, JPanel parentPane) { |
||||
this.parentCard = cardLayout; |
||||
this.parentPane = parentPane; |
||||
this.setLayout(new BorderLayout()); |
||||
JPanel updatePane = FRGUIPaneFactory.createBoxFlowInnerContainer_S_Pane(); |
||||
updatePane.setBackground(BACK_GROUND_COLOR); |
||||
//初始化迁移的面板
|
||||
initVcsLabel(updatePane); |
||||
//initVcsChoosePane
|
||||
initVcsChoosePane(); |
||||
//初始化listener
|
||||
initListener(); |
||||
this.add(updatePane); |
||||
checkVisible(); |
||||
//如果已经在迁移
|
||||
if (VcsMoveService.getInstance().isMoving()) { |
||||
initProcessPane(); |
||||
VcsMovePanel.this.getParentCard().show(getParentPane(), PROCESS); |
||||
} |
||||
} |
||||
|
||||
private void checkVisible() { |
||||
new SwingWorker<Boolean, Void>() { |
||||
@Override |
||||
protected Boolean doInBackground() throws Exception { |
||||
return VcsHelper.getInstance().checkMoveFunctionSupport(); |
||||
} |
||||
@Override |
||||
protected void done() { |
||||
try { |
||||
boolean useMove = get(); |
||||
VcsMovePanel.this.setVisible(useMove); |
||||
} catch (InterruptedException | ExecutionException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
}.execute(); |
||||
} |
||||
|
||||
private void initProcessPane() { |
||||
JPanel processPane = new JPanel(); |
||||
JPanel body = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane(); |
||||
progressBar.setStringPainted(true); |
||||
progressBar.setUI(new ModernUIProgressBarUI()); |
||||
progressBar.setBorderPainted(false); |
||||
progressBar.setOpaque(false); |
||||
progressBar.setBorder(null); |
||||
progressBar.setSize(BasicDialog.MEDIUM); |
||||
body.add(progressBar); |
||||
body.add(new UILabel(StringUtils.BLANK)); |
||||
tipLabel = new UILabel(Toolkit.i18nText("Fine-Design_Vcs_While_Moving")); |
||||
tipLabel.setAlignmentX(CENTER_ALIGNMENT); |
||||
body.add(tipLabel); |
||||
processPane.add(body); |
||||
processPane.setLayout(FRGUIPaneFactory.createCenterLayout(body, 0.5f, 0.5f)); |
||||
parentPane.add(processPane, PROCESS); |
||||
} |
||||
|
||||
private void initVcsChoosePane() { |
||||
choosePane = new BasicPane() { |
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Toolkit.i18nText("Fine-Design_Vcs_Deal_With_Entry"); |
||||
} |
||||
}; |
||||
VerticalFlowLayout layout = new VerticalFlowLayout(VerticalFlowLayout.TOP); |
||||
layout.setAlignLeft(true); |
||||
choosePane.setLayout(layout); |
||||
|
||||
//初始化上方的文字板块
|
||||
initTopDesc(); |
||||
//初始化中间区域的单选框
|
||||
initRadioButton(); |
||||
//初始化下方的Tip描述
|
||||
initTipDesc(); |
||||
} |
||||
|
||||
private void initTopDesc() { |
||||
UILabel label = new UILabel(Toolkit.i18nText("Fine-Design_Vcs_How_To_Deal_With_Entry")); |
||||
choosePane.add(label); |
||||
} |
||||
|
||||
private void initTipDesc() { |
||||
UILabel descLabel = FRWidgetFactory.createLineWrapLabel(Toolkit.i18nText("Fine-Design_Vcs_Move_Desc")); |
||||
descLabel.setForeground(TIP_COLOR); |
||||
choosePane.add(descLabel); |
||||
} |
||||
|
||||
private void initRadioButton() { |
||||
//保留全部
|
||||
moveAllButton = new UIRadioButton(Toolkit.i18nText("Fine-Design_Vcs_Move_All")); |
||||
//默认选项,保留部分
|
||||
moveDefaultButton = new UIRadioButton(Toolkit.i18nText("Fine-Design_Vcs_Move_Default")); |
||||
//全部放弃
|
||||
moveNothingButton = new UIRadioButton(Toolkit.i18nText("Fine-Design_Vcs_Move_Nothing")); |
||||
// 将按钮"保留部分"设置为选中状态
|
||||
moveDefaultButton.setSelected(true); |
||||
// 创建一个按钮组,添加三个按钮
|
||||
ButtonGroup buttonGroup = new ButtonGroup(); |
||||
buttonGroup.add(moveAllButton); |
||||
buttonGroup.add(moveDefaultButton); |
||||
buttonGroup.add(moveNothingButton); |
||||
|
||||
JPanel moveDefaultPanel = new JPanel(); |
||||
JPanel moveAllPane = new JPanel(); |
||||
JPanel moveNothingPane = new JPanel(); |
||||
moveAllPane.add(moveAllButton); |
||||
moveDefaultPanel.add(moveDefaultButton); |
||||
moveDefaultPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Vcs_Move_Default_Text_Left"))); |
||||
spinner = new UISpinner(MIN_VALUE, MAX_VALUE, STEP, DEFAULT_VALUE); |
||||
moveDefaultPanel.add(spinner); |
||||
moveDefaultPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Vcs_Move_Default_Text_Right"))); |
||||
moveNothingPane.add(moveNothingButton); |
||||
choosePane.add(moveAllPane); |
||||
choosePane.add(moveDefaultPanel); |
||||
choosePane.add(moveNothingPane); |
||||
} |
||||
|
||||
private void initVcsLabel(JPanel parent) { |
||||
vcsUpdateExistLabel = new UILabel(IconUtils.readIcon("/com/fr/design/vcs/vcs_move_icon.svg")); |
||||
vcsUpdateExistLabel.setText(Toolkit.i18nText("Fine-Design_Vcs_Can_Update")); |
||||
vcsUpdateFireLabel = new UILabel(Toolkit.i18nText("Fine-Design_Vcs_Update")); |
||||
vcsUpdateFireLabel.setForeground(LABEL_COLOR); |
||||
vcsUpdateFireLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
||||
parent.add(vcsUpdateExistLabel); |
||||
parent.add(vcsUpdateFireLabel); |
||||
} |
||||
|
||||
private void initListener() { |
||||
vcsUpdateFireLabel.addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
BasicDialog dlg = choosePane.showMediumWindow(SwingUtilities.getWindowAncestor(VcsMovePanel.this), new DialogActionAdapter() { |
||||
@Override |
||||
public void doOk() { |
||||
//进度条面板
|
||||
initProcessPane(); |
||||
VcsMovePanel.this.getParentCard().next(getParentPane()); |
||||
VcsMoveStrategy strategy; |
||||
if (moveDefaultButton.isSelected()) { |
||||
strategy = VcsMoveStrategy.createNumStrategy((int) spinner.getValue()); |
||||
} else if (moveNothingButton.isSelected()) { |
||||
strategy = VcsMoveStrategy.ALL_GIVE_UP; |
||||
} else { |
||||
strategy = VcsMoveStrategy.ALL_RETAIN; |
||||
} |
||||
new MoveWorker(strategy).execute(); |
||||
} |
||||
}); |
||||
dlg.setVisible(true); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void initSuccessPane() { |
||||
JPanel successPane = new JPanel(); |
||||
JPanel body = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane(); |
||||
successButton = new UIButton(Toolkit.i18nText("Fine-Design_Vcs_Move_Success_Go")); |
||||
iconLabel = new UILabel(IconUtils.readIcon("/com/fr/design/vcs/move_success.svg")); |
||||
successLabel = new UILabel(Toolkit.i18nText("Fine-Design_Vcs_Move_Success")); |
||||
successLabel.setFont(FONT); |
||||
successTipLabel = new UILabel(Toolkit.i18nText("Fine-Design_Vcs_Move_Success_Tip")); |
||||
successTipLabel.setForeground(TIP_COLOR); |
||||
body.add(iconLabel); |
||||
body.add(new UILabel(StringUtils.BLANK)); |
||||
body.add(successLabel); |
||||
body.add(new UILabel(StringUtils.BLANK)); |
||||
body.add(successTipLabel); |
||||
body.add(new UILabel(StringUtils.BLANK)); |
||||
body.add(successButton); |
||||
successPane.add(body); |
||||
successPane.setLayout(FRGUIPaneFactory.createCenterLayout(body, 0.5f, 0.5f)); |
||||
parentPane.add(successPane, SUCCESS); |
||||
iconLabel.setAlignmentX(CENTER_ALIGNMENT); |
||||
successLabel.setAlignmentX(CENTER_ALIGNMENT); |
||||
successButton.setAlignmentX(CENTER_ALIGNMENT); |
||||
successTipLabel.setAlignmentX(CENTER_ALIGNMENT); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
public CardLayout getParentCard() { |
||||
return parentCard; |
||||
} |
||||
|
||||
public JPanel getParentPane() { |
||||
return parentPane; |
||||
} |
||||
|
||||
private void initFailedPane() { |
||||
JPanel failedPane = new JPanel(); |
||||
JPanel body = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane(); |
||||
failedButton = new UIButton(Toolkit.i18nText("Fine-Design_Vcs_Move_Failed_Go")); |
||||
failedIconLabel = new UILabel(IconUtils.readIcon("/com/fr/design/vcs/move_failed.svg")); |
||||
failedLabel = new UILabel(Toolkit.i18nText("Fine-Design_Vcs_Move_Failed")); |
||||
failedLabel.setFont(FONT); |
||||
failedTipLabel = new UILabel(Toolkit.i18nText("Fine-Design_Vcs_Move_Failed_Tip")); |
||||
failedTipLabel.setForeground(TIP_COLOR); |
||||
body.add(failedIconLabel); |
||||
body.add(new UILabel(StringUtils.BLANK)); |
||||
body.add(failedLabel); |
||||
body.add(new UILabel(StringUtils.BLANK)); |
||||
body.add(failedTipLabel); |
||||
body.add(new UILabel(StringUtils.BLANK)); |
||||
body.add(failedButton); |
||||
failedPane.add(body); |
||||
failedPane.setLayout(FRGUIPaneFactory.createCenterLayout(body, 0.5f, 0.5f)); |
||||
parentPane.add(failedPane, FAILED); |
||||
failedIconLabel.setAlignmentX(CENTER_ALIGNMENT); |
||||
failedLabel.setAlignmentX(CENTER_ALIGNMENT); |
||||
failedButton.setAlignmentX(CENTER_ALIGNMENT); |
||||
failedTipLabel.setAlignmentX(CENTER_ALIGNMENT); |
||||
} |
||||
|
||||
|
||||
private class MoveWorker extends SwingWorker<Void, Integer> { |
||||
|
||||
private VcsMoveStrategy strategy; |
||||
|
||||
public MoveWorker(VcsMoveStrategy strategy) { |
||||
this.strategy = strategy; |
||||
} |
||||
|
||||
@Override |
||||
protected Void doInBackground() throws Exception { |
||||
try { |
||||
//开始迁移
|
||||
VcsMoveService.getInstance().startMove(new VcsMoveService.MoveServiceWhileMoving() { |
||||
@Override |
||||
public void publishProgress() { |
||||
int num = VcsMoveService.getInstance().getCurrentMove(); |
||||
publish(num); |
||||
} |
||||
@Override |
||||
public void prepare4Move() { |
||||
progressBar.setMaximum(VcsMoveService.getInstance().getTotal()); |
||||
} |
||||
}, strategy); |
||||
} catch (Exception e) { |
||||
this.cancel(true); |
||||
VcsMoveService.getInstance().stopMoving(); |
||||
initFailedPane(); |
||||
VcsMovePanel.this.getParentCard().show(getParentPane(), FAILED); |
||||
FineLoggerFactory.getLogger().error("[VcsV2] Vcs move failed!"); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
protected void process(List<Integer> chunks) { |
||||
progressBar.setValue(chunks.get(chunks.size() - 1)); |
||||
} |
||||
|
||||
@Override |
||||
protected void done() { |
||||
VcsMoveService.getInstance().stopMoving(); |
||||
initSuccessPane(); |
||||
VcsMovePanel.this.getParentCard().show(getParentPane(), SUCCESS); |
||||
Configurations.update(new WorkerAdaptor(VcsConfig.class) { |
||||
@Override |
||||
public void run() { |
||||
VcsConfig.getInstance().setUseV2(true); |
||||
} |
||||
}); |
||||
VcsManager.getInstance().updateManager(); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
After Width: | Height: | Size: 549 B |
After Width: | Height: | Size: 533 B |
Loading…
Reference in new issue