use of org.eclipse.jface.viewers.CellEditor in project erlide_eclipse by erlang.
the class ControlPanelView method createNodesTable.
private void createNodesTable(final Composite parent) {
final int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.grabExcessVerticalSpace = true;
nodesTableViewer = new TableViewer(parent, style);
nodesTableViewer.setUseHashlookup(true);
// table
final Table table = nodesTableViewer.getTable();
table.setLayoutData(gridData);
table.setHeaderVisible(true);
table.setLinesVisible(true);
// columns
final String[] columnProperties = new String[TracePatternColumn.values().length];
for (final NodeColumn column : NodeColumn.values()) {
final TableColumn tableColumn = new TableColumn(table, SWT.LEFT, column.ordinal());
tableColumn.setResizable(true);
tableColumn.setMoveable(false);
tableColumn.setWidth(column.getWidth());
tableColumn.setText(column.getName());
columnProperties[column.ordinal()] = column.name();
}
nodesTableViewer.setColumnProperties(columnProperties);
// providers
nodesTableViewer.setLabelProvider(new NodeLabelProvider());
nodesTableViewer.setContentProvider(new NodeContentProvider());
// input
nodesTableViewer.setInput(TraceBackend.getInstance());
// editors
final CellEditor[] editors = new CellEditor[TracePatternColumn.values().length];
editors[NodeColumn.ENABLED.ordinal()] = new CheckboxCellEditor(table);
editors[NodeColumn.NODE_NAME.ordinal()] = new TextCellEditor(table);
editors[NodeColumn.COOKIE.ordinal()] = new TextCellEditor(table);
nodesTableViewer.setCellEditors(editors);
nodesTableViewer.setCellModifier(new NodeCellModifier(nodesTableViewer));
}
use of org.eclipse.jface.viewers.CellEditor in project tmdm-studio-se by Talend.
the class ConsistencyConflictDialog method installCellEditor.
private void installCellEditor() {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
treeViewer.setColumnProperties(new String[] { "0", "1", "2", "3", "4" });
treeViewer.setCellModifier(new ICellModifier() {
public void modify(Object element, String property, Object value) {
if (property.equals("2")) {
// $NON-NLS-1$
int index = (Integer) value;
IRepositoryViewObject viewObj = (IRepositoryViewObject) ((TreeItem) element).getData();
if (index == 0) {
moveToDeployObjs(viewObj);
} else if (index == 1) {
moveToSkipObjs(viewObj);
}
treeViewer.refresh(viewObj);
}
}
public Object getValue(Object element, String property) {
IRepositoryViewObject viewObj = (IRepositoryViewObject) element;
if (isSkipObj(viewObj)) {
return 1;
}
return 0;
}
public boolean canModify(Object element, String property) {
if (property.equals("2") && !(element instanceof FolderRepositoryObject)) {
// $NON-NLS-1$
IRepositoryViewObject viewObj = (IRepositoryViewObject) element;
return getCompareResult(viewObj) != CompareResultEnum.NOT_EXIST_IN_SERVER;
}
return false;
}
});
CellEditor[] cellEditors = new CellEditor[5];
cellEditors[2] = new ComboBoxCellEditor(treeViewer.getTree(), OPERATIONS, SWT.READ_ONLY);
treeViewer.setCellEditors(cellEditors);
}
use of org.eclipse.jface.viewers.CellEditor in project tmdm-studio-se by Talend.
the class AnnotationOrderedListsDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
// Should not really be here but well,....
parent.getShell().setText(this.title);
Composite composite = (Composite) super.createDialogArea(parent);
GridLayout layout = (GridLayout) composite.getLayout();
layout.numColumns = 3;
layout.makeColumnsEqualWidth = false;
if (actionType == AnnotationWrite_ActionType || actionType == AnnotationHidden_ActionType) {
textControl = new CCombo(composite, SWT.BORDER | SWT.READ_ONLY);
// roles=Util.getCachedXObjectsNameSet(this.xObject, TreeObject.ROLE);
roles = getAllRolesStr();
((CCombo) textControl).setItems(roles.toArray(new String[roles.size()]));
} else if (actionType == AnnotationLookupField_ActionType || actionType == AnnotationPrimaKeyInfo_ActionType) {
textControl = new CCombo(composite, SWT.BORDER | SWT.READ_ONLY);
// roles=Util.getCachedXObjectsNameSet(this.xObject, TreeObject.ROLE);
roles = getConceptElements();
((CCombo) textControl).setItems(roles.toArray(new String[roles.size()]));
} else {
if (actionType == AnnotationOrderedListsDialog.AnnotationSchematron_ActionType) {
textControl = new Text(composite, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
} else {
textControl = new Text(composite, SWT.BORDER | SWT.SINGLE);
}
}
if (actionType == AnnotationOrderedListsDialog.AnnotationForeignKeyInfo_ActionType) {
textControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
} else {
if (actionType == AnnotationOrderedListsDialog.AnnotationSchematron_ActionType) {
textControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 7));
} else {
textControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
}
}
((GridData) textControl.getLayoutData()).minimumWidth = 400;
textControl.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
if ((e.stateMask == 0) && (e.character == SWT.CR)) {
xPaths.add(AnnotationOrderedListsDialog.getControlText(textControl));
viewer.refresh();
fireXPathsChanges();
}
}
});
if (actionType == AnnotationOrderedListsDialog.AnnotationForeignKeyInfo_ActionType) {
Button xpathButton = new Button(composite, SWT.PUSH | SWT.CENTER);
xpathButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
// $NON-NLS-1$
xpathButton.setText("...");
xpathButton.setToolTipText(Messages.AnnotationOrderedListsDialog_SelectXpath);
xpathButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
XpathSelectDialog dlg = getNewXpathSelectDialog(parentPage, dataModelName);
dlg.setLock(lock);
dlg.setBlockOnOpen(true);
dlg.open();
if (dlg.getReturnCode() == Window.OK) {
((Text) textControl).setText(dlg.getXpath());
dlg.close();
}
}
});
}
Button addLabelButton = new Button(composite, SWT.PUSH);
addLabelButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
// addLabelButton.setText("Set");
addLabelButton.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath()));
addLabelButton.setToolTipText(Messages.AnnotationOrderedListsDialog_Add);
addLabelButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
}
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
boolean exist = false;
for (String string : xPaths) {
if (string.equals(getControlText(textControl))) {
exist = true;
}
}
if (!exist && getControlText(textControl) != null && getControlText(textControl) != "") {
xPaths.add(getControlText(textControl));
}
viewer.refresh();
fireXPathsChanges();
}
});
final String COLUMN = columnName;
viewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
((GridData) viewer.getControl().getLayoutData()).heightHint = 100;
// Set up the underlying table
Table table = viewer.getTable();
// table.setLayoutData(new GridData(GridData.FILL_BOTH));
new TableColumn(table, SWT.CENTER).setText(COLUMN);
table.getColumn(0).setWidth(500);
for (int i = 1, n = table.getColumnCount(); i < n; i++) {
table.getColumn(i).pack();
}
table.setHeaderVisible(true);
table.setLinesVisible(true);
// Create the cell editors --> We actually discard those later: not natural for an user
CellEditor[] editors = new CellEditor[1];
if (actionType == AnnotationOrderedListsDialog.AnnotationWrite_ActionType || actionType == AnnotationOrderedListsDialog.AnnotationHidden_ActionType || actionType == AnnotationLookupField_ActionType || actionType == AnnotationPrimaKeyInfo_ActionType) {
editors[0] = new ComboBoxCellEditor(table, roles.toArray(new String[] {}), SWT.READ_ONLY);
} else {
editors[0] = new TextCellEditor(table);
}
viewer.setCellEditors(editors);
// set the content provider
viewer.setContentProvider(new IStructuredContentProvider() {
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public Object[] getElements(Object inputElement) {
@SuppressWarnings("unchecked") ArrayList<String> xPaths = (ArrayList<String>) inputElement;
ArrayList<DescriptionLine> lines = new ArrayList<DescriptionLine>();
for (String xPath : xPaths) {
DescriptionLine line = new DescriptionLine(xPath);
lines.add(line);
}
// we return an instance line made of a Sring and a boolean
return lines.toArray(new DescriptionLine[lines.size()]);
}
});
// set the label provider
viewer.setLabelProvider(new ITableLabelProvider() {
public boolean isLabelProperty(Object element, String property) {
return false;
}
public void dispose() {
}
public void addListener(ILabelProviderListener listener) {
}
public void removeListener(ILabelProviderListener listener) {
}
public String getColumnText(Object element, int columnIndex) {
// System.out.println("getColumnText() "+columnIndex);
DescriptionLine line = (DescriptionLine) element;
switch(columnIndex) {
case 0:
return line.getLabel();
}
// $NON-NLS-1$
return "";
}
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
});
// Set the column properties
viewer.setColumnProperties(new String[] { COLUMN });
// set the Cell Modifier
viewer.setCellModifier(new ICellModifier() {
public boolean canModify(Object element, String property) {
// if (INSTANCE_ACCESS.equals(property)) return true; Deactivated
return true;
// return false;
}
public void modify(Object element, String property, Object value) {
TableItem item = (TableItem) element;
DescriptionLine line = (DescriptionLine) item.getData();
String orgValue = line.getLabel();
if (actionType != AnnotationWrite_ActionType && actionType != AnnotationHidden_ActionType && actionType != AnnotationLookupField_ActionType && actionType != AnnotationPrimaKeyInfo_ActionType) {
int targetPos = xPaths.indexOf(value.toString());
if (targetPos < 0) {
line.setLabel(value.toString());
int index = xPaths.indexOf(orgValue);
xPaths.remove(index);
xPaths.add(index, value.toString());
viewer.update(line, null);
} else if (targetPos >= 0 && !value.toString().equals(orgValue)) {
MessageDialog.openInformation(null, Messages.Warning, Messages.AnnotationOrderedListsDialog_ValueAlreadyExists);
}
} else {
String[] attrs = roles.toArray(new String[] {});
int index = Integer.parseInt(value.toString());
if (index == -1) {
return;
}
value = attrs[index];
int pos = xPaths.indexOf(value.toString());
if (pos >= 0 && !(orgValue.equals(value))) {
MessageDialog.openInformation(null, Messages.Warning, Messages.AnnotationOrderedListsDialog_);
return;
} else if (pos < 0) {
line.setLabel(value.toString());
xPaths.set(index, value.toString());
viewer.update(line, null);
}
}
fireXPathsChanges();
}
public Object getValue(Object element, String property) {
DescriptionLine line = (DescriptionLine) element;
String value = line.getLabel();
if (actionType == AnnotationWrite_ActionType || actionType == AnnotationHidden_ActionType || actionType == AnnotationLookupField_ActionType || actionType == AnnotationPrimaKeyInfo_ActionType) {
String[] attrs = roles.toArray(new String[] {});
return Arrays.asList(attrs).indexOf(value);
} else {
return value;
}
}
});
// Listen for changes in the selection of the viewer to display additional parameters
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
if (line != null) {
if (textControl instanceof CCombo) {
((CCombo) textControl).setText(line.getLabel());
}
if (textControl instanceof Text) {
((Text) textControl).setText(line.getLabel());
}
}
}
});
// display for Delete Key events to delete an instance
viewer.getTable().addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
// System.out.println("Table keyReleased() ");
if ((e.stateMask == 0) && (e.character == SWT.DEL) && (viewer.getSelection() != null)) {
DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
@SuppressWarnings("unchecked") ArrayList<String> xPaths = (ArrayList<String>) viewer.getInput();
xPaths.remove(line.getLabel());
viewer.refresh();
}
}
});
viewer.setInput(xPaths);
viewer.refresh();
Composite rightButtonsComposite = new Composite(composite, SWT.NULL);
rightButtonsComposite.setLayout(new GridLayout(1, true));
rightButtonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
Button upButton = new Button(rightButtonsComposite, SWT.PUSH | SWT.CENTER);
upButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
upButton.setImage(ImageCache.getCreatedImage(EImage.PREV_NAV.getPath()));
upButton.setToolTipText(Messages.AnnotationOrderedListsDialog_MoveUpTheItem);
upButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
}
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
if (line == null) {
return;
}
int i = 0;
for (String xPath : xPaths) {
if (xPath.equals(line.getLabel())) {
if (i > 0) {
xPaths.remove(i);
xPaths.add(i - 1, xPath);
viewer.refresh();
viewer.getTable().setSelection(i - 1);
viewer.getTable().showSelection();
fireXPathsChanges();
}
return;
}
i++;
}
}
});
Button downButton = new Button(rightButtonsComposite, SWT.PUSH | SWT.CENTER);
downButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
downButton.setImage(ImageCache.getCreatedImage(EImage.NEXT_NAV.getPath()));
downButton.setToolTipText(Messages.AnnotationOrderedListsDialog_MoveDownTheItem);
downButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
}
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
if (line == null) {
return;
}
int i = 0;
for (String xPath : xPaths) {
if (xPath.equals(line.getLabel())) {
if (i < xPaths.size() - 1) {
xPaths.remove(i);
xPaths.add(i + 1, xPath);
viewer.refresh();
viewer.getTable().setSelection(i + 1);
viewer.getTable().showSelection();
fireXPathsChanges();
}
return;
}
i++;
}
}
});
Button delButton = new Button(rightButtonsComposite, SWT.PUSH | SWT.CENTER);
delButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
delButton.setImage(ImageCache.getCreatedImage(EImage.DELETE_OBJ.getPath()));
delButton.setToolTipText(Messages.AnnotationOrderedListsDialog_DelTheItem);
delButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
}
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
if (line != null) {
@SuppressWarnings("unchecked") ArrayList<String> xPaths = (ArrayList<String>) viewer.getInput();
xPaths.remove(line.getLabel());
viewer.refresh();
fireXPathsChanges();
}
}
});
textControl.setFocus();
if (actionType != AnnotationOrderedListsDialog.AnnotationForeignKeyInfo_ActionType && actionType != AnnotationOrderedListsDialog.AnnotationTargetSystems_ActionType && actionType != AnnotationOrderedListsDialog.AnnotationSchematron_ActionType && actionType != AnnotationOrderedListsDialog.AnnotationLookupField_ActionType && actionType != AnnotationOrderedListsDialog.AnnotationPrimaKeyInfo_ActionType) {
checkBox = new Button(composite, SWT.CHECK);
checkBox.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true, 2, 1));
checkBox.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
}
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
recursive = checkBox.getSelection();
}
});
checkBox.setSelection(recursive);
checkBox.setText(Messages.AnnotationOrderedListsDialog_SetRoleRecursively);
// Label label = new Label(composite, SWT.LEFT);
// label.setText("set role recursively");
// label.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true,
// 1, 1));
}
if (actionType == AnnotationForeignKeyInfo_ActionType) {
createFKInfoFormatComp(composite);
addDoubleClickListener();
}
return composite;
}
use of org.eclipse.jface.viewers.CellEditor in project tmdm-studio-se by Talend.
the class AnnotationLanguageLabelsDialog method createDialogArea.
protected Control createDialogArea(Composite parent) {
// Should not really be here but well,....
parent.getShell().setText(this.title);
Composite composite = (Composite) super.createDialogArea(parent);
GridLayout layout = (GridLayout) composite.getLayout();
layout.numColumns = 3;
// layout.verticalSpacing = 10;
languagesCombo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE);
languagesCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.NONE, false, false, 1, 1));
Set<String> languages = Util.lang2iso.keySet();
for (Iterator iter = languages.iterator(); iter.hasNext(); ) {
String language = (String) iter.next();
languagesCombo.add(language);
}
languagesCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
}
});
languagesCombo.select(0);
labelText = new Text(composite, SWT.BORDER | SWT.SINGLE);
labelText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
((GridData) labelText.getLayoutData()).minimumWidth = 150;
labelText.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
if ((e.stateMask == 0) && (e.character == SWT.CR)) {
String isoCode = Util.lang2iso.get(languagesCombo.getText());
descriptionsMap.put(isoCode, labelText.getText());
descriptionsViewer.refresh();
}
}
});
Button addLabelButton = new Button(composite, SWT.PUSH);
addLabelButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
addLabelButton.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath()));
addLabelButton.setToolTipText(Messages.AnnotationLanguageLabelsDialog_Add);
addLabelButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
}
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
String code = Util.lang2iso.get(languagesCombo.getText());
descriptionsMap.put(code, labelText.getText());
descriptionsViewer.refresh();
}
});
final String LANGUAGE = Messages.AnnotationLanguageLabelsDialog_Language;
final String LABEL = Messages.AnnotationLanguageLabelsDialog_Label;
descriptionsViewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
descriptionsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
((GridData) descriptionsViewer.getControl().getLayoutData()).heightHint = 100;
// Set up the underlying table
Table table = descriptionsViewer.getTable();
// table.setLayoutData(new GridData(GridData.FILL_BOTH));
new TableColumn(table, SWT.LEFT).setText(LANGUAGE);
new TableColumn(table, SWT.CENTER).setText(LABEL);
table.getColumn(0).setWidth(150);
table.getColumn(1).setWidth(150);
for (int i = 2, n = table.getColumnCount(); i < n; i++) {
table.getColumn(i).pack();
}
table.setHeaderVisible(true);
table.setLinesVisible(true);
Button delLabelButton = new Button(composite, SWT.PUSH);
delLabelButton.setLayoutData(new GridData(SWT.NONE, SWT.NONE, false, false, 1, 1));
delLabelButton.setImage(ImageCache.getCreatedImage(EImage.DELETE_OBJ.getPath()));
delLabelButton.setToolTipText(Messages.AnnotationLanguageLabelsDialog_Del);
delLabelButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
}
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
deleteItem();
}
});
// Create the cell editors --> We actually discard those later: not natural for an user
CellEditor[] editors = new CellEditor[2];
editors[0] = new ComboBoxCellEditor(table, Util.lang2iso.keySet().toArray(new String[] {}), SWT.READ_ONLY);
editors[1] = new TextCellEditor(table);
descriptionsViewer.setCellEditors(editors);
// set the content provider
descriptionsViewer.setContentProvider(new IStructuredContentProvider() {
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public Object[] getElements(Object inputElement) {
// System.out.println("getElements() ");
LinkedHashMap<String, String> descs = (LinkedHashMap<String, String>) inputElement;
Set<String> languages = descs.keySet();
ArrayList<DescriptionLine> lines = new ArrayList<DescriptionLine>();
for (Iterator iter = languages.iterator(); iter.hasNext(); ) {
String language = ((String) iter.next());
DescriptionLine line = new DescriptionLine(Util.iso2lang.get(language), descs.get(language));
lines.add(line);
}
// we return an instance line made of a Sring and a boolean
return lines.toArray(new DescriptionLine[lines.size()]);
}
});
// set the label provider
descriptionsViewer.setLabelProvider(new ITableLabelProvider() {
public boolean isLabelProperty(Object element, String property) {
return false;
}
public void dispose() {
}
public void addListener(ILabelProviderListener listener) {
}
public void removeListener(ILabelProviderListener listener) {
}
public String getColumnText(Object element, int columnIndex) {
// System.out.println("getColumnText() "+columnIndex);
DescriptionLine line = (DescriptionLine) element;
switch(columnIndex) {
case 0:
return line.getLanguage();
case 1:
return line.getLabel();
}
// $NON-NLS-1$
return "";
}
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
});
// Set the column properties
descriptionsViewer.setColumnProperties(new String[] { LANGUAGE, LABEL });
// set the Cell Modifier
descriptionsViewer.setCellModifier(new ICellModifier() {
public boolean canModify(Object element, String property) {
// if (INSTANCE_ACCESS.equals(property)) return true; Deactivated
return true;
}
public void modify(Object element, String property, Object value) {
TableItem item = (TableItem) element;
int columnIndex = Arrays.asList(descriptionsViewer.getColumnProperties()).indexOf(property);
DescriptionLine line = (DescriptionLine) item.getData();
if (columnIndex == 0) {
String[] attrs = Util.lang2iso.keySet().toArray(new String[] {});
int orgIndx = Arrays.asList(attrs).indexOf(line.getLanguage());
if (orgIndx != Integer.parseInt(value.toString())) {
String newLang = attrs[Integer.parseInt(value.toString())];
if (descriptionsMap.containsKey(Util.lang2iso.get(newLang))) {
MessageDialog.openInformation(null, Messages.Warnning, Messages.AnnotationLanguageLabelsDialog_InforContent);
return;
}
descriptionsMap.remove(Util.lang2iso.get(line.getLanguage()));
line.setLanguage(newLang);
descriptionsMap.put(Util.lang2iso.get(newLang), line.getLabel());
}
} else // column label
{
line.setLabel(value.toString());
descriptionsMap.put(Util.lang2iso.get(line.getLanguage()), line.getLabel());
}
descriptionsViewer.update(line, null);
}
public Object getValue(Object element, String property) {
int columnIndex = Arrays.asList(descriptionsViewer.getColumnProperties()).indexOf(property);
DescriptionLine line = (DescriptionLine) element;
if (columnIndex == 0) {
String[] attrs = Util.lang2iso.keySet().toArray(new String[] {});
return Arrays.asList(attrs).indexOf(line.getLanguage());
} else {
if (LANGUAGE.equals(property)) {
return line.getLanguage();
}
if (LABEL.equals(property)) {
return line.getLabel();
}
}
return null;
}
});
// Listen for changes in the selection of the viewer to display additional parameters
descriptionsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
}
});
// display for Delete Key events to delete an instance
descriptionsViewer.getTable().addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
// System.out.println("Table keyReleased() ");
if ((e.stateMask == 0) && (e.character == SWT.DEL) && (descriptionsViewer.getSelection() != null)) {
deleteItem();
}
}
});
descriptionsViewer.setInput(descriptionsMap);
descriptionsViewer.refresh();
labelText.setFocus();
return composite;
}
use of org.eclipse.jface.viewers.CellEditor 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;
}
}
});
}
Aggregations