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);
|
void setSelected(Collection<Entity> items);
|
||||||
|
|
||||||
CollectionDatasource getDatasource();
|
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.gui.config.ScreenInfo;
|
||||||
import com.haulmont.cuba.core.global.MetadataProvider;
|
import com.haulmont.cuba.core.global.MetadataProvider;
|
||||||
import com.haulmont.cuba.web.gui.GenericEditorWindow;
|
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.Element;
|
||||||
import org.dom4j.dom.DOMElement;
|
import org.dom4j.dom.DOMElement;
|
||||||
|
|
||||||
@ -13,21 +15,33 @@ class WindowConfig extends ScreenConfig {
|
|||||||
ScreenInfo screenInfo = screens.get(id);
|
ScreenInfo screenInfo = screens.get(id);
|
||||||
if (screenInfo == null) {
|
if (screenInfo == null) {
|
||||||
if (id.endsWith(".edit")) {
|
if (id.endsWith(".edit")) {
|
||||||
final String metaClass = id.substring(0, id.length() - ".edit".length());
|
return getGenericWindowInfo(id, ".edit", GenericEditorWindow.class.getName());
|
||||||
if (MetadataProvider.getSession().getClass(metaClass) != null) {
|
} else if (id.endsWith(".browse")) {
|
||||||
final Element element = new DOMElement("screen");
|
return getGenericWindowInfo(id, ".browse", GenericBrowserWindow.class.getName());
|
||||||
element.addAttribute("id", id);
|
} else if (id.endsWith(".lookup")) {
|
||||||
element.addAttribute("class", GenericEditorWindow.class.getName());
|
return getGenericWindowInfo(id, ".lookup", GenericLookupWindow.class.getName());
|
||||||
|
} else {
|
||||||
final Element paramElement = element.addElement("params").addElement("param");
|
throw new IllegalStateException("Screen '" + id + "' is not defined");
|
||||||
paramElement.addAttribute("name", "metaClass");
|
|
||||||
paramElement.addAttribute("value", metaClass);
|
|
||||||
|
|
||||||
return new ScreenInfo(id, element);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Screen '" + id + "' is not defined");
|
|
||||||
}
|
}
|
||||||
return screenInfo;
|
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) {
|
protected void init(Map<String, Object> params) {
|
||||||
final Table table = getComponent("roles");
|
final Table table = getComponent("roles");
|
||||||
|
|
||||||
table.addAction(
|
final TableActionsHelper helper = new TableActionsHelper(this, table);
|
||||||
new AbstractAction("edit")
|
helper.createCreateAction();
|
||||||
{
|
helper.createEditAction();
|
||||||
public String getCaption() {
|
helper.createRefreshAction();
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
table.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,4 +72,8 @@ public abstract class AbstractListComponent<T extends AbstractSelect>
|
|||||||
}
|
}
|
||||||
component.setValue(itemIds.size() == 1 ? itemIds.iterator().next() : itemIds);
|
component.setValue(itemIds.size() == 1 ? itemIds.iterator().next() : itemIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
|
datasource.refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user