Browse Source

Merge pull request #1031 in BA/design from ~PLOUGH/design:9.0 to 9.0

* commit 'be2ab9031440ee29f7f66aa4badeafe9aa7aafdd':
  REPORT-3163 合作开发9.0设计器=>代码规范
  REPORT-3163 合作开发9.0设计器=>控件设置事件编辑(报表)=》整合代码,实现保存设置
  REPORT-3163 合作开发9.0设计器=>控件设置事件编辑(表单)=>边框校正
  REPORT-3163 合作开发9.0设计器=>控件设置事件编辑(表单)=>去掉冗余代码
  REPORT-3163 合作开发9.0设计器=>控件设置事件编辑=>国际化;整理代码
  REPORT-3163 合作开发9.0设计器=>控件设置事件编辑(表单)=>bug解决;效率优化
  REPORT-3163 合作开发9.0设计器=>新列表面板=》修改弹出框的尺寸和边框
  无JIRA任务,收集模版信息时,不应该影响保存
  REPORT-3163 合作开发9.0设计器=>控件设置事件编辑(表单)=>可保存设置,但有bug
  REPORT-3163 合作开发9.0设计器=>控件设置事件编辑(表单)=>初步修改
  REPORT-3163 合作开发9.0设计器=>控件设置事件编辑(报表)初步修改
master
superman 7 years ago
parent
commit
acc35e63b1
  1. 43
      designer/src/com/fr/design/widget/WidgetEventPane.java
  2. 62
      designer_base/src/com/fr/design/gui/controlpane/ObjectUIControlPane.java
  3. 17
      designer_base/src/com/fr/design/gui/controlpane/UIControlPane.java
  4. 2
      designer_base/src/com/fr/design/gui/controlpane/UIListControlPane.java
  5. 1
      designer_base/src/com/fr/design/locale/designer.properties
  6. 1
      designer_base/src/com/fr/design/locale/designer_en_US.properties
  7. 1
      designer_base/src/com/fr/design/locale/designer_ja_JP.properties
  8. 1
      designer_base/src/com/fr/design/locale/designer_ko_KR.properties
  9. 1
      designer_base/src/com/fr/design/locale/designer_zh_CN.properties
  10. 1
      designer_base/src/com/fr/design/locale/designer_zh_TW.properties
  11. 5
      designer_base/src/com/fr/design/mainframe/JTemplate.java
  12. 132
      designer_base/src/com/fr/design/widget/EventCreator.java
  13. 453
      designer_form/src/com/fr/design/designer/properties/EventPropertyTable.java
  14. 9
      designer_form/src/com/fr/design/mainframe/JForm.java
  15. 21
      designer_form/src/com/fr/design/mainframe/WidgetPropertyPane.java

43
designer/src/com/fr/design/widget/WidgetEventPane.java

