Eclipse plugin "copy treeItem or tree data " - eclipse

I am working on Eclipse plugin. In this I am creating a view like console which is based on tree structure.
I am creating tree like below --
ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL );
Composite composite1 = new Composite(sc, SWT.NONE);
Composite composite_1 = creatingcomposite(composite1);
final Tree tree = new Tree(composite_1, SWT.FULL_SELECTION );
TreeItem item = new TreeItem(tree, SWT.NONE);
TreeItem subItem = new TreeItem(item, SWT.NONE);
TreeItem subsubItem = new TreeItem(subItem, SWT.NONE);
Now I want to copy some data of node(Like item or sub item),
In any node of tree or tree item suppose there is some data like " Hi this is ram and my contact number is 123456789658" now from this row i want to select/copy the contact number.
so how can I do it with the help of mouse (as we use in any other interface like wordpad).

Look at swt snippets for basic swt tree and menu examples.
Create menu(pop up menu) on tree item(s).
On click of menu items (say copy phone number) get the selected node text and extract the phone number out of this.

Related

Adding new menu item to a menu bar defined in plugin.xml programmatically in RCP application

I have an eclipse rcp application, with menu extension.
There is one menu item "File"
Now I want to add a new menu item from one of the views (I know this is a wrong design, just want to test it)
in the method createPartControl of my class that extends ViewPar, I have:
Menu menuBar = parent.getShell().getMenuBar(); //I get the Menu that contains File
MenuItem editMenuItem = new MenuItem(menuBar, SWT.CASCADE);
editMenuItem.setText("Edit");
Menu editMenu = new Menu(parent.getShell(), SWT.DROP_DOWN);
editMenuItem.setMenu(editMenu);
When in Debug I watch the parent.getShell().getMenuBar()
I get:
Menu {File, Edit}
But in application window I see only File menu.
To do this programatically rather than via an extension point it looks like you have to use IMenuService and add a contribution factory:
IMenuService menuService = (IMenuService)PlatformUI.getWorkbench().getService(IMenuService.class);
menuService.addContributionFactory(factory);
factory is a class derived from AbstractContributionFactory which provides the menu items.
This example is from http://wiki.eclipse.org/Menu_Contributions/Search_Menu
AbstractContributionFactory searchContribution = new AbstractContributionFactory(
"menu:org.eclipse.ui.main.menu?after=navigate") {
public void createContributionItems(IMenuService menuService,
List additions) {
MenuManager search = new MenuManager("Se&arch",
"org.eclipse.search.menu");
search.add(new GroupMarker("internalDialogGroup"));
search.add(new GroupMarker("dialogGroup"));
search.add(new Separator("fileSearchContextMenuActionsGroup"));
search.add(new Separator("contextMenuActionsGroup"));
search.add(new Separator("occurencesActionsGroup"));
search.add(new Separator("extraSearchGroup"));
additions.add(search);
}
public void releaseContributionItems(IMenuService menuService,
List items) {
// nothing to do here
}
};
menuService.addContributionFactory(searchContribution);

SmartGWT expanding Tree till a child node

I have created a tree using the following code. Is there a way to expand the tree till a particular child node from the code?
TreeGrid treeGrid = new TreeGrid();
Tree tree = new Tree();
tree.setRoot(new TreeNode("root", new TreeNode("File",
new TreeNode("FileChild")), new TreeNode("Edit", new TreeNode(
"EditChild", new TreeNode("EditGrandChild"))), new TreeNode(
"Window")));
treeGrid.setData(tree);
treeGrid.draw();
I want to display the "EditGrandChild" node when the tree is rendered. How do i do that?
Thanks
I used to open some parts of a treegrid depending on the result of a search and I used this bits of code
TreeNode[] tabNode = leTree.getParents(t);
leTree.openFolders(tabNode);
Hope it could help...

SWT Table checkbox for all columns

