MoMeak 7 years ago
parent
commit
d637e17b9a
  1. 35
      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. 6
      designer_base/src/com/fr/design/locale/designer.properties
  6. 1
      designer_base/src/com/fr/design/locale/designer_en_US.properties
  7. 25
      designer_base/src/com/fr/design/locale/designer_ja_JP.properties
  8. 25
      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. 6
      designer_base/src/com/fr/design/locale/designer_zh_TW.properties
  11. 3
      designer_base/src/com/fr/design/mainframe/JTemplate.java
  12. 28
      designer_base/src/com/fr/design/widget/EventCreator.java
  13. 389
      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

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

@ -4,10 +4,13 @@ package com.fr.design.widget;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.DBManipulationPane;
import com.fr.design.write.submit.SmartInsertDBManipulationInWidgetEventPane; import com.fr.design.write.submit.SmartInsertDBManipulationInWidgetEventPane;
import com.fr.design.gui.controlpane.NameableCreator; 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.gui.frpane.ListenerUpdatePane;
import com.fr.design.javascript.JavaScriptActionPane; import com.fr.design.javascript.JavaScriptActionPane;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
@ -15,30 +18,45 @@ import com.fr.design.mainframe.ElementCasePane;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.form.event.Listener; import com.fr.form.event.Listener;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import com.fr.general.FRLogger;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.general.NameObject; 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; import com.fr.stable.Nameable;
public class WidgetEventPane extends ObjectJControlPane { public class WidgetEventPane extends ObjectUIControlPane {
public WidgetEventPane() {
this(null);
}
public WidgetEventPane(ElementCasePane pane) { public WidgetEventPane(ElementCasePane pane) {
super(pane); super(pane);
this.setNameListEditable(false); this.setNameListEditable(false);
} }
@Override
public String getAddItemText() {
return Inter.getLocText("FR-Designer_Add_Event");
}
/** /**
* 生成添加按钮的NameableCreator * 生成添加按钮的NameableCreator
* @return 按钮的NameableCreator * @return 按钮的NameableCreator
*/ */
public NameableCreator[] createNameableCreators() { public NameableCreator[] createNameableCreators() {
return new NameableCreator[]{ return new NameableCreator[]{
EventCreator.STATECHANGE new EventCreator(Widget.EVENT_STATECHANGE, WidgetEventListenerUpdatePane.class)
}; };
} }
@Override
public void saveSettings() {
CellWidgetPropertyPane.getInstance().update();
}
@Override @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return Inter.getLocText("Event"); return Inter.getLocText("Event");
@ -46,9 +64,6 @@ public class WidgetEventPane extends ObjectJControlPane {
public static class WidgetEventListenerUpdatePane extends ListenerUpdatePane { public static class WidgetEventListenerUpdatePane extends ListenerUpdatePane {
private ElementCasePane epane; private ElementCasePane epane;
public WidgetEventListenerUpdatePane() {
this(null);
}
public WidgetEventListenerUpdatePane(ElementCasePane epane){ public WidgetEventListenerUpdatePane(ElementCasePane epane){
this.epane = epane; this.epane = epane;
super.initComponents(); super.initComponents();
@ -104,7 +119,7 @@ public class WidgetEventPane extends ObjectJControlPane {
return; return;
} }
this.refreshNameableCreator(EventCreator.createEventCreator(widget.supportedEvents())); this.refreshNameableCreator(EventCreator.createEventCreator(widget.supportedEvents(), WidgetEventListenerUpdatePane.class));
List<NameObject> list = new ArrayList<NameObject>(); List<NameObject> list = new ArrayList<NameObject>();
Listener listener; 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 ToolBarDef toolbarDef;
private UIToolbar toolBar; private UIToolbar toolBar;
private UIToolbar topToolBar;
protected PopupEditDialog popupEditDialog; protected PopupEditDialog popupEditDialog;
// peter:这是整体的一个cardLayout Pane // peter:这是整体的一个cardLayout Pane
protected CardLayout cardLayout; protected CardLayout cardLayout;
@ -146,7 +147,7 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH
// leftContentPane.setBorder(BorderFactory.createLineBorder(new Color(201, 198, 184))); // leftContentPane.setBorder(BorderFactory.createLineBorder(new Color(201, 198, 184)));
// 顶部标签及add按钮 // 顶部标签及add按钮
UIToolbar topToolBar = new UIToolbar(); topToolBar = new UIToolbar();
topToolBar.setLayout(new BorderLayout()); topToolBar.setLayout(new BorderLayout());
ShortCut addItem = addItemShortCut().getShortCut(); ShortCut addItem = addItemShortCut().getShortCut();
addItem.intoJToolBar(topToolBar); addItem.intoJToolBar(topToolBar);
@ -246,19 +247,27 @@ public abstract class UIControlPane extends BasicPane implements UnrepeatedNameH
toolbarDef.updateToolBar(toolBar); toolbarDef.updateToolBar(toolBar);
toolBar.validate(); toolBar.validate();
toolBar.repaint(); toolBar.repaint();
// 顶部按钮
topToolBar.removeAll();
ShortCut addItem = addItemShortCut().getShortCut();
addItem.intoJToolBar(topToolBar);
topToolBar.validate();
this.repaint(); this.repaint();
} }
// 点击"编辑"按钮,弹出面板 // 点击"编辑"按钮,弹出面板
protected class PopupEditDialog extends JDialog { protected class PopupEditDialog extends JDialog {
private JComponent editPane; private JComponent editPane;
private static final int WIDTH = 490; private static final int WIDTH = 570;
private static final int HEIGHT = 570; private static final int HEIGHT = 490;
PopupEditDialog(JComponent pane) { PopupEditDialog(JComponent pane) {
super(DesignerContext.getDesignerFrame()); super(DesignerContext.getDesignerFrame());
setUndecorated(true); setUndecorated(true);
pane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); pane.setBorder(BorderFactory.createEmptyBorder(20, 10, 10, 10));
this.editPane = pane; this.editPane = pane;
this.getContentPane().add(editPane, BorderLayout.CENTER); this.getContentPane().add(editPane, BorderLayout.CENTER);
setSize(WIDTH, HEIGHT); 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)); listModel.addElement(new ListModelElement(aNameableArray));
} }
if (listModel.size() > 0) { if (listModel.size() > 0 || this.nameableList.getSelectedIndex() != 0) {
this.nameableList.setSelectedIndex(0); this.nameableList.setSelectedIndex(0);
} }
this.checkButtonEnabled(); this.checkButtonEnabled();

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

@ -2095,10 +2095,12 @@ FR-Designer_CellElement_Property_Table=CellElement_Property_Table
FR-Designer_T_Insert_Float=Insert_Float FR-Designer_T_Insert_Float=Insert_Float
FR-Designer_Add_FloatElement=Add_FloatElement FR-Designer_Add_FloatElement=Add_FloatElement
FR-Designer_Insert_Image=Insert_Image FR-Designer_Insert_Image=Insert_Image
FR-Designer_Insert-Chart=Insert-Chart
FR-Designer_Insert-Text=Insert-Text
FR-Designer_Insert_Formula=Insert_Formula FR-Designer_Insert_Formula=Insert_Formula
FR-Designer_Scale_Down=Scale_Down FR-Designer_Scale_Down=Scale_Down
FR-Designer_Scale_Up=Scale_Up FR-Designer_Scale_Up=Scale_Up
FR-Designer_Scale_Slider=Scale_Slider FR-Designer_Scale_Slider=Scale_Slider
FR-Designer_Scale_Grade=Scale_Grade FR-Designer_Scale_Grade=Scale_Grade
FR-Designer_Insert_Chart=Insert_Chart
FR-Designer_Insert_Text=Insert_Text
FR-Designer_Double=Double
FR-Designer_Add_Event=Add Event

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

@ -2103,3 +2103,4 @@ FR-Designer_Scale_Down=Scale_Down
FR-Designer_Scale_Up=Scale_Up FR-Designer_Scale_Up=Scale_Up
FR-Designer_Scale_Slider=Scale_Slider FR-Designer_Scale_Slider=Scale_Slider
FR-Designer_Scale_Grade=Scale_Grade FR-Designer_Scale_Grade=Scale_Grade
FR-Designer_Add_Event=Add Event

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

@ -2084,3 +2084,28 @@ FR-Designer_Scale_Down=
FR-Designer_Scale_Up= FR-Designer_Scale_Up=
FR-Designer_Scale_Slider= FR-Designer_Scale_Slider=
FR-Designer_Scale_Grade= FR-Designer_Scale_Grade=
FR-Designer_AlphaFine_Enable=
FR-Designer_AlphaFine_EnableAlphaFine=
FR-Designer_AlphaFine_EnableInternet=
FR-Designer_AlphaFine_EnableInternetSearch=
FR-Designer_AlphaFine_Shortcut_Config=
FR-Designer_AlphaFine_SearchRange=
FR-Designer_AlphaFine_Recommend=
FR-Designer-Plugin_Addon=
FR-Designer_Templates=
FR-Designer_Templates_Content=
FR-Designer_AlphaFine_ShowAll=
FR-Designer_AlphaFine_Latest=
FR-Designer_AlphaFine_ShowLess=
FR-Designer_AlphaFine=
FR-Designer-Alphafine_No_Remind=
FR-Designer_AlphaFine_NoResult=
FR-Designer_ConnectionFailed=
FR-Designer_NoResult=
FR-Designer-AlphaFine_SetShortcuts=
FR-Designer_Write_Enhance_Preview=
FR-Designer-StyleAlignment_Style_PartSpacing=
FR-Designer_Use_Params_Template=
FR-Designer_Label_Name=
FR-Designer_Insert_Formula=
FR-Designer_Add_Event=

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

@ -2083,3 +2083,28 @@ FR-Designer_Scale_Down=
FR-Designer_Scale_Up= FR-Designer_Scale_Up=
FR-Designer_Scale_Slider= FR-Designer_Scale_Slider=
FR-Designer_Scale_Grade= FR-Designer_Scale_Grade=
FR-Designer_AlphaFine_Enable=
FR-Designer_AlphaFine_EnableAlphaFine=
FR-Designer_AlphaFine_EnableInternet=
FR-Designer_AlphaFine_EnableInternetSearch=
FR-Designer_AlphaFine_Shortcut_Config=
FR-Designer_AlphaFine_SearchRange=
FR-Designer_AlphaFine_Recommend=
FR-Designer-Plugin_Addon=
FR-Designer_Templates=
FR-Designer_Templates_Content=
FR-Designer_AlphaFine_ShowAll=
FR-Designer_AlphaFine_Latest=
FR-Designer_AlphaFine_ShowLess=
FR-Designer_AlphaFine=
FR-Designer-Alphafine_No_Remind=
FR-Designer_AlphaFine_NoResult=
FR-Designer_ConnectionFailed=
FR-Designer_NoResult=
FR-Designer-AlphaFine_SetShortcuts=
FR-Designer_Write_Enhance_Preview=
FR-Designer_Scale_customButton=
FR-Designer-StyleAlignment_Style_PartSpacing=
FR-Designer_Use_Params_Template=
FR-Designer_Label_Name=
FR-Designer_Add_Event=

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

@ -2101,6 +2101,7 @@ FR-Designer_Insert_Image=\u63D2\u5165\u56FE\u7247
FR-Designer_Insert_Chart=\u63D2\u5165\u56FE\u8868 FR-Designer_Insert_Chart=\u63D2\u5165\u56FE\u8868
FR-Designer_Insert_Text=\u63D2\u5165\u666E\u901A\u6587\u672C FR-Designer_Insert_Text=\u63D2\u5165\u666E\u901A\u6587\u672C
FR-Designer_Insert_Formula=\u63D2\u5165\u516C\u5F0F FR-Designer_Insert_Formula=\u63D2\u5165\u516C\u5F0F
FR-Designer_Add_Event=\u6DFB\u52A0\u4E8B\u4EF6
FR-Designer_Cell_Visible=\u5355\u5143\u683C\u53EF\u89C1 FR-Designer_Cell_Visible=\u5355\u5143\u683C\u53EF\u89C1
FR-Designer_Float_Visible=\u60AC\u6D6E\u5143\u7D20\u53EF\u89C1 FR-Designer_Float_Visible=\u60AC\u6D6E\u5143\u7D20\u53EF\u89C1
FR-Designer_Cell_Value=\u5355\u5143\u683C\u503C FR-Designer_Cell_Value=\u5355\u5143\u683C\u503C

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

@ -2102,3 +2102,9 @@ FR-Designer_Scale_Down=
FR-Designer_Scale_Up= FR-Designer_Scale_Up=
FR-Designer_Scale_Slider= FR-Designer_Scale_Slider=
FR-Designer_Scale_Grade= FR-Designer_Scale_Grade=
FR-Designer_AlphaFine_EnableInternet=
FR-Designer_Scale_EnlargeOrReduce=
FR-Designer-StyleAlignment_Style_PartSpacing=
FR-Designer_Use_Params_Template=
FR-Designer_Label_Name=
FR-Designer_Add_Event=

3
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; return;
} }
long saveTime = System.currentTimeMillis(); // 保存模板的时间点 long saveTime = System.currentTimeMillis(); // 保存模板的时间点
try {
tic.collectInfo(template, this, openTime, saveTime); tic.collectInfo(template, this, openTime, saveTime);
} catch (Throwable th) { // 不管收集过程中出现任何异常,都不应该影响模版保存
}
openTime = saveTime; // 更新 openTime,准备下一次计算 openTime = saveTime; // 更新 openTime,准备下一次计算
} }

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

