1 package cve.esecutori; 2 3 import cve.osservatori.servizioOACesec.*; 4 5 import cve.core.elementEEL.*; 6 import cve.osservatori.*; 7 import cve.esecutori.components.specificaLV.*; 8 import cve.esecutori.servizioEACesec.*; 9 import wippog.*; import wippog.tipidato.*; 11 import wippog.event.*; 12 import wippog.eccezioni.*; 13 14 import diagrammaticLanguage.*; 15 import cve.staticLayout.*; 16 import cve.util.ConfigurationRead; 17 18 import java.awt.*; 19 import java.util.*; 20 import javax.swing.*; 21 import java.io.File ; 22 import java.io.IOException ; 23 24 import org.jdom.*; 25 import org.jdom.input.SAXBuilder; 26 import org.jdom.output.XMLOutputter; 27 28 import org.apache.log4j.Logger; 29 30 public class EACesec extends Esecutore implements IEsecutionSentence 31 { 32 35 private Vector sentence; 36 37 40 private HashMap rappresentations; 41 42 45 String fileAlf,fileSent; 46 47 50 private Vector disabButton,enableButton; 51 52 55 private String path=ConfigurationRead.getCveRoot(); 56 57 60 private String nameId; 61 62 65 Vector listaSel; 66 67 70 private WippogMachine aut; 71 72 75 private WippogMachine sent; 76 77 80 private int contestoAutoma; 81 82 private IResource queryItem; 83 84 87 private String stateError=""; 88 89 92 private int contestoSentenza; 93 94 final private static int INIT=0; 95 final private static int SELEZIONE=1; 96 final private static int TRIGGER_REL=2; 97 final private static int TRIGGER_NON_REL=3; 98 final private static int RELATION_CREATED=4; 99 final private static int QUERY=5; 100 101 private String sincronizzatoreSent,sincronizzatoreAut ; 103 private String idIstanza; 104 private int numEle=0; 105 private Collection lista=new Vector(); 106 107 108 109 112 public EACesec() { 113 Cve.errLog.debug(""); 114 sentence = new Vector(); 115 listaSel= new Vector(); 116 rappresentations=new HashMap(); 117 sincronizzatoreSent=new String (); 118 sincronizzatoreAut=new String (); 119 } 120 121 125 public Collection getSentence(){ 126 Cve.errLog.debug(""); 127 Vector sentenceClone=new Vector(); 128 Iterator itSent=sentence.iterator(); 129 while(itSent.hasNext()){ 130 ReferrableElement element=(ReferrableElement)itSent.next(); 131 ReferrableElement elementClone=(ReferrableElement)element.clone(); 132 sentenceClone.add(elementClone); 133 } 134 return sentenceClone; 135 } 136 137 146 public Collection inputTrigger(String idTipo) { 147 Cve.errLog.debug(""); 148 ViewLog.writeInLog(" "+"\n"); 149 ViewLog.writeInLog(" #E Eseguito inputTrigger del tipo "+ idTipo + "\n"); 150 151 Representation rap=(Representation)rappresentations.get(idTipo); 153 String cp=rap.getAttribute("cp"); 155 cp=path+"/"+cp; 156 String activity; 158 if (rap.getAttribute("relation").equals("true")) { contestoAutoma=TRIGGER_REL; 160 contestoSentenza=TRIGGER_REL; 161 ViewLog.writeInLog(" ->Cliccato su una relazione"+"\n"); 162 activity="activity(idType="+idTipo+")"; 165 System.out.println(" #E inputTrigger: Creazione di una Relazione: "+activity); 166 System.out.println(" #E inputTrigger: Sincronizzazione Automa di Controllo"); 167 aut.addItemGet(activity); 168 synchronized(sincronizzatoreAut) { 169 try { 170 sincronizzatoreAut.wait(); 172 } 174 catch (InterruptedException e){ 175 Cve.errLog.error(e.toString()); 176 } 177 } 178 179 System.out.println(" #E inputTrigger: Sincronizzazione Automa di Sentenza"); 180 synchronized(sincronizzatoreSent) { 181 try { sincronizzatoreSent.wait(); 183 } 185 catch (InterruptedException e){ 186 Cve.errLog.error(e.toString()); 187 } 188 } 189 } else { contestoAutoma=TRIGGER_NON_REL; 191 contestoSentenza=TRIGGER_NON_REL; 192 ViewLog.writeInLog(" #E inputTrigger: Selezionata una NON relazione: idTipo "+idTipo+"\n"); 193 activity="activity(generate="+idTipo+")"; 194 ViewLog.writeInLog(" #E inputTrigger: Creazione di una NON Relazione: "+activity+"\n"); 196 System.out.println(" #E inputTrigger: Creazione di una NON Relazione: "+activity); 197 sent.addItemGet(activity); 198 199 System.out.println(" #E inputTrigger: Sincronizzazione Automa di Controllo"); 201 synchronized(sincronizzatoreSent) { 202 try { 203 sincronizzatoreSent.wait(); 205 } 207 catch (InterruptedException e){ 208 Cve.errLog.error(e.toString()); 209 } 210 } 211 } 212 213 SentenceEvent sentEv=new SentenceEvent(); 215 sentEv.setActionUser("trigger"); 216 sentEv.setSentence(sentence); 217 ObservableCve ob=getObservable(); 218 ob.setDate(sentEv); 219 ViewLog.writeInLog(" #E inputTrigger: Fine creazione elemento"+"\n"); 220 System.out.println(" #E inputTrigger: Fine creazione elemento"); 221 return sentence; 222 } 223 224 230 public void inputSelected(String idTipo,String idIstanza, boolean select) 231 { 232 Cve.errLog.debug(""); 233 Representation rapre=(Representation)rappresentations.get(idTipo); 235 236 if (rapre.getAttribute("relation").equals("true") == false){ 237 238 ViewLog.writeInLog(" #E Eseguito inputSelected del tipo: "+ idTipo + " Istanza: " + idIstanza + " Select: " + select + "\n"); 243 System.out.println(" #E Eseguito inputSelected del tipo: "+ idTipo + " Istanza: " + idIstanza + " Select: " + select); 244 245 contestoAutoma=SELEZIONE; 246 String action=""; 247 if (select){ action="action(select=true;deselect=false;"+"idInstance="+idIstanza+";idType="+idTipo+")"; 251 ViewLog.writeInLog(" AZIONE:"+action+"\n"); 252 } 253 else { action="action(select=false;deselect=true;"+"idInstance="+idIstanza+";idType="+idTipo+")"; 257 ViewLog.writeInLog(" AZIONE:"+action+"\n"); 258 } 259 260 ViewLog.writeInLog(" #E inputSelected: AZIONE WIPPOG: "+action+"\n"); 261 System.out.println(" #E inputSelected: AZIONE WIPPOG: "+action); 262 aut.addItemGet(action); 263 synchronized(lista) { 265 try { 266 lista.wait(); 267 } 268 catch (InterruptedException e){ 269 Cve.errLog.error(e.toString()); 270 } 271 } 272 SentenceEvent sentEv=new SentenceEvent(); 273 sentEv.setActionUser("selected"); 274 sentEv.setSentence(sentence); 275 ObservableCve ob=getObservable(); 276 ob.setDate(sentEv); 277 } 279 } 280 281 286 public void inputQuery(String idTipo,String idIstanza){ 287 Cve.errLog.debug(""); 288 ViewLog.writeInLog(" #E Eseguito inputQuery tipo "+ idTipo + " idIstanza: " + idIstanza + "\n"); 289 System.out.println(" #E Eseguito inputQuery tipo "+ idTipo + " idIstanza: " + idIstanza); 290 String activity="activity(idInstance="+idIstanza+";"+"query="+idTipo+")"; 291 294 ViewLog.writeInLog(" #E inputQuery: ATTIVITA' WIPPOG: "+activity+"\n"); 295 System.out.println(" #E inputQuery: ATTIVITA' WIPPOG: "+activity); 296 297 contestoSentenza=QUERY; 298 sent.addItemGet(activity); 299 synchronized(sincronizzatoreSent) { 300 try { 301 System.out.println(" Prima di Query"); 302 sincronizzatoreSent.wait(); 303 System.out.println(" Dopo Query"); 304 } 305 catch (InterruptedException e){ 306 Cve.errLog.error(e.toString()); 307 } 308 } 309 310 System.out.println(" #E Comunicazione 'query' a OAC"); 312 SentenceEvent sentEv=new SentenceEvent(); 313 sentEv.setActionUser("query"); 314 sentEv.setSentence(sentence); 315 ObservableCve ob=getObservable(); 316 ob.setDate(sentEv); 317 } 318 319 public void setQueryItem(IResource item){ 321 Cve.errLog.debug(""); 322 this.queryItem = item; 323 } 324 325 public IResource getQueryItem(){ 327 Cve.errLog.debug(""); 328 return this.queryItem; 329 } 330 331 336 public void setStateError(String state){ 337 Cve.errLog.debug(""); 338 this.stateError = state; 339 } 340 341 346 public String getStateError(){ 347 Cve.errLog.debug(""); 348 return this.stateError; 349 } 350 351 356 public void inputModify(String id,String idIstanza){ 357 Cve.errLog.debug(""); 358 } 359 360 368 public void setLanguage(String fileAut) { 369 370 Cve.errLog.debug(""); 373 ViewLog.writeInLog(" "+"\n"); 374 ViewLog.writeInLog(" Eseguito set language esecutore-->"+fileAut+"\n"); 375 setAlfabetoSent(fileAut); 378 Vector attributiRap=new Vector(); 384 try { 385 Specifica spe=new Specifica(fileAlf); 386 rappresentations.clear(); 388 rappresentations.putAll(spe.getRappresentation()); 389 } catch (java.io.IOException e){ 390 Cve.errLog.error(e.toString()); 391 ViewLog.writeInLog(" ->nome file errato"+"\n"); 392 } 393 ViewLog.writeInLog(" ->informo osservatori dei cambiamenti"+"\n"); 394 SentenceEvent sentEv=new SentenceEvent(); 395 sentEv.setActionUser("language"); 396 sentEv.setRappresentations(rappresentations); 397 ObservableCve ob=getObservable(); 398 ob.setDate(sentEv); 399 ViewLog.writeInLog(" ->inizializzo macchina wippog automa(abilitazioni,...)"+"\n"); 400 System.out.println("1"); 401 402 contestoAutoma = INIT; 403 initWippogAutoma(fileAut); 404 System.out.println("2"); 405 aut.addItemGet("init"); 406 ViewLog.writeInLog(" ->inizializzo macchina wippog sentenza"+"\n"); 407 ViewLog.writeInLog(" ->sincronizzo le macchine wippog "+"\n"); 408 synchronized(lista) { 409 try { lista.wait();} 410 catch (InterruptedException e){ 411 Cve.errLog.error(e.toString()); 412 } 413 } 414 ViewLog.writeInLog(" ->inizializzo macchina wippog sentenza"+"\n"); 415 initWippogSentence(); 416 } 417 418 419 423 public void clearLanguage(){ 424 Cve.errLog.debug(""); 425 ViewLog.writeInLog(" #E Eseguita Pulizia Linguaggio (clearLanguage) "+"\n"); 427 System.out.println(" #E Eseguita Pulizia Linguaggio (clearLanguage) "); 428 429 sentence.clear(); 430 rappresentations.clear(); 431 ObservableCve ob=getObservable(); 432 SentenceEvent sentEv=new SentenceEvent(); 433 sentEv.setActionUser("clearLanguage"); 434 ob.setDate(sentEv); 435 } 436 437 441 public void clearSentence(){ 442 Cve.errLog.debug(""); 444 ViewLog.writeInLog(" #E Eseguita Pulizia Sentenza (clearSentence) "+"\n"); 445 System.out.println(" #E Eseguita Pulizia Sentenza (clearSentence) "); 446 sentence.clear(); 447 ObservableCve ob=getObservable(); 448 SentenceEvent sentEv=new SentenceEvent(); 449 sentEv.setActionUser("clearSentence"); 450 ob.setDate(sentEv); 451 } 452 453 456 public void rappresentationsClear(){ 457 Cve.errLog.debug(""); 458 ViewLog.writeInLog(" "+"\n"); 459 ViewLog.writeInLog(" #E Eseguita Pulizia rappresentazione"+"\n"); 460 System.out.println(" #E Eseguita Pulizia rappresentazione"); 461 rappresentations.clear(); 462 } 463 464 467 public void sentenceClear(){ 468 Cve.errLog.debug(""); 469 ViewLog.writeInLog(" #E Eseguita Pulizia Sentenza (SentenceClear) "+"\n"); 470 System.out.println(" #E Eseguita Pulizia Sentenza (SentenceClear) "); 471 sentence.clear(); 472 } 473 474 477 public Map getRappresentations(){ 478 Cve.errLog.debug(""); 479 ViewLog.writeInLog(" #E Eseguito Lettura Rappresentazioni (getRappresentations) "+"\n"); 480 System.out.println(" #E Eseguito Lettura Rappresentazioni (getRappresentations) "); 481 return rappresentations; 482 } 483 484 487 public Collection getDisableButton() { 488 Cve.errLog.debug(""); 489 ViewLog.writeInLog(" #E Eseguito Lettura Pulsanti disabilitati (getDisableButton) : "+ disabButton.toString() + "\n"); 490 System.out.println(" #E Eseguito Lettura Pulsanti disabilitati (getDisableButton) : "+ disabButton.toString()); 491 492 return disabButton; 493 } 494 495 498 public Collection getEnableButton() { 499 Cve.errLog.debug(""); 500 ViewLog.writeInLog(" #E Eseguito Lettura Pulsanti abilitati (getEnableButton) :"+enableButton.toString()+"\n"); 501 System.out.println(" #E Eseguito Lettura Pulsanti abilitati (getEnableButton) :"+enableButton.toString()+"\n"); 502 503 return enableButton; 504 } 505 506 508 509 510 518 private void setButtonState(Collection stateList,boolean enable){ 519 Cve.errLog.debug(""); 520 System.out.println(" #E setButtonState: Abilitazione: " + enable +" Elenco: "+ stateList.toString()); 522 if (enable) 523 this.enableButton=new Vector(stateList); 524 else 525 this.disabButton=new Vector(stateList); 526 } 527 528 532 private void addDrawing(ReferrableElement d){ 533 Cve.errLog.debug(""); 534 sentence.addElement(d); 535 } 536 537 538 542 private void setAlfabetoSent(String fileAut){ 543 Cve.errLog.debug(""); 544 ViewLog.writeInLog(" #E setAlfabetoSent: file Automa = "+fileSent+"\n"); 545 System.out.println(" #E setAlfabetoSent: file Automa = "+fileSent); 546 Document docAut=null; 547 try { 548 SAXBuilder builder = new SAXBuilder(false); 550 docAut = builder.build(new File (fileAut)); 551 } catch (JDOMException e) { 552 Cve.errLog.error(e.toString()); 553 } catch (Exception e) { 554 Cve.errLog.error(e.toString()); 555 } 556 Element rootAut=docAut.getRootElement(); 557 java.util.List figliAut=rootAut.getChildren("Alphabet"); 558 if ((figliAut!=null)&&(figliAut.size()>0)){ 559 Element ele=(Element)(figliAut.get(0)); fileAlf=ele.getAttributeValue("name"); 562 563 fileAlf = ConfigurationRead.getCveRoot() + ConfigurationRead.getCveVCARWRoot() + "//" + fileAlf; 565 566 ViewLog.writeInLog(" #E setAlfabetoSent: file Alfabeto = "+fileAlf+"\n"); 567 } 568 569 java.util.List figliSent=rootAut.getChildren("Sentence"); 570 if ((figliSent!=null)&&(figliSent.size()>0)){ 571 Element ele=(Element)(figliSent.get(0)); fileSent=ele.getAttributeValue("name"); 574 fileSent = ConfigurationRead.getCveRoot() + ConfigurationRead.getCveWSpeRoot() + "//" + fileSent; 576 ViewLog.writeInLog(" #E setAlfabetoSent: file Automa Sentenza = "+fileSent+"\n"); 577 578 } 579 } 580 581 584 private boolean isInListaSel(String idIst){ 585 Cve.errLog.debug(""); 586 for (int i=0;i<listaSel.size();i++){ 587 Object idIstListaO=listaSel.elementAt(i); 588 String idIstLista=idIstListaO.toString(); 589 if (idIst.equals(idIstLista)) 591 return true; 592 } 593 return false; 594 } 595 596 600 private void initWippogAutoma(String fileAut){ 601 Cve.errLog.debug(""); 602 System.out.println(" #E Inizializzazione Listener WIPPOG AUTOMA da "+fileAut); 603 try { 604 aut=WippogFactory.load(fileAut,true); 608 contestoAutoma = INIT; 609 610 aut.addWippogListener(new WippogAdapter() { 612 613 java.util.List items; 615 WippogMachine wm; 616 Collection rules; 617 Iterator itRules; 618 Transition t; 619 620 public void resourceProduced( WippogEvent event ) { 622 Cve.errLog.debug(""); 623 System.out.println(" #E <WippogAut>: Ascoltatore AUT resourceProduced"); 624 625 items=event.getResouces(); 627 wm = event.getSource(); 628 try{ 629 wm.run(); 630 } catch (WippogException e){ 631 Cve.errLog.error(e.toString()); 632 } 633 System.out.println(" #E <WippogAut>: Ascoltatore AUT resourceProduced: Passo eseguito"); 634 } 635 636 public void stepExecuted( StepEvent event ) { 638 Cve.errLog.debug(""); 641 System.out.println(" #E <WippogAut>: Ascoltatore AUT stepExecuted: Passo eseguito"); 642 643 647 648 Iterator itItems; 649 IResource item; 650 651 Thread.yield(); 653 switch (contestoAutoma) { 655 case INIT: 656 ViewLog.writeInLog(" #E <WippogAut>: INIZIALIZZAZIONE:abilitazione pulsanti"+ "\n"); 657 System.out.println(" #E <WippogAut>: INIZIALIZZAZIONE:abilitazione pulsanti"); 658 659 itItems=items.iterator(); 660 while (itItems.hasNext()){ 661 item=(IResource)itItems.next(); 662 String nameItem=item.getTypeName(); 663 if (nameItem.equals("activity")){ 665 Collection dButton=(Collection)item.getAttribute("dButton"); 666 Iterator itbut=dButton.iterator(); 667 setButtonState(dButton,false); 668 SentenceEvent sentEv=new SentenceEvent(); 669 sentEv.setActionUser("deselectButton"); 670 ObservableCve ob=getObservable(); 671 ob.setDate(sentEv); 672 } 673 } 674 synchronized( lista ) { 675 lista.notifyAll(); 676 } 677 break; 678 case SELEZIONE: 679 ViewLog.writeInLog(" #E <WippogAut>: Azione SELECT-DESELECT"+ "\n"); 680 681 itItems=items.iterator(); 682 while (itItems.hasNext()){ 683 item=(IResource)itItems.next(); 684 String nameItem=item.getTypeName(); 685 686 if (nameItem.equals("state")){ 687 String stateValue = ((Stringa)item.getAttribute("current")).toString(); 688 689 System.out.println(" #E <WippogAut>: Stato corrente: "+ stateValue); 690 691 if (stateValue.endsWith("E")){ 692 693 setStateError(stateValue); 695 696 703 }else{ 704 setStateError(""); 705 } 706 } 707 if (nameItem.equals("listaSel")){ 708 listaSel.clear(); 709 listaSel.addAll( (Collection)item.getAttribute("lista")); 710 setSelectCp(listaSel); } 712 if (nameItem.equals("activity")){ 713 Collection eButton=(Collection)item.getAttribute("eButton"); 714 Collection dButton=(Collection)item.getAttribute("dButton"); 715 if (eButton.size()>0){ 716 Iterator itbut=eButton.iterator(); 717 System.out.println(" #E pulsanti da abilitare-->"+eButton.toString()); 719 setButtonState(eButton,true); 720 SentenceEvent sentEv=new SentenceEvent(); 721 sentEv.setActionUser("selectButton"); 722 ObservableCve ob=getObservable(); 723 ob.setDate(sentEv); 724 } 725 if (dButton.size()>0){ 726 Iterator itbut=dButton.iterator(); 727 System.out.println(" #E pulsanti da disabilitare-->"+dButton.toString()); 729 setButtonState(dButton,false); 730 SentenceEvent sentEv=new SentenceEvent(); 731 sentEv.setActionUser("deselectButton"); 732 ObservableCve ob=getObservable(); 733 ob.setDate(sentEv); 734 } 735 } 736 } 737 synchronized( lista ) { lista.notifyAll(); } 738 break; 739 case TRIGGER_REL: 740 ViewLog.writeInLog(" #E <WippogAut>: creazione RELAZIONE"+ "\n"); 742 System.out.println(" #E <WippogAut>: creazione RELAZIONE"); 743 744 Iterator itItemsRel=items.iterator(); 745 while (itItemsRel.hasNext()){ 746 item=(IResource)itItemsRel.next(); 747 String nameItem=item.getTypeName(); 748 if (nameItem.equals("listaSel")){ 750 ViewLog.writeInLog(" #E <WippogAut>: Creazione relazione in specifica sentenza"+"\n"); 751 System.out.println(" #E <WippogAut>: Creazione relazione in specifica sentenza"); 752 listaSel.clear(); 753 listaSel.addAll( (Collection)item.getAttribute("lista")); 755 } 756 } 757 synchronized( sincronizzatoreAut ) { 758 sincronizzatoreAut.notifyAll(); 759 } 760 break; 761 762 case RELATION_CREATED: 763 ViewLog.writeInLog(" #E <WippogAut>: RELAZIONE CREATA"+ "\n"); 765 System.out.println(" #E <WippogAut>: RELAZIONE CREATA"); 766 767 listaSel.clear(); 768 setSelectCp(listaSel); 769 Iterator itItemsCre=items.iterator(); 770 while (itItemsCre.hasNext()){ 771 item=(IResource)itItemsCre.next(); 772 String nameItem=item.getTypeName(); 773 if (nameItem.equals("activity")){ 774 Collection dButton=(Collection)item.getAttribute("dButton"); 775 if (dButton.size()>0){ 776 Iterator itbut=dButton.iterator(); 777 setButtonState(dButton,false); 778 SentenceEvent sentEv=new SentenceEvent(); 779 sentEv.setActionUser("deselectButton"); 780 ObservableCve ob=getObservable(); 781 ob.setDate(sentEv); 782 } 783 } 784 } 785 synchronized( sincronizzatoreAut ) { 786 sincronizzatoreAut.notifyAll(); 787 } 788 break; 789 790 } } 792 } ); } catch (Exception e) { 794 Cve.errLog.error(e.toString()); 795 ViewLog.writeInLog(" #E# problemi in wippog automa"+"\n"); 796 } 797 801 } 803 804 810 private void initWippogSentence(){ 811 Cve.errLog.debug(""); 812 System.out.println(" #E Inizializzazione Listener WIPPOG SENT da "+fileSent); 813 try { 814 sent=WippogFactory.load(fileSent,true); 815 sent.addWippogListener(new WippogAdapter() { 816 817 833 834 java.util.List items; 836 WippogMachine wm; 837 Collection rules; 838 Iterator itRules; 839 Transition t; 840 841 public void exportsPerformed( WippogEvent event){ 843 844 System.out.println(" #E <WippogSentenza>: Ascoltatore SENT exportsPerformed"); 845 846 Collection idOut = (Collection)event.getResouces(); 849 if (idOut != null){ 850 851 for( Iterator itOut=idOut.iterator(); itOut.hasNext(); ) { 852 853 IResource appo_resource = (IResource)itOut.next(); 855 String appo_name = appo_resource.getTypeName(); 856 857 System.out.println("EXPORTS : elemento: " + appo_name); 858 859 if (appo_name.equals("conditionRule")){ 862 contestoAutoma = RELATION_CREATED; 863 } 864 865 } 866 } 867 868 }; 869 870 871 public void resourceProduced( WippogEvent event ) { 873 Cve.errLog.debug(""); 874 System.out.println(" #E <WippogSentenza>: Ascoltatore SENT resourceProduced"); 875 876 items=event.getResouces(); 878 wm = event.getSource(); 879 try{ 880 wm.run(); 881 } catch (WippogException e){ 882 Cve.errLog.error(e.toString()); 883 } 884 System.out.println(" #E <WippogSentenza>: Ascoltatore SENT resourceProduced: Passo eseguito"); 885 } 886 887 public void stepExecuted( StepEvent event ) { 889 Cve.errLog.debug(""); 890 System.out.println(" #E <WippogSentenza>: Ascoltatore SENT stepExecuted: Passo eseguito"); 891 892 rules = event.getRules(); 893 itRules = rules.iterator();; 894 t = (Transition)itRules.next(); 896 Thread.yield(); 898 Iterator itItems; 900 902 switch (contestoSentenza){ 903 case TRIGGER_NON_REL: 904 String idTipo=((IResource)items.get(0)).getTypeName(); 911 Representation rapre=(Representation)rappresentations.get(idTipo); 912 nameId=rapre.getAttribute("nameId"); 913 IWippogObject idIstanzaW=((IResource)items.get(0)).getAttribute(nameId); 914 915 ViewLog.writeInLog(" #E <WippogSentenza>: Creazione Elemento NON RELAZIONE: idTipo: "+ idTipo + " nameId: " +nameId+" idIstanza: " +idIstanzaW+"\n"); 916 System.out.println(" #E <WippogSentenza>: Creazione Elemento NON RELAZIONE: idTipo: "+ idTipo + " nameId: " +nameId+" idIstanza: " +idIstanzaW); 917 918 if (rapre.getAttribute("cpType").equals("icon")){ 920 String cp=path+"/"+rapre.getAttribute("cp"); 922 ComplexGraphicElement cge=new ComplexGraphicElement(); 923 ImageIcon icon=new ImageIcon(cp); 924 IconElement ge=new IconElement(icon); 926 cge.addGraficElement(ge); 927 928 VisLabel lb_id = new VisLabel("id",idIstanzaW.toString()); 931 cge.addGraficElement(lb_id); 932 933 diagrammaticLanguage.Entity ent=new diagrammaticLanguage.Entity("",idTipo,idIstanzaW.toString()); 934 ent.setComplexGraphicElement(cge); 935 addDrawing((ReferrableElement)ent); 938 } 939 if (rapre.getAttribute("cpType").equals("adj")){ 940 try { 941 Class newIstanzaVis=Class.forName(rapre.getAttribute("cp")); 942 GraphicElement ge=(GraphicElement)newIstanzaVis.newInstance(); 943 ge.setAttachZone(new BorderPlace(ge)); 944 ComplexGraphicElement cge=new ComplexGraphicElement(); 945 cge.addGraficElement(ge); 946 947 VisLabel lb_id = new VisLabel((int)ge.getX(), (int)ge.getY(), "id",idIstanzaW.toString()); 949 cge.addGraficElement(lb_id); 950 951 if (rapre.getAttribute("max_token") != null){ 953 VisLabel lb_mt = new VisLabel((int)ge.getX(), (int)ge.getY()+15, "max token","1"); 955 cge.addGraficElement(lb_mt); 956 } 957 958 959 diagrammaticLanguage.Entity ent=new diagrammaticLanguage.Entity("",idTipo,idIstanzaW.toString()); 960 ent.setComplexGraphicElement(cge); 961 965 addDrawing((ReferrableElement)ent); 966 967 } catch(InstantiationException e){ 968 Cve.errLog.error(e.toString()); 969 ViewLog.writeInLog(" #E <WippogSentenza>: newIstance() fallita creazione istanza"+"\n"); 970 } catch(IllegalAccessException e1){ 971 Cve.errLog.error(e1.toString()); 972 ViewLog.writeInLog(" #E <WippogSentenza>: newIstance() fallito accesso"+"\n"); 973 } 974 catch(ClassNotFoundException e2){ 975 Cve.errLog.error(e2.toString()); 976 ViewLog.writeInLog(" #E <WippogSentenza>: newIstance() fallita ricerca classe"+"\n"); 977 } 978 } 979 break; 980 case TRIGGER_REL: 981 ViewLog.writeInLog(" #E <WippogSentenza>: Creazione Elemento RELAZIONE"+"\n"); 982 itItems=items.iterator(); 989 while (itItems.hasNext()){ 990 IResource item=(IResource)itItems.next(); 991 idTipo=item.getTypeName(); 992 rapre=(Representation)rappresentations.get(idTipo); 994 if ((rapre!=null)&&(rapre.getAttribute("relation").equals("true"))) { nameId=rapre.getAttribute("nameId"); 996 998 idIstanzaW=item.getAttribute(nameId); 1000 ViewLog.writeInLog(" #E <WippogSentenza>: RELAZIONE idIstanza: "+idIstanzaW.toString()+" nameId: "+nameId +"\n"); 1001 System.out.println(" #E <WippogSentenza>: RELAZIONE idIstanza: "+idIstanzaW.toString()+" nameId: "+nameId); 1002 1003 if (rapre.getAttribute("cpType").equals("adj")){ 1006 try { 1007 1008 ViewLog.writeInLog(" #E <WippogSentenza>: RELAZIONE Tipo: "+idTipo+" Rappresentazione: "+rapre.getAttribute("cp")+"\n"); 1010 System.out.println(" #E <WippogSentenza>: RELAZIONE Tipo: "+idTipo+" Rappresentazione: "+rapre.getAttribute("cp")); 1011 1012 ReferrableElement source = new ReferrableElement(); 1015 ReferrableElement target = new ReferrableElement(); 1016 1017 String sourceId = listaSel.get(0).toString(); 1019 String targetId = listaSel.get(1).toString(); 1020 System.out.println(" #E <WippogSentenza>: TRIGGER_REL DA SEL: SOURCEID: "+sourceId+" TARGETID: "+targetId); 1021 1022 source=trovaDrawingDaId(sourceId); 1023 target=trovaDrawingDaId(targetId); 1024 1025 System.out.println(" #E <WippogSentenza>: TRIGGER_REL: Tipo SOURCE: "+source.getIdType()+" TARGET: "+target.getIdType()); 1026 Touches touches=new Touches(source, target); 1027 Class newIstanzaVis=Class.forName(rapre.getAttribute("cp")); 1028 1029 GraphicElement graphicRel=(GraphicElement)newIstanzaVis.newInstance(); 1030 1031 1035 ComplexGraphicElement cge=new ComplexGraphicElement(); 1036 cge.addGraficElement(graphicRel); 1037 1038 Point sourceCentre = source.getComplexGraphicElement().getCentre(); 1041 Point targetCentre = target.getComplexGraphicElement().getCentre(); 1042 1043 VisLabel lb_id2 = new VisLabel(sourceCentre, targetCentre, "id",idIstanzaW.toString(),1); 1044 cge.addGraficElement(lb_id2); 1045 1046 ReferrableConnection con=new ReferrableConnection("",idTipo,idIstanzaW.toString()); 1048 con.setComplexGraphicElement(cge); 1049 1050 con.setTouches(touches); 1051 1052 1058 addDrawing((ReferrableElement)con); 1059 } catch(InstantiationException e){ 1061 Cve.errLog.error(e.toString()); 1062 ViewLog.writeInLog(" #E <WippogSentenza>: newIstance() fallita creazione istanza"+"\n"); 1063 } catch(IllegalAccessException e1){ 1064 Cve.errLog.error(e1.toString()); 1065 ViewLog.writeInLog(" #E <WippogSentenza>: newIstance() fallito accesso"+"\n"); 1066 } catch(ClassNotFoundException e2){ 1067 Cve.errLog.error(e2.toString()); 1068 ViewLog.writeInLog(" #E <WippogSentenza>: newIstance() fallita ricerca classe"+"\n"); 1069 } 1070 1071 } 1075 } 1076 } 1077 break; 1078 case QUERY: 1079 ViewLog.writeInLog(" #E <WippogSentenza>: QUERY ELEMENT"+"\n"); 1080 System.out.println(" #E <WippogSentenza>: QUERY ELEMENT"); 1081 1082 itItems=items.iterator(); 1083 while (itItems.hasNext()){ 1084 1085 IResource item=(IResource)itItems.next(); 1086 setQueryItem(item); 1087 1088 } 1089 1090 synchronized( sincronizzatoreSent ) { 1092 System.out.println("RILASCIO RISORSE DA QUERY!!!"); 1093 sincronizzatoreSent.notifyAll(); 1094 } 1095 1096 break; 1097 } synchronized( sincronizzatoreSent ) { 1099 sincronizzatoreSent.notifyAll(); 1100 } 1101 } 1102 } ); }catch (Exception e) { 1105 Cve.errLog.error(e.toString()); 1106 ViewLog.writeInLog(" #E# problemi in wippog sentenza"+"\n"); 1107 } 1108 } 1109 1110 1114 private ReferrableElement trovaDrawingDaId(String idIstanza){ 1115 Cve.errLog.debug(""); 1116 for (int i=0;i<sentence.size();i++){ 1117 ReferrableElement d=(ReferrableElement)sentence.elementAt(i); 1118 String idIst=d.getIdInstance(); 1119 if(idIst.equals(idIstanza)){ 1120 return d; 1122 } 1123 } 1124 return null; 1125 } 1126 1127 1131 private void setSelectCp(Collection listaSel){ 1132 Cve.errLog.debug(""); 1133 for (int i=0;i<sentence.size();i++){ 1134 ReferrableElement d=(ReferrableElement)sentence.elementAt(i); 1135 String idIst=d.getIdInstance(); 1136 if(isInListaSel(idIst)){ 1137 ViewLog.writeInLog(" #E Selected Element (setSelectCp): configuro l'elemento " + idIst + " come selezionato" + "\n"); 1138 d.setSelected(true); 1139 } else { 1140 ViewLog.writeInLog(" #E Selected Element (setSelectCp): configuro l'elemento " + idIst + " come NON selezionato" + "\n"); 1141 d.setSelected(false); 1142 } 1143 } 1144 1145 SentenceEvent sentEv=new SentenceEvent(); 1146 sentEv.setActionUser("selected"); 1147 sentEv.setSentence(sentence); 1148 ObservableCve ob=getObservable(); 1149 ob.setDate(sentEv); 1150 } 1151 1152} | Popular Tags |