It's all about the answers!

Ask a question

Rename Baseline in Plain Java API

Stephen Long (14311013) | asked May 12 '14, 9:09 a.m.

I want to rename a baseline (something that you can do via the client), but the IBaseline object does not seem to have a method that allows the name to be changed. 

Is this correct?  Is there another way of doing it?

   IWorkspaceManager workspaceManager = (IWorkspaceManager)repo.getClientLibrary(IWorkspaceManager.class);
   IComponentSearchCriteria compCrit = IComponentSearchCriteria.FACTORY.newInstance();
   List<IComponentHandle> components = workspaceManager.findComponents(compCrit,100,new SysoutProgressMonitor());
   IComponentHandle componentHandle = null;
   for (Iterator<IComponentHandle> ci = components.iterator(); ci.hasNext();) {
    componentHandle = (IComponentHandle);
    IComponent component_comp = (IComponent)repo.itemManager().fetchCompleteItem(componentHandle, IItemManager.DEFAULT, new SysoutProgressMonitor());
   IBaselineSearchCriteria crit1 = IBaselineSearchCriteria.FACTORY.newInstance();
   List<IBaselineHandle> baselines = workspaceManager.findBaselines(crit1,100,new SysoutProgressMonitor());
   for (Iterator<IBaselineHandle> bi = baselines.iterator(); bi.hasNext();) {
    IBaselineHandle baselineHandle = (IBaselineHandle);
    IBaseline baseline_comp = (IBaseline)repo.itemManager().fetchCompleteItem(baselineHandle, IItemManager.DEFAULT, new SysoutProgressMonitor());
    if (baseline_comp.getName().equals(oldBaseline)) {

sam detweiler commented May 12 '14, 9:21 a.m.

usually the I* interfaces has concrete classes behind them which hav the set....() methods.. usually the concrete classes are usually in 'internal' jar files.

so IBaseLine = Baseline.

Stephen Long commented May 12 '14, 11:19 a.m.


Thanks.  Seems I need to get a working copy of the object.  I can now call setName ok, but cannot see how to save the object back to the repository...

     Baseline theBaseline = (Baseline)baseline_comp.getWorkingCopy();

Accepted answer

permanent link
Tim Mok (6.6k38) | answered May 12 '14, 1:21 p.m.
You should go through IWorkspaceManager#getBaselineConnection(IBaselineHandle, IProgressMonitor) to get the baseline connection.

Then call IBaselineConnection#setName(String) to set the new name.
Stephen Long selected this answer as the correct answer

Stephen Long commented May 13 '14, 3:37 a.m. | edited May 13 '14, 3:38 a.m.

Thanks Tim. I figured this out last night by analysing the JavaDocs. 

Your answer

Register or to post your answer.