mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-03 03:38:33 +08:00
delete action
This commit is contained in:
parent
731ae33690
commit
16f40b35fa
@ -52,6 +52,7 @@ public class DataServiceBean implements DataService, DataServiceRemote
|
||||
for (Entity entity : context.getRemoveInstances()) {
|
||||
Entity e = em.merge(entity);
|
||||
em.remove(e);
|
||||
res.put(entity, e);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -473,5 +473,5 @@ public abstract class WindowManager {
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public abstract void showMessageDialog(String title, String message, IFrame.MessageType messageType);
|
||||
public abstract Action showOptionDialog(String title, String message, IFrame.MessageType messageType, Action[] actions);
|
||||
public abstract void showOptionDialog(String title, String message, IFrame.MessageType messageType, Action[] actions);
|
||||
}
|
||||
|
@ -138,8 +138,8 @@ public class AbstractFrame implements IFrame, Component.Wrapper {
|
||||
frame.showMessageDialog(title, message, messageType);
|
||||
}
|
||||
|
||||
public Action showOptionDialog(String title, String message, MessageType messageType, Action[] actions) {
|
||||
return frame.showOptionDialog(title, message, messageType, actions);
|
||||
public void showOptionDialog(String title, String message, MessageType messageType, Action[] actions) {
|
||||
frame.showOptionDialog(title, message, messageType, actions);
|
||||
}
|
||||
|
||||
public boolean close(String actionId) {
|
||||
@ -151,10 +151,9 @@ public class AbstractFrame implements IFrame, Component.Wrapper {
|
||||
}
|
||||
|
||||
public <A extends IFrame> A getFrame() {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
return (A) this;
|
||||
}
|
||||
|
||||
public void setFrame(IFrame frame) {
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
@ -51,5 +51,5 @@ public interface IFrame extends OrderedLayout, Component.Container, Component.Be
|
||||
}
|
||||
|
||||
void showMessageDialog(String title, String message, MessageType messageType);
|
||||
Action showOptionDialog(String title, String message, MessageType messageType, Action[] actions);
|
||||
void showOptionDialog(String title, String message, MessageType messageType, Action[] actions);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.haulmont.cuba.gui.components;
|
||||
|
||||
import com.haulmont.cuba.gui.WindowManager;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.core.entity.Entity;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
@ -105,9 +106,40 @@ abstract class ListActionsHelper<T extends List> {
|
||||
|
||||
public void actionPerform(Component component) {
|
||||
final Set selected = ListActionsHelper.this.component.getSelected();
|
||||
|
||||
for (Object o : selected) {
|
||||
if (!selected.isEmpty()) {
|
||||
frame.showOptionDialog(
|
||||
"Confirmation",
|
||||
"Are you sure you want to delete selected entities?",
|
||||
IFrame.MessageType.CONFIRMATION,
|
||||
new Action[]{new AbstractAction("ok") {
|
||||
public String getCaption() {
|
||||
return "Ok";
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void actionPerform(Component component) {
|
||||
final CollectionDatasource ds = ListActionsHelper.this.component.getDatasource();
|
||||
for (Object item : selected) {
|
||||
ds.removeItem((Entity) item);
|
||||
}
|
||||
|
||||
ds.commit();
|
||||
}
|
||||
}, new AbstractAction("cancel") {
|
||||
public String getCaption() {
|
||||
return "Cancel";
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void actionPerform(Component component) {
|
||||
}
|
||||
}});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -11,9 +11,9 @@ package com.haulmont.cuba.gui.data.impl;
|
||||
|
||||
import com.haulmont.chile.core.model.Instance;
|
||||
import com.haulmont.chile.core.model.MetaClass;
|
||||
import com.haulmont.cuba.core.entity.Entity;
|
||||
import com.haulmont.cuba.core.global.DataServiceRemote;
|
||||
import com.haulmont.cuba.core.global.PersistenceHelper;
|
||||
import com.haulmont.cuba.core.entity.Entity;
|
||||
import com.haulmont.cuba.gui.TemplateHelper;
|
||||
import com.haulmont.cuba.gui.data.*;
|
||||
import com.haulmont.cuba.gui.xml.ParametersHelper;
|
||||
@ -145,11 +145,10 @@ public class CollectionDatasourceImpl<T extends Entity, K>
|
||||
|
||||
if (PersistenceHelper.isNew(item)) {
|
||||
itemToCreate.remove(item);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
itemToDelete.add(item);
|
||||
}
|
||||
|
||||
|
||||
modified = true;
|
||||
forceCollectionChanged(
|
||||
new CollectionDatasourceListener.CollectionOperation<T>(
|
||||
@ -191,6 +190,25 @@ public class CollectionDatasourceImpl<T extends Entity, K>
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit() {
|
||||
if (Datasource.CommitMode.DATASTORE.equals(getCommitMode())) {
|
||||
final DataService service = getDataService();
|
||||
Set<Entity> commitInstances = new HashSet<Entity>();
|
||||
Set<Entity> deleteInstances = new HashSet<Entity>();
|
||||
|
||||
commitInstances.addAll(itemToCreate);
|
||||
commitInstances.addAll(itemToUpdate);
|
||||
deleteInstances.addAll(itemToDelete);
|
||||
|
||||
final Map<Entity, Entity> map =
|
||||
service.commit(new DataServiceRemote.CommitContext<Entity>(commitInstances, deleteInstances));
|
||||
commited(map);
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public void commited(Map<Entity, Entity> map) {
|
||||
if (map.containsKey(item)) {
|
||||
item = (T) map.get(item);
|
||||
|
@ -21,6 +21,7 @@ import com.haulmont.cuba.web.gui.components.ComponentsHelper;
|
||||
import com.haulmont.cuba.web.ui.ScreenTitlePane;
|
||||
import com.haulmont.cuba.web.xml.layout.WebComponentsFactory;
|
||||
import com.itmill.toolkit.terminal.ExternalResource;
|
||||
import com.itmill.toolkit.terminal.Sizeable;
|
||||
import com.itmill.toolkit.ui.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -139,10 +140,59 @@ public class ScreenManager extends WindowManager
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void showMessageDialog(String title, String message, IFrame.MessageType messageType) {
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
final com.itmill.toolkit.ui.Window window = new com.itmill.toolkit.ui.Window(title);
|
||||
|
||||
final VerticalLayout layout = new VerticalLayout();
|
||||
layout.setMargin(true);
|
||||
window.setLayout(layout);
|
||||
|
||||
Label desc = new Label(message);
|
||||
window.addComponent(layout);
|
||||
|
||||
window.setWidth(400, Sizeable.UNITS_PIXELS);
|
||||
window.setResizable(false);
|
||||
window.setModal(true);
|
||||
|
||||
App.getInstance().getMainWindow().addWindow(window);
|
||||
}
|
||||
|
||||
public Action showOptionDialog(String title, String message, IFrame.MessageType messageType, Action[] actions) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
public void showOptionDialog(String title, String message, IFrame.MessageType messageType, Action[] actions) {
|
||||
final com.itmill.toolkit.ui.Window window = new com.itmill.toolkit.ui.Window(title);
|
||||
|
||||
Label messageBox = new Label(message);
|
||||
|
||||
window.setWidth(400, Sizeable.UNITS_PIXELS);
|
||||
window.setResizable(false);
|
||||
window.setModal(true);
|
||||
|
||||
final VerticalLayout layout = new VerticalLayout();
|
||||
layout.setMargin(true);
|
||||
window.setLayout(layout);
|
||||
|
||||
HorizontalLayout actionsBar = new HorizontalLayout();
|
||||
actionsBar.setHeight(-1, Sizeable.UNITS_PIXELS);
|
||||
|
||||
HorizontalLayout buttonsContainer = new HorizontalLayout();
|
||||
|
||||
for (final Action action : actions) {
|
||||
buttonsContainer.addComponent(new Button(action.getCaption(), new Button.ClickListener() {
|
||||
public void buttonClick(Button.ClickEvent event) {
|
||||
action.actionPerform(null);
|
||||
App.getInstance().getMainWindow().removeWindow(window);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
actionsBar.addComponent(buttonsContainer);
|
||||
|
||||
layout.addComponent(messageBox);
|
||||
layout.addComponent(actionsBar);
|
||||
|
||||
messageBox.setSizeFull();
|
||||
layout.setExpandRatio(messageBox, 1);
|
||||
layout.setComponentAlignment(actionsBar, com.itmill.toolkit.ui.Alignment.BOTTOM_RIGHT);
|
||||
|
||||
App.getInstance().getMainWindow().addWindow(window);
|
||||
window.center();
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ public class RoleBrowser extends AbstractLookup
|
||||
final TableActionsHelper helper = new TableActionsHelper(this, table);
|
||||
helper.createCreateAction();
|
||||
helper.createEditAction();
|
||||
helper.createRemoveAction();
|
||||
helper.createRefreshAction();
|
||||
|
||||
table.refresh();
|
||||
|
@ -59,6 +59,7 @@ public class GenericBrowserWindow extends Window
|
||||
|
||||
helper.createCreateAction();
|
||||
helper.createEditAction();
|
||||
helper.createRemoveAction();
|
||||
helper.createRefreshAction();
|
||||
|
||||
return table;
|
||||
|
@ -10,8 +10,12 @@
|
||||
package com.haulmont.cuba.web.gui;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.haulmont.cuba.gui.components.TableActionsHelper;
|
||||
import com.haulmont.cuba.web.gui.components.*;
|
||||
import com.haulmont.chile.core.model.MetaClass;
|
||||
import com.itmill.toolkit.ui.*;
|
||||
import com.itmill.toolkit.ui.Button;
|
||||
import com.itmill.toolkit.ui.Table;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ -43,6 +47,17 @@ public class GenericLookupWindow extends GenericBrowserWindow implements com.hau
|
||||
return layout;
|
||||
}
|
||||
|
||||
protected com.haulmont.cuba.web.gui.components.Table createTable() {
|
||||
final com.haulmont.cuba.web.gui.components.Table table = new com.haulmont.cuba.web.gui.components.Table();
|
||||
|
||||
final TableActionsHelper helper = new TableActionsHelper(this, table);
|
||||
|
||||
helper.createEditAction();
|
||||
helper.createRefreshAction();
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(Map<String, Object> params) {
|
||||
super.init(params);
|
||||
|
@ -108,8 +108,8 @@ public class Window implements com.haulmont.cuba.gui.components.Window, Componen
|
||||
App.getInstance().getScreenManager().showMessageDialog(title, message, messageType);
|
||||
}
|
||||
|
||||
public Action showOptionDialog(String title, String message, MessageType messageType, Action[] actions) {
|
||||
return App.getInstance().getScreenManager().showOptionDialog(title, message, messageType, actions);
|
||||
public void showOptionDialog(String title, String message, MessageType messageType, Action[] actions) {
|
||||
App.getInstance().getScreenManager().showOptionDialog(title, message, messageType, actions);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -77,8 +77,8 @@ public class IFrame extends AbstractPanel implements com.haulmont.cuba.gui.compo
|
||||
App.getInstance().getScreenManager().showMessageDialog(title, message, messageType);
|
||||
}
|
||||
|
||||
public Action showOptionDialog(String title, String message, MessageType messageType, Action[] actions) {
|
||||
return App.getInstance().getScreenManager().showOptionDialog(title, message, messageType, actions);
|
||||
public void showOptionDialog(String title, String message, MessageType messageType, Action[] actions) {
|
||||
App.getInstance().getScreenManager().showOptionDialog(title, message, messageType, actions);
|
||||
}
|
||||
|
||||
public <A extends com.haulmont.cuba.gui.components.IFrame> A getFrame() {
|
||||
|
Loading…
Reference in New Issue
Block a user