use of org.eclipse.jface.viewers.ITreeViewerListener in project tdi-studio-se by Talend.
the class StatusManagerSettingPage method addRepositoryTreeViewer.
/**
* repository tree viewer.
*/
private void addRepositoryTreeViewer(Composite leftComposite) {
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.widthHint = 210;
gridData.heightHint = 400;
leftComposite.setLayoutData(gridData);
RepoCommonViewerProvider provider = RepoCommonViewerProvider.CHECKBOX;
treeViewer = (CheckboxRepositoryTreeViewer) provider.createViewer(leftComposite);
// filter
treeViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
RepositoryNode node = (RepositoryNode) element;
return filterRepositoryNode(node);
}
});
// event
treeViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
RepositoryNode node = (RepositoryNode) event.getElement();
List<RepositoryObject> objects = new ArrayList<RepositoryObject>();
processItems(objects, node);
if (!objects.isEmpty()) {
if (event.getChecked()) {
checkedObjects.addAll(objects);
} else {
checkedObjects.removeAll(objects);
removeItemElements(objects);
}
// researchMaxVersion();
refreshTableItems();
}
}
});
treeViewer.addTreeListener(new ITreeViewerListener() {
@Override
public void treeCollapsed(TreeExpansionEvent event) {
//
}
@Override
public void treeExpanded(TreeExpansionEvent event) {
// refreshCheckedTreeView();
}
});
expandSomeNodes(provider.getProjectRepositoryNode());
}
use of org.eclipse.jface.viewers.ITreeViewerListener in project tdi-studio-se by Talend.
the class MultiSchemasUI method addFieldListeners.
private void addFieldListeners() {
fileField.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
getConnection().setFilePath(fileField.getText());
previewBtn.setEnabled(checkFieldsValue());
clearPreview();
refreshPreview();
}
});
rowSeparatorText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
getConnection().setRowSeparatorValue(rowSeparatorText.getText());
previewBtn.setEnabled(checkFieldsValue());
clearPreview();
}
});
fieldSeparatorText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
getConnection().setFieldSeparatorValue(fieldSeparatorText.getText());
previewBtn.setEnabled(checkFieldsValue());
clearPreview();
}
});
useMultiSaparators.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean selected = useMultiSaparators.getSelection();
fieldSeparatorCombo.setEnabled(!selected);
fieldSeparatorText.setEditable(!selected);
multiSeparatorsText.setEditable(selected);
keyValuesText.setEditable(selected);
keyIndexText.setEditable(selected);
escapeCharCombo.setEnabled(selected);
textEnclosureCombo.setEnabled(selected);
csvRadio.setSelection(selected);
delimitedRadio.setSelection(!selected);
delimitedRadio.setEnabled(!selected);
if (selected) {
getConnection().setFieldSeparatorValue(multiSeparatorsText.getText());
multiSchemaManager.setSelectedColumnIndex(Integer.parseInt(keyIndexText.getText()));
} else {
getConnection().setFieldSeparatorValue(fieldSeparatorText.getText());
}
clearPreview();
previewBtn.setEnabled(checkFieldsValue());
if (previewBtn.isEnabled()) {
refreshPreview();
}
}
});
schemaTreeViewer.getTree().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
getUIManager().refreshSchemasDetailView(schemaTreeViewer, schemaDetailsViewer, getSchemaDetailModel());
}
});
schemaTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
removeRow.setEnabled(true);
editSchema.setEnabled(true);
if (isReadOnly()) {
leftBtn.setEnabled(false);
rightBtn.setEnabled(false);
} else {
leftBtn.setEnabled(getUIManager().enableMovedRecord(schemaTreeViewer, true));
rightBtn.setEnabled(getUIManager().enableMovedRecord(schemaTreeViewer, false));
}
IStructuredSelection selection = (IStructuredSelection) schemaTreeViewer.getSelection();
Object element = selection.getFirstElement();
if (element != null && (element instanceof SchemasKeyData) && ((SchemasKeyData) element).getTagLevel() > 0) {
cardText.setText(((SchemasKeyData) element).getCard());
cardText.setEnabled(true);
} else {
//$NON-NLS-1$
cardText.setText("");
cardText.setEnabled(false);
}
}
});
schemaTreeViewer.getTree().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
//
}
@Override
public void keyReleased(KeyEvent e) {
//
}
});
schemaTreeViewer.addTreeListener(new ITreeViewerListener() {
public void treeCollapsed(TreeExpansionEvent event) {
// getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
}
public void treeExpanded(TreeExpansionEvent event) {
// getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
}
});
}
use of org.eclipse.jface.viewers.ITreeViewerListener in project tmdm-studio-se by Talend.
the class DataModelSelectDialog method selectDataModel.
private void selectDataModel() {
Object input = domViewer.getInput();
TreeObject[] elements = (TreeObject[]) contentProvider.getElements(input);
selectDefaultDataModel(elements);
domViewer.addTreeListener(new ITreeViewerListener() {
public void treeExpanded(TreeExpansionEvent event) {
TreeParent parent = (TreeParent) event.getElement();
TreeObject[] children = parent.getChildren();
selectDefaultDataModel(children);
}
public void treeCollapsed(TreeExpansionEvent event) {
//
}
});
}
use of org.eclipse.jface.viewers.ITreeViewerListener in project tdq-studio-se by Talend.
the class DatabaseStructureView method addSession.
/**
* Add a new session to the database structure view. This will create a new tab for the session.
*
* @param session
*/
private void addSession(final MetaDataSession session) throws SQLCannotConnectException {
if (_allSessions.contains(session)) {
return;
}
try {
session.getMetaData();
session.setAutoCommit(true);
} catch (SQLCannotConnectException e) {
SQLExplorerPlugin.error(e);
throw e;
} catch (SQLException e) {
SQLExplorerPlugin.error(e);
MessageDialog.openError(getSite().getShell(), "Cannot connect", e.getMessage());
}
DatabaseNode rootNode = session.getRoot();
if (rootNode == null) {
return;
}
_allSessions.add(session);
if (_filterAction != null) {
_filterAction.setEnabled(true);
}
if (_tabFolder == null || _tabFolder.isDisposed()) {
clearParent();
// create tab folder for different sessions
_tabFolder = new CTabFolder(_parent, SWT.TOP | SWT.CLOSE);
// add listener to keep both views on the same active tab
_tabFolder.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// set the selected node in the detail view.
DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
synchronizeDetailView(detailView);
}
});
// Set up a gradient background for the selected tab
Display display = getSite().getShell().getDisplay();
_tabFolder.setSelectionBackground(new Color[] { display.getSystemColor(SWT.COLOR_WHITE), new Color(null, 211, 225, 250), new Color(null, 175, 201, 246), IConstants.TAB_BORDER_COLOR }, new int[] { 25, 50, 75 }, true);
// Add a listener to handle the close button on each tab
_tabFolder.addCTabFolder2Listener(new CTabFolder2Adapter() {
@Override
public void close(CTabFolderEvent event) {
CTabItem tabItem = (CTabItem) event.item;
TabData tabData = (TabData) tabItem.getData();
_allSessions.remove(tabData.session);
event.doit = true;
}
});
_parent.layout();
_parent.redraw();
}
// create tab
final CTabItem tabItem = new CTabItem(_tabFolder, SWT.NULL);
TabData tabData = new TabData();
tabItem.setData(tabData);
tabData.session = session;
// set tab text
String labelText = session.getUser().getDescription();
tabItem.setText(labelText);
// create composite for our outline
Composite composite = new Composite(_tabFolder, SWT.NULL);
composite.setLayout(new FillLayout());
tabItem.setControl(composite);
// create outline
final TreeViewer treeViewer = new TreeViewer(composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER);
tabData.treeViewer = treeViewer;
// add drag support
// TODO improve drag support options
Transfer[] transfers = new Transfer[] { TableNodeTransfer.getInstance() };
treeViewer.addDragSupport(DND.DROP_COPY, transfers, new DragSourceListener() {
public void dragFinished(DragSourceEvent event) {
System.out.println("$drag finished");
TableNodeTransfer.getInstance().setSelection(null);
}
public void dragSetData(DragSourceEvent event) {
Object sel = ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
event.data = sel;
}
public void dragStart(DragSourceEvent event) {
event.doit = !treeViewer.getSelection().isEmpty();
if (event.doit) {
Object sel = ((IStructuredSelection) treeViewer.getSelection()).getFirstElement();
if (!(sel instanceof TableNode)) {
event.doit = false;
} else {
TableNode tn = (TableNode) sel;
TableNodeTransfer.getInstance().setSelection(tn);
if (!tn.isTable()) {
event.doit = false;
}
}
}
}
});
// use hash lookup to improve performance
treeViewer.setUseHashlookup(true);
// add content and label provider
treeViewer.setContentProvider(new DBTreeContentProvider());
treeViewer.setLabelProvider(new DBTreeLabelProvider());
// set input session
treeViewer.setInput(rootNode);
// add selection change listener, so we can update detail view as
// required.
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent ev) {
// set the selected node in the detail view.
DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
synchronizeDetailView(detailView);
}
});
// bring detail to front on doubleclick of node
treeViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
try {
// find view
DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
if (detailView == null) {
getSite().getPage().showView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
}
getSite().getPage().bringToTop(detailView);
synchronizeDetailView(detailView);
} catch (Exception e) {
// fail silent
}
}
});
// add expand/collapse listener
treeViewer.addTreeListener(new ITreeViewerListener() {
public void treeCollapsed(TreeExpansionEvent event) {
// refresh the node to change image
INode node = (INode) event.getElement();
node.setExpanded(false);
TreeViewer viewer = (TreeViewer) event.getSource();
viewer.update(node, null);
}
public void treeExpanded(TreeExpansionEvent event) {
// refresh the node to change image
INode node = (INode) event.getElement();
node.setExpanded(true);
TreeViewer viewer = (TreeViewer) event.getSource();
viewer.update(node, null);
}
});
// set new tab as the active one
_tabFolder.setSelection(_tabFolder.getItemCount() - 1);
// update detail view
DatabaseDetailView detailView = (DatabaseDetailView) getSite().getPage().findView(SqlexplorerViewConstants.SQLEXPLORER_DBDETAIL);
if (detailView != null) {
// synchronze detail view with new session
synchronizeDetailView(detailView);
// bring detail to top of the view stack
getSite().getPage().bringToTop(detailView);
}
// refresh view
composite.layout();
_tabFolder.layout();
_tabFolder.redraw();
// bring this view to top of the view stack, above detail if needed..
getSite().getPage().bringToTop(this);
// add context menu
final DBTreeActionGroup actionGroup = new DBTreeActionGroup(treeViewer);
MenuManager menuManager = new MenuManager("DBTreeContextMenu");
menuManager.setRemoveAllWhenShown(true);
Menu contextMenu = menuManager.createContextMenu(treeViewer.getTree());
treeViewer.getTree().setMenu(contextMenu);
menuManager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
actionGroup.fillContextMenu(manager);
}
});
// if (sessionSelectionMap.containsKey(tabData.session)) {
// tabData.treeViewer.setSelection(sessionSelectionMap.get(tabData.session));
// sessionSelectionMap.remove(tabData.session);
// _allSessions.remove(tabData.session);
// }
}
use of org.eclipse.jface.viewers.ITreeViewerListener in project usbdm-eclipse-plugins by podonoghue.
the class UsbdmDevicePeripheralsView method createPartControl.
// /**
// * Provides the editor for the tree elements
// *
// * Does minor modifications to the default editor.
// */
// private class PeripheralsViewTextCellEditor extends TextCellEditor {
//
// private int minHeight;
//
// public PeripheralsViewTextCellEditor(Tree tree) {
// super(tree, SWT.BORDER);
// Text txt = (Text) getControl();
//
// Font fnt = txt.getFont();
// FontData[] fontData = fnt.getFontData();
// if (fontData != null && fontData.length > 0) {
// minHeight = fontData[0].getHeight() + 10;
// }
// }
//
// public LayoutData getLayoutData() {
// LayoutData data = super.getLayoutData();
// if (minHeight > 0)
// data.minimumHeight = minHeight;
// return data;
// }
// }
/**
* Callback that creates the viewer and initialises it.
*
* The View consists of a tree and a information panel
*/
public void createPartControl(Composite parent) {
// Create the manager and bind to main composite
resManager = new LocalResourceManager(JFaceResources.getResources(), parent);
parent.setLayoutData(new FillLayout());
SashForm form = new SashForm(parent, SWT.VERTICAL);
form.setLayout(new FillLayout());
// Make sash visible
form.setSashWidth(4);
form.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GRAY));
// =============================
fPeripheralsTreeViewer = new CheckboxTreeViewer(form, SWT.MULTI | SWT.V_SCROLL | SWT.FULL_SELECTION);
Tree tree = fPeripheralsTreeViewer.getTree();
tree.setLinesVisible(true);
tree.setHeaderVisible(true);
ColumnViewerToolTipSupport.enableFor(fPeripheralsTreeViewer);
// // Suppress tree expansion on double-click
// // see http://www.eclipse.org/forums/index.php/t/257325/
// peripheralsTreeViewer.getControl().addListener(SWT.MeasureItem, new Listener(){
// @Override
// public void handleEvent(Event event) {
// }});
fPeripheralsTreeViewer.setColumnProperties(fTreeProperties);
fPeripheralsTreeViewer.setCellEditors(new CellEditor[] { null, new TextCellEditor(fPeripheralsTreeViewer.getTree()), null });
// peripheralsTreeViewer.setCellEditors(new CellEditor[] { null, new PeripheralsViewTextCellEditor(peripheralsTreeViewer.getTree()), null });
fPeripheralsTreeViewer.setCellModifier(new PeripheralsViewCellModifier(this));
/*
* Name column
*/
TreeColumn column;
column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
column.setWidth(fDefaultNameColumnWidth);
column.setText("Name");
// Add listener to column so peripherals are sorted by name when clicked
column.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
fPeripheralsTreeViewer.setComparator(new PeripheralsViewSorter(PeripheralsViewSorter.SortCriteria.PeripheralNameOrder));
}
});
/*
* Value column
*/
column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
column.setWidth(fDefaultValueColumnWidth);
column.setText("Value");
column.setResizable(fDefaultValueColumnWidth != 0);
/*
* Field column
*/
column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
column.setWidth(fDefaultFieldColumnWidth);
column.setText("Field");
column.setResizable(fDefaultFieldColumnWidth != 0);
/*
* Mode column
*/
column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
column.setWidth(fDefaultModeWidth);
column.setText("Mode");
column.setResizable(fDefaultModeWidth != 0);
/*
* Location column
*/
column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
column.setWidth(fDefaultLocationColumnWidth);
column.setText("Location");
column.setResizable(fDefaultLocationColumnWidth != 0);
// Add listener to column so peripheral are sorted by address when clicked
column.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
fPeripheralsTreeViewer.setComparator(new PeripheralsViewSorter(PeripheralsViewSorter.SortCriteria.AddressOrder));
}
});
/*
* Description column
*/
column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
column.setWidth(fDefaultDescriptionColumnWidth);
column.setText("Description");
column.setResizable(fDefaultDescriptionColumnWidth != 0);
// Default to sorted by Peripheral name
fPeripheralsTreeViewer.setComparator(new PeripheralsViewSorter(PeripheralsViewSorter.SortCriteria.PeripheralNameOrder));
// Noting filtered
fPeripheralsTreeViewer.addFilter(new PeripheralsViewFilter(PeripheralsViewFilter.SelectionCriteria.SelectAll));
// Label provider
fPeripheralsTreeViewer.setLabelProvider(new PeripheralsViewCellLabelProvider(this));
// Content provider
fPeripheralsTreeViewer.setContentProvider(new PeripheralsViewContentProvider(this));
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(fPeripheralsTreeViewer) {
@Override
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
// ||
return (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION);
// (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
}
};
TreeViewerEditor.create(fPeripheralsTreeViewer, actSupport, TreeViewerEditor.DEFAULT);
// Create the help context id for the viewer's control
// PlatformUI.getWorkbench().getHelpSystem().setHelp(treeViewer.getControl(),
// "usbdmMemory.viewer");
// =============================
fPeripheralsInformationPanel = new PeripheralsInformationPanel(form, SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY, this.fPeripheralsTreeViewer);
form.setWeights(new int[] { 80, 20 });
// Tree expansion/collapse
fPeripheralsTreeViewer.addTreeListener(new ITreeViewerListener() {
@Override
public void treeExpanded(TreeExpansionEvent event) {
Object element = event.getElement();
// System.err.println("treeExpanded() => event.getElement().getClass() = " + element.getClass());
if (element instanceof RegisterModel) {
((RegisterModel) element).update();
}
if (element instanceof PeripheralModel) {
((PeripheralModel) element).update();
}
}
@Override
public void treeCollapsed(TreeExpansionEvent event) {
}
});
// When user checks a checkbox in the tree, check all its children
fPeripheralsTreeViewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
// peripheralsTreeViewer.expandToLevel(event.getElement(), 1);
fPeripheralsTreeViewer.setSubtreeChecked(event.getElement(), event.getChecked());
}
});
// Create the actions
makeActions();
// Add selected actions to context menu
hookContextMenu();
// Add selected actions to menu bar
contributeToActionBars();
}
Aggregations