1 package cve.osservatori; 2 3 import cve.esecutori.*; 4 import cve.core.elementEEL.*; 5 import interactionHandler.*; 6 import interactionGraphics.*; 7 import cve.osservatori.servizioOACBuildSemantic.*; 8 9 import cve.esecutori.servizioEACBuildSemantic.*; 10 import cve.staticLayout.*; 11 import cve.util.*; 12 13 import org.apache.log4j.Logger; 14 15 import java.awt.*; 16 import java.awt.event.*; 17 import java.io.File ; 18 import java.io.IOException ; 19 import java.io.*; 20 import java.util.*; 21 import javax.swing.filechooser.FileFilter ; 22 import javax.swing.*; 23 import javax.swing.tree.*; 24 25 import org.jdom.*; 26 import org.jdom.Document; 27 import org.jdom.Element; 28 import org.jdom.JDOMException; 29 import org.jdom.input.SAXBuilder; 30 import org.jdom.output.XMLOutputter; 31 32 45 public class OACBuildSemantic extends Osservatore { 46 47 50 private ControllerTree treeContr; 51 private TreeCve contSintRules; 53 private TreeCve contSemRules; 54 private TreeCve contAssSem; 55 private TreeCve contFileAssFile; 56 57 60 private SpecificationSemantic eseS; 61 62 private String fileSinRules = null; 64 private String fileSemRules = null; 65 private String fileAssSem = null; 66 private String fileAssFile = null; 67 68 private boolean sintaxRules =false; 70 private boolean semanticRules=false; 71 private boolean associationRules=false; 72 private boolean associa = true; 73 74 private ConfigurationSemantic configFrame; 75 private boolean configFrameIsOpen = false; 76 private String translationClass = new String (""); 77 78 79 80 83 public Action getRegoleSint = new AbstractAction("") { 84 public void actionPerformed(ActionEvent e) { 85 Cve.errLog.debug(""); 86 ViewLog.writeInLog(" #O# Eseguita attivita' (action) getRegoleSint"+"\n"); 87 88 fileSinRules = selectFile("Select Syntax Rules"); 91 92 93 if (fileSinRules.equals("")==false ){ 94 setSintaxRules(fileSinRules); 96 sintaxRules=true; 97 98 getRegoleSint.setEnabled(false); 100 cancRegoleSint.setEnabled(true); 101 getRegoleSem.setEnabled(true); 102 cancRegoleSem.setEnabled(false); 103 creaRegolaSem.setEnabled(true); 104 associaSemSint.setEnabled(false); 105 cancRegoleAss.setEnabled(false); 106 cancAll.setEnabled(false); 107 109 if ((sintaxRules)&&(semanticRules)){ 110 associaSemSint.setEnabled(true); 111 cancAll.setEnabled(true); 112 } 113 114 repaintAll(); 116 contSintRules.repaint(); 117 } else { 118 sintaxRules=false; 119 fileSinRules = null; 120 } 121 } 122 }; 123 124 128 public Action cancRegoleSint = new AbstractAction("") { 129 public void actionPerformed(ActionEvent e) { 130 Cve.errLog.debug(""); 131 ViewLog.writeInLog(" #O# Eseguita attivita' (action) cancRegoleSint"+"\n"); 132 delSintaxRules(); 133 134 sintaxRules=false; 135 fileSinRules = null; 136 137 if (associationRules){ 139 delAll(); 140 fileAssSem = null; 142 fileSemRules = null; 143 fileSinRules = null; 144 associationRules = false; 146 semanticRules=false; 147 sintaxRules=false; 148 associa=false; 149 impostaComandi(); 150 } else { 151 152 getRegoleSint.setEnabled(true); 154 cancRegoleSint.setEnabled(false); 155 getRegoleSem.setEnabled(true); 156 cancRegoleSem.setEnabled(false); 157 creaRegolaSem.setEnabled(true); 158 associaSemSint.setEnabled(false); 159 cancRegoleAss.setEnabled(false); 160 cancAll.setEnabled(false); 161 } 162 } 163 }; 164 165 168 public Action getRegoleSem = new AbstractAction("") { 169 public void actionPerformed(ActionEvent e) { 170 Cve.errLog.debug(""); 171 ViewLog.writeInLog(" #O# Eseguita attivita' (action) getRegoleSem"+"\n"); 172 175 fileSemRules = selectFile("Select Semantic Rules"); 176 if (fileSemRules.equals("")==false ){ 177 178 setSemanticRules(fileSemRules); 179 semanticRules=true; 180 181 getRegoleSem.setEnabled(false); 185 cancRegoleSem.setEnabled(true); 186 creaRegolaSem.setEnabled(true); 187 if ((sintaxRules)&&(semanticRules)){ 188 associaSemSint.setEnabled(true); 189 cancAll.setEnabled(true); 190 } 191 if (associationRules){ 192 cancRegoleAss.setEnabled(true); 193 cancAll.setEnabled(true); 194 } 195 repaintAll(); 196 contSemRules.repaint(); 197 } else{ 198 semanticRules=false; 199 fileSemRules = null; 200 } 201 } 202 }; 203 204 205 209 public Action cancRegoleSem = new AbstractAction("") { 210 public void actionPerformed(ActionEvent e) { 211 Cve.errLog.debug(""); 212 ViewLog.writeInLog(" #O# Eseguita attivita' (action) cancRegoleSem"+"\n"); 213 delSemanticRules(); 214 215 semanticRules=false; 216 fileSemRules = null; 217 218 getRegoleSem.setEnabled(true); 221 cancRegoleSem.setEnabled(false); 222 creaRegolaSem.setEnabled(true); 223 224 if (associationRules){ 226 delAssRules(); 227 228 associationRules = false; 229 fileAssSem = null; 230 fileAssFile = null; 231 associa=false; 232 } 233 cancAll.setEnabled(false); 234 associaSemSint.setEnabled(false); 235 } 236 }; 237 238 239 242 public Action creaRegolaSem = new AbstractAction("") { 243 public void actionPerformed(ActionEvent e) { 244 Cve.errLog.debug(""); 245 ViewLog.writeInLog(" #O# Eseguita attivita' (action) creaRegolaSem"+"\n"); 246 247 if (fileSemRules == null){ 248 252 fileSemRules = selectFile("Select Semantic Rules"); 253 254 if (fileSemRules.equals("")==false ){ 256 newSemanticTree(fileSemRules); 257 }else{ 258 fileSemRules = null; 259 semanticRules= false; 260 } 261 } 262 263 if (fileSemRules != null ){ 264 newSemanticRule(fileSemRules); 266 semanticRules=true; 267 getRegoleSem.setEnabled(false); 269 cancRegoleSem.setEnabled(true); 270 associaSemSint.setEnabled(false); 271 cancAll.setEnabled(false); 272 if ((sintaxRules)&&(semanticRules)){ 273 associaSemSint.setEnabled(true); 274 cancAll.setEnabled(true); 275 } 276 repaintAll(); 277 contSemRules.repaint(); 278 } else { 279 semanticRules=false; 280 fileSemRules = null; 281 creaRegolaSem.setEnabled(true); 282 } 283 } 284 }; 285 286 287 291 public Action associaSemSint = new AbstractAction("") { 292 public void actionPerformed(ActionEvent e) { 293 Cve.errLog.debug(""); 294 ViewLog.writeInLog(" #O# Eseguita attivita' (action) associaSemSint"+"\n"); 295 296 if (fileAssSem == null){ 298 302 fileAssSem = selectFile("Save Association Syntax-Semantic Rules in File..."); 303 304 if (fileAssSem.equals("")==false ){ 306 307 311 fileAssFile = selectFile("Save Environment in File..."); 312 313 if (fileAssFile.equals("")==false ){ 314 newAssociationTree(fileAssSem,fileAssFile); 315 } 316 }else{ 317 fileAssSem = null; 318 associationRules = false; 319 } 320 } 321 322 if (fileAssSem != null){ 323 324 associationRules = true; 325 assSemSint(); 326 associa = true; 327 cancAll.setEnabled(true); 329 } else { 330 associationRules = false; 331 fileAssSem = null; 332 associa = false; 333 associaSemSint.setEnabled(true); 334 cancAll.setEnabled(true); 335 } 336 } 337 }; 338 339 340 341 345 public Action cancRegoleAss = new AbstractAction("") { 346 public void actionPerformed(ActionEvent e) { 347 Cve.errLog.debug(""); 348 ViewLog.writeInLog(" #O# Eseguita attivita' (action) cancRegoleAss"+"\n"); 349 delAssRules(); 350 351 fileAssSem = null; 352 fileAssFile = null; 353 associationRules = false; 354 associa=false; 355 356 getRegoleSem.setEnabled(false); 358 cancRegoleSem.setEnabled(true); 359 associaSemSint.setEnabled(false); 360 cancAll.setEnabled(false); 361 creaRegolaSem.setEnabled(true); 362 363 } 364 }; 365 366 367 372 public Action openConfiguration = new AbstractAction("") { 373 public void actionPerformed(ActionEvent e) { 374 Cve.errLog.debug(""); 375 ViewLog.writeInLog(" #O# Eseguita attivita' (action) openConfiguration"+"\n"); 376 openConfigFrame(); 377 } 378 }; 379 380 381 385 public Action getAll = new AbstractAction("") { 386 public void actionPerformed(ActionEvent e) { 387 Cve.errLog.debug(""); 388 ViewLog.writeInLog(" #O# Eseguita attivita' (action) getAll"+"\n"); 389 392 fileAssFile = selectFile("Load File Environment..."); 393 394 if (fileAssFile.equals("")==false ){ 395 396 399 getAll(fileAssFile); 401 402 associationRules = true; 404 semanticRules = true; 405 sintaxRules = true; 406 associa = true; 407 408 getRegoleSint.setEnabled(false); 410 cancRegoleSint.setEnabled(true); 411 getRegoleSem.setEnabled(false); 412 cancRegoleSem.setEnabled(true); 413 creaRegolaSem.setEnabled(true); 414 associaSemSint.setEnabled(true); 415 cancRegoleAss.setEnabled(true); 416 cancAll.setEnabled(true); 417 getAll.setEnabled(true); 418 419 repaintAll(); 420 } 421 } 422 }; 423 424 428 public Action cancAll = new AbstractAction("") { 429 public void actionPerformed(ActionEvent e) { 430 Cve.errLog.debug(""); 431 ViewLog.writeInLog(" #O# Eseguita attivita' (action) cancAll"+"\n"); 432 delAll(); 433 434 fileAssSem = null; 436 fileSemRules = null; 437 fileSinRules = null; 438 439 associationRules = false; 441 semanticRules=false; 442 sintaxRules=false; 443 associa=false; 444 445 impostaComandi(); 446 } 447 }; 448 449 450 451 452 453 454 463 public OACBuildSemantic() { 464 Cve.errLog.debug(""); 465 cveCont.setLayout(new GridLayout(1,2)); 466 treeContr=new ControllerTree(); 468 470 contSintRules = new TreeCve(treeContr); 471 contSemRules = new TreeCve(treeContr); 472 contAssSem = new TreeCve(treeContr); 473 contFileAssFile = new TreeCve(treeContr); 474 475 JTabbed inputRules = new JTabbed(); 476 inputRules = (JTabbed)inputRules.addCve("Syntax Rule",contSintRules); 477 inputRules.setController(treeContr); 478 479 JTabbed outputSpe = new JTabbed(); 480 outputSpe = (JTabbed)outputSpe.addCve("Semantic Rule",contSemRules); 481 outputSpe = (JTabbed)outputSpe.addCve("Association Rule", contAssSem ); 482 outputSpe = (JTabbed)outputSpe.addCve("File Association", contFileAssFile ); 483 outputSpe.setController(treeContr); 484 485 JSplitPane splitPane = new JSplitPane(); 487 splitPane.setTopComponent( inputRules ); 488 splitPane.setBottomComponent( outputSpe ); 489 splitPane.setResizeWeight( 0.5 ); 490 splitPane.setDividerLocation( 380 ); 491 splitPane.setOneTouchExpandable( true ); 492 493 cveCont.add(splitPane, "Center" ); 495 496 499 impostaComandi(); 501 502 } 503 504 509 public void setSintaxRules(String fileScelto){ 510 Cve.errLog.debug(""); 511 eseS=(SpecificationSemantic)getEsecutore(); 512 eseS.setSintaxRules(fileScelto); 513 } 514 515 516 521 public void delSintaxRules(){ 522 Cve.errLog.debug(""); 523 eseS=(SpecificationSemantic)getEsecutore(); 524 eseS.delSintaxRules(); 525 } 526 527 528 534 public void setSemanticRules(String fileScelto){ 535 Cve.errLog.debug(""); 536 eseS=(SpecificationSemantic)getEsecutore(); 537 eseS.setSemanticRules(fileScelto); 538 } 539 540 541 545 public void delSemanticRules(){ 546 Cve.errLog.debug(""); 547 eseS=(SpecificationSemantic)getEsecutore(); 548 eseS.delSemanticRules(); 549 } 550 551 552 558 public void newSemanticTree(String fileScelto){ 559 Cve.errLog.debug(""); 560 eseS=(SpecificationSemantic)getEsecutore(); 561 eseS.newSemanticTree(fileScelto); 562 } 563 564 570 public void newSemanticRule(String fileScelto){ 571 Cve.errLog.debug(""); 572 EditorRules editor = new EditorRules("Editor Semantic Rules","//resource//EditSemRules.GIF"); 574 575 editor.setOAC(this); 577 editor.init(fileScelto); 578 579 JDesktopPane desktop; 581 desktop =Cve.getDesktop(); 582 desktop.add(editor); 583 584 try{ 585 editor.setSelected(true); 586 } catch (Exception e){} 587 } 588 589 596 public void newAssociationTree(String fileScelto, String fileAssFile){ 597 Cve.errLog.debug(""); 598 eseS=(SpecificationSemantic)getEsecutore(); 599 eseS.newAssociationTree(fileScelto, fileAssFile); 600 } 601 602 607 public void assSemSint(){ 608 609 String idRegSint = new String (); 610 String idRegSem = new String (); 611 612 Cve.errLog.debug(""); 613 DefaultMutableTreeNode regSint = contSintRules.getNode(); 615 616 DefaultMutableTreeNode regSem = contSemRules.getNode(); 618 619 String [] SintToken = (regSint.toString()).split("\\s"); 621 for (int x=0; x<SintToken.length; x++){ 622 if (SintToken[x].substring(0,2).equals("id")){ 623 idRegSint = SintToken[x].substring(3); 625 } 626 } 627 628 String [] SemToken = (regSem.toString()).split("\\s"); 630 for (int x=0; x<SemToken.length; x++){ 631 if (SintToken[x].substring(0,2).equals("id")){ 632 idRegSem = SemToken[x].substring(3); 634 } 635 } 636 637 System.out.println("#O Sint Selezionato : " + idRegSint); 638 System.out.println("#O Sem Selezionato : " + idRegSem); 639 640 if (regSint == null || regSem == null){ 642 System.out.println("Errore: Selezionare Una regola Sintattica ed Una Semantica!"); 643 }else{ 644 eseS=(SpecificationSemantic)getEsecutore(); 645 eseS.assSemSint(idRegSint, idRegSem); 646 } 647 648 } 649 650 655 public void delAssRules(){ 656 Cve.errLog.debug(""); 657 eseS=(SpecificationSemantic)getEsecutore(); 658 eseS.delAssRules(); 659 } 660 661 662 665 private void openConfigFrame(){ 666 667 Cve.errLog.debug(""); 668 if (configFrameIsOpen){ 669 try{ 670 configFrame.setSelected(true); 671 } catch (Exception e){} 672 673 }else{ 674 configFrame = new ConfigurationSemantic("Configuration Semantic","/resource/EditConfig.GIF"); 676 configFrameIsOpen = true; 677 678 configFrame.setOAC(this); 680 configFrame.init(); 681 682 JDesktopPane desktop; 684 desktop =Cve.getDesktop(); 685 desktop.add(configFrame); 686 try{ 687 configFrame.setSelected(true); 688 } catch (Exception e){} 689 } 690 691 } 692 693 698 public void setConfigFrameOpen(boolean flag){ 699 Cve.errLog.debug(""); 700 configFrameIsOpen = flag; 701 } 702 703 708 public boolean getConfigFrameOpen(){ 709 Cve.errLog.debug(""); 710 return configFrameIsOpen; 711 } 712 713 714 715 722 public void getAll(String fileScelto){ 723 Cve.errLog.debug(""); 724 eseS=(SpecificationSemantic)getEsecutore(); 725 eseS.getAll(fileScelto); 726 } 727 728 732 public void delAll(){ 733 Cve.errLog.debug(""); 734 eseS=(SpecificationSemantic)getEsecutore(); 735 eseS.delAll(); 736 } 737 738 739 public void setComponents (Collection param){ 740 Cve.errLog.debug(""); 741 } 742 743 744 746 747 752 public void setTranslationSemantic(String typeS){ 753 Cve.errLog.debug(""); 754 this.translationClass = typeS; 755 ViewLog.writeInLog(" #O Eseguita Impostazione Tipo Traduzione Semantica: "+translationClass+"\n"); 756 System.out.println(" #O Eseguita Impostazione Tipo Traduzione Semantica: "+translationClass); 757 758 eseS=(SpecificationSemantic)getEsecutore(); 759 eseS.setTranslationSemantic(translationClass); 760 761 } 762 763 768 public String getTranslationSemantic(){ 769 Cve.errLog.debug(""); 770 ViewLog.writeInLog(" #O Eseguita Lettura Tipo Traduzione Semantica: "+translationClass+"\n"); 771 System.out.println(" #O Eseguita Lettura Tipo Traduzione Semantica: "+translationClass); 772 eseS=(SpecificationSemantic)getEsecutore(); 773 774 return eseS.getTranslationSemantic(); 775 } 776 777 778 779 780 781 782 783 784 785 787 788 789 790 798 protected void react(Observable o, Object arg){ 799 Cve.errLog.debug(""); 800 if (arg instanceof SpecificationEventSem ){ 801 SpecificationEventSem speEv=(SpecificationEventSem)arg; 802 String action=speEv.getActionUser(); 803 if (action.equals("setSintaxRules")){ 804 eseS=(SpecificationSemantic)getEsecutore(); 805 ViewLog.writeInLog(" #O# Esecutore ha creato SpecificationEventSem che contiene modello Regole Sintattiche da visualizzare"+"\n"); 806 ViewLog.writeInLog(" #O# Sono in react osservatore (azione setSintaxRules)"+"\n"); 807 fileSinRules = speEv.getFileTree(); 808 contSintRules.setModel(speEv.getModelTree()); 809 } 810 if (action.equals("delSintaxRules")){ 811 eseS=(SpecificationSemantic)getEsecutore(); 812 ViewLog.writeInLog(" #O# Esecutore ha creato SpecificationEventSem per Cancellazione Regole Sintattiche"+"\n"); 813 ViewLog.writeInLog(" #O# Sono in react osservatore (azione delSintaxRules)"+"\n"); 814 contSintRules.setModel(null); 815 } 816 if (action.equals("setSemanticRules")){ 817 eseS=(SpecificationSemantic)getEsecutore(); 818 ViewLog.writeInLog(" #O# Esecutore ha creato SpecificationEventSem che contiene modello Regole Semantiche da visualizzare"+"\n"); 819 ViewLog.writeInLog(" #O# Sono in react osservatore (azione setSemanticRules)"+"\n"); 820 fileSemRules = speEv.getFileTree(); 821 contSemRules.setModel(speEv.getModelTree()); 822 } 823 if (action.equals("delSemanticRules")){ 824 eseS=(SpecificationSemantic)getEsecutore(); 825 ViewLog.writeInLog(" #O# Esecutore ha creato SpecificationEventSem per Cancellazione Regole Semantiche"+"\n"); 826 ViewLog.writeInLog(" #O# Sono in react osservatore (azione delSemanticRules)"+"\n"); 827 contSemRules.setModel(null); 828 } 829 if (action.equals("setAssociationSemantic")){ 831 eseS=(SpecificationSemantic)getEsecutore(); 832 ViewLog.writeInLog(" #O# Esecutore ha creato SpecificationEventSem che contiene il modello aggiornato Associazione Sintassi-Semantica"+"\n"); 833 ViewLog.writeInLog(" #O# Sono in react osservatore (azione setAssociationSemantic)"+"\n"); 834 if (associationRules) { 835 contAssSem.setModel(null); 836 837 } 838 fileAssSem = speEv.getFileTree(); 839 contAssSem.setModel(speEv.getModelTree()); 840 } 841 if (action.equals("setAssociationFile")){ 843 eseS=(SpecificationSemantic)getEsecutore(); 844 ViewLog.writeInLog(" #O# Esecutore ha creato SpecificationEventSem che contiene il modello aggiornato Associazione File Sintassi-Semantica"+"\n"); 845 ViewLog.writeInLog(" #O# Sono in react osservatore (azione setAssociationFile)"+"\n"); 846 if (associationRules) { 847 contFileAssFile.setModel(null); 848 } 849 fileAssFile = speEv.getFileTree(); 850 contFileAssFile.setModel(speEv.getModelTree()); 851 } 852 853 if (action.equals("delAssRules")){ 854 eseS=(SpecificationSemantic)getEsecutore(); 855 ViewLog.writeInLog(" #O# Esecutore ha creato SpecificationEventSem per Cancellazione Associazione Regole"+"\n"); 856 ViewLog.writeInLog(" #O# Sono in react osservatore (azione delAssRules)"+"\n"); 857 if (associationRules) { 858 contAssSem.setModel(null); 859 contFileAssFile.setModel(null); 860 } 861 } 862 if (action.equals("delAll")){ 868 eseS=(SpecificationSemantic)getEsecutore(); 869 ViewLog.writeInLog(" #O# Esecutore ha creato SpecificationEventSem per Cancellazione Ambiente di Lavoro"+"\n"); 870 ViewLog.writeInLog(" #O# Sono in react osservatore (azione delAll)"+"\n"); 871 if (sintaxRules) contSintRules.setModel(null); 872 if (semanticRules) contSemRules.setModel(null); 873 if (associationRules) { 874 contAssSem.setModel(null); 875 contFileAssFile.setModel(null); 876 } 877 } 878 repaintAll(); 879 ViewLog.writeInLog(" "+"\n"); 880 } 881 } 882 883 884 885 886 887 890 private void impostaComandi(){ 891 Cve.errLog.debug(""); 892 getRegoleSint.setEnabled(true); 893 cancRegoleSint.setEnabled(false); 894 getRegoleSem.setEnabled(true); 895 cancRegoleSem.setEnabled(false); 896 creaRegolaSem.setEnabled(true); 897 associaSemSint.setEnabled(false); 898 cancRegoleAss.setEnabled(false); 899 cancAll.setEnabled(false); 900 } 901 902 private String selectFile(String title) 904 { 905 Cve.errLog.debug(""); 906 JFileChooser chooser = new JFileChooser(); 908 chooser.setCurrentDirectory(new File (ConfigurationRead.getCveRoot()+ ConfigurationRead.getCveWSpeRoot())); 909 javax.swing.filechooser.FileFilter filter = new ClassFileFilter("xml","XML File (*xml)"); 910 chooser.addChoosableFileFilter( filter ); 911 chooser.setFileFilter(filter); 912 chooser.setDialogTitle(title); 913 914 JDesktopPane desktop; 915 desktop =Cve.getDesktop(); 916 917 int result = chooser.showOpenDialog(desktop); 918 if(result == JFileChooser.APPROVE_OPTION) 919 { 920 File file = chooser.getSelectedFile(); 921 return file.getAbsolutePath(); 922 } 923 return ""; 925 } 926 927 928 929 } | Popular Tags |