mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 12:17:41 +08:00
user edit
This commit is contained in:
parent
18d29c8a08
commit
5892ebb6d0
@ -105,7 +105,11 @@ public class DataServiceBean implements DataService, DataServiceRemote
|
||||
final String name = entry.getKey();
|
||||
if (queryString.contains(":" + name)) {
|
||||
final Object value = entry.getValue();
|
||||
query.setParameter(entry.getKey(), value);
|
||||
if (value instanceof Entity) {
|
||||
query.setParameter(entry.getKey(), ((Entity) value).getId());
|
||||
} else {
|
||||
query.setParameter(entry.getKey(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,9 +30,7 @@ public class CollectionDatasourceImpl<T extends Entity, K>
|
||||
private String query;
|
||||
private ParametersHelper.ParameterInfo[] queryParameters;
|
||||
|
||||
protected Data data;
|
||||
// private Collection<K> itemIds = Collections.emptyList();
|
||||
// private Map<K, T> itemsByKey = Collections.emptyMap();
|
||||
protected Data data = new Data(Collections.<K>emptyList(), Collections.<K,T>emptyMap());
|
||||
|
||||
public CollectionDatasourceImpl(
|
||||
DsContext context, DataService dataservice,
|
||||
@ -247,7 +245,7 @@ public class CollectionDatasourceImpl<T extends Entity, K>
|
||||
|
||||
break;
|
||||
}
|
||||
case CONTEXT: {
|
||||
case PARAM: {
|
||||
final Object value =
|
||||
dsContext.getContext() == null ?
|
||||
null : dsContext.getContext().getValue(info.getPath());
|
||||
|
@ -33,7 +33,7 @@ public class ParametersHelper {
|
||||
public enum Type {
|
||||
DATASOURCE("ds"),
|
||||
COMPONENT("component"),
|
||||
CONTEXT("context");
|
||||
PARAM("param");
|
||||
|
||||
private String prefix;
|
||||
|
||||
@ -101,8 +101,8 @@ public class ParametersHelper {
|
||||
|
||||
if (ParameterInfo.Type.DATASOURCE.prefix.equals(source)) {
|
||||
return new ParameterInfo(name, ParameterInfo.Type.DATASOURCE);
|
||||
} else if (ParameterInfo.Type.CONTEXT.prefix.equals(source)) {
|
||||
return new ParameterInfo(name, ParameterInfo.Type.CONTEXT);
|
||||
} else if (ParameterInfo.Type.PARAM.prefix.equals(source)) {
|
||||
return new ParameterInfo(name, ParameterInfo.Type.PARAM);
|
||||
} else if (ParameterInfo.Type.COMPONENT.prefix.equals(source)) {
|
||||
return new ParameterInfo(name, ParameterInfo.Type.COMPONENT);
|
||||
} else
|
||||
|
@ -18,7 +18,7 @@
|
||||
<screen id="sec$Group.browse"
|
||||
template="/com/haulmont/cuba/web/app/ui/security/group/browse/group-browse.xml"/>
|
||||
|
||||
<screen id="sec$Role.browse"
|
||||
template="/com/haulmont/cuba/web/app/ui/security/role/browse/role-browse.xml"/>
|
||||
<!--<screen id="sec$Role.browse"-->
|
||||
<!--template="/com/haulmont/cuba/web/app/ui/security/role/browse/role-browse.xml"/>-->
|
||||
|
||||
</screen-config>
|
@ -17,7 +17,7 @@ import com.haulmont.cuba.security.entity.Role;
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
|
||||
public class RoleBrowser extends AbstractWindow
|
||||
public class RoleBrowser extends AbstractLookup
|
||||
{
|
||||
public RoleBrowser(IFrame frame) {
|
||||
super(frame);
|
||||
|
@ -1,5 +1,7 @@
|
||||
<window
|
||||
class="com.haulmont.cuba.web.app.ui.security.role.browse.RoleBrowser">
|
||||
class="com.haulmont.cuba.web.app.ui.security.role.browse.RoleBrowser"
|
||||
lookupComponent="users"
|
||||
>
|
||||
|
||||
<metadataContext>
|
||||
<view entity="sec$Role" name="role-browse">
|
||||
@ -19,6 +21,7 @@
|
||||
<layout>
|
||||
<vbox id="table-panel" expand="roles">
|
||||
<hbox>
|
||||
<button action="roles.create"/>
|
||||
<button action="roles.edit"/>
|
||||
<button action="roles.refresh"/>
|
||||
</hbox>
|
||||
|
@ -11,7 +11,13 @@ package com.haulmont.cuba.web.app.ui.security.user.edit;
|
||||
|
||||
import com.haulmont.cuba.gui.components.*;
|
||||
import com.haulmont.cuba.gui.WindowManager;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.gui.data.DsContext;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import com.haulmont.cuba.security.entity.User;
|
||||
import com.haulmont.cuba.security.entity.UserRole;
|
||||
import com.haulmont.cuba.security.entity.Role;
|
||||
import com.haulmont.chile.core.model.MetaClass;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
@ -22,10 +28,14 @@ public class UserEditor extends AbstractEditor {
|
||||
}
|
||||
|
||||
protected void init(Map<String, Object> params) {
|
||||
Button button = getComponent("browse");
|
||||
button.setAction(new AbstractAction("Browse") {
|
||||
final DsContext dsContext = getDsContext();
|
||||
final Datasource userDs = dsContext.get("user");
|
||||
|
||||
final Table rolesTable = getComponent("roles");
|
||||
|
||||
rolesTable.addAction(new AbstractAction("include") {
|
||||
public String getCaption() {
|
||||
return "Browse...";
|
||||
return "Include";
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
@ -33,16 +43,34 @@ public class UserEditor extends AbstractEditor {
|
||||
}
|
||||
|
||||
public void actionPerform(Component component) {
|
||||
openLookup("sec$User.browse", new Lookup.Handler() {
|
||||
final CollectionDatasource ds = rolesTable.getDatasource();
|
||||
openLookup("sec$Role.lookup", new Lookup.Handler() {
|
||||
public void handleLookup(Collection items) {
|
||||
if (items.size() == 1) {
|
||||
final User item = (User) items.iterator().next();
|
||||
final Field field = getComponent("name");
|
||||
field.setValue(item.getName());
|
||||
for (Object item : items) {
|
||||
final MetaClass metaClass = ds.getMetaClass();
|
||||
|
||||
UserRole userRole = ds.getDataService().newInstance(metaClass);
|
||||
userRole.setRole((Role) item);
|
||||
userRole.setUser((User) userDs.getItem());
|
||||
|
||||
ds.addItem(userRole);
|
||||
}
|
||||
}
|
||||
}, WindowManager.OpenType.THIS_TAB);
|
||||
}
|
||||
});
|
||||
rolesTable.addAction(new AbstractAction("exclude") {
|
||||
public String getCaption() {
|
||||
return "Exclude";
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void actionPerform(Component component) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,14 @@
|
||||
<views>
|
||||
<view entity="sec$User" name="edit">
|
||||
<view entity="sec$User" name="user.edit">
|
||||
<property name="name"/>
|
||||
<property name="login"/>
|
||||
<property name="group" view="lookup"/>
|
||||
</view>
|
||||
|
||||
<view entity="sec$UserRole" name="user.edit">
|
||||
<property name="role">
|
||||
<property name="name"/>
|
||||
</property>
|
||||
</view>
|
||||
|
||||
</views>
|
@ -13,7 +13,7 @@
|
||||
<datasource
|
||||
id="user"
|
||||
class="com.haulmont.cuba.security.entity.User"
|
||||
view="edit"
|
||||
view="user.edit"
|
||||
/>
|
||||
|
||||
<collectionDatasource
|
||||
@ -23,31 +23,50 @@
|
||||
>
|
||||
<query>select g from sec$Group g</query>
|
||||
</collectionDatasource>
|
||||
|
||||
<collectionDatasource
|
||||
id="roles"
|
||||
class="com.haulmont.cuba.security.entity.UserRole"
|
||||
view="user.edit"
|
||||
>
|
||||
<query>select r from sec$UserRole r where r.user.id=:ds$user</query>
|
||||
</collectionDatasource>
|
||||
</dsContext>
|
||||
|
||||
<layout>
|
||||
<grid>
|
||||
<columns>
|
||||
<column flex="1"/>
|
||||
<column flex="3"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row>
|
||||
<label value="Name"/>
|
||||
<textField id="name" datasource="user" property="name"/>
|
||||
</row>
|
||||
<row>
|
||||
<label value="Login"/>
|
||||
<hbox>
|
||||
<vbox expand="roles-pane">
|
||||
<grid>
|
||||
<columns>
|
||||
<column flex="1"/>
|
||||
<column flex="3"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row>
|
||||
<label value="Name"/>
|
||||
<textField id="name" datasource="user" property="name"/>
|
||||
</row>
|
||||
<row>
|
||||
<label value="Login"/>
|
||||
<textField id="login" datasource="user" property="login"/>
|
||||
<button id="browse" caption="Browse..."/>
|
||||
</hbox>
|
||||
</row>
|
||||
<row>
|
||||
<label value="Group"/>
|
||||
<lookupField id="group" datasource="user" property="group" lookupDatasource="groups" captionProperty="name"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</row>
|
||||
<row>
|
||||
<label value="Group"/>
|
||||
<lookupField id="group" datasource="user" property="group" lookupDatasource="groups" captionProperty="name"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
<vbox id="roles-pane" expand="roles">
|
||||
<hbox>
|
||||
<button action="roles.include"/>
|
||||
<button action="roles.exclude"/>
|
||||
</hbox>
|
||||
<table id="roles">
|
||||
<columns>
|
||||
<column id="role" caption="Role"/>
|
||||
</columns>
|
||||
<rows datasource="roles"/>
|
||||
</table>
|
||||
</vbox>
|
||||
</vbox>
|
||||
</layout>
|
||||
</window>
|
||||
|
@ -65,7 +65,8 @@ public class GenericBrowserWindow extends Window
|
||||
}
|
||||
|
||||
protected Layout createActionsToolbar(Table table) {
|
||||
final OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
|
||||
final HorizontalLayout layout = new HorizontalLayout();
|
||||
|
||||
final Collection<Action> actions = table.getActions();
|
||||
for (Action action : actions) {
|
||||
final Button button = new Button();
|
||||
@ -82,7 +83,7 @@ public class GenericBrowserWindow extends Window
|
||||
View view = getView(params);
|
||||
|
||||
if (metaClass == null) throw new UnsupportedOperationException();
|
||||
setCaption("Browse " + metaClass.getName());
|
||||
initCaption(metaClass);
|
||||
|
||||
final DsContextImpl context = createDsContext(metaClass, view);
|
||||
setDsContext(context);
|
||||
@ -93,6 +94,10 @@ public class GenericBrowserWindow extends Window
|
||||
table.setDatasource(ds);
|
||||
}
|
||||
|
||||
protected void initCaption(MetaClass metaClass) {
|
||||
setCaption("Browse " + metaClass.getName());
|
||||
}
|
||||
|
||||
protected View getView(Map<String, Object> params) {
|
||||
final MetaClass metaClass = getMetaClass(params);
|
||||
|
||||
|
@ -10,18 +10,19 @@
|
||||
package com.haulmont.cuba.web.gui;
|
||||
|
||||
import com.haulmont.cuba.gui.components.Component;
|
||||
import com.itmill.toolkit.ui.Layout;
|
||||
import com.itmill.toolkit.ui.OrderedLayout;
|
||||
import com.itmill.toolkit.ui.Button;
|
||||
import com.haulmont.chile.core.model.MetaClass;
|
||||
import com.itmill.toolkit.ui.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class GenericLookupWindow extends GenericBrowserWindow implements com.haulmont.cuba.gui.components.Window.Lookup {
|
||||
private Handler handler;
|
||||
|
||||
@Override
|
||||
protected com.itmill.toolkit.ui.Component createLayout() {
|
||||
final Layout layout = (Layout) super.createLayout();
|
||||
final VerticalLayout layout = (VerticalLayout) super.createLayout();
|
||||
|
||||
OrderedLayout okbar = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
|
||||
HorizontalLayout okbar = new HorizontalLayout();
|
||||
okbar.setHeight("25px");
|
||||
|
||||
final Button selectButton = new Button("Select");
|
||||
@ -37,10 +38,20 @@ public class GenericLookupWindow extends GenericBrowserWindow implements com.hau
|
||||
okbar.addComponent(cancelButton);
|
||||
|
||||
layout.addComponent(okbar);
|
||||
layout.setComponentAlignment(okbar, com.itmill.toolkit.ui.Alignment.BOTTOM_RIGHT);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(Map<String, Object> params) {
|
||||
super.init(params);
|
||||
}
|
||||
|
||||
protected void initCaption(MetaClass metaClass) {
|
||||
setCaption("Lookup " + metaClass.getName());
|
||||
}
|
||||
|
||||
public Component getLookupComponent() {
|
||||
return table;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class AbstractActionOwnerComponent<T extends com.itmill.toolkit.ui.Compon
|
||||
}
|
||||
|
||||
public Collection<com.haulmont.cuba.gui.components.Action> getActions() {
|
||||
return actions.keySet();
|
||||
return actionsOrder;
|
||||
}
|
||||
|
||||
public com.haulmont.cuba.gui.components.Action getAction(String id) {
|
||||
|
Loading…
Reference in New Issue
Block a user