Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee')
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ReplaceArtifactWithBaselineOperation.java19
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ReplaceAttributeWithBaselineOperation.java17
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/commandHandlers/ReplaceWithBaselineHandler.java126
3 files changed, 69 insertions, 93 deletions
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ReplaceArtifactWithBaselineOperation.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ReplaceArtifactWithBaselineOperation.java
index 1793e7b3692..21557ffe4bb 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ReplaceArtifactWithBaselineOperation.java
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ReplaceArtifactWithBaselineOperation.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.osee.framework.ui.skynet.blam.operation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -19,7 +21,6 @@ import org.eclipse.osee.framework.core.operation.AbstractOperation;
import org.eclipse.osee.framework.core.util.Conditions;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.change.Change;
-import org.eclipse.osee.framework.skynet.core.change.ChangeWorkerUtil;
import org.eclipse.osee.framework.skynet.core.change.IChangeWorker;
import org.eclipse.osee.framework.skynet.core.change.RelationChange;
import org.eclipse.osee.framework.skynet.core.revision.LoadChangeType;
@@ -47,7 +48,6 @@ public class ReplaceArtifactWithBaselineOperation extends AbstractOperation {
if (!monitor.isCanceled() && Conditions.notNull(changeReportChanges, artifacts)) {
monitor.beginTask("Reverting artifact(s)", artifacts.size());
if (!artifacts.isEmpty()) {
-
Artifact firstArtifact = artifacts.iterator().next();
SkynetTransaction transaction =
TransactionManager.createTransaction(firstArtifact.getBranch(),
@@ -55,18 +55,19 @@ public class ReplaceArtifactWithBaselineOperation extends AbstractOperation {
for (Artifact artifact : artifacts) {
monitor.subTask("Reverting: " + artifact.getName());
- monitor.worked(1 / artifacts.size());
+ monitor.worked(1);
Collection<Change> changes = getArtifactSpecificChanges(artifact.getArtId(), changeReportChanges);
revertArtifact(artifact, changes);
artifact.persist(transaction);
+ monitor.done();
}
monitor.subTask(String.format("Persisting %s artifact(s)", artifacts.size()));
transaction.execute();
persistAndReloadArtifacts();
- monitor.done();
}
+ monitor.done();
}
}
@@ -103,10 +104,12 @@ public class ReplaceArtifactWithBaselineOperation extends AbstractOperation {
}
}
- private void revertArtifact(Artifact artifact, Collection<Change> changes) throws OseeStateException, OseeCoreException {
- for (Change change : changes) {
- IChangeWorker changeWorker = ChangeWorkerUtil.create(change, artifact);
- changeWorker.revert();
+ private void revertArtifact(Artifact artifact, Collection<Change> changes) throws OseeStateException, OseeCoreException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
+ for (Change change : changes) {
+ Class<? extends IChangeWorker> workerClass = change.getWorker();
+ Constructor<?> ctor = workerClass.getConstructor(Change.class, Artifact.class);
+ IChangeWorker worker = (IChangeWorker) ctor.newInstance(change, artifact);
+ worker.revert();
}
}
}
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ReplaceAttributeWithBaselineOperation.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ReplaceAttributeWithBaselineOperation.java
index ed58e31f6bd..8551cb356de 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ReplaceAttributeWithBaselineOperation.java
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ReplaceAttributeWithBaselineOperation.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.osee.framework.ui.skynet.blam.operation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@@ -22,7 +24,6 @@ import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.Attribute;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.framework.skynet.core.change.Change;
-import org.eclipse.osee.framework.skynet.core.change.ChangeWorkerUtil;
import org.eclipse.osee.framework.skynet.core.change.IChangeWorker;
import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager;
@@ -54,11 +55,12 @@ public class ReplaceAttributeWithBaselineOperation extends AbstractOperation {
for (Change change : changes) {
monitor.subTask("Reverting: " + changes.toString());
- monitor.worked(1 / changes.size());
+ monitor.worked(1);
Artifact artifact = ArtifactQuery.getArtifactFromId(change.getArtId(), change.getBranch());
revertAttribute(artifact, change);
artifactHistory.add(artifact);
artifact.persist(transaction);
+ monitor.done();
}
transaction.execute();
@@ -73,14 +75,13 @@ public class ReplaceAttributeWithBaselineOperation extends AbstractOperation {
}
}
- private void revertAttribute(Artifact artifact, Change change) throws OseeStateException, OseeCoreException {
+ private void revertAttribute(Artifact artifact, Change change) throws OseeStateException, OseeCoreException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
Attribute<?> attribute = artifact.getAttributeById(change.getItemId(), true);
if (attribute != null && change.getItemId() == attribute.getId()) {
- IChangeWorker changeWorker = ChangeWorkerUtil.create(change, artifact);
- if (changeWorker != null) {
- changeWorker.revert();
- }
+ Class<? extends IChangeWorker> workerClass = change.getWorker();
+ Constructor<?> ctor = workerClass.getConstructor(Change.class, Artifact.class);
+ IChangeWorker worker = (IChangeWorker) ctor.newInstance(change, artifact);
+ worker.revert();
}
}
-
}
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/commandHandlers/ReplaceWithBaselineHandler.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/commandHandlers/ReplaceWithBaselineHandler.java
index 219400c61bc..9db3aac0069 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/commandHandlers/ReplaceWithBaselineHandler.java
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/commandHandlers/ReplaceWithBaselineHandler.java
@@ -13,6 +13,7 @@ package org.eclipse.osee.framework.ui.skynet.commandHandlers;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
+import java.util.logging.Level;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
@@ -21,7 +22,6 @@ import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.osee.framework.access.AccessControlManager;
@@ -32,25 +32,20 @@ import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
-import org.eclipse.osee.framework.skynet.core.artifact.Attribute;
-import org.eclipse.osee.framework.skynet.core.change.AttributeChange;
import org.eclipse.osee.framework.skynet.core.change.Change;
import org.eclipse.osee.framework.skynet.core.revision.LoadChangeType;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.skynet.blam.operation.ReplaceArtifactWithBaselineOperation;
import org.eclipse.osee.framework.ui.skynet.blam.operation.ReplaceAttributeWithBaselineOperation;
-import org.eclipse.osee.framework.ui.skynet.change.view.ChangeReportEditor;
import org.eclipse.osee.framework.ui.skynet.internal.Activator;
import org.eclipse.osee.framework.ui.skynet.replace.ReplaceWithBaselineVersionDialog;
import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.PlatformUI;
/**
* @author Paul K. Waldfogel
* @author Jeff C. Phillips
+ * @author Karol Wilk
*/
public class ReplaceWithBaselineHandler extends AbstractHandler {
private Collection<Change> changes;
@@ -72,23 +67,24 @@ public class ReplaceWithBaselineHandler extends AbstractHandler {
setSelectedData();
LoadChangeType lastChangeType = null;
+ changes = Handlers.getArtifactChangesFromStructuredSelection(structuredSelection);
+ // Only use the item selected for accessControl
+ if (structuredSelection != null) {
+ for (Change change : changes) {
+ if (lastChangeType == null) {
+ lastChangeType = change.getChangeType();
+ }
+ isEnabled = lastChangeType == change.getChangeType();
- //Only use the item selected for accessControl
- for (Change change : Handlers.getArtifactChangesFromStructuredSelection(structuredSelection)) {
-
- if (lastChangeType == null) {
- lastChangeType = change.getChangeType();
- }
- isEnabled = lastChangeType == change.getChangeType();
-
- try {
- isEnabled =
- isEnabled && AccessControlManager.hasPermission(change.getChangeArtifact(), PermissionEnum.WRITE);
- } catch (OseeCoreException ex) {
- OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, "Error loading changes for change report handler");
- }
- if (!isEnabled) {
- break;
+ try {
+ isEnabled =
+ isEnabled && AccessControlManager.hasPermission(change.getChangeArtifact(), PermissionEnum.WRITE);
+ } catch (OseeCoreException ex) {
+ OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, "Error when checking permisstions", ex);
+ }
+ if (!isEnabled) {
+ break;
+ }
}
}
return isEnabled;
@@ -97,43 +93,22 @@ public class ReplaceWithBaselineHandler extends AbstractHandler {
private void setSelectedData() {
IWorkbench workbench = PlatformUI.getWorkbench();
if (!workbench.isClosing() || !workbench.isStarting()) {
- IWorkbenchPage page = AWorkbench.getActivePage();
-
- if (page != null) {
- IWorkbenchPart part = page.getActivePart();
-
- if (part != null) {
- IWorkbenchSite site = part.getSite();
-
- if (part instanceof ChangeReportEditor) {
- ChangeReportEditor changeReportEditor = (ChangeReportEditor) part;
- changes = changeReportEditor.getChanges().getChanges();
- }
- if (site != null) {
-
- ISelectionProvider selectionProvider = site.getSelectionProvider();
- if (selectionProvider != null) {
- ISelection selection = selectionProvider.getSelection();
- if (selection instanceof IStructuredSelection) {
- structuredSelection = (IStructuredSelection) selection;
- }
- }
- }
- }
+ try {
+ ISelection selection =
+ AWorkbench.getActivePage().getActivePart().getSite().getSelectionProvider().getSelection();
+ structuredSelection = (IStructuredSelection) selection;
+ } catch (Exception e) {
+ structuredSelection = null;
+ OseeLog.log(Activator.class, Level.WARNING, "Could not obtain replace selection from UI", e);
}
}
}
- private boolean enableButtons(IStructuredSelection selection, LoadChangeType changeType) {
+ private boolean enableButtons(Collection<Change> changes, LoadChangeType changeType) {
boolean attrEnabled = false;
-
- Collection<Change> changes = Handlers.getArtifactChangesFromStructuredSelection(selection);
-
for (Change change : changes) {
- if (change.getChangeType() == changeType) {
- attrEnabled = true;
- } else {
- attrEnabled = false;
+ attrEnabled = change.getChangeType() == changeType;
+ if (!attrEnabled) {
break;
}
}
@@ -142,35 +117,32 @@ public class ReplaceWithBaselineHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
- try {
- Set<Artifact> duplicateArtCheck = new HashSet<Artifact>();
- Set<Attribute<?>> duplicateAttrCheck = new HashSet<Attribute<?>>();
+ if (structuredSelection != null) {
+ try {
+ boolean attrEnabled = enableButtons(changes, LoadChangeType.attribute);
+ boolean artEnabled = enableButtons(changes, LoadChangeType.artifact);
- for (Change change : changes) {
- Artifact changeArtifact = change.getChangeArtifact();
+ ReplaceWithBaselineVersionDialog dialog = new ReplaceWithBaselineVersionDialog(artEnabled, attrEnabled);
+ if (dialog.open() == Window.OK) {
+ IOperation op =
+ dialog.isAttributeSelected() ? new ReplaceAttributeWithBaselineOperation(changes) : new ReplaceArtifactWithBaselineOperation(
+ changes, removeDuplicateArtifacts());
- if (change instanceof AttributeChange) {
- duplicateAttrCheck.add(((AttributeChange) change).getAttribute());
+ Operations.executeAsJob(op, true, Job.LONG, adapter);
}
- duplicateArtCheck.add(changeArtifact);
+ } catch (Exception ex) {
+ throw new ExecutionException(ex.getMessage());
}
+ }
+ return null;
+ }
- boolean attrEnabled = enableButtons(structuredSelection, LoadChangeType.attribute);
- boolean artEnabled = enableButtons(structuredSelection, LoadChangeType.artifact);
-
- ReplaceWithBaselineVersionDialog dialog = new ReplaceWithBaselineVersionDialog(artEnabled, attrEnabled);
- if (dialog.open() == Window.OK) {
- IOperation op =
- dialog.isAttributeSelected() ? new ReplaceAttributeWithBaselineOperation(
- Handlers.getArtifactChangesFromStructuredSelection(structuredSelection)) : new ReplaceArtifactWithBaselineOperation(
- changes, Handlers.getArtifactsFromStructuredSelection(structuredSelection));
+ private Set<Artifact> removeDuplicateArtifacts() {
+ Set<Artifact> duplicateArtCheck = new HashSet<Artifact>();
- Operations.executeAsJob(op, true, Job.LONG, adapter);
- }
-
- } catch (Exception ex) {
- throw new ExecutionException(ex.getMessage());
+ for (Change change : changes) {
+ duplicateArtCheck.add(change.getChangeArtifact());
}
- return null;
+ return duplicateArtCheck;
}
}

Back to the top