use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.
the class GridTableViewer method doResetItem.
/**
* {@inheritDoc}
*/
protected void doResetItem(Item item) {
GridItem gridItem = (GridItem) item;
int columnCount = Math.max(1, grid.getColumnCount());
for (int i = 0; i < columnCount; i++) {
//$NON-NLS-1$
gridItem.setText(i, "");
gridItem.setImage(null);
}
}
use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.
the class TermBaseSearchDialog method createGridItem.
/**
* 向表格中添加记录
* @param metaData
* @param map
* ;
*/
private void createGridItem(MetaData metaData, IdentityHashMap<String, String> map) {
// Bug #2232
List<HashMap<String, String>> lstMap = new ArrayList<HashMap<String, String>>();
Iterator<Entry<String, String>> it = map.entrySet().iterator();
String srcText = null;
while (it.hasNext()) {
Entry<String, String> e = (Entry<String, String>) it.next();
String key = e.getKey();
if (key.equalsIgnoreCase(strSrcLang)) {
srcText = resetCleanString(e.getValue());
continue;
}
boolean isContain = false;
for (HashMap<String, String> hashMap : lstMap) {
if (!hashMap.containsKey(key)) {
hashMap.put(key, e.getValue());
isContain = true;
}
}
if (!isContain) {
HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put(key, e.getValue());
lstMap.add(hashMap);
}
}
for (HashMap<String, String> hashMap : lstMap) {
GridItem item = new GridItem(grid, SWT.NONE);
hashMap.put("dbName", metaData.getDatabaseName());
hashMap.put("dbType", metaData.getDbType());
hashMap.put("severName", metaData.getServerName());
int arrIndex = 0;
if (strSrcLang != null) {
item.setText(arrIndex++, srcText);
}
if (strTgtLang != null) {
String tgtText = hashMap.get(strTgtLang) == null ? "" : hashMap.get(strTgtLang);
tgtText = resetCleanString(tgtText);
item.setText(arrIndex++, tgtText);
}
item.setData(hashMap);
item.setData("metaData", metaData);
for (int i = 0; i < lstLangs.size(); i++) {
item.setText((arrIndex + i), hashMap.get(lstLangs.get(i)) == null ? "" : hashMap.get(lstLangs.get(i)));
}
}
}
use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.
the class TBSearchCellRenderer method notify.
/**
* {@inheritDoc}
*/
public boolean notify(int event, Point point, Object value) {
GridItem item = (GridItem) value;
if (isCheck()) {
if (event == IInternalWidget.MouseMove) {
if (overCheck(item, point)) {
setHoverDetail("check");
return true;
}
}
if (event == IInternalWidget.LeftMouseButtonDown) {
if (overCheck(item, point)) {
if (!item.getCheckable(getColumn())) {
return false;
}
item.setChecked(getColumn(), !item.getChecked(getColumn()));
item.getParent().redraw();
item.fireCheckEvent(getColumn());
return true;
}
}
}
if (isTree() && item.hasChildren()) {
if (event == IInternalWidget.MouseMove) {
if (overToggle(item, point)) {
setHoverDetail("toggle");
return true;
}
}
if (event == IInternalWidget.LeftMouseButtonDown) {
if (overToggle(item, point)) {
item.setExpanded(!item.isExpanded());
item.getParent().redraw();
if (item.isExpanded()) {
item.fireEvent(SWT.Expand);
} else {
item.fireEvent(SWT.Collapse);
}
return true;
}
}
}
return false;
}
use of org.eclipse.nebula.widgets.grid.GridItem 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.GridItem in project translationstudio8 by heartsome.
the class TBSearchCellRenderer method computeSize.
/**
* {@inheritDoc}
*/
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
GridItem item = (GridItem) value;
gc.setFont(item.getFont(getColumn()));
int x = 0;
x += leftMargin;
if (isTree()) {
x += getToggleIndent(item);
x += toggleRenderer.getBounds().width + insideMargin;
}
if (isCheck()) {
x += checkRenderer.getBounds().width + insideMargin;
}
int y = 0;
Image image = item.getImage(getColumn());
if (image != null) {
y = topMargin + image.getBounds().height + bottomMargin;
x += image.getBounds().width + insideMargin;
}
// MOPR-DND
// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
//
// x += gc.stringExtent(item.getText(column)).x + rightMargin;
//
// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
//
// with this code:
int textHeight = 0;
if (!isWordWrap()) {
x += gc.textExtent(item.getText(getColumn())).x + rightMargin;
textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
} else {
int plainTextWidth;
if (wHint == SWT.DEFAULT)
plainTextWidth = getBounds().width - x - rightMargin;
else
plainTextWidth = wHint - x - rightMargin;
TextLayout currTextLayout = new TextLayout(gc.getDevice());
currTextLayout.setFont(gc.getFont());
currTextLayout.setText(item.getText(getColumn()));
currTextLayout.setAlignment(getAlignment());
currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);
x += plainTextWidth + rightMargin;
textHeight += topMargin + textTopMargin;
for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++) textHeight += currTextLayout.getLineBounds(cnt).height;
textHeight += textBottomMargin + bottomMargin;
currTextLayout.dispose();
}
y = Math.max(y, textHeight);
return new Point(x, y);
}
Aggregations