use of org.eclipse.jface.viewers.ColumnLayoutData in project eclipse.platform.text by eclipse.
the class ColumnLayout method computeTableSize.
private Point computeTableSize(Table table, int wHint, int hHint) {
Point result = table.computeSize(wHint, hHint);
int width = 0;
int size = columns.size();
for (int i = 0; i < size; ++i) {
ColumnLayoutData layoutData = columns.get(i);
if (layoutData instanceof ColumnPixelData) {
ColumnPixelData col = (ColumnPixelData) layoutData;
width += col.width;
if (col.addTrim) {
width += COLUMN_TRIM;
}
} else if (layoutData instanceof ColumnWeightData) {
ColumnWeightData col = (ColumnWeightData) layoutData;
width += col.minimumWidth;
} else {
// $NON-NLS-1$
Assert.isTrue(false, "Unknown column layout data");
}
}
if (width > result.x)
result.x = width;
return result;
}
use of org.eclipse.jface.viewers.ColumnLayoutData in project eclipse.platform.text by eclipse.
the class ColumnLayout method layoutTable.
private void layoutTable(final Table table, final int width, final Rectangle area, final boolean increase) {
final TableColumn[] tableColumns = table.getColumns();
final int size = Math.min(columns.size(), tableColumns.length);
final int[] widths = new int[size];
final int[] weightIteration = new int[size];
int numberOfWeightColumns = 0;
int fixedWidth = 0;
int minWeightWidth = 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) {
ColumnPixelData cpd = (ColumnPixelData) col;
int pixels = cpd.width;
if (cpd.addTrim) {
pixels += COLUMN_TRIM;
}
widths[i] = pixels;
fixedWidth += pixels;
} else if (col instanceof ColumnWeightData) {
ColumnWeightData cw = (ColumnWeightData) col;
weightIteration[numberOfWeightColumns] = i;
numberOfWeightColumns++;
totalWeight += cw.weight;
minWeightWidth += cw.minimumWidth;
widths[i] = cw.minimumWidth;
} else {
// $NON-NLS-1$
Assert.isTrue(false, "Unknown column layout data");
}
}
// Do we have columns that have a weight?
final int restIncludingMinWidths = width - fixedWidth;
final int rest = restIncludingMinWidths - minWeightWidth;
if (numberOfWeightColumns > 0 && rest > 0) {
// Modify the weights to reflect what each column already
// has due to its minimum. Otherwise, columns with low
// minimums get discriminated.
int totalWantedPixels = 0;
final int[] wantedPixels = new int[numberOfWeightColumns];
for (int i = 0; i < numberOfWeightColumns; i++) {
ColumnWeightData cw = (ColumnWeightData) columns.get(weightIteration[i]);
wantedPixels[i] = totalWeight == 0 ? 0 : cw.weight * restIncludingMinWidths / totalWeight;
totalWantedPixels += wantedPixels[i];
}
// Now distribute the rest to the columns with weight.
int totalDistributed = 0;
for (int i = 0; i < numberOfWeightColumns; ++i) {
int pixels = totalWantedPixels == 0 ? 0 : wantedPixels[i] * rest / totalWantedPixels;
totalDistributed += pixels;
widths[weightIteration[i]] += pixels;
}
// Distribute any remaining pixels to columns with weight.
int diff = rest - totalDistributed;
for (int i = 0; diff > 0; i = ((i + 1) % numberOfWeightColumns)) {
++widths[weightIteration[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 eclipse.platform.text by eclipse.
the class HyperlinkDetectorsConfigurationBlock method createControl.
@Override
public Control createControl(Composite parent) {
PixelConverter pixelConverter = new PixelConverter(parent);
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
addFiller(composite, 2);
String label = TextEditorMessages.HyperlinksEnabled_label;
fHyperlinksEnabledCheckBox = addCheckBox(composite, label, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED, 0);
fHyperlinksEnabledCheckBox.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean state = fHyperlinksEnabledCheckBox.getSelection();
fHyperlinkDefaultKeyModifierText.setEnabled(state);
fHyperlinkKeyModifierText.setEnabled(state && getSelectedItem() != null);
fHyperlinkDetectorsViewer.getTable().setEnabled(state);
handleHyperlinkKeyModifierModified();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
// Text field for default modifier string
label = TextEditorMessages.HyperlinkDefaultKeyModifier_label;
fHyperlinkDefaultKeyModifierText = (Text) addTextField(composite, label, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINK_KEY_MODIFIER, 15, 20, pixelConverter)[1];
fHyperlinkDefaultKeyModifierText.addKeyListener(new KeyListener() {
private boolean isModifierCandidate;
@Override
public void keyPressed(KeyEvent e) {
isModifierCandidate = e.keyCode > 0 && e.character == 0 && e.stateMask == 0;
}
@Override
public void keyReleased(KeyEvent e) {
if (isModifierCandidate && e.stateMask > 0 && e.stateMask == e.stateMask && e.character == 0) {
// && e.time -time < 1000) {
String modifierString = fHyperlinkDefaultKeyModifierText.getText();
Point selection = fHyperlinkDefaultKeyModifierText.getSelection();
int i = selection.x - 1;
while (i > -1 && Character.isWhitespace(modifierString.charAt(i))) {
i--;
}
boolean needsPrefixDelimiter = i > -1 && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
i = selection.y;
while (i < modifierString.length() && Character.isWhitespace(modifierString.charAt(i))) {
i++;
}
boolean needsPostfixDelimiter = i < modifierString.length() && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
String insertString;
if (needsPrefixDelimiter && needsPostfixDelimiter)
insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifierAndDelimiter, Action.findModifierString(e.stateMask));
else if (needsPrefixDelimiter)
insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifier, Action.findModifierString(e.stateMask));
else if (needsPostfixDelimiter)
insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertModifierAndDelimiter, Action.findModifierString(e.stateMask));
else
insertString = Action.findModifierString(e.stateMask);
fHyperlinkDefaultKeyModifierText.insert(insertString);
}
}
});
fHyperlinkDefaultKeyModifierText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
handleHyperlinkDefaultKeyModifierModified();
}
});
addFiller(composite, 2);
Composite editorComposite = new Composite(composite, SWT.NONE);
GridData gd;
gd = new GridData(SWT.FILL, SWT.TOP, true, false);
gd.horizontalSpan = 2;
gd.horizontalIndent = 20;
editorComposite.setLayoutData(gd);
TableColumnLayout tableColumnlayout = new TableColumnLayout();
editorComposite.setLayout(tableColumnlayout);
// Hyperlink detector table
Table hyperlinkDetectorTable = new Table(editorComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION | SWT.CHECK);
hyperlinkDetectorTable.setHeaderVisible(true);
hyperlinkDetectorTable.setLinesVisible(true);
hyperlinkDetectorTable.setFont(parent.getFont());
hyperlinkDetectorTable.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
handleListSelection();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
ColumnLayoutData columnLayoutData = new ColumnWeightData(1);
TableColumn nameColumn = new TableColumn(hyperlinkDetectorTable, SWT.NONE, 0);
nameColumn.setText(TextEditorMessages.HyperlinkDetectorTable_nameColumn);
tableColumnlayout.setColumnData(nameColumn, columnLayoutData);
TableColumn modifierKeysColumn = new TableColumn(hyperlinkDetectorTable, SWT.NONE, 1);
modifierKeysColumn.setText(TextEditorMessages.HyperlinkDetectorTable_modifierKeysColumn);
tableColumnlayout.setColumnData(modifierKeysColumn, columnLayoutData);
TableColumn targetNameColumn = new TableColumn(hyperlinkDetectorTable, SWT.NONE, 2);
targetNameColumn.setText(TextEditorMessages.HyperlinkDetectorTable_targetNameColumn);
tableColumnlayout.setColumnData(targetNameColumn, columnLayoutData);
fHyperlinkDetectorsViewer = new CheckboxTableViewer(hyperlinkDetectorTable);
fHyperlinkDetectorsViewer.setUseHashlookup(true);
fHyperlinkDetectorsViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
String id = ((ListItem) event.getElement()).id;
if (id == null)
return;
fStore.setValue(id, !event.getChecked());
}
});
fHyperlinkDetectorsViewer.setLabelProvider(new ItemLabelProvider());
fHyperlinkDetectorsViewer.setContentProvider(new ItemContentProvider());
gd = new GridData(SWT.FILL, SWT.FILL, true, false);
gd.heightHint = pixelConverter.convertHeightInCharsToPixels(10);
fHyperlinkDetectorsViewer.getControl().setLayoutData(gd);
// addFiller(composite, 2);
// Text field for modifier string
label = TextEditorMessages.HyperlinkKeyModifier_label;
fHyperlinkKeyModifierText = (Text) addTextField(composite, label, null, 15, 20, pixelConverter)[1];
fHyperlinkKeyModifierText.addKeyListener(new KeyListener() {
private boolean isModifierCandidate;
@Override
public void keyPressed(KeyEvent e) {
isModifierCandidate = e.keyCode > 0 && e.character == 0 && e.stateMask == 0;
}
@Override
public void keyReleased(KeyEvent e) {
if (isModifierCandidate && e.stateMask > 0 && e.stateMask == e.stateMask && e.character == 0) {
// && e.time -time < 1000) {
String modifierString = fHyperlinkKeyModifierText.getText();
Point selection = fHyperlinkKeyModifierText.getSelection();
int i = selection.x - 1;
while (i > -1 && Character.isWhitespace(modifierString.charAt(i))) {
i--;
}
boolean needsPrefixDelimiter = i > -1 && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
i = selection.y;
while (i < modifierString.length() && Character.isWhitespace(modifierString.charAt(i))) {
i++;
}
boolean needsPostfixDelimiter = i < modifierString.length() && !String.valueOf(modifierString.charAt(i)).equals(MODIFIER_DELIMITER);
String insertString;
if (needsPrefixDelimiter && needsPostfixDelimiter)
insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifierAndDelimiter, Action.findModifierString(e.stateMask));
else if (needsPrefixDelimiter)
insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertDelimiterAndModifier, Action.findModifierString(e.stateMask));
else if (needsPostfixDelimiter)
insertString = NLSUtility.format(TextEditorMessages.HyperlinkKeyModifier_insertModifierAndDelimiter, Action.findModifierString(e.stateMask));
else
insertString = Action.findModifierString(e.stateMask);
fHyperlinkKeyModifierText.insert(insertString);
}
}
});
fHyperlinkKeyModifierText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
handleHyperlinkKeyModifierModified();
}
});
return composite;
}
use of org.eclipse.jface.viewers.ColumnLayoutData in project xtext-eclipse by eclipse.
the class AssociationHierarchyViewPart method getLocationColumnDescriptions.
@Override
protected Pair<String, ColumnLayoutData>[] getLocationColumnDescriptions() {
ColumnWeightData _columnWeightData = new ColumnWeightData(60);
Pair<String, ColumnLayoutData> _mappedTo = Pair.<String, ColumnLayoutData>of("Line", _columnWeightData);
ColumnWeightData _columnWeightData_1 = new ColumnWeightData(300);
Pair<String, ColumnLayoutData> _mappedTo_1 = Pair.<String, ColumnLayoutData>of("Property", _columnWeightData_1);
return new Pair[] { _mappedTo, _mappedTo_1 };
}
use of org.eclipse.jface.viewers.ColumnLayoutData in project xtext-eclipse by eclipse.
the class AbstractCallHierarchyViewPart method createLocationViewer.
protected TableViewer createLocationViewer(final Composite parent) {
final TableViewer locationViewer = new TableViewer(parent);
ArrayContentProvider _arrayContentProvider = new ArrayContentProvider();
locationViewer.setContentProvider(_arrayContentProvider);
locationViewer.setLabelProvider(this.createLocationLabelProvider());
final TableLayout layout = new TableLayout();
Table _table = locationViewer.getTable();
_table.setLayout(layout);
Table _table_1 = locationViewer.getTable();
_table_1.setHeaderVisible(true);
final Consumer<Pair<Integer, Pair<String, ColumnLayoutData>>> _function = (Pair<Integer, Pair<String, ColumnLayoutData>> it) -> {
layout.addColumnData(it.getValue().getValue());
this.createColumn(locationViewer.getTable(), it.getValue(), (it.getKey()).intValue());
};
IterableExtensions.<Pair<String, ColumnLayoutData>>indexed(((Iterable<? extends Pair<String, ColumnLayoutData>>) Conversions.doWrapArray(this.getLocationColumnDescriptions()))).forEach(_function);
return locationViewer;
}
Aggregations