From ea7b408e3b9ef18aef0130a393b96773c7815f18 Mon Sep 17 00:00:00 2001 From: donald.g.dunne Date: Mon, 21 Nov 2016 11:51:08 -0700 Subject: bug[ats_ATS325709]: Add load selection to Resource History Change-Id: Ib03f4682b6ffa80546eb7b7c447b4204ef622f35 --- .../skynet/core/revision/ChangeManager.java | 5 ++ .../skynet/core/revision/RevisionChangeLoader.java | 28 +++++++++ .../core/transaction/TransactionIdComparator.java | 32 +++++++++++ .../ui/skynet/widgets/xHistory/XHistoryWidget.java | 67 +++++++++++++++++++++- 4 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionIdComparator.java diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ChangeManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ChangeManager.java index 9d4d39ee93b..dd108ba3ea1 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ChangeManager.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ChangeManager.java @@ -69,6 +69,10 @@ public final class ChangeManager { return revsionChangeLoader.getChangesPerArtifact(artifact, monitor, loadChangeTypes); } + public static Collection getChangesPerArtifact(Artifact artifact, int numberTransactionsToShow, IProgressMonitor monitor) { + return revsionChangeLoader.getChangesPerArtifact(artifact, numberTransactionsToShow, monitor); + } + /** * Acquires artifact, relation and attribute changes from a source branch since its creation. */ @@ -184,4 +188,5 @@ public final class ChangeManager { } return branchMap; } + } \ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/RevisionChangeLoader.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/RevisionChangeLoader.java index 9096fb2a18f..4f9bab6110a 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/RevisionChangeLoader.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/RevisionChangeLoader.java @@ -12,6 +12,7 @@ package org.eclipse.osee.framework.skynet.core.revision; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; @@ -48,6 +49,7 @@ import org.eclipse.osee.framework.skynet.core.internal.ServiceUtil; import org.eclipse.osee.framework.skynet.core.revision.acquirer.ArtifactChangeAcquirer; import org.eclipse.osee.framework.skynet.core.revision.acquirer.AttributeChangeAcquirer; import org.eclipse.osee.framework.skynet.core.revision.acquirer.RelationChangeAcquirer; +import org.eclipse.osee.framework.skynet.core.transaction.TransactionIdComparator; import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager; import org.eclipse.osee.framework.skynet.core.utility.ConnectionHandler; import org.eclipse.osee.jdbc.JdbcStatement; @@ -89,6 +91,31 @@ public final class RevisionChangeLoader { return changes; } + public Collection getChangesPerArtifact(Artifact artifact, int numberTransactionsToShow, IProgressMonitor monitor) { + BranchId branch = artifact.getBranch(); + Set transactionIds = new LinkedHashSet<>(); + boolean recurseThroughBranchHierarchy = true; + loadBranchTransactions(branch, artifact, transactionIds, TransactionManager.getHeadTransaction(branch), + recurseThroughBranchHierarchy); + + Collection changes = new ArrayList<>(); + List sortedTransIds = new ArrayList<>(); + sortedTransIds.addAll(transactionIds); + Collections.sort(sortedTransIds, new TransactionIdComparator()); + Collections.reverse(sortedTransIds); + + int count = 0; + for (TransactionToken transactionId : sortedTransIds) { + loadChanges(null, transactionId, monitor, artifact, changes, LoadChangeType.artifact, LoadChangeType.attribute, + LoadChangeType.relation); + count++; + if (count >= numberTransactionsToShow) { + break; + } + } + return changes; + } + private void loadBranchTransactions(BranchId branch, Artifact artifact, Set transactionIds, TransactionId transactionId, boolean recurseThroughBranchHierarchy) throws OseeCoreException { loadTransactions(branch, artifact, transactionId, transactionIds); @@ -237,4 +264,5 @@ public final class RevisionChangeLoader { } return changes; } + } \ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionIdComparator.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionIdComparator.java new file mode 100644 index 00000000000..e0cfcf7afff --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionIdComparator.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2016 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.skynet.core.transaction; + +import java.io.Serializable; +import java.util.Comparator; +import org.eclipse.osee.framework.core.data.TransactionId; + +/** + * @author Donald G. Dunne + */ +public class TransactionIdComparator implements Comparator, Serializable { + + private static final long serialVersionUID = 1L; + + public TransactionIdComparator() { + super(); + } + + @Override + public int compare(TransactionId trans1, TransactionId trans2) { + return trans1.getId().compareTo(trans2.getId()); + } +} \ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/xHistory/XHistoryWidget.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/xHistory/XHistoryWidget.java index d927f777cba..9a5ffafc532 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/xHistory/XHistoryWidget.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/xHistory/XHistoryWidget.java @@ -71,13 +71,14 @@ public class XHistoryWidget extends GenericXWidget { private HistoryXViewer xHistoryViewer; public final static String normalColor = "#EEEEEE"; - private static final String LOADING = "Loading ..."; private static final String NO_HISTORY = "No History changes were found"; protected Label extraInfoLabel; private Artifact artifact; private ToolBar toolBar; private Composite rightComp; private final Set shadedTransactions = new HashSet<>(); + private int numberTransactionsToShow = 25; + private ToolItem show25Item, show75Item, showAllItem, show50Item; public XHistoryWidget() { super("History"); @@ -184,6 +185,63 @@ public class XHistoryWidget extends GenericXWidget { } }); + show25Item = new ToolItem(toolBar, SWT.RADIO | SWT.BORDER); + show25Item.setText(" 25"); + show25Item.setToolTipText("Show last 25 transactions."); + show25Item.setSelection(true); + show25Item.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + numberTransactionsToShow = 25; + show25Item.setSelection(true); + show50Item.setSelection(false); + show75Item.setSelection(false); + showAllItem.setSelection(false); + } + }); + + show50Item = new ToolItem(toolBar, SWT.RADIO | SWT.BORDER); + show50Item.setText(" 50"); + show50Item.setToolTipText("Show last 50 transactions."); + show50Item.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + numberTransactionsToShow = 50; + show25Item.setSelection(false); + show50Item.setSelection(true); + show75Item.setSelection(false); + showAllItem.setSelection(false); + } + }); + + show75Item = new ToolItem(toolBar, SWT.RADIO | SWT.BORDER); + show75Item.setText(" 75"); + show75Item.setToolTipText("Show last 75 transactions."); + show75Item.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + numberTransactionsToShow = 75; + show25Item.setSelection(false); + show50Item.setSelection(false); + show75Item.setSelection(true); + showAllItem.setSelection(false); + } + }); + + showAllItem = new ToolItem(toolBar, SWT.RADIO | SWT.BORDER); + showAllItem.setText(" All"); + showAllItem.setToolTipText("Show All transactions."); + showAllItem.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + numberTransactionsToShow = Integer.MAX_VALUE; + show25Item.setSelection(false); + show50Item.setSelection(false); + show75Item.setSelection(false); + showAllItem.setSelection(true); + } + }); + new ActionContributionItem(xHistoryViewer.getCustomizeAction()).fill(toolBar, -1); rightComp.layout(); @@ -257,7 +315,10 @@ public class XHistoryWidget extends GenericXWidget { public void setInputData(final Artifact artifact, final boolean loadHistory) { this.artifact = artifact; - extraInfoLabel.setText(LOADING); + extraInfoLabel.setText(String.format("Loading %d Transactions...", + (numberTransactionsToShow == Integer.MAX_VALUE ? "All" : numberTransactionsToShow))); + + final int fNumnberTransactionsToShow = numberTransactionsToShow; Job job = new Job("History: " + artifact.getName()) { @@ -267,7 +328,7 @@ public class XHistoryWidget extends GenericXWidget { try { if (loadHistory) { - changes.addAll(ChangeManager.getChangesPerArtifact(artifact, monitor)); + changes.addAll(ChangeManager.getChangesPerArtifact(artifact, fNumnberTransactionsToShow, monitor)); } Displays.ensureInDisplayThread(new Runnable() { -- cgit v1.2.3