use of org.eclipse.swt.events.ControlAdapter in project eclipse.platform.text by eclipse.
the class LineNumberRulerColumn method createControl.
@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
fParentRuler = parentRuler;
fCachedTextViewer = parentRuler.getTextViewer();
fCachedTextWidget = fCachedTextViewer.getTextWidget();
// on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the line ruler
fCachedTextWidget.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
if (fCachedTextWidget != null && fCachedTextWidget.getWordWrap()) {
postRedraw();
}
}
});
// track when StyledText is redrawn to check if some line height changed. In this case, the ruler must be redrawn
// to draw line number with well height.
VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
fCanvas = new Canvas(parentControl, SWT.NO_FOCUS) {
@Override
public void addMouseListener(MouseListener listener) {
// see bug 40889, bug 230073 and AnnotationRulerColumn#isPropagatingMouseListener()
if (listener == fMouseHandler)
super.addMouseListener(listener);
else {
TypedListener typedListener = null;
if (listener != null)
typedListener = new TypedListener(listener);
addListener(SWT.MouseDoubleClick, typedListener);
}
}
};
fCanvas.setBackground(getBackground(fCanvas.getDisplay()));
fCanvas.setForeground(fForeground);
fCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
if (fCachedTextViewer != null)
doubleBufferPaint(event.gc);
}
});
fCanvas.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
handleDispose();
fCachedTextViewer = null;
fCachedTextWidget = null;
}
});
fMouseHandler = new MouseHandler();
fCanvas.addMouseListener(fMouseHandler);
fCanvas.addMouseMoveListener(fMouseHandler);
fCanvas.addMouseWheelListener(fMouseHandler);
if (fCachedTextViewer != null) {
VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
fCachedTextViewer.addTextListener(fInternalListener);
if (fFont == null) {
if (fCachedTextWidget != null && !fCachedTextWidget.isDisposed())
fFont = fCachedTextWidget.getFont();
}
}
if (fFont != null)
fCanvas.setFont(fFont);
updateNumberOfDigits();
computeIndentations();
return fCanvas;
}
use of org.eclipse.swt.events.ControlAdapter in project eclipse.platform.swt by eclipse.
the class MJ_Table method cout_visible_items_Snippet253.
@Test
public void cout_visible_items_Snippet253() {
final Shell shell = mkShell("Ensure correct item count is displayed in count. Try resizing shell to show 15 items, it should show 15. Gtk3 issues");
knownToBeBrokenGtk3("On gtk3, the measure is off, see bug 531884");
FillLayout layout = new FillLayout(SWT.VERTICAL);
shell.setLayout(layout);
final Table table = new Table(shell, SWT.NONE);
for (int i = 0; i < 32; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText("Item " + (i + 1) + " is quite long");
}
final Button button = new Button(shell, SWT.PUSH);
Runnable fixCount = () -> {
Rectangle rect = table.getClientArea();
int itemHeight = table.getItemHeight();
int headerHeight = table.getHeaderHeight();
int visibleCount = (rect.height - headerHeight + itemHeight - 1) / itemHeight;
button.setText("Visible Items [" + visibleCount + "]");
};
button.setText("Visible Items []");
button.addListener(SWT.Selection, e -> {
fixCount.run();
});
shell.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
fixCount.run();
}
});
shell.addShellListener(new ShellAdapter() {
@Override
public void shellActivated(ShellEvent e) {
fixCount.run();
}
});
// setSize(..)_ affects bug/snippet behaviour.
// 820 => ~15 items or so, depending on your theme.
shell.setSize(1160, 820);
shell.open();
mainLoop(shell);
}
use of org.eclipse.swt.events.ControlAdapter in project translationstudio8 by heartsome.
the class QAResultViewPart method createTable.
public void createTable() {
table = new KTable(parent, SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWTX.FILL_WITH_LASTCOL | SWT.WRAP);
tableModel = new KtableModel();
table.setModel(tableModel);
table.setLayoutData(new GridData(GridData.FILL_BOTH));
table.setColorRightBorder(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
table.setColorLeftBorder(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
table.setColorTopBorder(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
table.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
locationRow();
}
});
table.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.keyCode == QAConstant.QA_CENTERKEY_1 || e.keyCode == QAConstant.QA_CENTERKEY_2) {
locationRow();
}
}
});
table.addCellResizeListener(new KTableCellResizeListener() {
public void rowResized(int arg0, int arg1) {
tableModel.textRenderer.clearRowHeiMap();
table.redraw();
}
public void columnResized(int arg0, int arg1) {
tableModel.textRenderer.clearRowHeiMap();
table.redraw();
}
});
table.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
tableModel.textRenderer.clearRowHeiMap();
table.redraw();
}
});
table.addMouseWheelListener(new MouseWheelListener() {
public void mouseScrolled(MouseEvent e) {
tableModel.textRenderer.clearRowHeiMap();
table.redraw();
}
});
createPropMenu();
}
use of org.eclipse.swt.events.ControlAdapter 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.swt.events.ControlAdapter in project dbeaver by serge-rider.
the class ViewerColumnController method createVisibleColumns.
private void createVisibleColumns() {
boolean hasLazyColumns = false;
List<ColumnInfo> visibleColumns = getVisibleColumns();
for (int i = 0; i < visibleColumns.size(); i++) {
final ColumnInfo columnInfo = visibleColumns.get(i);
columnInfo.order = i;
final Item colItem;
ViewerColumn viewerColumn;
if (viewer instanceof TreeViewer) {
final TreeViewerColumn item = new TreeViewerColumn((TreeViewer) viewer, columnInfo.style);
viewerColumn = item;
final TreeColumn column = item.getColumn();
colItem = column;
column.setText(columnInfo.name);
column.setMoveable(true);
column.setWidth(columnInfo.width);
if (!CommonUtils.isEmpty(columnInfo.description)) {
column.setToolTipText(columnInfo.description);
}
column.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
columnInfo.width = column.getWidth();
saveColumnConfig();
}
@Override
public void controlMoved(ControlEvent e) {
if (!isInitializing && e.getSource() instanceof TreeColumn) {
updateColumnOrder(column, column.getParent().getColumnOrder());
}
}
});
columnInfo.column = column;
} else if (viewer instanceof TableViewer) {
final TableViewerColumn item = new TableViewerColumn((TableViewer) viewer, columnInfo.style);
viewerColumn = item;
final TableColumn column = item.getColumn();
colItem = column;
column.setText(columnInfo.name);
column.setMoveable(true);
column.setWidth(columnInfo.width);
if (!CommonUtils.isEmpty(columnInfo.description)) {
column.setToolTipText(columnInfo.description);
}
column.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
columnInfo.width = column.getWidth();
saveColumnConfig();
}
@Override
public void controlMoved(ControlEvent e) {
if (!isInitializing && e.getSource() instanceof TableColumn) {
updateColumnOrder(column, column.getParent().getColumnOrder());
}
}
});
columnInfo.column = column;
} else {
continue;
}
viewerColumn.setLabelProvider(columnInfo.labelProvider);
viewerColumn.setEditingSupport(columnInfo.editingSupport);
colItem.setData(columnInfo);
if (columnInfo.labelProvider instanceof ILazyLabelProvider) {
hasLazyColumns = true;
} else if (columnInfo.labelProvider instanceof ILabelProvider) {
columnInfo.sortListener = new SortListener(columnInfo);
columnInfo.column.addListener(SWT.Selection, columnInfo.sortListener);
}
}
if (hasLazyColumns) {
viewer.getControl().addListener(SWT.PaintItem, new Listener() {
public void handleEvent(Event event) {
if (viewer instanceof TreeViewer) {
TreeColumn column = ((TreeViewer) viewer).getTree().getColumn(event.index);
if (((ColumnInfo) column.getData()).labelProvider instanceof ILazyLabelProvider && CommonUtils.isEmpty(((TreeItem) event.item).getText(event.index))) {
final String lazyText = ((ILazyLabelProvider) ((ColumnInfo) column.getData()).labelProvider).getLazyText(event.item.getData());
if (!CommonUtils.isEmpty(lazyText)) {
((TreeItem) event.item).setText(event.index, lazyText);
}
}
} else {
TableColumn column = ((TableViewer) viewer).getTable().getColumn(event.index);
if (((ColumnInfo) column.getData()).labelProvider instanceof ILazyLabelProvider && CommonUtils.isEmpty(((TableItem) event.item).getText(event.index))) {
final String lazyText = ((ILazyLabelProvider) ((ColumnInfo) column.getData()).labelProvider).getLazyText(event.item.getData());
if (!CommonUtils.isEmpty(lazyText)) {
((TableItem) event.item).setText(event.index, lazyText);
}
}
}
}
});
}
}
Aggregations