I am trying to create a two-column-table with checkboxes in both of them
I have created a table with the following snippet:
Table table = new Table(parent, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
TableColumn tableColumn = new TableColumn(table, SWT.NONE);
tableColumn.setWidth(300);
tableColumn.setText("Check Column1");
TableColumn tableColumn1 = new TableColumn(table, SWT.NONE);
tableColumn1.setWidth(300);
tableColumn1.setText("Check Column2");
TableItem tableItem=new TableItem(table,SWT.NONE);
Image image=getImage(imagePath);
tableItem.setImage(0, image);
what I am getting is the first column the checkbox was created but not in the second one
Do you know why?
This is not supported by the standard SWT Table Widget. Try the Nattable from Nebula for a more feature rich table widget.
If you want to show CheckBox in Table Cell, you could do it in two ways.
show image ( check on/off) depending on state of the data that you have and you need listen on mouse click on table cell.
you could add Button ( SWT.CHECK) as I mentioned below
SWT - Tableviewer adding a remove button to a column in the table

Changing dynamically view content in Eclipse plugin view

I'm developing Eclipse plugin that has a treeview with toolbar and buttons. I'd want to make the plugin work so that it would show the treeview as default but in case of some error there would be some text and button to initialize or update the plugin. The plugin view should change dynamically depending on the state of the plugin between the treeview and the "error view".
For now I'm creating the treeview instance and doing the other needed actions in createPartControl method to show the treeview right. How should I implement the dynamic view showing different kind of content in the plugin view? Is that possible at all?
Code of the createPartControlMethod:
public void createPartControl(Composite parent) {
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
drillDownAdapter = new DrillDownAdapter(viewer);
viewContentProvider = new ViewContentProvider();
viewer.setContentProvider(viewContentProvider);
viewer.setLabelProvider(new ViewLabelProvider());
viewer.setSorter(new NameSorter());
viewer.setInput(getViewSite());
viewer.expandToLevel(2);
// Create the help context id for the viewer's control
PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "my.plugin.viewer");
makeActions();
hookContextMenu();
hookDoubleClickAction();
contributeToActionBars();
setToolBarButtonsEnabled();
Simplest way would be to create a Composite with a StackLayout and two children instead:
private Composite container;
private TreeViewer viewer;
private Composite errorComposite;
private StackLayout layout;
public void createPartControl(Composite parent) {
container = new Composite(parent);
layout = new StackLayout();
viewer = new TreeViewer(container, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
... // setup viewer
errorComposite = new Composite(container, SWT.NONE);
... // setup error view
}

Editable SWT table

How to edit SWT table Values without Using Mouse Listeners?
Do the TableEditor snippets in the below link help?
SWT Snippets
The first example in the TableEditor section uses a SelectionListener on the table (unlike the second example which uses a MouseDown event you mentioned you don't want)
You could perhaps make use of the TraverseListener or KeyListener too to help you achieve what you want.
final int EDITABLECOLUMN = 1;
tblProvisionInfo.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
// Clean up any previous editor control
final TableEditor editor = new TableEditor(tblProvisionInfo);
// The editor must have the same size as the cell and must
// not be any smaller than 50 pixels.
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
editor.minimumWidth = 50;
Control oldEditor = editor.getEditor();
if (oldEditor != null)
oldEditor.dispose();
// Identify the selected row
TableItem item = (TableItem) e.item;
if (item == null)
return;
// The control that will be the editor must be a child of the
// Table
Text newEditor = new Text(tblProvisionInfo, SWT.NONE);
newEditor.setText(item.getText(EDITABLECOLUMN));
newEditor.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent me) {
Text text = (Text) editor.getEditor();
editor.getItem()
.setText(EDITABLECOLUMN, text.getText());
}
});
newEditor.selectAll();
newEditor.setFocus();
editor.setEditor(newEditor, item, EDITABLECOLUMN);
}
});
Here tblProvision is the name of your table. you can just now edit Your table by clicking on it. I have Declare EDITABLECOLUMN. this is the column that u want to edit.
If you can use JFace as well and not just pain SWT, have a look at the JFace Snippets, especially
Snippet036FocusBorderCellHighlighter - Demonstrates keyboard navigation by highlighting the currently selected cell with a focus border showing once more the flexibility of the new cell navigation support
Snippet034CellEditorPerRowNewAPI - Demonstrates different CellEditor-Types in one COLUMN with 3.3-API of JFace-Viewers
You can get or set the value of a item, for example:
Table table = new Table(parent, SWT.NONE);
TableItem item = new TableItem(table, SWT.NONE);
item.setText("My new Text");
I suggest you to us TableViewer, it is very powerful table which it you can use databinding very easy too.