Browse Source

Merge pull request #2743 in DESIGN/design from bugfix/10.0 to feature/10.0

* commit '2c2c66549ca5c3c40f4cb7416d7b334ca4117457':
  修改:换一种方式获取参数面板高度
  修改
  删除多余导包
  REPORT-34739 自适应布局下调整绝对画布块高度,绝对画布块乱跳并导致撤销功能失效 【问题原因】在调整绝对画布块的高度时,因为前面对绝对画布块的backupBounds做了处理,忽略了参数面板块高度带来的偏移量,所以会导致其乱跳并且撤销出错 【改动方案】在com.fr.design.designer.beans.adapters.layout.FRFitLayoutAdapter.fix(com.fr.design.designer.creator.XCreator)方法中加个判断,如果是绝对画布块,就将漏算的偏移量加上
  REPORT-40515 jar包更新到最新后普通用户切换远程目录失败
  REPORT-38688 设计器在双屏下拖动会有卡屏的现象
  REPORT-38688 设计器在双屏下拖动会有卡屏的现象
  REPORT-40027 NPE
  REPORT-40027 代码修改
  REPORT-40646 去掉无用的代码
  REPORT-40646 远程设计对接平台密码策略
  REPORT-40027 缓存模板的组件树展开路径,在切换模板的时候保证组件树的展开
research/11.0
superman 4 years ago
parent
commit
29177fb1fe
  1. 48
      designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java
  2. 55
      designer-base/src/main/java/com/fr/design/dialog/link/MessageWithLink.java
  3. 3
      designer-base/src/main/java/com/fr/design/env/RemoteDesignerWorkspaceInfo.java
  4. 22
      designer-base/src/main/java/com/fr/design/mainframe/JTemplateActionListenerAdapter.java
  5. 19
      designer-base/src/main/java/com/fr/env/RemoteEnvPane.java
  6. 2
      designer-base/src/main/java/com/fr/env/RemoteWorkspaceURL.java
  7. 139
      designer-base/src/main/java/com/fr/env/TestConnectionResult.java
  8. 15
      designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java
  9. 97
      designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java
  10. 80
      designer-form/src/main/java/com/fr/design/mainframe/FormHierarchyTreePane.java
  11. 12
      designer-form/src/main/java/com/fr/design/mainframe/JForm.java

48
designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java

