use of org.eclipse.jface.viewers.IStructuredContentProvider in project jbosstools-hibernate by jbosstools.
the class QueryParametersPage method createQueryParametersTable.
/**
* This method initializes queryParametersTable
*/
private void createQueryParametersTable() {
GridData gridData = new org.eclipse.swt.layout.GridData();
gridData.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData.grabExcessVerticalSpace = true;
gridData.grabExcessHorizontalSpace = true;
gridData.verticalAlignment = org.eclipse.swt.layout.GridData.FILL;
queryParametersTable = new Table(top, SWT.FULL_SELECTION);
queryParametersTable.setHeaderVisible(true);
queryParametersTable.setLayoutData(gridData);
queryParametersTable.setLinesVisible(true);
TableColumn nameColumn = new TableColumn(queryParametersTable, SWT.NONE);
nameColumn.setWidth(100);
nameColumn.setText(HibernateConsoleMessages.QueryParametersPage_name);
TableColumn typeColumn = new TableColumn(queryParametersTable, SWT.NONE);
typeColumn.setWidth(75);
typeColumn.setText(HibernateConsoleMessages.QueryParametersPage_type);
TableColumn valueColumn = new TableColumn(queryParametersTable, SWT.NONE);
valueColumn.setWidth(100);
valueColumn.setText(HibernateConsoleMessages.QueryParametersPage_value);
TableColumn nullColumn = new TableColumn(queryParametersTable, SWT.NONE);
nullColumn.setWidth(32);
nullColumn.setText(HibernateConsoleMessages.QueryParametersPage_null);
tableViewer = new TableViewer(queryParametersTable);
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
if (statusLabel != null) {
Object firstElement = ((IStructuredSelection) tableViewer.getSelection()).getFirstElement();
if (firstElement instanceof ConsoleQueryParameter) {
statusLabel.setText(HibernateConsoleMessages.QueryParametersPage_format + ((ConsoleQueryParameter) firstElement).getDefaultFormat());
} else {
// $NON-NLS-1$
statusLabel.setText("");
}
}
}
});
final List<IType> possibleTypes = new ArrayList<IType>(model.getService().newTypeFactory().getTypeFormats().keySet());
Collections.sort(possibleTypes, new Comparator<IType>() {
public int compare(IType t1, IType t2) {
return t1.getName().compareTo(t2.getName());
}
});
tableViewer.setCellModifier(new ICellModifier() {
public void modify(Object element, String property, Object value) {
TableItem item = (TableItem) element;
ConsoleQueryParameter cqp = (ConsoleQueryParameter) item.getData();
if (NAME_PROPERTY.equals(property)) {
cqp.setName((String) value);
}
if (TYPE_PROPERTY.equals(property)) {
Iterator<IType> iterator = possibleTypes.iterator();
int i = 0;
while (iterator.hasNext()) {
IType type = iterator.next();
if (i == ((Integer) value).intValue()) {
if (!cqp.getTypeName().equals(type.getName())) {
cqp.setType(type);
// have to reset to ensure it's working
cqp.setNull();
}
break;
}
i++;
}
}
if (VALUE_PROPERTY.equals(property)) {
String[] inputStrings;
if (value instanceof String[]) {
inputStrings = (String[]) value;
} else {
inputStrings = new String[] { (String) value };
}
Object[] values = new Object[inputStrings.length];
for (int i = 0; i < inputStrings.length; i++) {
values[i] = cqp.convertStringToValue(inputStrings[i]);
}
if (values.length > 1) {
cqp.setValue(values);
} else if (values.length == 1) {
cqp.setValue(values[0]);
} else {
cqp.setValue(null);
}
}
if (NULL_PROPERTY.equals(property)) {
if (cqp.isNull()) {
// best attempt to "unnull" //$NON-NLS-1$
cqp.setValue(cqp.convertStringToValue(""));
} else {
cqp.setNull();
}
}
tableViewer.refresh(cqp);
}
public Object getValue(Object element, String property) {
ConsoleQueryParameter cqp = (ConsoleQueryParameter) element;
if (NAME_PROPERTY.equals(property)) {
return cqp.getName();
}
if (TYPE_PROPERTY.equals(property)) {
Iterator<IType> iterator = possibleTypes.iterator();
String type = cqp.getTypeName();
int i = 0;
while (iterator.hasNext()) {
if (type.equals(iterator.next().getName())) {
return Integer.valueOf(i);
}
i++;
}
}
if (VALUE_PROPERTY.equals(property)) {
return cqp.getStringValues();
}
if (NULL_PROPERTY.equals(property)) {
return Boolean.valueOf(cqp.isNull());
}
return null;
}
public boolean canModify(Object element, String property) {
return true;
}
});
tableViewer.setContentProvider(new IStructuredContentProvider() {
public Object[] getElements(Object inputElement) {
return ((QueryInputModel) inputElement).getQueryParameters();
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
String[] columnProperties = new String[] { NAME_PROPERTY, TYPE_PROPERTY, VALUE_PROPERTY, NULL_PROPERTY };
tableViewer.setColumnProperties(columnProperties);
String[] valueTypes = new String[possibleTypes.size()];
Iterator<IType> iterator = possibleTypes.iterator();
int i = 0;
while (iterator.hasNext()) {
IType element = iterator.next();
valueTypes[i++] = element.getName();
}
CellEditor[] editors = new CellEditor[columnProperties.length];
editors[0] = new TextCellEditor(queryParametersTable);
editors[1] = new ComboBoxCellEditor(queryParametersTable, valueTypes, SWT.READ_ONLY);
editors[2] = new StringArrayDialogCellEditor(queryParametersTable) {
private Button b;
public void activate() {
Object param = ((IStructuredSelection) tableViewer.getSelection()).getFirstElement();
if (param instanceof ConsoleQueryParameter) {
try {
Integer.parseInt(((ConsoleQueryParameter) param).getName());
// "ordered" parameter doesn't allow list value
// see also HQLQueryPage#setupParameters()
b.setVisible(false);
} catch (NumberFormatException nfe) {
// "named" parameter allows parameter list value
b.setVisible(true);
}
}
}
protected org.eclipse.swt.widgets.Button createButton(Composite parent) {
return b = super.createButton(parent);
}
};
editors[3] = new CheckboxCellEditor(queryParametersTable);
tableViewer.setCellEditors(editors);
tableViewer.setLabelProvider(new ITableLabelProvider() {
public void removeListener(ILabelProviderListener listener) {
}
public boolean isLabelProperty(Object element, String property) {
return true;
}
public void dispose() {
}
public void addListener(ILabelProviderListener listener) {
}
public String getColumnText(Object element, int columnIndex) {
ConsoleQueryParameter cqp = (ConsoleQueryParameter) element;
switch(columnIndex) {
case 0:
return cqp.getName();
case 1:
return cqp.getTypeName();
case 2:
{
String label = cqp.getStringValues()[0];
for (int j = 1; j < cqp.getStringValues().length; j++) {
// $NON-NLS-1$
label += "|" + cqp.getStringValues()[j];
}
return label;
}
case 3:
// cqp.isNull()?"X":"";
return null;
default:
return null;
}
}
public Image getColumnImage(Object element, int columnIndex) {
if (columnIndex == 3) {
ConsoleQueryParameter cqp = (ConsoleQueryParameter) element;
return cqp.isNull() ? EclipseImages.getImage(ImageConstants.CHECKBOX_FULL) : EclipseImages.getImage(ImageConstants.CHECKBOX_EMPTY);
} else {
return null;
}
}
});
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project arduino-eclipse-plugin by Sloeber.
the class SerialMonitor method createPartControl.
/**
* This is a callback that will allow us to create the viewer and initialize
* it.
*/
@Override
public void createPartControl(Composite parent1) {
this.parent = parent1;
parent1.setLayout(new GridLayout());
GridLayout layout = new GridLayout(5, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
Composite top = new Composite(parent1, SWT.NONE);
top.setLayout(layout);
top.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
this.serialPorts = new ComboViewer(top, SWT.READ_ONLY | SWT.DROP_DOWN);
GridData minSizeGridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
minSizeGridData.widthHint = 150;
this.serialPorts.getControl().setLayoutData(minSizeGridData);
this.serialPorts.setContentProvider(new IStructuredContentProvider() {
@Override
public void dispose() {
// no need to do something here
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// no need to do something here
}
@Override
public Object[] getElements(Object inputElement) {
@SuppressWarnings("unchecked") Map<Serial, SerialListener> items = (Map<Serial, SerialListener>) inputElement;
return items.keySet().toArray();
}
});
this.serialPorts.setLabelProvider(new LabelProvider());
this.serialPorts.setInput(this.serialConnections);
this.serialPorts.addSelectionChangedListener(new ComPortChanged(this));
this.sendString = new Text(top, SWT.SINGLE | SWT.BORDER);
this.sendString.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
this.lineTerminator = new ComboViewer(top, SWT.READ_ONLY | SWT.DROP_DOWN);
this.lineTerminator.setContentProvider(new ArrayContentProvider());
this.lineTerminator.setLabelProvider(new LabelProvider());
this.lineTerminator.setInput(SerialManager.listLineEndings());
this.lineTerminator.getCombo().select(MyPreferences.getLastUsedSerialLineEnd());
this.lineTerminator.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
MyPreferences.setLastUsedSerialLineEnd(SerialMonitor.this.lineTerminator.getCombo().getSelectionIndex());
}
});
this.send = new Button(top, SWT.BUTTON1);
this.send.setText(Messages.serialMonitorSend);
this.send.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
int index = SerialMonitor.this.lineTerminator.getCombo().getSelectionIndex();
GetSelectedSerial().write(SerialMonitor.this.sendString.getText(), SerialManager.getLineEnding(index));
// $NON-NLS-1$
SerialMonitor.this.sendString.setText("");
SerialMonitor.this.sendString.setFocus();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// nothing needs to be done here
}
});
this.send.setEnabled(false);
this.reset = new Button(top, SWT.BUTTON1);
this.reset.setText(Messages.serialMonitorReset);
this.reset.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
GetSelectedSerial().reset();
SerialMonitor.this.sendString.setFocus();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// nothing needs to be done here
}
});
this.reset.setEnabled(false);
// register the combo as a Selection Provider
getSite().setSelectionProvider(this.serialPorts);
this.monitorOutput = new StyledText(top, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
this.monitorOutput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
this.monitorOutput.setEditable(false);
IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
ITheme currentTheme = themeManager.getCurrentTheme();
FontRegistry fontRegistry = currentTheme.getFontRegistry();
// $NON-NLS-1$
this.monitorOutput.setFont(fontRegistry.get("io.sloeber.serial.fontDefinition"));
this.monitorOutput.setText(Messages.serialMonitorNoInput);
this.parent.getShell().setDefaultButton(this.send);
makeActions();
contributeToActionBars();
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project egit by eclipse.
the class CommitFileDiffViewer method doSelectAll.
private void doSelectAll() {
final IStructuredContentProvider cp;
final Object in = getInput();
if (in == null)
return;
cp = ((IStructuredContentProvider) getContentProvider());
final Object[] el = cp.getElements(in);
if (el == null || el.length == 0)
return;
setSelection(new StructuredSelection(el));
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project egit by eclipse.
the class ProblemLabelDecorator method getAffectedElements.
private List<Object> getAffectedElements(Set<IResource> resources) {
List<Object> result = new ArrayList<>();
if (viewer.getContentProvider() instanceof IStructuredContentProvider) {
IStructuredContentProvider contentProvider = (IStructuredContentProvider) viewer.getContentProvider();
getAffectedElements(resources, contentProvider.getElements(null), contentProvider, result);
}
return result;
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project tdq-studio-se by Talend.
the class SQLHistoryView method createPartControl.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
public void createPartControl(final Composite parent) {
// MOD gdbu 2011-4-29 bug : 20960
SQLHistory tem_history = SQLExplorerPlugin.getDefault().getSQLHistory();
final SQLHistory history = tem_history == null ? new SQLHistory() : tem_history;
// ~20960
history.sort(1, SWT.DOWN);
// $NON-NLS-1$
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, SQLExplorerPlugin.PLUGIN_ID + ".SQLHistoryView");
history.addListener(this);
Composite composite = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
layout.marginLeft = 0;
layout.horizontalSpacing = 0;
layout.verticalSpacing = 2;
layout.marginWidth = 0;
layout.marginHeight = 0;
composite.setLayout(layout);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
// add search box
_searchBox = new Text(composite, SWT.BORDER);
_searchBox.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
// $NON-NLS-1$
_searchBox.setText(Messages.getString("SQLHistoryView.SearchText"));
_searchBox.selectAll();
SQLHistorySearchListener searchListener = new SQLHistorySearchListener(history);
_searchBox.addModifyListener(searchListener);
_searchBox.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
Text searchbox = (Text) e.widget;
if (searchbox.getText() != null && searchbox.getText().equals(Messages.getString("SQLHistoryView.SearchText"))) {
searchbox.setText("");
}
}
});
_tableViewer = new TableViewer(composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.MULTI | SWT.VIRTUAL);
getSite().setSelectionProvider(_tableViewer);
_table = _tableViewer.getTable();
_table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
_table.setHeaderVisible(true);
_table.setLinesVisible(true);
_table.setItemCount(history.getEntryCount());
_tableViewer.setLabelProvider(new SQLHistoryLabelProvider());
_tableViewer.setContentProvider(new IStructuredContentProvider() {
public void dispose() {
}
public Object[] getElements(Object inputElement) {
return SQLExplorerPlugin.getDefault().getSQLHistory().toArray();
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
_tableViewer.setInput(history);
// create listener for sorting
Listener sortListener = new Listener() {
public void handleEvent(Event e) {
// determine new sort column and direction
TableColumn sortColumn = _table.getSortColumn();
TableColumn currentColumn = (TableColumn) e.widget;
int dir = _table.getSortDirection();
if (sortColumn == currentColumn) {
dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
} else {
_table.setSortColumn(currentColumn);
dir = SWT.UP;
}
sortColumn = _table.getSortColumn();
TableColumn[] cols = _table.getColumns();
for (int i = 0; i < cols.length; i++) {
if (cols[i] == sortColumn) {
history.sort(i, dir);
break;
}
}
// update data displayed in table
_table.setSortDirection(dir);
_tableViewer.refresh();
}
};
String[] columnLabels = new String[] { Messages.getString("SQLHistoryView.Column.SQL"), Messages.getString("SQLHistoryView.Column.Time"), Messages.getString("SQLHistoryView.Column.Connection"), Messages.getString("SQLHistoryView.Column.Executions") };
_tableViewer.setColumnProperties(columnLabels);
// add all column headers to our table
for (int i = 0; i < columnLabels.length; i++) {
// add column header
TableColumn column = new TableColumn(_table, SWT.LEFT);
column.setText(columnLabels[i]);
column.setMoveable(false);
column.setResizable(true);
column.addListener(SWT.Selection, sortListener);
}
_tableViewer.refresh();
// add sizing weights to the different columns
TableLayout tableLayout = new TableLayout();
tableLayout.addColumnData(new ColumnWeightData(7, 150));
tableLayout.addColumnData(new ColumnWeightData(2, 120));
tableLayout.addColumnData(new ColumnWeightData(1, 50));
tableLayout.addColumnData(new ColumnWeightData(1, 50));
_table.setLayout(tableLayout);
_table.layout();
// redraw table if view is resized
parent.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
super.controlResized(e);
// reset weights in case of view resizing
TableLayout tableLayout = new TableLayout();
tableLayout.addColumnData(new ColumnWeightData(7, 150));
tableLayout.addColumnData(new ColumnWeightData(2, 120));
tableLayout.addColumnData(new ColumnWeightData(1, 50));
tableLayout.addColumnData(new ColumnWeightData(1, 50));
_table.setLayout(tableLayout);
}
});
// create action bar
final IToolBarManager toolBarMgr = getViewSite().getActionBars().getToolBarManager();
final SQLHistoryActionGroup actionGroup = new SQLHistoryActionGroup(this, history, _tableViewer, toolBarMgr);
_tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
actionGroup.refresh();
toolBarMgr.update(true);
}
});
// add context menus
final MenuManager menuMgr = new MenuManager("#HistoryPopupMenu");
menuMgr.setRemoveAllWhenShown(true);
Menu historyContextMenu = menuMgr.createContextMenu(_table);
_table.setMenu(historyContextMenu);
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
toolBarMgr.markDirty();
actionGroup.fillContextMenu(manager);
}
});
// also add action as default when an entry is doubleclicked.
final OpenInEditorAction openInEditorAction = new OpenInEditorAction();
openInEditorAction.setTableViewer(_tableViewer);
openInEditorAction.setView(this);
_tableViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
openInEditorAction.run();
}
});
// add remove action on delete key
final RemoveFromHistoryAction removeFromHistoryAction = new RemoveFromHistoryAction();
removeFromHistoryAction.setTableViewer(_tableViewer);
_table.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
// delete entry
if (e.keyCode == SWT.DEL) {
removeFromHistoryAction.run();
}
}
});
// Set multi-line tooltip
final Display display = parent.getDisplay();
_tipShell = new Shell(parent.getShell(), SWT.ON_TOP);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
gridLayout.marginWidth = 2;
gridLayout.marginHeight = 2;
_tipShell.setLayout(gridLayout);
_tipShell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
_tipLabelText = new Label(_tipShell, SWT.WRAP | SWT.LEFT);
_tipLabelText.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
_tipLabelText.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
_tipLabelText.setLayoutData(gridData);
_table.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
if (_tipShell.isVisible()) {
_tipShell.setVisible(false);
_tipWidget = null;
}
}
});
_table.addMouseTrackListener(new MouseTrackAdapter() {
public void mouseExit(MouseEvent e) {
if (_tipShell.isVisible())
_tipShell.setVisible(false);
_tipWidget = null;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.MouseTrackListener#mouseHover(org.eclipse.swt.events.MouseEvent)
*/
public void mouseHover(MouseEvent event) {
Point pt = new Point(event.x, event.y);
Widget widget = event.widget;
TableItem tableItem = null;
if (widget instanceof Table) {
Table table = (Table) widget;
widget = table.getItem(pt);
}
if (widget instanceof TableItem) {
tableItem = (TableItem) widget;
}
if (widget == null) {
_tipShell.setVisible(false);
_tipWidget = null;
return;
}
if (widget == _tipWidget)
return;
_tipWidget = widget;
_tipPosition = _table.toDisplay(pt);
SQLHistoryElement sqlString = (SQLHistoryElement) tableItem.getData();
String text = TextUtil.getWrappedText(sqlString.getRawSQLString());
if (text == null || text.equals("")) {
_tipWidget = null;
return;
}
// Set off the table tooltip as we provide our own
_table.setToolTipText("");
_tipLabelText.setText(text);
_tipShell.pack();
setHoverLocation(_tipShell, _tipPosition, _tipLabelText.getBounds().height);
_tipShell.setVisible(true);
}
});
_tableViewer.setSelection(null);
composite.layout();
parent.layout();
}
Aggregations