ItEr30S06CUAltaMaquina: Create machine

This commit is contained in:
Diego Pino Garcia 2009-10-19 09:37:03 +02:00 committed by Javier Moran Rua
parent b228b7c51b
commit ad8390432c
5 changed files with 120 additions and 9 deletions

View file

@ -22,6 +22,7 @@ package org.navalplanner.web.resources.machine;
import java.util.List;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.resources.entities.Machine;
/*
@ -29,6 +30,12 @@ import org.navalplanner.business.resources.entities.Machine;
*/
public interface IMachineModel {
Machine getMachine();
List<Machine> getMachines();
void initCreate();
void confirmSave() throws ValidationException;
}

View file

@ -24,6 +24,7 @@ import static org.navalplanner.web.I18nHelper._;
import java.util.List;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.resources.entities.Machine;
import org.navalplanner.web.common.IMessagesForUser;
import org.navalplanner.web.common.Level;
@ -80,7 +81,7 @@ public class MachineCRUDController extends GenericForwardComposer {
}
public void goToCreateForm() {
// entity.initCreate();
machineModel.initCreate();
editWindow.setTitle(_("Create machine"));
showEditWindow();
Util.reloadBindings(editWindow);
@ -99,9 +100,13 @@ public class MachineCRUDController extends GenericForwardComposer {
public void save() {
validate();
// model.confirmSave();
goToList();
messagesForUser.showMessage(Level.INFO, _("Machine saved"));
try {
machineModel.confirmSave();
goToList();
messagesForUser.showMessage(Level.INFO, _("Machine saved"));
} catch (ValidationException e) {
e.printStackTrace();
}
}
private void validate() {
@ -113,7 +118,7 @@ public class MachineCRUDController extends GenericForwardComposer {
Util.reloadBindings(listWindow);
}
public void close() {
public void cancel() {
goToList();
}
@ -121,4 +126,8 @@ public class MachineCRUDController extends GenericForwardComposer {
return machineModel.getMachines();
}
public Machine getMachine() {
return machineModel.getMachine();
}
}

View file

@ -22,7 +22,11 @@ package org.navalplanner.web.resources.machine;
import java.util.List;
import org.hibernate.validator.ClassValidator;
import org.hibernate.validator.InvalidValue;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.resources.daos.IMachineDAO;
import org.navalplanner.business.resources.daos.IResourceDAO;
import org.navalplanner.business.resources.entities.Machine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
@ -37,13 +41,40 @@ import org.springframework.transaction.annotation.Transactional;
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class MachineModel implements IMachineModel {
@Autowired
IResourceDAO resourceDAO;
@Autowired
IMachineDAO machineDAO;
private Machine machine;
private ClassValidator<Machine> validator = new ClassValidator<Machine>(Machine.class);
@Override
public void initCreate() {
machine = Machine.create();
}
@Override
@Transactional(readOnly = true)
public List<Machine> getMachines() {
return machineDAO.getAll();
}
@Override
public Machine getMachine() {
return machine;
}
@Override
@Transactional
public void confirmSave() throws ValidationException {
InvalidValue[] invalidValues = validator.getInvalidValues(getMachine());
if (invalidValues.length > 0) {
throw new ValidationException(invalidValues);
}
resourceDAO.save(machine);
}
}

View file

@ -0,0 +1,68 @@
<!--
This file is part of ###PROJECT_NAME###
Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
Desenvolvemento Tecnolóxico de Galicia
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<window id="editWindow" >
<tabbox>
<tabs>
<tab label="${i18n:_('Machine data')}"></tab>
<tab label="${i18n:_('Assigned criterions')}"></tab>
<tab label="${i18n:_('Calendar')}"></tab>
<tab label="${i18n:_('Configuration')}"></tab>
</tabs>
<tabpanels>
<tabpanel>
<grid fixedLayout="true">
<columns>
<column width="200px" />
<column />
</columns>
<rows>
<row>
<label value="${i18n:_('Code')}" />
<textbox
value="@{controller.machine.code}" constraint="no empty" width="500px"/>
</row>
<row>
<label value="${i18n:_('Name')}" />
<textbox
value="@{controller.machine.name}" constraint="no empty" width="500px"/>
</row>
<row>
<label value="${i18n:_('Description')}" />
<textbox
value="@{controller.machine.description}" constraint="no empty" width="500px"/>
</row>
</rows>
</grid>
</tabpanel>
<tabpanel>
<!-- Assigned criterions -->
</tabpanel>
<tabpanel visible="false">
<!-- Calendar -->
</tabpanel>
<tabpanel visible="false">
<!-- Configuration-->
</tabpanel>
</tabpanels>
</tabbox>
<button label="${i18n:_('Save')}" onClick="controller.save();" />
<button label="${i18n:_('Cancel')}" onClick="controller.cancel();" />
</window>

View file

@ -27,9 +27,7 @@
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?component name="list" inline="true" macroURI="_listMachines.zul"?>
<!--
<?component name="edition" inline="true" macroURI="_editMachine.zul"?>
-->
<zk>
<window self="@{define(content)}"
@ -37,8 +35,6 @@
sclass="machinewindow">
<vbox id="messagesContainer" />
<list id="listWindow" />
<!--
<edition id="editWindow" />
-->
</window>
</zk>