Java Code Examples for org.eclipse.swt.widgets.Tree#addListener()

The following examples show how to use org.eclipse.swt.widgets.Tree#addListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSection.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * New tree.
 *
 * @param parent the parent
 * @param style          SWT.SINGLE SWT.MULTI SWT.CHECK SWT.FULL_SELECTION
 * @return the TableTree
 */
protected Tree newTree(Composite parent, int style) {
  Tree tt = new Tree(parent, style);
  tt.setLayoutData(new GridData(GridData.FILL_BOTH));
  toolkit.adapt(tt, true, true);
  tt.addListener(SWT.Selection, this);
  tt.addListener(SWT.KeyUp, this); // for delete key
  tt.addListener(SWT.MouseDoubleClick, this); // for edit
  tt.addListener(SWT.Expand, this);
  tt.addListener(SWT.Collapse, this);
 
  // Make the TableTree's border visible since TableTree is NOT a widget supported
  // by FormToolkit.  Needed by RedHat Linux
  tt.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
  return tt;
}
 
Example 2
Source File: Bug280635Test.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public void testBug280635ForTree() {
	final Tree g = createTree(SWT.V_SCROLL | SWT.VIRTUAL);

	g.addListener(SWT.SetData, new Listener() {

		public void handleEvent(Event event) {
			TreeItem item = (TreeItem) event.item;
			int index;
			if (item.getParentItem() != null) {
				index = item.getParentItem().indexOf(item);
				item.setItemCount(0);
			} else {
				index = g.indexOf(item);
				item.setItemCount(100);
			}

			System.out.println("setData index " + index); //$NON-NLS-1$
			// Your image here
			// item.setImage(eclipseImage);
			item.setText("Item " + index); //$NON-NLS-1$
		}

	});

	g.setItemCount(1);

	g.getItem(0).dispose();

	assertEquals(g.getItemCount(), 0);
	g.dispose();

}
 
Example 3
Source File: TreeThemer.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void addMeasureItemListener()
{
	if (controlIsDisposed())
	{
		return;
	}

	final Tree tree = getTree();
	// Hack to force a specific row height and width based on font
	measureItemListener = new Listener()
	{
		public void handleEvent(Event event)
		{
			if (!useEditorFont())
			{
				return;
			}
			Font font = JFaceResources.getFont(IThemeManager.VIEW_FONT_NAME);
			if (font == null)
			{
				font = JFaceResources.getTextFont();
			}
			if (font != null)
			{
				event.gc.setFont(font);
				FontMetrics metrics = event.gc.getFontMetrics();
				int height = metrics.getHeight() + 2;
				TreeItem item = (TreeItem) event.item;
				int width = event.gc.stringExtent(item.getText()).x + 24; // minimum width we need for text plus eye
				event.height = height;
				if (width > event.width)
				{
					event.width = width;
				}
			}
		}
	};
	tree.addListener(SWT.MeasureItem, measureItemListener);
}
 
Example 4
Source File: TreeValueDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates and initializes the tree viewer.
 * 
 * @param parent
 *            the parent composite
 * @return the tree viewer
 * @see #doCreateTreeViewer(Composite, int)
 */
protected TreeViewer createTreeViewer( Composite parent )
{
	TreeViewer treeViewer = super.createTreeViewer( parent );
	Tree tree = treeViewer.getTree( );
	assert ( tree != null );
	for ( int i = 0; i < listeners.size( ); i++ )
	{
		int type = listeners.get( i ).type;
		Listener listener = listeners.get( i ).listener;
		tree.addListener( type, listener );
	}
	return treeViewer;
}
 
Example 5
Source File: AbstractSection.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * New tree.
 *
 * @param parent the parent
 * @return the tree
 */
protected Tree newTree(Composite parent) {
  Tree local_tree = toolkit.createTree(parent, SWT.SINGLE);
  local_tree.setLayoutData(new GridData(GridData.FILL_BOTH));
  local_tree.addListener(SWT.Selection, this);
  local_tree.addListener(SWT.KeyUp, this);
  return local_tree;
}
 
Example 6
Source File: AbstractDialog.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * New tree.
 *
 * @param parent the parent
 * @param style the style
 * @return the tree
 */
protected Tree newTree(Composite parent, int style) {
  Tree tree = new Tree(parent, style | SWT.BORDER);
  GridData gd = new GridData(GridData.FILL_BOTH);
  tree.setLayoutData(gd);
  tree.addListener(SWT.Selection, this);
  tree.addListener(SWT.KeyUp, this); // delete key
  return tree;
}
 
