use of org.eclipse.nebula.widgets.nattable.grid.layer.event.ColumnHeaderSelectionEvent in project nebula.widgets.nattable by eclipse.
the class ColumnHeaderSelectionListener method handleLayerEvent.
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof ColumnSelectionEvent) {
ColumnSelectionEvent selectionEvent = (ColumnSelectionEvent) event;
ColumnHeaderSelectionEvent colHeaderSelectionEvent = new ColumnHeaderSelectionEvent(this.columnHeaderLayer, selectionEvent.getColumnPositionRanges());
this.columnHeaderLayer.fireLayerEvent(colHeaderSelectionEvent);
}
}
use of org.eclipse.nebula.widgets.nattable.grid.layer.event.ColumnHeaderSelectionEvent in project tdq-studio-se by Talend.
the class DataSampleTable method addCustomSelectionBehaviour.
private void addCustomSelectionBehaviour() {
natTable.addLayerListener(new ILayerListener() {
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof ColumnHeaderSelectionEvent) {
ColumnHeaderSelectionEvent columnEvent = (ColumnHeaderSelectionEvent) event;
Collection<Range> ranges = columnEvent.getColumnPositionRanges();
if (ranges.size() > 0) {
Range range = ranges.iterator().next();
handleColumnSelectionChange(range.start);
}
} else if (event instanceof ColumnReorderEvent) {
if (ColumnIndexMap == null) {
ColumnIndexMap = new HashMap<String, Integer>();
} else {
ColumnIndexMap.clear();
}
// save propertyNames oder into lastTimePropertyNameOrder
initPropertyNameOrder();
// Fill elements into ColumnIndexMap before the order change ones.
fillPreElement();
// Fill the oder all of elements which display on the table into ColumnIndexMap
fillElementWhichDisplayOnTable();
// Fill the oder all of elements which after the order change ones.
fillEndElement();
// update newest order state on the lastTimePropertyNameOrder list
savePropertyNameState();
notifyObservers();
}
}
/**
* DOC talend Comment method "fillElementWhichDisplayOnTable". copy by #fillElementWhichDisplayOnTable
*/
private void fillElementWhichDisplayOnTable() {
for (int index = 1; index < natTable.getColumnCount(); index++) {
int columnIndexByPosition = natTable.getColumnIndexByPosition(index);
ColumnIndexMap.put(propertyNames[columnIndexByPosition], ColumnIndexMap.size());
}
}
private void fillEndElement() {
for (int index = ColumnIndexMap.size(); index < propertyNames.length; index++) {
ColumnIndexMap.put(lastTimePropertyNameOrder.get(index), index);
}
}
private void fillPreElement() {
int disColumnCount = natTable.getColumnCount() - 1;
// display all case so that no preElement one need to be filled
if (disColumnCount >= lastTimePropertyNameOrder.size()) {
return;
}
// not all display
String endName = propertyNames[natTable.getColumnIndexByPosition(1)];
int firstOneLastPosition = lastTimePropertyNameOrder.indexOf(endName);
endName = propertyNames[natTable.getColumnIndexByPosition(2)];
int secondOneLastPosition = lastTimePropertyNameOrder.indexOf(endName);
if (secondOneLastPosition - firstOneLastPosition > 0) {
// 1 is not be change order case
endName = lastTimePropertyNameOrder.get(firstOneLastPosition);
// For example 1->2+
if (secondOneLastPosition - firstOneLastPosition == 1) {
String moveColName = findMoveColumnName(firstOneLastPosition - 1);
if (moveColName != null) {
endName = moveColName;
}
}
// For example 1->2,2+->1
} else if (secondOneLastPosition - firstOneLastPosition < 0) {
// in fact the value shoud be
// firstOneLastPosition+secondOneLastPosition-firstOneLastPosition
endName = lastTimePropertyNameOrder.get(secondOneLastPosition);
}
// ~ not all display
int index = 0;
for (String propertyName : lastTimePropertyNameOrder) {
if (endName.equals(propertyName)) {
break;
}
ColumnIndexMap.put(propertyName, index++);
}
}
/**
* Find the column name which be moved on the ui
*
* @param spacing
* @return
*/
private String findMoveColumnName(int spacing) {
for (int index = 3; index < natTable.getColumnCount() - 1; index++) {
String propertyName = propertyNames[natTable.getColumnIndexByPosition(index)];
int lastPosition = lastTimePropertyNameOrder.indexOf(propertyName);
if (spacing > lastPosition - index) {
return propertyName;
} else if (spacing == lastPosition - index) {
continue;
} else {
break;
}
}
return null;
}
});
}
Aggregations