It changes the way to edit/create the entity sequences
FEA : ItEr64S06NavalPlanEntities
This commit is contained in:
parent
07cea17fdb
commit
d631b20b3d
6 changed files with 169 additions and 131 deletions
|
|
@ -49,6 +49,11 @@ public class EntitySequence extends BaseEntity {
|
|||
return create(new EntitySequence(prefix, entityName));
|
||||
}
|
||||
|
||||
public static EntitySequence create(String prefix,
|
||||
EntityNameEnum entityName, Integer digits) {
|
||||
return create(new EntitySequence(prefix, entityName, digits));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for hibernate. Do not use!
|
||||
*/
|
||||
|
|
@ -60,6 +65,13 @@ public class EntitySequence extends BaseEntity {
|
|||
this.entityName = entityName;
|
||||
}
|
||||
|
||||
public EntitySequence(String prefix, EntityNameEnum entityName,
|
||||
Integer digits) {
|
||||
this.prefix = prefix;
|
||||
this.entityName = entityName;
|
||||
this.setNumberOfDigits(digits);
|
||||
}
|
||||
|
||||
private String prefix;
|
||||
|
||||
private EntityNameEnum entityName;
|
||||
|
|
|
|||
|
|
@ -22,9 +22,12 @@ package org.navalplanner.web.common;
|
|||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
|
|
@ -35,16 +38,18 @@ import org.navalplanner.business.common.entities.ProgressType;
|
|||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.web.common.components.bandboxsearch.BandboxSearch;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
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.event.SelectEvent;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.ArrayGroupsModel;
|
||||
import org.zkoss.zul.Button;
|
||||
import org.zkoss.zul.Combobox;
|
||||
import org.zkoss.zul.Constraint;
|
||||
import org.zkoss.zul.Grid;
|
||||
import org.zkoss.zul.Group;
|
||||
import org.zkoss.zul.Intbox;
|
||||
import org.zkoss.zul.Label;
|
||||
import org.zkoss.zul.Listbox;
|
||||
|
|
@ -53,11 +58,10 @@ import org.zkoss.zul.Messagebox;
|
|||
import org.zkoss.zul.Radio;
|
||||
import org.zkoss.zul.Row;
|
||||
import org.zkoss.zul.RowRenderer;
|
||||
import org.zkoss.zul.SimpleListModel;
|
||||
import org.zkoss.zul.Tabpanel;
|
||||
import org.zkoss.zul.Textbox;
|
||||
import org.zkoss.zul.api.Window;
|
||||
|
||||
|
||||
/**
|
||||
* Controller for {@link Configuration} entity.
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
|
|
@ -77,7 +81,15 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
|
||||
private Component messagesContainer;
|
||||
|
||||
private Tabpanel panelEntitySequences;
|
||||
private Grid entitySequencesGrid;
|
||||
|
||||
private Combobox entityCombo;
|
||||
|
||||
private Intbox numDigitBox;
|
||||
|
||||
private Textbox prefixBox;
|
||||
|
||||
private Map<EntityNameEnum, Boolean> mapOpenedGroups = new HashMap<EntityNameEnum, Boolean>();
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
|
|
@ -97,9 +109,8 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
});
|
||||
initializeProgressTypeList();
|
||||
messages = new MessagesForUser(messagesContainer);
|
||||
|
||||
createPanelEntityComponents();
|
||||
|
||||
initOpenedGroup();
|
||||
reloadEntitySequences();
|
||||
}
|
||||
|
||||
private void initializeProgressTypeList() {
|
||||
|
|
@ -134,54 +145,18 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
configurationModel.setProgressType(progressType);
|
||||
}
|
||||
|
||||
private void createPanelEntityComponents() {
|
||||
private void initOpenedGroup() {
|
||||
for (final EntityNameEnum entityName : EntityNameEnum.values()) {
|
||||
Component entitySequenceComponent = Executions.createComponents(
|
||||
"components/panelEntitySequence.zul", panelEntitySequences
|
||||
.getFellow("panelEntitySequence"),
|
||||
new HashMap<String, String>());
|
||||
initLabelInPanelSequence(entitySequenceComponent, entityName);
|
||||
initButtonInPanelSequence(entitySequenceComponent, entityName);
|
||||
initGridInPanelSequence(entitySequenceComponent, entityName);
|
||||
reloadEntitySequenceList(entityName);
|
||||
this.mapOpenedGroups.put(entityName, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void initLabelInPanelSequence(Component component,
|
||||
final EntityNameEnum entityName) {
|
||||
try {
|
||||
Label label = (Label) component.getFirstChild().getFirstChild();
|
||||
label.setValue(_(entityName.getSequenceLiteral()));
|
||||
label.invalidate();
|
||||
} catch (ClassCastException e) {
|
||||
}
|
||||
private boolean isOpenedGroup(EntityNameEnum entityName) {
|
||||
return mapOpenedGroups.get(entityName);
|
||||
}
|
||||
|
||||
private void initButtonInPanelSequence(Component component,
|
||||
final EntityNameEnum entityName) {
|
||||
try {
|
||||
Button button = (Button) component.getFirstChild().getLastChild();
|
||||
button.setLabel(_("New sequence"));
|
||||
button.addEventListener(Events.ON_CLICK, new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
addEntitySequence(entityName);
|
||||
}
|
||||
});
|
||||
} catch (ClassCastException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private void initGridInPanelSequence(Component component,
|
||||
EntityNameEnum entityName) {
|
||||
String name = entityName.getDescription();
|
||||
String id = name + "SequenceList";
|
||||
try {
|
||||
Grid grid = (Grid) component.getLastChild().getFirstChild();
|
||||
grid.setId(id);
|
||||
} catch (ClassCastException e) {
|
||||
}
|
||||
public void onOpenGroup(EntityNameEnum entityName, boolean open) {
|
||||
mapOpenedGroups.put(entityName, open);
|
||||
}
|
||||
|
||||
public List<BaseCalendar> getCalendars() {
|
||||
|
|
@ -221,9 +196,11 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
|
||||
private void reloadWindow() {
|
||||
Util.reloadBindings(configurationWindow);
|
||||
for (EntityNameEnum sequence : EntityNameEnum.values()) {
|
||||
reloadEntitySequenceList(sequence);
|
||||
}
|
||||
}
|
||||
|
||||
private void reloadEntitySequences() {
|
||||
entitySequencesGrid.setModel(getEntitySequenceModel());
|
||||
entitySequencesGrid.invalidate();
|
||||
}
|
||||
|
||||
public String getCompanyCode() {
|
||||
|
|
@ -345,7 +322,8 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
} catch (IllegalArgumentException e) {
|
||||
messages.showMessage(Level.ERROR, e.getMessage());
|
||||
}
|
||||
reloadEntitySequenceList(entitySequence.getEntityName());
|
||||
onOpenGroup(entitySequence.getEntityName(), true);
|
||||
reloadEntitySequences();
|
||||
}
|
||||
|
||||
public void setExpandCompanyPlanningViewCharts(
|
||||
|
|
@ -388,39 +366,48 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
return configurationModel.isMonteCarloMethodTabVisible();
|
||||
}
|
||||
|
||||
private void reloadEntitySequenceList(EntityNameEnum entityNameEnum) {
|
||||
String nameList = entityNameEnum.getDescription();
|
||||
Grid grid = (Grid) configurationWindow.getFellow(nameList
|
||||
+ "SequenceList");
|
||||
grid.setModel(new SimpleListModel(getEntitySequences(entityNameEnum)));
|
||||
grid.invalidate();
|
||||
}
|
||||
|
||||
public EntitySequenceRowRenderer getEntitySequenceRowRenderer() {
|
||||
return new EntitySequenceRowRenderer();
|
||||
}
|
||||
|
||||
private class EntitySequenceRowRenderer implements RowRenderer {
|
||||
|
||||
public class EntitySequenceGroupRenderer implements RowRenderer {
|
||||
@Override
|
||||
public void render(Row row, Object data) throws Exception {
|
||||
|
||||
EntitySequence entitySequence = (EntitySequence) data;
|
||||
row.setValue(entitySequence);
|
||||
final EntityNameEnum entityName = entitySequence.getEntityName();
|
||||
|
||||
appendActiveRadiobox(row, entitySequence);
|
||||
appendPrefixTextbox(row, entitySequence);
|
||||
appendNumberOfDigitsInbox(row, entitySequence);
|
||||
appendLastValueInbox(row, entitySequence);
|
||||
appendOperations(row, entitySequence);
|
||||
if (row instanceof Group) {
|
||||
final Group group = ((Group) row);
|
||||
if (!isOpenedGroup(entityName)) {
|
||||
group.setOpen(false);
|
||||
}
|
||||
group.setValue(entityName);
|
||||
group
|
||||
.appendChild(new Label(_(entityName
|
||||
.getSequenceLiteral())));
|
||||
group.addEventListener(Events.ON_OPEN, new EventListener() {
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
onOpenGroup(entityName, group.isOpen());
|
||||
}
|
||||
});
|
||||
|
||||
if (entitySequence.isAlreadyInUse()) {
|
||||
row
|
||||
.setTooltiptext(_("The code sequence is already in use and it can not be updated."));
|
||||
} else {
|
||||
|
||||
row.setValue(entitySequence);
|
||||
appendActiveRadiobox(row, entitySequence);
|
||||
appendPrefixTextbox(row, entitySequence);
|
||||
appendNumberOfDigitsInbox(row, entitySequence);
|
||||
appendLastValueInbox(row, entitySequence);
|
||||
appendOperations(row, entitySequence);
|
||||
|
||||
if (entitySequence.isAlreadyInUse()) {
|
||||
row
|
||||
.setTooltiptext(_("The code sequence is already in use and it can not be updated."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void appendActiveRadiobox(final Row row,
|
||||
final EntitySequence entitySequence) {
|
||||
|
||||
final Radio radiobox = Util.bind(new Radio(),
|
||||
new Util.Getter<Boolean>() {
|
||||
|
||||
|
|
@ -432,25 +419,20 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
|
||||
@Override
|
||||
public void set(Boolean value) {
|
||||
entitySequence.setActive(value);
|
||||
updateOtherSequences(entitySequence);
|
||||
entitySequence.setActive(value);
|
||||
Util.reloadBindings(entitySequencesGrid);
|
||||
reloadEntitySequences();
|
||||
}
|
||||
});
|
||||
|
||||
row.appendChild(radiobox);
|
||||
|
||||
if (entitySequence.isActive()) {
|
||||
radiobox.getRadiogroup().setSelectedItem(radiobox);
|
||||
radiobox.getRadiogroup().invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateOtherSequences(final EntitySequence activeSequence) {
|
||||
for (EntitySequence sequence : getEntitySequences(activeSequence
|
||||
.getEntityName())) {
|
||||
if (sequence.getId() != activeSequence.getId()) {
|
||||
sequence.setActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -538,7 +520,7 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
if (isLastOne(row)) {
|
||||
if (isLastOne(entitySequence)) {
|
||||
showMessageNotDelete();
|
||||
} else {
|
||||
removeEntitySequence(entitySequence);
|
||||
|
|
@ -598,20 +580,22 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
};
|
||||
}
|
||||
|
||||
public void addEntitySequence(EntityNameEnum entityName) {
|
||||
configurationModel.addEntitySequence(entityName);
|
||||
reloadEntitySequenceList(entityName);
|
||||
public void addEntitySequence(EntityNameEnum entityName, String prefix,
|
||||
Integer digits) {
|
||||
configurationModel.addEntitySequence(entityName, prefix, digits);
|
||||
onOpenGroup(entityName, true);
|
||||
reloadEntitySequences();
|
||||
}
|
||||
|
||||
public List<EntitySequence> getEntitySequences(EntityNameEnum entityName) {
|
||||
return configurationModel.getEntitySequences(entityName);
|
||||
}
|
||||
|
||||
private boolean isLastOne(final Row row) {
|
||||
return (row.getGrid().getRows().getChildren().size() == 1);
|
||||
private boolean isLastOne(EntitySequence sequence) {
|
||||
return (getEntitySequences(sequence.getEntityName()).size() == 1);
|
||||
}
|
||||
|
||||
public void showMessageNotDelete() {
|
||||
private void showMessageNotDelete() {
|
||||
try {
|
||||
Messagebox
|
||||
.show(
|
||||
|
|
@ -622,4 +606,51 @@ public class ConfigurationController extends GenericForwardComposer {
|
|||
messages.showMessage(Level.ERROR, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public class EntitySequenceComparator implements Comparator {
|
||||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
EntitySequence seq1 = (EntitySequence) o1;
|
||||
EntitySequence seq2 = (EntitySequence) o2;
|
||||
return seq1.getEntityName().compareTo(seq2.getEntityName());
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayGroupsModel getEntitySequenceModel() {
|
||||
return new ArrayGroupsModel(getAllEntitySequences().toArray(),
|
||||
new EntitySequenceComparator());
|
||||
}
|
||||
|
||||
public EntitySequenceGroupRenderer getEntitySequenceGroupRenderer() {
|
||||
return new EntitySequenceGroupRenderer();
|
||||
}
|
||||
|
||||
private List<EntitySequence> getAllEntitySequences() {
|
||||
List<EntitySequence> allSequences = new ArrayList<EntitySequence>();
|
||||
for (final EntityNameEnum entityName : EntityNameEnum.values()) {
|
||||
allSequences.addAll(this.getEntitySequences(entityName));
|
||||
}
|
||||
return allSequences;
|
||||
}
|
||||
|
||||
public void addNewEntitySequence() {
|
||||
if (entityCombo != null && numDigitBox != null) {
|
||||
if (entityCombo.getSelectedItem() == null) {
|
||||
throw new WrongValueException(entityCombo,
|
||||
_("Select entity, please"));
|
||||
}
|
||||
|
||||
try {
|
||||
addEntitySequence((EntityNameEnum) entityCombo
|
||||
.getSelectedItem().getValue(), prefixBox.getValue(),
|
||||
numDigitBox.getValue());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new WrongValueException(numDigitBox, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public EntityNameEnum[] getEntityNames() {
|
||||
return EntityNameEnum.values();
|
||||
}
|
||||
}
|
||||
|
|
@ -501,9 +501,11 @@ public class ConfigurationModel implements IConfigurationModel {
|
|||
return entitySequences.get(entityName);
|
||||
}
|
||||
|
||||
public void addEntitySequence(EntityNameEnum entityName) {
|
||||
public void addEntitySequence(EntityNameEnum entityName, String prefix,
|
||||
Integer digits) {
|
||||
List<EntitySequence> sequences = entitySequences.get(entityName);
|
||||
EntitySequence entitySequence = EntitySequence.create("", entityName);
|
||||
EntitySequence entitySequence = EntitySequence.create(prefix,
|
||||
entityName, digits);
|
||||
if (sequences.isEmpty()) {
|
||||
entitySequence.setActive(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,10 @@ public interface IConfigurationModel {
|
|||
Boolean generateCodeForMaterialCategories);
|
||||
|
||||
List<EntitySequence> getEntitySequences(EntityNameEnum entityName);
|
||||
void addEntitySequence(EntityNameEnum entityName);
|
||||
|
||||
void addEntitySequence(EntityNameEnum entityName, String prefix,
|
||||
Integer digits);
|
||||
|
||||
void removeEntitySequence(EntitySequence entitySequence)
|
||||
throws IllegalArgumentException;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
<!--
|
||||
This file is part of NavalPlan
|
||||
|
||||
Copyright (C) 2009-2010 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/>.
|
||||
-->
|
||||
<vbox>
|
||||
<hbox valign="center">
|
||||
<label />
|
||||
<button />
|
||||
</hbox>
|
||||
<radiogroup>
|
||||
<grid fixedLayout="true" rowRenderer="@{configurationController.entitySequenceRowRenderer}" >
|
||||
<columns sizable="true">
|
||||
<column label="${i18n:_('Active')}" />
|
||||
<column label="${i18n:_('Prefix')}" />
|
||||
<column label="${i18n:_('Number of digits')}"/>
|
||||
<column label="${i18n:_('Last value')}" />
|
||||
<column label="${i18n:_('Operations')}" />
|
||||
</columns>
|
||||
</grid>
|
||||
<separator bar="false" height="15px" />
|
||||
</radiogroup>
|
||||
</vbox>
|
||||
|
|
@ -173,6 +173,33 @@
|
|||
<tabpanel id="panelEntitySequences">
|
||||
<panel border="normal" title="Entity code sequences">
|
||||
<panelchildren id="panelEntitySequence">
|
||||
<vbox>
|
||||
<hbox valign="center">
|
||||
<label value="${i18n:_('Select entity:')}"/>
|
||||
<combobox id="entityCombo" model="@{configurationController.entityNames}"
|
||||
constraint="no empty:${i18n:_('cannot be null or empty')}">
|
||||
<comboitem self="@{each=entityName}" label="@{entityName.description}" value="@{entityName}"/>
|
||||
</combobox>
|
||||
|
||||
<label value="${i18n:_('Prefix:')}"/>
|
||||
<textbox id="prefixBox" constraint="no empty:${i18n:_('cannot be null or empty')}"/>
|
||||
<label value="${i18n:_('Number of digits:')}"/>
|
||||
<intbox id="numDigitBox" value="5"
|
||||
constraint="no empty:${i18n:_('cannot be null or empty')}"/>
|
||||
<button label="${i18n:_('add')}"
|
||||
onClick="configurationController.addNewEntitySequence()"/>
|
||||
</hbox>
|
||||
<separator bar="false" height="4px" orient="vertical"/>
|
||||
<grid id="entitySequencesGrid" fixedLayout="true" height="400px" rowRenderer="@{configurationController.entitySequenceGroupRenderer}">
|
||||
<columns sizable="true">
|
||||
<column label="${i18n:_('Active')}" />
|
||||
<column label="${i18n:_('Prefix')}" />
|
||||
<column label="${i18n:_('Number of digits')}"/>
|
||||
<column label="${i18n:_('Last value')}" />
|
||||
<column label="${i18n:_('Operations')}" />
|
||||
</columns>
|
||||
</grid>
|
||||
</vbox>
|
||||
</panelchildren>
|
||||
</panel>
|
||||
</tabpanel>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue