/*******************************************************************************
* Copyright (c) 2007, 2014 compeople AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* compeople AG - initial API and implementation
*******************************************************************************/
package org.eclipse.riena.sample.snippets;
import org.eclipse.jface.viewers.ColumnLayoutData;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.riena.beans.common.WordNode;
import org.eclipse.riena.ui.ridgets.IGroupedTreeTableRidget;
import org.eclipse.riena.ui.ridgets.swt.SwtRidgetFactory;
import org.eclipse.riena.ui.swt.utils.UIControlsFactory;
/**
* Demonstrates automatic tree column creation and setting the column widths.
*/
public class SnippetTreeTableRidget005 {
public SnippetTreeTableRidget005(final Shell shell) {
final Tree tree = new Tree(shell, SWT.FULL_SELECTION | SWT.MULTI);
// need ONE column to show that this tree is a table-tree. The correct
// number of columns will be created as needed, when bind is invoked.
new TreeColumn(tree, SWT.NONE);
final IGroupedTreeTableRidget treeTableRidget = (IGroupedTreeTableRidget) SwtRidgetFactory.createRidget(tree);
// set the widths
final ColumnLayoutData[] widths = new ColumnLayoutData[] { new ColumnWeightData(2), new ColumnWeightData(1) };
treeTableRidget.setColumnWidths(widths);
final String[] columnValues = new String[] { "word", "upperCase" }; //$NON-NLS-1$//$NON-NLS-2$
final String[] columnHeaders = new String[] { "Word", "Uppercase" }; //$NON-NLS-1$//$NON-NLS-2$
treeTableRidget.bindToModel(createTreeInput(), WordNode.class, "children", "parent", //$NON-NLS-1$//$NON-NLS-2$
columnValues, columnHeaders);
treeTableRidget.expandAll();
}
/**
* @param args
*/
public static void main(final String[] args) {
final Display display = Display.getDefault();
try {
final Shell shell = UIControlsFactory.createShell(display);
shell.setText(SnippetTreeTableRidget005.class.getSimpleName());
new SnippetTreeTableRidget005(shell);
shell.setSize(400, 400);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
} finally {
display.dispose();
}
}
private WordNode[] createTreeInput() {
final WordNode root = new WordNode("Words"); //$NON-NLS-1$
final WordNode bTowns = new WordNode(root, "B"); //$NON-NLS-1$
new WordNode(bTowns, "Boring"); //$NON-NLS-1$
new WordNode(bTowns, "Buchanan"); //$NON-NLS-1$
new WordNode(bTowns, "Beaverton").setUpperCase(true); //$NON-NLS-1$
new WordNode(bTowns, "Bend"); //$NON-NLS-1$
new WordNode(bTowns, "Black Butte Ranch"); //$NON-NLS-1$
new WordNode(bTowns, "Baker City"); //$NON-NLS-1$
new WordNode(bTowns, "Bay City"); //$NON-NLS-1$
new WordNode(bTowns, "Bridgeport"); //$NON-NLS-1$
final WordNode cTowns = new WordNode(root, "C"); //$NON-NLS-1$
new WordNode(cTowns, "Cedar Mill"); //$NON-NLS-1$
new WordNode(cTowns, "Crater Lake"); //$NON-NLS-1$
new WordNode(cTowns, "Coos Bay"); //$NON-NLS-1$
new WordNode(cTowns, "Corvallis"); //$NON-NLS-1$
new WordNode(cTowns, "Cannon Beach"); //$NON-NLS-1$
final WordNode dTowns = new WordNode(root, "D"); //$NON-NLS-1$
new WordNode(dTowns, "Dunes City"); //$NON-NLS-1$
new WordNode(dTowns, "Damascus"); //$NON-NLS-1$
new WordNode(dTowns, "Diamond Lake"); //$NON-NLS-1$
new WordNode(dTowns, "Dallas"); //$NON-NLS-1$
new WordNode(dTowns, "Depoe Bay"); //$NON-NLS-1$
return new WordNode[] { root };
}
}