@Override public Object executeWithException(ExecutionEvent event, IStructuredSelection selection) throws OseeCoreException { Branch selectedBranch = Handlers.getBranchesFromStructuredSelection(selection).iterator().next(); EntryDialog ed = new EntryDialog( "Set Associated Artifact", "Set Associated Artifact for Branch\n\n\"" + selectedBranch.getName() + "\"" + (selectedBranch.getAssociatedArtifactId() != null ? "\n\nCurrently: " + selectedBranch.getAssociatedArtifactId() : "") + "\n\nEnter new Artifact Id to associate:"); ed.setEntry(String.valueOf(selectedBranch.getAssociatedArtifactId())); if (ed.open() == 0) { String artId = ed.getEntry(); Artifact associatedArtifact = ArtifactQuery.getArtifactFromId(Integer.parseInt(artId), BranchManager.getCommonBranch()); if (MessageDialog.openConfirm( Displays.getActiveShell(), "Set Associated Artifact", "Set Associated Artifact for Branch\n\n\"" + selectedBranch.getName() + "\"\nto\nArtifact: " + associatedArtifact)) { selectedBranch.setAssociatedArtifactId(Integer.parseInt(artId)); BranchManager.persist(selectedBranch); } } return null; }
public Collection<Branch> updateCache( AbstractBranchCacheMessage cacheMessage, IOseeCache<String, Branch> cache) throws OseeCoreException { List<Branch> updatedItems = new ArrayList<Branch>(); Map<Integer, Integer> branchToAssocArt = cacheMessage.getBranchToAssocArt(); preLoadTransactions(cacheMessage); for (BranchRow srcItem : cacheMessage.getBranchRows()) { int branchId = srcItem.getBranchId(); Branch updated = factory.createOrUpdate( cache, srcItem.getBranchId(), srcItem.getStorageState(), srcItem.getBranchGuid(), srcItem.getBranchName(), srcItem.getBranchType(), srcItem.getBranchState(), srcItem.getBranchArchived().isArchived()); updatedItems.add(updated); Integer artifactId = branchToAssocArt.get(branchId); if (artifactId != null) { updated.setAssociatedArtifactId(artifactId); } updated.setBaseTransaction(getTx(cacheMessage.getBranchToBaseTx(), branchId)); updated.setSourceTransaction(getTx(cacheMessage.getBranchToSourceTx(), branchId)); } for (Entry<Integer, Integer> entry : cacheMessage.getChildToParent().entrySet()) { Branch parent = cache.getById(entry.getValue()); if (parent != null) { Branch child = cache.getById(entry.getKey()); if (child != null) { child.setParentBranch(parent); } } } for (Triplet<String, String, String> entry : cacheMessage.getMergeBranches()) { IOseeBranch sourceBranch = Strings.isValid(entry.getFirst()) ? cache.getByGuid(entry.getFirst()) : null; IOseeBranch destinationBranch = Strings.isValid(entry.getSecond()) ? cache.getByGuid(entry.getSecond()) : null; Branch branch = cache.getByGuid(entry.getThird()); MergeBranch mergeBranch = null; try { mergeBranch = (MergeBranch) branch; mergeBranch.setSourceBranch(sourceBranch); mergeBranch.setDestinationBranch(destinationBranch); } catch (ClassCastException ex) { throw new OseeCoreException( ex, "Problem casting branch [%s] to MergeBranch, source: [%s], dest: [%s]", branch, sourceBranch, destinationBranch); } } return updatedItems; }