use of org.eclipse.swt.widgets.Listener in project otertool by wuntee.
the class GuiWorkshop method addColumnSorter.
public static void addColumnSorter(final Table table, TableColumn column, final int index, final String[] dataKeys) {
Listener sortListener = new Listener() {
public void handleEvent(Event e) {
TableItem[] items = table.getItems();
Collator collator = Collator.getInstance(Locale.getDefault());
TableColumn column = (TableColumn) e.widget;
for (int i = 1; i < items.length; i++) {
String value1 = items[i].getText(index);
for (int j = 0; j < i; j++) {
String value2 = items[j].getText(index);
if (table.getSortDirection() == SWT.UP || table.getSortDirection() == SWT.NONE && collator.compare(value1, value2) < 0) {
String[] values = new String[table.getColumnCount()];
for (int k = 0; k < table.getColumnCount(); k++) {
values[k] = items[i].getText(k);
}
// Get data from list item
Map<String, Object> dataMap = new HashMap<String, Object>();
for (String key : dataKeys) {
dataMap.put(key, items[i].getData(key));
}
items[i].dispose();
TableItem item = new TableItem(table, SWT.NONE, j);
item.setText(values);
// Set data for new item
for (String key : dataMap.keySet()) {
item.setData(key, dataMap.get(key));
}
items = table.getItems();
break;
} else if (table.getSortDirection() == SWT.DOWN && collator.compare(value1, value2) > 0) {
String[] values = new String[table.getColumnCount()];
for (int k = 0; k < table.getColumnCount(); k++) {
values[k] = items[i].getText(k);
}
// Get data from list item
Map<String, Object> dataMap = new HashMap<String, Object>();
for (String key : dataKeys) {
dataMap.put(key, items[i].getData(key));
}
items[i].dispose();
TableItem item = new TableItem(table, SWT.NONE, j);
item.setText(values);
// Set data for new item
for (String key : dataMap.keySet()) {
item.setData(key, dataMap.get(key));
}
items = table.getItems();
break;
}
}
}
if (table.getSortDirection() == SWT.NONE || table.getSortDirection() == SWT.UP) {
table.setSortDirection(SWT.DOWN);
} else {
table.setSortDirection(SWT.UP);
}
table.setSortColumn(column);
}
};
column.addListener(SWT.Selection, sortListener);
}
use of org.eclipse.swt.widgets.Listener in project tdi-studio-se by Talend.
the class ToolbarOutputZone method addListeners.
/**
* DOC amaumont Comment method "addListeners".
*/
private void addListeners() {
// final UIManager uiManager = getMapperManager().getUiManager();
addOutputItem.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
getMapperManager().addOutput();
}
});
removeOutputItem.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
getMapperManager().removeSelectedOutput();
}
});
guessItem.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
List<DataMapTableView> outputsTablesView = getMapperManager().getUiManager().getOutputsTablesView();
for (DataMapTableView dataMapTableView : outputsTablesView) {
dataMapTableView.notifyFocusLost();
}
getMapperManager().mapAutomaticallly();
}
});
}
use of org.eclipse.swt.widgets.Listener in project tdi-studio-se by Talend.
the class ProcessVersionComposite method addSortListener.
/**
* DOC Administrator Comment method "addSortListener".
*
* @param table
* @param column1
* @param column2
* @param column3
*/
private void addSortListener(final Table table, final TableColumn column1, final TableColumn column2, final TableColumn column3, final TableColumn column4) {
Listener sortListener = new Listener() {
private int direction = 1;
@Override
public void handleEvent(Event e) {
final TableColumn column = (TableColumn) e.widget;
if (column == table.getSortColumn()) {
direction = -direction;
}
if (direction == 1) {
table.setSortDirection(SWT.DOWN);
} else {
table.setSortDirection(SWT.UP);
}
table.setSortColumn(column);
tableViewer.setSorter(new ViewerSorter() {
int index = 0;
@Override
public void sort(Viewer viewer, Object[] elements) {
while (index < table.getColumns().length && table.getColumn(index) != column) {
index++;
}
super.sort(viewer, elements);
}
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
ITableLabelProvider labelProvider = (ITableLabelProvider) tableViewer.getLabelProvider();
String columnText = labelProvider.getColumnText(e1, index) != null ? labelProvider.getColumnText(e1, index) : //$NON-NLS-1$
"";
String columnText2 = labelProvider.getColumnText(e2, index) != null ? labelProvider.getColumnText(e2, index) : //$NON-NLS-1$
"";
return getComparator().compare(columnText, columnText2) * direction;
}
});
}
};
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
/*
* (non-Javadoc)
*
* @seeorg.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.
* SelectionChangedEvent)
*/
@Override
public void selectionChanged(SelectionChangedEvent event) {
ProcessVersionComposite.this.selection = event.getSelection();
if (getParentWizard() != null) {
((WizardPage) getParentWizard()).setPageComplete(true);
}
}
});
column1.addListener(SWT.Selection, sortListener);
column2.addListener(SWT.Selection, sortListener);
column3.addListener(SWT.Selection, sortListener);
column4.addListener(SWT.Selection, sortListener);
table.setSortColumn(column1);
table.setSortDirection(SWT.DOWN);
tableViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
if (getParentWizard() == null) {
ITreeContextualAction editPropertiesAction = getEditPropertiesAction(EditPropertiesAction.class);
if (editPropertiesAction != null) {
editPropertiesAction.run();
}
}
}
});
}
use of org.eclipse.swt.widgets.Listener in project tdi-studio-se by Talend.
the class ToolbarOutputZone method addListeners.
/**
* DOC amaumont Comment method "addListeners".
*/
private void addListeners() {
// final UIManager uiManager = getMapperManager().getUiManager();
addOutputItem.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
getMapperManager().addOutput();
}
});
removeOutputItem.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
getMapperManager().removeSelectedOutputTable();
}
});
guessItem.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
getMapperManager().mapAutomaticallly();
}
});
}
use of org.eclipse.swt.widgets.Listener in project tdi-studio-se by Talend.
the class ToolbarInputZone method addListeners.
/**
* DOC amaumont Comment method "addListeners".
*/
private void addListeners() {
// final UIManager uiManager = getMapperManager().getUiManager();
addAlias.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
getMapperManager().addInputAliasTable();
}
});
removeAlias.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
getMapperManager().removeSelectedAliasInputTable();
}
});
}
Aggregations