How to get RTC Component name from ProjectExplorer view
Hi,
Im using RTC Eclipse Client v3.0.1.
I have loaded a Java project from RTC Server repository to my Eclipse Workspace. Now in projectExploer view, I can the RTC Component added to the project name as shown below:
<ProjectName> ( <RTC Repository> - <RTC Component>)
Can you let me know how to get the RTC component from ProjectExplorer view of a particular project programmatically.
Thanks and Regards
Suri
One answer
I had the same requirement and here is what i did to get them.
Step 1: get the project explorer view part from that get the selection provider
Step 2: Get the tree from the selection provider and get the appropriate project that you need. All the projects will be a first level leaf in this tree.
Step 3: Get the TreeItem of the project on which you need to get the rtc component from.
(TreeItem can be got either by getSelection or by searching the each treeitem for the project of your concern.
Step 4: Once the required tree item found, get the Text from the tree item and split the text. and get your rtc component name.
Code snippet for your help:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IWorkbenchPart viewpart = page.findView("org.eclipse.ui.navigator.ProjectExplorer");
Tree tree = (Tree) ((TreeViewer) part.getSite().getSelectionProvider()).getControl();
TreeItem[] selTree = tree.getSelection();
choose the tree item that you need.
String decoratedName = treeItem.getText().split(" ");
String[] temp = decoratedName.split(" ");
if (temp.length < 2 || null == temp[1]) {
return null;
}
String ComponentName = temp[2].trim().replace(")", "");
(no exception handling shown above, please take care)
Hope this help.
Comments
David Lafreniere
FORUM MODERATOR / JAZZ DEVELOPER Dec 02 '13, 3:54 p.m.Here's some ideas (I have not tested this yet however).
Items in the package explorer are of type "org.eclipse.core.resources.IResource". (ex: IProject, IFolder, IFile)
If using the RTC SDK, you can try:
String componentName = null;
IResource resource = <get me from a node in the Package Explorer>
IShareable shareable = (IShareable) resource.getAdapter(IShareable.class);
if (shareable != null) {
IShare share = shareable.getShare(new NullProgressMonitor());
if (share != null) {
componentName = share.getSharingDescriptor().getComponentName();
}
}