@ -4,10 +4,13 @@ package com.fr.design.widget;
import java.util.ArrayList;
import java.util.List;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.controlpane.ObjectUIControlPane;
import com.fr.design.mainframe.CellWidgetPropertyPane;
import com.fr.design.present.CellWriteAttrPane;
import com.fr.design.write.submit.DBManipulationPane;
import com.fr.design.write.submit.SmartInsertDBManipulationInWidgetEventPane;
import com.fr.design.gui.controlpane.NameableCreator;
import com.fr.design.gui.controlpane.ObjectJControlPane;
import com.fr.design.gui.frpane.ListenerUpdatePane;
import com.fr.design.javascript.JavaScriptActionPane;
import com.fr.design.mainframe.DesignerContext;
@ -15,40 +18,52 @@ import com.fr.design.mainframe.ElementCasePane;
import com.fr.design.mainframe.JTemplate;
import com.fr.form.event.Listener;
import com.fr.form.ui.Widget;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.general.NameObject;
import com.fr.grid.GridUtils;
import com.fr.grid.selection.CellSelection;
import com.fr.privilege.finegrain.WidgetPrivilegeControl;
import com.fr.report.cell.DefaultTemplateCellElement;
import com.fr.report.cell.TemplateCellElement;
import com.fr.report.elementcase.TemplateElementCase;
import com.fr.report.stable.ReportConstants;
import com.fr.stable.Nameable;
public class WidgetEventPane extends ObjectJControlPane {
public WidgetEventPane() {
this(null);
}
public class WidgetEventPane extends ObjectUIControlPane {
public WidgetEventPane(ElementCasePane pane) {
super(pane);
this.setNameListEditable(false);
}
@Override
public String getAddItemText() {
return Inter.getLocText("FR-Designer_Add_Event");
}
/**
* 生成添加按钮的NameableCreator
* @return 按钮的NameableCreator
*/
public NameableCreator[] createNameableCreators() {
return new NameableCreator[]{
EventCreator.STATECHANGE
new EventCreator(Widget.EVENT_STATECHANGE, WidgetEventListenerUpdatePane.class)
};
}
@Override
@Override
public void saveSettings() {
CellWidgetPropertyPane.getInstance().update();
}
@Override
protected String title4PopupWindow() {
return Inter.getLocText("Event");
}
public static class WidgetEventListenerUpdatePane extends ListenerUpdatePane {
private ElementCasePane epane;
public WidgetEventListenerUpdatePane() {
this(null);
}
private ElementCasePane epane;
public WidgetEventListenerUpdatePane(ElementCasePane epane){
this.epane = epane;
super.initComponents();
@ -104,7 +119,7 @@ public class WidgetEventPane extends ObjectJControlPane {
return;
}
this.refreshNameableCreator(EventCreator.createEventCreator(widget.supportedEvents()));
this.refreshNameableCreator(EventCreator.createEventCreator(widget.supportedEvents(), WidgetEventListenerUpdatePane.class));
List<NameObject> list = new ArrayList<NameObject>();
Listener listener;

62
designer_base/src/com/fr/design/gui/controlpane/ObjectUIControlPane.java

@ -0,0 +1,62 @@
package com.fr.design.gui.controlpane;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import com.fr.design.beans.BasicBeanPane;
/**
* Created by plough on 2017/8/1.
*/
public abstract class ObjectUIControlPane extends UIListControlPane {
private Object object;
public ObjectUIControlPane() {
this(null);
}
public ObjectUIControlPane(Object object) {
super();
this.object = object;
}
@Override
protected BasicBeanPane createPaneByCreators(NameableCreator creator) {
try {
if (object == null) {
return super.createPaneByCreators(creator);
} else if (object.getClass().isArray()) {
return creator.getUpdatePane().getConstructor(object.getClass()).newInstance(object);
} else {
Constructor<? extends BasicBeanPane> constructor = getConstructor(creator.getUpdatePane(), object.getClass());
return constructor == null ? super.createPaneByCreators(creator) : constructor.newInstance(object);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 传进BasicBeanPane的构造函数的参数可能是
*
* @param clazz
* @param cls
* @return
*/
private Constructor<? extends BasicBeanPane> getConstructor(Class<? extends BasicBeanPane> clazz, Class<?> cls) {
Constructor<? extends BasicBeanPane> constructor = null;
try {
constructor = clazz.getConstructor(cls);
} catch (SecurityException e) {
} catch (NoSuchMethodException e) {
}
if (constructor != null) {
return constructor;
} else {
if (cls.getName() == Object.class.getName()) {
return null;
}
return getConstructor(clazz, cls.getSuperclass());
}
}
}

17
designer_base/src/com/fr/design/gui/controlpane/UIControlPane.java

@ -28,6 +28,7 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH
private ToolBarDef toolbarDef;
private UIToolbar toolBar;
private UIToolbar topToolBar;
protected PopupEditDialog popupEditDialog;
// peter:这是整体的一个cardLayout Pane
protected CardLayout cardLayout;
@ -146,7 +147,7 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH
// leftContentPane.setBorder(BorderFactory.createLineBorder(new Color(201, 198, 184)));
// 顶部标签及add按钮
UIToolbar topToolBar = new UIToolbar();
topToolBar = new UIToolbar();
topToolBar.setLayout(new BorderLayout());
ShortCut addItem = addItemShortCut().getShortCut();
addItem.intoJToolBar(topToolBar);
@ -246,19 +247,27 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH
toolbarDef.updateToolBar(toolBar);
toolBar.validate();
toolBar.repaint();
// 顶部按钮
topToolBar.removeAll();
ShortCut addItem = addItemShortCut().getShortCut();
addItem.intoJToolBar(topToolBar);
topToolBar.validate();
this.repaint();
}
// 点击"编辑"按钮,弹出面板
protected class PopupEditDialog extends JDialog {
private JComponent editPane;
private static final int WIDTH = 490;
private static final int HEIGHT = 570;
private static final int WIDTH = 570;
private static final int HEIGHT = 490;
PopupEditDialog(JComponent pane) {
super(DesignerContext.getDesignerFrame());
setUndecorated(true);
pane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
pane.setBorder(BorderFactory.createEmptyBorder(20, 10, 10, 10));
this.editPane = pane;
this.getContentPane().add(editPane, BorderLayout.CENTER);
setSize(WIDTH, HEIGHT);

2
designer_base/src/com/fr/design/gui/controlpane/UIListControlPane.java

@ -210,7 +210,7 @@ public abstract class UIListControlPane extends UIControlPane {
listModel.addElement(new ListModelElement(aNameableArray));
}
if (listModel.size() > 0) {
if (listModel.size() > 0 || this.nameableList.getSelectedIndex() != 0) {
this.nameableList.setSelectedIndex(0);
}
this.checkButtonEnabled();

1
designer_base/src/com/fr/design/locale/designer.properties

@ -2105,3 +2105,4 @@ FR-Designer_Insert_Formula=Insert_Formula
FR-Designer_Insert_Chart=
FR-Designer_Insert_Text=
FR-Designer_Double=
FR-Designer_Add_Event=Add Event

1
designer_base/src/com/fr/design/locale/designer_en_US.properties

@ -2106,3 +2106,4 @@ FR-Designer_Insert_Formula=Insert_Formula
FR-Designer_Insert-Chart=
FR-Designer_Insert-Text=
FR-Designer_Double=
FR-Designer_Add_Event=Add Event

1
designer_base/src/com/fr/design/locale/designer_ja_JP.properties

@ -2107,3 +2107,4 @@ FR-Designer_Label_Name=
FR-Designer_Insert-Chart=
FR-Designer_Insert-Text=
FR-Designer_Insert_Formula=
FR-Designer_Add_Event=

1
designer_base/src/com/fr/design/locale/designer_ko_KR.properties

@ -2107,3 +2107,4 @@ FR-Designer_Use_Params_Template=
FR-Designer_Label_Name=
FR-Designer_Insert-Chart=
FR-Designer_Insert-Text=
FR-Designer_Add_Event=

1
designer_base/src/com/fr/design/locale/designer_zh_CN.properties

@ -2101,3 +2101,4 @@ FR-Designer_Insert_Image=\u63D2\u5165\u56FE\u7247
FR-Designer_Insert_Chart=\u63D2\u5165\u56FE\u8868
FR-Designer_Insert_Text=\u63D2\u5165\u666E\u901A\u6587\u672C
FR-Designer_Insert_Formula=\u63D2\u5165\u516C\u5F0F
FR-Designer_Add_Event=\u6DFB\u52A0\u4E8B\u4EF6

1
designer_base/src/com/fr/design/locale/designer_zh_TW.properties

@ -2107,3 +2107,4 @@ FR-Designer_Use_Params_Template=
FR-Designer_Label_Name=
FR-Designer_Insert-Chart=
FR-Designer_Insert-Text=
FR-Designer_Add_Event=

5
designer_base/src/com/fr/design/mainframe/JTemplate.java

@ -126,7 +126,10 @@ public abstract class JTemplate<T extends IOFile, U extends BaseUndoState<?>> ex
return;
}
long saveTime = System.currentTimeMillis(); // 保存模板的时间点
tic.collectInfo(template, this, openTime, saveTime);
try {
tic.collectInfo(template, this, openTime, saveTime);
} catch (Throwable th) { // 不管收集过程中出现任何异常,都不应该影响模版保存
}
openTime = saveTime; // 更新 openTime,准备下一次计算
}

132
designer/src/com/fr/design/widget/EventCreator.java → designer_base/src/com/fr/design/widget/EventCreator.java

@ -1,76 +1,58 @@
package com.fr.design.widget;
import com.fr.base.FRContext;
import com.fr.design.gui.controlpane.NameableSelfCreator;
import com.fr.design.gui.controlpane.UnrepeatedNameHelper;
import com.fr.design.gui.ilist.ListModelElement;
import com.fr.form.event.Listener;
import com.fr.form.ui.FileEditor;
import com.fr.form.ui.Widget;
import com.fr.general.Inter;
import com.fr.general.NameObject;
import com.fr.stable.Nameable;
public class EventCreator extends NameableSelfCreator {
private String eventName;
public EventCreator(String eventName) {
super(switchLang(eventName), Listener.class, WidgetEventPane.WidgetEventListenerUpdatePane.class);
this.eventName = eventName;
}
@Override
public Nameable createNameable(UnrepeatedNameHelper helper) {
return new NameObject(helper.createUnrepeatedName(this.menuName()),new Listener(this.eventName)) ;
}
public static EventCreator[] createEventCreator(String[] supportedEvents) {
EventCreator[] creators = new EventCreator[supportedEvents.length];
for (int i = 0; i < supportedEvents.length; i++) {
creators[i] = new EventCreator(supportedEvents[i]);
}
return creators;
}
/*
* richer:国际化事件名称所有需要国际化的事件都应按格式Event-eventName来进行国际化
*/
public static final String switchLang(String eventName) {
try {
return Inter.getLocText("Event-" + eventName);
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
return eventName;
}
}
@Override
public void saveUpdatedBean(ListModelElement wrapper, Object bean) {
((NameObject)wrapper.wrapper).setObject(bean);
}
public static final EventCreator BEFOREEDIT = new EventCreator(Widget.BEFOREEDIT);
public static final EventCreator AFTEREDIT = new EventCreator(Widget.AFTEREDIT);
public static final EventCreator CHANGE = new EventCreator(Widget.CHANGE);
public static final EventCreator CLICK = new EventCreator(Widget.EVENT_CLICK);
public static final EventCreator SUCCESS = new EventCreator("success");
public static final EventCreator AFTERINIT = new EventCreator(Widget.AFTERINIT);
public static final EventCreator STOPEDIT = new EventCreator(Widget.STOPEDIT);
public static final EventCreator STATECHANGE = new EventCreator(Widget.EVENT_STATECHANGE);
public static final EventCreator CALLBACK = new EventCreator(FileEditor.EVENT_UPLOAD_CALLBACK);
@Override
public String createTooltip() {
return null;
}
package com.fr.design.widget;
import com.fr.base.FRContext;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.controlpane.NameableSelfCreator;
import com.fr.design.gui.controlpane.UnrepeatedNameHelper;
import com.fr.design.gui.ilist.ListModelElement;
import com.fr.form.event.Listener;
import com.fr.form.ui.FileEditor;
import com.fr.form.ui.Widget;
import com.fr.general.Inter;
import com.fr.general.NameObject;
import com.fr.stable.Nameable;
public class EventCreator extends NameableSelfCreator {
private String eventName;
public EventCreator(String eventName, Class<? extends BasicBeanPane> updatePane) {
super(switchLang(eventName), Listener.class, updatePane);
this.eventName = eventName;
}
@Override
public Nameable createNameable(UnrepeatedNameHelper helper) {
return new NameObject(helper.createUnrepeatedName(this.menuName()),new Listener(this.eventName)) ;
}
public static EventCreator[] createEventCreator(String[] supportedEvents, Class<? extends BasicBeanPane> updatePane) {
EventCreator[] creators = new EventCreator[supportedEvents.length];
for (int i = 0; i < supportedEvents.length; i++) {
creators[i] = new EventCreator(supportedEvents[i], updatePane);
}
return creators;
}
/*
* richer:国际化事件名称所有需要国际化的事件都应按格式Event-eventName来进行国际化
*/
public static final String switchLang(String eventName) {
try {
return Inter.getLocText("Event-" + eventName);
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
return eventName;
}
}
@Override
public void saveUpdatedBean(ListModelElement wrapper, Object bean) {
((NameObject)wrapper.wrapper).setObject(bean);
}
@Override
public String createTooltip() {
return null;
}
}

453
designer_form/src/com/fr/design/designer/properties/EventPropertyTable.java

@ -1,243 +1,73 @@
package com.fr.design.designer.properties;
import com.fr.base.BaseUtils;
import com.fr.base.FRContext;
import com.fr.design.actions.UpdateAction;
import com.fr.design.gui.controlpane.NameableCreator;
import com.fr.design.gui.controlpane.UIListControlPane;
import com.fr.design.gui.frpane.ListenerUpdatePane;
import com.fr.design.gui.ilist.JNameEdList;
import com.fr.design.gui.itoolbar.UIToolbar;
import com.fr.design.javascript.EmailPane;
import com.fr.design.javascript.JavaScriptActionPane;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.menu.MenuDef;
import com.fr.design.menu.ShortCut;
import com.fr.design.menu.ToolBarDef;
import com.fr.design.widget.EventCreator;
import com.fr.design.write.submit.DBManipulationPane;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.editor.ValueEditorPaneFactory;
import com.fr.design.designer.creator.XCreator;
import com.fr.form.event.Listener;
import com.fr.design.form.javascript.FormEmailPane;
import com.fr.form.ui.Widget;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.general.NameObject;
import com.fr.js.JavaScriptImpl;
import com.fr.stable.Nameable;
import com.fr.design.utils.gui.GUICoreUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.util.ArrayList;
public class EventPropertyTable extends BasicPane {
public class EventPropertyTable extends UIListControlPane {
private ShortCut[] shorts;
private XCreator creator;
private JNameEdList nameableList;
private ToolBarDef toolbarDef;
private AddItemMenuDef itemMenu;
private ShortCut editItemAction;
private ShortCut copyItemAction;
private ShortCut removeItemAction;
private UIToolbar toolbar;
private ListenerUpdatePane listenerPane;
private FormDesigner designer;
public EventPropertyTable(FormDesigner designer) {
super();
this.designer = designer;
this.initComponents();
}
protected void initComponents() {
this.setLayout(new BorderLayout());
nameableList = new JNameEdList(new DefaultListModel());
this.add(new JScrollPane(nameableList), BorderLayout.CENTER);
@Override
public String getAddItemText() {
return Inter.getLocText("FR-Designer_Add_Event");
}
nameableList.setCellRenderer(new NameableListCellRenderer());
nameableList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
nameableList.addMouseListener(listMouseListener);
nameableList.setTransferHandler(new DnDTransferHandler());
nameableList.setDropMode(DropMode.INSERT);
nameableList.setDragEnabled(true);
public static class WidgetEventListenerUpdatePane extends ListenerUpdatePane {
toolbarDef = new ToolBarDef();
shorts = new ShortCut[] { itemMenu = new AddItemMenuDef(), editItemAction = new EditItemMenuDef(),
copyItemAction = new CopyItemAction(), removeItemAction = new RemoveItemAction() };
for (ShortCut sj : shorts) {
toolbarDef.addShortCut(sj);
}
toolbar = ToolBarDef.createJToolBar();
toolbarDef.updateToolBar(toolbar);
this.add(toolbar, BorderLayout.NORTH);
}
/**
* 指定索引添加对象
* @param nameObject 对象名
* @param index 索引
*/
public void addNameObject(NameObject nameObject, int index) {
DefaultListModel model = (DefaultListModel) nameableList.getModel();
model.add(index, nameObject);
nameableList.setSelectedIndex(index);
nameableList.ensureIndexIsVisible(index);
nameableList.repaint();
}
/**
* 刷新控件
* @param strings 字符数组
*/
public void refreshNameableCreator(String[] strings) {
itemMenu.populate(strings);
toolbarDef.updateToolBar(toolbar);
toolbar.validate();
toolbar.repaint();
this.repaint();
}
private void checkButtonEnabled() {
boolean enable = nameableList.getSelectedValue() instanceof NameObject;
itemMenu.setEnabled(this.creator != null && itemMenu.getShortCutCount() > 0);
editItemAction.setEnabled(enable);
copyItemAction.setEnabled(enable);
removeItemAction.setEnabled(enable);
}
private MouseListener listMouseListener = new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent evt) {
checkButtonEnabled();
if (evt.getClickCount() >= 2 && SwingUtilities.isLeftMouseButton(evt)) {
NameObject object = (NameObject) nameableList.getSelectedValue();
showEventPane(object);
}
}
};
private void showEventPane(final NameObject object) {
if (listenerPane == null) {
listenerPane = new ListenerUpdatePane() {
protected JavaScriptActionPane createJavaScriptActionPane() {
return new JavaScriptActionPane() {
@Override
protected JavaScriptActionPane createJavaScriptActionPane() {
return new JavaScriptActionPane() {
@Override
protected DBManipulationPane createDBManipulationPane() {
return new DBManipulationPane(ValueEditorPaneFactory.formEditors());
}
@Override
protected String title4PopupWindow() {
return Inter.getLocText("Set_Callback_Function");
}
@Override
protected EmailPane initEmaiPane() {
return new FormEmailPane();
}
@Override
public boolean isForm() {
return true;
}
protected String[] getDefaultArgs() {
return new String[0];
}
protected DBManipulationPane createDBManipulationPane() {
return new DBManipulationPane(ValueEditorPaneFactory.formEditors());
}
};
@Override
protected String title4PopupWindow() {
return Inter.getLocText("Set_Callback_Function");
}
@Override
protected boolean supportCellAction() {
return false;
protected EmailPane initEmaiPane() {
return new FormEmailPane();
}
@Override
public boolean isForm() {
return true;
}
};
}
listenerPane.populateBean((Listener) object.getObject());
BasicDialog dialog = listenerPane.showWindow(SwingUtilities.getWindowAncestor(this));
dialog.addDialogActionListener(new DialogActionAdapter() {
@Override
public void doOk() {
object.setObject(listenerPane.updateBean());
updateWidgetListener(creator);
}
});
dialog.setVisible(true);
}
private class NameableListCellRenderer extends DefaultListCellRenderer {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof NameObject) {
Nameable wrappee = (NameObject) value;
this.setText(wrappee.getName());
}
return this;
}
}
/*
* 增加项的MenuDef
*/
protected class AddItemMenuDef extends MenuDef {
public AddItemMenuDef() {
this.setName(Inter.getLocText("Add"));
this.setMnemonic('A');
this.setIconPath("/com/fr/design/images/control/addPopup.png");
}
public void populate(String[] eventNames) {
this.clearShortCuts();
for (int i = 0; i < eventNames.length; i++) {
final String eventname = eventNames[i];
this.addShortCut(new UpdateAction() {
{
this.setName(switchLang(eventname));
}
public void actionPerformed(ActionEvent e) {
NameObject nameable = new NameObject(createUnrepeatedName(switchLang(eventname)), new Listener(
eventname,new JavaScriptImpl()));
EventPropertyTable.this.addNameObject(nameable, EventPropertyTable.this.nameableList.getModel()
.getSize());
updateWidgetListener(creator);
}
});
}
}
}
protected String[] getDefaultArgs() {
return new String[0];
}
protected class EditItemMenuDef extends UpdateAction {
public EditItemMenuDef() {
this.setName(Inter.getLocText("Edit"));
this.setMnemonic('E');
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/control/edit.png"));
};
}
public void actionPerformed(ActionEvent evt) {
if (nameableList.getSelectedValue() instanceof NameObject) {
showEventPane((NameObject) nameableList.getSelectedValue());
}
@Override
protected boolean supportCellAction() {
return false;
}
}
@ -261,222 +91,53 @@ public class EventPropertyTable extends BasicPane {
}
Widget widget = creator.toData();
refreshNameableCreator(widget.supportedEvents());
refreshNameableCreator(EventCreator.createEventCreator(widget.supportedEvents(), WidgetEventListenerUpdatePane.class));
((DefaultListModel) nameableList.getModel()).removeAllElements();
ArrayList<NameObject> nameObjectList = new ArrayList<>();
for (int i = 0, size = widget.getListenerSize(); i < size; i++) {
Listener listener = widget.getListener(i);
if (!listener.isDefault()) {
addNameObject(new NameObject(switchLang(listener.getEventName()) + (i + 1), listener), i);
}
nameObjectList.add(i, new NameObject(switchLang(listener.getEventName()) + (i + 1), listener));
}
}
populate(nameObjectList.toArray(new NameObject[widget.getListenerSize()]));
checkButtonEnabled();
this.repaint();
}
}
/**
* 更新控件事件
* @param creator 控件
*/
public void updateWidgetListener(XCreator creator) {
DefaultListModel listModel = (DefaultListModel) this.nameableList.getModel();
(creator.toData()).clearListeners();
for (int i = 0, len = listModel.getSize(); i < len; i++) {
(creator.toData()).addListener((Listener) ((NameObject) listModel.getElementAt(i)).getObject());
}
designer.fireTargetModified();
(creator.toData()).clearListeners();
Nameable[] res = this.update();
for (int i = 0; i < res.length; i++) {
NameObject nameObject = (NameObject)res[i];
(creator.toData()).addListener((Listener) nameObject.getObject());
}
designer.fireTargetModified();
checkButtonEnabled();
}
private class RemoveItemAction extends UpdateAction {
public RemoveItemAction() {
this.setName(Inter.getLocText("Remove"));
this.setMnemonic('R');
this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/remove.png"));
}
public void actionPerformed(ActionEvent evt) {
GUICoreUtils.removeJListSelectedNodes(SwingUtilities.getWindowAncestor(EventPropertyTable.this),
nameableList);
updateWidgetListener(creator);
}
}
/*
* CopyItem
*/
private class CopyItemAction extends UpdateAction {
public CopyItemAction() {
this.setName(Inter.getLocText("Copy"));
this.setMnemonic('C');
this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/copy.png"));
}
public void actionPerformed(ActionEvent evt) {
NameObject selectedNameObject = (NameObject) nameableList.getSelectedValue();
// p: 用反射机制实现
try {
NameObject newNameObject = (NameObject) BaseUtils.cloneObject(selectedNameObject);
newNameObject.setName("CopyOf" + selectedNameObject.getName());
EventPropertyTable.this.addNameObject(newNameObject, nameableList.getSelectedIndex() + 1);
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
updateWidgetListener(creator);
}
}
@Override
protected String title4PopupWindow() {
return "Event";
}
/**
* 生成不重复名字
* @param prefix 字符
* @return 返回
*/
public String createUnrepeatedName(String prefix) {
DefaultListModel model = (DefaultListModel) nameableList.getModel();
Nameable[] all = new Nameable[model.getSize()];
for (int i = 0; i < model.size(); i++) {
all[i] = (Nameable) model.get(i);
}
int count = 1;
while (true) {
String name_test = prefix + count;
boolean repeated = false;
for (int i = 0, len = model.size(); i < len; i++) {
Nameable nameable = all[i];
if (ComparatorUtils.equals(nameable.getName(), name_test)) {
repeated = true;
break;
}
}
if (!repeated) {
return name_test;
}
count++;
}
}
private class DnDTransferHandler extends TransferHandler {
private int action;
public DnDTransferHandler() {
this(TransferHandler.MOVE);
}
public DnDTransferHandler(int action) {
this.action = action;
}
@Override
public int getSourceActions(JComponent comp) {
return action;
}
@Override
public Transferable createTransferable(JComponent comp) {
int index = nameableList.getSelectedIndex();
if (index < 0 || index >= nameableList.getModel().getSize()) {
return null;
}
return new DnDListItem((NameObject) nameableList.getSelectedValue());
}
@Override
public boolean canImport(TransferSupport support) {
if (!support.isDrop()) {
return false;
}
if (!support.isDataFlavorSupported(DnDListItem.FLAVOR)) {
return false;
}
boolean actionSupported = (action & support.getSourceDropActions()) == action;
if (actionSupported) {
support.setDropAction(action);
return true;
}
return false;
}
@Override
public boolean importData(TransferHandler.TransferSupport support) {
if (!canImport(support)) {
return false;
}
JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
int importIndex = dl.getIndex();
try {
NameObject item = (NameObject) support.getTransferable().getTransferData(DnDListItem.FLAVOR);
JList list = (JList) support.getComponent();
DefaultListModel model = (DefaultListModel) list.getModel();
for (int i = 0; i <= importIndex; i++) {
if (ComparatorUtils.equals(item,model.getElementAt(i))) {
importIndex--;
break;
}
}
model.removeElement(item);
model.insertElementAt(item, importIndex);
updateWidgetListener(creator);
} catch (UnsupportedFlavorException e) {
return false;
} catch (java.io.IOException e) {
return false;
}
return true;
}
@Override
public NameableCreator[] createNameableCreators() {
return new NameableCreator[]{
new EventCreator(Widget.EVENT_STATECHANGE, WidgetEventListenerUpdatePane.class)
};
}
public static class DnDListItem implements Transferable {
private NameObject no;
public static final DataFlavor FLAVOR = new DataFlavor(DnDListItem.class, "DnDListItem.class");
public DnDListItem(NameObject no) {
this.no = no;
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] { FLAVOR };
}
@Override
/**
*是否支持 dataFlavor
*@param DataFlavor类
*@return 支持返回true
*/
public boolean isDataFlavorSupported(DataFlavor flavor) {
if (ComparatorUtils.equals(flavor,FLAVOR)) {
return true;
}
return false;
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (ComparatorUtils.equals(flavor,FLAVOR)) {
return no;
}
return null;
}
}
@Override
public void saveSettings() {
if (isPopulating) {
return;
}
updateWidgetListener(creator);
}
}

9
designer_form/src/com/fr/design/mainframe/JForm.java

@ -221,14 +221,19 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm {
}
});
formDesign.addDesignerEditListener(new DesignerEditListener() {
private XComponent lastAffectedCreator;
@Override
public void fireCreatorModified(DesignerEvent evt) {
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_CUTED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED) {
setPropertyPaneChange(formDesign.getRootComponent());
} else if (evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) {
setPropertyPaneChange(evt.getAffectedCreator());
// 防止多次触发
if (lastAffectedCreator != null && lastAffectedCreator == evt.getAffectedCreator()) {
return;
}
lastAffectedCreator = evt.getAffectedCreator();
setPropertyPaneChange(lastAffectedCreator);
}
}
});

21
designer_form/src/com/fr/design/mainframe/WidgetPropertyPane.java

@ -4,10 +4,7 @@ import com.fr.base.BaseUtils;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.designer.beans.events.DesignerEditListener;
import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWParameterLayout;
import com.fr.design.designer.creator.*;
import com.fr.design.designer.properties.EventPropertyTable;
import com.fr.design.designer.properties.WidgetPropertyTable;
import com.fr.design.fun.WidgetPropertyUIProvider;
@ -130,9 +127,6 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
private void createEventTable() {
eventTable = new EventPropertyTable(designer);
designer.addDesignerEditListener(new EventPropertyDesignerAdapter(eventTable));
eventTable.setBorder(null);
esp = new UIScrollPane(eventTable); //用来装载事件table
esp.setBorder(null);
}
/**
@ -242,7 +236,7 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
tabbedPane.setBorder(null);
tabbedPane.setTabPlacement(SwingConstants.BOTTOM);
tabbedPane.addTab(Inter.getLocText("FR-Designer_Properties"), psp);
tabbedPane.addTab(Inter.getLocText("FR-Designer_Event"), esp);
tabbedPane.addTab(Inter.getLocText("FR-Designer_Event"), eventTable);
tabbedPane.addTab(Inter.getLocText("FR-Widget_Mobile_Terminal"), wsp);
}
@ -314,6 +308,7 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
*/
private class EventPropertyDesignerAdapter implements DesignerEditListener {
EventPropertyTable propertyTable;
private XComponent lastAffectedCreator;
EventPropertyDesignerAdapter(EventPropertyTable eventTable) {
this.propertyTable = eventTable;
@ -321,8 +316,14 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
@Override
public void fireCreatorModified(DesignerEvent evt) {
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) {
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED) {
propertyTable.refresh();
} else if (evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) {
// 防止多次触发
if (lastAffectedCreator != null && lastAffectedCreator == evt.getAffectedCreator()) {
return;
}
lastAffectedCreator = evt.getAffectedCreator();
propertyTable.refresh();
}
}

Loading…
Cancel
Save