mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 20:28:00 +08:00
add refresh method to lists
support generic screens
This commit is contained in:
parent
a874fa66a3
commit
18d29c8a08
@ -17,4 +17,6 @@ public interface List extends Component, Component.BelongToFrame, Component.Act
|
||||
void setSelected(Collection<Entity> items);
|
||||
|
||||
CollectionDatasource getDatasource();
|
||||
|
||||
void refresh();
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import com.haulmont.cuba.gui.config.ScreenConfig;
|
||||
import com.haulmont.cuba.gui.config.ScreenInfo;
|
||||
import com.haulmont.cuba.core.global.MetadataProvider;
|
||||
import com.haulmont.cuba.web.gui.GenericEditorWindow;
|
||||
import com.haulmont.cuba.web.gui.GenericBrowserWindow;
|
||||
import com.haulmont.cuba.web.gui.GenericLookupWindow;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.dom.DOMElement;
|
||||
|
||||
@ -13,21 +15,33 @@ class WindowConfig extends ScreenConfig {
|
||||
ScreenInfo screenInfo = screens.get(id);
|
||||
if (screenInfo == null) {
|
||||
if (id.endsWith(".edit")) {
|
||||
final String metaClass = id.substring(0, id.length() - ".edit".length());
|
||||
if (MetadataProvider.getSession().getClass(metaClass) != null) {
|
||||
final Element element = new DOMElement("screen");
|
||||
element.addAttribute("id", id);
|
||||
element.addAttribute("class", GenericEditorWindow.class.getName());
|
||||
|
||||
final Element paramElement = element.addElement("params").addElement("param");
|
||||
paramElement.addAttribute("name", "metaClass");
|
||||
paramElement.addAttribute("value", metaClass);
|
||||
|
||||
return new ScreenInfo(id, element);
|
||||
}
|
||||
return getGenericWindowInfo(id, ".edit", GenericEditorWindow.class.getName());
|
||||
} else if (id.endsWith(".browse")) {
|
||||
return getGenericWindowInfo(id, ".browse", GenericBrowserWindow.class.getName());
|
||||
} else if (id.endsWith(".lookup")) {
|
||||
return getGenericWindowInfo(id, ".lookup", GenericLookupWindow.class.getName());
|
||||
} else {
|
||||
throw new IllegalStateException("Screen '" + id + "' is not defined");
|
||||
}
|
||||
throw new IllegalStateException("Screen '" + id + "' is not defined");
|
||||
}
|
||||
return screenInfo;
|
||||
}
|
||||
|
||||
private ScreenInfo getGenericWindowInfo(String id, String actionName, String windowClass) {
|
||||
final String metaClass = id.substring(0, id.length() - actionName.length());
|
||||
|
||||
if (MetadataProvider.getSession().getClass(metaClass) != null) {
|
||||
final Element element = new DOMElement("screen");
|
||||
element.addAttribute("id", id);
|
||||
element.addAttribute("class", windowClass);
|
||||
|
||||
final Element paramElement = element.addElement("params").addElement("param");
|
||||
paramElement.addAttribute("name", "metaClass");
|
||||
paramElement.addAttribute("value", metaClass);
|
||||
|
||||
return new ScreenInfo(id, element);
|
||||
} else {
|
||||
throw new IllegalStateException("Screen '" + id + "' is not defined");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,40 +26,11 @@ public class RoleBrowser extends AbstractWindow
|
||||
protected void init(Map<String, Object> params) {
|
||||
final Table table = getComponent("roles");
|
||||
|
||||
table.addAction(
|
||||
new AbstractAction("edit")
|
||||
{
|
||||
public String getCaption() {
|
||||
return "Edit";
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void actionPerform(Component component) {
|
||||
final Set selected = table.getSelected();
|
||||
if (selected.size() == 1) {
|
||||
Role user = (Role) selected.iterator().next();
|
||||
openEditor("sec$Role.edit", user, WindowManager.OpenType.THIS_TAB);
|
||||
}
|
||||
}
|
||||
});
|
||||
table.addAction(
|
||||
new AbstractAction("refresh")
|
||||
{
|
||||
public String getCaption() {
|
||||
return "Refresh";
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void actionPerform(Component component) {
|
||||
table.getDatasource().refresh();
|
||||
}
|
||||
});
|
||||
final TableActionsHelper helper = new TableActionsHelper(this, table);
|
||||
helper.createCreateAction();
|
||||
helper.createEditAction();
|
||||
helper.createRefreshAction();
|
||||
|
||||
table.refresh();
|
||||
}
|
||||
}
|
||||
|
@ -72,4 +72,8 @@ public abstract class AbstractListComponent<T extends AbstractSelect>
|
||||
}
|
||||
component.setValue(itemIds.size() == 1 ? itemIds.iterator().next() : itemIds);
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
datasource.refresh();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user