use of org.eclipse.swt.widgets.TableColumn in project translationstudio8 by heartsome.
the class TableCombo method defineColumnsInternal.
/**
* Defines what columns the drop down table will have.
* @param columnHeaders
* @param columnBounds
*/
private void defineColumnsInternal(String[] columnHeaders, int[] columnBounds, int totalColumnsToBeCreated) {
checkWidget();
int totalColumnHeaders = columnHeaders == null ? 0 : columnHeaders.length;
int totalColBounds = columnBounds == null ? 0 : columnBounds.length;
if (totalColumnsToBeCreated > 0) {
for (int index = 0; index < totalColumnsToBeCreated; index++) {
TableColumn column = new TableColumn(table, SWT.NONE);
if (index < totalColumnHeaders) {
column.setText(columnHeaders[index]);
}
if (index < totalColBounds) {
column.setWidth(columnBounds[index]);
}
column.setResizable(true);
column.setMoveable(true);
}
}
}
use of org.eclipse.swt.widgets.TableColumn in project translationstudio8 by heartsome.
the class TableCombo method dropDown.
/**
* handle DropDown request
* @param drop
*/
void dropDown(boolean drop) {
// if already dropped then return
if (drop == isDropped())
return;
// closing the dropDown
if (!drop) {
popup.setVisible(false);
if (!isDisposed() && isFocusControl()) {
text.setFocus();
}
return;
}
// if not visible then return
if (!isVisible())
return;
// create a new popup if needed.
if (getShell() != popup.getParent()) {
int selectionIndex = table.getSelectionIndex();
table.removeListener(SWT.Dispose, listener);
popup.dispose();
popup = null;
table = null;
createPopup(selectionIndex);
}
// get the size of the TableCombo.
Point tableComboSize = getSize();
// calculate the table height.
int itemCount = table.getItemCount();
itemCount = (itemCount == 0) ? visibleItemCount : Math.min(visibleItemCount, itemCount);
int itemHeight = (table.getItemHeight() * itemCount);
// visible item count.
if (table.getItemCount() <= visibleItemCount) {
itemHeight += 1;
}
// add height of header if the header is being displayed.
if (table.getHeaderVisible()) {
itemHeight += table.getHeaderHeight();
}
// get table column references
TableColumn[] tableColumns = table.getColumns();
int totalColumns = (tableColumns == null ? 0 : tableColumns.length);
// then just create a blank one.
if (table.getColumnCount() == 0) {
new TableColumn(table, SWT.NONE);
totalColumns = 1;
tableColumns = table.getColumns();
}
int totalColumnWidth = 0;
// now pack any columns that do not have a explicit value set for them.
for (int colIndex = 0; colIndex < totalColumns; colIndex++) {
if (!wasColumnWidthSpecified(colIndex)) {
tableColumns[colIndex].pack();
}
totalColumnWidth += tableColumns[colIndex].getWidth();
}
// reset the last column's width to the preferred size if it has a
// explicit value.
int lastColIndex = totalColumns - 1;
if (wasColumnWidthSpecified(lastColIndex)) {
tableColumns[lastColIndex].setWidth(columnWidths[lastColIndex]);
}
// calculate the table size after making adjustments.
Point tableSize = table.computeSize(SWT.DEFAULT, itemHeight, false);
// calculate the table width and table height.
double pct = tableWidthPercentage / 100d;
int tableWidth = (int) (Math.max(tableComboSize.x - 2, tableSize.x) * pct);
int tableHeight = tableSize.y;
// not viewing the full table.
if (tableWidthPercentage < 100) {
tableHeight += table.getHorizontalBar().getSize().y;
}
// set the bounds on the table.
table.setBounds(1, 1, tableWidth, tableHeight);
// it is needed or not.
if (!table.getVerticalBar().getVisible() && tableSize.x - table.getVerticalBar().getSize().x >= tableComboSize.x - 2) {
tableWidth = tableWidth - table.getVerticalBar().getSize().x;
// reset the bounds on the table.
table.setBounds(1, 1, tableWidth, tableHeight);
}
table.getHorizontalBar().setVisible(false);
// adjust the last column to make sure that there is no empty space.
autoAdjustColumnWidthsIfNeeded(tableColumns, tableWidth, totalColumnWidth);
// set the table top index if there is a valid selection.
String indexStr = (String) text.getData();
if (indexStr != null && !indexStr.equals("")) {
int index = Integer.parseInt(indexStr);
table.setSelection(index);
table.setTopIndex(index);
}
// calculate popup dimensions.
Display display = getDisplay();
Rectangle tableRect = table.getBounds();
Rectangle parentRect = display.map(getParent(), null, getBounds());
Point comboSize = getSize();
Rectangle displayRect = getMonitor().getClientArea();
int overallWidth = 0;
// now set what the overall width should be.
if (tableWidthPercentage < 100) {
overallWidth = tableRect.width + 2;
} else {
overallWidth = Math.max(comboSize.x, tableRect.width + 2);
}
int overallHeight = tableRect.height + 2;
int x = parentRect.x;
int y = parentRect.y + comboSize.y;
if (y + overallHeight > displayRect.y + displayRect.height)
y = parentRect.y - overallHeight;
if (x + overallWidth > displayRect.x + displayRect.width)
x = displayRect.x + displayRect.width - tableRect.width;
// set the bounds of the popup
popup.setBounds(x, y, overallWidth, overallHeight);
// set the popup visible
popup.setVisible(true);
// set focus on the table.
table.setFocus();
}
use of org.eclipse.swt.widgets.TableColumn in project translationstudio8 by heartsome.
the class MergeXliffWizardPage method createMergeXlfGroup.
public void createMergeXlfGroup(Composite tparent) {
final Group xliffDataGroup = new Group(tparent, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(2).margins(8, 8).applyTo(xliffDataGroup);
GridDataFactory.fillDefaults().grab(true, true).applyTo(xliffDataGroup);
xliffDataGroup.setText(Messages.getString("wizard.MergeXliffWizardPage.xliffDataGroup"));
tableViewer = new TableViewer(xliffDataGroup, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
final Table table = tableViewer.getTable();
GridData tableData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
tableData.heightHint = 50;
table.setLayoutData(tableData);
table.setLinesVisible(true);
table.setHeaderVisible(true);
String[] columnNames = new String[] { Messages.getString("wizard.MergeXliffWizardPage.columnNames1"), Messages.getString("wizard.MergeXliffWizardPage.columnNames2") };
int[] columnAlignments = new int[] { SWT.LEFT, SWT.LEFT };
for (int i = 0; i < columnNames.length; i++) {
TableColumn tableColumn = new TableColumn(table, columnAlignments[i]);
tableColumn.setText(columnNames[i]);
}
tableViewer.setLabelProvider(new TableViewerLabelProvider());
tableViewer.setContentProvider(new ArrayContentProvider());
tableViewer.setInput(getSplitTableInfos());
validXlf();
// 让列表列宽动态变化
table.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event event) {
final Table table = ((Table) event.widget);
final TableColumn[] columns = table.getColumns();
event.widget.getDisplay().syncExec(new Runnable() {
public void run() {
double[] columnWidths = new double[] { 0.15, 0.75 };
for (int i = 0; i < columns.length; i++) columns[i].setWidth((int) (table.getBounds().width * columnWidths[i]));
}
});
}
});
Composite buttonComp = new Composite(xliffDataGroup, SWT.None);
GridLayoutFactory.fillDefaults().numColumns(1).margins(8, 8).applyTo(buttonComp);
GridDataFactory.fillDefaults().grab(false, true).hint(100, SWT.DEFAULT).applyTo(buttonComp);
Button addbutton = new Button(buttonComp, SWT.NONE);
addbutton.setText(Messages.getString("wizard.MergeXliffWizardPage.addbutton"));
addbutton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
addbutton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(xliffDataGroup.getShell(), true, IResource.FILE);
dialog.setMessage(Messages.getString("wizard.MergeXliffWizardPage.dialogMsg"));
dialog.setTitle(Messages.getString("wizard.MergeXliffWizardPage.dialogTitle"));
dialog.setDoubleClickSelects(true);
try {
dialog.setInput(EFS.getStore(root.getLocationURI()));
} catch (CoreException e1) {
LOGGER.error("", e1);
e1.printStackTrace();
}
dialog.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof LocalFile) {
LocalFile folder = (LocalFile) element;
if (folder.getName().equalsIgnoreCase(".hsConfig") || folder.getName().equalsIgnoreCase(".metadata") || folder.getName().equalsIgnoreCase(".config") || folder.getName().equalsIgnoreCase(".nonTransElement")) {
return false;
}
if (projectPath.equals(folder.toString())) {
return true;
}
String xliffFolderPath = folder.toString();
String tempPath = projectPath + System.getProperty("file.separator") + ".TEMP";
String configPath = projectPath + System.getProperty("file.separator") + ".config";
String projectFilePath = projectPath + System.getProperty("file.separator") + ".project";
if (xliffFolderPath.startsWith(tempPath) || xliffFolderPath.startsWith(configPath) || xliffFolderPath.startsWith(projectFilePath)) {
return false;
} else if (xliffFolderPath.startsWith(projectPath)) {
return xliffFolderPath.substring(projectPath.length()).startsWith(System.getProperty("file.separator"));
}
}
return false;
}
});
dialog.create();
dialog.open();
if (dialog.getResult() != null) {
Object[] selectFiles = dialog.getResult();
XLFValidator.resetFlag();
for (int i = 0; i < selectFiles.length; i++) {
IFile iFile = root.getFileForLocation(Path.fromOSString(selectFiles[i].toString()));
if (XLFValidator.validateXliffFile(iFile)) {
// 如果该文件已经存在于列表中,就向添加到重复集合中
if (model.getMergeXliffFile().indexOf(iFile) >= 0) {
exsistFileList.add(iFile);
}
model.getMergeXliffFile().add(iFile);
}
}
XLFValidator.resetFlag();
tableViewer.setInput(getSplitTableInfos());
if (!validIsRepeate()) {
validXlf();
}
// for (int i = 0; i < selectFiles.length; i++) {
// IFile file = root.getFileForLocation(Path.fromOSString(selectFiles[i].toString()));
// // 如果该文件已经存在于列表中,就向添加到重复集合中
// if (model.getMergeXliffFile().indexOf(file) >= 0) {
// exsistFileList.add(file);
// }
// model.getMergeXliffFile().add(file);
// }
// tableViewer.setInput(getSplitTableInfos());
// if (!validIsRepeate()) {
// validXlf();
// }
}
}
});
Button deleteButton = new Button(buttonComp, SWT.NONE);
deleteButton.setText(Messages.getString("wizard.MergeXliffWizardPage.deleteButton"));
deleteButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
deleteButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
ISelection selection = tableViewer.getSelection();
Table table = tableViewer.getTable();
if (selection != null && !selection.isEmpty()) {
int[] indices = table.getSelectionIndices();
for (int index : indices) {
String fileFullPath = table.getItem(index).getText(1);
for (int i = 0; i < model.getMergeXliffFile().size(); i++) {
if (model.getMergeXliffFile().get(i).getFullPath().toOSString().equals(fileFullPath)) {
model.getMergeXliffFile().remove(i);
break;
}
}
// 如果该文件存在于重复集合中,则从该集合中删除
for (int j = 0; j < exsistFileList.size(); j++) {
if (exsistFileList.get(j).getFullPath().toOSString().equals(fileFullPath)) {
exsistFileList.remove(j);
break;
}
}
}
tableViewer.setInput(getSplitTableInfos());
}
if (!validIsRepeate()) {
validXlf();
}
}
});
}
use of org.eclipse.swt.widgets.TableColumn in project translationstudio8 by heartsome.
the class PreMachineTranslationDialog method createTableViewerColumn.
/**
* 设置TableViewer 列属性
* @param viewer
* @param title
* 列标题
* @param bound
* 列宽
* @param colNumber
* 列序号
* @return {@link TableViewerColumn};
*/
private TableViewerColumn createTableViewerColumn(TableViewer viewer, String title, int bound, final int colNumber) {
final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE | SWT.Resize);
final TableColumn column = viewerColumn.getColumn();
column.setText(title);
column.setWidth(bound);
column.setResizable(true);
column.setMoveable(true);
return viewerColumn;
}
use of org.eclipse.swt.widgets.TableColumn in project translationstudio8 by heartsome.
the class LockRepeatedSegmentDialog method createFileDataGroup.
/**
* @param parent
*/
public void createFileDataGroup(Composite parent) {
Composite parentCmp = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().extendedMargins(9, 9, 0, 0).numColumns(1).applyTo(parentCmp);
GridDataFactory.fillDefaults().grab(true, true).applyTo(parentCmp);
tableViewer = new TableViewer(parentCmp, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
final Table table = tableViewer.getTable();
GridData tableData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
tableData.heightHint = 50;
table.setLayoutData(tableData);
table.setLinesVisible(true);
table.setHeaderVisible(true);
String[] columnNames = new String[] { Messages.getString("dialog.LockRepeatedSegmentDialog.columnNames1"), Messages.getString("dialog.LockRepeatedSegmentDialog.columnNames2") };
int[] columnAlignments = new int[] { SWT.LEFT, SWT.LEFT };
for (int i = 0; i < columnNames.length; i++) {
TableColumn tableColumn = new TableColumn(table, columnAlignments[i]);
tableColumn.setText(columnNames[i]);
tableColumn.setWidth(50);
}
tableViewer.setLabelProvider(new TableViewerLabelProvider());
tableViewer.setContentProvider(new ArrayContentProvider());
tableViewer.setInput(getTableData());
// 让列表列宽动态变化
table.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event event) {
final Table table = ((Table) event.widget);
final TableColumn[] columns = table.getColumns();
event.widget.getDisplay().syncExec(new Runnable() {
public void run() {
double[] columnWidths = new double[] { 0.1, 0.8 };
for (int i = 0; i < columns.length; i++) columns[i].setWidth((int) (table.getBounds().width * columnWidths[i]));
}
});
}
});
tableViewer.getTable().setFocus();
btnLockInnerRepeat = new Button(parentCmp, SWT.CHECK);
btnLockInnerRepeat.setText(Messages.getString("dialog.LockRepeatedSegmentDialog.btnLockInnerRepeat"));
btnLockInnerRepeat.setSelection(true);
btnLockTM100 = new Button(parentCmp, SWT.CHECK);
btnLockTM100.setText(Messages.getString("dialog.LockRepeatedSegmentDialog.btnLockTM100"));
btnLockTM100.setSelection(true);
if (CommonFunction.checkEdition("U")) {
btnLockTM101 = new Button(parentCmp, SWT.CHECK);
btnLockTM101.setText(Messages.getString("dialog.LockRepeatedSegmentDialog.btnLockTM101"));
btnLockTM101.setSelection(true);
}
}
Aggregations