use of org.cytoscape.model.events.ColumnCreatedEvent in project cytoscape-impl by cytoscape.
the class TableEventHelperFacade method fireEvent.
@Override
public <E extends CyEvent<?>> void fireEvent(final E event) {
final CyEventHelper eventHelper = getEventHelper();
// always propagate the actual event
eventHelper.fireEvent(event);
// make sure the source is something we care about
Object source = event.getSource();
if (!(source instanceof CyTable))
return;
Reference<LocalTableFacade> reference;
synchronized (lock) {
reference = facadeMap.get((CyTable) source);
}
if (reference == null)
return;
LocalTableFacade facade = reference.get();
if (facade == null)
return;
// create a new event for the facade table based on the actual event
CyEvent<?> facadeEvent = null;
if (event instanceof TableTitleChangedEvent) {
TableTitleChangedEvent e = (TableTitleChangedEvent) event;
facadeEvent = new TableTitleChangedEvent(facade, e.getOldTitle());
} else if (event instanceof TablePrivacyChangedEvent) {
facadeEvent = new TablePrivacyChangedEvent(facade);
} else if (event instanceof ColumnNameChangedEvent) {
ColumnNameChangedEvent e = (ColumnNameChangedEvent) event;
facadeEvent = new ColumnNameChangedEvent(facade, e.getOldColumnName(), e.getNewColumnName());
} else if (event instanceof ColumnDeletedEvent) {
ColumnDeletedEvent e = (ColumnDeletedEvent) event;
facadeEvent = new ColumnDeletedEvent(facade, e.getColumnName());
} else if (event instanceof ColumnCreatedEvent) {
ColumnCreatedEvent e = (ColumnCreatedEvent) event;
facadeEvent = new ColumnCreatedEvent(facade, e.getColumnName());
}
// fire the new facade event
if (facadeEvent != null)
eventHelper.fireEvent(facadeEvent);
}
use of org.cytoscape.model.events.ColumnCreatedEvent in project cytoscape-impl by cytoscape.
the class CyTableImpl method createListColumn.
@Override
public <T> void createListColumn(final String columnName, final Class<T> listElementType, final boolean isImmutable, final List<T> defaultValue) {
synchronized (lock) {
if (columnName == null)
throw new NullPointerException("column name is null");
final String normalizedColName = normalizeColumnName(columnName);
if (types.containsKey(normalizedColName))
throw new IllegalArgumentException("column already exists with name: '" + columnName + "' with type: " + types.get(normalizedColName).getType());
if (listElementType == null)
throw new NullPointerException("listElementType is null");
checkClass(listElementType);
VirtualColumnInfo virtualInfo = NonVirtualColumnInfo.create(isImmutable);
types.put(normalizedColName, new CyColumnImpl(this, columnName, List.class, listElementType, virtualInfo, /* isPrimaryKey = */
false, isImmutable, defaultValue));
attributes.put(normalizedColName, columnFactory.create(primaryKeyType, List.class, listElementType, defaultInitSize));
colList.add(types.get(normalizedColName));
}
eventHelper.fireEvent(new ColumnCreatedEvent(this, columnName));
}
use of org.cytoscape.model.events.ColumnCreatedEvent in project cytoscape-impl by cytoscape.
the class CyTableImpl method addVirtualColumn.
@Override
public final String addVirtualColumn(final String virtualColumnName, final String sourceColumnName, final CyTable sourceTable, final String targetJoinKeyName, final boolean isImmutable) {
if (virtualColumnName == null)
throw new NullPointerException("\"virtualColumn\" argument must never be null.");
if (sourceColumnName == null)
throw new NullPointerException("\"sourceColumn\" argument must never be null.");
if (sourceTable == null)
throw new NullPointerException("\"sourceTable\" argument must never be null.");
if (targetJoinKeyName == null)
throw new NullPointerException("\"targetJoinKey\" argument must never be null.");
String targetName = "failed to create column";
synchronized (lock) {
final String normalizedColName = normalizeColumnName(virtualColumnName);
if (types.containsKey(normalizedColName))
throw new IllegalArgumentException("column already exists with name: '" + virtualColumnName + "' with type: " + types.get(normalizedColName).getType());
final CyColumn sourceColumn = sourceTable.getColumn(normalizeColumnName(sourceColumnName));
if (sourceColumn == null)
throw new IllegalArgumentException("\"" + sourceColumnName + "\" is not a column in source table.");
final CyColumn targetJoinKey = this.getColumn(targetJoinKeyName);
if (targetJoinKey == null)
throw new IllegalArgumentException("\"" + targetJoinKeyName + "\" is not a known column in this table.");
final CyColumn sourceJoinKey = sourceTable.getPrimaryKey();
if (sourceJoinKey.getType() != targetJoinKey.getType())
throw new IllegalArgumentException("\"" + sourceJoinKey.getName() + "\" has a different type from \"" + targetJoinKeyName + "\".");
VirtualColumn virtualColumn = new VirtualColumn((CyTableImpl) sourceTable, sourceColumnName, this, sourceTable.getPrimaryKey().getName(), targetJoinKeyName, isImmutable);
targetName = virtualColumnName;
final CyColumn targetColumn = new CyColumnImpl(this, targetName, sourceColumn.getType(), sourceColumn.getListElementType(), virtualColumn, /* isPrimaryKey = */
false, isImmutable, sourceColumn.getDefaultValue());
((CyTableImpl) sourceTable).addDependent(sourceColumnName, targetColumn);
final String normalizedTargetName = normalizeColumnName(targetName);
types.put(normalizedTargetName, targetColumn);
attributes.put(normalizedTargetName, columnFactory.create(primaryKeyType, sourceColumn.getType(), sourceColumn.getListElementType(), defaultInitSize));
virtualColumnMap.put(normalizedTargetName, virtualColumn);
colList.add(types.get(normalizedTargetName));
}
eventHelper.fireEvent(new ColumnCreatedEvent(this, targetName));
return targetName;
}
use of org.cytoscape.model.events.ColumnCreatedEvent in project cytoscape-impl by cytoscape.
the class CyTableImpl method createColumn.
@Override
public <T> void createColumn(final String columnName, final Class<? extends T> type, final boolean isImmutable, final T defaultValue) {
synchronized (lock) {
if (columnName == null)
throw new NullPointerException("column name is null");
final String normalizedColName = normalizeColumnName(columnName);
if (types.containsKey(normalizedColName))
throw new IllegalArgumentException("column already exists with name: '" + columnName + "' with type: " + types.get(normalizedColName).getType());
if (type == null)
throw new NullPointerException("type is null");
if (type == List.class)
throw new IllegalArgumentException("use createListColumn() to create List columns instead of createColumn for column '" + columnName + "'.");
checkClass(type);
VirtualColumnInfo virtualInfo = NonVirtualColumnInfo.create(isImmutable);
types.put(normalizedColName, new CyColumnImpl(this, columnName, type, /* listElementType = */
null, virtualInfo, /* isPrimaryKey = */
false, isImmutable, defaultValue));
attributes.put(normalizedColName, columnFactory.create(primaryKeyType, type, null, defaultInitSize));
colList.add(types.get(normalizedColName));
}
eventHelper.fireEvent(new ColumnCreatedEvent(this, columnName));
}
Aggregations