/** * Sets the currently active {@link #editor}. This triggers any necessary updates to the UI * asynchronously. * * <p><b>Note:</b> This method should only be called when the active editor changes, e.g., via the * {@link IPartListener2} implementation in this class. * * @param activeEditor The new editor, or null to unset it. This is assumed to be a new value. */ private void setActiveEditor(ICEFormEditor activeEditor) { // If necessary, clear the contents of the view. if (editor != null) { // Clear the ResourceComponent and related UI pieces. setResourceComponent(null); // Unset the reference to the ICEResourcePage. resourcePage = null; // Unset the reference to the active editor. editor = null; } // If the new active editor is valid, update the contents of the view. if (activeEditor != null) { // ---- Determine the ResourceComponent from the editor ---- // // Create a visitor to used to find a ResourceComponent. final AtomicReference<ResourceComponent> componentRef; componentRef = new AtomicReference<ResourceComponent>(); IComponentVisitor visitor = new SelectiveComponentVisitor() { @Override public void visit(ResourceComponent component) { componentRef.set(component); } }; // Loop over the Form Components to find a ResourceComponent. Form activeForm = ((ICEFormInput) activeEditor.getEditorInput()).getForm(); for (Component i : activeForm.getComponents()) { i.accept(visitor); // Exit the loop when the first ResourceComponent is found. if (componentRef.get() != null) { break; } } // --------------------------------------------------------- // // If a ResourceComponent was found, update the known // ResourceComponent. if (componentRef.get() != null) { setResourceComponent(componentRef.get()); } // Set the reference to the new active editor and its resource page. editor = activeEditor; resourcePage = editor.getResourcePage(); } return; }
/** Tests the IPSReader */ @Test public void checkIPSReader() { // Set up where to look IProject project = projectSpace; String separator = System.getProperty("file.separator"); String filePath = System.getProperty("user.home") + separator + "ICETests" + separator + "caebatTesterWorkspace" + separator + "Caebat_Model" + separator + "example_ini.conf"; IPath fileIPath = new Path(filePath); IFile inputFile = project.getFile("Caebat_Model" + separator + "example_ini.conf"); // Create an IPSReader to test IPSReader reader = new IPSReader(); assertNotNull(reader); assertEquals(reader.getReaderType(), "IPSReader"); // Try to read in invalid INI file IFile fakeFile = null; Form form = null; form = reader.read(fakeFile); assertTrue(form == null); // Load the INI file and parse the contents into Components form = reader.read(inputFile); // Make sure we found some components ArrayList<Component> components = form.getComponents(); assertEquals(4, components.size()); DataComponent timeLoopData = (DataComponent) components.get(0); TableComponent globalConfig = (TableComponent) components.get(1); TableComponent portsTable = (TableComponent) components.get(2); MasterDetailsComponent portsMaster = (MasterDetailsComponent) components.get(3); /* --- Check the GLOBAL CONFIGURATION component --- */ String configName = "Global Configuration"; assertEquals(configName, globalConfig.getName()); assertEquals(20, globalConfig.numberOfRows()); for (int i = 0; i < 20; i++) { assertNotNull(globalConfig.getRow(i)); } /* --- Check the PORTS TABLE component --- */ String portsName = "Ports Table"; assertEquals(portsName, portsTable.getName()); assertEquals(5, portsTable.numberOfRows()); for (int i = 0; i < 5; i++) { assertNotNull(portsTable.getRow(i)); } /* --- Check the Ports Master component --- */ String masterName = "Ports Master"; assertEquals(masterName, portsMaster.getName()); assertEquals(5, portsMaster.numberOfMasters()); for (int i = 0; i < 5; i++) { assertNotNull(portsMaster.getMasterAtIndex(i)); } /* --- Check the TIME LOOP component --- */ String timeLoopName = "Time Loop Data"; assertEquals(timeLoopName, timeLoopData.getName()); assertEquals(5, timeLoopData.retrieveAllEntries().size()); for (int i = 0; i < 5; i++) { assertNotNull(timeLoopData.retrieveAllEntries().get(i)); } /* --- Test the findAll method --- */ String regex = "SIM_ROOT = .*"; String fakex = "Sassafras my mass"; ArrayList<Entry> matches = reader.findAll(inputFile, regex); ArrayList<Entry> fakes = reader.findAll(inputFile, fakex); assertEquals(fakes.size(), 0); assertEquals(matches.size(), 1); assertEquals( matches.get(0).getValue(), "SIM_ROOT = $CAEBAT_ROOT/vibe/trunk/examples/${SIM_NAME}"); // Okay good job return; }