use of org.cytoscape.work.undo.AbstractCyEdit in project cytoscape-impl by cytoscape.
the class VizMapperMediator method onSelectedVisualStyleChanged.
private void onSelectedVisualStyleChanged(final PropertyChangeEvent e) {
final VisualStyle newStyle = (VisualStyle) e.getNewValue();
final VisualStyle oldStyle = vmProxy.getCurrentVisualStyle();
if (!ignoreVisualStyleSelectedEvents && newStyle != null && !newStyle.equals(oldStyle)) {
// Update proxy
vmProxy.setCurrentVisualStyle(newStyle);
// Undo support
final UndoSupport undo = servicesUtil.get(UndoSupport.class);
undo.postEdit(new AbstractCyEdit("Set Current Style") {
@Override
public void undo() {
vmProxy.setCurrentVisualStyle(oldStyle);
}
@Override
public void redo() {
vmProxy.setCurrentVisualStyle(newStyle);
}
});
}
}
use of org.cytoscape.work.undo.AbstractCyEdit in project cytoscape-impl by cytoscape.
the class VizMapperMediator method openDefaultValueEditor.
@SuppressWarnings("rawtypes")
private void openDefaultValueEditor(final ActionEvent evt, final VisualPropertySheetItem vpSheetItem) {
final VisualPropertySheetItemModel model = vpSheetItem.getModel();
final VisualProperty vp = model.getVisualProperty();
final VisualStyle style = vmProxy.getCurrentVisualStyle();
final Object oldValue = style.getDefaultValue(vp);
Object val = null;
try {
final EditorManager editorMgr = servicesUtil.get(EditorManager.class);
val = editorMgr.showVisualPropertyValueEditor(vizMapperMainPanel, vp, oldValue);
} catch (final Exception ex) {
logger.error("Error opening Visual Property values editor for: " + vp, ex);
}
final Object newValue = val;
if (newValue != null && !newValue.equals(oldValue)) {
style.setDefaultValue(vp, newValue);
// Undo support
final UndoSupport undo = servicesUtil.get(UndoSupport.class);
undo.postEdit(new AbstractCyEdit("Set Default Value") {
@Override
public void undo() {
style.setDefaultValue(vp, oldValue);
}
@Override
public void redo() {
style.setDefaultValue(vp, newValue);
}
});
}
}
use of org.cytoscape.work.undo.AbstractCyEdit in project cytoscape-impl by cytoscape.
the class CellEditorEventHandler method processEvent.
/**
* Execute commands based on PropertyEditor's local event.
*
* In this handler, we should handle the following:
* <ul>
* <li>Mapping Type change
* <li>Attribute Name Change
* </ul>
*
* Other old global events (ex. Cytoscape.NETWORK_LOADED) is replaced by new
* events.
*
* @param e PCE to be processed in this handler.
*/
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void processEvent(final PropertyChangeEvent e) {
final Object newVal = e.getNewValue();
final Object oldVal = e.getOldValue();
// Check update is necessary or not.
if (newVal == null && oldVal == null)
return;
// Same value. No change required.
if (newVal != null && newVal.equals(oldVal))
return;
final VisualPropertySheetItem<?> vpSheetItem = vizMapperMediator.getCurrentVisualPropertySheetItem();
final PropertySheetPanel propSheetPnl = vpSheetItem != null ? vpSheetItem.getPropSheetPnl() : null;
if (propSheetPnl == null)
return;
final VizMapperProperty<?, ?, ?> prop = vizMapperMediator.getCurrentVizMapperProperty();
if (prop == null)
return;
final VisualProperty<?> vp = vpSheetItem.getModel().getVisualProperty();
final VisualMappingFunction mapping = vpSheetItem.getModel().getVisualMappingFunction();
if (prop.getCellType() == CellType.DISCRETE && mapping instanceof DiscreteMapping) {
// Discrete mapping value changed:
// -------------------------------
// Create new map entry and register it.
final DiscreteMapping<Object, Object> discMap = (DiscreteMapping<Object, Object>) mapping;
setDiscreteMappingEntry(prop.getKey(), oldVal, newVal, discMap);
} else {
VisualMappingFunction newMapping = mapping;
String undoName = null;
if (prop.getCellType() == CellType.VISUAL_PROPERTY_TYPE) {
// -----------------------
if (newVal != null && e.getSource() instanceof AttributeComboBoxPropertyEditor) {
final AttributeComboBoxPropertyEditor editor = (AttributeComboBoxPropertyEditor) e.getSource();
final VisualMappingFunctionFactory factory = (VisualMappingFunctionFactory) propSheetPnl.getTable().getValueAt(1, 1);
newMapping = switchColumn(factory, editor, prop, newVal.toString(), propSheetPnl);
vpSheetItem.getModel().setVisualMappingFunction(newMapping);
if (newMapping == null)
vpSheetItem.getModel().setMappingColumnName(prop.getValue() != null ? prop.getValue().toString() : null);
undoName = "Set Mapping Column";
}
} else if (prop.getCellType() == CellType.MAPPING_TYPE) {
// Mapping type changed:
// -----------------------
// Parent is always root.
// TODO: refactor--this class should not have to know the row/column where the value is
Object controllingAttrName = propSheetPnl.getTable().getValueAt(0, 1);
if (vp != null && controllingAttrName != null && (newVal == null || newVal instanceof VisualMappingFunctionFactory)) {
newMapping = switchMappingType(prop, vp, (VisualMappingFunctionFactory) oldVal, (VisualMappingFunctionFactory) newVal, controllingAttrName.toString(), propSheetPnl);
vpSheetItem.getModel().setVisualMappingFunction(newMapping);
undoName = "Set Mapping Type";
}
}
if (newMapping != mapping && undoName != null) {
// Add undo support
final VisualMappingFunction myNewMapping = newMapping;
final UndoSupport undo = servicesUtil.get(UndoSupport.class);
undo.postEdit(new AbstractCyEdit(undoName) {
@Override
public void undo() {
vpSheetItem.getModel().setVisualMappingFunction(mapping);
}
@Override
public void redo() {
vpSheetItem.getModel().setVisualMappingFunction(myNewMapping);
}
});
}
}
}
use of org.cytoscape.work.undo.AbstractCyEdit in project cytoscape-impl by cytoscape.
the class CellEditorEventHandler method setDiscreteMappingEntry.
private void setDiscreteMappingEntry(final Object key, final Object oldVal, final Object newVal, final DiscreteMapping<Object, Object> mapping) {
final VisualProperty<?> vp = mapping.getVisualProperty();
if (newVal == null || vp.getRange().getType().isAssignableFrom(newVal.getClass())) {
mapping.putMapValue(key, newVal);
// Undo support
if ((oldVal != null && newVal == null) || (newVal != null && !newVal.equals(oldVal))) {
final UndoSupport undo = servicesUtil.get(UndoSupport.class);
undo.postEdit(new AbstractCyEdit("Set Discrete Mapping Value") {
@Override
public void undo() {
mapping.putMapValue(key, oldVal);
}
@Override
public void redo() {
mapping.putMapValue(key, newVal);
}
});
}
}
}
Aggregations