use of org.eclipse.nebula.widgets.grid.Grid in project translationstudio8 by heartsome.
the class GridViewerColumn method hookColumnResizeListener.
private void hookColumnResizeListener() {
if (columnResizeListener == null) {
columnResizeListener = new Listener() {
public void handleEvent(Event event) {
boolean autoPreferredSize = false;
if (viewer instanceof GridTableViewer)
autoPreferredSize = ((GridTableViewer) viewer).getAutoPreferredHeight();
if (viewer instanceof GridTreeViewer)
autoPreferredSize = ((GridTreeViewer) viewer).getAutoPreferredHeight();
if (autoPreferredSize && column.getWordWrap()) {
Grid grid = column.getParent();
for (int cnt = 0; cnt < grid.getItemCount(); cnt++) grid.getItem(cnt).pack();
grid.redraw();
}
}
};
column.addListener(SWT.Resize, columnResizeListener);
column.addListener(SWT.Hide, columnResizeListener);
column.addListener(SWT.Show, columnResizeListener);
}
}
use of org.eclipse.nebula.widgets.grid.Grid in project translationstudio8 by heartsome.
the class GridViewerEditor method updateFocusCell.
/**
* {@inheritDoc}
*/
protected void updateFocusCell(ViewerCell focusCell, ColumnViewerEditorActivationEvent event) {
Grid grid = ((Grid) getViewer().getControl());
if (event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC || event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL) {
grid.setFocusColumn(grid.getColumn(focusCell.getColumnIndex()));
grid.setFocusItem((GridItem) focusCell.getItem());
if (selectionFollowsEditor) {
grid.setCellSelection(new Point(focusCell.getColumnIndex(), grid.indexOf((GridItem) focusCell.getItem())));
}
}
grid.showColumn(grid.getColumn(focusCell.getColumnIndex()));
grid.showItem((GridItem) focusCell.getItem());
}
use of org.eclipse.nebula.widgets.grid.Grid in project translationstudio8 by heartsome.
the class TermBaseSearchDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite tparent = (Composite) super.createDialogArea(parent);
tparent.setLayout(new GridLayout());
GridData parentData = new GridData(GridData.FILL_BOTH);
parentData.heightHint = 600;
parentData.widthHint = 775;
tparent.setLayoutData(parentData);
Group groupSearch = new Group(tparent, SWT.None);
groupSearch.setText(Messages.getString("dialog.TermBaseSearchDialog.groupSearch"));
GridLayoutFactory.swtDefaults().margins(5, 5).numColumns(3).equalWidth(false).applyTo(groupSearch);
GridDataFactory.fillDefaults().grab(true, false).applyTo(groupSearch);
Label lblSearch = new Label(groupSearch, SWT.NONE);
lblSearch.setText(Messages.getString("dialog.TermBaseSearchDialog.lblSearch"));
GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(lblSearch);
cmbSearch = new Combo(groupSearch, SWT.DROP_DOWN | SWT.BORDER);
cmbSearch.setText(strSearchText == null ? "" : strSearchText);
GridData txtData = new GridData();
// 解决在 Windows 下文本框高度太小的问题
// txtData.heightHint = 20;
txtData.widthHint = 590;
cmbSearch.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
btnSearch = new Button(groupSearch, SWT.PUSH);
btnSearch.setText(Messages.getString("dialog.TermBaseSearchDialog.btnSearch"));
new Label(groupSearch, SWT.NONE);
Composite compCondition = new Composite(groupSearch, SWT.NONE);
GridLayoutFactory.fillDefaults().spacing(8, 0).numColumns(4).equalWidth(false).applyTo(compCondition);
GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(compCondition);
btnIsCaseSensitive = new Button(compCondition, SWT.CHECK);
btnIsCaseSensitive.setText(Messages.getString("dialog.TermBaseSearchDialog.btnIsCaseSensitive"));
GridDataFactory.swtDefaults().applyTo(btnIsCaseSensitive);
btnIsIgnoreMark = new Button(compCondition, SWT.CHECK);
btnIsIgnoreMark.setText(Messages.getString("dialog.TermBaseSearchDialog.btnIsIgnoreMark"));
btnIsIgnoreMark.setSelection(true);
GridDataFactory.swtDefaults().applyTo(btnIsIgnoreMark);
btnApplyRegularExpression = new Button(compCondition, SWT.CHECK);
btnApplyRegularExpression.setText(Messages.getString("dialog.TermBaseSearchDialog.btnApplyRegularExpression"));
GridDataFactory.swtDefaults().applyTo(btnApplyRegularExpression);
Composite compMatchQuality = new Composite(compCondition, SWT.NONE);
GridLayoutFactory.fillDefaults().extendedMargins(0, 0, 0, 0).margins(0, 0).spacing(0, 0).numColumns(3).equalWidth(false).applyTo(compMatchQuality);
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).grab(true, false).applyTo(compMatchQuality);
new Label(compMatchQuality, SWT.NONE).setText(Messages.getString("dialog.TermBaseSearchDialog.lblQuality"));
spiMatchQuality = new Spinner(compMatchQuality, SWT.BORDER);
spiMatchQuality.setMaximum(100);
spiMatchQuality.setMinimum(30);
spiMatchQuality.setIncrement(5);
spiMatchQuality.setSelection(100);
GridData spinnaData = new GridData();
spinnaData.widthHint = 23;
spiMatchQuality.setLayoutData(spinnaData);
new Label(compMatchQuality, SWT.NONE).setText("%");
Label lblTB = new Label(groupSearch, SWT.NONE);
lblTB.setText(Messages.getString("dialog.TermBaseSearchDialog.lblTB"));
GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(lblTB);
Composite cmpTB = new Composite(groupSearch, SWT.NONE);
GridLayoutFactory.fillDefaults().spacing(8, 0).numColumns(2).equalWidth(false).applyTo(cmpTB);
GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(cmpTB);
cmbDatabase = new Combo(cmpTB, SWT.READ_ONLY);
GridDataFactory.swtDefaults().hint(120, SWT.DEFAULT).applyTo(cmbDatabase);
initDatabaseCombo();
btnSelectLang = new Button(cmpTB, SWT.RIGHT);
// GridData data = new GridData();
// data.widthHint = 150;
// data.heightHint = 27;
// btnSelectLang.setLayoutData(data);
// btnSelectLang.setImage(Activator.getImageDescriptor(ImageConstants.CONCORDANCE_SELECT_LANG).createImage());
// btnSelectLang.addPaintListener(new PaintListener() {
// public void paintControl(PaintEvent e) {
// e.gc.drawText(Messages.getString("dialog.TermBaseSearchDialog.btnSelectLang"), 5, 5,
// SWT.DRAW_TRANSPARENT);
// }
// });
btnSelectLang.setText(Messages.getString("dialog.TermBaseSearchDialog.btnSelectLang"));
initLanguageMenu();
Group groupTable = new Group(tparent, SWT.NONE);
GridLayoutFactory.swtDefaults().margins(10, 10).applyTo(groupTable);
groupTable.setLayoutData(new GridData(GridData.FILL_BOTH));
// GridDataFactory.fillDefaults().hint(700, 440).applyTo(groupTable);
groupTable.setText(Messages.getString("dialog.TermBaseSearchDialog.groupTable"));
grid = new Grid(groupTable, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
grid.setHeaderVisible(true);
grid.setLinesVisible(true);
grid.setLayoutData(new GridData(GridData.FILL_BOTH));
grid.setAutoHeight(true);
grid.setRowsResizeable(true);
grid.setWordWrapHeader(true);
if (strSrcLang != null) {
columnSrcLang = new GridColumn(grid, SWT.NONE);
srcCellRenderer.setVerticalAlignment(SWT.CENTER);
srcCellRenderer.setStyleColumn(0);
columnSrcLang.setCellRenderer(srcCellRenderer);
columnSrcLang.setText(strSrcLang);
columnSrcLang.setWidth(365);
columnSrcLang.setWordWrap(true);
}
if (strTgtLang != null) {
GridColumn columnTgtLang = new GridColumn(grid, SWT.NONE);
TBSearchCellRenderer cellRenderer = new TBSearchCellRenderer();
cellRenderer.setVerticalAlignment(SWT.CENTER);
columnTgtLang.setCellRenderer(cellRenderer);
columnTgtLang.setText(strTgtLang);
columnTgtLang.setWidth(365);
columnTgtLang.setWordWrap(true);
}
for (String strLang : lstLangs) {
final GridColumn column = new GridColumn(grid, SWT.NONE);
TBSearchCellRenderer cellRenderer = new TBSearchCellRenderer();
cellRenderer.setVerticalAlignment(SWT.CENTER);
column.setCellRenderer(cellRenderer);
column.setText(strLang);
column.setWidth(0);
column.setWordWrap(true);
}
readDialogSettings();
setEnabled();
updateCombo(cmbSearch, lstSearchHistory);
if (!strSearchText.equals("")) {
cmbSearch.setText(strSearchText);
} else if (lstSearchHistory != null && lstSearchHistory.size() > 0) {
cmbSearch.setText(lstSearchHistory.get(0));
}
cmbSearch.setSelection(new Point(0, cmbSearch.getText().length()));
initListener();
return parent;
}
use of org.eclipse.nebula.widgets.grid.Grid in project translationstudio8 by heartsome.
the class TBSearchCellRenderer method getBranches.
/**
* Calculates the sequence of branch lines which should be rendered for the provided item
* @param item
* @return an array of integers composed using the constants in {@link BranchRenderer}
*/
private int[] getBranches(GridItem item) {
int[] branches = new int[item.getLevel() + 1];
GridItem[] roots = item.getParent().getRootItems();
// Is this a node or a leaf?
if (item.getParentItem() == null) {
// Add descender if not last item
if (!item.isExpanded() && roots[roots.length - 1].equals(item)) {
if (item.hasChildren())
branches[item.getLevel()] = BranchRenderer.LAST_ROOT;
else
branches[item.getLevel()] = BranchRenderer.SMALL_L;
} else {
if (item.hasChildren())
branches[item.getLevel()] = BranchRenderer.ROOT;
else
branches[item.getLevel()] = BranchRenderer.SMALL_T;
}
} else if (item.hasChildren())
if (item.isExpanded())
branches[item.getLevel()] = BranchRenderer.NODE;
else
branches[item.getLevel()] = BranchRenderer.NONE;
else
branches[item.getLevel()] = BranchRenderer.LEAF;
// Branch for current item
GridItem parent = item.getParentItem();
if (parent == null)
return branches;
// Are there siblings below this item?
if (parent.indexOf(item) < parent.getItemCount() - 1)
branches[item.getLevel() - 1] = BranchRenderer.T;
else // Is the next node a root?
if (parent.getParentItem() == null && !parent.equals(roots[roots.length - 1]))
branches[item.getLevel() - 1] = BranchRenderer.T;
else
// This must be the last element at this level
branches[item.getLevel() - 1] = BranchRenderer.L;
Grid grid = item.getParent();
item = parent;
parent = item.getParentItem();
// Branches for parent items
while (item.getLevel() > 0) {
if (parent.indexOf(item) == parent.getItemCount() - 1) {
if (parent.getParentItem() == null && !grid.getRootItem(grid.getRootItemCount() - 1).equals(parent))
branches[item.getLevel() - 1] = BranchRenderer.I;
else
branches[item.getLevel() - 1] = BranchRenderer.NONE;
} else
branches[item.getLevel() - 1] = BranchRenderer.I;
item = parent;
parent = item.getParentItem();
}
// item should be null at this point
return branches;
}
use of org.eclipse.nebula.widgets.grid.Grid in project translationstudio8 by heartsome.
the class DefaultCellRenderer method getBranches.
/**
* Calculates the sequence of branch lines which should be rendered for the provided item
* @param item
* @return an array of integers composed using the constants in {@link BranchRenderer}
*/
private int[] getBranches(GridItem item) {
int[] branches = new int[item.getLevel() + 1];
GridItem[] roots = item.getParent().getRootItems();
// Is this a node or a leaf?
if (item.getParentItem() == null) {
// Add descender if not last item
if (!item.isExpanded() && roots[roots.length - 1].equals(item)) {
if (item.hasChildren())
branches[item.getLevel()] = BranchRenderer.LAST_ROOT;
else
branches[item.getLevel()] = BranchRenderer.SMALL_L;
} else {
if (item.hasChildren())
branches[item.getLevel()] = BranchRenderer.ROOT;
else
branches[item.getLevel()] = BranchRenderer.SMALL_T;
}
} else if (item.hasChildren())
if (item.isExpanded())
branches[item.getLevel()] = BranchRenderer.NODE;
else
branches[item.getLevel()] = BranchRenderer.NONE;
else
branches[item.getLevel()] = BranchRenderer.LEAF;
// Branch for current item
GridItem parent = item.getParentItem();
if (parent == null)
return branches;
// Are there siblings below this item?
if (parent.indexOf(item) < parent.getItemCount() - 1)
branches[item.getLevel() - 1] = BranchRenderer.T;
else // Is the next node a root?
if (parent.getParentItem() == null && !parent.equals(roots[roots.length - 1]))
branches[item.getLevel() - 1] = BranchRenderer.T;
else
// This must be the last element at this level
branches[item.getLevel() - 1] = BranchRenderer.L;
Grid grid = item.getParent();
item = parent;
parent = item.getParentItem();
// Branches for parent items
while (item.getLevel() > 0) {
if (parent.indexOf(item) == parent.getItemCount() - 1) {
if (parent.getParentItem() == null && !grid.getRootItem(grid.getRootItemCount() - 1).equals(parent))
branches[item.getLevel() - 1] = BranchRenderer.I;
else
branches[item.getLevel() - 1] = BranchRenderer.NONE;
} else
branches[item.getLevel() - 1] = BranchRenderer.I;
item = parent;
parent = item.getParentItem();
}
// item should be null at this point
return branches;
}
Aggregations