Example 7
Source File: TreeClipboard.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Registers Ctr+c for copying table content to clipboard and returns an
 * action which also calls this function.
 */
public static Action onCopy(Tree tree, ClipboardLabelProvider label) {
	tree.addListener(SWT.KeyUp, (event) -> {
		if (event.stateMask == SWT.CTRL && event.keyCode == 'c') {
			copy(tree, label);
		}
	});
	ImageDescriptor image = Icon.COPY.descriptor();
	return Actions.create(M.Copy, image, () -> copy(tree, label));
}
 
Example 8
Source File: TreeClipboard.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
public static Action onCopy(Tree tree) {
	tree.addListener(SWT.KeyUp, (event) -> {
		if (event.stateMask == SWT.CTRL && event.keyCode == 'c') {
			copy(tree);
		}
	});
	ImageDescriptor image = Icon.COPY.descriptor();
	return Actions.create(M.Copy, image, () -> copy(tree));
}
 
Example 9
Source File: CTreeCombo.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
void createPopup(Collection<CTreeComboItem> items, CTreeComboItem selectedItem) {
	// create shell and list
	popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
	final int style = getStyle();
	int listStyle = SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE;
	if ((style & SWT.FLAT) != 0) {
		listStyle |= SWT.FLAT;
	}
	if ((style & SWT.RIGHT_TO_LEFT) != 0) {
		listStyle |= SWT.RIGHT_TO_LEFT;
	}
	if ((style & SWT.LEFT_TO_RIGHT) != 0) {
		listStyle |= SWT.LEFT_TO_RIGHT;
	}
	tree = new Tree(popup, listStyle);
	tree.addTreeListener(hookListener);
	if (font != null) {
		tree.setFont(font);
	}
	if (foreground != null) {
		tree.setForeground(foreground);
	}
	if (background != null) {
		tree.setBackground(background);
	}

	final int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate };
	for (int i = 0; i < popupEvents.length; i++) {
		popup.addListener(popupEvents[i], listener);
	}
	final int[] listEvents = { SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn, SWT.Dispose, SWT.Collapse, SWT.Expand };
	for (int i = 0; i < listEvents.length; i++) {
		tree.addListener(listEvents[i], listener);
	}

	for (final CTreeComboColumn c : columns) {
		final TreeColumn col = new TreeColumn(tree, SWT.NONE);
		c.setRealTreeColumn(col);
	}

	if (items != null) {
		createTreeItems(items.toArray(new CTreeComboItem[0]));
	}

	if (selectedItem != null) {
		tree.setSelection(selectedItem.getRealTreeItem());
	}
}
 
Example 10
Source File: PTWidgetTree.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @see org.eclipse.nebula.widgets.opal.propertytable.AbstractPTWidget#buildWidget(org.eclipse.swt.widgets.Composite)
 */
@Override
protected void buildWidget(final Composite parent) {
	tree = new Tree(parent, SWT.FULL_SELECTION);
	tree.setLinesVisible(true);
	tree.setHeaderVisible(true);
	tree.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 3, 1));

	final TreeColumn propertyColumn = new TreeColumn(tree, SWT.NONE);
	propertyColumn.setText(ResourceManager.getLabel(ResourceManager.PROPERTY));

	final TreeColumn valueColumn = new TreeColumn(tree, SWT.NONE);
	valueColumn.setText(ResourceManager.getLabel(ResourceManager.VALUE));

	fillData();
	tree.addControlListener(new ControlAdapter() {

		/**
		 * @see org.eclipse.swt.events.ControlAdapter#controlResized(org.eclipse.swt.events.ControlEvent)
		 */
		@Override
		public void controlResized(final ControlEvent e) {
			final Rectangle area = tree.getParent().getClientArea();
			final Point size = tree.computeSize(SWT.DEFAULT, SWT.DEFAULT);
			final ScrollBar vBar = tree.getVerticalBar();
			int width = area.width - tree.computeTrim(0, 0, 0, 0).width - vBar.getSize().x;
			if (size.y > area.height + tree.getHeaderHeight()) {
				// Subtract the scrollbar width from the total column width
				// if a vertical scrollbar will be required
				final Point vBarSize = vBar.getSize();
				width -= vBarSize.x;
			}
			propertyColumn.pack();
			valueColumn.setWidth(width - propertyColumn.getWidth());
			tree.removeControlListener(this);
		}

	});

	tree.addListener(SWT.Selection, event -> {
		if (tree.getSelectionCount() == 0 || tree.getSelection()[0] == null) {
			return;
		}
		updateDescriptionPanel(tree.getSelection()[0].getData());
	});

}
 
