View Javadoc

1   /*
2    * Criado em 16/02/2005
3    */ 
4   package ecar.taglib.util;
5   
6   import java.util.ArrayList;
7   import java.util.Collection;
8   import java.util.Collections;
9   import java.util.Iterator;
10  import java.util.List;
11  import java.util.Set;
12  
13  import javax.servlet.http.HttpServletRequest;
14  import javax.servlet.jsp.JspException;
15  import javax.servlet.jsp.JspWriter;
16  import javax.servlet.jsp.tagext.TagSupport;
17  
18  
19  import comum.util.Pagina;
20  
21  import ecar.dao.AbaDao;
22  import ecar.dao.PontoCriticoDao;
23  import ecar.exception.ECARException;
24  import ecar.pojo.Aba;
25  import ecar.pojo.AcompReferenciaItemAri;
26  import ecar.pojo.UsuarioUsu;
27  import ecar.util.Dominios;
28  
29  /** 
30   * @author felipev
31   *
32   */
33  public class BarraLinksRegAcompTag extends TagSupport{
34      
35      /**
36  	 * 
37  	 */
38  	private static final long serialVersionUID = -6728974818698770839L;
39  
40  	private AcompReferenciaItemAri acompReferenciaItem;
41      private UsuarioUsu usuario;
42      private String selectedFuncao;
43      private AcompReferenciaItemAri acompReferenciaItemSubNivel;
44      private String primeiroAcomp;
45      private HttpServletRequest request;
46      private String tela;
47      private Set gruposUsuario;
48      private String abaSuperior=Dominios.NAO;
49      
50      private String listaGeral;
51      
52      //private String srcImg;
53  
54      private static final String PATH_ACOMP = "/regAcompanhamento/elabAcompanhamento/";
55  
56  
57  	/**
58       * Inicializa a montagem da tag para ser adicionada na tela de HTML.<br>
59       * 
60       * @author N/C
61  	 * @since N/C
62  	 * @version N/C
63  	 * @return int
64  	 * @throws JspException
65       */
66  	@Override
67  	public int doStartTag() throws JspException {
68  
69          JspWriter writer = this.pageContext.getOut();
70          try {
71          	StringBuffer s = new StringBuffer();
72          	String link ="";
73          	String linkPrimeiro = "";
74          	//srcImg = "";
75          	s.append("<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" id=\"abas\"><tr><td>");
76  			
77  			/* Aba de resumo é fixa, não está no banco */
78          	String situacaoAba = "abadesabilitada";
79          	
80          	        	          
81          	//Aba RELACAO - Ficará isolada na aba superior
82          	//if("RELACAO".equals(selectedFuncao))
83              
84          	if (abaSuperior == null || getAbaSuperior().equals(Dominios.NAO)){
85  	        	if("RESUMO".equals(selectedFuncao))
86  	                situacaoAba = "abahabilitada";
87  	            
88  	            linkPrimeiro = "";
89  	            if(!"".equals(primeiroAcomp))
90  	            	linkPrimeiro = "primeiroAcomp=" + primeiroAcomp + "&";
91  	            
92  	            link = request.getContextPath() + PATH_ACOMP + "listaItens.jsp?" + linkPrimeiro + "codAcomp=" + acompReferenciaItem.getAcompReferenciaAref().getCodAref()+"&";
93  	
94  	            if(getTela() != null && !getTela().equals("") && getTela().equals("acompanhamento")) {
95  					//entra aqui no caso de ser chamado pela nova tela de monitoramento
96  	            	link = "javaScript:trocarAba('../resumo/detalharItem.jsp');";
97  	            	criaAbaMonitoramento(situacaoAba, link, "Resumo", s);
98  	            } else {
99  	            	criaAba(situacaoAba, link, "Resumo", s);
100 	            }
101         	}
102         	        	
103             /* **** FIM - Aba de relação dos Itens, é fixa não está no banco */
104             
105             //---------------------------------------------------------------------------
106             //situacaoAba = "abadesabilitada";
107             //if("PARECER".equals(selectedFuncao))
108             //    situacaoAba = "abahabilitada";
109             
110             //link = request.getContextPath() + PATH_ACOMP + "parecer.jsp?" + linkPrimeiro + "codAcomp=" + acompReferenciaItem.getAcompReferenciaAref().getCodAref()+"&";         
111             
112             //criaAba(situacaoAba, link, "Parecer", s);
113             //---------------------------------------------------------------------------
114                         
115             AbaDao abaDao = new AbaDao(null);
116 			
117             List<Aba> listAbasComAcesso = null;
118             
119             if (abaSuperior.equals("S")) {
120             	listAbasComAcesso = abaDao.getListaAbasSuperiorComAcesso(acompReferenciaItem.getAcompReferenciaAref().getTipoAcompanhamentoTa(), gruposUsuario);            	
121             } else {
122             	listAbasComAcesso = abaDao.getListaAbasComAcesso(acompReferenciaItem.getAcompReferenciaAref().getTipoAcompanhamentoTa(), gruposUsuario);
123             }
124             
125             if (listAbasComAcesso ==null)
126             	listAbasComAcesso =new ArrayList<Aba>();
127             
128             //Aba fixa LISTA GERAL
129             Aba abaListaGeral = new Aba();
130             
131             if (abaSuperior.equals("S")) {
132 	            abaListaGeral.setAbaSuperior("S");
133 	            abaListaGeral.setNomeAba("LISTA_GERAL");
134 	            abaListaGeral.setLabelAba("Lista Geral");
135 	            abaListaGeral.setOrdemAba(0);
136 	            listAbasComAcesso.add(0, abaListaGeral);
137             }
138                        
139                         
140 			for  (Iterator it = listAbasComAcesso.iterator();it.hasNext();) {
141 				Aba aba = (Aba) it.next();
142 				
143 				if (!"NIVEL_PLANEJAMENTO".equals(aba.getNomeAba())) {
144 					situacaoAba = "abadesabilitada";
145 
146 					if (selectedFuncao.equals(aba.getNomeAba())) {
147 						situacaoAba = "abahabilitada";
148 					} else if ("PONTOS_CRITICOS".equals(aba.getNomeAba())) {
149 						// verificação dos pontos críticos
150 						try {
151 							PontoCriticoDao pontoCriticoDao = new PontoCriticoDao(
152 									null);
153 							Collection pontosCriticos = Collections.EMPTY_LIST;
154 							pontosCriticos = pontoCriticoDao
155 									.getPontosCriticosNaoSolucionados(acompReferenciaItem
156 											.getItemEstruturaIett());
157 
158 							if (pontoCriticoDao
159 									.verificaDatasUltrapassadas(pontosCriticos)) {
160 								situacaoAba = "abapontocritico";
161 							}
162 						} catch (Exception e) {
163 							situacaoAba = "abadesabilitada";
164 						}
165 						// fim - verificação dos pontos críticos
166 					}
167 					// precisa melhorar isto aqui, é preciso armazenar em alguma
168 					// estrutura
169 					if(getTela() != null && !getTela().equals("") && getTela().equals("acompanhamento")) {
170 						//entra aqui no caso de ser chamado pela nova tela de monitoramento
171 						link = "";
172 						if ("DADOS_GERAIS".equals(aba.getNomeAba())) {
173 								link += "javaScript:trocarAba('../dadosGerais/frm_con.jsp');";
174 						} else if ("EVENTOS".equals(aba.getNomeAba())) {
175 							link += "javaScript:trocarAba('../realizacoes/eventos.jsp');";						
176 						} else if ("PONTOS_CRITICOS".equals(aba.getNomeAba())) {
177 							link += "javaScript:trocarAba('../restricoes/pontosCriticos.jsp');";
178 						} else if(aba.getNomeAba().equals("SITUACAO_DATAS")) {
179 							link += "javaScript:trocarAba('../situacaoDatas/situacaoDatas.jsp');";
180 						} else if ("GALERIA".equals(aba.getNomeAba())) {
181 							link += "javaScript:trocarAba('../galeria/galeria.jsp');";
182 						} else if ("FINANCEIRO".equals(aba.getNomeAba())) {
183 							link += "javaScript:trocarAba('../financeiro/financeiro.jsp');";
184 						} else if("RELACAO".equals(aba.getNomeAba())){
185 			            	link += "javascript:voltarTelaAnterior('../resumo/detalharItem.jsp');";
186 			            } else if ("REL_FISICO_IND_RESULTADO".equals(aba.getNomeAba())) {
187 							link += "javaScript:trocarAba('../resultado/indicadoresResultado.jsp');";
188 						} else if (aba.getNomeAba().equals("SITUACAO_INDICADORES")) { 
189 							link += "javaScript:trocarAba('../situacaoIndicadores/situacaoIndicadores.jsp');";
190 						}	else if ("ETAPA".equals(aba.getNomeAba())) {
191 							link += "javaScript:trocarAba('../etapa/etapas.jsp');";
192 						} else if ("DATAS_LIMITES".equals(aba.getNomeAba())) {
193 							link += "javaScript:trocarAba('../datasLimites/datasLimites.jsp');";
194 						} else if("SITUACAO".equals(aba.getNomeAba())){
195 							link += "javaScript:trocarAba('../situacao/relatorios.jsp');";
196 						} else if("GRAFICO_DE_GANTT".equals(aba.getNomeAba())){
197 							link += "javaScript:trocarAba('../graficoGantt/graficoGantt.jsp');";
198 						}
199 						else if ("LISTA_GERAL".equals(aba.getNomeAba())){
200 							//link = "javascript:voltarTelaAnterior('../posicaoGeral.jsp?mesReferencia=" + acompReferenciaItem.getAcompReferenciaAref().getCodAref()+"&periodo="+Pagina.getParamStr(request, "periodo")+"');";
201 							link += "javaScript:trocarAba('" + getListaGeral() + "');";
202 						}
203 							
204 
205 					} else {
206 						link = request.getContextPath() + PATH_ACOMP;
207 						if ("DADOS_GERAIS".equals(aba.getNomeAba())) {
208 							link += "dadosGerais/frm_con.jsp?" + linkPrimeiro;
209 						} else if ("EVENTOS".equals(aba.getNomeAba())) {
210 							link += "realizacoes/eventos.jsp?" + linkPrimeiro;
211 						} else if ("PONTOS_CRITICOS".equals(aba.getNomeAba())) {
212 							link += "pontosCriticos.jsp?" + linkPrimeiro;
213 						} else if ("GALERIA".equals(aba.getNomeAba())) {
214 							link += "galeria.jsp?" + linkPrimeiro;
215 						} else if ("FINANCEIRO".equals(aba.getNomeAba())) {
216 							link += "financeiro.jsp?" + linkPrimeiro;
217 						} else if("SITUACAO".equals(aba.getNomeAba())){
218 			            	link += "situacao.jsp?"+linkPrimeiro;
219 			            } else if ("REL_FISICO_IND_RESULTADO".equals(aba.getNomeAba())) {
220 							link += "realizadoFisico.jsp?" + linkPrimeiro;
221 						} else if ("ETAPA".equals(aba.getNomeAba())) {
222 							link += "Etapas/frm_con.jsp?" + linkPrimeiro;
223 						} else if ("DATAS_LIMITES".equals(aba.getNomeAba())) {
224 							link += "datasLimites.jsp?" + linkPrimeiro;
225 						} else if("GRAFICO_DE_GANTT".equals(aba.getNomeAba())){
226 							link += "graficoGantt/graficoGantt.jsp?" + linkPrimeiro;
227 						}		            
228 						if (acompReferenciaItemSubNivel != null) {
229 							link += "codAriSubNivel="
230 									+ acompReferenciaItemSubNivel.getCodAri() + "&";
231 						}
232 					}
233 		            
234 				}
235 		            
236 				// criaAba(situacaoAba, link, aba.getLabelAba(),s);
237 				if(getTela() != null && !getTela().equals("") && getTela().equals("acompanhamento")) {
238 					//entra aqui no caso de ser chamado pela nova tela de monitoramento
239 					criaAbaMonitoramento(situacaoAba, link, aba,s);
240 				} else {
241 					criaAba(situacaoAba, link, aba,s);
242 				}
243 			}
244         	//********************* ABA DE IMPRESSÃO FIXA **********************
245         	/* Não é para aparecer a aba relatorio impresso na aba superior, 
246 			 * mas na aba normal sim
247 			 */
248 			if (getAbaSuperior().equals(Dominios.NAO) && getTela() != null && getTela().equals("acompanhamento")) {
249 				situacaoAba = "abadesabilitada";            
250 	            if (selectedFuncao.equals("relatorioImpresso")) {	            	
251 	                situacaoAba = "abahabilitada";
252 	            }
253 	            
254 	            link = "javaScript:trocarAba('../relatorios/relatorioImpresso.jsp?tela=R');";
255 	            criaAbaMonitoramento(situacaoAba, link, "Relatório Impresso", s);
256 			}        	
257         	//*******************************************************************
258 			
259             s.append("</td></tr></table>");
260             writer.print(s.toString());
261         } catch (Exception e) {
262         	e.printStackTrace();
263         }
264         return BarraLinksRegAcompTag.SKIP_BODY;
265 
266     }
267 	
268 	
269 	/**
270 	 * Cria Aba.<br>
271 	 * 
272 	 * @author N/C
273 	 * @since N/C
274 	 * @version N/C
275 	 * @param String situacaoAba
276 	 * @param String link
277 	 * @param String label
278 	 * @param StringBuffer s
279 	 * @throws ECARException
280 	 */
281 	private void criaAba(String situacaoAba, String link, String label, StringBuffer s) throws ECARException{
282 		link += "codAri=" + acompReferenciaItem.getCodAri() + "&codAcomp=" + acompReferenciaItem.getAcompReferenciaAref().getCodAref();
283 		
284 		s.append("<table class=\"").append(situacaoAba).append("\"><tr><td nowrap>");            
285         s.append("<a href=\"").append(link).append("\">");
286         s.append(label);
287         s.append("</a>");
288         s.append("</td></tr></table>");
289     }
290 	
291 	private void criaAba(String situacaoAba, String link, Aba aba, StringBuffer s) throws ECARException{
292 		link += "codAri=" + acompReferenciaItem.getCodAri() + "&codAcomp=" + acompReferenciaItem.getAcompReferenciaAref().getCodAref();
293 		if (aba.getFuncaoFun() != null) {
294 			link += "&codAba=" + aba.getFuncaoFun().getCodFun().toString();
295 		}
296 		
297 		s.append("<table class=\"").append(situacaoAba).append("\"><tr><td nowrap>");            
298         s.append("<a href=\"").append(link).append("\">");
299         s.append(aba.getLabelAba());
300         s.append("</a>");
301         s.append("</td></tr></table>");
302     }
303 	
304 	private void criaAbaMonitoramento(String situacaoAba, String link, Aba aba, StringBuffer s) throws ECARException{	
305 		s.append("<table class=\"").append(situacaoAba).append("\"><tr><td nowrap>");            
306         s.append("<a href=\"").append(link).append("\">");
307         s.append(aba.getLabelAba());
308         s.append("</a>");
309         s.append("</td></tr></table>");
310     }
311 	
312 	private void criaAbaMonitoramento(String situacaoAba, String link, String aba, StringBuffer s) throws ECARException{	
313 		s.append("<table class=\"").append(situacaoAba).append("\"><tr><td nowrap>");            
314         s.append("<a href=\"").append(link).append("\">");
315         s.append(aba);
316         s.append("</a>");
317         s.append("</td></tr></table>");
318     }
319 
320 	/**
321 	 * Encerra Tag.<br>
322 	 * 
323 	 * @author N/C
324 	 * @since N/C
325 	 * @version N/C
326 	 * @return int
327 	 * @throws JspException
328 	 */
329     @Override
330 	public int doEndTag() throws JspException {
331         /* processa o restante da página jsp */
332         return BarraLinksRegAcompTag.EVAL_PAGE;
333     }
334 
335     public String getTela() {
336 		return tela;
337 	}
338 
339 
340 	public void setTela(String tela) {
341 		this.tela = tela;
342 	}
343 
344 	/**
345      * Retorna AcompReferenciaItemAri acompReferenciaItem.<br>
346      * 
347      * @author N/C
348 	 * @since N/C
349 	 * @version N/C
350      * @return AcompReferenciaItemAri - (Returns the acompReferenciaItem)
351      */
352     public AcompReferenciaItemAri getAcompReferenciaItem() {
353         return acompReferenciaItem;
354     }
355     /**
356      * Atribui valor especificado para AcompReferenciaItemAri acompReferenciaItem.<br>
357      * 
358      * @author N/C
359 	 * @since N/C
360 	 * @version N/C
361      * @param AcompReferenciaItemAri acompReferenciaItem - (The acompReferenciaItem to set)
362      */
363     public void setAcompReferenciaItem(AcompReferenciaItemAri acompReferenciaItem) {
364         this.acompReferenciaItem = acompReferenciaItem;
365     }
366     
367     /**
368      * Retorna valor especificado para String selectedFuncao.<br>
369      * 
370      * @author N/C
371 	 * @since N/C
372 	 * @version N/C
373      * @return String - (Returns the selectedFuncao)
374      */
375     public String getSelectedFuncao() {
376         return selectedFuncao;
377     }
378     /**
379      * Atribui valor especificado para String selectedFuncao.<br>
380      * 
381      * @author N/C
382 	 * @since N/C
383 	 * @version N/C
384      * @param String selectedFuncao - (The selectedFuncao to set)
385      */
386     public void setSelectedFuncao(String selectedFuncao) {
387         this.selectedFuncao = selectedFuncao;
388     }
389     
390     /**
391      * Retorna UsuarioUsu usuario.<br>
392      * 
393      * @author N/C
394 	 * @since N/C
395 	 * @version N/C
396      * @return UsuarioUsu - (Returns the usuario)
397      */
398     public UsuarioUsu getUsuario() {
399         return usuario;
400     }
401     
402     /**
403      * Atribui valor especificado para UsuarioUsu usuario.<br>
404      * 
405      * @author N/C
406 	 * @since N/C
407 	 * @version N/C
408      * @param UsuarioUsu usuario - (The usuario to set)
409      */
410     public void setUsuario(UsuarioUsu usuario) {
411         this.usuario = usuario;
412     }
413 
414     /**
415      * Retorna AcompReferenciaItemAri acompReferenciaItemSubNivel.<br>
416      * 
417      * @author N/C
418 	 * @since N/C
419 	 * @version N/C
420      * @return AcompReferenciaItemAri
421      */
422 	public AcompReferenciaItemAri getAcompReferenciaItemSubNivel() {
423 		return acompReferenciaItemSubNivel;
424 	}
425 
426 	/**
427 	 * Atribui valor especificado para AcompReferenciaItemAri acompReferenciaItemSubNivel.<br>
428 	 * 
429 	 * @author N/C
430 	 * @since N/C
431 	 * @version N/C
432 	 * @param AcompReferenciaItemAri acompReferenciaItemSubNivel
433 	 */
434 	public void setAcompReferenciaItemSubNivel(AcompReferenciaItemAri acompReferenciaItemSubNivel) {
435 		this.acompReferenciaItemSubNivel = acompReferenciaItemSubNivel;
436 	}
437 
438 	/**
439 	 * Retorna String primeiroAcomp.<br>
440 	 * 
441 	 * @author N/C
442 	 * @since N/C
443 	 * @version N/C
444 	 * @return String
445 	 */
446 	public String getPrimeiroAcomp() {
447 		return primeiroAcomp;
448 	}
449 
450 	/**
451 	 * Atribui valor especificado para String primeiroAcomp.<br>
452 	 * 
453 	 * @author N/C
454 	 * @since N/C
455 	 * @version N/C
456 	 * @param String primeiroAcomp
457 	 */
458 	public void setPrimeiroAcomp(String primeiroAcomp) {
459 		this.primeiroAcomp = primeiroAcomp;
460 	}
461 	
462     /**
463      * @return HttpServletRequest
464      */
465     public HttpServletRequest getRequest() {
466 		return request;
467 	}
468 
469     /**
470      * @param request 
471      */
472     public void setRequest(HttpServletRequest request) {
473 		this.request = request;
474 	}
475 
476 
477 	public void setGruposUsuario(Set gruposUsuario) {
478 		this.gruposUsuario = gruposUsuario;
479 	}
480 
481 
482 	public String getAbaSuperior() {
483 		return abaSuperior;
484 	}
485 
486 
487 	public void setAbaSuperior(String abaSuperior) {
488 		this.abaSuperior = abaSuperior;
489 	}
490 
491 
492 	public Set getGruposUsuario() {
493 		return gruposUsuario;
494 	}
495 
496 
497 	public String getListaGeral() {
498 		return listaGeral;
499 	}
500 
501 
502 	public void setListaGeral(String listaGeral) {
503 		this.listaGeral = listaGeral;
504 	}
505 
506 
507 	
508 }