use of org.eclipse.jface.viewers.ViewerCell in project cubrid-manager by CUBRID.
the class TableFocusCellManager method handleSelection.
/**
*
* Handle the selection event
*
* @param event Event
*/
private void handleSelection(Event event) {
if ((event.detail & SWT.CHECK) == 0 && focusCell != null && focusCell.getItem() != event.item && event.item != null && !event.item.isDisposed()) {
ViewerRow row = viewer.getViewerRowByItem(event.item);
ViewerCell tmp = row.getCell(focusCell.getColumnIndex());
if (!focusCell.equals(tmp)) {
setFocusCell(tmp);
}
}
}
use of org.eclipse.jface.viewers.ViewerCell in project cubrid-manager by CUBRID.
the class TableFocusCellManager method getFocusCell.
/**
*
* Get the focus cell
*
* @return ViewerCell
*/
public ViewerCell getFocusCell() {
ViewerCell cell = this.focusCell;
Table t = (Table) getViewer().getControl();
// It is possible that the selection has changed under the hood
if (cell != null) {
if (t.getSelection().length == 1 && t.getSelection()[0] != cell.getItem()) {
setFocusCell(getViewer().getViewerRowByItem(t.getSelection()[0]).getCell(cell.getColumnIndex()));
}
}
return this.focusCell;
}
use of org.eclipse.jface.viewers.ViewerCell in project cubrid-manager by CUBRID.
the class TableFocusCellManager method setFocusCell.
/**
*
* Set the focus cell
*
* @param focusCell
*/
public void setFocusCell(ViewerCell focusCell) {
ViewerCell oldCell = this.focusCell;
if (this.focusCell != null && !this.focusCell.getItem().isDisposed()) {
this.focusCell.getItem().removeDisposeListener(itemDeletionListener);
}
this.focusCell = focusCell;
if (this.focusCell != null && !this.focusCell.getItem().isDisposed()) {
this.focusCell.getItem().addDisposeListener(itemDeletionListener);
}
if (focusCell != null) {
focusCell.scrollIntoView();
}
this.cellHighlighter.focusCellChanged(focusCell, oldCell);
getViewer().getControl().getAccessible().setFocus(ACC.CHILDID_SELF);
}
use of org.eclipse.jface.viewers.ViewerCell in project hale by halestudio.
the class ClassificationMappingParameterPage method createManualTabControl.
private Control createManualTabControl(Composite tabParent) {
// TODO load occurring value sources
Composite tabContent = new Composite(tabParent, SWT.NONE);
tabContent.setLayout(new GridLayout(1, true));
ToolBar toolBar = new ToolBar(tabContent, SWT.NONE);
toolBar.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
Composite tableContainer = new Composite(tabContent, SWT.NONE);
tableContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
TableColumnLayout layout = new TableColumnLayout();
tableContainer.setLayout(layout);
tableViewer = new TableViewer(tableContainer, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
tableViewer.getTable().setLinesVisible(true);
tableViewer.getTable().setHeaderVisible(true);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
TableViewerColumn sourceColumn = new TableViewerColumn(tableViewer, SWT.NONE);
sourceColumn.getColumn().setText("Source value");
layout.setColumnData(sourceColumn.getColumn(), new ColumnWeightData(1));
sourceColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
@SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) element;
return entry.getKey().getStringRepresentation();
}
});
TableViewerColumn targetColumn = new TableViewerColumn(tableViewer, SWT.NONE);
targetColumn.getColumn().setText("Target value");
layout.setColumnData(targetColumn.getColumn(), new ColumnWeightData(1));
targetColumn.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
@SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) cell.getElement();
if (entry.getValue() == null) {
StyledString styledString = new StyledString("(unmapped)", StyledString.DECORATIONS_STYLER);
cell.setText(styledString.getString());
cell.setStyleRanges(styledString.getStyleRanges());
} else {
cell.setText(entry.getValue().getStringRepresentation());
cell.setStyleRanges(null);
}
super.update(cell);
}
});
tableViewer.setInput(lookupTable.entrySet());
tableViewer.getTable().addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
ViewerCell cell = tableViewer.getCell(new Point(e.x, e.y));
if (cell != null) {
@SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) cell.getElement();
Value oldValue;
Value newValue;
if (cell.getColumnIndex() == 0) {
oldValue = entry.getKey();
newValue = selectValue(sourceProperty, sourceEntity, "Edit source value", "Enter a new source value", oldValue.getStringRepresentation());
} else {
oldValue = entry.getValue();
String initialValue = oldValue == null ? null : oldValue.getStringRepresentation();
newValue = selectValue(targetProperty, targetEntity, "Edit target value", "Enter a target value", initialValue);
}
if (newValue == null)
return;
if (cell.getColumnIndex() == 0) {
if (!newValue.equals(oldValue) && lookupTable.containsKey(newValue)) {
showDuplicateSourceWarning(newValue.getStringRepresentation());
} else {
lookupTable.put(newValue, entry.getValue());
lookupTable.remove(oldValue);
tableViewer.refresh();
}
} else {
entry.setValue(newValue);
tableViewer.update(entry, null);
}
}
}
});
final ToolItem valueAdd = new ToolItem(toolBar, SWT.PUSH);
final ToolItem fillValues = new ToolItem(toolBar, SWT.PUSH);
new ToolItem(toolBar, SWT.SEPARATOR);
final ToolItem loadButton = new ToolItem(toolBar, SWT.PUSH);
saveButton = new ToolItem(toolBar, SWT.PUSH);
new ToolItem(toolBar, SWT.SEPARATOR);
final ToolItem valueRemove = new ToolItem(toolBar, SWT.PUSH);
removeAllButton = new ToolItem(toolBar, SWT.PUSH);
valueAdd.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_ADD));
valueAdd.setToolTipText("Add source value");
valueAdd.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Value newSource = selectValue(sourceProperty, sourceEntity, "Add source value", "Enter a new source value", null);
if (newSource != null) {
if (lookupTable.containsKey(newSource))
showDuplicateSourceWarning(newSource.getStringRepresentation());
else {
lookupTable.put(newSource, null);
removeAllButton.setEnabled(true);
saveButton.setEnabled(true);
tableViewer.refresh();
}
}
}
});
loadButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_OPEN));
loadButton.setToolTipText("Load classification from file");
loadButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
LookupTableLoadWizard wizard = new LookupTableLoadWizard();
LookupLoadAdvisor advisor = new LookupLoadAdvisor();
wizard.setAdvisor(advisor, null);
Shell shell = Display.getCurrent().getActiveShell();
HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
dialog.open();
if (advisor.getLookupTable() != null) {
lookupTable.putAll(advisor.getLookupTable().getTable().asMap());
tableViewer.refresh();
removeAllButton.setEnabled(!lookupTable.isEmpty());
saveButton.setEnabled(!lookupTable.isEmpty());
}
}
});
fillValues.setImage(fillValuesIcon);
fillValues.setToolTipText("Attempt to fill source values with enumerations and occurring values.");
fillValues.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// first try enumeration
Enumeration<?> enumeration = sourceProperty.getPropertyType().getConstraint(Enumeration.class);
if (enumeration.getValues() != null) {
addSourceValuesIfNew(enumeration.getValues());
}
// then try occurring values
if (!ovs.updateOccurringValues(sourceEntity)) {
// values already there or not possible
addOccurringSourceValues(ovs.getOccurringValues(sourceEntity));
} else {
// job is running, listener will be notified
}
removeAllButton.setEnabled(!lookupTable.isEmpty());
saveButton.setEnabled(!lookupTable.isEmpty());
}
});
saveButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_SAVE));
saveButton.setToolTipText("Save classification to file");
saveButton.setEnabled(false);
saveButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
LookupTableExportWizard wizard = new LookupTableExportWizard();
LookupExportAdvisor advisor = new LookupExportAdvisor(new LookupTableInfoImpl(new LookupTableImpl(lookupTable), "current", "not set"));
wizard.setAdvisor(advisor, null);
Shell shell = Display.getCurrent().getActiveShell();
HaleWizardDialog dialog = new HaleWizardDialog(shell, wizard);
dialog.open();
}
});
valueRemove.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_REMOVE));
valueRemove.setToolTipText("Remove classification entry");
valueRemove.setEnabled(false);
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
valueRemove.setEnabled(!event.getSelection().isEmpty());
saveButton.setEnabled(!event.getSelection().isEmpty());
}
});
valueRemove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (tableViewer.getSelection().isEmpty())
return;
Object element = ((IStructuredSelection) tableViewer.getSelection()).getFirstElement();
@SuppressWarnings("unchecked") Entry<Value, Value> entry = (Entry<Value, Value>) element;
lookupTable.remove(entry.getKey());
tableViewer.refresh();
removeAllButton.setEnabled(!lookupTable.isEmpty());
saveButton.setEnabled(!lookupTable.isEmpty());
}
});
removeAllButton.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_TRASH));
removeAllButton.setEnabled(false);
removeAllButton.setToolTipText("Remove complete classification");
removeAllButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
lookupTable.clear();
tableViewer.refresh();
removeAllButton.setEnabled(false);
saveButton.setEnabled(false);
}
});
Label desc = new Label(tabContent, SWT.NONE);
desc.setText("Double click on a table cell to change its value.");
return tabContent;
}
use of org.eclipse.jface.viewers.ViewerCell in project hale by halestudio.
the class SourceListParameterPage method createContent.
/**
* @see HaleWizardPage#createContent(Composite)
*/
@Override
protected void createContent(Composite page) {
GridLayout layout = GridLayoutFactory.swtDefaults().create();
// Add margin to leave space for control decorations
layout.marginLeft = 5;
layout.marginRight = 5;
page.setLayout(layout);
// input field
textField = createAndLayoutTextField(page);
// let subclasses for example add validation
configure(textField);
addContentProposalProvider(projectVariablesProposalsProvider);
setText(textField, initialValue);
// variables
Label label = new Label(page, SWT.NONE);
label.setText("Available variables (double click to insert)");
label.setLayoutData(GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.CENTER).indent(4, 12).create());
// variables table
Composite tableComposite = new Composite(page, SWT.NONE);
tableComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 100).create());
TableColumnLayout columnLayout = new TableColumnLayout();
tableComposite.setLayout(columnLayout);
varTable = new TableViewer(tableComposite, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
varTable.getTable().setHeaderVisible(true);
TableViewerColumn entityColumn = new TableViewerColumn(varTable, SWT.NONE);
columnLayout.setColumnData(entityColumn.getColumn(), new ColumnWeightData(2, true));
entityColumn.getColumn().setText("Entity");
varTable.setContentProvider(ArrayContentProvider.getInstance());
varTable.setLabelProvider(new StyledDefinitionLabelProvider(varTable) {
@Override
protected Object extractElement(Object element) {
if (element instanceof Entry) {
return ((Entry<?, ?>) element).getKey();
}
return super.extractElement(element);
}
});
varTable.getTable().addMouseListener(new MouseAdapter() {
/**
* @see MouseAdapter#mouseDoubleClick(MouseEvent)
*/
@Override
public void mouseDoubleClick(MouseEvent e) {
ISelection sel = varTable.getSelection();
if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
Object selected = ((IStructuredSelection) sel).getFirstElement();
if (selected instanceof Entry) {
selected = ((Entry<?, ?>) selected).getValue();
}
insertTextAtCurrentPos(textField, selected.toString());
}
}
});
// variable name column
TableViewerColumn varColumn = new TableViewerColumn(varTable, SWT.NONE);
columnLayout.setColumnData(varColumn.getColumn(), new ColumnWeightData(1, true));
varColumn.getColumn().setText("Variable");
varColumn.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
Object element = cell.getElement();
if (element instanceof Entry) {
element = ((Entry<?, ?>) element).getValue();
}
cell.setText(element.toString());
}
});
}
Aggregations