From e8e8b62dfbfd8769c3b63ca78c5dd535613322dd Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Mon, 3 Jul 2017 12:45:53 +0300 Subject: Add editor open event to Grid Editor (#9623) Fixes #9596 --- .../java/com/vaadin/ui/components/grid/Editor.java | 11 ++++ .../com/vaadin/ui/components/grid/EditorImpl.java | 8 +++ .../vaadin/ui/components/grid/EditorOpenEvent.java | 74 ++++++++++++++++++++++ .../ui/components/grid/EditorOpenListener.java | 44 +++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/EditorOpenEvent.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/EditorOpenListener.java (limited to 'server') diff --git a/server/src/main/java/com/vaadin/ui/components/grid/Editor.java b/server/src/main/java/com/vaadin/ui/components/grid/Editor.java index 0eff213c7e..26ef8101ab 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/Editor.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/Editor.java @@ -176,6 +176,17 @@ public interface Editor extends Serializable { */ public Registration addCancelListener(EditorCancelListener listener); + /** + * Adds an editor open {@code listener}. + * + * @param listener + * open listener + * @return a registration object for removing the listener + * + * @since 8.1 + */ + public Registration addOpenListener(EditorOpenListener listener); + /** * Gets the Grid instance which this editor belongs to. * diff --git a/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java b/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java index 07b792a221..502f530d9a 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java @@ -238,6 +238,8 @@ public class EditorImpl extends AbstractGridExtension getState().columnFields.put(getInternalIdForColumn(c), component.getConnectorId()); }); + + eventRouter.fireEvent(new EditorOpenEvent(this, edited)); } @Override @@ -345,6 +347,12 @@ public class EditorImpl extends AbstractGridExtension EditorCancelListener.class.getDeclaredMethods()[0]); } + @Override + public Registration addOpenListener(EditorOpenListener listener) { + return eventRouter.addListener(EditorOpenEvent.class, listener, + EditorOpenListener.class.getDeclaredMethods()[0]); + } + @Override public Grid getGrid() { return getParent(); diff --git a/server/src/main/java/com/vaadin/ui/components/grid/EditorOpenEvent.java b/server/src/main/java/com/vaadin/ui/components/grid/EditorOpenEvent.java new file mode 100644 index 0000000000..70e0423991 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/EditorOpenEvent.java @@ -0,0 +1,74 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.ui.components.grid; + +import java.util.EventObject; + +import com.vaadin.ui.Grid; + +/** + * An event that is fired when a Grid editor is opened. + * + * @author Vaadin Ltd + * @since 8.1 + * + * @see EditorOpenListener + * @see Editor#addOpenListener(EditorOpenListener) + * + * @param + * the bean type + */ +public class EditorOpenEvent extends EventObject { + + private T bean; + + /** + * Constructor for a editor open event. + * + * @param editor + * the source of the event + * @param bean + * the bean being edited + */ + public EditorOpenEvent(Editor editor, T bean) { + super(editor); + this.bean = bean; + } + + @SuppressWarnings("unchecked") + @Override + public Editor getSource() { + return (Editor) super.getSource(); + } + + /** + * Gets the editors' grid. + * + * @return the editors' grid + */ + public Grid getGrid() { + return getSource().getGrid(); + } + + /** + * Gets the bean being edited. + * + * @return the bean being edited + */ + public T getBean() { + return bean; + } +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/EditorOpenListener.java b/server/src/main/java/com/vaadin/ui/components/grid/EditorOpenListener.java new file mode 100644 index 0000000000..071ed0549a --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/EditorOpenListener.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.ui.components.grid; + +import java.io.Serializable; + +import com.vaadin.ui.Grid; + +/** + * An event listener for a {@link Grid} editor save events. + * + * @author Vaadin Ltd + * @since 8.1 + * + * @param + * the bean type + * + * @see EditorOpenEvent + * @see Editor#addOpenListener(EditorOpenListener) + */ +@FunctionalInterface +public interface EditorOpenListener extends Serializable { + + /** + * Called when the editor is opened. + * + * @param event + * open event + */ + public void onEditorOpen(EditorOpenEvent event); +} -- cgit v1.2.3