From 7d3df6366867d407cff1b6b93b87e9b1241d8afb Mon Sep 17 00:00:00 2001 From: gleimar Date: Fri, 25 Jul 2014 12:28:05 +0000 Subject: [PATCH] [fixes bug#5532] git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@36823 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../menu/MenuFactoryPropertiesImpl.java | 142 ++++++++++++------ .../segopcional/SubMenuSegOpcional.java | 16 ++ web/WEB-INF/i3-label_es_MX.label | 1 + web/WEB-INF/i3-label_pt_BR.label | 1 + 4 files changed, 110 insertions(+), 50 deletions(-) create mode 100644 src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/tarifas/segopcional/SubMenuSegOpcional.java diff --git a/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/MenuFactoryPropertiesImpl.java b/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/MenuFactoryPropertiesImpl.java index b32e58741..7e00785fc 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/MenuFactoryPropertiesImpl.java +++ b/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/MenuFactoryPropertiesImpl.java @@ -6,8 +6,8 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; -import java.util.Properties; +import org.apache.commons.lang.StringUtils; import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; @@ -25,11 +25,14 @@ public class MenuFactoryPropertiesImpl implements MenuFactory { private List tree = new ArrayList();// Una lista con los itens del menu private BufferedReader menuReader; // El reader para leer el properties como un archivo texto - private Properties miProperties; // El properties cargado normalmente. Asi se puede ocupar con las claves, etc private Desktop desktop; // Desktop de la aplicación private List listUsuarioPerfil;// El perfil del usuario private List listClavesPermisos; + public MenuFactoryPropertiesImpl() { + + } + public MenuFactoryPropertiesImpl(Desktop desktop, List listUsuarioPerfil) { super(); this.desktop = desktop; @@ -59,7 +62,7 @@ public class MenuFactoryPropertiesImpl implements MenuFactory { this.contruir(null); for (No no : tree) { - String klass = miProperties.getProperty(no.getNombre()); + String klass = no.getKlass(); Menu menu = this.createMenu(klass); menuBar.appendChild(menu); @@ -80,7 +83,7 @@ public class MenuFactoryPropertiesImpl implements MenuFactory { */ private void contruirMenus(No no, Menu menu) { for (No noH : no.getHijos()) { - String klass = miProperties.getProperty(noH.getNombre()); + String klass = noH.getKlass(); if (noH.getHijos().isEmpty()) { Menupopup menupopup = menu.getMenupopup(); if (menupopup == null) { @@ -96,7 +99,7 @@ public class MenuFactoryPropertiesImpl implements MenuFactory { nuevoMenupopup.appendChild(menuHijo); Menupopup menupopup = menu.getMenupopup(); - menupopup.appendChild(nuevoMenupopup); + menupopup.appendChild(menuHijo); contruirMenus(noH, menuHijo); } } @@ -109,40 +112,34 @@ public class MenuFactoryPropertiesImpl implements MenuFactory { * @throws IOException */ public void contruir(No noPadre) throws IOException { - String linea = menuReader.readLine(); - - if (linea == null) { - return; - } - - String[] arregloLinea = linea.split("="); - - if (noPadre == null) { - No padre = new No(arregloLinea[0]); - tree.add(padre); - this.contruir(padre); - } else { - No hijo = new No(arregloLinea[0]); - - if (hijo.getNivel() == 1) { - tree.add(hijo); - contruir(hijo); - return; - } - if ((noPadre.getNivel() + 1) == hijo.getNivel()) { - noPadre.add(hijo); - contruir(hijo); - } else { - for (No no : tree) { - if (((no.getNivel() + 1) == hijo.getNivel()) && (hijo.getNombre().startsWith(no.getNombre()))) { - no.add(hijo); - contruir(no); + String linea = null; + + while((linea = menuReader.readLine()) != null){ + No no = new No(linea); + + if (no.getNivel() == 1){ + tree.add(no); + }else{ + for(No n1: tree){ + if (adicionarFilho(no, n1)){ break; - } } } } + + } + private boolean adicionarFilho(No noHijo,No noPadre){ + boolean encontrou = false; + if (noPadre.getNombre().equals(noHijo.getPadre())){ + noPadre.getHijos().add(noHijo); + encontrou=true; + }else{ + for(No n1 : noPadre.getHijos()){ + encontrou=adicionarFilho(noHijo, n1); + } + } + return encontrou; } /** @@ -156,9 +153,6 @@ public class MenuFactoryPropertiesImpl implements MenuFactory { if (item != null) { Menu j = new Menu(item.getDescItemMenu()); -// if (item.getClaveMenu() != null) { não é usado. O arquivo de menu que deve controlar isso -// j.setVisible(listClavesPermisos.contains(item.getClaveMenu())); -// } return j; } return null; @@ -203,8 +197,6 @@ public class MenuFactoryPropertiesImpl implements MenuFactory { classe = (ItemMenuSistema) c.newInstance(); classe.setDesktop(desktop); - // Constructor constructor = c.getConstructor(new Class[]{Desktop.class}); - // classe = (ItemMenuSistema) constructor.newInstance(Executions.getCurrent().getDesktop()); } catch (ClassNotFoundException e) { throw new MenuNoExisteException("El menu " + strClass + " no fue encontrado.", e); } catch (InstantiationException e) { @@ -224,11 +216,6 @@ public class MenuFactoryPropertiesImpl implements MenuFactory { private void cargarMenuProperties() throws IOException { InputStream miStream = this.getClass().getResourceAsStream("/com/rjconsultores/ventaboletos/web/cliente/menu/menu.properties"); menuReader = new BufferedReader(new InputStreamReader(miStream)); - - InputStream miStream2 = this.getClass().getResourceAsStream("/com/rjconsultores/ventaboletos/web/cliente/menu/menu.properties"); - - miProperties = new Properties(); - miProperties.load(miStream2); } /** @@ -237,13 +224,27 @@ public class MenuFactoryPropertiesImpl implements MenuFactory { * @author gleimar * */ - public class No { + public static class No { String nombre; List hijos; + String klass; + String padre; + String path; - public No(String nombre) { - this.nombre = nombre; - this.hijos = new ArrayList(); + public No(String linea){ + hijos = new ArrayList();; + String[] arrayLinea = linea.split("="); + + path=arrayLinea[0]; + klass=arrayLinea[1]; + + String[] tmp = path.split("\\."); + if (tmp.length != 1){ + padre = tmp[tmp.length-2]; + nombre = tmp[tmp.length-1]; + }else{ + nombre = tmp[0]; + } } public No(String nombre, String hijo) { @@ -280,9 +281,50 @@ public class MenuFactoryPropertiesImpl implements MenuFactory { } public int getNivel() { - return nombre.split("\\.").length; + return path.split("\\.").length; } - } + public String getKlass() { + return klass; + } + public void setKlass(String klass) { + this.klass = klass; + } + + public String getPadre() { + return padre; + } + + + + } + public void print(){ + Integer nivel = 1; + for(No n : tree){ + System.out.println(StringUtils.repeat("*", nivel)+n.getNombre()); + print(n, nivel); + } + } + private void print(No n,Integer nivel){ + int mNivel = nivel+1; + for(No n1 : n.getHijos()){ + System.out.println(StringUtils.repeat("*", mNivel)+n1.getNombre()); + if (!n1.getHijos().isEmpty()){ + print(n1, mNivel); + } + } + } + public static void main(String args[]){ + try { + MenuFactoryPropertiesImpl menuFactoryTestes = new MenuFactoryPropertiesImpl(); + menuFactoryTestes.cargarMenuProperties(); + menuFactoryTestes.contruir(null); + menuFactoryTestes.print(); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } diff --git a/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/tarifas/segopcional/SubMenuSegOpcional.java b/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/tarifas/segopcional/SubMenuSegOpcional.java new file mode 100644 index 000000000..b637fa0f1 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/tarifas/segopcional/SubMenuSegOpcional.java @@ -0,0 +1,16 @@ +package com.rjconsultores.ventaboletos.web.utilerias.menu.item.tarifas.segopcional; + +import com.rjconsultores.ventaboletos.web.utilerias.menu.DefaultItemMenuSistema; + +public class SubMenuSegOpcional extends DefaultItemMenuSistema { + + public SubMenuSegOpcional() { + super("indexController.mnSubSegOpcional.label"); + } + + @Override + public String getClaveMenu() { + return "COM.RJCONSULTORES.ADMINISTRACION.GUI.TARIFAS"; + } + +} diff --git a/web/WEB-INF/i3-label_es_MX.label b/web/WEB-INF/i3-label_es_MX.label index 1adde78eb..9216a01bc 100644 --- a/web/WEB-INF/i3-label_es_MX.label +++ b/web/WEB-INF/i3-label_es_MX.label @@ -88,6 +88,7 @@ indexController.mnConfiguracionesComerciales.label = Configuración comercial indexController.mnEsquemaOperacional.label = Esquema operacional indexController.mnPricing.label = Pricing indexController.mnTarifas.label = Adm. de precio +indexController.mnSubSegOpcional.label= Seg. Opcional indexController.mnTarifasOficial.label = Cálculo de precio indexController.mnSendaAmigo.label = Pasajero frecuente indexController.mniMarcas.label = Marcas diff --git a/web/WEB-INF/i3-label_pt_BR.label b/web/WEB-INF/i3-label_pt_BR.label index 54354a46c..d78f8bff6 100644 --- a/web/WEB-INF/i3-label_pt_BR.label +++ b/web/WEB-INF/i3-label_pt_BR.label @@ -90,6 +90,7 @@ indexController.mnConfiguracionesComerciales.label = Configuração Comercial indexController.mnEsquemaOperacional.label = Esquema Operacional indexController.mnPricing.label = Pricing indexController.mnTarifas.label = Adm. de Preço +indexController.mnSubSegOpcional.label= Seg. Opcional indexController.mnTarifasOficial.label = Cálculo de Preço indexController.mnSendaAmigo.label = Passageiro Frequente indexController.mniMarcas.label = Marcas