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

The following are Jave code examples for showing how to use addListener() of the org.eclipse.swt.widgets.Tree class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: convertigo-eclipse   File: ProjectSchemaWizardPage.java   Source Code and License Vote up 5 votes
public void createControl(Composite parent) {
	Composite container = new Composite(parent, SWT.NULL);
	GridLayout layout = new GridLayout();
	container.setLayout(layout);
	layout.numColumns = 2;
	layout.verticalSpacing = 9;

	Label label = new Label(container, SWT.NULL);
	label.setText("&Project:");
	
	tree = new Tree(container, SWT.SINGLE | SWT.BORDER);
	tree.setHeaderVisible(false);
	GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
	gridData.verticalSpan = 20;
	gridData.horizontalSpan = 2;
	tree.setLayoutData(gridData);		
	tree.addListener(SWT.Selection, new Listener() {
		public void handleEvent(final Event event) {
			TreeItem item = (TreeItem) event.item;
			projectName = item.getText();
			dialogChanged();
		}
	});
	tree.setVisible(false);
	
	initialize();
	setControl(container);
	dialogChanged();
}
 
Example 2
Project: team-explorer-everywhere   File: QueryResultsTreeControl.java   Source Code and License Vote up 5 votes
private void setupTree(final Tree tree) {
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    tree.setLayout(new TreeLayout());

    /* Pad table height by four pixels to increase readability */
    tree.addListener(/* SWT.MeasureItem */41, new MeasureItemHeightListener(4));
    tree.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(final MouseEvent e) {
        }
    });
}
 
