use of org.eclipse.jface.viewers.ColumnWeightData in project tdi-studio-se by Talend.
the class AssignmentPropertySection method createControls.
@Override
public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
super.createControls(parent, aTabbedPropertySheetPage);
composite = getWidgetFactory().createFlatFormComposite(parent);
// PTODO mhelleboid externalize tableviewer creation
adapterFactory = new BusinessItemProviderAdapterFactory();
tableViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
tableViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
tableViewer.setLabelProvider(new RepositoryFactoryProxyLabelProvider(adapterFactory));
Table table = tableViewer.getTable();
TableLayout tableLayout = new TableLayout();
table.setLayout(tableLayout);
table.setHeaderVisible(true);
table.setLinesVisible(true);
final String[] columnProperties = new String[] { Messages.getString("AssignmentPropertySection.Type"), Messages.getString("AssignmentPropertySection.Name"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Messages.getString("AssignmentPropertySection.Comment") };
TableColumn column1 = new TableColumn(table, SWT.NONE);
tableLayout.addColumnData(new ColumnPixelData(125, true));
column1.setText(columnProperties[0]);
TableColumn column2 = new TableColumn(table, SWT.NONE);
tableLayout.addColumnData(new ColumnPixelData(125, true));
column2.setText(columnProperties[1]);
TableColumn column3 = new TableColumn(table, SWT.NONE);
tableLayout.addColumnData(new ColumnWeightData(1, 150, true));
column3.setText(columnProperties[2]);
tableViewer.setColumnProperties(columnProperties);
final IItemPropertyDescriptor itemPropertyDescriptor = getItemPropertyDescriptor();
tableViewer.setCellModifier(new ICellModifier() {
public boolean canModify(Object element, String property) {
return property.equals(columnProperties[2]);
}
public Object getValue(Object element, String property) {
return EmfPropertyHelper.getValue(itemPropertyDescriptor, element);
}
public void modify(Object element, String property, Object value) {
if (element instanceof TableItem) {
TableItem tableItem = (TableItem) element;
itemPropertyDescriptor.setPropertyValue(tableItem.getData(), value);
}
}
});
CellEditor[] cellEditors = new CellEditor[3];
cellEditors[2] = new TextCellEditor(table);
tableViewer.setCellEditors(cellEditors);
createKeyListener(table);
createSelectionListener();
createPopupMenu();
createDoubleClickListener();
handleLayout(parent, table, column1, column2, column3);
aTabbedPropertySheetPage.getSite().setSelectionProvider(this);
}
use of org.eclipse.jface.viewers.ColumnWeightData in project bndtools by bndtools.
the class BundleTree method createInfoViewer.
private void createInfoViewer(Composite container) {
infoViewerComposite = new Composite(container, SWT.NONE);
infoViewerComposite.setLayoutData(createFillGridData());
TreeColumnLayout layout = new TreeColumnLayout();
infoViewerComposite.setLayout(layout);
infoViewer = new TreeViewer(infoViewerComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
infoViewer.setUseHashlookup(true);
infoViewer.getTree().setHeaderVisible(true);
TreeViewerColumn treeViewerColumn = new TreeViewerColumn(infoViewer, SWT.NONE);
TreeColumn treeColumn = treeViewerColumn.getColumn();
layout.setColumnData(treeColumn, new ColumnWeightData(450, 180, true));
treeColumn.setText(Messages.bundleAndPackageName);
treeViewerColumn.setLabelProvider(new InfoLabelProvider());
treeViewerColumn = new TreeViewerColumn(infoViewer, SWT.NONE);
treeColumn = treeViewerColumn.getColumn();
layout.setColumnData(treeColumn, new ColumnWeightData(80, 80, true));
treeColumn.setText(Messages.version2);
treeViewerColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof Baseline) {
return ((Baseline) element).getOlderVersion().getWithoutQualifier().toString();
}
if (element instanceof Info) {
return ((Info) element).olderVersion.toString();
}
//$NON-NLS-1$
return "";
}
});
treeViewerColumn = new TreeViewerColumn(infoViewer, SWT.NONE);
treeColumn = treeViewerColumn.getColumn();
layout.setColumnData(treeColumn, new ColumnWeightData(80, 80, true));
treeColumn.setText(Messages.newVersion);
treeViewerColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof Baseline) {
return ((Baseline) element).getSuggestedVersion().toString();
}
if (element instanceof Info) {
//$NON-NLS-1$
return ((Info) element).suggestedVersion != null ? ((Info) element).suggestedVersion.toString() : "";
}
//$NON-NLS-1$
return "";
}
});
treeViewerColumn.setEditingSupport(new InlineComboEditingSupport(infoViewer));
infoViewer.setContentProvider(infoTreeViewerProvider);
infoViewer.setAutoExpandLevel(2);
}
use of org.eclipse.jface.viewers.ColumnWeightData 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.ColumnWeightData 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.ColumnWeightData 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;
}
Aggregations