@ -5,6 +5,7 @@ import com.fr.design.data.DesignTableDataManager;
import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.dialog.link.MessageWithLink;
import com.fr.design.env.DesignerWorkspaceGenerator; import com.fr.design.env.DesignerWorkspaceGenerator;
import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceInfo;
import com.fr.design.env.DesignerWorkspaceType; import com.fr.design.env.DesignerWorkspaceType;
@ -18,7 +19,10 @@ import com.fr.design.mainframe.JTemplate;
import com.fr.design.utils.DesignUtils; import com.fr.design.utils.DesignUtils;
import com.fr.env.CheckServiceDialog; import com.fr.env.CheckServiceDialog;
import com.fr.env.EnvListPane; import com.fr.env.EnvListPane;
import com.fr.env.RemoteWorkspaceURL;
import com.fr.env.TestConnectionResult;
import com.fr.exit.DesignerExiter; import com.fr.exit.DesignerExiter;
import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralUtils; import com.fr.general.GeneralUtils;
import com.fr.invoke.Reflect; import com.fr.invoke.Reflect;
import com.fr.json.JSONArray; import com.fr.json.JSONArray;
@ -40,6 +44,7 @@ import com.fr.workspace.connect.WorkspaceConnectionInfo;
import com.fr.workspace.engine.base.FineObjectPool; import com.fr.workspace.engine.base.FineObjectPool;
import com.fr.workspace.engine.channel.http.FunctionalHttpRequest; import com.fr.workspace.engine.channel.http.FunctionalHttpRequest;
import com.fr.workspace.engine.exception.WorkspaceAuthException; import com.fr.workspace.engine.exception.WorkspaceAuthException;
import com.fr.workspace.engine.exception.WorkspaceCheckException;
import com.fr.workspace.engine.exception.WorkspaceConnectionException; import com.fr.workspace.engine.exception.WorkspaceConnectionException;
import com.fr.workspace.engine.rpc.WorkspaceProxyPool; import com.fr.workspace.engine.rpc.WorkspaceProxyPool;
@ -145,21 +150,28 @@ public class EnvChangeEntrance {
strategy.showTip(new PopTip() { strategy.showTip(new PopTip() {
@Override @Override
public void show() { public void show() {
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Error"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"),
Toolkit.i18nText("Fine-Design_Basic_Error"),
ERROR_MESSAGE,
UIManager.getIcon("OptionPane.errorIcon"));
} }
}); });
return false; return false;
} catch (WorkspaceCheckException e) {
handleWorkspaceCheckException(e, strategy, connectionInfo);
return false;
} catch (Exception exception) { } catch (Exception exception) {
if (exception.getCause() instanceof WorkspaceCheckException) {
handleWorkspaceCheckException((WorkspaceCheckException) exception.getCause(), strategy, connectionInfo);
} else {
FineLoggerFactory.getLogger().error(exception.getMessage(), exception); FineLoggerFactory.getLogger().error(exception.getMessage(), exception);
strategy.showTip(new PopTip() { strategy.showTip(() -> FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
@Override Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"),
public void show() { Toolkit.i18nText("Fine-Design_Basic_Error"),
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), ERROR_MESSAGE,
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Error"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); UIManager.getIcon("OptionPane.errorIcon")));
} }
});
return false; return false;
} }
TemplateTreePane.getInstance().refreshDockingView(); TemplateTreePane.getInstance().refreshDockingView();
@ -170,6 +182,24 @@ public class EnvChangeEntrance {
return true; return true;
} }
private void handleWorkspaceCheckException(WorkspaceCheckException e, PopTipStrategy strategy, WorkspaceConnectionInfo info) {
TestConnectionResult result = TestConnectionResult.parseByException(e);
FineLoggerFactory.getLogger().error(e.getMessage(), e);
if (ComparatorUtils.equals(result, TestConnectionResult.AUTH_FAILED)) {
strategy.showTip(() -> FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"),
Toolkit.i18nText("Fine-Design_Basic_Error"),
ERROR_MESSAGE,
UIManager.getIcon("OptionPane.errorIcon")));
} else {
strategy.showTip(() -> FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
new MessageWithLink(result.getText(), Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Modify_PassWord"), info.getUrl() + RemoteWorkspaceURL.SYSTEM_LOGIN_PATH),
Toolkit.i18nText("Fine-Design_Basic_Error"),
ERROR_MESSAGE,
UIManager.getIcon("OptionPane.errorIcon")));
}
}
/** /**
* 这个功能留着可能会加回来先做注释处理 * 这个功能留着可能会加回来先做注释处理
* 切换远程环境之前进行版本检测当版本不一致的时候提示 * 切换远程环境之前进行版本检测当版本不一致的时候提示

55
designer-base/src/main/java/com/fr/design/dialog/link/MessageWithLink.java

@ -0,0 +1,55 @@
package com.fr.design.dialog.link;
import com.fr.design.gui.ilable.UILabel;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Font;
import java.net.URI;
import javax.swing.JEditorPane;
import javax.swing.event.HyperlinkEvent;
/**
* 用来构建JOptionPane带超链的消息提示
*
* @author hades
* @version 10.0
* Created by hades on 2020/10/23
*/
public class MessageWithLink extends JEditorPane {
public MessageWithLink(String message, String linkName, String link) {
super("text/html", "<html><body style=\"" + getStyle() + "\">" + message + "<a href=\"" + link + "\">" + linkName + "</a>" + "</body></html>");
addHyperlinkListener(e -> {
if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
try {
Desktop.getDesktop().browse(URI.create(link));
} catch (Exception exception) {
FineLoggerFactory.getLogger().error(exception.getMessage(), exception);
}
}
});
setEditable(false);
setBorder(null);
}
public MessageWithLink(String linkName, String link ) {
this(StringUtils.EMPTY, linkName, link);
}
private static StringBuilder getStyle() {
// 构建和相同风格样式
UILabel label = new UILabel();
Font font = label.getFont();
Color color = label.getBackground();
StringBuilder style = new StringBuilder("font-family:" + font.getFamily() + ";");
style.append("font-weight:").append(font.isBold() ? "bold" : "normal").append(";");
style.append("font-size:").append(font.getSize()).append("pt;");
style.append("background-color: rgb(").append(color.getRed()).append(",").append(color.getGreen()).append(",").append(color.getBlue()).append(");");
return style;
}
}

