use of com.l2fprod.common.propertysheet.PropertySheetTable in project cytoscape-impl by cytoscape.
the class VizMapPropertyBuilder method setDiscreteProps.
/**
* Set value, title, and renderer for each property in the category. This
* list should be created against all available attribute values.
*/
private <K, V> void setDiscreteProps(VisualProperty<V> vp, VisualMappingFunction<K, V> mapping, SortedSet<Object> attrSet, VisualPropertyEditor<V> vpEditor, PropertySheetPanel propertySheetPanel) {
if (attrSet == null)
return;
final Map<K, V> discMapping = ((DiscreteMapping<K, V>) mapping).getAll();
V val = null;
VizMapperProperty<K, V, VisualMappingFunction<K, V>> valProp;
String strVal;
final PropertySheetTable table = propertySheetPanel.getTable();
final PropertyRendererRegistry cellRendererFactory = (PropertyRendererRegistry) table.getRendererFactory();
final PropertyEditorRegistry cellEditorFactory = (PropertyEditorRegistry) table.getEditorFactory();
for (final Object key : attrSet) {
valProp = new VizMapperProperty<K, V, VisualMappingFunction<K, V>>(CellType.DISCRETE, (K) key, mapping.getVisualProperty().getRange().getType());
strVal = key.toString();
valProp.setDisplayName(strVal);
// but we don't know the type of the list items.
if (mapping.getMappingColumnType() == String.class && !(key instanceof String))
val = discMapping.get(key.toString());
else
val = discMapping.get(key);
if (val != null)
valProp.setType(val.getClass());
propertySheetPanel.addProperty(valProp);
if (vpEditor != null) {
final TableCellRenderer renderer = vpEditor.getDiscreteTableCellRenderer();
if (renderer != null)
cellRendererFactory.registerRenderer(valProp, renderer);
PropertyEditor cellEditor = null;
if (vpEditor instanceof VisualPropertyEditor2) {
cellEditor = ((VisualPropertyEditor2) vpEditor).getPropertyEditor(vp);
} else {
cellEditor = vpEditor.getPropertyEditor();
}
if (cellEditor != null)
cellEditorFactory.registerEditor(valProp, cellEditor);
}
valProp.setValue(val);
valProp.setInternalValue(mapping);
}
}
use of com.l2fprod.common.propertysheet.PropertySheetTable in project cytoscape-impl by cytoscape.
the class RemoveSelectedDiscreteValuesAction method updateEnableState.
@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 with non-null value
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 && prop.getValue() != null) {
enabled = true;
break;
}
}
}
}
}
}
setEnabled(enabled);
}
use of com.l2fprod.common.propertysheet.PropertySheetTable in project cytoscape-impl by cytoscape.
the class RemoveSelectedDiscreteValuesAction method actionPerformed.
// ==[ PUBLIC METHODS ]=============================================================================================
/**
* Remove all selected values 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 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
if (prop.getValue() != null)
previousValues.put(prop.getKey(), prop.getValue());
// Mapping values to be removed
newValues.put(prop.getKey(), null);
}
}
}
// Save the mapping->old_values for undo
if (!previousValues.isEmpty())
previousMappingValues.put(dm, previousValues);
// Update the visual mapping
dm.putAll(newValues);
}
// Undo support
if (!previousMappingValues.isEmpty()) {
final UndoSupport undo = servicesUtil.get(UndoSupport.class);
undo.postEdit(new RemoveSelectedDiscreteValuesEdit());
}
}
Aggregations