Example 11
Source File: LogAnalysis.java    From AndroidRobot with Apache License 2.0 4 votes vote down vote up
public void createLogList() {
    tabFolderLogList = new CTabFolder(sashFormLog, SWT.NONE | SWT.BORDER);
    tabFolderLogList.setTabHeight(0);
    tabFolderLogList.marginHeight = 0;
    tabFolderLogList.marginWidth = 0;
    tabFolderLogList.setLayout(new FillLayout());
    tabFolderLogList.setBounds(5, 5, 200, 465);
    tabFolderLogList.setSimple(false);
    tabFolderLogList.setUnselectedCloseVisible(true);

    CTabItem tabItemLogList = new CTabItem(tabFolderLogList, SWT.NONE | SWT.MULTI
                                                             | SWT.V_SCROLL);
    tabFolderLogList.setSelection(tabItemLogList);
    tabItemLogList.setText("日志浏览");

    Composite composite = new Composite(tabFolderLogList, SWT.NONE);
    composite.setLayout(new GridLayout());
    treeLog = new Tree(composite, SWT.BORDER);
    colorBlack = display.getSystemColor(SWT.COLOR_BLACK);

    tabItemLogList.setControl(composite);
    treeLog.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    treeLog.addListener(SWT.MouseDoubleClick, new Listener() {
        public void handleEvent(Event event) {
            Point point = new Point(event.x, event.y);
            TreeItem item = treeLog.getItem(point);
            if (item != null) {
                String taskName = (String) item.getData("task");
                String loop = String.valueOf(item.getData("loop"));
                String caseName = (String) item.getData("case");
                int index = (Integer) item.getData("index");
                //System.out.println("task:"+taskName+" loop:"+loop+" caseName:"+caseName+" index:"+index);
                if (index != 0)
                    Log.loadLogs(styledTextLog, display, logFile, taskName, loop, caseName,
                        index);
            }
        }
    });

}
 
Example 12
Source File: TreeThemer.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private void addCustomTreeControlDrawing()
{
	// Hack to overdraw the native tree expand/collapse controls and use custom plus/minus box.
	if (isMacOSX || isUbuntu || controlIsDisposed())
	{
		return;
	}

	// FIXME The native control/arrow still shows through on OpenSuSE 11.4
	final Tree tree = getTree();
	customDrawingListener = new Listener()
	{
		public void handleEvent(Event event)
		{
			if (!invasiveThemesEnabled())
			{
				return;
			}
			GC gc = event.gc;
			Widget item = event.item;
			boolean isExpanded = false;
			boolean draw = false;
			if (item instanceof TreeItem)
			{
				TreeItem tItem = (TreeItem) item;
				isExpanded = tItem.getExpanded();
				draw = tItem.getItemCount() > 0;
			}
			if (!draw)
			{
				return;
			}
			final int width = 10;
			final int height = 12;
			final int x = event.x - 16;
			final int y = event.y + 4;
			Color oldBackground = gc.getBackground();
			gc.setBackground(getBackground());
			// wipe out the native control
			gc.fillRectangle(x, y, width + 1, height - 1); // +1 and -1 because of hovering selecting on windows
			// vista
			// draw a plus/minus based on expansion!
			gc.setBackground(getForeground());
			// draw surrounding box (with alpha so that it doesn't get too strong).
			gc.setAlpha(195);
			gc.drawRectangle(x + 1, y + 1, width - 2, width - 2); // make it smaller than the area erased
			gc.setAlpha(255);
			// draw '-'
			int halfWidth = width >> 1;
			gc.drawLine(x + 3, y + halfWidth, x + 7, y + halfWidth);
			if (!isExpanded)
			{
				// draw '|' to make it a plus
				gc.drawLine(x + halfWidth, y + 3, x + halfWidth, y + 7);
			}
			gc.setBackground(oldBackground);

			event.detail &= ~SWT.BACKGROUND;
		}
	};
	tree.addListener(SWT.PaintItem, customDrawingListener);
}
 
Example 13
Source File: TreeManager.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public TreeManager( Tree tree, GUIResource guiResource ) {
  this.guiResource = guiResource;
  this.tree = tree;
  tree.addListener( SWT.Expand, e -> setExpanded( (TreeItem) e.item, true ) );
  tree.addListener( SWT.Collapse, e -> setExpanded( (TreeItem) e.item, false ) );
}