Search in sources :

Example 1 with VendorOptionTableModel

use of com.sldeditor.common.vendoroption.selection.VendorOptionTableModel in project sldeditor by robward-scisys.

the class VendorOptionTableModelTest method testGetVendorOption.

/**
 * Test method for
 * {@link com.sldeditor.common.vendoroption.selection.VendorOptionTableModel#getVendorOption(int)}.
 * Test method for
 * {@link com.sldeditor.common.vendoroption.selection.VendorOptionTableModel#setSelectedVendorOptionVersions(java.util.List)}.
 * Test method for
 * {@link com.sldeditor.common.vendoroption.selection.VendorOptionTableModel#getVendorOptionVersionList()}.
 */
@Test
public void testGetVendorOption() {
    Map<VendorOptionTypeInterface, String> options = new LinkedHashMap<VendorOptionTypeInterface, String>();
    VendorOptionTypeInterface vendorOption = VendorOptionManager.getInstance().getClass(GeoServerVendorOption.class);
    options.put(vendorOption, vendorOption.getName());
    VendorOptionTableModel model = new VendorOptionTableModel(options, null);
    assertEquals(1, model.getRowCount());
    // Try invalid calls to getVendorOption
    assertNull(model.getVendorOption(-1));
    assertNull(model.getVendorOption(1));
    // Valid call to getVendorOption
    List<VersionData> actualList = model.getVendorOption(0);
    assertEquals(vendorOption.getVersionList().size(), actualList.size());
    assertEquals(Localisation.getString(VendorOptionTableModel.class, "common.notSet"), actualList.get(0).getVersionString());
    model.setSelectedVendorOptionVersions(null);
    List<VersionData> selectedVersionList = new ArrayList<VersionData>();
    VersionData expectedVersionData = vendorOption.getVersionList().get(1);
    selectedVersionList.add(expectedVersionData);
    model.setSelectedVendorOptionVersions(selectedVersionList);
    actualList = model.getVendorOptionVersionList();
    assertEquals(2, actualList.size());
    assertEquals(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData(), actualList.get(0));
    assertEquals(expectedVersionData.getVersionString(), actualList.get(1).getVersionString());
    // Try with unknown
    selectedVersionList = new ArrayList<VersionData>();
    expectedVersionData = VersionData.getEarliestVersion(Double.class);
    selectedVersionList.add(expectedVersionData);
    model.setSelectedVendorOptionVersions(selectedVersionList);
    actualList = model.getVendorOptionVersionList();
    assertEquals(1, actualList.size());
    assertEquals(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData(), actualList.get(0));
}
Also used : VersionData(com.sldeditor.common.vendoroption.VersionData) ArrayList(java.util.ArrayList) VendorOptionTableModel(com.sldeditor.common.vendoroption.selection.VendorOptionTableModel) VendorOptionTypeInterface(com.sldeditor.common.vendoroption.VendorOptionTypeInterface) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 2 with VendorOptionTableModel

use of com.sldeditor.common.vendoroption.selection.VendorOptionTableModel in project sldeditor by robward-scisys.

the class VendorOptionTableModelTest method testGetColumnCount.

/**
 * Test method for
 * {@link com.sldeditor.common.vendoroption.selection.VendorOptionTableModel#getColumnCount()}.
 * Test method for
 * {@link com.sldeditor.common.vendoroption.selection.VendorOptionTableModel#getColumnName(int)}.
 * Test method for
 * {@link com.sldeditor.common.vendoroption.selection.VendorOptionTableModel#getColumnClass(int)}.
 * Test method for
 * {@link com.sldeditor.common.vendoroption.selection.VendorOptionTableModel#isCellEditable(int, int)}.
 */
@Test
public void testGetColumnCount() {
    VendorOptionTableModel model = new VendorOptionTableModel(null, null);
    assertEquals(2, model.getColumnCount());
    assertEquals(Localisation.getString(VendorOptionTableModel.class, "VendorOptionTableModel.vendor"), model.getColumnName(0));
    assertEquals(Localisation.getString(VendorOptionTableModel.class, "VendorOptionTableModel.selected"), model.getColumnName(1));
    assertEquals(String.class, model.getColumnClass(1));
    assertEquals(Object.class, model.getColumnClass(0));
    assertEquals(0, model.getRowCount());
    assertFalse(model.isCellEditable(0, 0));
    assertTrue(model.isCellEditable(0, 1));
}
Also used : VendorOptionTableModel(com.sldeditor.common.vendoroption.selection.VendorOptionTableModel) Test(org.junit.Test)

Example 3 with VendorOptionTableModel

