use of org.eclipse.nebula.widgets.grid.GridColumn in project translationstudio8 by heartsome.
the class DefaultColumnHeaderRenderer method getControlBounds.
/**
* @return the bounds reserved for the control
*/
protected Rectangle getControlBounds(Object value, boolean preferred) {
Rectangle bounds = getBounds();
GridColumn column = (GridColumn) value;
Point controlSize = computeControlSize(column);
int y = getBounds().y + getBounds().height - bottomMargin - controlSize.y;
return new Rectangle(bounds.x + 3, y, bounds.width - 6, controlSize.y);
}
use of org.eclipse.nebula.widgets.grid.GridColumn in project translationstudio8 by heartsome.
the class TerminologyViewPart method createPartControl.
/**
* 创建控件。
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
this.parent = parent;
createAction();
GridLayout parentGl = new GridLayout(1, false);
parentGl.marginWidth = 0;
parentGl.marginHeight = 0;
parent.setLayout(parentGl);
final Composite contentPanel = new Composite(parent, SWT.NONE);
GridLayout secondPageCompositeGl = new GridLayout(1, false);
secondPageCompositeGl.marginBottom = -1;
secondPageCompositeGl.marginLeft = -1;
secondPageCompositeGl.marginRight = -1;
secondPageCompositeGl.marginTop = -1;
secondPageCompositeGl.marginWidth = 0;
secondPageCompositeGl.marginHeight = 0;
contentPanel.setLayout(secondPageCompositeGl);
contentPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
contentPanel.setLayout(secondPageCompositeGl);
contentPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
// firstPageComposite = new Composite(contentPanel, SWT.NONE);
// firstPageComposite.setLayout(new GridLayout(1, false));
// secondPageComposite = new Composite(contentPanel, SWT.NONE);
// GridLayout secondPageCompositeGl = new GridLayout(1, false);
// secondPageCompositeGl.marginBottom = -1;
// secondPageCompositeGl.marginLeft = -1;
// secondPageCompositeGl.marginRight = -1;
// secondPageCompositeGl.marginTop = -1;
// secondPageCompositeGl.marginWidth = 0;
// secondPageCompositeGl.marginHeight = 0;
// secondPageComposite.setLayout(secondPageCompositeGl);
// secondPageComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
gridTable = new Grid(contentPanel, SWT.BORDER | SWT.V_SCROLL);
gridTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
gridTable.setHeaderVisible(true);
gridTable.setAutoHeight(true);
gridTable.setRowsResizeable(true);
gridTable.setData("selectedBgColor", selectedBgColor);
final GridColumn idItem = new GridColumn(gridTable, SWT.NONE);
idItem.setText(Messages.getString("view.TerminologyViewPart.idItem"));
idColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
idColumnCellRenderer.setVerticalAlignment(SWT.CENTER);
idItem.setCellRenderer(idColumnCellRenderer);
idItem.setWordWrap(true);
srcTableColumn = new GridColumn(gridTable, SWT.NONE);
srcTableColumn.setText(Messages.getString("view.TerminologyViewPart.srcTableColumn"));
srcColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
srcTableColumn.setCellRenderer(srcColumnCellRenderer);
srcTableColumn.setWordWrap(true);
tgtTableColumn = new GridColumn(gridTable, SWT.NONE);
tgtTableColumn.setText(Messages.getString("view.TerminologyViewPart.tgtTableColumn"));
tgtColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
tgtTableColumn.setCellRenderer(tgtColumnCellRenderer);
tgtTableColumn.setWordWrap(true);
final GridColumn propertyColumn = new GridColumn(gridTable, SWT.NONE);
propertyColumn.setText(Messages.getString("view.TerminologyViewPart.propertyColumn"));
propColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
propertyColumn.setCellRenderer(propColumnCellRenderer);
propertyColumn.setWordWrap(true);
copyEnable = new GridCopyEnable(gridTable);
srcColumnCellRenderer.setCopyEnable(copyEnable);
tgtColumnCellRenderer.setCopyEnable(copyEnable);
// 设置列宽按比例
contentPanel.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Rectangle area = contentPanel.getClientArea();
Point preferredSize = gridTable.computeSize(SWT.DEFAULT, SWT.DEFAULT);
// - 2 * gridTable.getBorderWidth();
int width = area.width;
if (preferredSize.y > area.height + gridTable.getHeaderHeight()) {
Point vBarSize = gridTable.getVerticalBar().getSize();
width -= vBarSize.x;
}
gridTable.setSize(area.width, area.height);
width -= 45;
idItem.setWidth(45);
srcTableColumn.setWidth((int) (width * 0.4));
tgtTableColumn.setWidth((int) (width * 0.4));
propertyColumn.setWidth((int) (width * 0.2));
}
});
Composite statusComposite = new Composite(contentPanel, SWT.NONE);
GridLayout statusComptGridLayout = new GridLayout(2, false);
statusComptGridLayout.marginBottom = -1;
statusComptGridLayout.marginLeft = -1;
statusComptGridLayout.marginRight = -1;
statusComptGridLayout.marginTop = -1;
statusComptGridLayout.marginWidth = 0;
statusComptGridLayout.marginHeight = 0;
statusComposite.setLayout(statusComptGridLayout);
statusComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
tipLabel = new CLabel(statusComposite, SWT.NONE);
tipLabel.setAlignment(SWT.LEFT);
CLabel label = new CLabel(statusComposite, SWT.None);
GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd.heightHint = 20;
label.setLayoutData(gd);
gridTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
selectItem();
}
});
gridTable.addListener(SWT.MouseDoubleClick, new Listener() {
public void handleEvent(Event event) {
firstAction.run();
}
});
initHookMenu();
}
use of org.eclipse.nebula.widgets.grid.GridColumn in project archi by archimatetool.
the class RelationshipsMatrixDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
setTitle(Messages.RelationshipsMatrixDialog_0);
setMessage(Messages.RelationshipsMatrixDialog_1);
Composite composite = (Composite) super.createDialogArea(parent);
Composite client = new Composite(composite, SWT.NULL);
GridLayout layout = new GridLayout(2, false);
client.setLayout(layout);
client.setLayoutData(new GridData(GridData.FILL_BOTH));
GridData gd;
GridTableViewer viewer = new GridTableViewer(client);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 800;
gd.heightHint = 500;
viewer.getControl().setLayoutData(gd);
viewer.getGrid().setHeaderVisible(true);
viewer.getGrid().setRowHeaderVisible(true);
viewer.getGrid().setRowsResizeable(true);
viewer.getGrid().setCellSelectionEnabled(true);
// viewer.setColumnProperties(new String[] {"1", "2", "3"});
viewer.setRowHeaderLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(ArchiLabelProvider.INSTANCE.getDefaultName((EClass) cell.getElement()));
cell.setImage(ArchiLabelProvider.INSTANCE.getImage(cell.getElement()));
}
});
for (EClass eClass : getData()) {
GridColumn column = new GridColumn(viewer.getGrid(), SWT.NONE);
column.setWidth(70);
column.setImage(ArchiLabelProvider.INSTANCE.getImage(eClass));
column.setHeaderTooltip(ArchiLabelProvider.INSTANCE.getDefaultName(eClass));
}
viewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
return getData().toArray();
}
});
viewer.setLabelProvider(new MyLabelProvider());
// hookContextMenu(viewer);
viewer.setInput(getData());
// $NON-NLS-1$
String text = "";
for (Entry<EClass, Character> entry : RelationshipsMatrix.INSTANCE.getRelationshipsValueMap().entrySet()) {
// $NON-NLS-1$ //$NON-NLS-2$
text += entry.getValue() + ": " + ArchiLabelProvider.INSTANCE.getDefaultName(entry.getKey()) + "\n";
}
Label label = new Label(client, SWT.NULL);
label.setText(text);
label.setLayoutData(new GridData(SWT.TOP, SWT.TOP, false, true));
return composite;
}
use of org.eclipse.nebula.widgets.grid.GridColumn in project tdq-studio-se by Talend.
the class AbstractIndicatorSelectGrid method handleCellHighlight.
// private boolean handleMouseScroll(MouseEvent e) {
// if (e.x > getRowHeaderWidth() && e.x < getRowHeaderWidth() + 150) {
// ScrollBar hScrollBar = getHorizontalBar();
// if (hScrollBar.getSelection() == hScrollBar.getMinimum()) {
// return false;
// }
// if (!isScrolling && e.x < getRowHeaderWidth() + 100) {
// isScrolling = true;
// thread = new HoverScrollThread(-1, hScrollBar);
// Display.getDefault().timerExec(200, thread);
// handleCellHighlight(e, getVisibleRange());
// }
// if (isScrolling) {
// thread.setAccelaration(getRowHeaderWidth() + 150 - e.x);
// startColumnIndex = -1;
// endColumnIndex = -1;
// return true;
// }
// } else if (e.x > getBounds().width - 150 && e.x < getBounds().width) {
// ScrollBar hScrollBar = getHorizontalBar();
// if (!isScrolling && e.x > getBounds().width - 100) {
// isScrolling = true;
// thread = new HoverScrollThread(1, hScrollBar);
// Display.getDefault().timerExec(200, thread);
// handleCellHighlight(e, getVisibleRange());
// }
// if (isScrolling) {
// thread.setAccelaration(e.x + 150 - getBounds().width);
// startColumnIndex = -1;
// endColumnIndex = -1;
// return true;
// }
// } else {
// if (isScrolling) {
// isScrolling = false;
// Display.getDefault().timerExec(-1, thread); // interrupt the thread
// }
// }
// return false;
// }
private boolean handleCellHighlight(MouseEvent e, GridVisibleRange range) {
Point cell = getCell(new Point(e.x, e.y));
if (cell != null) {
// any cell except the row select cells
List<GridColumn> columnList = Arrays.asList(range.getColumns());
// replace cell.x with the current position in case the column has been moved.
cell.x = columnList.indexOf(getColumn(cell.x)) + 2;
for (GridItem item : range.getItems()) {
int i = indexOf(item);
// set background for row headers
if (i == cell.y) {
item.setBackground(0, highlightBlue);
item.setBackground(1, highlightBlue);
} else {
item.setBackground(0, gray);
item.setBackground(1, getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
if (item.getCheckable(1)) {
item.setBackground(highlightBlue);
}
}
// set background for cells
for (GridColumn column : range.getColumns()) {
// real index in current visible range.
int realIdx = columnList.indexOf(column) + 2;
// the original index to be colored.
int j = indexOf(column);
if (i == cell.y && realIdx == cell.x) {
item.setBackground(j, highlightBlue);
} else if (i == cell.y && realIdx < cell.x || realIdx == cell.x && i < cell.y) {
item.setBackground(j, highlightBlue);
} else {
item.setBackground(j, null);
}
}
}
// set background for column headers
for (GridColumn column : range.getColumns()) {
// real index in current visible range.
int realIdx = columnList.indexOf(column) + 2;
column.getHeaderRenderer().setSelected(realIdx == cell.x);
}
return true;
}
return false;
}
use of org.eclipse.nebula.widgets.grid.GridColumn in project tdq-studio-se by Talend.
the class AbstractIndicatorSelectGrid method createRowSelectColumn.
/**
* This column just used to take in space so that visible is false
*/
protected void createRowSelectColumn() {
GridColumn rowSelectCol = new TalendGridColumn(this, SWT.CHECK);
rowSelectCol.setHeaderRenderer(getColumnHeaderRenderer());
rowSelectCol.setCellRenderer(getCellRenderer());
// $NON-NLS-1$
rowSelectCol.setText("Select All");
rowSelectCol.setWidth(COLUMN_WIDTH);
rowSelectCol.setWordWrap(true);
rowSelectCol.setCellSelectionEnabled(true);
// hide the row select column, it is also visible in the fixed column.
rowSelectCol.setVisible(false);
}
Aggregations