Browse Source

Merge remote-tracking branch 'origin/release/10.0' into release/10.0

feature/big-screen
alex.sung 6 years ago
parent
commit
1b87859eba
  1. 25
      designer-base/src/main/java/com/fr/design/gui/itree/filetree/JFileTree.java
  2. 17
      designer-base/src/main/java/com/fr/env/LocalEnvPane.java
  3. 29
      designer-realize/src/main/java/com/fr/design/widget/WidgetDefinePaneFactory.java
  4. 66
      designer-realize/src/test/java/com/fr/design/widget/WidgetDefinePaneFactoryTest.java

25
designer-base/src/main/java/com/fr/design/gui/itree/filetree/JFileTree.java

@ -1,10 +1,11 @@
package com.fr.design.gui.itree.filetree; package com.fr.design.gui.itree.filetree;
import com.fr.base.BaseUtils;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
import org.jetbrains.annotations.Nullable;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JTree; import javax.swing.JTree;
@ -29,7 +30,8 @@ import java.util.Stack;
* File Tree. * File Tree.
*/ */
public class JFileTree extends AbstractFileTree { public class JFileTree extends AbstractFileTree {
protected FileFilter fileFilter;
private FileFilter fileFilter;
public JFileTree() { public JFileTree() {
this(null); this(null);
@ -68,11 +70,11 @@ public class JFileTree extends AbstractFileTree {
DefaultMutableTreeNode rootTreeNode = (DefaultMutableTreeNode) defaultTreeModel.getRoot(); DefaultMutableTreeNode rootTreeNode = (DefaultMutableTreeNode) defaultTreeModel.getRoot();
rootTreeNode.removeAllChildren(); rootTreeNode.removeAllChildren();
for (int k = 0; k < rootFiles.length; k++) { for (File rootFile : rootFiles) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode(new RootFile(rootFiles[k])); DefaultMutableTreeNode node = new DefaultMutableTreeNode(new RootFile(rootFile));
rootTreeNode.add(node); rootTreeNode.add(node);
if (rootFiles[k].isDirectory()) { if (rootFile.isDirectory()) {
node.add(new DefaultMutableTreeNode(Boolean.TRUE)); node.add(new DefaultMutableTreeNode(Boolean.TRUE));
} }
} }
@ -93,6 +95,7 @@ public class JFileTree extends AbstractFileTree {
this.fileFilter = fileFilter; this.fileFilter = fileFilter;
} }
@Nullable
public File getSelectedFile() { public File getSelectedFile() {
TreePath selectedTreePath = this.getSelectionPath(); TreePath selectedTreePath = this.getSelectionPath();
if (selectedTreePath == null) { if (selectedTreePath == null) {
@ -140,7 +143,7 @@ public class JFileTree extends AbstractFileTree {
File rootFile = rootLocalFile.getFile(); File rootFile = rootLocalFile.getFile();
// 是父子关系,开始找孩子. // 是父子关系,开始找孩子.
if (AbstractFileTree.isParentFile(rootFile, currentFile)) { if (AbstractFileTree.isParentFile(rootFile, currentFile)) {
Stack nameStack = new Stack(); // 将所有的名字加入Stack. Stack<String> nameStack = new Stack<>(); // 将所有的名字加入Stack.
while (true) { while (true) {
if (ComparatorUtils.equals(rootFile, currentFile)) { if (ComparatorUtils.equals(rootFile, currentFile)) {
break; break;
@ -153,7 +156,7 @@ public class JFileTree extends AbstractFileTree {
} }
DefaultMutableTreeNode curChildTreeNode = rootChildTreeNode; DefaultMutableTreeNode curChildTreeNode = rootChildTreeNode;
while (!nameStack.isEmpty()) { while (!nameStack.isEmpty()) {
String name = (String) nameStack.pop(); String name = nameStack.pop();
this.expandTreeNode(curChildTreeNode); this.expandTreeNode(curChildTreeNode);
for (int j = 0; j < curChildTreeNode.getChildCount(); j++) { for (int j = 0; j < curChildTreeNode.getChildCount(); j++) {
DefaultMutableTreeNode tmpChildTreeNode = DefaultMutableTreeNode tmpChildTreeNode =
@ -198,9 +201,8 @@ public class JFileTree extends AbstractFileTree {
if (files == null) { if (files == null) {
return new FileDirectoryNode[0]; return new FileDirectoryNode[0];
} }
List fileNodeList = new ArrayList(); List<FileDirectoryNode> fileNodeList = new ArrayList<>();
for (int k = 0; k < files.length; k++) { for (File tmpFile : files) {
File tmpFile = files[k];
// 文件属性为隐藏的话 不放入列表 // 文件属性为隐藏的话 不放入列表
if (tmpFile.isHidden()) { if (tmpFile.isHidden()) {
continue; continue;
@ -256,7 +258,7 @@ public class JFileTree extends AbstractFileTree {
// 得到本地tree图标 // 得到本地tree图标
Icon tmpIcon = view.getSystemIcon(currentFile); Icon tmpIcon = view.getSystemIcon(currentFile);
if (currentFile.isDirectory() && fBuf.length() > 0) { if (currentFile.isDirectory() && fBuf.length() > 0) {
tmpIcon = BaseUtils.readIcon("/com/fr/design/images/gui/folder.png"); tmpIcon = IOUtils.readIcon("/com/fr/design/images/gui/folder.png");
} }
this.setIcon(tmpIcon); this.setIcon(tmpIcon);
this.setName(null); this.setName(null);
@ -299,6 +301,7 @@ public class JFileTree extends AbstractFileTree {
*/ */
@Override @Override
public int compare(FileDirectoryNode v1, FileDirectoryNode v2) { public int compare(FileDirectoryNode v1, FileDirectoryNode v2) {
//noinspection Duplicates
if (v1.isDirectory()) { if (v1.isDirectory()) {
if (v2.isDirectory()) { if (v2.isDirectory()) {
return v1.getName().toLowerCase().compareTo(v2.getName().toLowerCase()); return v1.getName().toLowerCase().compareTo(v2.getName().toLowerCase());

17
designer-base/src/main/java/com/fr/env/LocalEnvPane.java vendored

@ -6,9 +6,9 @@ import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextarea.UITextArea; import com.fr.design.gui.itextarea.UITextArea;
import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.gui.itree.filetree.JFileTree; import com.fr.design.gui.itree.filetree.JFileTree;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.file.filter.OnlyShowDirectoryFileFilter; import com.fr.file.filter.OnlyShowDirectoryFileFilter;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -33,8 +33,9 @@ public class LocalEnvPane extends BasicBeanPane<LocalDesignerWorkspaceInfo> {
JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
this.add(northPane, BorderLayout.NORTH); this.add(northPane, BorderLayout.NORTH);
northPane.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Location") + ":"), BorderLayout.WEST); northPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Location") + ":"), BorderLayout.WEST);
northPane.add(pathTextField = new UITextField(), BorderLayout.CENTER); pathTextField = new UITextField();
northPane.add(pathTextField, BorderLayout.CENTER);
// 删除选择文件按钮 添加JFileTree // 删除选择文件按钮 添加JFileTree
@ -54,19 +55,23 @@ public class LocalEnvPane extends BasicBeanPane<LocalDesignerWorkspaceInfo> {
@Override @Override
public void valueChanged(TreeSelectionEvent e) { public void valueChanged(TreeSelectionEvent e) {
pathTextField.setText(localEnvTree.getSelectedFile().getPath()); File selectFile = localEnvTree.getSelectedFile();
if (selectFile == null) {
return;
}
pathTextField.setText(selectFile.getPath());
} }
}); });
UITextArea description = new UITextArea(); UITextArea description = new UITextArea();
centerPane.add(description, BorderLayout.SOUTH); centerPane.add(description, BorderLayout.SOUTH);
description.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Env_Des1")); description.setText(Toolkit.i18nText("Fine-Design_Basic_Env_Des1"));
description.setEditable(false); description.setEditable(false);
} }
@Override @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Location"); return Toolkit.i18nText("Fine-Design_Basic_Location");
} }
@Override @Override

29
designer-realize/src/main/java/com/fr/design/widget/WidgetDefinePaneFactory.java

@ -48,6 +48,7 @@ import com.fr.report.web.button.write.AppendRowButton;
import com.fr.report.web.button.write.DeleteRowButton; import com.fr.report.web.button.write.DeleteRowButton;
import com.fr.stable.bridge.BridgeMark; import com.fr.stable.bridge.BridgeMark;
import com.fr.stable.bridge.StableFactory; import com.fr.stable.bridge.StableFactory;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -60,7 +61,9 @@ import java.util.Map;
* Time : 上午11:17 * Time : 上午11:17
*/ */
public class WidgetDefinePaneFactory { public class WidgetDefinePaneFactory {
private static Map<Class<? extends Widget>, Appearance> defineMap = new HashMap<Class<? extends Widget>, Appearance>(); private static Map<Class<? extends Widget>, Appearance> defineMap = new HashMap<Class<? extends Widget>, Appearance>();
private static Map<Class<? extends Widget>, Appearance> pluginDefineMap = ExtraDesignClassManager.getInstance().getCellWidgetOptionsMap();
static { static {
defineMap.put(NumberEditor.class, new Appearance(NumberEditorDefinePane.class, WidgetConstants.NUMBER + "")); defineMap.put(NumberEditor.class, new Appearance(NumberEditorDefinePane.class, WidgetConstants.NUMBER + ""));
@ -91,24 +94,32 @@ public class WidgetDefinePaneFactory {
defineMap.put(AppendRowButton.class, new Appearance(ButtonDefinePane.class, WidgetConstants.BUTTON + "")); defineMap.put(AppendRowButton.class, new Appearance(ButtonDefinePane.class, WidgetConstants.BUTTON + ""));
defineMap.put(DeleteRowButton.class, new Appearance(ButtonDefinePane.class, WidgetConstants.BUTTON + "")); defineMap.put(DeleteRowButton.class, new Appearance(ButtonDefinePane.class, WidgetConstants.BUTTON + ""));
defineMap.put(TreeNodeToggleButton.class, new Appearance(ButtonDefinePane.class, WidgetConstants.BUTTON + "")); defineMap.put(TreeNodeToggleButton.class, new Appearance(ButtonDefinePane.class, WidgetConstants.BUTTON + ""));
defineMap.putAll(ExtraDesignClassManager.getInstance().getCellWidgetOptionsMap());
} }
private WidgetDefinePaneFactory() { private WidgetDefinePaneFactory() {
} }
@Nullable
public static RN createWidgetDefinePane(Widget widget, Operator operator) { public static RN createWidgetDefinePane(Widget widget, Operator operator) {
Appearance dn = defineMap.get(widget.getClass()); Appearance dn = defineMap.get(widget.getClass());
DataModify<Widget> definePane = null; // 再走一遍插件。
try { if (dn == null) {
definePane = (DataModify) dn.getDefineClass().newInstance(); dn = pluginDefineMap.get(widget.getClass());
definePane.populateBean(widget);
operator.did(definePane.dataUI(), dn.getDisplayName());
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
return new RN(definePane, dn.getDisplayName()); if (dn != null) {
DataModify<Widget> definePane = null;
try {
definePane = (DataModify) dn.getDefineClass().newInstance();
definePane.populateBean(widget);
operator.did(definePane.dataUI(), dn.getDisplayName());
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return new RN(definePane, dn.getDisplayName());
}
return null;
} }
public static class RN { public static class RN {

66
designer-realize/src/test/java/com/fr/design/widget/WidgetDefinePaneFactoryTest.java

@ -0,0 +1,66 @@
package com.fr.design.widget;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.data.DataCreatorUI;
import com.fr.design.widget.ui.ButtonDefinePane;
import com.fr.form.ui.Button;
import com.fr.form.ui.Widget;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.util.HashMap;
import java.util.Map;
@RunWith(PowerMockRunner.class)
@PowerMockIgnore("javax.swing.*")
public class WidgetDefinePaneFactoryTest {
@Test
@PrepareForTest({ExtraDesignClassManager.class, WidgetDefinePaneFactory.class})
public void testCreateWidgetDefinePane() throws Exception {
Map<Class<? extends Widget>, Appearance> map = new HashMap<>();
ExtraDesignClassManager mockDesignManager = EasyMock.mock(ExtraDesignClassManager.class);
EasyMock.expect(mockDesignManager.getCellWidgetOptionsMap()).andReturn(map).anyTimes();
EasyMock.replay(mockDesignManager);
PowerMock.mockStatic(ExtraDesignClassManager.class);
EasyMock.expect(ExtraDesignClassManager.getInstance()).andReturn(mockDesignManager).anyTimes();
PowerMock.replayAll(ExtraDesignClassManager.class);
Button mockWidget = EasyMock.mock(Button.class);
EasyMock.replay(mockWidget);
ButtonDefinePane mockPane = EasyMock.mock(ButtonDefinePane.class);
mockPane.populateBean(EasyMock.anyObject(Button.class));
EasyMock.expectLastCall();
EasyMock.replay(mockPane);
Operator mockOperator = EasyMock.mock(Operator.class);
mockOperator.did(EasyMock.anyObject(DataCreatorUI.class), EasyMock.anyString());
EasyMock.replay(mockOperator);
WidgetDefinePaneFactory.RN rn1 = WidgetDefinePaneFactory.createWidgetDefinePane(mockWidget, mockOperator);
Assert.assertNull(rn1);
Appearance appearance = new Appearance(ButtonDefinePane.class, "test");
map.put(mockWidget.getClass(), appearance);
WidgetDefinePaneFactory.RN rn2 = WidgetDefinePaneFactory.createWidgetDefinePane(mockWidget, mockOperator);
Assert.assertNotNull(rn2);
map.clear();
WidgetDefinePaneFactory.RN rn3 = WidgetDefinePaneFactory.createWidgetDefinePane(mockWidget, mockOperator);
Assert.assertNull(rn3);
}
}
Loading…
Cancel
Save