3
designer-base/src/main/java/com/fr/design/env/RemoteDesignerWorkspaceInfo.java vendored

@ -169,7 +169,8 @@ public class RemoteDesignerWorkspaceInfo implements DesignerWorkspaceInfo {
return result; return result;
} }
try { try {
result = WorkContext.getConnector().testConnection(connection); WorkContext.getConnector().validateVT(connection);
result = true;
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
return result; return result;

22
designer-base/src/main/java/com/fr/design/mainframe/JTemplateActionListenerAdapter.java

@ -0,0 +1,22 @@
package com.fr.design.mainframe;
/**
* @Author: Yuan.Wang
* @Date: 2020/10/27
*/
public class JTemplateActionListenerAdapter implements JTemplateActionListener {
@Override
public void templateOpened(JTemplate<?, ?> jt) {
}
@Override
public void templateSaved(JTemplate<?, ?> jt) {
}
@Override
public void templateClosed(JTemplate<?, ?> jt) {
}
}

19
designer-base/src/main/java/com/fr/env/RemoteEnvPane.java vendored

@ -4,6 +4,8 @@ import com.fr.design.DesignerEnvManager;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.beans.BasicBeanPane; import com.fr.design.beans.BasicBeanPane;
import com.fr.design.border.UITitledBorder; import com.fr.design.border.UITitledBorder;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.dialog.link.MessageWithLink;
import com.fr.design.env.RemoteDesignerWorkspaceInfo; import com.fr.design.env.RemoteDesignerWorkspaceInfo;
import com.fr.design.fun.DesignerEnvProcessor; import com.fr.design.fun.DesignerEnvProcessor;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
@ -16,6 +18,7 @@ import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.scrollruler.ModLineBorder; import com.fr.design.scrollruler.ModLineBorder;
import com.fr.license.exception.RegistEditionException; import com.fr.license.exception.RegistEditionException;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
@ -25,6 +28,7 @@ import com.fr.workspace.WorkContext;
import com.fr.workspace.connect.WorkspaceConnectionInfo; import com.fr.workspace.connect.WorkspaceConnectionInfo;
import com.fr.workspace.engine.exception.WorkspaceAuthException; import com.fr.workspace.engine.exception.WorkspaceAuthException;
import com.fr.workspace.engine.exception.WorkspaceCheckException;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.JDialog; import javax.swing.JDialog;
@ -53,12 +57,13 @@ import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.io.File; import java.io.File;
import java.util.function.Supplier;
import static com.fr.design.layout.TableLayout.FILL; import static com.fr.design.layout.TableLayout.FILL;
import static com.fr.design.layout.TableLayout.PREFERRED; import static com.fr.design.layout.TableLayout.PREFERRED;
import static com.fr.env.TestConnectionResult.AUTH_FAILED; import static com.fr.env.TestConnectionResult.AUTH_FAILED;
import static com.fr.third.guava.base.Optional.fromNullable; import static com.fr.third.guava.base.Optional.fromNullable;
import static javax.swing.JOptionPane.ERROR_MESSAGE;
/** /**
* @author yaohwu * @author yaohwu
@ -583,6 +588,8 @@ public class RemoteEnvPane extends BasicBeanPane<RemoteDesignerWorkspaceInfo> {
} catch (RegistEditionException e) { } catch (RegistEditionException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
throw e; throw e;
} catch (WorkspaceCheckException e) {
return TestConnectionResult.parseByException(e);
} }
} }
@ -591,6 +598,14 @@ public class RemoteEnvPane extends BasicBeanPane<RemoteDesignerWorkspaceInfo> {
okButton.setEnabled(true); okButton.setEnabled(true);
try { try {
TestConnectionResult result = get(); TestConnectionResult result = get();
if (result.isVerifyResult()) {
dialog.dispose();
FineJOptionPane.showMessageDialog(RemoteEnvPane.this,
new MessageWithLink(result.getText(), Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Modify_PassWord"), connection.getUrl() + RemoteWorkspaceURL.SYSTEM_LOGIN_PATH),
Toolkit.i18nText("Fine-Design_Basic_Dialog_Message_Title"),
ERROR_MESSAGE,
UIManager.getIcon("OptionPane.errorIcon"));
}
message.setText(result.getText()); message.setText(result.getText());
uiLabel.setIcon(result.getIcon()); uiLabel.setIcon(result.getIcon());
} catch (Exception e) { } catch (Exception e) {
@ -635,7 +650,7 @@ public class RemoteEnvPane extends BasicBeanPane<RemoteDesignerWorkspaceInfo> {
message.setBorder(BorderFactory.createEmptyBorder(8, 5, 0, 0)); message.setBorder(BorderFactory.createEmptyBorder(8, 5, 0, 0));
okButton.setEnabled(false); okButton.setEnabled(false);
dialog = new JDialog((Dialog) SwingUtilities.getWindowAncestor(RemoteEnvPane.this), UIManager.getString("OptionPane.messageDialogTitle"), true); dialog = new JDialog((Dialog) SwingUtilities.getWindowAncestor(RemoteEnvPane.this), Toolkit.i18nText("Fine-Design_Basic_Dialog_Message_Title"), true);
dialog.setSize(new Dimension(308, 132)); dialog.setSize(new Dimension(308, 132));
okButton.setEnabled(false); okButton.setEnabled(false);

2
designer-base/src/main/java/com/fr/env/RemoteWorkspaceURL.java vendored

@ -9,6 +9,8 @@ import com.fr.stable.StringUtils;
*/ */
public class RemoteWorkspaceURL implements FCloneable { public class RemoteWorkspaceURL implements FCloneable {
public static final String SYSTEM_LOGIN_PATH = "#management/system/login";
/** /**
* 默认 web app name * 默认 web app name
*/ */

139
designer-base/src/main/java/com/fr/env/TestConnectionResult.java vendored

@ -1,12 +1,15 @@
package com.fr.env; package com.fr.env;
import com.fr.decision.webservice.exception.login.UserLoginLockException;
import com.fr.decision.webservice.exception.login.UserPasswordNeedUpdateException;
import com.fr.decision.webservice.exception.user.UserPasswordStrengthLimitException;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.log.FineLoggerFactory; import com.fr.exception.RemoteDesignPermissionDeniedException;
import com.fr.stable.AssistUtils; import com.fr.general.ComparatorUtils;
import com.fr.workspace.WorkContext; import com.fr.stable.StringUtils;
import com.fr.workspace.connect.WorkspaceConnectionInfo; import com.fr.workspace.connect.WorkspaceConnectionInfo;
import com.fr.workspace.engine.channel.http.FunctionalHttpRequest;
import com.fr.workspace.engine.exception.WorkspaceCheckException;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.UIManager; import javax.swing.UIManager;
@ -76,12 +79,127 @@ public enum TestConnectionResult {
public String getText() { public String getText() {
return Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Auth_Failed"); return Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Auth_Failed");
} }
},
/**
* 登录锁定
*/
LOGIN_LOCK {
private String value;
@Override
public Icon getIcon() {
return UIManager.getIcon("OptionPane.errorIcon");
}
@Override
public String getText() {
return Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Login_Lock", value);
}
@Override
public String errorCode() {
return UserLoginLockException.ERROR_CODE;
}
@Override
public void setValue(String lockMin) {
this.value = lockMin;
}
@Override
public boolean isVerifyResult() {
return true;
}
},
/**
* 没有远程设计权限
*/
PERMISSION_DENIED {
@Override
public Icon getIcon() {
return UIManager.getIcon("OptionPane.errorIcon");
}
@Override
public String getText() {
return Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Permission_Denied");
}
@Override
public String errorCode() {
return RemoteDesignPermissionDeniedException.ERROR_CODE;
}
},
/**
* 弱密码
*/
PASSWORD_STRENGTH_LIMIT () {
@Override
public Icon getIcon() {
return UIManager.getIcon("OptionPane.errorIcon");
}
@Override
public String getText() {
return Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Weak_Password");
}
@Override
public String errorCode() {
return UserPasswordStrengthLimitException.ERROR_CODE;
}
@Override
public boolean isVerifyResult() {
return true;
}
},
/**
* 密码更新
*/
PASSWORD_NEED_UPDATE {
@Override
public Icon getIcon() {
return UIManager.getIcon("OptionPane.errorIcon");
}
@Override
public String getText() {
return Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Update_Password");
}
@Override
public String errorCode() {
return UserPasswordNeedUpdateException.ERROR_CODE;
}
@Override
public boolean isVerifyResult() {
return true;
}
}; };
public abstract Icon getIcon(); public abstract Icon getIcon();
public abstract String getText(); public abstract String getText();
public void setValue(String value) {
// do noting
}
public String errorCode() {
return StringUtils.EMPTY;
}
public boolean isVerifyResult() {
return false;
}
public static TestConnectionResult parse(Boolean value, WorkspaceConnectionInfo info) { public static TestConnectionResult parse(Boolean value, WorkspaceConnectionInfo info) {
if (value == null) { if (value == null) {
return AUTH_FAILED; return AUTH_FAILED;
@ -92,4 +210,17 @@ public enum TestConnectionResult {
//去掉测试连接时所做的检测 //去掉测试连接时所做的检测
return FULLY_SUCCESS; return FULLY_SUCCESS;
} }
public static TestConnectionResult parseByException(WorkspaceCheckException e) {
for (TestConnectionResult result : values()) {
if (ComparatorUtils.equals(e.errorCode(), result.errorCode())) {
// 登录锁定 获取下锁定的时间
if (ComparatorUtils.equals(result, LOGIN_LOCK)) {
result.setValue(e.getMessage().replaceAll("\\D+", StringUtils.EMPTY));
}
return result;
}
}
return AUTH_FAILED;
}
} }

15
designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java

@ -19,7 +19,12 @@ import com.fr.design.designer.creator.cardlayout.XWCardTitleLayout;
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; import com.fr.design.designer.creator.cardlayout.XWTabFitLayout;
import com.fr.design.designer.properties.FRFitLayoutConstraints; import com.fr.design.designer.properties.FRFitLayoutConstraints;
import com.fr.design.designer.properties.FRFitLayoutPropertiesGroupModel; import com.fr.design.designer.properties.FRFitLayoutPropertiesGroupModel;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.fun.FormWidgetOptionProvider; import com.fr.design.fun.FormWidgetOptionProvider;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.JForm;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.ComponentUtils;
import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.LayoutBorderStyle;
import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WAbsoluteLayout;
@ -342,7 +347,15 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
//拖拽组件原大小、位置 //拖拽组件原大小、位置
Rectangle backupBound = creator.getBackupBound(); Rectangle backupBound = creator.getBackupBound();
backupBound.x -= container.getX(); backupBound.x -= container.getX();
backupBound.y -= container.getY(); // REPORT-34739 对绝对画布块的backupBound.y的调整还需要考虑一下参数面板块的高度造成的偏移
int paraHeight = 0;
if (creator.acceptType(XWAbsoluteLayout.class)) {
JTemplate<?, ?> jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if (jTemplate instanceof JForm) {
paraHeight = ((JForm) jTemplate).getFormDesign().getParaHeight();
}
}
backupBound.y -= (container.getY() - paraHeight);
//当前拖拽组件的位置 //当前拖拽组件的位置
int x = creator.getX(); int x = creator.getX();
int y = creator.getY(); int y = creator.getY();

97
designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java

@ -4,11 +4,9 @@ import com.fr.design.constants.UIConstants;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XCreatorUtils; import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWAbsoluteBodyLayout;
import com.fr.design.designer.creator.XWFitLayout;
import com.fr.design.designer.creator.cardlayout.XCardSwitchButton;
import com.fr.design.designer.treeview.ComponentTreeCellRenderer; import com.fr.design.designer.treeview.ComponentTreeCellRenderer;
import com.fr.design.designer.treeview.ComponentTreeModel; import com.fr.design.designer.treeview.ComponentTreeModel;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.gui.itree.UITreeUI; import com.fr.design.gui.itree.UITreeUI;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
@ -19,9 +17,7 @@ import javax.swing.JPanel;
import javax.swing.JPopupMenu; import javax.swing.JPopupMenu;
import javax.swing.JTree; import javax.swing.JTree;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel; import javax.swing.tree.TreeSelectionModel;
import java.awt.BorderLayout; import java.awt.BorderLayout;
@ -37,8 +33,9 @@ import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Vector; import java.util.Map;
public class ComponentTree extends JTree { public class ComponentTree extends JTree {
@ -46,6 +43,8 @@ public class ComponentTree extends JTree {
private ComponentTreeModel model; private ComponentTreeModel model;
private UITreeUI uiTreeUI = new UITreeUI(); private UITreeUI uiTreeUI = new UITreeUI();
private PopupPreviewPane previewPane; private PopupPreviewPane previewPane;
private static final Map<String, List<TreePath>> treePathCache = new HashMap<>();
private static final int PADDING_LEFT = 5; private static final int PADDING_LEFT = 5;
private static final int PADDING_TOP = 5; private static final int PADDING_TOP = 5;
@ -85,6 +84,7 @@ public class ComponentTree extends JTree {
public ComponentTree(FormDesigner designer, ComponentTreeModel model) { public ComponentTree(FormDesigner designer, ComponentTreeModel model) {
this(designer); this(designer);
this.setModel(model); this.setModel(model);
expandTree();
} }
public void setSelectionPath(TreePath path) { public void setSelectionPath(TreePath path) {
@ -138,7 +138,6 @@ public class ComponentTree extends JTree {
setSelectionPaths(treepath); setSelectionPaths(treepath);
if (treepath.length > 0) { if (treepath.length > 0) {
scrollPathToVisible(treepath[0]); scrollPathToVisible(treepath[0]);
//expandPath(treepath[0]);
} }
} }
@ -193,6 +192,20 @@ public class ComponentTree extends JTree {
return paths; return paths;
} }
@Override
protected void setExpandedState(TreePath path, boolean state) {
super.setExpandedState(path, state);
saveTreePath();
}
/**
* 删除key对应的缓存展开路径
*/
public void removeTreePath(String key) {
if (StringUtils.isNotEmpty(key)) {
treePathCache.remove(key);
}
}
private void setSelectionPath() { private void setSelectionPath() {
@ -232,6 +245,7 @@ public class ComponentTree extends JTree {
public void refreshTreeRoot() { public void refreshTreeRoot() {
model = new ComponentTreeModel(designer, designer.getTopContainer()); model = new ComponentTreeModel(designer, designer.getTopContainer());
setModel(model); setModel(model);
expandTree();
setDragEnabled(false); setDragEnabled(false);
setDropMode(DropMode.ON_OR_INSERT); setDropMode(DropMode.ON_OR_INSERT);
setTransferHandler(new TreeTransferHandler()); setTransferHandler(new TreeTransferHandler());
@ -239,49 +253,56 @@ public class ComponentTree extends JTree {
} }
/** /**
* 获得树的展开路径 * 从缓存中获取展开路径并进行展开
* */ */
public void getExpandNodes(List<TreePath> searchList) { public void expandTree() {
getExpandNodes((XLayoutContainer)designer.getTopContainer(),searchList); expandTree(loadTreePath());
} }
public void getExpandNodes(XLayoutContainer container, List<TreePath> searchList) { /**
TreePath treePath = buildTreePath(container); * 按照传入参数展开组件树
if (isExpanded(treePath)) { */
searchList.add(treePath); private void expandTree(List<TreePath> list) {
for (int i = 0, size = container.getXCreatorCount(); i < size; i++) { if (list == null) {
XCreator creator = container.getXCreator(i); return;
if (creator.acceptType(XLayoutContainer.class) || creator.acceptType(XCardSwitchButton.class)) {
getExpandNodes((XLayoutContainer) creator.getXCreator(), searchList);
}
} }
for (TreePath treePath : list) {
expandPath(treePath);
} }
//对绝对布局做特殊处理
if (container.acceptType(XWFitLayout.class)) {
XWFitLayout bodyFitLayout = (XWFitLayout) container;
for (int j = 0; j < bodyFitLayout.getXCreatorCount(); j++) {
//类型是绝对布局并且还是body
if (bodyFitLayout.getXCreator(j).acceptType(XWAbsoluteBodyLayout.class)) {
container = (XLayoutContainer) bodyFitLayout.getXCreator(j);
getExpandNodes(container, searchList);
} }
/**
* 获得树的展开路径
*/
private List<TreePath> getExpandTreePaths() {
List<TreePath> result = new ArrayList<>();
TreePath rootTreePath = buildTreePath(designer.getTopContainer());
Enumeration<TreePath> enumeration = getExpandedDescendants(rootTreePath);
if (enumeration != null) {
while (enumeration.hasMoreElements()) {
result.add(enumeration.nextElement());
} }
} }
return result;
} }
/** private void saveTreePath() {
* 将树按照展开路径进行展开 String templateID = designer.getTarget().getTemplateID();
* */ JTemplate<?, ?> jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
public void expandNodes(List<TreePath> list){ if (templateID != null && jt != null && StringUtils.equals(templateID, jt.getTarget().getTemplateID())) {
for(TreePath treePath:list) { String key = jt.getEditingFILE().getPath() + templateID;
if (treePath.getLastPathComponent() instanceof XLayoutContainer) { treePathCache.put(key, getExpandTreePaths());
XLayoutContainer creator= (XLayoutContainer) treePath.getLastPathComponent();
if (XCreatorUtils.getParentXLayoutContainer(creator) == null) {
continue;
} }
expandPath(treePath);
} }
private List<TreePath> loadTreePath() {
JTemplate<?, ?> jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if (jt == null) {
return null;
} }
String key = jt.getEditingFILE().getPath() + designer.getTarget().getTemplateID();
return treePathCache.get(key);
} }
private TreePath buildTreePath(Component comp) { private TreePath buildTreePath(Component comp) {

80
designer-form/src/main/java/com/fr/design/mainframe/FormHierarchyTreePane.java

@ -4,7 +4,6 @@ import com.fr.base.BaseUtils;
import com.fr.design.actions.UndoableAction; import com.fr.design.actions.UndoableAction;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.design.designer.beans.events.DesignerEditListener; import com.fr.design.designer.beans.events.DesignerEditListener;
import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XWAbsoluteBodyLayout; import com.fr.design.designer.creator.XWAbsoluteBodyLayout;
import com.fr.design.designer.creator.XWParameterLayout; import com.fr.design.designer.creator.XWParameterLayout;
@ -24,14 +23,12 @@ import javax.swing.Icon;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.tree.TreePath;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
/** /**
@ -48,6 +45,10 @@ public class FormHierarchyTreePane extends FormDockView implements HierarchyTree
private ShortCut4JControlPane[] shorts; private ShortCut4JControlPane[] shorts;
private ComponentTree componentTree; private ComponentTree componentTree;
private final DesignerEditListener designerEditListener = evt -> {
refreshComponentTree();
};
public static FormHierarchyTreePane getInstance() { public static FormHierarchyTreePane getInstance() {
return HOLDER.singleton; return HOLDER.singleton;
} }
@ -94,10 +95,8 @@ public class FormHierarchyTreePane extends FormDockView implements HierarchyTree
//TODO 太乱了,需要重写,监听器里加了监听器是什么意思,每次调用该方法都会添加一个新的监听器 //TODO 太乱了,需要重写,监听器里加了监听器是什么意思,每次调用该方法都会添加一个新的监听器
public void refreshDockingView() { public void refreshDockingView() {
FormDesigner formDesigner = this.getEditingFormDesigner(); FormDesigner formDesigner = this.getEditingFormDesigner();
List<TreePath> list = new ArrayList<>();
removeAll(); removeAll();
if (this.componentTree != null) { if (this.componentTree != null) {
componentTree.getExpandNodes(list);
this.componentTree.removeAll(); this.componentTree.removeAll();
} }
if (formDesigner == null) { if (formDesigner == null) {
@ -106,13 +105,7 @@ public class FormHierarchyTreePane extends FormDockView implements HierarchyTree
} }
componentTree = new ComponentTree(formDesigner); componentTree = new ComponentTree(formDesigner);
//保证删除组件后组件树不收起 //保证删除组件后组件树不收起
componentTree.expandNodes(list); formDesigner.addDesignerEditListener(designerEditListener);
formDesigner.addDesignerEditListener(new DesignerEditListener() {
@Override
public void fireCreatorModified(DesignerEvent evt) {
refreshComponentTree();
}
});
ComponentTreeModel treeModel = (ComponentTreeModel) componentTree.getModel(); ComponentTreeModel treeModel = (ComponentTreeModel) componentTree.getModel();
XCreator root = (XCreator) treeModel.getRoot(); XCreator root = (XCreator) treeModel.getRoot();
@ -128,6 +121,38 @@ public class FormHierarchyTreePane extends FormDockView implements HierarchyTree
refreshComponentTree(); refreshComponentTree();
} }
public void removeTreePath(String key) {
componentTree.removeTreePath(key);
}
/**
* 刷新树
*/
public void refreshRoot() {
componentTree.refreshTreeRoot();
}
@Override
/**
* 位置
*
* @return 位置
*/
public Location preferredLocation() {
return Location.WEST_BELOW;
}
protected ShortCut4JControlPane[] createShortcuts() {
ArrayList<ShortCut4JControlPane> shortCutList = new ArrayList<>();
FormDesigner designer = getEditingFormDesigner();
for (Action action : designer.getActions()) {
shortCutList.add(new WidgetEnableShortCut((UndoableAction) action));
}
return shortCutList.toArray(new ShortCut4JControlPane[shortCutList.size()]);
}
private void refreshComponentTree() { private void refreshComponentTree() {
componentTree.setAndScrollSelectionPath(componentTree.getSelectedTreePath()); componentTree.setAndScrollSelectionPath(componentTree.getSelectedTreePath());
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@ -178,17 +203,6 @@ public class FormHierarchyTreePane extends FormDockView implements HierarchyTree
return toolBarPaneWrapper; return toolBarPaneWrapper;
} }
protected ShortCut4JControlPane[] createShortcuts() {
ArrayList<ShortCut4JControlPane> shortCutList = new ArrayList<>();
FormDesigner designer = getEditingFormDesigner();
for (Action action : designer.getActions()) {
shortCutList.add(new WidgetEnableShortCut((UndoableAction) action));
}
return shortCutList.toArray(new ShortCut4JControlPane[shortCutList.size()]);
}
/** /**
* 调整结构树para和body的位置 * 调整结构树para和body的位置
* *
@ -212,26 +226,6 @@ public class FormHierarchyTreePane extends FormDockView implements HierarchyTree
componentTree = new ComponentTree(formDesigner, treeModel); componentTree = new ComponentTree(formDesigner, treeModel);
} }
/**
* 刷新树
*/
public void refreshRoot() {
if (componentTree == null) {
return;
}
componentTree.refreshTreeRoot();
}
@Override
/**
* 位置
*
* @return 位置
*/
public Location preferredLocation() {
return Location.WEST_BELOW;
}
private class WidgetEnableShortCut extends ShortCut4JControlPane { private class WidgetEnableShortCut extends ShortCut4JControlPane {
public WidgetEnableShortCut(ShortCut shortCut) { public WidgetEnableShortCut(ShortCut shortCut) {
this.shortCut = shortCut; this.shortCut = shortCut;

12
designer-form/src/main/java/com/fr/design/mainframe/JForm.java

@ -307,6 +307,16 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm<F
} }
} }
}); });
addJTemplateActionListener(new JTemplateActionListenerAdapter() {
@Override
public void templateClosed(JTemplate<?, ?> jt) {
if (jt == null) {
return;
}
String key = jt.getEditingFILE().getPath() + jt.getTarget().getTemplateID();
FormHierarchyTreePane.getInstance().removeTreePath(key);
}
});
return tabCenterPane; return tabCenterPane;
} }
@ -998,7 +1008,7 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm<F
return ViewRequestConstants.FORM_VIEW_PATH; return ViewRequestConstants.FORM_VIEW_PATH;
} }
protected void addChooseFILEFilter(FILEChooserPane fileChooser){ protected void addChooseFILEFilter(FILEChooserPane fileChooser) {
String appName = ProductConstants.APP_NAME; String appName = ProductConstants.APP_NAME;
// richer:form文件 daniel 改成三个字 // richer:form文件 daniel 改成三个字
fileChooser.addChooseFILEFilter(new ChooseFileFilter(FileExtension.FRM, appName + Toolkit.i18nText("Fine-Design_Report_Template_File"))); fileChooser.addChooseFILEFilter(new ChooseFileFilter(FileExtension.FRM, appName + Toolkit.i18nText("Fine-Design_Report_Template_File")));

Loading…
Cancel
Save