use of com.sldeditor.common.vendoroption.selection.VendorOptionTableModel in project sldeditor by robward-scisys.

the class VendorOptionTableModelTest method testSetValueAtObjectIntInt.

/**
 * Test method for
 * {@link com.sldeditor.common.vendoroption.selection.VendorOptionTableModel#setValueAt(java.lang.Object, int, int)}.
 * Test method for
 * {@link com.sldeditor.common.vendoroption.selection.VendorOptionTableModel#setSelectedVersion(com.sldeditor.common.vendoroption.VersionData, int)}.
 */
@Test
public void testSetValueAtObjectIntInt() {
    Map<VendorOptionTypeInterface, String> options = new LinkedHashMap<VendorOptionTypeInterface, String>();
    VendorOptionTypeInterface vendorOption = VendorOptionManager.getInstance().getClass(GeoServerVendorOption.class);
    options.put(vendorOption, vendorOption.getName());
    VendorOptionTableModel model = new VendorOptionTableModel(options, null);
    assertEquals(1, model.getRowCount());
    VersionData latest = VersionData.getLatestVersion(GeoServerVendorOption.class);
    VersionData earliest = VersionData.getEarliestVersion(GeoServerVendorOption.class);
    // Invalid column
    model.setValueAt(earliest, 0, 0);
    VersionData actual = (VersionData) model.getValueAt(0, 1);
    assertEquals(latest.getVersionString(), actual.getVersionString());
    // Invalid row
    model.setValueAt(earliest, -1, 1);
    actual = (VersionData) model.getValueAt(0, 1);
    assertEquals(latest.getVersionString(), actual.getVersionString());
    model.setValueAt(earliest, 1, 1);
    actual = (VersionData) model.getValueAt(0, 1);
    assertEquals(latest.getVersionString(), actual.getVersionString());
    // Valid row
    model.setValueAt(earliest, 0, 1);
    actual = (VersionData) model.getValueAt(0, 1);
    assertEquals(earliest.getVersionString(), actual.getVersionString());
    // Try setSelectedVersion
    model.setSelectedVersion(latest, 0);
    actual = (VersionData) model.getValueAt(0, 1);
    assertEquals(latest.getVersionString(), actual.getVersionString());
}
Also used : VersionData(com.sldeditor.common.vendoroption.VersionData) VendorOptionTableModel(com.sldeditor.common.vendoroption.selection.VendorOptionTableModel) VendorOptionTypeInterface(com.sldeditor.common.vendoroption.VendorOptionTypeInterface) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 4 with VendorOptionTableModel

use of com.sldeditor.common.vendoroption.selection.VendorOptionTableModel in project sldeditor by robward-scisys.

the class VendorOptionTableModelTest method testGetValueAt.

/**
 * Test method for
 * {@link com.sldeditor.common.vendoroption.selection.VendorOptionTableModel#getValueAt(int, int)}.
 * Test method for
 * {@link com.sldeditor.common.vendoroption.selection.VendorOptionTableModel#getRowCount()}.
 */
@Test
public void testGetValueAt() {
    Map<VendorOptionTypeInterface, String> options = new LinkedHashMap<VendorOptionTypeInterface, String>();
    VendorOptionTypeInterface vendorOption = VendorOptionManager.getInstance().getClass(GeoServerVendorOption.class);
    options.put(vendorOption, vendorOption.getName());
    VendorOptionTableModel model = new VendorOptionTableModel(options, null);
    assertEquals(1, model.getRowCount());
    String actualValue1 = (String) model.getValueAt(0, 0);
    assertEquals(vendorOption.getName(), actualValue1);
    VersionData actualValue2 = (VersionData) model.getValueAt(0, 1);
    VersionData latest = VersionData.getLatestVersion(GeoServerVendorOption.class);
    assertEquals(latest.getVersionString(), actualValue2.getVersionString());
    assertNull(model.getValueAt(0, -1));
    assertNull(model.getValueAt(0, 5));
}
Also used : VersionData(com.sldeditor.common.vendoroption.VersionData) VendorOptionTableModel(com.sldeditor.common.vendoroption.selection.VendorOptionTableModel) VendorOptionTypeInterface(com.sldeditor.common.vendoroption.VendorOptionTypeInterface) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 5 with VendorOptionTableModel

use of com.sldeditor.common.vendoroption.selection.VendorOptionTableModel in project sldeditor by robward-scisys.

the class VendorOptionUI method createUI.

/**
 * Creates the UI.
 */
