You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
5.3 KiB
162 lines
5.3 KiB
package com.fr.design.fit.common; |
|
|
|
|
|
import com.fr.design.file.HistoryTemplateListCache; |
|
import com.fr.design.file.MutilTempalteTabPane; |
|
import com.fr.design.fit.DesignerUIModeConfig; |
|
import com.fr.design.fit.JFormType; |
|
import com.fr.design.fit.NewJForm; |
|
import com.fr.design.mainframe.DesignerContext; |
|
import com.fr.design.mainframe.JForm; |
|
import com.fr.design.mainframe.JTemplate; |
|
import com.fr.event.Event; |
|
import com.fr.event.Listener; |
|
import com.fr.file.MemFILE; |
|
import com.fr.file.StashedFILE; |
|
import com.fr.form.fit.common.LightTool; |
|
import com.fr.general.ComparatorUtils; |
|
import java.util.List; |
|
|
|
/** |
|
* @description:模板工具类 |
|
* @author: Henry.Wang |
|
* @create: 2020/09/03 14:19 |
|
*/ |
|
public class TemplateTool { |
|
//和转换有关的所有代码都在这个监听器中 |
|
//在判断新老模式时,统一使用FormUIModeConfig.getInstance().newUIMode()进行判断 |
|
private static Listener<JTemplate> switchListener = new Listener<JTemplate>() { |
|
@Override |
|
public void on(Event event, JTemplate jTemplate) { |
|
if (!(jTemplate instanceof JForm)) { |
|
JFormType.OLD_TYPE.switchUIMode(); |
|
return; |
|
} |
|
JFormType currentType = JFormType.OLD_TYPE; |
|
if (AdaptiveSwitchUtil.isSwitchJFromIng()) { |
|
currentType = DesignerUIModeConfig.getInstance().newUIMode() ? JFormType.NEW_TYPE : JFormType.OLD_TYPE; |
|
} else if (isNewJForm(jTemplate)) { |
|
currentType = JFormType.NEW_TYPE; |
|
} |
|
//UI转换 |
|
currentType.switchUIMode(); |
|
//标志位转换 |
|
currentType.updateJFromTemplateType(jTemplate); |
|
//预览方式转换 |
|
currentType.updatePreviewType(jTemplate); |
|
} |
|
}; |
|
|
|
private static boolean isNewJForm(JTemplate jTemplate) { |
|
if (jTemplate instanceof NewJForm) { |
|
NewJForm newJForm = (NewJForm) jTemplate; |
|
if (LightTool.containNewFormFlag(newJForm.getTarget()) || newJForm.getTarget().getTemplateID() == null) { |
|
return true; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public static Listener<JTemplate> getSwitchListener() { |
|
return switchListener; |
|
} |
|
|
|
/** |
|
* @param |
|
* @Description: 获取当前模板 |
|
* @return: |
|
* @Author: Henry.Wang |
|
* @date: 2020/9/6 14:17 |
|
*/ |
|
public static JTemplate getCurrentEditingTemplate() { |
|
JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
return jTemplate; |
|
} |
|
|
|
/** |
|
* @param |
|
* @Description: 获取当前NewJForm类型的模板 |
|
* @return: |
|
* @Author: Henry.Wang |
|
* @date: 2020/9/6 14:17 |
|
*/ |
|
public static NewJForm getCurrentEditingNewJForm() { |
|
JTemplate jTemplate = getCurrentEditingTemplate(); |
|
if (jTemplate instanceof NewJForm) |
|
return (NewJForm) jTemplate; |
|
return null; |
|
} |
|
|
|
/** |
|
* @param newJTemplate |
|
* @Description: 每次切换设计模式,都会生成新的JForm对象。但是TabPane关联的还是老的JForm对象,所以要重置关联的对象 |
|
* @return: |
|
* @Author: Henry.Wang |
|
* @date: 2020/9/6 14:15 |
|
*/ |
|
public static void resetTabPaneEditingTemplate(JTemplate newJTemplate) { |
|
if (newJTemplate == null) |
|
return; |
|
List<JTemplate<?, ?>> jTemplateList = HistoryTemplateListCache.getInstance().getHistoryList(); |
|
for (int i = 0; i < jTemplateList.size(); i++) { |
|
JTemplate oldJTemplate = jTemplateList.get(i); |
|
if (oldJTemplate != null && ComparatorUtils.equals(oldJTemplate.getEditingFILE(), newJTemplate.getEditingFILE())) { |
|
jTemplateList.set(i, newJTemplate); |
|
MutilTempalteTabPane.getInstance().refreshOpenedTemplate(jTemplateList); |
|
return; |
|
} |
|
} |
|
} |
|
|
|
|
|
/** |
|
* @param jTemplate |
|
* @Description: 是否是新建的且没有操作的模板 |
|
* @return: |
|
* @Author: Henry.Wang |
|
* @date: 2020/9/14 20:41 |
|
*/ |
|
public static boolean isNewTemplateWithoutModify(JTemplate jTemplate) { |
|
return ((jTemplate.getEditingFILE() instanceof MemFILE) && jTemplate.isSaved()) ? true : false; |
|
} |
|
|
|
/** |
|
* @param template |
|
* @Description: 激活模板 |
|
* @return: |
|
* @Author: Henry.Wang |
|
* @date: 2020/9/6 14:16 |
|
*/ |
|
public static void activeAndResizeTemplate(JTemplate template) { |
|
DesignerContext.getDesignerFrame().addAndActivateJTemplate(template); |
|
DesignerContext.getDesignerFrame().setVisible(true); |
|
DesignerContext.getDesignerFrame().resizeFrame(); |
|
} |
|
|
|
/** |
|
* @param jTemplate |
|
* @Description:保存模板 |
|
* @return: |
|
* @Author: Henry.Wang |
|
* @date: 2020/9/6 14:32 |
|
*/ |
|
public static void saveForm(JTemplate<?, ?> jTemplate) { |
|
//为空不保存 |
|
if (jTemplate == null) |
|
return; |
|
//不是NewJForm的模板不保存 |
|
if (!(jTemplate instanceof NewJForm)) |
|
return; |
|
//切换环境时产生的模板不保存 |
|
if (jTemplate.getEditingFILE() instanceof StashedFILE) |
|
return; |
|
//新建的且没有操作的模板不保存 |
|
if (TemplateTool.isNewTemplateWithoutModify(jTemplate)) |
|
return; |
|
jTemplate.stopEditing(); |
|
jTemplate.saveTemplate(); |
|
jTemplate.requestFocus(); |
|
} |
|
|
|
|
|
}
|
|
|