Browse Source

REPORT-6868 设计器数据列单元格切换频繁弹出sql参数对话框

master
yaoh.wu 7 years ago
parent
commit
5c7c5acef3
  1. 48
      designer-base/src/com/fr/design/gui/demo/ComboBoxDemo.java
  2. 17
      designer-base/src/com/fr/design/gui/demo/SwingComponentsDemo.java
  3. 140
      designer-base/src/com/fr/design/gui/icombobox/LazyComboBox.java
  4. 48
      designer-base/src/com/fr/design/gui/icombobox/UIComboBox.java
  5. 132
      designer-realize/src/com/fr/design/dscolumn/DSColumnPane.java

48
designer-base/src/com/fr/design/gui/demo/ComboBoxDemo.java

@ -1,34 +1,37 @@
package com.fr.design.gui.demo;
import java.awt.BorderLayout;
import java.awt.Component;
import java.util.ArrayList;
import javax.swing.DefaultListCellRenderer;
import com.fr.design.gui.ilable.UILabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.ListCellRenderer;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreePath;
import com.fr.base.FRContext;
import com.fr.design.gui.icombobox.filter.Filter;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.icombobox.ComboCheckBox;
import com.fr.design.gui.icombobox.DictionaryComboBox;
import com.fr.design.gui.icombobox.ExtendedComboBox;
import com.fr.design.gui.icombobox.FRTreeComboBox;
import com.fr.design.gui.icombobox.FilterComboBox;
import com.fr.design.gui.icombobox.LazyComboBox;
import com.fr.design.gui.icombobox.filter.Filter;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.parameter.ParameterInputPane;
import com.fr.general.Inter;
import com.fr.stable.ParameterProvider;
import com.fr.stable.StringUtils;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.ListCellRenderer;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreePath;
import java.awt.BorderLayout;
import java.awt.Component;
import java.util.ArrayList;
/**
* Created by IntelliJ IDEA.
* User: Richer
@ -42,12 +45,12 @@ public class ComboBoxDemo extends JPanel {
double f = TableLayout.FILL;
Component[][] coms = new Component[][]{
{new UILabel(Inter.getLocText("Form-ComboCheckBox")+":"), createComboCheckBox()},
{new UILabel(Inter.getLocText(new String[]{"DS-Dictionary", "Form-ComboBox"})+":"), createDictComboBox()},
{new UILabel(Inter.getLocText("long_data_can_not_show_fully")+":"), createExtendedComboBox()},
{new UILabel(Inter.getLocText(new String[]{"Filter", "Form-ComboBox"})+":"), createFilterComboBox()},
{new UILabel(Inter.getLocText("Form-ComboBox")+":"), createTreeComboBox()},
{new UILabel(Inter.getLocText(new String[]{"Delay", "Load", "Form-ComboBox"})+":"), createLazyComboBox()}
{new UILabel(Inter.getLocText("Form-ComboCheckBox") + ":"), createComboCheckBox()},
{new UILabel(Inter.getLocText(new String[]{"DS-Dictionary", "Form-ComboBox"}) + ":"), createDictComboBox()},
{new UILabel(Inter.getLocText("long_data_can_not_show_fully") + ":"), createExtendedComboBox()},
{new UILabel(Inter.getLocText(new String[]{"Filter", "Form-ComboBox"}) + ":"), createFilterComboBox()},
{new UILabel(Inter.getLocText("Form-ComboBox") + ":"), createTreeComboBox()},
{new UILabel(Inter.getLocText(new String[]{"Delay", "Load", "Form-ComboBox"}) + ":"), createLazyComboBox()}
};
double[] rowSize = new double[coms.length];
double[] columnSize = {p, f};
@ -165,6 +168,7 @@ public class ComboBoxDemo extends JPanel {
// 睡5秒
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
FRContext.getLogger().error(e.getMessage(), e);
}

17
designer-base/src/com/fr/design/gui/demo/SwingComponentsDemo.java

@ -1,16 +1,15 @@
package com.fr.design.gui.demo;
import java.awt.BorderLayout;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.utils.DesignUtils;
import com.fr.design.utils.gui.GUICoreUtils;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.utils.DesignUtils;
import com.fr.design.utils.gui.GUICoreUtils;
import java.awt.BorderLayout;
/**
* Created by IntelliJ IDEA.
@ -19,10 +18,10 @@ import com.fr.design.utils.gui.GUICoreUtils;
* Time: 下午4:54
*/
public class SwingComponentsDemo extends JFrame {
public SwingComponentsDemo() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
private SwingComponentsDemo() {
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
init();
JPanel contentPane = (JPanel)getContentPane();
JPanel contentPane = (JPanel) getContentPane();
contentPane.setLayout(FRGUIPaneFactory.createBorderLayout());
JTabbedPane tab = new JTabbedPane();
contentPane.add(tab, BorderLayout.CENTER);
@ -40,12 +39,12 @@ public class SwingComponentsDemo extends JFrame {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame f = new SwingComponentsDemo();
f.setSize(500, 500);
f.setVisible(true);
GUICoreUtils.centerWindow(f);
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
});
}