public void createUI() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    // Vendor options
    JPanel vendorOptionSelectionPanel = new JPanel();
    vendorOptionSelectionPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), Localisation.getString(VendorOptionUI.class, "VendorOptionUI.vendorOptions"), TitledBorder.LEADING, TitledBorder.TOP, null, null));
    vendorOptionSelectionPanel.setLayout(new BorderLayout());
    add(vendorOptionSelectionPanel);
    vendorOptionTable = new JTable();
    JScrollPane scrollPane = new JScrollPane(vendorOptionTable);
    vendorOptionSelectionPanel.add(scrollPane, BorderLayout.CENTER);
    vendorOptionSelectionPanel.setPreferredSize(new Dimension(400, 100));
    vendorOptionModel = new VendorOptionTableModel(options, getClass());
    vendorOptionTable.setModel(vendorOptionModel);
    vendorOptionTable.getColumnModel().getColumn(1).setCellRenderer(new VersionCellRenderer());
    vendorOptionTable.getColumnModel().getColumn(1).setCellEditor(new VersionCellEditor(vendorOptionModel));
    // Vendor option information
    VendorOptionInfoPanel vendorOptionInfoPanel = VendorOptionInfoManager.getInstance().getPanel(getClass());
    vendorOptionInfoPanel.setPreferredSize(new Dimension(400, 200));
    add(vendorOptionInfoPanel);
    // VendorOption present table
    JPanel voPresentPanel = new JPanel();
    voPresentPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), Localisation.getString(VendorOptionUI.class, "VendorOptionUI.loadedSymbol"), TitledBorder.LEADING, TitledBorder.TOP, null, null));
    voPresentPanel.setLayout(new BorderLayout());
    voPresentPanel.setPreferredSize(new Dimension(400, 300));
    vendorOptionPresentTable = new JTable();
    vendorOptionPresentTable.setModel(vendorOptionPresentModel);
    JScrollPane scrollPaneTable = new JScrollPane(vendorOptionPresentTable);
    voPresentPanel.add(scrollPaneTable, BorderLayout.CENTER);
    add(voPresentPanel);
    JPanel panel = new JPanel();
    voPresentPanel.add(panel, BorderLayout.SOUTH);
    panel.setLayout(new BorderLayout(0, 0));
    JPanel panel_2 = new JPanel();
    panel.add(panel_2, BorderLayout.EAST);
    JButton btnHelp = new JButton(Localisation.getString(VendorOptionUI.class, "common.help"));
    panel_2.add(btnHelp);
    btnHelp.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Help.getInstance().display(CONTEXT_HELP);
        }
    });
    JPanel panel_1 = new JPanel();
    panel.add(panel_1, BorderLayout.CENTER);
    btnLatestVO = new JButton(Localisation.getString(VendorOptionUI.class, "VendorOptionUI.latest"));
    panel_1.add(btnLatestVO);
    btnLatestVO.setEnabled(false);
    btnMinimumVendorOption = new JButton(Localisation.getString(VendorOptionUI.class, "VendorOptionUI.minimumVO"));
    panel_1.add(btnMinimumVendorOption);
    btnMinimumVendorOption.setEnabled(false);
    btnMinimumVendorOption.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vendorOptionsUpdated(vendorOptionPresentModel.getMinimum());
        }
    });
    btnLatestVO.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vendorOptionsUpdated(VendorOptionManager.getInstance().getLatest());
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) VersionCellEditor(com.sldeditor.common.vendoroption.selection.VersionCellEditor) VendorOptionInfoPanel(com.sldeditor.common.vendoroption.info.VendorOptionInfoPanel) VersionCellRenderer(com.sldeditor.common.vendoroption.selection.VersionCellRenderer) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) TitledBorder(javax.swing.border.TitledBorder) VendorOptionTableModel(com.sldeditor.common.vendoroption.selection.VendorOptionTableModel) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable)

Aggregations

VendorOptionTableModel (com.sldeditor.common.vendoroption.selection.VendorOptionTableModel)5 Test (org.junit.Test)4 VendorOptionTypeInterface (com.sldeditor.common.vendoroption.VendorOptionTypeInterface)3 VersionData (com.sldeditor.common.vendoroption.VersionData)3 LinkedHashMap (java.util.LinkedHashMap)3 VendorOptionInfoPanel (com.sldeditor.common.vendoroption.info.VendorOptionInfoPanel)1 VersionCellEditor (com.sldeditor.common.vendoroption.selection.VersionCellEditor)1 VersionCellRenderer (com.sldeditor.common.vendoroption.selection.VersionCellRenderer)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ArrayList (java.util.ArrayList)1 BoxLayout (javax.swing.BoxLayout)1 JButton (javax.swing.JButton)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JTable (javax.swing.JTable)1 TitledBorder (javax.swing.border.TitledBorder)1