Fixes #614 Автоматический опрос состояния actions, связанных с таблицами и деревьями

This commit is contained in:
Konstantin Krivopustov 2011-08-02 09:11:05 +00:00
parent 2329ffe3d4
commit e8c51bc5ae
7 changed files with 121 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.gui.components.Window;
import com.haulmont.cuba.gui.components.actions.EditAction;
import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.data.impl.CollectionDsActionsNotifier;
import com.haulmont.cuba.gui.data.impl.CollectionDsListenerAdapter;
import com.haulmont.cuba.gui.presentations.Presentations;
import com.haulmont.cuba.security.entity.EntityAttrAccess;
@ -360,6 +361,8 @@ public abstract class DesktopAbstractTable<C extends JTable>
if (rowsCount != null)
rowsCount.setDatasource(datasource);
datasource.addListener(new CollectionDsActionsNotifier(this));
}
private void setColumnIdentifiers() {

View File

@ -15,6 +15,7 @@ import com.haulmont.cuba.gui.components.Tree;
import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.data.Datasource;
import com.haulmont.cuba.gui.data.HierarchicalDatasource;
import com.haulmont.cuba.gui.data.impl.CollectionDsActionsNotifier;
import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
@ -164,6 +165,8 @@ public class DesktopTree
}
action.setDatasource(datasource);
}
datasource.addListener(new CollectionDsActionsNotifier(this));
}
@Override

View File

