use of de.jaret.util.ui.table.model.IColumn in project translationstudio8 by heartsome.
the class JaretTable method setTableModel.
/**
* Set a table model to be displayed by the jaret table.
*
* @param model the table model to be displayed.
*/
public void setTableModel(IJaretTableModel model) {
if (_model != null) {
_model.removeJaretTableModelListener(this);
}
_model = model;
_model.addJaretTableModelListener(this);
_hierarchicalModel = null;
// update the sorted columnlist
List<IColumn> cList = new ArrayList<IColumn>();
for (int i = 0; i < model.getColumnCount(); i++) {
cList.add(model.getColumn(i));
}
_tvs.setSortedColumns(cList);
updateColumnList();
registerRowsForOptimization();
updateRowList();
updateYScrollBar();
updateXScrollBar();
redraw();
}
use of de.jaret.util.ui.table.model.IColumn in project translationstudio8 by heartsome.
the class ConcordanceSearchDialog method initLanguageMenu.
/**
* 初始化语言菜单 ;
*/
private void initLanguageMenu() {
Set<String> set = new HashSet<String>();
for (DatabaseModelBean model : lstDatabase) {
MetaData metaData = model.toDbMetaData();
DBOperator dbop = DatabaseService.getDBOperator(metaData);
if (null == dbop) {
continue;
}
try {
dbop.start();
set.addAll(dbop.getLanguages());
} catch (SQLException e) {
LOGGER.error(Messages.getString("dialog.ConcordanceSearchDialog.logger1"), e);
} catch (ClassNotFoundException e) {
LOGGER.error(Messages.getString("dialog.ConcordanceSearchDialog.logger1"), e);
} finally {
try {
if (dbop != null) {
dbop.end();
}
} catch (SQLException e) {
LOGGER.error("", e);
}
}
}
set.remove(strSrcLang);
set.remove(strTgtLang);
lstLangs = new ArrayList<String>(set);
Collections.sort(lstLangs);
// cmbLang.setItems((String[]) langs.toArray(new String[langs.size()]));
menu = new Menu(getShell(), SWT.POP_UP);
if (strTgtLang != null) {
MenuItem itemTgt = new MenuItem(menu, SWT.CHECK);
itemTgt.setText(strTgtLang);
itemTgt.setSelection(true);
itemTgt.setEnabled(false);
}
for (final String lang : lstLangs) {
final MenuItem itemLang = new MenuItem(menu, SWT.CHECK);
itemLang.setText(lang);
itemLang.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
ArrayList<IColumn> lstShowColumn = new ArrayList<IColumn>();
// }
if (itemLang.getSelection()) {
// int totalWidth = 0;
boolean blnIsResetWidth = false;
// tableModel.getColumnCount()
for (int index = 1; index < tableModel.getColumnCount(); index++) {
IColumn column = tableModel.getColumn(index);
int width = jTable.getTableViewState().getColumnWidth(column);
if (column.getHeaderLabel().equals(lang) && width == 0) {
jTable.getTableViewState().setColumnVisible(column, true);
jTable.updateColumnList();
jTable.redraw();
// jTable.getTableViewState().setColumnWidth(column, width0);
lstShowColumn.add(column);
blnIsResetWidth = true;
} else if (width > 0) {
// totalWidth += width;
lstShowColumn.add(column);
// jTable.columnWidthChanged(column, width0);
}
}
if (blnIsResetWidth) {
int width = totalWidth / lstShowColumn.size() + 1;
for (int colNum = 1; colNum < jTable.getColumnCount(); colNum++) {
jTable.getTableViewState().setColumnWidth(jTable.getColumn(colNum), width);
}
// for (IColumn column : lstShowColumn) {
// // jTable.getTableViewState().setColumnVisible(column, true);
// jTable.getTableViewState().setColumnWidth(column, width);
// }
}
// initGroupIdAndSearch();
} else {
// int totalWidth = 0;
IColumn deleteColumn = null;
for (int index = 1; index < jTable.getColumnCount(); index++) {
IColumn column = jTable.getColumn(index);
int width = jTable.getTableViewState().getColumnWidth(column);
if (width > 0) {
// totalWidth += width;
lstShowColumn.add(column);
}
if (column.getHeaderLabel().equals(lang)) {
deleteColumn = column;
// 将删除列中的数据清空,以保证行高正常调整
// for (GridItem item : tableModel.getRowCount()) {
// item.setText(index, "");
// }
}
}
// int width = (jTable.getTableViewState().getColumnWidth(deleteColumn) * lstShowColumn.size() -
// 100)
// / (lstShowColumn.size() - 1);
int width = totalWidth / (lstShowColumn.size() - 1) + 1;
jTable.getTableViewState().setColumnWidth(deleteColumn, 0);
jTable.getTableViewState().setColumnVisible(deleteColumn, false);
lstShowColumn.remove(deleteColumn);
for (IColumn column : lstShowColumn) {
jTable.getTableViewState().setColumnWidth(column, width);
}
// initGroupIdAndSearch();
}
}
});
}
btnSelectLang.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
Rectangle rect = btnSelectLang.getBounds();
Point pt = btnSelectLang.toDisplay(new Point(event.x, event.y + rect.height));
// Point pt = btnSelectLang.toDisplay(new Point(event.x + rect.width, event.y + rect.height));
menu.setOrientation(getShell().getOrientation());
menu.setLocation(pt.x, pt.y);
menu.setVisible(true);
}
});
}
use of de.jaret.util.ui.table.model.IColumn in project translationstudio8 by heartsome.
the class DefaultSelectionProvider method getISelection.
/**
* {@inheritDoc}. Returns a structured selection containig rows and columns and cells that have been selected.
*/
@SuppressWarnings("unchecked")
protected ISelection getISelection() {
IJaretTableSelection selection = _table.getSelectionModel().getSelection();
if (selection != null && !selection.isEmpty()) {
List list = new ArrayList();
for (IRow row : selection.getSelectedRows()) {
list.add(row);
}
for (IColumn col : selection.getSelectedColumns()) {
list.add(col);
}
for (IJaretTableCell cell : selection.getSelectedCells()) {
list.add(cell);
}
StructuredSelection sselection = new StructuredSelection(list);
return sselection;
}
return new StructuredSelection();
}
Aggregations