use of org.eclipse.swt.events.ControlEvent 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);
}
}
}
}
});
}
}
use of org.eclipse.swt.events.ControlEvent in project dbeaver by serge-rider.
the class ViewerColumnController method recreateColumns.
private void recreateColumns(boolean pack) {
final Control control = viewer.getControl();
control.setRedraw(false);
isInitializing = true;
try {
boolean needRefresh = false;
for (ColumnInfo columnInfo : columns) {
if (columnInfo.column != null) {
columnInfo.column.dispose();
columnInfo.column = null;
needRefresh = true;
}
}
createVisibleColumns();
if (pack && !isAllSized()) {
repackColumns();
control.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
control.removeControlListener(this);
repackColumns();
}
});
}
if (needRefresh) {
viewer.refresh();
for (ColumnInfo columnInfo : getVisibleColumns()) {
if (columnInfo.column instanceof TreeColumn) {
((TreeColumn) columnInfo.column).pack();
} else {
((TableColumn) columnInfo.column).pack();
}
}
}
} finally {
control.setRedraw(true);
isInitializing = false;
}
}
use of org.eclipse.swt.events.ControlEvent in project dbeaver by serge-rider.
the class DataTransferPagePipes method createControl.
@Override
public void createControl(Composite parent) {
initializeDialogUnits(parent);
Composite composite = new Composite(parent, SWT.NULL);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
consumersTable = new TableViewer(composite, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
consumersTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
consumersTable.getTable().setLinesVisible(true);
consumersTable.setContentProvider(new IStructuredContentProvider() {
@Override
public void dispose() {
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof Collection) {
return ((Collection<?>) inputElement).toArray();
}
return new Object[0];
}
});
CellLabelProvider labelProvider = new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
TransferTarget element = (TransferTarget) cell.getElement();
if (cell.getColumnIndex() == 0) {
if (element.processor != null) {
cell.setImage(DBeaverIcons.getImage(element.processor.getIcon()));
cell.setText(element.processor.getName());
} else {
cell.setImage(DBeaverIcons.getImage(element.consumer.getIcon()));
cell.setText(element.consumer.getName());
}
} else {
if (element.processor != null) {
cell.setText(element.processor.getDescription());
} else {
cell.setText(element.consumer.getDescription());
}
}
}
};
{
TableViewerColumn columnName = new TableViewerColumn(consumersTable, SWT.LEFT);
columnName.setLabelProvider(labelProvider);
columnName.getColumn().setText(CoreMessages.data_transfer_wizard_init_column_exported);
TableViewerColumn columnDesc = new TableViewerColumn(consumersTable, SWT.LEFT);
columnDesc.setLabelProvider(labelProvider);
columnDesc.getColumn().setText(CoreMessages.data_transfer_wizard_init_column_description);
}
loadConsumers();
consumersTable.getTable().addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
final IStructuredSelection selection = (IStructuredSelection) consumersTable.getSelection();
TransferTarget target;
if (!selection.isEmpty()) {
target = (TransferTarget) selection.getFirstElement();
} else {
target = null;
}
if (target == null) {
getWizard().getSettings().selectConsumer(null, null);
} else {
getWizard().getSettings().selectConsumer(target.consumer, target.processor);
}
updatePageCompletion();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
if (isPageComplete()) {
getWizard().getContainer().showPage(getWizard().getNextPage(DataTransferPagePipes.this));
}
}
});
consumersTable.getTable().addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
UIUtils.packColumns(consumersTable.getTable());
UIUtils.maxTableColumnsWidth(consumersTable.getTable());
consumersTable.getTable().removeControlListener(this);
}
});
setControl(composite);
DataTransferNodeDescriptor consumer = getWizard().getSettings().getConsumer();
DataTransferProcessorDescriptor processor = getWizard().getSettings().getProcessor();
if (consumer != null) {
Collection<TransferTarget> targets = (Collection<TransferTarget>) consumersTable.getInput();
for (TransferTarget target : targets) {
if (target.consumer == consumer && target.processor == processor) {
consumersTable.setSelection(new StructuredSelection(target));
break;
}
}
}
updatePageCompletion();
}
use of org.eclipse.swt.events.ControlEvent in project cubrid-manager by CUBRID.
the class ShardEnvStatusView method createPartControl.
/**
* Create the page content
*
* @param parent
* the parent composite
*/
public void createPartControl(Composite parent) {
composite = new Composite(parent, SWT.NONE);
composite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
composite.setLayout(new FillLayout());
createTable();
// makeActions();
composite.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent event) {
updateTableLayout();
}
});
new StatusUpdate().start();
}
use of org.eclipse.swt.events.ControlEvent in project cubrid-manager by CUBRID.
the class BrokerEnvStatusView method createPartControl.
/**
* Create the page content
*
* @param parent the parent composite
*/
public void createPartControl(Composite parent) {
composite = new Composite(parent, SWT.NONE);
composite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
composite.setLayout(new FillLayout());
createTable();
makeActions();
composite.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent event) {
updateTableLayout();
}
});
new StatusUpdate().start();
}
Aggregations