@ -13,11 +13,15 @@ package com.haulmont.cuba.gui.components.actions;
import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.MessageProvider;
import com.haulmont.cuba.core.global.UserSessionProvider;
import com.haulmont.cuba.gui.AppConfig;
import com.haulmont.cuba.gui.UserSessionClient;
import com.haulmont.cuba.gui.WindowManager;
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.gui.components.AbstractAction;
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.ListComponent;
import com.haulmont.cuba.gui.components.Window;
import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.data.CollectionDatasourceListener;
import com.haulmont.cuba.gui.data.Datasource;
import com.haulmont.cuba.gui.data.PropertyDatasource;
import com.haulmont.cuba.security.entity.EntityOp;
@ -26,7 +30,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class EditAction extends AbstractAction {
public class EditAction extends AbstractAction implements CollectionDatasourceListener {
private static final long serialVersionUID = -4849373795449480016L;
@ -53,7 +57,7 @@ public class EditAction extends AbstractAction {
public String getCaption() {
final String messagesPackage = AppConfig.getInstance().getMessagesPack();
if (UserSessionClient.getUserSession().isEntityOpPermitted(owner.getDatasource().getMetaClass(), EntityOp.UPDATE))
if (UserSessionProvider.getUserSession().isEntityOpPermitted(owner.getDatasource().getMetaClass(), EntityOp.UPDATE))
return MessageProvider.getMessage(messagesPackage, "actions.Edit");
else
return MessageProvider.getMessage(messagesPackage, "actions.View");
@ -109,4 +113,22 @@ public class EditAction extends AbstractAction {
protected void afterWindowClosed(Window window) {
}
@Override
public void collectionChanged(CollectionDatasource ds, Operation operation) {
}
@Override
public void itemChanged(Datasource ds, Entity prevItem, Entity item) {
setEnabled(item != null);
}
@Override
public void stateChanged(Datasource ds, Datasource.State prevState, Datasource.State state) {
setEnabled(Datasource.State.VALID.equals(state) && ds.getItem() != null);
}
@Override
public void valueChanged(Object source, String property, Object prevValue, Object value) {
}
}

View File

@ -18,12 +18,14 @@ import com.haulmont.cuba.core.global.UserSessionProvider;
import com.haulmont.cuba.gui.AppConfig;
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.data.CollectionDatasourceListener;
import com.haulmont.cuba.gui.data.Datasource;
import com.haulmont.cuba.gui.data.PropertyDatasource;
import com.haulmont.cuba.security.entity.EntityOp;
import java.util.Set;
public class RemoveAction extends AbstractAction {
public class RemoveAction extends AbstractAction implements CollectionDatasourceListener {
private static final long serialVersionUID = -8700360141431140203L;
@ -145,4 +147,22 @@ public class RemoveAction extends AbstractAction {
protected void afterRemove(Set selected) {
}
@Override
public void collectionChanged(CollectionDatasource ds, Operation operation) {
}
@Override
public void itemChanged(Datasource ds, Entity prevItem, Entity item) {
setEnabled(item != null);
}
@Override
public void stateChanged(Datasource ds, Datasource.State prevState, Datasource.State state) {
setEnabled(Datasource.State.VALID.equals(state) && ds.getItem() != null);
}
@Override
public void valueChanged(Object source, String property, Object prevValue, Object value) {
}
}

View File

@ -0,0 +1,62 @@
/*
* Copyright (c) 2011 Haulmont Technology Ltd. All Rights Reserved.
* Haulmont Technology proprietary and confidential.
* Use is subject to license terms.
*/
package com.haulmont.cuba.gui.data.impl;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.gui.components.Action;
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.data.*;
/**
* <p>$Id$</p>
*
* @author krivopustov
*/
public class CollectionDsActionsNotifier implements CollectionDatasourceListener {
private Component.ActionsHolder actionsHolder;
public CollectionDsActionsNotifier(Component.ActionsHolder actionsHolder) {
this.actionsHolder = actionsHolder;
}
@Override
public void stateChanged(Datasource ds, Datasource.State prevState, Datasource.State state) {
for (Action action : actionsHolder.getActions()) {
if (action instanceof DatasourceListener) {
((DatasourceListener) action).stateChanged(ds, prevState, state);
}
}
}
@Override
public void itemChanged(Datasource ds, Entity prevItem, Entity item) {
for (Action action : actionsHolder.getActions()) {
if (action instanceof DatasourceListener) {
((DatasourceListener) action).itemChanged(ds, prevItem, item);
}
}
}
@Override
public void collectionChanged(CollectionDatasource ds, Operation operation) {
for (Action action : actionsHolder.getActions()) {
if (action instanceof CollectionDatasourceListener) {
((CollectionDatasourceListener) action).collectionChanged(ds, operation);
}
}
}
@Override
public void valueChanged(Object source, String property, Object prevValue, Object value) {
for (Action action : actionsHolder.getActions()) {
if (action instanceof ValueListener) {
((ValueListener) action).valueChanged(source, property, prevValue, value);
}
}
}
}

View File

@ -26,6 +26,7 @@ import com.haulmont.cuba.gui.components.Formatter;
import com.haulmont.cuba.gui.components.Table;
import com.haulmont.cuba.gui.components.Window;
import com.haulmont.cuba.gui.data.*;
import com.haulmont.cuba.gui.data.impl.CollectionDsActionsNotifier;
import com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl;
import com.haulmont.cuba.gui.presentations.Presentations;
import com.haulmont.cuba.gui.presentations.PresentationsImpl;
@ -503,6 +504,8 @@ public abstract class WebAbstractTable<T extends com.haulmont.cuba.web.toolkit.u
if (rowsCount != null)
rowsCount.setDatasource(datasource);
datasource.addListener(new CollectionDsActionsNotifier(this));
}
protected abstract CollectionDsWrapper createContainerDatasource(CollectionDatasource datasource, Collection<MetaPropertyPath> columns, DsManager dsManager);

View File

@ -18,6 +18,7 @@ import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.ShowInfoAction;
import com.haulmont.cuba.gui.components.Tree;
import com.haulmont.cuba.gui.data.HierarchicalDatasource;
import com.haulmont.cuba.gui.data.impl.CollectionDsActionsNotifier;
import com.haulmont.cuba.web.gui.data.DsManager;
import com.haulmont.cuba.web.gui.data.HierarchicalDsWrapper;
import com.vaadin.data.Property;
@ -157,5 +158,7 @@ public class WebTree
}
action.setDatasource(datasource);
}
datasource.addListener(new CollectionDsActionsNotifier(this));
}
}