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.ComparatorUtils;
import com.fr.general.data.DataModel; import com.fr.general.data.DataModel;
import com.fr.general.data.TableDataException; import com.fr.general.data.TableDataException;
import com.fr.general.sql.sqlnote.SqlNoteConstants;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.module.ModuleContext; import com.fr.module.ModuleContext;
import com.fr.script.Calculator; import com.fr.script.Calculator;
@ -571,6 +572,7 @@ public abstract class DesignTableDataManager {
parameter.setValue(parameterMap.get(parameter.getName())); 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); return DataOperator.getInstance().previewTableData(TableDataSourceTailor.extractTableData(tableDataSource), tabledata, parameterMap, rowCount);
} catch (Exception e) { } catch (Exception e) {
throw new TableDataException(e.getMessage(), 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.StringUtils;
import com.fr.stable.core.PropertyChangeAdapter; import com.fr.stable.core.PropertyChangeAdapter;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel; import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JPopupMenu; import javax.swing.JPopupMenu;
import javax.swing.ListCellRenderer;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
@ -343,21 +346,46 @@ public abstract class JListControlPane extends JControlPane implements ListContr
} }
protected class NameableListCellRenderer extends 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 @Override
public Component getListCellRendererComponent(JList list, Object value, public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) { int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected,
cellHasFocus);
if (value instanceof ListModelElement) { if (value instanceof ListModelElement) {
ListModelElement element = ((ListModelElement) value); ListModelElement element = ((ListModelElement) value);
Nameable nameable = element.wrapper; Nameable nameable = element.wrapper;
this.setText(nameable.getName()); this.textLabel.setText(nameable.getName());
boolean iconSet = false; boolean iconSet = false;
for (NameableCreator creator : JListControlPane.this.creators()) { for (NameableCreator creator : JListControlPane.this.creators()) {
if (creator.menuIcon() != null && creator.acceptObject2Populate(nameable) != null) { 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()); this.setToolTipText(creator.createTooltip());
iconSet = true; iconSet = true;
break; break;
@ -369,8 +397,16 @@ public abstract class JListControlPane extends JControlPane implements ListContr
} }
return this; return this;
} }
}
/**
* 改造后兼容子类NoIconNameableListCellRenderer使用,添加此setIcon函数
*
* @param icon 图标,可为null
*/
public void setIcon(Icon icon) {
this.iconLabel.setIcon(icon);
}
}
@Override @Override
public BasicBeanPane createPaneByCreators(NameableCreator creator) { public BasicBeanPane createPaneByCreators(NameableCreator creator) {
return Reflect.on(creator.getUpdatePane()).create().get(); 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.ListModel;
import javax.swing.event.CellEditorListener; import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import java.util.ArrayList;
import java.util.Vector;
import java.awt.Component; import java.awt.Component;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.awt.event.FocusListener; import java.awt.event.FocusListener;
import java.util.ArrayList;
import java.util.Vector;
public class JNameEdList extends UIList implements CellEditorListener { 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; private boolean editable = true;
// kunsnat: 是否强制ListName是数字 (int型) // 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 javax.swing.SwingWorker;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -44,7 +46,7 @@ public class TemplateUtils {
* @param openNewTemplate 是否需要在创建后打开模板 * @param openNewTemplate 是否需要在创建后打开模板
*/ */
public static void createAndOpenTemplate(String prefix, FILE file, boolean createByEditingTemplate, boolean 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; Runnable doAfterCreateTemplate;
//判断一下要保存的文件是否已打开 //判断一下要保存的文件是否已打开
int index = HistoryTemplateListCache.getInstance().contains(file); int index = HistoryTemplateListCache.getInstance().contains(file);
if (index == -1) { JTemplate template = null;
doAfterCreateTemplate = () -> {}; if (index != -1) {
} else { template = HistoryTemplateListCache.getInstance().getHistoryList().get(index);
JTemplate template = HistoryTemplateListCache.getInstance().getHistoryList().get(index);
doAfterCreateTemplate = () -> HistoryTemplateListCache.getInstance().closeSelectedReport(template);
} }
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本身不满足格式要求 * 返回值可以为null, 为null表示没有点击保存按钮或者传递进来的文件file本身不满足格式要求
@ -111,31 +131,17 @@ public class TemplateUtils {
} }
/** /**
* 创建新的模板文件并打开模板并在创建备份模板成功后执行doAfterCreate * 生成备份模板
* *
* @param prefix 模板文件名称前缀 * @param file saveAs的模板文件
* @param file 模板文件
* @param createByEditingTemplate 是否根据 当前编辑模板 来创建新模板 * @param createByEditingTemplate 是否根据 当前编辑模板 来创建新模板
* 为true时以CurrentEditingTemplate为准创建新模板 * 为true时以CurrentEditingTemplate为准创建新模板
* 为false时以传入的File文件为准创建新模板此文件可以不是编辑状态 * 为false时以传入的File文件为准创建新模板此文件可以不是编辑状态
* @param openNewTemplate 是否需要在创建后打开模板 * @param oldPath 被saveAs的文件路径
* @param doAfterCreateTemplate 创建备份模板成功后调用
*/ */
public static void createAndOpenTemplate(String prefix, FILE file, boolean createByEditingTemplate, boolean openNewTemplate, Runnable doAfterCreateTemplate) { private static CompletableFuture<Boolean> createTemplate(FILE file, String oldPath, boolean createByEditingTemplate) {
String oldPath = file.getPath(); return CompletableFuture.supplyAsync(() -> {
file = getSavedFile(prefix, file); try {
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 {
// 读取模板数据 // 读取模板数据
byte[] content = getTemplateData(createByEditingTemplate, oldPath); byte[] content = getTemplateData(createByEditingTemplate, oldPath);
OutputStream out = null; OutputStream out = null;
@ -144,7 +150,7 @@ public class TemplateUtils {
boolean saveAsLock = WorkContext.getCurrent().get(TplOperator.class).saveAs(file.getPath()); boolean saveAsLock = WorkContext.getCurrent().get(TplOperator.class).saveAs(file.getPath());
if (!saveAsLock) { if (!saveAsLock) {
// 加锁失败时,直接返回 // 加锁失败时,直接返回
return false; throw new RuntimeException("[RemoteDesign] back up template file failed");
} }
out = file.asOutputStream(); out = file.asOutputStream();
out.write(content); out.write(content);
@ -159,20 +165,43 @@ public class TemplateUtils {
} }
} }
return true; 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 @Override
protected void done() { protected void done() {
try { try {
if (!get()) { if (get()) {
throw new Exception("[RemoteDesign] back up template file failed"); //模板释放锁成功后关闭该模板
HistoryTemplateListCache.getInstance().closeSelectedReport(template);
} }
// 创建备份成功后,关闭原模板
doAfterCreateTemplate.run();
if (openNewTemplate) { if (openNewTemplate) {
DesignerContext.getDesignerFrame().openTemplate(file); DesignerContext.getDesignerFrame().openTemplate(file);
} }
// 备份成功刷新下目录树 展示出来备份的模板 // 刷新下目录树
TemplateTreePane.getInstance().refresh(); TemplateTreePane.getInstance().refresh();
} catch (Exception e) { } catch (Exception e) {
SaveFailureHandler.getInstance().process(e); SaveFailureHandler.getInstance().process(e);
@ -182,6 +211,15 @@ public class TemplateUtils {
}.execute(); }.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)), new FileNodeFILE(new FileNode(template.getPath(), false)),
true, true,
true, true,
// 创建并打开备份模板后,关闭原模板,无需释放原模板锁(因为已经被超管手动清除了) //另存之后需要关闭的模板
() -> HistoryTemplateListCache.getInstance().closeSelectedReport(template)); template);
} }
} }
} }
@ -141,8 +141,8 @@ public class SaveFailureHandler implements ThrowableHandler {
new FileNodeFILE(new FileNode(template.getPath(), false)), new FileNodeFILE(new FileNode(template.getPath(), false)),
true, true,
true, true,
// 创建并打开备份模板后,关闭原模板,无需释放原模板锁(锁定信息不一致 = 此用户模板锁信息已被清除) //另存之后需要关闭的模板
() -> HistoryTemplateListCache.getInstance().closeSelectedReport(template)); template);
} }
} }
} }

Loading…
Cancel
Save