140
designer-base/src/com/fr/design/gui/icombobox/LazyComboBox.java

@ -3,108 +3,115 @@
*/
package com.fr.design.gui.icombobox;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import javax.swing.*;
import javax.swing.DefaultComboBoxModel;
import javax.swing.SwingWorker;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import javax.swing.plaf.basic.BasicComboPopup;
import com.fr.general.Inter;
import java.awt.Dimension;
import java.util.concurrent.ExecutionException;
/**
* @author richer
* @version 2018年2月6日14点43分 by @yaoh.wu
* @since 6.5.5 创建于2011-6-15 延迟加载的下拉框
*/
public abstract class LazyComboBox extends UIComboBox implements PopupMenuListener {
private static final int NUM = 80;
private static final String[] PENDING_CONTENT = new String[]{"", Inter.getLocText("Loading") + "..."};
/**
* 是否加载完成
*/
protected boolean loaded = false;
private List<EventListener> ls = new ArrayList<EventListener>();
private Object initialSelected = null;
private static final int NUM=80;
public static final Object PENDING = new Object() {
/**
* 初始化选项
*/
private Object initialSelected = null;
@Override
public String toString() {
return Inter.getLocText("Loading") + "...";
}
};
public LazyComboBox() {
protected LazyComboBox() {
super();
this.setEditor(new FilterComboBoxEditor());
addPopupMenuListener(this);
// updateUI();
}
public void setLoaded(boolean loaded) {
this.loaded = loaded;
}
/**
* 加载下拉框中的选项
*
* @return 下拉框中的选项
*/
public abstract Object[] load();
@Override
public void setSelectedItem(Object anObject) {
initialSelected = anObject;
if (loaded) {
super.setSelectedItem(anObject);
} else {
setModel(new DefaultComboBoxModel(new Object[] { anObject }));
this.setModel(new DefaultComboBoxModel<>(new Object[]{anObject}));
super.setSelectedItem(anObject);
}
}
/**
* 通过调用该方法在点击下拉框按钮之前就加载好数据
*/
public void loadInstant() {
if (loaded) {
return;
}
setModel(new DefaultComboBoxModel(load()));
loaded = true;
}
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
if (loaded) {
return;
}
DefaultComboBoxModel loadingModel = new DefaultComboBoxModel(new String[]{"", Inter.getLocText("Loading") + "..."});
LazyComboBox.this.setModel(loadingModel);
new SwingWorker<Void, Void>() {
DefaultComboBoxModel<String> loadingModel = new DefaultComboBoxModel<>(PENDING_CONTENT);
this.setModel(loadingModel);
new SwingWorker<Object[], Void>() {
@Override
protected Void doInBackground() throws Exception {
final Object selectedObj = getSelectedItem();
loadList();
return null;
protected Object[] doInBackground() {
return load();
}
@Override
public void done() {
LazyComboBox.this.updateUI();
LazyComboBox.this.fireEvent();
try {
LazyComboBox.this.loadList(get());
} catch (InterruptedException | ExecutionException exception) {
FRLogger.getLogger().debug(exception.getMessage());
}
LazyComboBox.this.showPopup();
}
}.execute();
}
/**
* 加载下拉列表
*/
public void loadList() {
DefaultComboBoxModel<Object> model = new DefaultComboBoxModel<>(load());
model.setSelectedItem(initialSelected);
this.setModel(model);
this.selectedItemReminder = initialSelected;
loaded = true;
}
/**
* 计算加载下拉列表
* 加载下拉列表
*
* @param contents 下拉列表内容
*/
public void loadList() {
DefaultComboBoxModel model = new DefaultComboBoxModel(load());
private void loadList(Object[] contents) {
DefaultComboBoxModel<Object> model = new DefaultComboBoxModel<>(contents);
model.setSelectedItem(initialSelected);
LazyComboBox.this.setModel(model);
LazyComboBox.this.selectedItemReminder = initialSelected ;
this.setModel(model);
this.selectedItemReminder = initialSelected;
loaded = true;
}
@ -118,19 +125,6 @@ public abstract class LazyComboBox extends UIComboBox implements PopupMenuListen
}
public void addClickListener(EventListener l) {
if (ls == null) {
ls = new ArrayList<LazyComboBox.EventListener>();
}
ls.add(l);
}
public void fireEvent() {
for (int i = 0, n = ls.size(); i < n; i++) {
ls.get(i).fireEvent();
}
}
@Override
public Dimension getPreferredSize() {
Dimension dim = super.getPreferredSize();
@ -138,26 +132,6 @@ public abstract class LazyComboBox extends UIComboBox implements PopupMenuListen
return dim;
}
private static class LazyPopMenu extends BasicComboPopup {
public LazyPopMenu(final JComboBox combo) {
super(combo);
LazyComboBox comboc = (LazyComboBox) combo;
comboc.addClickListener(new EventListener() {
@Override
public void fireEvent() {
LazyPopMenu.this.show();
combo.showPopup();
}
});
}
}
private interface EventListener {
void fireEvent();
}
class FilterComboBoxEditor extends UIComboBoxEditor implements DocumentListener {
private Object item;
private volatile boolean filtering = false;
@ -168,12 +142,12 @@ public abstract class LazyComboBox extends UIComboBox implements PopupMenuListen
textField.getDocument().addDocumentListener(this);
}
@Override
public void setItem(Object item) {
if (filtering) {
return;
}
this.item = item;
this.setting = true;
textField.setSetting(true);
String newText = (item == null) ? "" : item.toString();
@ -182,23 +156,27 @@ public abstract class LazyComboBox extends UIComboBox implements PopupMenuListen
this.setting = false;
}
@Override
public Object getItem() {
return this.item;
}
@Override
public void insertUpdate(DocumentEvent e) {
handleChange();
}
@Override
public void removeUpdate(DocumentEvent e) {
handleChange();
}
@Override
public void changedUpdate(DocumentEvent e) {
handleChange();
}
protected void handleChange() {
void handleChange() {
if (setting) {
return;
}

48
designer-base/src/com/fr/design/gui/icombobox/UIComboBox.java

@ -4,12 +4,13 @@ import com.fr.design.event.GlobalNameListener;
import com.fr.design.event.GlobalNameObserver;
import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener;
import com.fr.design.utils.gui.GUICoreUtils;
import javax.swing.*;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.ListCellRenderer;
import javax.swing.plaf.ComboBoxUI;
import javax.swing.plaf.basic.ComboPopup;
import java.awt.*;
import java.awt.Dimension;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
@ -112,8 +113,6 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser
public void setRenderer(ListCellRenderer aRenderer) {
if (aRenderer instanceof UIComboBoxRenderer) {
super.setRenderer(aRenderer);
} else {
//throw new IllegalArgumentException("Must be UIComboBoxRenderer");
}
}
@ -121,13 +120,15 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser
return null;
}
@Override
public void setGlobalName(String name) {
comboBoxName = name;
}
@Override
public Dimension getPreferredSize() {
return new Dimension(super.getPreferredSize().width + SIZE5, SIZE);//加5的原因在于:render里,每一个项前面了空了一格,要多几像素
//加5的原因在于:render里,每一个项前面了空了一格,要多几像素
return new Dimension(super.getPreferredSize().width + SIZE5, SIZE);
}
/**
@ -147,68 +148,51 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser
/**
*
*/
@Override
public void updateUI() {
setUI(getUIComboBoxUI());
}
/**
*
* @param listener 观察者监听事件
*/
@Override
public void registerChangeListener(UIObserverListener listener) {
uiObserverListener = listener;
}
public void removeChangeListener(){
public void removeChangeListener() {
uiObserverListener = null;
}
public UIObserverListener getUiObserverListener(){
public UIObserverListener getUiObserverListener() {
return uiObserverListener;
}
/**
* @return
* @return 是否响应变更事件
*/
@Override
public boolean shouldResponseChangeListener() {
return true;
}
/**
*
* @param listener 观察者监听事件
*/
@Override
public void registerNameListener(GlobalNameListener listener) {
globalNameListener = listener;
}
/**
*
* @return
* @return 是否响应名称事件
*/
@Override
public boolean shouldResponseNameListener() {
return true;
}
/**
* @param args
*/
public static void main(String... args) {
LayoutManager layoutManager = null;
JFrame jf = new JFrame("test");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel content = (JPanel) jf.getContentPane();
content.setLayout(layoutManager);
UIComboBox bb = new UIComboBox(new String[]{"", "jerry", "kunsnat", "richer"});
bb.setEditable(true);
bb.setBounds(20, 20, bb.getPreferredSize().width, bb.getPreferredSize().height);
content.add(bb);
GUICoreUtils.centerWindow(jf);
jf.setSize(400, 400);
jf.setVisible(true);
}
}

132
designer-realize/src/com/fr/design/dscolumn/DSColumnPane.java

@ -1,26 +1,30 @@
package com.fr.design.dscolumn;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.fr.base.FRContext;
import com.fr.data.TableDataSource;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.frpane.UITabbedPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.dialog.BasicPane;
import com.fr.general.Inter;
import com.fr.design.mainframe.ElementCasePane;
import com.fr.general.Inter;
import com.fr.report.cell.CellElement;
import com.fr.report.cell.DefaultTemplateCellElement;
import com.fr.report.cell.TemplateCellElement;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
/**
* @author null
* @version 2018年2月9日13点47分
* @since 8.0
*/
public class DSColumnPane extends BasicPane {
private TableDataSource tplEC;
@ -29,13 +33,52 @@ public class DSColumnPane extends BasicPane {
private DSColumnConditionsPane conditionPane = null;
private DSColumnAdvancedPane advancedPane = null;
private TemplateCellElement cellElement;
protected Component lastSelectedComponent;
private Component lastSelectedComponent;
public static final int SETTING_ALL = 2;
public static final int SETTING_DSRELATED = 1;
private ChangeListener appliedWizardTabChangeListener = new ChangeListener() {
@Override
public void stateChanged(ChangeEvent evt) {
try {
if (lastSelectedComponent == null) {
lastSelectedComponent = basicPane;
}
// selectTabComponent是正要切换到的那个Pane
Component selectTabComponent = tabbedPane.getSelectedComponent();
// denny: 如果切换Tab时上一个Pane是basicPane, 则刷新一下其他Pane,
// 因为选择的数据列可能改变, 导致后面过滤和使用公式用到的数据项改变
if (lastSelectedComponent == basicPane) {
basicPane.update(cellElement);
// denny_GUI: 刷新其他面板
refreshOtherTabs();
}
// 切换标签的时候就,确认是否有没有添加到列表中的条件
lastSelectedComponent = selectTabComponent;
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
};
/**
* cellElement 改变时刷新一下
* 比如上边切换Tab时basicPane Update了一下可能会改变Field cellElement的值
*/
private PropertyChangeListener myPropertyChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
refreshOtherTabs();
}
};
public DSColumnPane() {
this.initComponents(SETTING_ALL);
this(SETTING_ALL);
}
public DSColumnPane(int setting) {
@ -71,8 +114,12 @@ public class DSColumnPane extends BasicPane {
return Inter.getLocText("ExpandD-Data_Column");
}
/*
* populate
/**
* 更新面板信息
*
* @param tds 数据源
* @param cellElement 单元格
* @throws Exception e
*/
public void populate(TableDataSource tds, TemplateCellElement cellElement) throws Exception {
this.tplEC = tds;
@ -85,15 +132,18 @@ public class DSColumnPane extends BasicPane {
// _denny: 这边需要克隆一下,因为在设置时,可能改变字段cellElement,但改变真实值是不被期望的
try {
this.cellElement = (TemplateCellElement) cellElement.clone();
} catch (CloneNotSupportedException ce) {
} catch (CloneNotSupportedException ignored) {
}
//REPORT-7744 9.0里面过滤条件和高级设置可以通过其他地方设置,populate的时候需要更新所有面板的信息,防止设置丢失
this.basicPane.populate(tds, this.cellElement);
this.conditionPane.populate(tds, this.cellElement);
this.advancedPane.populate(this.cellElement);
}
/*
* update
/**
* update 保存
*
* @return 单元格信息
*/
public CellElement update() {
this.basicPane.update(cellElement);
@ -101,50 +151,20 @@ public class DSColumnPane extends BasicPane {
this.advancedPane.update(cellElement);
return cellElement;
}
public ChangeListener appliedWizardTabChangeListener = new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
try {
if (lastSelectedComponent == null) {
lastSelectedComponent = basicPane;
}
//selectTabComponent是正要切换到的那个Pane
Component selectTabComponent = tabbedPane.getSelectedComponent();
// _denny: 如果切换Tab时上一个Pane是basicPane, 则刷新一下其他Pane,
// 因为选择的数据列可能改变, 导致后面过滤和使用公式用到的数据项改变
if (lastSelectedComponent == basicPane) {
basicPane.update(cellElement);
// denny_GUI: 刷新其他面板
refrushOtherTabs();
}
// 切换标签的时候就,确认是否有没有添加到列表中的条件
lastSelectedComponent = selectTabComponent;
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
};
// cellElement 改变时,刷新一下
// 比如:上边切换Tab时,basicPane Update了一下,可能会改变Field cellElement的值
PropertyChangeListener myPropertyChangeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
refrushOtherTabs();
}
};
//_denny:当数据tab中的数据发生变化的时候刷新后面的tab
public void refrushOtherTabs() {
// ——deny:当JTabPane中加入一个Pane时,后面的Pane可能还没有初始化
/**
* denny:当数据tab中的数据发生变化的时候刷新后面的tab
*/
private void refreshOtherTabs() {
// deny:当JTabPane中加入一个Pane时,后面的Pane可能还没有初始化
if (conditionPane == null || advancedPane == null) {
return;
}
this.conditionPane.populate(tplEC, cellElement);
this.advancedPane.populate(cellElement);
}
public void putElementcase(ElementCasePane t){
public void putElementcase(ElementCasePane t) {
basicPane.putElementcase(t);
}

Loading…
Cancel
Save