summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkwilk2012-04-02 11:36:32 (EDT)
committerRoberto E. Escobar2012-04-02 11:36:32 (EDT)
commit622303469a1b462632d14ca257b2875649c3debf (patch)
tree132f832633d57529176641694931963a184ff821
parent622cbe83bacf2bbc7330226c20811184f9e771e1 (diff)
downloadorg.eclipse.osee-622303469a1b462632d14ca257b2875649c3debf.zip
org.eclipse.osee-622303469a1b462632d14ca257b2875649c3debf.tar.gz
org.eclipse.osee-622303469a1b462632d14ca257b2875649c3debf.tar.bz2
refactor: Replace changes
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ArtifactChange.java6
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/AttributeChange.java10
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/AttributeChangeWorker.java1
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/Change.java2
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ChangeWorkerUtil.java33
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ErrorChange.java5
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/RelationChange.java9
-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
10 files changed, 99 insertions, 129 deletions
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ArtifactChange.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ArtifactChange.java
index 6ac0fbc..bc26cc4 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ArtifactChange.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ArtifactChange.java
@@ -21,6 +21,7 @@ import org.eclipse.osee.framework.skynet.core.revision.LoadChangeType;
*/
public final class ArtifactChange extends Change {
private static LoadChangeType changeType = LoadChangeType.artifact;
+ private static Class<ArtifactChangeWorker> worker = ArtifactChangeWorker.class;
public ArtifactChange(IOseeBranch branch, long sourceGamma, int artId, TransactionDelta txDelta, ModificationType modType, boolean isHistorical, Artifact changeArtifact, ArtifactDelta artifactDelta) {
super(branch, sourceGamma, artId, txDelta, modType, isHistorical, changeArtifact, artifactDelta);
@@ -65,4 +66,9 @@ public final class ArtifactChange extends Change {
public LoadChangeType getChangeType() {
return changeType;
}
+
+ @Override
+ public Class<? extends IChangeWorker> getWorker() {
+ return worker;
+ }
}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/AttributeChange.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/AttributeChange.java
index 01f6fb2..b847d14 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/AttributeChange.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/AttributeChange.java
@@ -13,6 +13,7 @@ package org.eclipse.osee.framework.skynet.core.change;
import java.util.List;
import java.util.logging.Level;
+
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.exception.AttributeDoesNotExist;
@@ -29,12 +30,14 @@ import org.eclipse.osee.framework.skynet.core.revision.LoadChangeType;
* @author Jeff C. Phillips
*/
public final class AttributeChange extends Change {
+ private final static LoadChangeType changeType = LoadChangeType.attribute;
+ private final static Class<AttributeChangeWorker> worker = AttributeChangeWorker.class;
+
private final String isValue;
private final String wasValue;
private final int attrId;
private final AttributeType attributeType;
private final ModificationType artModType;
- public static LoadChangeType changeType = LoadChangeType.attribute;
public AttributeChange(IOseeBranch branch, long sourceGamma, int artId, TransactionDelta txDelta, ModificationType modType, String isValue, String wasValue, int attrId, AttributeType attributeType, ModificationType artModType, boolean isHistorical, Artifact changeArtifact, ArtifactDelta artifactDelta) {
super(branch, sourceGamma, artId, txDelta, modType, isHistorical, changeArtifact, artifactDelta);
@@ -145,4 +148,9 @@ public final class AttributeChange extends Change {
public LoadChangeType getChangeType() {
return changeType;
}
+
+ @Override
+ public Class<? extends IChangeWorker> getWorker() {
+ return worker;
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/AttributeChangeWorker.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/AttributeChangeWorker.java
index 96fb719..8469a2e 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/AttributeChangeWorker.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/AttributeChangeWorker.java
@@ -35,5 +35,4 @@ public class AttributeChangeWorker implements IChangeWorker {
artifact.getAttributeById(change.getItemId(), true).delete();
}
}
-
}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/Change.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/Change.java
index 7904d7f..162f3e5 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/Change.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/Change.java
@@ -161,6 +161,8 @@ public abstract class Change implements IAdaptable, Comparable<Change>, HasBranc
public abstract LoadChangeType getChangeType();
+ public abstract Class<? extends IChangeWorker> getWorker();
+
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Class adapter) {
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ChangeWorkerUtil.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ChangeWorkerUtil.java
deleted file mode 100644
index fe2fda3..0000000
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ChangeWorkerUtil.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 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.change;
-
-import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
-
-public class ChangeWorkerUtil {
-
- public static IChangeWorker create(Change change, Artifact artifact) {
- IChangeWorker changeWorker = null;
-
- switch (change.getChangeType()) {
- case artifact:
- changeWorker = new ArtifactChangeWorker(change, artifact);
- break;
- case attribute:
- changeWorker = new AttributeChangeWorker(change, artifact);
- break;
- case relation:
- changeWorker = new RelationChangeWorker(change, artifact);
- break;
- }
- return changeWorker;
- }
-}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ErrorChange.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ErrorChange.java
index 1874ba2..4525901 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ErrorChange.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/ErrorChange.java
@@ -76,4 +76,9 @@ public final class ErrorChange extends Change {
return null;
}
+ @Override
+ public Class<? extends IChangeWorker> getWorker() {
+ return null;
+ }
+
}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/RelationChange.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/RelationChange.java
index edf7812..0552731 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/RelationChange.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/change/RelationChange.java
@@ -22,7 +22,9 @@ import org.eclipse.osee.framework.skynet.core.revision.LoadChangeType;
* @author Jeff C. Phillips
*/
public final class RelationChange extends Change {
- public static LoadChangeType changeType = LoadChangeType.relation;
+ private final static LoadChangeType changeType = LoadChangeType.relation;
+ private final static Class<RelationChangeWorker> worker = RelationChangeWorker.class;
+
private final int bArtId;
private final Artifact endTxBArtifact;
private final int relLinkId;
@@ -109,4 +111,9 @@ public final class RelationChange extends Change {
public int getItemId() {
return relLinkId;
}
+
+ @Override
+ public Class<? extends IChangeWorker> getWorker() {
+ return worker;
+ }
}
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 1793e7b..21557ff 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 ed58e31..8551cb3 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 219400c..9db3aac 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;
}
}