Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2015-07-18 16:20:08 +0000
committerEike Stepper2015-07-18 16:20:08 +0000
commitff5870ad00d84b68cc99110c41f5aaf0a7621c72 (patch)
tree6d0c34198614829db521f1f188799834be856d49 /plugins/org.eclipse.emf.cdo.explorer
parent3469e7b87e0db45ceeef02d6d0c6310912989dda (diff)
downloadcdo-ff5870ad00d84b68cc99110c41f5aaf0a7621c72.tar.gz
cdo-ff5870ad00d84b68cc99110c41f5aaf0a7621c72.tar.xz
cdo-ff5870ad00d84b68cc99110c41f5aaf0a7621c72.zip
[458349] Consolidate UI - CheckoutDuplicateHandler
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=458349
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.explorer')
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/CDOExplorerManager.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/checkouts/CDOCheckout.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractManager.java33
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java26
4 files changed, 69 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/CDOExplorerManager.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/CDOExplorerManager.java
index 09df5a814f..e4b9f6ae29 100644
--- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/CDOExplorerManager.java
+++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/CDOExplorerManager.java
@@ -24,6 +24,11 @@ import org.eclipse.core.runtime.IAdaptable;
public interface CDOExplorerManager<T extends CDOExplorerElement> extends IContainer<T>, IAdaptable
{
/**
+ * @since 4.5
+ */
+ public String getUniqueLabel(String label);
+
+ /**
* @author Eike Stepper
*/
public interface ElementsChangedEvent extends IEvent
diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/checkouts/CDOCheckout.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/checkouts/CDOCheckout.java
index 3811506cfe..331ac787ec 100644
--- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/checkouts/CDOCheckout.java
+++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/checkouts/CDOCheckout.java
@@ -82,6 +82,11 @@ public interface CDOCheckout extends CDOExplorerElement, CDOTimeProvider, StateP
public void setRootID(CDOID rootID);
+ /**
+ * @since 4.5
+ */
+ public CDOCheckout duplicate();
+
public State getState();
public boolean isOpen();
diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractManager.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractManager.java
index a458b4c011..77be55c28c 100644
--- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractManager.java
+++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractManager.java
@@ -29,8 +29,12 @@ import org.eclipse.emf.ecore.EObject;
import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* @author Eike Stepper
@@ -38,6 +42,8 @@ import java.util.Properties;
public abstract class AbstractManager<T extends CDOExplorerElement> extends SetContainer<T>
implements CDOExplorerManager<T>
{
+ private static final Pattern LABEL_PATTERN = Pattern.compile("(.+?) *\\([0-9]+\\)");
+
private final File folder;
private final Map<String, T> elementMap = new HashMap<String, T>();
@@ -75,6 +81,33 @@ public abstract class AbstractManager<T extends CDOExplorerElement> extends SetC
return folder;
}
+ public String getUniqueLabel(String label)
+ {
+ Set<String> names = new HashSet<String>();
+
+ for (T element : getElements())
+ {
+ names.add(element.getLabel());
+ }
+
+ Matcher matcher = LABEL_PATTERN.matcher(label);
+ if (matcher.matches())
+ {
+ label = matcher.group(1);
+ }
+
+ for (int i = 1; i < Integer.MAX_VALUE; i++)
+ {
+ String name = i == 1 ? label : label + " (" + i + ")";
+ if (!names.contains(name))
+ {
+ return name;
+ }
+ }
+
+ throw new IllegalStateException("Too many elements");
+ }
+
public T getElement(String id)
{
return elementMap.get(id);
diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java
index 4f20591c09..fa6635c529 100644
--- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java
+++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchManager;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.explorer.CDOExplorerUtil;
import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
import org.eclipse.emf.cdo.explorer.repositories.CDORepository;
import org.eclipse.emf.cdo.internal.explorer.AbstractElement;
@@ -350,6 +351,31 @@ public abstract class CDOCheckoutImpl extends AbstractElement implements CDOChec
this.rootID = rootID;
}
+ public CDOCheckout duplicate()
+ {
+ Properties properties = new Properties();
+ collectDuplicationProperties(properties);
+
+ CDOCheckout copy = CDOExplorerUtil.getCheckoutManager().addCheckout(properties);
+ if (isOpen())
+ {
+ copy.open();
+ }
+
+ return copy;
+ }
+
+ protected void collectDuplicationProperties(Properties properties)
+ {
+ properties.setProperty(PROP_TYPE, getType());
+ properties.setProperty(PROP_LABEL, getManager().getUniqueLabel(getLabel()));
+ properties.setProperty(PROP_REPOSITORY, getRepository().getID());
+ properties.setProperty(PROP_BRANCH_ID, Integer.toString(getBranchID()));
+ properties.setProperty(PROP_TIME_STAMP, Long.toString(getTimeStamp()));
+ properties.setProperty(PROP_READ_ONLY, Boolean.toString(isReadOnly()));
+ properties.setProperty(PROP_ROOT_ID, getCDOIDString(getRootID()));
+ }
+
public final State getState()
{
return state;

Back to the top