@Override
  public void updateEnableState() {
    boolean enabled = false;
    final VizMapperMainPanel vizMapperMainPanel = getVizMapperMainPanel();
    VisualPropertySheet vpSheet = null;

    if (vizMapperMainPanel != null) vpSheet = vizMapperMainPanel.getSelectedVisualPropertySheet();

    if (vpSheet != null) {
      for (final VisualPropertySheetItem<?> vpSheetItem : vpSheet.getSelectedItems()) {
        final VisualPropertySheetItemModel<?> model = vpSheetItem.getModel();
        final PropertySheetTable table = vpSheetItem.getPropSheetPnl().getTable();
        final int[] selected = table.getSelectedRows();

        if (selected != null && model.getVisualMappingFunction() instanceof DiscreteMapping) {
          // Make sure the selected rows have at least one Discrete Mapping entry
          for (int i = 0; i < selected.length; i++) {
            final Item item = (Item) table.getValueAt(selected[i], 0);

            if (item != null && item.getProperty() instanceof VizMapperProperty) {
              final VizMapperProperty<?, ?, ?> prop =
                  (VizMapperProperty<?, ?, ?>) item.getProperty();

              if (prop.getCellType() == CellType.DISCRETE) {
                enabled = true;
                break;
              }
            }
          }
        }
      }
    }

    setEnabled(enabled);
  }
    public void configure(PropertySheetTable table, Item item) {
      isProperty = item.isProperty();
      toggleState = item.isVisible();
      showToggle = item.hasToggle();

      indentWidth = getIndent(table, item);
      insets.left = indentWidth + (showToggle ? HOTSPOT_SIZE : 0) + 2;
      ;
    }
 public boolean isEnabled() {
   int row = PropertySheetTable.this.getSelectedRow();
   if (row != -1) {
     Item item = PropertySheetTable.this.getSheetModel().getPropertySheetElement(row);
     return item.hasToggle();
   } else {
     return false;
   }
 }
 public void mouseReleased(MouseEvent event) {
   PropertySheetTable table = (PropertySheetTable) event.getComponent();
   int row = table.rowAtPoint(event.getPoint());
   int column = table.columnAtPoint(event.getPoint());
   if (row != -1 && column == 0) {
     // if we clicked on an Item, see if we clicked on its hotspot
     Item item = table.getSheetModel().getPropertySheetElement(row);
     int x = event.getX() - getIndent(table, item);
     if (x > 0 && x < HOTSPOT_SIZE) item.toggle();
   }
 }
  /**
   * Gets the CellEditor for the given row and column. It uses the editor registry to find a
   * suitable editor for the property.
   *
   * @see javax.swing.JTable#getCellEditor(int, int)
   */
  public TableCellEditor getCellEditor(int row, int column) {
    if (column == 0) {
      return null;
    }

    Item item = getSheetModel().getPropertySheetElement(row);
    if (!item.isProperty()) return null;

    TableCellEditor result = null;
    Property propery = item.getProperty();
    PropertyEditor editor = getEditorFactory().createPropertyEditor(propery);
    if (editor != null) result = new CellEditorAdapter(editor);

    return result;
  }
  /**
   * Calculates the required left indent for a given item, given its type and its hierarchy level.
   */
  static int getIndent(PropertySheetTable table, Item item) {
    int indent = 0;

    if (item.isProperty()) {
      // it is a property, it has no parent or a category, and no child
      if ((item.getParent() == null || !item.getParent().isProperty()) && !item.hasToggle()) {
        indent = table.getWantsExtraIndent() ? HOTSPOT_SIZE : 0;
      } else {
        // it is a property with children
        if (item.hasToggle()) {
          indent = item.getDepth() * HOTSPOT_SIZE;
        } else {
          indent = (item.getDepth() + 1) * HOTSPOT_SIZE;
        }
      }

      if (table.getSheetModel().getMode() == PropertySheet.VIEW_AS_CATEGORIES
          && table.getWantsExtraIndent()) {
        indent += HOTSPOT_SIZE;
      }

    } else {
      // category has no indent
      indent = 0;
    }
    return indent;
  }
  /** Edit all selected cells at once. This is for Discrete Mapping only. */
  @Override
  @SuppressWarnings({"rawtypes", "unchecked"})
  public void actionPerformed(final ActionEvent e) {
    final VizMapperMainPanel vizMapperMainPanel = getVizMapperMainPanel();

    if (vizMapperMainPanel == null) return;

    final VisualPropertySheet vpSheet = vizMapperMainPanel.getSelectedVisualPropertySheet();

    if (vpSheet == null) return;

    for (final VisualPropertySheetItem<?> vpSheetItem : vpSheet.getSelectedItems()) {
      final VisualPropertySheetItemModel<?> model = vpSheetItem.getModel();
      final PropertySheetTable table = vpSheetItem.getPropSheetPnl().getTable();
      final int[] selected = table.getSelectedRows();

      if (selected == null
          || selected.length == 0
          || !(model.getVisualMappingFunction() instanceof DiscreteMapping)) continue;

      // Test with the first selected item
      final DiscreteMapping dm = (DiscreteMapping) model.getVisualMappingFunction();
      final VisualProperty vp = dm.getVisualProperty();

      Object newValue = null;

      try {
        // Get new value
        newValue =
            editorManager.showVisualPropertyValueEditor(vizMapperMainPanel, vp, vp.getDefault());
      } catch (Exception ex) {
        logger.error("Could not edit value.", ex);
      }

      if (newValue == null) continue;

      final Map<Object, Object> newValues = new HashMap<Object, Object>();
      final Map<Object, Object> previousValues = new HashMap<Object, Object>();

      for (int i = 0; i < selected.length; i++) {
        final Item item = ((Item) table.getValueAt(selected[i], 0));

        if (item != null && item.getProperty() instanceof VizMapperProperty) {
          final VizMapperProperty<?, ?, ?> prop = (VizMapperProperty<?, ?, ?>) item.getProperty();

          if (prop.getCellType() == CellType.DISCRETE) {
            // Save the current value for undo
            previousValues.put(prop.getKey(), prop.getValue());

            // New value
            newValues.put(prop.getKey(), newValue);
          }
        }
      }

      // Save the mapping->old_values for undo
      if (!previousValues.isEmpty()) previousMappingValues.put(dm, previousValues);

      // Save the mapping->new_values for redo
      if (!newValues.isEmpty()) newMappingValues.put(dm, newValues);

      // Update the visual mapping
      dm.putAll(newValues);
    }

    // Undo support
    if (!previousMappingValues.isEmpty()) {
      final UndoSupport undo = servicesUtil.get(UndoSupport.class);
      undo.postEdit(new EditSelectedDiscreteValuesEdit());
    }
  }
 public void actionPerformed(ActionEvent e) {
   int row = PropertySheetTable.this.getSelectedRow();
   Item item = PropertySheetTable.this.getSheetModel().getPropertySheetElement(row);
   item.toggle();
   PropertySheetTable.this.addRowSelectionInterval(row, row);
 }