Example 3
Project: Vitruv   File: ApplicationSelectionPage.java   Source Code and License Vote up 5 votes
@Override
public void createControl(Composite parent) {
	container = new Composite(parent, SWT.NONE);
	Label label1 = new Label(container, SWT.NONE);
	label1.setText(SELECTION_LABEL);
	tree = new Tree(container, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
	GridLayout layout = new GridLayout();
	container.setLayout(layout);
	layout.numColumns = 1;
	GridData treeGridData = new GridData(GridData.FILL_BOTH);
	tree.setLayoutData(treeGridData);
	tree.addListener(SWT.Selection, new Listener() {

		@Override
		public void handleEvent(Event event) {
			if (event.detail == SWT.CHECK) {
				TreeItem item = (TreeItem) event.item;
				if (item.getChecked()) {
					selectedApplications.add((VitruvApplication) item.getData());
				} else {
					selectedApplications.remove(item.getData());
				}
				setPageComplete(!selectedApplications.isEmpty());
			}
		}
	});

	setControl(container);
	setPageComplete(false);
}
 
Example 4
Project: xstreamer   File: AbstractPlayerFormPage.java   Source Code and License Vote up 5 votes
private void createArmySection() {
	Section squadSection = toolkit.createSection(form.getBody(),
			ExpandableComposite.TWISTIE | Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
	String points = "";
	squadSection.setText("Army - Total Points " + points);

	squadSection.setExpanded(true);
	squadSection.setDescription("This contains the player's army");

	Composite squadComposite = toolkit.createComposite(squadSection);
	GridLayout squadGridLayout = new GridLayout();
	squadGridLayout.numColumns = 3;

	squadComposite.setLayout(squadGridLayout);

	treeViewer = new TreeViewer(squadComposite, SWT.WRAP | SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
	treeViewer.setContentProvider(new ArmyContentProvider());
	treeViewer.setLabelProvider(new ArmyLabelProvider());
	treeViewer.setInput(getPlayerModel());
	treeViewer.addSelectionChangedListener(new ArmySelectionChangeListener());

	GridData treeSize = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 5);
	treeSize.minimumHeight = 300;
	treeSize.heightHint = 300;

	treeViewer.getTree().setLayoutData(treeSize);
	Tree tree = treeViewer.getTree();
	tree.addListener(SWT.Resize, new Listener() {
		@Override
		public void handleEvent(Event arg0) {
			Point size = tree.getSize();

			if (size.x > 300) {
				tree.setSize(300, size.y);
			}
		}
	});

	squadSection.setClient(squadComposite);
}
 
Example 5
Project: EsperDist   File: TestSWTTree.java   Source Code and License Vote up 5 votes
public static void main(String[] args) {
	Display display = new Display();
	Shell shell = new Shell(display);
	shell.setText("Tree Example");

	final Text text = new Text(shell, SWT.BORDER);
	text.setBounds(0, 270, 290, 25);

	final Tree tree = new Tree(shell, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL
			| SWT.H_SCROLL);
	
	tree.setSize(290, 260);
	shell.setSize(300, 330);

	for (int loopIndex0 = 0; loopIndex0 < 10; loopIndex0++) {
		TreeItem treeItem0 = new TreeItem(tree, 0);
		treeItem0.setText("Level 0 Item " + loopIndex0);
		for (int loopIndex1 = 0; loopIndex1 < 10; loopIndex1++) {
			TreeItem treeItem1 = new TreeItem(treeItem0, 0);
			treeItem1.setText("Level 1 Item " + loopIndex1);
			for (int loopIndex2 = 0; loopIndex2 < 10; loopIndex2++) {
				TreeItem treeItem2 = new TreeItem(treeItem1, 0);
				treeItem2.setText("Level 2 Item " + loopIndex2);
			}
		}
	}

	tree.addListener(SWT.Selection, new Listener() {
		public void handleEvent(Event event) {
			if (event.detail == SWT.CHECK) {
				text.setText(event.item + " was checked.");
			} else {
				text.setText(event.item + " was selected");
			}
		}
	});

	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
 
Example 6
Project: APICloud-Studio   File: TreeThemer.java   Source Code and License Vote up 5 votes
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 7
Project: convertigo-eclipse   File: ComponentInfoWizardPage.java   Source Code and License Vote up 4 votes
public void createControl(Composite parent) {
	container = new Composite(parent, SWT.NONE);
	GridLayout layout = new GridLayout();
	container.setLayout(layout);
	layout.numColumns = 2;
	layout.verticalSpacing = 9;

	Label label = new Label(container, SWT.NULL);
	label.setText("&Name:");

	beanName = new Text(container, SWT.BORDER | SWT.SINGLE);
	GridData gd = new GridData(GridData.FILL_HORIZONTAL);
	beanName.setLayoutData(gd);
	beanName.addModifyListener(new ModifyListener() {
		public void modifyText(ModifyEvent e) {
			dialogChanged();
		}
	});
	
	if (parentObject instanceof CouchDbConnector || parentObject instanceof FullSyncConnector) {
		couchVariablesComposite = new CouchVariablesComposite(container, SWT.V_SCROLL);
		
		GridData couchVarData = new GridData(GridData.FILL_BOTH);
		couchVarData.horizontalSpan = 2;
		
		couchVariablesComposite.setLayoutData(couchVarData);
		
	} else {
		tree = new Tree(container, SWT.SINGLE | SWT.BORDER);
		tree.setHeaderVisible(false);
		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
		gridData.verticalSpan = 20;
		gridData.horizontalSpan = 2;
		tree.setLayoutData(gridData);		
		tree.addListener(SWT.Selection, new Listener() {
			public void handleEvent(final Event event) {
				TreeItem item = (TreeItem) event.item;
				treeItemName = item.getText();
				String suffix = getBeanName().endsWith(ScHandlerStatement.EVENT_ENTRY_HANDLER) ? 
						ScHandlerStatement.EVENT_ENTRY_HANDLER:
							getBeanName().endsWith(ScHandlerStatement.EVENT_EXIT_HANDLER) ?
									ScHandlerStatement.EVENT_EXIT_HANDLER : "";
				setBeanName("on"+ treeItemName + suffix);
				dialogChanged();
			}
		});
		tree.setVisible(false);
	}
	
	initialize();
	dialogChanged();
	setControl(container);
}
 
Example 8
Project: convertigo-eclipse   File: ObjectInfoWizardPage.java   Source Code and License Vote up 4 votes
public void createControl(Composite parent) {
	container = new Composite(parent, SWT.NONE);
	GridLayout layout = new GridLayout();
	container.setLayout(layout);
	layout.numColumns = 2;
	layout.verticalSpacing = 9;

	Label label = new Label(container, SWT.NULL);
	label.setText("&Name:");

	beanName = new Text(container, SWT.BORDER | SWT.SINGLE);
	GridData gd = new GridData(GridData.FILL_HORIZONTAL);
	beanName.setLayoutData(gd);
	beanName.addModifyListener(new ModifyListener() {
		public void modifyText(ModifyEvent e) {
			dialogChanged();
		}
	});
	
	if (parentObject instanceof CouchDbConnector || parentObject instanceof FullSyncConnector) {
		couchVariablesComposite = new CouchVariablesComposite(container, SWT.V_SCROLL);
		
		GridData couchVarData = new GridData(GridData.FILL_BOTH);
		couchVarData.horizontalSpan = 2;
		
		couchVariablesComposite.setLayoutData(couchVarData);
		
	} else {
		tree = new Tree(container, SWT.SINGLE | SWT.BORDER);
		tree.setHeaderVisible(false);
		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
		gridData.verticalSpan = 20;
		gridData.horizontalSpan = 2;
		tree.setLayoutData(gridData);		
		tree.addListener(SWT.Selection, new Listener() {
			public void handleEvent(final Event event) {
				TreeItem item = (TreeItem) event.item;
				treeItemName = item.getText();
				String suffix = getBeanName().endsWith(ScHandlerStatement.EVENT_ENTRY_HANDLER) ? 
						ScHandlerStatement.EVENT_ENTRY_HANDLER:
							getBeanName().endsWith(ScHandlerStatement.EVENT_EXIT_HANDLER) ?
									ScHandlerStatement.EVENT_EXIT_HANDLER : "";
				setBeanName("on"+ treeItemName + suffix);
				dialogChanged();
			}
		});
		tree.setVisible(false);
	}
	
	initialize();
	dialogChanged();
	setControl(container);
}
 
Example 9
Project: xstreamer   File: AbstractPlayerFormPage.java   Source Code and License Vote up 4 votes
private void createSquadSection() {
	Section squadSection = toolkit.createSection(form.getBody(),
			ExpandableComposite.TWISTIE | Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
	XwsSpec xwsModel = getPlayerModel();
	String points = xwsModel != null ? Integer.toString(xwsModel.getPoints()) : "";
	squadSection.setText("Squad - Total Points " + points);

	squadSection.setExpanded(true);
	squadSection.setDescription("This contains the player's squadron");

	Composite squadComposite = toolkit.createComposite(squadSection);
	GridLayout squadGridLayout = new GridLayout();
	squadGridLayout.numColumns = 3;

	squadComposite.setLayout(squadGridLayout);

	treeViewer = new TreeViewer(squadComposite, SWT.WRAP | SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
	treeViewer.setContentProvider(new SquadContentProvider());
	treeViewer.setLabelProvider(new SquadLabelProvider());
	treeViewer.setInput(getPlayerModel());
	treeViewer.addSelectionChangedListener(new SquadSelectionChangeListener(this));

	GridData treeSize = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 5);
	treeSize.minimumHeight = 300;
	treeSize.heightHint = 300;

	treeViewer.getTree().setLayoutData(treeSize);
	Tree tree = treeViewer.getTree();
	tree.addListener(SWT.Resize, new Listener() {
		@Override
		public void handleEvent(Event arg0) {
			Point size = tree.getSize();

			if (size.x > 300) {
				tree.setSize(300, size.y);
			}
		}
	});

	squadSection.setClient(squadComposite);
}
 
Example 10
Project: AndroidRobot   File: LogAnalysis.java   Source Code and License Vote up 4 votes
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 11
Project: APICloud-Studio   File: TreeThemer.java   Source Code and License Vote up 4 votes
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 12
Project: mytourbook   File: ColumnManager.java   Source Code and License Vote up 4 votes
/**
 * set context menu depending on the position of the mouse
 * 
 * @param tree
 * @param defaultContextMenu
 *            can be <code>null</code>
 */
public void createHeaderContextMenu(final Tree tree, final Menu defaultContextMenu) {

	// remove old listener
	if (_treeMenuDetectListener != null) {
		tree.removeListener(SWT.MenuDetect, _treeMenuDetectListener);
	}

	final Menu headerContextMenu = createHCM_0_Menu(tree, defaultContextMenu);

	// add the context menu to the tree viewer
	_treeMenuDetectListener = new Listener() {
		@Override
		public void handleEvent(final Event event) {

			final Decorations shell = tree.getShell();
			final Display display = shell.getDisplay();

			final Point mousePosition = display.map(null, tree, new Point(event.x, event.y));

			final Rectangle clientArea = tree.getClientArea();

			final int headerHeight = tree.getHeaderHeight();
			final int headerBottom = clientArea.y + headerHeight;

			final boolean isTreeHeaderHit = clientArea.y <= mousePosition.y && mousePosition.y < headerBottom;

			_headerColumn = getHeaderColumn(tree, mousePosition, isTreeHeaderHit);

			final Menu contextMenu = getContextMenu(isTreeHeaderHit, headerContextMenu, defaultContextMenu);

			tree.setMenu(contextMenu);

			/*
			 * Set context menu position to the right border of the column
			 */
			if (_headerColumn != null) {

				int posX = _headerColumn.columnRightBorder;
				int xOffset = 0;

				final ScrollBar hBar = tree.getHorizontalBar();

				if (hBar != null) {
					xOffset = hBar.getSelection();
				}

				/*
				 * It is possible that the context menu is outside of the tree, this occures
				 * when the column is very wide and horizonal scrolled.
				 */
				if (posX - xOffset > clientArea.width) {
					posX = xOffset + clientArea.width;
				}

				final Point displayPosition = tree.toDisplay(posX, headerBottom);

				event.x = displayPosition.x - 1;
				event.y = displayPosition.y - 2;
			}
		}
	};

	tree.addListener(SWT.MenuDetect, _treeMenuDetectListener);
}
 
Example 13
Project: sophie   File: FilesTree.java   Source Code and License Vote up 4 votes
/**
 * Create a new tree listing Solr config files.
 * 
 * @param composite
 *            Parent composite.
 */
public FilesTree(Composite composite) throws SophieException {
    Composite parent = new Composite(composite, SWT.NULL);
    parent.setLayout(new GridLayout(2, true));
    parent.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Instantiate Tree.
    tree = new Tree(parent, SWT.BORDER);
    tree.setHeaderVisible(true);
    tree.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Display file in viewer when user double clicks tree item.
    tree.addListener(SWT.MouseDoubleClick, new Listener() {
        @Override
        public void handleEvent(Event event) {
            Point point = new Point(event.x, event.y);
            TreeItem item = tree.getItem(point);
            if (item != null) {
                String fullPath = Objects.toString(item.getData(), "");
                String content;
                if (StringUtils.isEmpty(fullPath)) {
                    content = "This is a directory.";
                } else {
                    try {
                        content = SolrUtils.getFileContent(fullPath);
                    } catch (SophieException e) {
                        content = "Unable to fetch content for " + fullPath + ": " + e.getMessage();
                        Sophie.log.error("Unable to fetch content for " + fullPath, e);
                    }
                }
                styledText.setText(content);
            }
        }
    });

    // Create column.
    columnName = new TreeColumn(tree, SWT.LEFT);
    columnName.setText("File Name");

    // Instantiate viewer.
    styledText = new StyledText(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    styledText.setText("No file selected.");
    styledText.setEditable(false);
    styledText.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Config files are easier to read with a monospaced font.
    Font monospaced = JFaceResources.getFont(JFaceResources.TEXT_FONT);
    styledText.setFont(monospaced);

    // Populate tree with data from Solr.
    populate();

    // Pack columns.
    columnName.pack();
}