use of org.talend.designer.fileoutputxml.ui.edit.FOXTargetTreeViewerProvider in project tdi-studio-se by Talend.
the class FOXUI method addXMLViewer.
/**
* create xml viewer.
*
* @param mainComposite
* @param form
* @param width
* @param height
*/
private void addXMLViewer(final Composite mainComposite, final int width, final int height) {
// Group Schema Viewer
//$NON-NLS-1$
Group group = Form.createGroup(mainComposite, 1, Messages.getString("FOXUI.0"), height);
// group.setBackgroundMode(SWT.INHERIT_FORCE);
xmlViewer = new TreeViewer(group, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.VIRTUAL);
GridData gridData = new GridData(GridData.FILL_BOTH);
xmlViewer.getControl().setLayoutData(gridData);
xmlViewer.setUseHashlookup(true);
Tree tree = xmlViewer.getTree();
// see bug 7087
if (canModify || isRepository) {
tree.setEnabled(false);
}
tree.setLinesVisible(true);
tree.setBackground(tree.getDisplay().getSystemColor(SWT.COLOR_WHITE));
TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
//$NON-NLS-1$
column1.setText(Messages.getString("FOXUI.1"));
column1.setWidth(170);
// Related Column
TreeColumn column2 = new TreeColumn(tree, SWT.CENTER);
//$NON-NLS-1$
column2.setText(Messages.getString("FOXUI.2"));
column2.setWidth(100);
TreeColumn column3 = new TreeColumn(tree, SWT.CENTER);
//$NON-NLS-1$
column3.setText(Messages.getString("FOXUI.3"));
column3.setWidth(90);
TreeColumn column4 = new TreeColumn(tree, SWT.CENTER);
//$NON-NLS-1$
column4.setText(Messages.getString("FOXUI.4"));
column4.setWidth(90);
tree.setHeaderVisible(true);
// tree.setBackgroundMode(SWT.INHERIT_NONE);
FOXTargetTreeViewerProvider provider = new FOXTargetTreeViewerProvider();
xmlViewer.setLabelProvider(provider);
xmlViewer.setCellModifier(new ICellModifier() {
@Override
public boolean canModify(Object element, String property) {
FOXTreeNode node = (FOXTreeNode) element;
if (property.equals("C1")) {
//$NON-NLS-1$
if (node.getLabel() != null && node.getLabel().length() > 0) {
return true;
}
}
if (property.equals("C4")) {
//$NON-NLS-1$
if (node.getDefaultValue() != null && node.getDefaultValue().length() > 0) {
return true;
}
}
return false;
}
@Override
public Object getValue(Object element, String property) {
FOXTreeNode node = (FOXTreeNode) element;
if (property.equals("C1")) {
//$NON-NLS-1$
return node.getLabel();
}
if (property.equals("C4")) {
//$NON-NLS-1$
return node.getDefaultValue();
}
return null;
}
@Override
public void modify(Object element, String property, Object value) {
TreeItem treeItem = (TreeItem) element;
FOXTreeNode node = (FOXTreeNode) treeItem.getData();
if (property.equals("C1")) {
//$NON-NLS-1$
node.setLabel((String) value);
}
if (property.equals("C4")) {
//$NON-NLS-1$
node.setDefaultValue((String) value);
}
xmlViewer.refresh(node);
}
});
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
xmlViewer.setColumnProperties(new String[] { "C1", "C2", "C3", "C4" });
CellEditor editor = new TextCellEditor(xmlViewer.getTree());
//$NON-NLS-1$
editor.addListener(new DialogErrorXMLLabelCellEditor(editor, "C1"));
// add by wzhang for bug 8572. set Default value column to be edit.
CellEditor editorDefault = new TextCellEditor(xmlViewer.getTree());
//$NON-NLS-1$
editorDefault.addListener(new DialogErrorXMLLabelCellEditor(editorDefault, "C4"));
xmlViewer.setCellEditors(new CellEditor[] { editor, null, null, editorDefault });
xmlViewer.setContentProvider(provider);
xmlViewer.setInput(this.foxManager.getTreeData());
createAction();
//$NON-NLS-1$
MenuManager menuMgr = new MenuManager("#PopupMenu");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
FOXUI.this.fillContextMenu(manager);
}
});
Menu menu = menuMgr.createContextMenu(xmlViewer.getControl());
xmlViewer.getControl().setMenu(menu);
xmlViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
// TODO Auto-generated method stub
}
});
refreshXMLViewer(null);
}
Aggregations