use of org.eclipse.jface.viewers.ColumnLayoutData in project erlide_eclipse by erlang.
the class TableLayoutComposite method layoutTable.
protected void layoutTable(final Table table, final int width, final Rectangle area, final boolean increase) {
if (width <= 1) {
return;
}
final TableColumn[] tableColumns = table.getColumns();
final int size = Math.min(columns.size(), tableColumns.length);
final int[] widths = new int[size];
int fixedWidth = 0;
int numberOfWeightColumns = 0;
int totalWeight = 0;
// First calc space occupied by fixed columns
for (int i = 0; i < size; i++) {
final ColumnLayoutData col = columns.get(i);
if (col instanceof ColumnPixelData) {
final int pixels = ((ColumnPixelData) col).width;
widths[i] = pixels;
fixedWidth += pixels;
} else if (col instanceof ColumnWeightData) {
final ColumnWeightData cw = (ColumnWeightData) col;
numberOfWeightColumns++;
// first time, use the weight specified by the column data,
// otherwise use
// the actual width as the weight
// int weight = firstTime ? cw.weight :
// tableColumns[i].getWidth();
final int weight = cw.weight;
totalWeight += weight;
} else {
// $NON-NLS-1$
Assert.isTrue(false, "Unknown column layout data");
}
}
// Do we have columns that have a weight
if (numberOfWeightColumns > 0) {
// Now distribute the rest to the columns with weight.
final int rest = width - fixedWidth;
int totalDistributed = 0;
for (int i = 0; i < size; ++i) {
final ColumnLayoutData col = columns.get(i);
if (col instanceof ColumnWeightData) {
final ColumnWeightData cw = (ColumnWeightData) col;
// calculate weight as above
// int weight = firstTime ? cw.weight :
// tableColumns[i].getWidth();
final int weight = cw.weight;
int pixels = totalWeight == 0 ? 0 : weight * rest / totalWeight;
if (pixels < cw.minimumWidth) {
pixels = cw.minimumWidth;
}
totalDistributed += pixels;
widths[i] = pixels;
}
}
// Distribute any remaining pixels to columns with weight.
int diff = rest - totalDistributed;
for (int i = 0; diff > 0; ++i) {
if (i == size) {
i = 0;
}
final ColumnLayoutData col = columns.get(i);
if (col instanceof ColumnWeightData) {
++widths[i];
--diff;
}
}
}
if (increase) {
table.setSize(area.width, area.height);
}
for (int i = 0; i < size; i++) {
tableColumns[i].setWidth(widths[i]);
}
if (!increase) {
table.setSize(area.width, area.height);
}
}
use of org.eclipse.jface.viewers.ColumnLayoutData in project liferay-ide by liferay.
the class FreemarkerMultiPageEditor method createContextPage.
void createContextPage() {
contextValues = new Properties();
Composite composite = new Composite(getContainer(), SWT.NULL);
composite.setLayout(new FillLayout());
contextValuesTable = new Table(composite, SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION);
contextValuesTable.setVisible(true);
contextValuesTable.setLinesVisible(false);
contextValuesTable.setHeaderVisible(true);
contextValuesTable.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
editContextValueButton.setEnabled(true);
deleteContextValueButton.setEnabled(true);
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
contextValuesTable.addKeyListener(new ContextValueDeleteKeyListener());
contextValuesTable.addMouseListener(new EditContextValueButtonListener());
// create the columns
TableColumn keyColumn = new TableColumn(contextValuesTable, SWT.LEFT);
TableColumn valueColumn = new TableColumn(contextValuesTable, SWT.LEFT);
keyColumn.setText(Messages.FreemarkerMultiPageEditor_COLUMN_NAME);
valueColumn.setText(Messages.FreemarkerMultiPageEditor_COLUMN_TYPE);
ColumnLayoutData keyColumnLayout = new ColumnWeightData(30, false);
ColumnLayoutData valueColumnLayout = new ColumnWeightData(70, false);
// set columns in Table layout
TableLayout tableLayout = new TableLayout();
tableLayout.addColumnData(keyColumnLayout);
tableLayout.addColumnData(valueColumnLayout);
contextValuesTable.setLayout(tableLayout);
GridData data = new GridData(GridData.FILL_BOTH);
data.heightHint = 50;
data.grabExcessHorizontalSpace = true;
data.grabExcessVerticalSpace = true;
contextValuesTable.setLayoutData(data);
Composite buttonComposite = new Composite(composite, SWT.NONE);
data = new GridData();
data.horizontalAlignment = GridData.BEGINNING;
data.verticalAlignment = GridData.BEGINNING;
buttonComposite.setLayoutData(data);
GridLayout gl = new GridLayout(1, true);
buttonComposite.setLayout(gl);
buttonComposite.setVisible(true);
addContextValueButton = new Button(buttonComposite, SWT.NATIVE);
addContextValueButton.setText(Messages.FreemarkerMultiPageEditor_BUTTON_NEW);
addContextValueButton.setVisible(true);
addContextValueButton.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
addContextValueButton.addSelectionListener(new AddContextValueButtonListener());
data = new GridData();
data.widthHint = 45;
data.grabExcessHorizontalSpace = true;
addContextValueButton.setLayoutData(data);
editContextValueButton = new Button(buttonComposite, SWT.NATIVE);
editContextValueButton.setText(Messages.FreemarkerMultiPageEditor_BUTTON_EDIT);
editContextValueButton.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
editContextValueButton.addSelectionListener(new EditContextValueButtonListener());
data = new GridData();
data.widthHint = 45;
data.grabExcessHorizontalSpace = true;
editContextValueButton.setLayoutData(data);
deleteContextValueButton = new Button(buttonComposite, SWT.NATIVE);
deleteContextValueButton.setText(Messages.FreemarkerMultiPageEditor_BUTTON_DELETE);
deleteContextValueButton.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
deleteContextValueButton.addSelectionListener(new ContextValueDeleteKeyListener());
data = new GridData();
data.widthHint = 45;
data.grabExcessHorizontalSpace = true;
deleteContextValueButton.setLayoutData(data);
reloadContextValues();
int index = addPage(composite);
setPageText(index, Messages.FreemarkerMultiPageEditor_PAGE_TEXT_CONTEXT);
}
use of org.eclipse.jface.viewers.ColumnLayoutData in project jbosstools-hibernate by jbosstools.
the class AutoResizeTableLayout method autoSizeColumns.
private void autoSizeColumns() {
int width = table.getClientArea().width;
if (width <= 1) {
return;
}
TableColumn[] tableColumns = table.getColumns();
int size = Math.min(columns.size(), tableColumns.length);
int[] widths = new int[size];
int fixedWidth = 0;
int numberOfWeightColumns = 0;
int totalWeight = 0;
// First calc space occupied by fixed columns.
for (int i = 0; i < size; i++) {
ColumnLayoutData col = columns.get(i);
if (col instanceof ColumnPixelData) {
int pixels = ((ColumnPixelData) col).width;
widths[i] = pixels;
fixedWidth += pixels;
} else if (col instanceof ColumnWeightData) {
ColumnWeightData cw = (ColumnWeightData) col;
numberOfWeightColumns++;
int weight = cw.weight;
totalWeight += weight;
} else {
throw new IllegalStateException(HibernateConsoleMessages.AutoResizeTableLayout_unknown_column_layout_data);
}
}
// Do we have columns that have a weight?
if (numberOfWeightColumns > 0) {
// Now, distribute the rest
// to the columns with weight.
int rest = width - fixedWidth;
int totalDistributed = 0;
for (int i = 0; i < size; i++) {
ColumnLayoutData col = columns.get(i);
if (col instanceof ColumnWeightData) {
ColumnWeightData cw = (ColumnWeightData) col;
int weight = cw.weight;
int pixels = totalWeight == 0 ? 0 : weight * rest / totalWeight;
totalDistributed += pixels;
widths[i] = pixels;
}
}
// Distribute any remaining pixels
// to columns with weight.
int diff = rest - totalDistributed;
for (int i = 0; diff > 0; i++) {
if (i == size) {
i = 0;
}
ColumnLayoutData col = columns.get(i);
if (col instanceof ColumnWeightData) {
++widths[i];
--diff;
}
}
}
for (int i = 0; i < size; i++) {
if (tableColumns[i].getWidth() != widths[i]) {
tableColumns[i].setWidth(widths[i]);
}
}
}
Aggregations