@Override public Component createPageComponent() { GridBagConstraints gbc = new GridBagConstraints(); final JPanel panel = new JPanel(new GridBagLayout()); gbc.anchor = GridBagConstraints.WEST; gbc.gridy = 0; gbc.gridx = 0; gbc.gridy++; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridwidth = 2; panel.add(new JLabel("URL for WMS (e.g. http://<host>/<server>):"), gbc); gbc.weightx = 1; gbc.weighty = 0; gbc.gridx = 0; gbc.gridy++; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridwidth = 1; history = new UserInputHistory(8, PROPERTY_WMS_HISTORY); history.initBy(getContext().getAppContext().getPreferences()); if (history.getNumEntries() == 0) { history.push("http://www.mapserver.niedersachsen.de/freezoneogc/mapserverogc"); history.push("http://demo.cubewerx.com/demo/cubeserv/cubeserv.cgi"); history.push("http://wms.globexplorer.com/gexservlets/wms"); } wmsUrlBox = new JComboBox(new HistoryComboBoxModel(history)); wmsUrlBox.setEditable(true); panel.add(wmsUrlBox, gbc); wmsUrlBox.addItemListener(new MyItemListener()); return panel; }
@Test public void testLoadHistory() { final PropertyMap map = new PropertyMap(); map.setPropertyString("historyItem.0", "one"); final UserInputHistory history = new UserInputHistory(3, "historyItem"); history.initBy(map); final HistoryComboBoxModel model = new HistoryComboBoxModel(history); assertEquals(1, model.getSize()); map.setPropertyString("historyItem.1", "two"); map.setPropertyString("historyItem.2", "three"); model.getHistory().initBy(map); assertEquals(3, model.getSize()); assertEquals("one", model.getElementAt(0)); assertEquals("two", model.getElementAt(1)); assertEquals("three", model.getElementAt(2)); }
@Test public void testValidation() { final PropertyMap map = new PropertyMap(); map.setPropertyString("historyItem.0", "one"); map.setPropertyString("historyItem.1", "two"); map.setPropertyString("historyItem.2", "three"); final UserInputHistory history = new UserInputHistory(3, "historyItem") { @Override protected boolean isValidItem(String item) { return "two".equals(item); } }; history.initBy(map); final HistoryComboBoxModel model = new HistoryComboBoxModel(history); assertEquals(1, model.getSize()); assertEquals("two", model.getElementAt(0)); }
@Test public void testLoadHistoryOverwritesCurrentModel() { final PropertyMap map = new PropertyMap(); map.setPropertyString("historyItem.0", "one"); final UserInputHistory history = new UserInputHistory(3, "historyItem"); history.initBy(map); final HistoryComboBoxModel model = new HistoryComboBoxModel(history); assertEquals(1, model.getSize()); model.setSelectedItem("two"); model.setSelectedItem("three"); assertEquals(3, model.getSize()); map.setPropertyString("historyItem.1", "two2"); map.setPropertyString("historyItem.2", "three3"); model.getHistory().initBy(map); assertEquals(3, model.getSize()); assertEquals("one", model.getElementAt(0)); assertEquals("two2", model.getElementAt(1)); assertEquals("three3", model.getElementAt(2)); }
@Test public void testAddElementWithInnitilaizedProperties() { final PropertyMap map = new PropertyMap(); map.setPropertyString("historyItem.0", "one"); map.setPropertyString("historyItem.1", "two"); final UserInputHistory history = new UserInputHistory(3, "historyItem"); history.initBy(map); final HistoryComboBoxModel model = new HistoryComboBoxModel(history); assertEquals(2, model.getSize()); assertEquals("one", model.getElementAt(0)); assertEquals("two", model.getElementAt(1)); model.setSelectedItem("three"); assertEquals(3, model.getSize()); assertEquals("three", model.getElementAt(0)); assertEquals("one", model.getElementAt(1)); assertEquals("two", model.getElementAt(2)); model.setSelectedItem("four"); assertEquals(3, model.getSize()); assertEquals("four", model.getElementAt(0)); assertEquals("three", model.getElementAt(1)); assertEquals("one", model.getElementAt(2)); }
history.initBy(map); final HistoryComboBoxModel model = new HistoryComboBoxModel(history); assertEquals(2, model.getSize());
assertNull(history.getEntries()); history.initBy(properties);