From dd1bfadd21d82ace400e84677c315735b78ef614 Mon Sep 17 00:00:00 2001 From: plough Date: Tue, 1 Aug 2017 21:28:12 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-3163=20=E5=90=88=E4=BD=9C=E5=BC=80?= =?UTF-8?q?=E5=8F=919.0=E8=AE=BE=E8=AE=A1=E5=99=A8=3D>=E6=8E=A7=E4=BB=B6?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=BA=8B=E4=BB=B6=E7=BC=96=E8=BE=91=EF=BC=88?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=EF=BC=89=3D>=E5=88=9D=E6=AD=A5=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/widget/WidgetEventPane.java | 4 +- .../com/fr/design/widget/EventCreator.java | 151 ++++++------- .../properties/EventPropertyTable.java | 208 +++++------------- 3 files changed, 128 insertions(+), 235 deletions(-) rename {designer => designer_base}/src/com/fr/design/widget/EventCreator.java (57%) diff --git a/designer/src/com/fr/design/widget/WidgetEventPane.java b/designer/src/com/fr/design/widget/WidgetEventPane.java index 5d9845c3c..20fd5cc4e 100644 --- a/designer/src/com/fr/design/widget/WidgetEventPane.java +++ b/designer/src/com/fr/design/widget/WidgetEventPane.java @@ -35,7 +35,7 @@ public class WidgetEventPane extends ObjectUIControlPane { */ public NameableCreator[] createNameableCreators() { return new NameableCreator[]{ - EventCreator.STATECHANGE + new EventCreator(Widget.EVENT_STATECHANGE, WidgetEventListenerUpdatePane.class) }; } @@ -108,7 +108,7 @@ public class WidgetEventPane extends ObjectUIControlPane { return; } - this.refreshNameableCreator(EventCreator.createEventCreator(widget.supportedEvents())); + this.refreshNameableCreator(EventCreator.createEventCreator(widget.supportedEvents(), WidgetEventListenerUpdatePane.class)); List list = new ArrayList(); Listener listener; diff --git a/designer/src/com/fr/design/widget/EventCreator.java b/designer_base/src/com/fr/design/widget/EventCreator.java similarity index 57% rename from designer/src/com/fr/design/widget/EventCreator.java rename to designer_base/src/com/fr/design/widget/EventCreator.java index 3826d7b6f..530bd34aa 100644 --- a/designer/src/com/fr/design/widget/EventCreator.java +++ b/designer_base/src/com/fr/design/widget/EventCreator.java @@ -1,76 +1,77 @@ -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 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 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); + } + + +// 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; + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/properties/EventPropertyTable.java b/designer_form/src/com/fr/design/designer/properties/EventPropertyTable.java index bec1b44f8..4fd1a8fab 100644 --- a/designer_form/src/com/fr/design/designer/properties/EventPropertyTable.java +++ b/designer_form/src/com/fr/design/designer/properties/EventPropertyTable.java @@ -3,6 +3,9 @@ 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.ShortCut4JControlPane; +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; @@ -12,6 +15,7 @@ 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; @@ -39,11 +43,11 @@ 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 JNameEdList nameableList; +// private JNameEdList nameableList; private ToolBarDef toolbarDef; private AddItemMenuDef itemMenu; private ShortCut editItemAction; @@ -59,27 +63,22 @@ public class EventPropertyTable extends BasicPane { 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); - + @Override + protected void initComponentPane() { toolbarDef = new ToolBarDef(); - shorts = new ShortCut[] { itemMenu = new AddItemMenuDef(), editItemAction = new EditItemMenuDef(), - copyItemAction = new CopyItemAction(), removeItemAction = new RemoveItemAction() }; +// shorts = new ShortCut[] { itemMenu = new AddItemMenuDef(), editItemAction = new EditItemMenuDef(), +// copyItemAction = new CopyItemAction(), removeItemAction = new RemoveItemAction() }; + shorts = new ShortCut[] { itemMenu = new AddItemMenuDef()}; for (ShortCut sj : shorts) { toolbarDef.addShortCut(sj); } toolbar = ToolBarDef.createJToolBar(); toolbarDef.updateToolBar(toolbar); - this.add(toolbar, BorderLayout.NORTH); + + super.initComponentPane(); + } + + protected void initComponents() { } /** @@ -110,74 +109,41 @@ public class EventPropertyTable extends BasicPane { 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); - } + public static class WidgetEventListenerUpdatePane extends ListenerUpdatePane { - 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); - } - } - }; + protected JavaScriptActionPane createJavaScriptActionPane() { + return new JavaScriptActionPane() { - private void showEventPane(final NameObject object) { - if (listenerPane == null) { - listenerPane = new ListenerUpdatePane() { + @Override + protected DBManipulationPane createDBManipulationPane() { + return new DBManipulationPane(ValueEditorPaneFactory.formEditors()); + } @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 String title4PopupWindow() { + return Inter.getLocText("Set_Callback_Function"); + } + @Override + protected EmailPane initEmaiPane() { + return new FormEmailPane(); } @Override - protected boolean supportCellAction() { - return false; + public boolean isForm() { + return true; + } + + protected String[] getDefaultArgs() { + return new String[0]; } - + }; } - 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); + + @Override + protected boolean supportCellAction() { + return false; + } } private class NameableListCellRenderer extends DefaultListCellRenderer { @@ -226,20 +192,6 @@ public class EventPropertyTable extends BasicPane { } } } - - 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) { return Inter.getLocText("Event-" + eventName); @@ -261,7 +213,7 @@ public class EventPropertyTable extends BasicPane { } Widget widget = creator.toData(); - refreshNameableCreator(widget.supportedEvents()); + refreshNameableCreator(EventCreator.createEventCreator(widget.supportedEvents(), WidgetEventListenerUpdatePane.class)); ((DefaultListModel) nameableList.getModel()).removeAllElements(); for (int i = 0, size = widget.getListenerSize(); i < size; i++) { @@ -288,81 +240,21 @@ public class EventPropertyTable extends BasicPane { 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; - } - } + @Override + public NameableCreator[] createNameableCreators() { + return new NameableCreator[]{ + new EventCreator(Widget.EVENT_STATECHANGE, WidgetEventListenerUpdatePane.class) + }; + } - if (!repeated) { - return name_test; - } + @Override + public void saveSettings() { - count++; - } } private class DnDTransferHandler extends TransferHandler {