|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.fr.design.widget.ui.designer; |
|
|
|
|
|
|
|
|
|
import com.fr.base.iofile.attr.TemplateLayoutIdAttrMark; |
|
|
|
|
import com.fr.design.border.UITitledMatteBorder; |
|
|
|
|
import com.fr.design.designer.beans.PredefinedLayout; |
|
|
|
|
import com.fr.design.designer.beans.models.NewFormModel; |
|
|
|
@ -15,6 +16,11 @@ import com.fr.design.mainframe.DesignerContext;
|
|
|
|
|
import com.fr.design.mainframe.JTemplate; |
|
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
|
import com.fr.form.main.Form; |
|
|
|
|
import com.fr.form.ui.Widget; |
|
|
|
|
import com.fr.form.ui.container.OccupiedLayout; |
|
|
|
|
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; |
|
|
|
|
import com.fr.form.ui.container.WBorderLayout; |
|
|
|
|
import com.fr.form.ui.container.WFitLayout; |
|
|
|
|
import com.fr.general.ComparatorUtils; |
|
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
@ -43,6 +49,8 @@ import java.util.List;
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
public class NewFormPane extends BasicPane { |
|
|
|
|
private static final String EMPTY_FORM_LAYOUTID = "9ebf6aff-ad53-45a9-a175-9633f4162a3a"; |
|
|
|
|
|
|
|
|
|
private NewFormModel newFormModel; |
|
|
|
|
private UIDialog dialog; |
|
|
|
|
private PredefinedLayoutPane selectedLayoutPane = null; |
|
|
|
@ -276,19 +284,66 @@ public class NewFormPane extends BasicPane {
|
|
|
|
|
private void newForm(String path) { |
|
|
|
|
BaseJForm jForm; |
|
|
|
|
try { |
|
|
|
|
if (StringUtils.isNotEmpty(path)) { |
|
|
|
|
Form form = new Form(); |
|
|
|
|
form.readStream(NewFormPane.class.getResourceAsStream(path)); |
|
|
|
|
jForm = StableFactory.getMarkedInstanceObjectFromClass(BaseJForm.XML_TAG, new Object[]{form}, BaseJForm.class); |
|
|
|
|
} else { |
|
|
|
|
jForm = StableFactory.getMarkedInstanceObjectFromClass(BaseJForm.XML_TAG, BaseJForm.class); |
|
|
|
|
} |
|
|
|
|
Form form = initEmptyBodyForm(); |
|
|
|
|
initLayoutInfo(form, path); |
|
|
|
|
jForm = StableFactory.getMarkedInstanceObjectFromClass(BaseJForm.XML_TAG, new Object[]{form}, BaseJForm.class); |
|
|
|
|
DesignerContext.getDesignerFrame().addAndActivateJTemplate((JTemplate<?, ?>) jForm); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Form initEmptyBodyForm() { |
|
|
|
|
WFitLayout body = new WFitLayout(); |
|
|
|
|
WBorderLayout borderLayout = new WBorderLayout("form"); |
|
|
|
|
borderLayout.addCenter(body); |
|
|
|
|
return new Form(borderLayout); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 通过布局文件的位置初始化Form对象的布局信息 |
|
|
|
|
* |
|
|
|
|
* @param form 新建的form对象 |
|
|
|
|
* @param path 布局文件位置 |
|
|
|
|
* @throws Exception |
|
|
|
|
*/ |
|
|
|
|
private void initLayoutInfo(Form form, String path) throws Exception { |
|
|
|
|
if (isNewEmptyForm(path)) { |
|
|
|
|
initEmptyFormLayoutId(form); |
|
|
|
|
} else { |
|
|
|
|
Form layoutTemplate = new Form(); |
|
|
|
|
layoutTemplate.readStream(NewFormPane.class.getResourceAsStream(path)); |
|
|
|
|
|
|
|
|
|
if (layoutTemplate.getBody() != null && layoutTemplate.getBody() instanceof WFitLayout) { |
|
|
|
|
WFitLayout layoutTemplateBody = (WFitLayout) layoutTemplate.getBody(); |
|
|
|
|
WFitLayout body = (WFitLayout) form.getBody(); |
|
|
|
|
|
|
|
|
|
body.setMargin(layoutTemplateBody.getMargin()); |
|
|
|
|
body.setCompInterval(layoutTemplateBody.getCompInterval()); |
|
|
|
|
for (int i = 0; i < layoutTemplateBody.getWidgetCount(); i++) { |
|
|
|
|
Widget boundsWidget = layoutTemplateBody.getWidget(i); |
|
|
|
|
if (boundsWidget != null && boundsWidget instanceof BoundsWidget) { |
|
|
|
|
Widget widget = ((BoundsWidget) boundsWidget).getWidget(); |
|
|
|
|
if (widget != null && widget instanceof OccupiedLayout) { |
|
|
|
|
body.addWidget((Widget) boundsWidget.clone()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
form.setLayoutId(layoutTemplate.getLayoutId()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initEmptyFormLayoutId(Form form) { |
|
|
|
|
form.addAttrMark(new TemplateLayoutIdAttrMark(EMPTY_FORM_LAYOUTID)); |
|
|
|
|
form.setLayoutId(EMPTY_FORM_LAYOUTID); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isNewEmptyForm(String layoutTemplatePath) { |
|
|
|
|
return StringUtils.isEmpty(layoutTemplatePath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setSelectedLayoutPane(PredefinedLayoutPane layoutPane) { |
|
|
|
|
if (selectedLayoutPane != layoutPane) { |
|
|
|
|
if (selectedLayoutPane != null) { |
|
|
|
|