Browse Source

Merge remote-tracking branch 'origin/feature/x' into feature/x

feature/x
parent
commit
7ddb20bae1
  1. 2
      designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java
  2. 50
      designer-base/src/main/java/com/fr/design/gui/controlpane/JListControlPane.java
  3. 11
      designer-base/src/main/java/com/fr/design/gui/ilist/JNameEdList.java
  4. 104
      designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java
  5. 8
      designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java

2
designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java

@ -32,6 +32,7 @@ import com.fr.file.TableDataConfig;
import com.fr.general.ComparatorUtils;
import com.fr.general.data.DataModel;
import com.fr.general.data.TableDataException;
import com.fr.general.sql.sqlnote.SqlNoteConstants;
import com.fr.log.FineLoggerFactory;
import com.fr.module.ModuleContext;
import com.fr.script.Calculator;
@ -571,6 +572,7 @@ public abstract class DesignTableDataManager {
parameter.setValue(parameterMap.get(parameter.getName()));
}
}
parameterMap.put(SqlNoteConstants.SQL_NOTE_TEMPLATE, HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getEditingFILE().getPath());
return DataOperator.getInstance().previewTableData(TableDataSourceTailor.extractTableData(tableDataSource), tabledata, parameterMap, rowCount);
} catch (Exception e) {
throw new TableDataException(e.getMessage(), e);

50
designer-base/src/main/java/com/fr/design/gui/controlpane/JListControlPane.java

@ -17,16 +17,19 @@ import com.fr.stable.Nameable;
import com.fr.stable.StringUtils;
import com.fr.stable.core.PropertyChangeAdapter;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.ListCellRenderer;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@ -343,21 +346,46 @@ public abstract class JListControlPane extends JControlPane implements ListContr
}
protected class NameableListCellRenderer extends
DefaultListCellRenderer {
JPanel implements ListCellRenderer<Object> {
private final JLabel textLabel;
private final JLabel iconLabel;
/**
* JList默认单元格渲染器的选中背景色
*/
private final Color selectedBgColor = new Color(65, 155, 249);
protected NameableListCellRenderer() {
setLayout(new BorderLayout());
this.textLabel = new JLabel();
this.iconLabel = new JLabel();
add(this.textLabel, BorderLayout.CENTER);
add(this.iconLabel, BorderLayout.WEST);
this.iconLabel.setBackground(Color.WHITE);
//iconLabel和textLabel的背景颜色不会被JList背景颜色覆盖,开发者自定义
this.textLabel.setOpaque(true);
this.iconLabel.setOpaque(true);
}
@Override
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected,
cellHasFocus);
if (value instanceof ListModelElement) {
ListModelElement element = ((ListModelElement) value);
Nameable nameable = element.wrapper;
this.setText(nameable.getName());
this.textLabel.setText(nameable.getName());
boolean iconSet = false;
for (NameableCreator creator : JListControlPane.this.creators()) {
if (creator.menuIcon() != null && creator.acceptObject2Populate(nameable) != null) {
this.setIcon(creator.menuIcon());
this.iconLabel.setIcon(creator.menuIcon());
if(isSelected) {
this.textLabel.setBackground(selectedBgColor);
this.textLabel.setForeground(Color.WHITE);
} else {
this.textLabel.setBackground(Color.WHITE);
this.textLabel.setForeground(Color.BLACK);
}
this.setToolTipText(creator.createTooltip());
iconSet = true;
break;
@ -369,8 +397,16 @@ public abstract class JListControlPane extends JControlPane implements ListContr
}
return this;
}
}
/**
* 改造后兼容子类NoIconNameableListCellRenderer使用,添加此setIcon函数
*
* @param icon 图标,可为null
*/
public void setIcon(Icon icon) {
this.iconLabel.setIcon(icon);
}
}
@Override
public BasicBeanPane createPaneByCreators(NameableCreator creator) {
return Reflect.on(creator.getUpdatePane()).create().get();

11
designer-base/src/main/java/com/fr/design/gui/ilist/JNameEdList.java

@ -11,15 +11,20 @@ import com.fr.stable.core.PropertyChangeAdapter;
import javax.swing.ListModel;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import java.util.ArrayList;
import java.util.Vector;
import java.awt.Component;
import java.awt.Rectangle;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.util.ArrayList;
import java.util.Vector;
public class JNameEdList extends UIList implements CellEditorListener {
private static final int ICON_WIDTH = 20;
/**
* 原值为20,设计器图标由png替换为svg之后JNameEdList的icon大小为16x16
* 重命名是会出现左侧一部分带有背景色的渲染
*/
private static final int ICON_WIDTH = 16;
private boolean editable = true;
// kunsnat: 是否强制ListName是数字 (int型)

104
designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java

@ -24,6 +24,8 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.SwingWorker;
import java.io.OutputStream;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@ -44,7 +46,7 @@ public class TemplateUtils {
* @param openNewTemplate 是否需要在创建后打开模板
*/
public static void createAndOpenTemplate(String prefix, FILE file, boolean createByEditingTemplate, boolean openNewTemplate) {
createAndOpenTemplate(prefix, file, createByEditingTemplate, openNewTemplate, () -> {});
createAndOpenTemplate(prefix, file, createByEditingTemplate, openNewTemplate, null);
}
/**
@ -66,15 +68,33 @@ public class TemplateUtils {
Runnable doAfterCreateTemplate;
//判断一下要保存的文件是否已打开
int index = HistoryTemplateListCache.getInstance().contains(file);
if (index == -1) {
doAfterCreateTemplate = () -> {};
} else {
JTemplate template = HistoryTemplateListCache.getInstance().getHistoryList().get(index);
doAfterCreateTemplate = () -> HistoryTemplateListCache.getInstance().closeSelectedReport(template);
JTemplate template = null;
if (index != -1) {
template = HistoryTemplateListCache.getInstance().getHistoryList().get(index);
}
createAndOpenTemplate0(file, oldPath, createByEditingTemplate, openNewTemplate, doAfterCreateTemplate);
createAndOpenTemplate0(file, oldPath, createByEditingTemplate, openNewTemplate, template);
}
/**
* 创建新的模板文件并打开模板并在创建备份模板成功后执行doAfterCreate
*
* @param prefix 模板文件名称前缀
* @param file 模板文件
* @param createByEditingTemplate 是否根据 当前编辑模板 来创建新模板
* 为true时以CurrentEditingTemplate为准创建新模板
* 为false时以传入的File文件为准创建新模板此文件可以不是编辑状态
* @param openNewTemplate 是否需要在创建后打开模板
* @param template 备份成功后需要关闭的模板
*/
public static void createAndOpenTemplate(String prefix, FILE file, boolean createByEditingTemplate, boolean openNewTemplate, @Nullable JTemplate<?, ?> template) {
String oldPath = file.getPath();
file = getSavedFile(prefix, file);
if (file == null) {
return;
}
createAndOpenTemplate0(file, oldPath, createByEditingTemplate, openNewTemplate, template);
}
/**
* 返回值可以为null, 为null表示没有点击保存按钮或者传递进来的文件file本身不满足格式要求
@ -111,31 +131,17 @@ public class TemplateUtils {
}
/**
* 创建新的模板文件并打开模板并在创建备份模板成功后执行doAfterCreate
* 生成备份模板
*
* @param prefix 模板文件名称前缀
* @param file 模板文件
* @param file saveAs的模板文件
* @param createByEditingTemplate 是否根据 当前编辑模板 来创建新模板
* 为true时以CurrentEditingTemplate为准创建新模板
* 为false时以传入的File文件为准创建新模板此文件可以不是编辑状态
* @param openNewTemplate 是否需要在创建后打开模板
* @param doAfterCreateTemplate 创建备份模板成功后调用
* @param oldPath 被saveAs的文件路径
*/
public static void createAndOpenTemplate(String prefix, FILE file, boolean createByEditingTemplate, boolean openNewTemplate, Runnable doAfterCreateTemplate) {
String oldPath = file.getPath();
file = getSavedFile(prefix, file);
if (file == null) {
return;
}
createAndOpenTemplate0(file, oldPath, createByEditingTemplate, openNewTemplate, doAfterCreateTemplate);
}
private static void createAndOpenTemplate0(FILE file, String oldPath, boolean createByEditingTemplate, boolean openNewTemplate, Runnable doAfterCreateTemplate) {
new SwingWorker<Boolean, Void>() {
@Override
protected Boolean doInBackground() throws Exception {
private static CompletableFuture<Boolean> createTemplate(FILE file, String oldPath, boolean createByEditingTemplate) {
return CompletableFuture.supplyAsync(() -> {
try {
// 读取模板数据
byte[] content = getTemplateData(createByEditingTemplate, oldPath);
OutputStream out = null;
@ -144,7 +150,7 @@ public class TemplateUtils {
boolean saveAsLock = WorkContext.getCurrent().get(TplOperator.class).saveAs(file.getPath());
if (!saveAsLock) {
// 加锁失败时,直接返回
return false;
throw new RuntimeException("[RemoteDesign] back up template file failed");
}
out = file.asOutputStream();
out.write(content);
@ -159,20 +165,43 @@ public class TemplateUtils {
}
}
return true;
} catch (Exception e) {
SaveFailureHandler.getInstance().process(e);
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return false;
}
});
}
/**
* 打开saveAs的新模板并关闭指定的旧模板
*
* @param file 模板文件
* @param openNewTemplate 是否需要打开新模板
* @param template 需要关闭的模板
*/
private static void openNewTemplateAndCloseOldTemplate(FILE file, boolean openNewTemplate, @Nullable JTemplate<?, ?> template) {
new SwingWorker<Boolean, Void>() {
@Override
protected Boolean doInBackground() throws Exception {
if (JTemplate.isValid(template)) {
//给要关闭的模板解锁
WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(template.getPath());
return true;
}
return false;
}
@Override
protected void done() {
try {
if (!get()) {
throw new Exception("[RemoteDesign] back up template file failed");
if (get()) {
//模板释放锁成功后关闭该模板
HistoryTemplateListCache.getInstance().closeSelectedReport(template);
}
// 创建备份成功后,关闭原模板
doAfterCreateTemplate.run();
if (openNewTemplate) {
DesignerContext.getDesignerFrame().openTemplate(file);
}
// 备份成功刷新下目录树 展示出来备份的模板
// 刷新下目录树
TemplateTreePane.getInstance().refresh();
} catch (Exception e) {
SaveFailureHandler.getInstance().process(e);
@ -182,6 +211,15 @@ public class TemplateUtils {
}.execute();
}
private static void createAndOpenTemplate0(FILE file, String oldPath, boolean createByEditingTemplate, boolean openNewTemplate, @Nullable JTemplate<?, ?> template) {
createTemplate(file, oldPath, createByEditingTemplate).thenApply((Function<Boolean, Void>) aBoolean -> {
if (aBoolean) {
openNewTemplateAndCloseOldTemplate(file, openNewTemplate, template);
}
return null;
});
}
/**
* 读取模板文件数据
*

8
designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java

@ -119,8 +119,8 @@ public class SaveFailureHandler implements ThrowableHandler {
new FileNodeFILE(new FileNode(template.getPath(), false)),
true,
true,
// 创建并打开备份模板后,关闭原模板,无需释放原模板锁(因为已经被超管手动清除了)
() -> HistoryTemplateListCache.getInstance().closeSelectedReport(template));
//另存之后需要关闭的模板
template);
}
}
}
@ -141,8 +141,8 @@ public class SaveFailureHandler implements ThrowableHandler {
new FileNodeFILE(new FileNode(template.getPath(), false)),
true,
true,
// 创建并打开备份模板后,关闭原模板,无需释放原模板锁(锁定信息不一致 = 此用户模板锁信息已被清除)
() -> HistoryTemplateListCache.getInstance().closeSelectedReport(template));
//另存之后需要关闭的模板
template);
}
}
}

Loading…
Cancel
Save