Changeset 1956 for trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs
- Timestamp:
- 06/01/15 10:18:50 (9 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/commands/CMDgenerateAltIndex.java
r1946 r1956 15 15 package de.ugoe.cs.autoquest.plugin.jfc.commands; 16 16 17 import java.io.File;18 17 import java.nio.charset.Charset; 19 18 import java.nio.file.Files; … … 21 20 import java.util.Collection; 22 21 import java.util.HashMap; 22 import java.util.Iterator; 23 23 import java.util.List; 24 import java.util.logging.Level;25 24 26 25 import de.ugoe.cs.autoquest.CommandHelpers; 26 import de.ugoe.cs.autoquest.SequenceInstanceOf; 27 27 import de.ugoe.cs.autoquest.eventcore.Event; 28 28 import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; 29 29 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 30 import de.ugoe.cs.autoquest.plugin.jfc.JFCSimplifiedLogParser;31 30 import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCGUIElement; 32 31 import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCGUIElementSpec; … … 34 33 import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCMenuButton; 35 34 import de.ugoe.cs.util.console.Command; 36 import de.ugoe.cs.util.console.Console;37 35 import de.ugoe.cs.util.console.GlobalDataContainer; 38 36 … … 42 40 * </p> 43 41 * 44 * @author Steffen Herbold42 * @author Daniel May 45 43 */ 46 public class CMD parseJFCDirwithJacaretoIndicesimplements Command {44 public class CMDgenerateAltIndex implements Command { 47 45 48 46 private List<String> menuList; … … 53 51 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 54 52 */ 53 @SuppressWarnings("unchecked") 55 54 @Override 56 55 public void run(List<Object> parameters) { 57 String path;58 56 String sequencesName = "sequences"; 59 57 60 58 try { 61 path= (String) parameters.get(0);59 sequencesName = (String) parameters.get(0); 62 60 if (parameters.size() >= 2) { 63 sequencesName = (String) parameters.get(1);64 }65 if (parameters.size() >= 3) {66 61 menuList = 67 Files.readAllLines(Paths.get((String) parameters.get( 2)),62 Files.readAllLines(Paths.get((String) parameters.get(1)), 68 63 Charset.defaultCharset()); 69 64 } 70 71 65 } 72 66 catch (Exception e) { … … 74 68 } 75 69 76 File folder = new File(path); 77 if (!folder.isDirectory()) { 78 Console.printerrln(path + " is not a directory"); 70 Collection<List<Event>> sequences = null; 71 Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName); 72 if (dataObject == null) { 73 CommandHelpers.objectNotFoundMessage(sequencesName); 79 74 return; 80 75 } 81 82 JFCSimplifiedLogParser parser = new JFCSimplifiedLogParser(); 83 84 String absolutPath = folder.getAbsolutePath(); 85 for (String filename : folder.list()) { 86 String source = absolutPath + File.separator + filename; 87 Console.traceln(Level.INFO, "Processing file: " + source); 88 89 try { 90 parser.parseFile(source); 91 } 92 catch (Exception e) { 93 Console.printerrln("Could not parse " + source + ": " + e.getMessage()); 94 } 95 } 96 97 Collection<List<Event>> sequences = parser.getSequences(); 98 99 GUIModel targets = parser.getGuiModel(); 100 targets.condenseModel(); 101 102 // TODO: throw our stuff before this 103 104 generateJacaretoIndices(targets.getRootElements(), targets); 105 106 // TODO: iterate over all sequences 107 // TODO: iterate over all events in the sequences 108 // TODO: for each event: find representing node in GUI element 109 // TODO: then update altIndex 110 111 if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) { 112 CommandHelpers.dataOverwritten(sequencesName); 113 } 114 115 if (GlobalDataContainer.getInstance().addData(sequencesName + "_targets", targets)) { 116 CommandHelpers.dataOverwritten(sequencesName + "_targets"); 76 if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) { 77 CommandHelpers.objectNotType(sequencesName, "Collection<List<Event<?>>>"); 78 return; 79 } 80 sequences = (Collection<List<Event>>) dataObject; 81 GUIModel model = null; 82 83 for (List<Event> sequence : sequences) { 84 if (model == null) { 85 // generate jacareto indices for the GUI model of this sequence 86 JFCGUIElement element = (JFCGUIElement) sequence.get(0).getTarget(); 87 model = element.getGUIModel(); 88 generateJacaretoIndices(model.getRootElements(), model); 89 } 90 else { 91 for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) { 92 // find and set the alt index for every target 93 IGUIElement target = (IGUIElement) eventIter.next().getTarget(); 94 findAltIndex(target, model.getRootElements(), model); 95 } 96 } 97 } 98 } 99 100 private void findAltIndex(IGUIElement target, List<IGUIElement> elements, GUIModel model) { 101 int altIndex = ((JFCGUIElementSpec) target.getSpecification()).getAltIndex(); 102 103 if (altIndex < 0) { 104 for (IGUIElement child : elements) { 105 if (target.equals(child)) { 106 int childAltIndex = 107 ((JFCGUIElementSpec) child.getSpecification()).getAltIndex(); 108 109 if (childAltIndex > -1) { 110 ((JFCGUIElementSpec) target.getSpecification()).setAltIndex(childAltIndex); 111 } 112 else { 113 findAltIndex(target, model.getChildren(child), model); 114 } 115 } 116 else { 117 findAltIndex(target, model.getChildren(child), model); 118 } 119 } 117 120 } 118 121 }
Note: See TracChangeset
for help on using the changeset viewer.