diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-07-03 12:45:53 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-07-03 12:45:53 +0300 |
commit | e8e8b62dfbfd8769c3b63ca78c5dd535613322dd (patch) | |
tree | 4ace36230e57109110aa7c671db09cb4926c6185 /server | |
parent | dde0f91af4a21ae9a1d141bed46e3030abc2c2d9 (diff) | |
download | vaadin-framework-e8e8b62dfbfd8769c3b63ca78c5dd535613322dd.tar.gz vaadin-framework-e8e8b62dfbfd8769c3b63ca78c5dd535613322dd.zip |
Add editor open event to Grid Editor (#9623)
Fixes #9596
Diffstat (limited to 'server')
4 files changed, 137 insertions, 0 deletions
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 @@ -177,6 +177,17 @@ public interface Editor<T> extends Serializable { public Registration addCancelListener(EditorCancelListener<T> 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<T> listener); + + /** * Gets the Grid instance which this editor belongs to. * * @return the grid which owns the editor 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<T> extends AbstractGridExtension<T> getState().columnFields.put(getInternalIdForColumn(c), component.getConnectorId()); }); + + eventRouter.fireEvent(new EditorOpenEvent<T>(this, edited)); } @Override @@ -346,6 +348,12 @@ public class EditorImpl<T> extends AbstractGridExtension<T> } @Override + public Registration addOpenListener(EditorOpenListener<T> listener) { + return eventRouter.addListener(EditorOpenEvent.class, listener, + EditorOpenListener.class.getDeclaredMethods()[0]); + } + + @Override public Grid<T> 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 <T> + * the bean type + */ +public class EditorOpenEvent<T> 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<T> editor, T bean) { + super(editor); + this.bean = bean; + } + + @SuppressWarnings("unchecked") + @Override + public Editor<T> getSource() { + return (Editor<T>) super.getSource(); + } + + /** + * Gets the editors' grid. + * + * @return the editors' grid + */ + public Grid<T> 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 <T> + * the bean type + * + * @see EditorOpenEvent + * @see Editor#addOpenListener(EditorOpenListener) + */ +@FunctionalInterface +public interface EditorOpenListener<T> extends Serializable { + + /** + * Called when the editor is opened. + * + * @param event + * open event + */ + public void onEditorOpen(EditorOpenEvent<T> event); +} |