use of org.eclipse.jface.viewers.IStructuredContentProvider in project archi-modelrepository-plugin by archi-contribs.
the class ConflictsDialog method createTableControl.
private void createTableControl(Composite parent) {
Composite tableComp = new Composite(parent, SWT.BORDER);
TableColumnLayout tableLayout = new TableColumnLayout();
tableComp.setLayout(tableLayout);
tableComp.setLayoutData(new GridData(GridData.FILL_BOTH));
Table table = new Table(tableComp, SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK);
table.setHeaderVisible(true);
fTableViewer = new CheckboxTableViewer(table);
fTableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
fTableViewer.getTable().setLinesVisible(true);
fTableViewer.setComparator(new ViewerComparator());
// Columns
TableViewerColumn column1 = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
column1.getColumn().setText(Messages.ConflictsDialog_5);
tableLayout.setColumnData(column1.getColumn(), new ColumnWeightData(100, true));
// Content Provider
fTableViewer.setContentProvider(new IStructuredContentProvider() {
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public void dispose() {
}
public Object[] getElements(Object inputElement) {
MergeResult result = fHandler.getMergeResult();
return result.getConflicts().keySet().toArray();
}
});
fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
String path = (String) ((StructuredSelection) event.getSelection()).getFirstElement();
try {
fFileViewerOurs.setText(fHandler.getArchiRepository().getFileContents(path, IGraficoConstants.HEAD));
fFileViewerTheirs.setText(fHandler.getArchiRepository().getFileContents(path, IGraficoConstants.ORIGIN_MASTER));
fFileViewerDiff.setText(fHandler.getArchiRepository().getWorkingTreeFileContents(path));
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
// Label Provider
fTableViewer.setLabelProvider(new LabelProvider());
// Start the table
// anything will do //$NON-NLS-1$
fTableViewer.setInput("");
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project nebula.widgets.nattable by eclipse.
the class FilterNatCombo method createDropdownControl.
@Override
protected void createDropdownControl(int style) {
super.createDropdownControl(style);
int dropdownListStyle = style | SWT.NO_SCROLL | HorizontalAlignmentEnum.getSWTStyle(this.cellStyle) | SWT.FULL_SELECTION;
this.selectAllItemViewer = CheckboxTableViewer.newCheckList(this.dropdownShell, dropdownListStyle);
// add a column to be able to resize the item width in the dropdown
new TableColumn(this.selectAllItemViewer.getTable(), SWT.NONE);
this.selectAllItemViewer.getTable().addListener(SWT.Resize, new Listener() {
@Override
public void handleEvent(Event event) {
calculateColumnWidth();
}
});
FormData data = new FormData();
if (this.showDropdownFilter) {
data.top = new FormAttachment(this.filterBox, 0, SWT.BOTTOM);
} else {
data.top = new FormAttachment(this.dropdownShell, 0, SWT.TOP);
}
data.left = new FormAttachment(0);
data.right = new FormAttachment(100);
this.selectAllItemViewer.getTable().setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(this.selectAllItemViewer.getControl(), 0, SWT.BOTTOM);
data.left = new FormAttachment(0);
data.right = new FormAttachment(100);
data.bottom = new FormAttachment(100);
this.dropdownTable.setLayoutData(data);
this.selectAllItemViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@SuppressWarnings("unchecked")
@Override
public Object[] getElements(Object inputElement) {
return ((Collection<String>) inputElement).toArray();
}
});
this.selectAllItemViewer.setLabelProvider(new ILabelProvider() {
@Override
public void removeListener(ILabelProviderListener listener) {
}
@Override
public boolean isLabelProperty(Object element, String property) {
return false;
}
@Override
public void dispose() {
}
@Override
public void addListener(ILabelProviderListener listener) {
}
@Override
public String getText(Object element) {
return element.toString();
}
@Override
public Image getImage(Object element) {
return null;
}
});
// $NON-NLS-1$
final String selectAllLabel = Messages.getString("FilterNatCombo.selectAll");
List<String> input = new ArrayList<String>();
input.add(selectAllLabel);
this.selectAllItemViewer.setInput(input);
this.selectAllItemViewer.getTable().setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
this.selectAllItemViewer.getTable().setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
this.selectAllItemViewer.getTable().setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT));
this.selectAllItemViewer.getTable().addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
showDropdownControl();
}
});
this.selectAllItemViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
if (event.getChecked()) {
// select all
FilterNatCombo.this.dropdownTable.selectAll();
} else {
// deselect all
FilterNatCombo.this.dropdownTable.deselectAll();
}
// selection and checkboxes are in sync
for (TableItem tableItem : FilterNatCombo.this.dropdownTable.getItems()) {
tableItem.setChecked(FilterNatCombo.this.dropdownTable.isSelected(FilterNatCombo.this.itemList.indexOf(tableItem.getText())));
}
// all checkbox
for (String item : FilterNatCombo.this.itemList) {
FilterNatCombo.this.selectionStateMap.put(item, event.getChecked());
}
updateTextControl(!FilterNatCombo.this.multiselect);
}
});
for (ICheckStateListener l : this.checkStateListener) {
this.selectAllItemViewer.addCheckStateListener(l);
}
// set an ICheckStateProvider that sets the checkbox state of the select
// all checkbox regarding the selection of the items in the dropdown
this.selectAllItemViewer.setCheckStateProvider(new ICheckStateProvider() {
@Override
public boolean isGrayed(Object element) {
return getSelectionCount() < FilterNatCombo.this.itemList.size();
}
@Override
public boolean isChecked(Object element) {
return getSelectionCount() > 0;
}
});
// add a selection listener to the items that simply refreshes the
// select all checkbox
this.dropdownTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FilterNatCombo.this.selectAllItemViewer.refresh();
}
});
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project nebula.widgets.nattable by eclipse.
the class NatCombo method createDropdownControl.
/**
* Create the dropdown control of this NatCombo, adding styles,
* look&feel and needed listeners for the control only.
*
* @param style
* The style for the Table Control to construct. Uses this style
* adding internal styles via ConfigRegistry.
*/
protected void createDropdownControl(int style) {
this.dropdownShell = new Shell(getShell(), SWT.MODELESS);
// (SWT.V_SCROLL | SWT.NO_SCROLL) prevents appearance of unnecessary
// horizontal scrollbar on mac
// see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=304128
int scrollStyle = ((this.itemList != null && this.itemList.size() > this.maxVisibleItems) && this.maxVisibleItems > 0) ? (SWT.V_SCROLL | SWT.NO_SCROLL) : SWT.NO_SCROLL;
int dropdownListStyle = style | scrollStyle | HorizontalAlignmentEnum.getSWTStyle(this.cellStyle) | SWT.FULL_SELECTION;
this.dropdownTable = new Table(this.dropdownShell, dropdownListStyle);
this.dropdownTableViewer = new TableViewer(this.dropdownTable);
this.dropdownTable.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
this.dropdownTable.setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
this.dropdownTable.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT));
// add a column to be able to resize the item width in the dropdown
new TableColumn(this.dropdownTable, SWT.NONE);
this.dropdownTableViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
return (Object[]) inputElement;
}
});
this.dropdownTableViewer.setLabelProvider(new ILabelProvider() {
@Override
public void removeListener(ILabelProviderListener listener) {
}
@Override
public boolean isLabelProperty(Object element, String property) {
return false;
}
@Override
public void dispose() {
}
@Override
public void addListener(ILabelProviderListener listener) {
}
@Override
public String getText(Object element) {
return element.toString();
}
@Override
public Image getImage(Object element) {
return null;
}
});
this.dropdownTable.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.ARROW_DOWN) {
int selected = NatCombo.this.dropdownTable.getSelectionIndex();
if (selected < 0) {
// no selection before, select the first entry
if (!NatCombo.this.useCheckbox) {
select(0);
} else {
getDropdownTable().select(0);
}
event.doit = false;
}
}
}
});
this.dropdownTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean selected = e.detail != SWT.CHECK;
boolean isCtrlPressed = (e.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL;
TableItem chosenItem = (TableItem) e.item;
// Given the ability to filter we need to find the item's
// table index which may not match the index in the itemList
int itemTableIndex = NatCombo.this.dropdownTable.indexOf(chosenItem);
// This case handles check actions
if (!selected) {
if (!chosenItem.getChecked()) {
NatCombo.this.selectionStateMap.put(chosenItem.getText(), Boolean.FALSE);
} else {
NatCombo.this.selectionStateMap.put(chosenItem.getText(), Boolean.TRUE);
}
} else if (!NatCombo.this.useCheckbox) {
if (NatCombo.this.multiselect && isCtrlPressed) {
boolean isSelected = NatCombo.this.dropdownTable.isSelected(itemTableIndex);
NatCombo.this.selectionStateMap.put(chosenItem.getText(), isSelected);
if (NatCombo.this.useCheckbox) {
chosenItem.setChecked(isSelected);
}
} else {
// A single item was selected. Clear all previous state
for (String item : NatCombo.this.itemList) {
NatCombo.this.selectionStateMap.put(item, Boolean.FALSE);
}
// Set the state for the selected item
NatCombo.this.selectionStateMap.put(chosenItem.getText(), Boolean.TRUE);
}
}
updateTextControl(false);
}
});
this.dropdownTable.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if ((event.keyCode == SWT.CR) || (event.keyCode == SWT.KEYPAD_CR)) {
updateTextControl(true);
} else if (event.keyCode == SWT.F2 && NatCombo.this.freeEdit) {
NatCombo.this.text.forceFocus();
hideDropdownControl();
}
}
});
this.dropdownTable.addFocusListener(new FocusListenerWrapper());
FormLayout layout = new FormLayout();
layout.spacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
this.dropdownShell.setLayout(layout);
FormData dropDownLayoutData = new FormData();
dropDownLayoutData.left = new FormAttachment(0);
dropDownLayoutData.right = new FormAttachment(100);
dropDownLayoutData.bottom = new FormAttachment(100);
if (this.showDropdownFilter) {
this.filterBox = new Text(this.dropdownShell, SWT.BORDER);
this.filterBox.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT));
this.filterBox.setEnabled(true);
this.filterBox.setEditable(true);
this.filterBox.addFocusListener(new FocusListenerWrapper());
this.filterBox.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (null != NatCombo.this.dropdownTableViewer && !NatCombo.this.dropdownTable.isDisposed()) {
NatCombo.this.dropdownTableViewer.refresh();
calculateBounds();
setDropdownSelection(getTextAsArray());
}
}
});
FormData data = new FormData();
data.top = new FormAttachment(0);
data.left = new FormAttachment(0);
data.right = new FormAttachment(100);
this.filterBox.setLayoutData(data);
data = new FormData();
if (this.showDropdownFilter) {
dropDownLayoutData.top = new FormAttachment(this.filterBox, 0, SWT.BOTTOM);
} else {
dropDownLayoutData.top = new FormAttachment(this.dropdownShell, 0, SWT.TOP);
}
this.dropdownTable.setLayoutData(dropDownLayoutData);
ViewerFilter viewerFilter = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (null != element && element instanceof String) {
return ((String) element).toLowerCase().contains(NatCombo.this.filterBox.getText().toLowerCase());
}
return false;
}
};
this.dropdownTableViewer.addFilter(viewerFilter);
} else {
dropDownLayoutData.top = new FormAttachment(0);
this.dropdownTable.setLayoutData(dropDownLayoutData);
}
if (this.itemList != null) {
setItems(this.itemList.toArray(new String[] {}));
}
// apply the listeners that were registered before the creation of the
// dropdown control
applyDropdownListener();
setDropdownSelection(getTextAsArray());
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project n4js by eclipse.
the class ExportSelectionPage method createChoiceListGroup.
/**
* The List of projects
*
* @param composite
*/
private void createChoiceListGroup(Composite parent) {
Composite choiceListGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
choiceListGroup.setLayout(layout);
choiceListGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
choiceListGroup.setFont(parent.getFont());
choiceList = CheckboxTableViewer.newCheckList(choiceListGroup, SWT.BORDER);
choiceList.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
choiceList.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
// sort the projects before displaying, ignoring case like in the workspace projects view.
final List<IProject> sortedProjects = new ArrayList<>(projects.keySet());
sortedProjects.sort((a, b) -> a.getName().compareToIgnoreCase(b.getName()));
choiceList.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// n.t.d.
}
@Override
public void dispose() {
// n.t.d.
}
@Override
public Object[] getElements(Object inputElement) {
return sortedProjects.toArray();
}
});
choiceList.setCheckStateProvider(new ICheckStateProvider() {
@Override
public boolean isGrayed(Object element) {
return false;
}
@Override
public boolean isChecked(Object element) {
Boolean checkedState = projects.get(element);
return checkedState != null && checkedState.booleanValue();
}
});
choiceList.setInput(new StructuredSelection(projects));
choiceList.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
handleCheckStateChange(event);
}
});
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project hale by halestudio.
the class LayersDialog method createDialogArea.
/**
* @see TitleAreaDialog#createDialogArea(Composite)
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite page = new Composite(parent, SWT.NONE);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
page.setLayoutData(data);
page.setLayout(new FillLayout());
CheckboxTableViewer table = CheckboxTableViewer.newCheckList(page, SWT.V_SCROLL | SWT.BORDER);
TableColumn names = new TableColumn(table.getTable(), SWT.NONE);
names.setWidth(200);
names.setText(Messages.LayersDialog_2);
TableColumn descs = new TableColumn(table.getTable(), SWT.NONE);
descs.setWidth(200);
descs.setText(Messages.LayersDialog_3);
// labels
table.setLabelProvider(new LayerLabelProvider());
table.setCheckStateProvider(new LayerCheckStateProvider());
table.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
((Layer) event.getElement()).setSelected(event.getChecked());
}
});
// content
table.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// ignore
}
@Override
public void dispose() {
// ignore
}
@Override
@SuppressWarnings("unchecked")
public Object[] getElements(Object inputElement) {
return ((List<Layer>) inputElement).toArray();
}
});
table.setInput(layers);
table.getTable().setLinesVisible(true);
table.getTable().setHeaderVisible(true);
// pack columns
names.pack();
descs.pack();
return page;
}
Aggregations