Adapted ScenarioCRUDController to extend BaseCRUDController.
FEA: ItEr75S14ShowInformationEditedEntity
This commit is contained in:
parent
e5ad03701d
commit
14358eb27f
6 changed files with 76 additions and 95 deletions
|
|
@ -29,8 +29,8 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
|
@ -39,6 +39,7 @@ import org.hibernate.validator.AssertTrue;
|
|||
import org.hibernate.validator.NotEmpty;
|
||||
import org.joda.time.DateTime;
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
import org.navalplanner.business.common.IHumanIdentifiable;
|
||||
import org.navalplanner.business.common.Registry;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
|
|
@ -50,7 +51,7 @@ import org.navalplanner.business.scenarios.daos.IScenarioDAO;
|
|||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public class Scenario extends BaseEntity {
|
||||
public class Scenario extends BaseEntity implements IHumanIdentifiable {
|
||||
|
||||
private String name;
|
||||
|
||||
|
|
@ -276,4 +277,9 @@ public class Scenario extends BaseEntity {
|
|||
.hasBeenModifiedAfter(lastNotOwnedReassignationsTimeStamp);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public String getHumanId() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,11 +57,11 @@ public abstract class BaseCRUDController<T extends IHumanIdentifiable> extends
|
|||
|
||||
protected Window editWindow;
|
||||
|
||||
private enum CRUCControllerState {
|
||||
protected enum CRUDControllerState {
|
||||
LIST, CREATE, EDIT
|
||||
};
|
||||
|
||||
private CRUCControllerState state = CRUCControllerState.LIST;
|
||||
protected CRUDControllerState state = CRUDControllerState.LIST;
|
||||
|
||||
/**
|
||||
* Call to super and do some extra stuff: <br />
|
||||
|
|
@ -153,7 +153,7 @@ public abstract class BaseCRUDController<T extends IHumanIdentifiable> extends
|
|||
* Show list window and reload bindings there
|
||||
*/
|
||||
public final void goToList() {
|
||||
state = CRUCControllerState.LIST;
|
||||
state = CRUDControllerState.LIST;
|
||||
showListWindow();
|
||||
}
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ public abstract class BaseCRUDController<T extends IHumanIdentifiable> extends
|
|||
* implemented in subclasses.
|
||||
*/
|
||||
public final void goToCreateForm() {
|
||||
state = CRUCControllerState.CREATE;
|
||||
state = CRUDControllerState.CREATE;
|
||||
initCreate();
|
||||
showEditWindow();
|
||||
}
|
||||
|
|
@ -180,7 +180,7 @@ public abstract class BaseCRUDController<T extends IHumanIdentifiable> extends
|
|||
* Entity to be edited
|
||||
*/
|
||||
public final void goToEditForm(T entity) {
|
||||
state = CRUCControllerState.EDIT;
|
||||
state = CRUDControllerState.EDIT;
|
||||
initEdit(entity);
|
||||
showEditWindow();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,26 +29,22 @@ import java.util.Set;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.business.scenarios.IScenarioManager;
|
||||
import org.navalplanner.business.scenarios.bootstrap.PredefinedScenarios;
|
||||
import org.navalplanner.business.scenarios.entities.Scenario;
|
||||
import org.navalplanner.web.common.IMessagesForUser;
|
||||
import org.navalplanner.web.common.BaseCRUDController;
|
||||
import org.navalplanner.web.common.ITemplateModel;
|
||||
import org.navalplanner.web.common.Level;
|
||||
import org.navalplanner.web.common.MessagesForUser;
|
||||
import org.navalplanner.web.common.OnlyOneVisible;
|
||||
import org.navalplanner.web.common.Util;
|
||||
import org.navalplanner.web.common.ITemplateModel.IOnFinished;
|
||||
import org.navalplanner.web.common.Level;
|
||||
import org.navalplanner.web.common.Util;
|
||||
import org.navalplanner.web.security.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.event.Events;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Button;
|
||||
import org.zkoss.zul.Label;
|
||||
import org.zkoss.zul.SimpleTreeNode;
|
||||
|
|
@ -56,14 +52,13 @@ import org.zkoss.zul.Treecell;
|
|||
import org.zkoss.zul.Treeitem;
|
||||
import org.zkoss.zul.TreeitemRenderer;
|
||||
import org.zkoss.zul.Treerow;
|
||||
import org.zkoss.zul.api.Window;
|
||||
|
||||
/**
|
||||
* Controller for CRUD actions over a {@link Scenario}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public class ScenarioCRUDController extends GenericForwardComposer {
|
||||
public class ScenarioCRUDController extends BaseCRUDController<Scenario> {
|
||||
|
||||
private static final Log LOG = LogFactory
|
||||
.getLog(ScenarioCRUDController.class);
|
||||
|
|
@ -77,76 +72,36 @@ public class ScenarioCRUDController extends GenericForwardComposer {
|
|||
@Autowired
|
||||
private IScenarioManager scenarioManager;
|
||||
|
||||
private Window listWindow;
|
||||
|
||||
private Window createWindow;
|
||||
|
||||
private Window editWindow;
|
||||
|
||||
private OnlyOneVisible visibility;
|
||||
|
||||
private IMessagesForUser messagesForUser;
|
||||
|
||||
private Component messagesContainer;
|
||||
|
||||
private ScenariosTreeitemRenderer scenariosTreeitemRenderer = new ScenariosTreeitemRenderer();
|
||||
|
||||
public Scenario getScenario() {
|
||||
return scenarioModel.getScenario();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
messagesForUser = new MessagesForUser(messagesContainer);
|
||||
comp.setVariable("scenarioController", this, true);
|
||||
getVisibility().showOnly(listWindow);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
scenarioModel.cancel();
|
||||
goToList();
|
||||
}
|
||||
|
||||
public void goToList() {
|
||||
Util.reloadBindings(listWindow);
|
||||
getVisibility().showOnly(listWindow);
|
||||
}
|
||||
|
||||
public void goToEditForm(Scenario scenario) {
|
||||
scenarioModel.initEdit(scenario);
|
||||
getVisibility().showOnly(editWindow);
|
||||
Util.reloadBindings(editWindow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
try {
|
||||
scenarioModel.confirmSave();
|
||||
messagesForUser.showMessage(Level.INFO, _("Scenario \"{0}\" saved",
|
||||
scenarioModel.getScenario().getName()));
|
||||
goToList();
|
||||
} catch (ValidationException e) {
|
||||
messagesForUser.showInvalidValues(e);
|
||||
}
|
||||
scenarioModel.confirmSave();
|
||||
}
|
||||
|
||||
private OnlyOneVisible getVisibility() {
|
||||
if (visibility == null) {
|
||||
visibility = new OnlyOneVisible(listWindow, createWindow,
|
||||
editWindow);
|
||||
}
|
||||
return visibility;
|
||||
@Override
|
||||
protected void initCreate() {
|
||||
// Do nothing, direct scenario creation is not allowed it should be
|
||||
// derived
|
||||
}
|
||||
|
||||
public void goToCreateDerivedForm(Scenario scenario) {
|
||||
state = CRUDControllerState.CREATE;
|
||||
scenarioModel.initCreateDerived(scenario);
|
||||
getVisibility().showOnly(createWindow);
|
||||
Util.reloadBindings(createWindow);
|
||||
showEditWindow();
|
||||
}
|
||||
|
||||
public ScenariosTreeModel getScenariosTreeModel() {
|
||||
return new ScenariosTreeModel(new ScenarioTreeRoot(scenarioModel
|
||||
.getScenarios()));
|
||||
return new ScenariosTreeModel(new ScenarioTreeRoot(
|
||||
scenarioModel.getScenarios()));
|
||||
}
|
||||
|
||||
public ScenariosTreeitemRenderer getScenariosTreeitemRenderer() {
|
||||
|
|
@ -205,8 +160,7 @@ public class ScenarioCRUDController extends GenericForwardComposer {
|
|||
|
||||
@Override
|
||||
public void onEvent(Event event) {
|
||||
scenarioModel.remove(scenario);
|
||||
Util.reloadBindings(listWindow);
|
||||
confirmDelete(scenario);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
@ -279,4 +233,29 @@ public class ScenarioCRUDController extends GenericForwardComposer {
|
|||
return scenario.getOrders().keySet();
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
protected String getEntityType() {
|
||||
return "Scenario";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPluralEntityType() {
|
||||
return "Scenarios";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initEdit(Scenario scenario) {
|
||||
scenarioModel.initEdit(scenario);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Scenario getEntityBeingEdited() {
|
||||
return scenarioModel.getScenario();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void delete(Scenario scenario) throws InstanceNotFoundException {
|
||||
scenarioModel.remove(scenario);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<window id="${arg.top_id}" title="${arg.title}">
|
||||
<window id="${arg.top_id}">
|
||||
|
||||
<grid fixedLayout="true" style="margin-bottom: 10px;">
|
||||
<columns>
|
||||
|
|
@ -29,22 +29,23 @@
|
|||
<rows>
|
||||
<row>
|
||||
<label value="${i18n:_('Name')}" />
|
||||
<textbox value="@{scenarioController.scenario.name}" width="300px"
|
||||
<textbox value="@{controller.scenario.name}" width="300px"
|
||||
constraint="no empty:${i18n:_('cannot be null or empty')}"
|
||||
disabled="@{scenarioController.scenario.predefined}" />
|
||||
disabled="@{controller.scenario.predefined}"
|
||||
onBlur="controller.updateWindowTitle()" />
|
||||
</row>
|
||||
<row visible="@{scenarioController.scenario.derived}">
|
||||
<row visible="@{controller.scenario.derived}">
|
||||
<label value="${i18n:_('Predecessor')}" />
|
||||
<label value="@{scenarioController.scenario.predecessor.name}" />
|
||||
<label value="@{controller.scenario.predecessor.name}" />
|
||||
</row>
|
||||
<row>
|
||||
<label value="${i18n:_('Description')}" />
|
||||
<textbox value="@{scenarioController.scenario.description}"
|
||||
<textbox value="@{controller.scenario.description}"
|
||||
rows="5" width="300px" />
|
||||
</row>
|
||||
<row>
|
||||
<label value="${i18n:_('Projects')}" />
|
||||
<listbox model="@{scenarioController.orders}">
|
||||
<listbox model="@{controller.orders}">
|
||||
<listhead>
|
||||
<listheader label="${i18n:_('Code')}" />
|
||||
<listheader label="${i18n:_('Name')}" />
|
||||
|
|
@ -59,13 +60,15 @@
|
|||
</grid>
|
||||
|
||||
<hbox>
|
||||
<button onClick="scenarioController.save();"
|
||||
label="${arg.save_button_label}"
|
||||
sclass="save-button global-action"
|
||||
visible="${arg.save_button_visible}" />
|
||||
<button onClick="scenarioController.cancel();"
|
||||
label="${arg.cancel_button_label}"
|
||||
sclass="cancel-button global-action" />
|
||||
<button label="${i18n:_('Save')}"
|
||||
onClick="controller.saveAndExit()"
|
||||
sclass="save-button global-action"/>
|
||||
<button label="${i18n:_('Save & Continue')}"
|
||||
onClick="controller.saveAndContinue()"
|
||||
sclass="saveandcontinue-button global-action"/>
|
||||
<button label="${i18n:_('Cancel')}"
|
||||
onClick="controller.cancelForm()"
|
||||
sclass="cancel-button global-action"/>
|
||||
</hbox>
|
||||
|
||||
</window>
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@
|
|||
-->
|
||||
|
||||
<window id="${arg.top_id}" title="${i18n:_('Scenarios List')}">
|
||||
<tree id="tree" model="@{scenarioController.scenariosTreeModel}"
|
||||
treeitemRenderer="@{scenarioController.scenariosTreeitemRenderer}"
|
||||
<tree id="tree" model="@{controller.scenariosTreeModel}"
|
||||
treeitemRenderer="@{controller.scenariosTreeitemRenderer}"
|
||||
zclass="z-dottree">
|
||||
<treecols sizable="true">
|
||||
<treecol label="${i18n:_('Name')}" />
|
||||
|
|
|
|||
|
|
@ -34,13 +34,6 @@
|
|||
<vbox id="messagesContainer"></vbox>
|
||||
|
||||
<list top_id="listWindow" />
|
||||
<edition top_id="createWindow" title="${i18n:_('Create Scenario')}"
|
||||
save_button_label="${i18n:_('Save')}"
|
||||
save_button_visible="true"
|
||||
cancel_button_label="${i18n:_('Cancel')}" />
|
||||
<edition top_id="editWindow" title="${i18n:_('Edit Scenario')}"
|
||||
save_button_label="${i18n:_('Save')}"
|
||||
save_button_visible="true"
|
||||
cancel_button_label="${i18n:_('Cancel')}" />
|
||||
<edition top_id="editWindow" />
|
||||
</window>
|
||||
</zk>
|
||||
Loading…
Add table
Reference in a new issue