use of org.eclipse.swt.events.TreeListener in project cubrid-manager by CUBRID.
the class OIDNavigatorDialog method createDialogArea.
/**
* Create dialog area content
*
* @param parent the parent composite
* @return the control
*/
protected Control createDialogArea(Composite parent) {
Composite parentComp = (Composite) super.createDialogArea(parent);
Composite composite = new Composite(parentComp, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout();
layout.numColumns = 5;
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
Label oidValueLabel = new Label(composite, SWT.LEFT);
oidValueLabel.setText(Messages.lblOIDValue);
oidValueLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
oidValueText = new Text(composite, SWT.LEFT | SWT.BORDER);
oidValueText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 3, 1, -1, -1));
if (oidStr != null) {
oidValueText.setText(oidStr);
}
oidValueText.addModifyListener(this);
findButton = new Button(composite, SWT.CENTER);
findButton.setText(Messages.btnFind);
findButton.setLayoutData(CommonUITool.createGridData(1, 1, 60, -1));
if (oidStr == null || oidStr.trim().length() <= 0) {
findButton.setEnabled(false);
}
findButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
find();
}
});
Composite findResultComp = new Composite(composite, SWT.BORDER);
findResultComp.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 5, 1, -1, 200));
findResultComp.setLayout(new GridLayout());
resultTree = new Tree(findResultComp, SWT.NONE | SWT.VIRTUAL);
GridData data = new GridData(GridData.FILL_BOTH);
resultTree.setLayoutData(data);
resultTree.addTreeListener(new TreeListener() {
public void treeCollapsed(TreeEvent event) {
//empty
}
public void treeExpanded(TreeEvent event) {
TreeItem item = (TreeItem) event.item;
if (item.getData(OID_ITEM_FLAG) == null || (item.getData(EXPANDED_ITEM_FLAG) != null)) {
return;
}
if (item.getItemCount() > 0) {
Object obj = item.getItem(0).getData(DUMY_ITEM_FLAG);
if (obj instanceof String && OIDNavigatorDialog.DUMY_ITEM_FLAG.equals((String) obj)) {
item.removeAll();
}
}
searchOID((String) (item.getData(OID_ITEM_FLAG)), item);
item.setData(EXPANDED_ITEM_FLAG, "true");
}
});
setTitle(Messages.titleOIDNavigatorDialog);
setMessage(Messages.msgOIDNavigatorDialog);
return parentComp;
}
use of org.eclipse.swt.events.TreeListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_widgets_Tree method test_addTreeListenerTreeExpandedAdapterLorg_eclipse_swt_events_TreeListener.
@Test
public void test_addTreeListenerTreeExpandedAdapterLorg_eclipse_swt_events_TreeListener() {
TreeListener listener = TreeListener.treeExpandedAdapter(e -> eventOccurred = true);
tree.addTreeListener(listener);
eventOccurred = false;
tree.notifyListeners(SWT.Expand, new Event());
assertTrue(eventOccurred);
eventOccurred = false;
tree.notifyListeners(SWT.Collapse, new Event());
assertFalse(eventOccurred);
tree.removeTreeListener(listener);
eventOccurred = false;
tree.notifyListeners(SWT.Expand, new Event());
assertFalse(eventOccurred);
tree.notifyListeners(SWT.Collapse, new Event());
assertFalse(eventOccurred);
}
use of org.eclipse.swt.events.TreeListener in project pentaho-kettle by pentaho.
the class TreeMemory method addTreeListener.
/**
* This method creates, adds and returns a tree listener that will keep track of the expanded/collapsed state of the
* TreeItems. This state will then be stored in the TreeMemory singleton.
*
* @param tree
* The tree to add the listener to
* @return The created/added TreeListener
*/
public static final TreeListener addTreeListener(final Tree tree, final String treeName) {
TreeListener treeListener = new TreeListener() {
public void treeExpanded(TreeEvent e) {
TreeItem treeItem = (TreeItem) e.item;
String[] path = ConstUI.getTreeStrings(treeItem);
TreeMemory treeMemory = TreeMemory.getInstance();
treeMemory.storeExpanded(treeName, path, true);
}
public void treeCollapsed(TreeEvent e) {
TreeItem treeItem = (TreeItem) e.item;
String[] path = ConstUI.getTreeStrings(treeItem);
TreeMemory treeMemory = TreeMemory.getInstance();
treeMemory.storeExpanded(treeName, path, false);
}
};
tree.addTreeListener(treeListener);
return treeListener;
}
use of org.eclipse.swt.events.TreeListener in project nebula.widgets.nattable by eclipse.
the class ColumnChooserDialog method populateDialogArea.
@Override
public void populateDialogArea(Composite parent) {
GridDataFactory.fillDefaults().grab(true, true).applyTo(parent);
parent.setLayout(new GridLayout(4, false));
createLabels(parent, this.availableLabel, this.selectedLabel);
this.availableTree = new Tree(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.Expand);
GridData gridData = GridDataFactory.fillDefaults().grab(true, true).create();
this.availableTree.setLayoutData(gridData);
this.availableTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
addSelected();
}
});
this.availableTree.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.character == ' ')
addSelected();
}
});
Composite buttonComposite = new Composite(parent, SWT.NONE);
buttonComposite.setLayout(new GridLayout(1, true));
Button addButton = new Button(buttonComposite, SWT.PUSH);
// $NON-NLS-1$
addButton.setImage(GUIHelper.getImage("arrow_right"));
gridData = GridDataFactory.fillDefaults().grab(false, true).align(SWT.CENTER, SWT.CENTER).create();
addButton.setLayoutData(gridData);
addButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
addSelected();
}
});
final Button removeButton = new Button(buttonComposite, SWT.PUSH);
// $NON-NLS-1$
removeButton.setImage(GUIHelper.getImage("arrow_left"));
gridData = GridDataFactory.copyData(gridData);
removeButton.setLayoutData(gridData);
removeButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
removeSelected();
}
});
this.selectedTree = new Tree(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.Expand);
gridData = GridDataFactory.fillDefaults().grab(true, true).create();
this.selectedTree.setLayoutData(gridData);
this.selectedTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
if (ColumnChooserDialog.this.preventHidingAllColumns) {
if (!isSelectedTreeCompletelySelected()) {
removeSelected();
}
} else {
removeSelected();
}
}
});
this.selectedTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
boolean controlMask = (e.stateMask & SWT.MOD1) == SWT.MOD1;
if (controlMask && e.keyCode == SWT.ARROW_UP) {
moveSelectedUp();
e.doit = false;
} else if (controlMask && e.keyCode == SWT.ARROW_DOWN) {
moveSelectedDown();
e.doit = false;
}
}
@Override
public void keyReleased(KeyEvent e) {
if (e.character == ' ')
removeSelected();
}
});
this.selectedTree.addTreeListener(new TreeListener() {
@Override
public void treeCollapsed(TreeEvent event) {
selectedTreeCollapsed(event);
}
@Override
public void treeExpanded(TreeEvent event) {
selectedTreeExpanded(event);
}
});
this.selectedTree.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent event) {
widgetSelected(event);
}
@Override
public void widgetSelected(SelectionEvent event) {
toggleColumnGroupSelection((TreeItem) event.item);
if (ColumnChooserDialog.this.preventHidingAllColumns) {
removeButton.setEnabled(!isSelectedTreeCompletelySelected());
}
}
});
Composite upDownbuttonComposite = new Composite(parent, SWT.NONE);
upDownbuttonComposite.setLayout(new GridLayout(1, true));
Button topButton = new Button(upDownbuttonComposite, SWT.PUSH);
// $NON-NLS-1$
topButton.setImage(GUIHelper.getImage("arrow_up_top"));
gridData = GridDataFactory.fillDefaults().grab(false, true).align(SWT.CENTER, SWT.CENTER).create();
topButton.setLayoutData(gridData);
topButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
moveSelectedToTop();
}
});
Button upButton = new Button(upDownbuttonComposite, SWT.PUSH);
// $NON-NLS-1$
upButton.setImage(GUIHelper.getImage("arrow_up"));
gridData = GridDataFactory.fillDefaults().grab(false, true).align(SWT.CENTER, SWT.CENTER).create();
upButton.setLayoutData(gridData);
upButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
moveSelectedUp();
}
});
Button downButton = new Button(upDownbuttonComposite, SWT.PUSH);
// $NON-NLS-1$
downButton.setImage(GUIHelper.getImage("arrow_down"));
gridData = GridDataFactory.copyData(gridData);
downButton.setLayoutData(gridData);
downButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
moveSelectedDown();
}
});
Button bottomButton = new Button(upDownbuttonComposite, SWT.PUSH);
// $NON-NLS-1$
bottomButton.setImage(GUIHelper.getImage("arrow_down_end"));
gridData = GridDataFactory.copyData(gridData);
bottomButton.setLayoutData(gridData);
bottomButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
moveSelectedToBottom();
}
});
}
use of org.eclipse.swt.events.TreeListener in project tdq-studio-se by Talend.
the class Grid method initAccessible.
/**
* Initialize accessibility.
*/
private void initAccessible() {
final Accessible accessible = getAccessible();
accessible.addAccessibleListener(new AccessibleAdapter() {
public void getDescription(AccessibleEvent e) {
int childID = e.childID;
if (childID >= 0 && childID < items.size()) {
String descrption = "";
for (int i = 0; i < columns.size(); i++) {
if (i != 0) {
descrption += ((GridColumn) columns.get(i)).getText() + " : ";
descrption += ((GridItem) items.get(childID)).getText(i) + " ";
}
}
e.result = descrption;
}
}
public void getName(AccessibleEvent e) {
int childID = e.childID;
if (childID >= 0 && childID < items.size()) {
// Name of the items
e.result = ((GridItem) items.get(childID)).getText();
} else if (childID >= items.size() && childID < items.size() + columns.size()) {
// Name of the column headers
e.result = ((GridColumn) columns.get(childID - items.size())).getText();
} else if (childID >= items.size() + columns.size() && childID < items.size() + columns.size() + columnGroups.length) {
// Name of the column group headers
e.result = ((GridColumnGroup) columnGroups[childID - items.size() - columns.size()]).getText();
} else if (childID >= items.size() + columns.size() + columnGroups.length && childID < items.size() + columns.size() + columnGroups.length + columnGroups.length) {
// Name of the toggle button for column group headers
e.result = ACC_TOGGLE_BUTTON_NAME;
}
}
});
accessible.addAccessibleControlListener(new AccessibleControlAdapter() {
public void getChildAtPoint(AccessibleControlEvent e) {
Point location = toControl(e.x, e.y);
e.childID = ACC.CHILDID_SELF;
// Grid Items
GridItem item = getItem(location);
if (item != null) {
for (int i = 0; i < getItems().length; i++) {
if (item.equals(getItem(i))) {
e.childID = i;
return;
}
}
} else {
// Column Headers
GridColumn column = overColumnHeader(location.x, location.y);
if (column != null) {
for (int i = 0; i < getColumns().length; i++) {
if (column.equals(getColumn(i))) {
e.childID = getItems().length + i;
return;
}
}
} else {
// Column Group headers
GridColumnGroup columnGroup = overColumnGroupHeader(location.x, location.y);
if (columnGroup != null) {
for (int i = 0; i < getColumnGroups().length; i++) {
if (columnGroup.equals(getColumnGroup(i))) {
Rectangle toggle = ((DefaultColumnGroupHeaderRenderer) columnGroup.getHeaderRenderer()).getToggleBounds();
if (toggle.contains(location.x, location.y)) {
// Toggle button for column group
// header
e.childID = getItems().length + getColumns().length + getColumnGroups().length + i;
} else {
// Column Group header
e.childID = getItems().length + getColumns().length + i;
}
return;
}
}
}
}
}
}
public void getChildCount(AccessibleControlEvent e) {
if (e.childID == ACC.CHILDID_SELF) {
int length = items.size();
if (isTree) {
// it is consider as children of Grid
for (int i = 0; i < items.size(); i++) {
if (((GridItem) items.get(i)).getParentItem() != null) {
length--;
}
}
}
e.detail = length;
}
}
public void getChildren(AccessibleControlEvent e) {
if (e.childID == ACC.CHILDID_SELF) {
int length = items.size();
if (isTree) {
for (int i = 0; i < items.size(); i++) {
if (((GridItem) items.get(i)).getParentItem() != null) {
length--;
}
}
Object[] children = new Object[length];
int j = 0;
for (int i = 0; i < items.size(); i++) {
if (((GridItem) items.get(i)).getParentItem() == null) {
children[j] = new Integer(i);
j++;
}
}
e.children = children;
} else {
Object[] children = new Object[length];
for (int i = 0; i < items.size(); i++) {
children[i] = new Integer(i);
}
e.children = children;
}
}
}
public void getDefaultAction(AccessibleControlEvent e) {
int childID = e.childID;
if (childID >= 0 && childID < items.size()) {
if (getItem(childID).hasChildren()) {
// Action of tree items
if (getItem(childID).isExpanded()) {
e.result = ACC_ITEM_ACTION_COLLAPSE;
} else {
e.result = ACC_ITEM_ACTION_EXPAND;
}
} else {
// action of default items
e.result = ACC_ITEM_DEFAULT_ACTION;
}
} else if (childID >= items.size() && childID < items.size() + columns.size() + columnGroups.length) {
// action of column and column group header
e.result = ACC_COLUMN_DEFAULT_ACTION;
} else if (childID >= items.size() + columns.size() + columnGroups.length && childID < items.size() + columns.size() + columnGroups.length + columnGroups.length) {
// action of toggle button of column group header
e.result = SWT.getMessage("SWT_Press");
}
}
public void getLocation(AccessibleControlEvent e) {
// location of parent
Rectangle location = getBounds();
location.x = 0;
location.y = 0;
int childID = e.childID;
if (childID >= 0 && childID < items.size()) {
// location of items
GridItem item = getItem(childID);
if (item != null) {
Point p = getOrigin((GridColumn) columns.get(0), item);
location.y = p.y;
location.height = item.getHeight();
}
} else if (childID >= items.size() && childID < items.size() + columns.size()) {
// location of columns headers
GridColumn column = getColumn(childID - items.size());
if (column != null) {
location.x = getColumnHeaderXPosition(column);
if (column.getColumnGroup() == null) {
location.y = 0;
} else {
location.y = groupHeaderHeight;
}
location.height = headerHeight;
location.width = column.getWidth();
}
} else if (childID >= items.size() + columns.size() && childID < items.size() + columns.size() + columnGroups.length) {
// location of column group header
GridColumnGroup columnGroup = getColumnGroup(childID - items.size() - columns.size());
if (columnGroup != null) {
location.y = 0;
location.height = groupHeaderHeight;
location.x = getColumnHeaderXPosition(columnGroup.getFirstVisibleColumn());
int width = 0;
for (int i = 0; i < columnGroup.getColumns().length; i++) {
if (columnGroup.getColumns()[i].isVisible()) {
width += columnGroup.getColumns()[i].getWidth();
}
}
location.width = width;
}
} else if (childID >= items.size() + columns.size() + columnGroups.length && childID < items.size() + columns.size() + columnGroups.length + columnGroups.length) {
// location of toggle button of column group header
GridColumnGroup columnGroup = getColumnGroup(childID - items.size() - columns.size() - columnGroups.length);
location = ((DefaultColumnGroupHeaderRenderer) columnGroup.getHeaderRenderer()).getToggleBounds();
}
if (location != null) {
Point pt = toDisplay(location.x, location.y);
e.x = pt.x;
e.y = pt.y;
e.width = location.width;
e.height = location.height;
}
}
public void getRole(AccessibleControlEvent e) {
int childID = e.childID;
if (childID >= 0 && childID < items.size()) {
// role of items
if (isTree) {
e.detail = ACC.ROLE_TREEITEM;
} else {
e.detail = ACC.ROLE_LISTITEM;
}
} else if (childID >= items.size() && childID < items.size() + columns.size() + columnGroups.length) {
// role of columns headers and column group headers
e.detail = ACC.ROLE_TABLECOLUMNHEADER;
} else if (childID >= items.size() + columns.size() + columnGroups.length && childID < items.size() + columns.size() + columnGroups.length + columnGroups.length) {
// role of toggle button of column group headers
e.detail = ACC.ROLE_PUSHBUTTON;
} else if (childID == ACC.CHILDID_SELF) {
// role of parent
if (isTree) {
e.detail = ACC.ROLE_TREE;
} else {
e.detail = ACC.ROLE_TABLE;
}
}
}
public void getSelection(AccessibleControlEvent e) {
e.childID = ACC.CHILDID_NONE;
if (selectedItems.size() == 1) {
// Single selection
e.childID = indexOf(((GridItem) selectedItems.get(0)));
} else if (selectedItems.size() > 1) {
// multiple selection
e.childID = ACC.CHILDID_MULTIPLE;
int length = selectedItems.size();
Object[] children = new Object[length];
for (int i = 0; i < length; i++) {
GridItem item = (GridItem) selectedItems.get(i);
children[i] = new Integer(indexOf(item));
}
e.children = children;
}
}
public void getState(AccessibleControlEvent e) {
int childID = e.childID;
if (childID >= 0 && childID < items.size()) {
// state of items
e.detail = ACC.STATE_SELECTABLE;
if (getDisplay().getActiveShell() == getParent().getShell()) {
e.detail |= ACC.STATE_FOCUSABLE;
}
if (selectedItems.contains(getItem(childID))) {
e.detail |= ACC.STATE_SELECTED;
if (getDisplay().getActiveShell() == getParent().getShell()) {
e.detail |= ACC.STATE_FOCUSED;
}
}
if (getItem(childID).getChecked()) {
e.detail |= ACC.STATE_CHECKED;
}
// only for tree type items
if (getItem(childID).hasChildren()) {
if (getItem(childID).isExpanded()) {
e.detail |= ACC.STATE_EXPANDED;
} else {
e.detail |= ACC.STATE_COLLAPSED;
}
}
if (!getItem(childID).isVisible()) {
e.detail |= ACC.STATE_INVISIBLE;
}
} else if (childID >= items.size() && childID < items.size() + columns.size() + columnGroups.length) {
// state of column headers and column group headers
e.detail = ACC.STATE_READONLY;
} else if (childID >= items.size() + columns.size() + columnGroups.length && childID < items.size() + columns.size() + columnGroups.length + columnGroups.length) {
// state of toggle button of column group headers
if (getColumnGroup(childID - items.size() - columns.size() - columnGroups.length).getExpanded()) {
e.detail = ACC.STATE_EXPANDED;
} else {
e.detail = ACC.STATE_COLLAPSED;
}
}
}
public void getValue(AccessibleControlEvent e) {
int childID = e.childID;
if (childID >= 0 && childID < items.size()) {
// value for tree items
if (isTree) {
e.result = "" + getItem(childID).getLevel();
}
}
}
});
addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
if (selectedItems.size() > 0) {
accessible.setFocus(items.indexOf(selectedItems.get(selectedItems.size() - 1)));
}
}
});
addTreeListener(new TreeListener() {
public void treeCollapsed(TreeEvent e) {
if (getFocusItem() != null) {
accessible.setFocus(items.indexOf(getFocusItem()));
}
}
public void treeExpanded(TreeEvent e) {
if (getFocusItem() != null) {
accessible.setFocus(items.indexOf(getFocusItem()));
}
}
});
}
Aggregations