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.
220 lines
7.7 KiB
220 lines
7.7 KiB
/* |
|
* Copyright (C), 2018-2021 |
|
* Project: starter |
|
* FileName: ReturnFormatPane |
|
* Author: Louis |
|
* Date: 2021/11/29 15:01 |
|
*/ |
|
package com.fr.plugin.hrjf.pane; |
|
|
|
import com.fanruan.api.util.StringKit; |
|
import com.fr.base.BaseFormula; |
|
import com.fr.design.editor.editor.*; |
|
import com.fr.design.gui.ibutton.UIButtonGroup; |
|
import com.fr.design.i18n.Toolkit; |
|
import com.fr.design.mainframe.widget.editors.DataBindingEditor; |
|
import com.fr.design.mainframe.widget.editors.DataTableEditor; |
|
import com.fr.design.mainframe.widget.editors.ServerDataBindingEditor; |
|
import com.fr.design.mainframe.widget.editors.ServerDataTableEditor; |
|
import com.fr.general.ComparatorUtils; |
|
import com.fr.plugin.hrjf.items.DateFormatItems; |
|
import com.fr.plugin.hrjf.widget.VueDateEditor; |
|
|
|
import javax.swing.*; |
|
import java.awt.*; |
|
|
|
/** |
|
* <Function Description><br> |
|
* <ReturnFormatPane> |
|
* |
|
* @author fr.open |
|
* @since 1.0.0 |
|
*/ |
|
public class ReturnFormatPane extends JPanel { |
|
private UIButtonGroup widgetValueHead; |
|
private Editor[] editor; |
|
private JPanel customPane; |
|
private CardLayout cardLayout; |
|
|
|
public ReturnFormatPane() { |
|
this.editor = createWidgetValueEditor(new int[]{1, 3}, true); |
|
this.setLayout(new BorderLayout(0, 4)); |
|
this.cardLayout = new CardLayout(); |
|
this.customPane = new JPanel(this.cardLayout); |
|
String[] editorNames = new String[this.editor.length]; |
|
for (int i = 0; i < this.editor.length; ++i) { |
|
this.customPane.add(this.editor[i], this.editor[i].getName()); |
|
editorNames[i] = this.editor[i].getName(); |
|
} |
|
this.widgetValueHead = new UIButtonGroup(editorNames); |
|
this.add(this.widgetValueHead, BorderLayout.NORTH); |
|
this.add(this.customPane, BorderLayout.CENTER); |
|
} |
|
|
|
public static Editor createWidgetValueEditorByType(int editorType, boolean var1) { |
|
switch (editorType) { |
|
case 0: |
|
return new DoubleEditor(); |
|
case 1: |
|
return new TextEditor(); |
|
case 2: |
|
return (Editor) (var1 ? new ServerDataBindingEditor() : new DataBindingEditor()); |
|
case 3: |
|
return new FormulaEditor(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Parameter_Formula")); |
|
case 4: |
|
return new DateEditor(true, Toolkit.i18nText("Fine-Design_Basic_Date")); |
|
case 5: |
|
return new BooleanEditor(false); |
|
case 6: |
|
return (Editor) (var1 ? new ServerDataTableEditor() : new DataTableEditor()); |
|
default: |
|
return null; |
|
} |
|
} |
|
|
|
public static Editor[] createWidgetValueEditor(int[] editorTypes, boolean var1) { |
|
Editor[] editors = new Editor[editorTypes.length]; |
|
for (int var4 = 0; var4 < editorTypes.length; ++var4) { |
|
editors[var4] = createWidgetValueEditorByType(editorTypes[var4], var1); |
|
} |
|
return editors; |
|
} |
|
|
|
public void attributeChange() { |
|
int var1 = this.widgetValueHead.getSelectedIndex(); |
|
if (var1 == -1) { |
|
var1 = 0; |
|
this.widgetValueHead.setSelectedIndex(var1); |
|
} |
|
|
|
if (ComparatorUtils.equals(this.editor[var1].getName(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Widget_Field"))) { |
|
this.customPane.setPreferredSize(new Dimension(100, 47)); |
|
} else { |
|
this.customPane.setPreferredSize(new Dimension(100, 20)); |
|
} |
|
|
|
this.cardLayout.show(this.customPane, this.editor[var1].getName()); |
|
} |
|
|
|
public void update(VueDateEditor dateEditor, boolean isShowDate) { |
|
this.attributeChange(); |
|
int selectedIndex = this.widgetValueHead.getSelectedIndex(); |
|
Editor editor = this.editor[selectedIndex]; |
|
Object value = editor.getValue(); |
|
if (isShowDate) { |
|
updateShowDate(dateEditor, value); |
|
} else { |
|
updateReturnFormat(dateEditor, value); |
|
} |
|
} |
|
|
|
private void updateShowDate(VueDateEditor dateEditor, Object value) { |
|
if (value == null) { |
|
return; |
|
} |
|
if (value instanceof BaseFormula) { |
|
dateEditor.setShowDate(StringKit.EMPTY); |
|
dateEditor.setShowDateFM((BaseFormula) value); |
|
} else if (value instanceof String) { |
|
dateEditor.setShowDate(String.valueOf(value)); |
|
dateEditor.setShowDateFM(null); |
|
} else { |
|
dateEditor.setShowDate(String.valueOf(value)); |
|
dateEditor.setShowDateFM(null); |
|
} |
|
} |
|
|
|
private void updateReturnFormat(VueDateEditor dateEditor, Object value) { |
|
if (value == null) { |
|
return; |
|
} |
|
if (value instanceof BaseFormula) { |
|
dateEditor.setReturnFormat(StringKit.EMPTY); |
|
dateEditor.setReturnFormatFM((BaseFormula) value); |
|
} else if (value instanceof String) { |
|
dateEditor.setReturnFormat(String.valueOf(value)); |
|
dateEditor.setReturnFormatFM(null); |
|
} else { |
|
dateEditor.setReturnFormat(String.valueOf(value)); |
|
dateEditor.setReturnFormatFM(null); |
|
} |
|
} |
|
|
|
public void populateShowDate(VueDateEditor dateEditor) { |
|
if (StringKit.isNotBlank(dateEditor.getShowDate())) { |
|
this.populate(dateEditor.getShowDate()); |
|
} else if (dateEditor.getShowDateFM() != null) { |
|
this.populate(dateEditor.getShowDateFM()); |
|
} |
|
} |
|
|
|
public void populateShowDate(Object dateFormat) { |
|
if (dateFormat == null) { |
|
return; |
|
} |
|
String str; |
|
switch (String.valueOf(dateFormat)) { |
|
case DateFormatItems.YEAR: |
|
str = "yyyy"; |
|
break; |
|
case DateFormatItems.MONTH: |
|
str = "yyyy-MM"; |
|
break; |
|
case DateFormatItems.DATE: |
|
str = "yyyy-MM-dd"; |
|
break; |
|
case DateFormatItems.WEEK: |
|
str = "yyyy-WW"; |
|
break; |
|
case DateFormatItems.DATERANGE: |
|
str = "yyyy-MM-dd"; |
|
break; |
|
case DateFormatItems.DATERANGEWEEK: |
|
str = "yyyy-WW"; |
|
break; |
|
case DateFormatItems.DATERANGEMONTH: |
|
str = "yyyy-MM"; |
|
break; |
|
case DateFormatItems.DATES: |
|
str = "yyyy-MM-dd"; |
|
break; |
|
case DateFormatItems.DATETIME: |
|
str = "yyyy-MM-dd hh:mm:ss"; |
|
break; |
|
case DateFormatItems.DATETIMERANGE: |
|
str = "yyyy-MM-dd hh:mm:ss"; |
|
break; |
|
default: |
|
str = "yyyy-MM-dd"; |
|
} |
|
this.populate(str); |
|
} |
|
|
|
public void populateReturnFormat(VueDateEditor dateEditor) { |
|
if (StringKit.isNotBlank(dateEditor.getReturnFormat())) { |
|
this.populate(dateEditor.getReturnFormat()); |
|
} else if (dateEditor.getReturnFormatFM() != null) { |
|
this.populate(dateEditor.getReturnFormatFM()); |
|
} |
|
} |
|
|
|
public void populate(Object value) { |
|
for (int i = 0; i < this.editor.length; ++i) { |
|
if (this.editor[i].accept(value)) { |
|
this.setCardValue(i, value); |
|
break; |
|
} |
|
} |
|
this.attributeChange(); |
|
} |
|
|
|
private void setCardValue(int var1, Object var2) { |
|
this.widgetValueHead.setSelectedIndex(var1); |
|
this.editor[var1].setValue(var2); |
|
for (int i = 0; i < this.editor.length; ++i) { |
|
if (var1 != i) { |
|
this.editor[i].setValue((Object) null); |
|
} |
|
} |
|
} |
|
} |