use of net.sourceforge.nattable.selection.command.SelectCellCommand in project translationstudio8 by heartsome.
the class XLIFFEditorImplWithNatTable method addFilterComposite.
/**
* 添加填充过滤器面板内容的面板
* @param parent
* @return 过滤器面板;
*/
private void addFilterComposite(Composite main) {
Composite top = new Composite(main, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).margins(0, 0).applyTo(top);
top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// 输入行号进行定位
final String rowLocationStr = Messages.getString("editor.XLIFFEditorImplWithNatTable.rowLocationStr");
Text txtRowLocation = new Text(top, SWT.BORDER);
txtRowLocation.setText(rowLocationStr);
int width = 40;
if (Util.isLinux()) {
width = 35;
}
GridDataFactory.swtDefaults().hint(width, SWT.DEFAULT).applyTo(txtRowLocation);
txtRowLocation.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
Text text = (Text) e.widget;
if (rowLocationStr.equals(text.getText())) {
text.setText("");
}
}
@Override
public void focusLost(FocusEvent e) {
Text text = (Text) e.widget;
if ("".equals(text.getText())) {
text.setText(rowLocationStr);
}
}
});
txtRowLocation.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
String rowNumString = ((Text) event.widget).getText().trim();
if (rowNumString != null && !"".equals(rowNumString)) {
int rowPosition;
try {
rowPosition = Integer.parseInt(rowNumString) - 1;
jumpToRow(rowPosition, false);
updateStatusLine();
} catch (NumberFormatException e) {
Text text = (Text) event.widget;
text.setText("");
}
}
}
}
});
txtRowLocation.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent event) {
if (event.keyCode == 0 && event.stateMask == 0) {
// 文本框得到焦点时
} else if (Character.isDigit(event.character) || event.character == '\b' || event.keyCode == 127) {
// 输入数字,或者按下Backspace、Delete键
if ("".equals(((Text) event.widget).getText().trim()) && event.character == '0') {
event.doit = false;
} else {
event.doit = true;
}
} else {
event.doit = false;
}
}
});
cmbFilter = new Combo(top, SWT.BORDER | SWT.READ_ONLY);
cmbFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// TODO 完善过滤器初始化数据。
// cmbFilter.add("所有文本段");
// cmbFilter.add("未翻译文本段");
// cmbFilter.add("已翻译文本段");
// cmbFilter.add("未批准文本段");
// cmbFilter.add("已批准文本段");
// cmbFilter.add("有批注文本段");
// cmbFilter.add("锁定文本段");
// cmbFilter.add("未锁定文本段");
// cmbFilter.add("重复文本段");
// cmbFilter.add("疑问文本段");
// cmbFilter.add("上下文匹配文本段");
// cmbFilter.add("完全匹配文本段");
// cmbFilter.add("模糊匹配文本段");
// cmbFilter.add("快速翻译文本段");
// cmbFilter.add("自动繁殖文本段");
// cmbFilter.add("错误标记文本段");
// cmbFilter.add("术语不一致文本段");
// cmbFilter.add("译文不一致文本段");
// cmbFilter.add("带修订标记文本段");
final Set<String> filterNames = XLFHandler.getFilterNames();
for (String filterName : filterNames) {
cmbFilter.add(filterName);
}
// 添加选项改变监听
cmbFilter.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Fixed Bug #2243 by Jason 当鼠标焦点在源文单元框中使用过滤器,对过滤后的译文进行操作会提示该行锁定不能操作
// ActiveCellEditor.commit();
HsMultiActiveCellEditor.commit(true);
Combo cmbFilter = (Combo) e.widget;
boolean isUpdated = handler.doFilter(cmbFilter.getText(), langFilterCondition);
if (isUpdated) {
if (table != null) {
bodyLayer.getSelectionLayer().clear();
if (bodyLayer.selectionLayer.getRowCount() > 0) {
// 默认选中第一行
HsMultiActiveCellEditor.commit(true);
bodyLayer.selectionLayer.doCommand(new SelectCellCommand(bodyLayer.getSelectionLayer(), getTgtColumnIndex(), isHorizontalLayout ? 0 : 1, false, false));
HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.this);
}
table.setFocus();
}
// 自动调整 NatTable 大小 ;
autoResize();
// 更新状态栏
updateStatusLine();
NattableUtil.refreshCommand(XLIFFEditorSelectionPropertyTester.PROPERTY_NAMESPACE, XLIFFEditorSelectionPropertyTester.PROPERTY_ENABLED);
}
}
});
Button btnSaveFilter = new Button(top, SWT.NONE);
// TODO 考虑换成图片显示。
btnSaveFilter.setText(Messages.getString("editor.XLIFFEditorImplWithNatTable.btnAddFilter"));
btnSaveFilter.setToolTipText(Messages.getString("editor.XLIFFEditorImplWithNatTable.btnAddFilterTooltip"));
btnSaveFilter.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
CustomFilterDialog dialog = new CustomFilterDialog(table.getShell(), cmbFilter);
dialog.open();
// int res = dialog.open();
// if (res == CustomFilterDialog.OK) {
// cmbFilter.select(cmbFilter.getItemCount() - 1); // 选中最后一行数据
// cmbFilter.notifyListeners(SWT.Selection, null);
// }
}
});
// 默认选中第一行数据
cmbFilter.select(0);
cmbFilter.notifyListeners(SWT.Selection, null);
// 更新nattable的列名为语言对
renameColumn();
top.pack();
}
use of net.sourceforge.nattable.selection.command.SelectCellCommand in project translationstudio8 by heartsome.
the class PopupMenuAction method run.
@Override
public void run(NatTable natTable, MouseEvent event) {
// ActiveCellEditor.commit(); // 执行弹出菜单前先关闭编辑模式的单元格
super.run(natTable, event);
if (selectionLayer == null) {
selectionLayer = LayerUtil.getLayer(natTable, SelectionLayer.class);
}
int rowIndex = natTable.getRowIndexByPosition(getGridRowPosition());
XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
if (!editor.isHorizontalLayout()) {
rowIndex = rowIndex / 2;
}
// 如果该行已经选中的了,直接显示出右键菜单。
if (!isSelected(rowIndex)) {
HsMultiActiveCellEditor.commit(true);
natTable.doCommand(new SelectCellCommand(natTable, getGridColumnPosition(), getGridRowPosition(), isWithShiftMask(), isWithControlMask()));
HsMultiCellEditorControl.activeSourceAndTargetCell(editor);
}
menu.setData(event.data);
menu.setVisible(true);
}
use of net.sourceforge.nattable.selection.command.SelectCellCommand in project translationstudio8 by heartsome.
the class SelectCellAction method run.
@Override
public void run(NatTable natTable, MouseEvent event) {
super.run(natTable, event);
natTable.doCommand(new SelectCellCommand(natTable, getGridColumnPosition(), getGridRowPosition(), isWithShiftMask(), isWithControlMask()));
}
use of net.sourceforge.nattable.selection.command.SelectCellCommand in project translationstudio8 by heartsome.
the class UpdateDataOperation method refreshNatTable.
/**
* 更新 NatTable 的 UI
* @param value
* 单元格保存的值
* @param move
* 是否移动单元格到指定区域;
*/
private IStatus refreshNatTable(Object value, boolean move) {
if (table == null || table.isDisposed()) {
return Status.CANCEL_STATUS;
}
int rowIndex = command.getRowPosition();
int columnIndex = command.getColumnPosition();
int columnPosition = viewportLayer.getColumnPositionByIndex(columnIndex);
int rowPosition = viewportLayer.getRowPositionByIndex(rowIndex);
// 实质上 DataLayer 层的 index 和 position 是一致的,此方法可以对范围判断
if (rowIndex == -1 || columnIndex == -1) {
return Status.CANCEL_STATUS;
}
// 修改值并刷新 UI。
dataLayer.getDataProvider().setDataValue(columnIndex, rowIndex, value);
dataLayer.fireLayerEvent(new CellVisualChangeEvent(dataLayer, columnPosition, rowPosition));
// 修改行在当前一屏显示的几行中的相对位置
int currentRow = rowPosition + 1;
table.doCommand(new AutoResizeCurrentRowsCommand(table, new int[] { currentRow }, table.getConfigRegistry()));
int selectedRow = XLIFFEditorImplWithNatTable.getCurrent().getSelectedRows()[0];
if (value instanceof UpdateDataBean & rowIndex == selectedRow) {
UpdateDataBean bean = (UpdateDataBean) value;
StyledTextCellEditor sourceCellEditor = HsMultiActiveCellEditor.getSourceStyledEditor();
StyledTextCellEditor targetCellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
if (sourceCellEditor != null && sourceCellEditor.getRowIndex() == rowIndex && sourceCellEditor.getColumnIndex() == columnIndex) {
ISegmentViewer segviewer = sourceCellEditor.getSegmentViewer();
if (segviewer != null) {
segviewer.setText(bean.getText());
}
} else if (targetCellEditor != null && targetCellEditor.getRowIndex() == rowIndex && targetCellEditor.getColumnIndex() == columnIndex) {
ISegmentViewer segviewer = targetCellEditor.getSegmentViewer();
if (segviewer != null) {
segviewer.setText(bean.getText());
}
}
}
// 先记录下可见区域的范围
int originRowPosition = viewportLayer.getOriginRowPosition();
// 总行数
int rowCount = viewportLayer.getRowCount();
int row = LayerUtil.convertRowPosition(dataLayer, rowPosition, viewportLayer);
if (move) {
// 定位到屏幕第三行的位置
if (rowPosition < originRowPosition || rowPosition > originRowPosition + rowCount) {
HsMultiActiveCellEditor.commit(true);
viewportLayer.doCommand(new SelectCellCommand(viewportLayer, columnPosition, row, false, false));
HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.getCurrent());
} else {
XLIFFEditorImplWithNatTable.getCurrent().jumpToRow(rowIndex);
}
}
return Status.OK_STATUS;
}
use of net.sourceforge.nattable.selection.command.SelectCellCommand in project translationstudio8 by heartsome.
the class SearchGridCellsCommandHandler method doCommand.
public boolean doCommand(ILayer targetLayer, SearchCommand searchCommand) {
searchCommand.convertToTargetLayer(targetLayer);
AbstractSearchStrategy searchStrategy = (AbstractSearchStrategy) searchCommand.getSearchStrategy();
if (searchCommand.getSearchEventListener() != null) {
selectionLayer.addLayerListener(searchCommand.getSearchEventListener());
}
PositionCoordinate anchor = selectionLayer.getSelectionAnchor();
if (anchor.columnPosition < 0 || anchor.rowPosition < 0) {
anchor = new PositionCoordinate(selectionLayer, 0, 0);
}
searchStrategy.setContextLayer(targetLayer);
Object dataValueToFind = null;
if ((dataValueToFind = searchCommand.getSearchText()) == null) {
dataValueToFind = selectionLayer.getDataValueByPosition(anchor.columnPosition, anchor.rowPosition);
}
searchStrategy.setCaseSensitive(searchCommand.isCaseSensitive());
searchStrategy.setWrapSearch(searchCommand.isWrapSearch());
searchStrategy.setSearchDirection(searchCommand.getSearchDirection());
searchStrategy.setComparator(searchCommand.getComparator());
searchResultCellCoordinate = searchStrategy.executeSearch(dataValueToFind);
selectionLayer.fireLayerEvent(new SearchEvent(searchResultCellCoordinate));
if (searchResultCellCoordinate != null) {
final SelectCellCommand command = new SelectCellCommand(selectionLayer, searchResultCellCoordinate.columnPosition, searchResultCellCoordinate.rowPosition, false, false);
command.setForcingEntireCellIntoViewport(true);
selectionLayer.doCommand(command);
}
return true;
}
Aggregations