@ -1,6 +1,7 @@
package com.fr.design.widget; package com.fr.design.widget;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.controlpane.NameableSelfCreator; import com.fr.design.gui.controlpane.NameableSelfCreator;
import com.fr.design.gui.controlpane.UnrepeatedNameHelper; import com.fr.design.gui.controlpane.UnrepeatedNameHelper;
import com.fr.design.gui.ilist.ListModelElement; import com.fr.design.gui.ilist.ListModelElement;
@ -14,8 +15,8 @@ import com.fr.stable.Nameable;
public class EventCreator extends NameableSelfCreator { public class EventCreator extends NameableSelfCreator {
private String eventName; private String eventName;
public EventCreator(String eventName) { public EventCreator(String eventName, Class<? extends BasicBeanPane> updatePane) {
super(switchLang(eventName), Listener.class, WidgetEventPane.WidgetEventListenerUpdatePane.class); super(switchLang(eventName), Listener.class, updatePane);
this.eventName = eventName; this.eventName = eventName;
} }
@ -24,11 +25,11 @@ public class EventCreator extends NameableSelfCreator {
return new NameObject(helper.createUnrepeatedName(this.menuName()),new Listener(this.eventName)) ; return new NameObject(helper.createUnrepeatedName(this.menuName()),new Listener(this.eventName)) ;
} }
public static EventCreator[] createEventCreator(String[] supportedEvents) { public static EventCreator[] createEventCreator(String[] supportedEvents, Class<? extends BasicBeanPane> updatePane) {
EventCreator[] creators = new EventCreator[supportedEvents.length]; EventCreator[] creators = new EventCreator[supportedEvents.length];
for (int i = 0; i < supportedEvents.length; i++) { for (int i = 0; i < supportedEvents.length; i++) {
creators[i] = new EventCreator(supportedEvents[i]); creators[i] = new EventCreator(supportedEvents[i], updatePane);
} }
return creators; return creators;
@ -50,25 +51,6 @@ public class EventCreator extends NameableSelfCreator {
((NameObject)wrapper.wrapper).setObject(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 @Override
public String createTooltip() { public String createTooltip() {
return null; return null;

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

@ -1,142 +1,45 @@
package com.fr.design.designer.properties; package com.fr.design.designer.properties;
import com.fr.base.BaseUtils; import com.fr.design.gui.controlpane.NameableCreator;
import com.fr.base.FRContext; import com.fr.design.gui.controlpane.UIListControlPane;
import com.fr.design.actions.UpdateAction;
import com.fr.design.gui.frpane.ListenerUpdatePane; 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.EmailPane;
import com.fr.design.javascript.JavaScriptActionPane; import com.fr.design.javascript.JavaScriptActionPane;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormDesigner;
import com.fr.design.menu.MenuDef; import com.fr.design.widget.EventCreator;
import com.fr.design.menu.ShortCut;
import com.fr.design.menu.ToolBarDef;
import com.fr.design.write.submit.DBManipulationPane; 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.editor.ValueEditorPaneFactory;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.form.event.Listener; import com.fr.form.event.Listener;
import com.fr.design.form.javascript.FormEmailPane; import com.fr.design.form.javascript.FormEmailPane;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.general.NameObject; import com.fr.general.NameObject;
import com.fr.js.JavaScriptImpl;
import com.fr.stable.Nameable; import com.fr.stable.Nameable;
import com.fr.design.utils.gui.GUICoreUtils;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.util.ArrayList;
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;
public class EventPropertyTable extends BasicPane { public class EventPropertyTable extends UIListControlPane {
private ShortCut[] shorts;
private XCreator creator; 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; private FormDesigner designer;
public EventPropertyTable(FormDesigner designer) { public EventPropertyTable(FormDesigner designer) {
super(); super();
this.designer = designer; this.designer = designer;
this.initComponents();
} }
protected void initComponents() {
this.setLayout(new BorderLayout());
nameableList = new JNameEdList(new DefaultListModel());
this.add(new JScrollPane(nameableList), BorderLayout.CENTER);
nameableList.setCellRenderer(new NameableListCellRenderer());
nameableList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
nameableList.addMouseListener(listMouseListener);
nameableList.setTransferHandler(new DnDTransferHandler());
nameableList.setDropMode(DropMode.INSERT);
nameableList.setDragEnabled(true);
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 @Override
public void mouseReleased(MouseEvent evt) { public String getAddItemText() {
checkButtonEnabled(); return Inter.getLocText("FR-Designer_Add_Event");
if (evt.getClickCount() >= 2 && SwingUtilities.isLeftMouseButton(evt)) {
NameObject object = (NameObject) nameableList.getSelectedValue();
showEventPane(object);
}
} }
};
private void showEventPane(final NameObject object) { public static class WidgetEventListenerUpdatePane extends ListenerUpdatePane {
if (listenerPane == null) {
listenerPane = new ListenerUpdatePane() {
@Override @Override
protected JavaScriptActionPane createJavaScriptActionPane() { protected JavaScriptActionPane createJavaScriptActionPane() {
return new JavaScriptActionPane() { return new JavaScriptActionPane() {
@Override @Override
protected DBManipulationPane createDBManipulationPane() { protected DBManipulationPane createDBManipulationPane() {
return new DBManipulationPane(ValueEditorPaneFactory.formEditors()); return new DBManipulationPane(ValueEditorPaneFactory.formEditors());
@ -161,84 +64,11 @@ public class EventPropertyTable extends BasicPane {
}; };
} }
@Override @Override
protected boolean supportCellAction() { protected boolean supportCellAction() {
return false; return false;
} }
};
}
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 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());
}
}
} }
private String switchLang(String eventName) { private String switchLang(String eventName) {
@ -261,15 +91,16 @@ public class EventPropertyTable extends BasicPane {
} }
Widget widget = creator.toData(); 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++) { for (int i = 0, size = widget.getListenerSize(); i < size; i++) {
Listener listener = widget.getListener(i); Listener listener = widget.getListener(i);
if (!listener.isDefault()) { 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(); checkButtonEnabled();
this.repaint(); this.repaint();
} }
@ -279,204 +110,34 @@ public class EventPropertyTable extends BasicPane {
* @param creator 控件 * @param creator 控件
*/ */
public void updateWidgetListener(XCreator creator) { public void updateWidgetListener(XCreator creator) {
DefaultListModel listModel = (DefaultListModel) this.nameableList.getModel();
(creator.toData()).clearListeners(); (creator.toData()).clearListeners();
for (int i = 0, len = listModel.getSize(); i < len; i++) { Nameable[] res = this.update();
(creator.toData()).addListener((Listener) ((NameObject) listModel.getElementAt(i)).getObject()); for (int i = 0; i < res.length; i++) {
NameObject nameObject = (NameObject)res[i];
(creator.toData()).addListener((Listener) nameObject.getObject());
} }
designer.fireTargetModified(); designer.fireTargetModified();
checkButtonEnabled(); 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 @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return "Event"; 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 @Override
public int getSourceActions(JComponent comp) { public NameableCreator[] createNameableCreators() {
return action; return new NameableCreator[]{
} new EventCreator(Widget.EVENT_STATECHANGE, WidgetEventListenerUpdatePane.class)
};
@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 @Override
public boolean importData(TransferHandler.TransferSupport support) { public void saveSettings() {
if (!canImport(support)) { if (isPopulating) {
return false; return;
}
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); updateWidgetListener(creator);
} catch (UnsupportedFlavorException e) {
return false;
} catch (java.io.IOException e) {
return false;
}
return true;
}
}
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;
}
} }
} }

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() { formDesign.addDesignerEditListener(new DesignerEditListener() {
private XComponent lastAffectedCreator;
@Override @Override
public void fireCreatorModified(DesignerEvent evt) { public void fireCreatorModified(DesignerEvent evt) {
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_CUTED if (evt.getCreatorEventID() == DesignerEvent.CREATOR_CUTED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED) { || evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED) {
setPropertyPaneChange(formDesign.getRootComponent()); setPropertyPaneChange(formDesign.getRootComponent());
} else if (evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) { } 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.ExtraDesignClassManager;
import com.fr.design.designer.beans.events.DesignerEditListener; import com.fr.design.designer.beans.events.DesignerEditListener;
import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.*;
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.properties.EventPropertyTable; import com.fr.design.designer.properties.EventPropertyTable;
import com.fr.design.designer.properties.WidgetPropertyTable; import com.fr.design.designer.properties.WidgetPropertyTable;
import com.fr.design.fun.WidgetPropertyUIProvider; import com.fr.design.fun.WidgetPropertyUIProvider;
@ -130,9 +127,6 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
private void createEventTable() { private void createEventTable() {
eventTable = new EventPropertyTable(designer); eventTable = new EventPropertyTable(designer);
designer.addDesignerEditListener(new EventPropertyDesignerAdapter(eventTable)); 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.setBorder(null);
tabbedPane.setTabPlacement(SwingConstants.BOTTOM); tabbedPane.setTabPlacement(SwingConstants.BOTTOM);
tabbedPane.addTab(Inter.getLocText("FR-Designer_Properties"), psp); 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); 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 { private class EventPropertyDesignerAdapter implements DesignerEditListener {
EventPropertyTable propertyTable; EventPropertyTable propertyTable;
private XComponent lastAffectedCreator;
EventPropertyDesignerAdapter(EventPropertyTable eventTable) { EventPropertyDesignerAdapter(EventPropertyTable eventTable) {
this.propertyTable = eventTable; this.propertyTable = eventTable;
@ -321,8 +316,14 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
@Override @Override
public void fireCreatorModified(DesignerEvent evt) { public void fireCreatorModified(DesignerEvent evt) {
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED if (evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED) {
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) { propertyTable.refresh();
} else if (evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) {
// 防止多次触发
if (lastAffectedCreator != null && lastAffectedCreator == evt.getAffectedCreator()) {
return;
}
lastAffectedCreator = evt.getAffectedCreator();
propertyTable.refresh(); propertyTable.refresh();
} }
} }

Loading…
Cancel
Save