Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/ICUStringCollator.java63
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringCollator.java42
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbProjectPropertiesPage.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/MappedByPane.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java10
5 files changed, 94 insertions, 43 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/ICUStringCollator.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/ICUStringCollator.java
new file mode 100644
index 0000000000..555fa43caf
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/ICUStringCollator.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Oracle. 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:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.core.internal.utility;
+
+import java.util.Comparator;
+import java.util.Locale;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import com.ibm.icu.text.Collator;
+
+/**
+ * This collator simply wraps an ICU4J collator and implements a
+ * {@link String} {@link Comparator} (instead of an {@link Object}
+ * {@link Comparator}, which is what {@link Collator} does, mimicking the
+ * JDK(?)).
+ *
+ * @see Collator
+ */
+public class ICUStringCollator
+ implements Comparator<String>
+{
+ private final Collator collator;
+
+
+ /**
+ * Wrap the default collator.
+ * @see Collator#getInstance()
+ */
+ public ICUStringCollator() {
+ this(Collator.getInstance());
+ }
+
+ /**
+ * Wrap the collator for the specified locale.
+ * @see Collator#getInstance(Locale)
+ */
+ public ICUStringCollator(Locale locale) {
+ this(Collator.getInstance(locale));
+ }
+
+ /**
+ * Wrap the specified collator.
+ */
+ public ICUStringCollator(Collator collator) {
+ super();
+ this.collator = collator;
+ }
+
+ public int compare(String string1, String string2) {
+ return this.collator.compare(string1, string2);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.collator);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringCollator.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringCollator.java
index 2949b78748..eefb0b0a33 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringCollator.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringCollator.java
@@ -9,50 +9,54 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.internal;
-import java.io.Serializable;
import java.text.Collator;
import java.util.Comparator;
+import java.util.Locale;
/**
- * This collator simply wraps the default Java collator and implements a
+ * This collator simply wraps a Java text collator and implements a
* {@link String} {@link Comparator} (instead of an {@link Object}
* {@link Comparator}, which is what {@link Collator} does, possibly for
* backward-compatibility reasons(?)).
*
- * @see Collator#getInstance()
+ * @see Collator
*/
public class StringCollator
- implements Comparator<String>, Serializable
+ implements Comparator<String>
{
- // singleton
- private static final StringCollator INSTANCE = new StringCollator();
+ private final Collator collator;
+
/**
- * Return the singleton.
+ * Wrap the default collator.
+ * @see Collator#getInstance()
*/
- public static Comparator<String> instance() {
- return INSTANCE;
+ public StringCollator() {
+ this(Collator.getInstance());
}
/**
- * Ensure single instance.
+ * Wrap the collator for the specified locale.
+ * @see Collator#getInstance(Locale)
*/
- private StringCollator() {
+ public StringCollator(Locale locale) {
+ this(Collator.getInstance(locale));
+ }
+
+ /**
+ * Wrap the specified collator.
+ */
+ public StringCollator(Collator collator) {
super();
+ this.collator = collator;
}
public int compare(String string1, String string2) {
- return Collator.getInstance().compare(string1, string2);
+ return this.collator.compare(string1, string2);
}
@Override
public String toString() {
- return this.getClass().getSimpleName();
- }
-
- private static final long serialVersionUID = 1L;
- private Object readResolve() {
- // replace this object with the singleton
- return INSTANCE;
+ return StringTools.buildToStringFor(this, this.collator);
}
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbProjectPropertiesPage.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbProjectPropertiesPage.java
index 5f4da1f944..d9471eee5b 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbProjectPropertiesPage.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbProjectPropertiesPage.java
@@ -15,6 +15,7 @@ import java.util.Comparator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jpt.common.core.internal.utility.ICUStringCollator;
import org.eclipse.jpt.common.ui.internal.properties.JptProjectPropertiesPage;
import org.eclipse.jpt.common.ui.internal.utility.swt.SWTTools;
import org.eclipse.jpt.common.utility.internal.StringConverter;
@@ -49,7 +50,6 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
-import com.ibm.icu.text.Collator;
/**
* Way more complicated UI than you would think....
@@ -64,11 +64,7 @@ public class JaxbProjectPropertiesPage
private BufferedWritablePropertyValueModel<JaxbPlatformDescription> platformModel;
private PropertyChangeListener platformListener;
- /* private */ static final Comparator<String> STRING_COMPARATOR = new Comparator<String>() {
- public int compare(String string1, String string2){
- return Collator.getInstance().compare(string1, string2);
- }
- };
+ /* private */ static final Comparator<String> STRING_COMPARATOR = new ICUStringCollator();
// ************ construction ************
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/MappedByPane.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/MappedByPane.java
index e349e72384..913fb2dfa2 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/MappedByPane.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/MappedByPane.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2011 Oracle. 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.
@@ -9,9 +9,8 @@
******************************************************************************/
package org.eclipse.jpt.jpa.ui.internal.details;
-import java.util.Comparator;
import java.util.Iterator;
-
+import org.eclipse.jpt.common.core.internal.utility.ICUStringCollator;
import org.eclipse.jpt.common.ui.internal.widgets.Pane;
import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter;
@@ -23,8 +22,6 @@ import org.eclipse.jpt.jpa.core.context.MappedByRelationshipStrategy;
import org.eclipse.jpt.jpa.ui.internal.JpaHelpContextIds;
import org.eclipse.swt.widgets.Composite;
-import com.ibm.icu.text.Collator;
-
/**
* Here the layout of this pane:
* <pre>
@@ -34,7 +31,6 @@ import com.ibm.icu.text.Collator;
* | -------------------------------------------------------------- |
* -----------------------------------------------------------------------------</pre>
*
- * @see NonOwningMapping
* @see ManyToManyMappingComposite - A container of this pane
* @see OneToManyMappingComposite - A container of this pane
* @see OneToOneMappingComposite - A container of this pane
@@ -79,11 +75,7 @@ public class MappedByPane
return this.subject.candidateMappedByAttributeNames();
}
},
- new Comparator<String>() {
- public int compare(String string1, String string2){
- return Collator.getInstance().compare(string1, string2);
- }
- }
+ new ICUStringCollator()
);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java
index c6454aac56..201b8e1df5 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2011 Oracle. 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.
@@ -23,6 +23,7 @@ import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaElementDelta;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jpt.common.core.internal.utility.ICUStringCollator;
import org.eclipse.jpt.common.ui.internal.listeners.SWTPropertyChangeListenerWrapper;
import org.eclipse.jpt.common.ui.internal.properties.JptProjectPropertiesPage;
import org.eclipse.jpt.common.ui.internal.util.SWTUtil;
@@ -102,7 +103,6 @@ import org.eclipse.swt.widgets.Link;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
-import com.ibm.icu.text.Collator;
/**
* Way more complicated UI than you would think....
@@ -143,11 +143,7 @@ public class JpaProjectPropertiesPage
private static final String BUILD_PATHS_PROPERTY_PAGE_ID = "org.eclipse.jdt.ui.propertyPages.BuildPathsPropertyPage"; //$NON-NLS-1$
- /* private */ static final Comparator<String> STRING_COMPARATOR = new Comparator<String>() {
- public int compare(String string1, String string2){
- return Collator.getInstance().compare(string1, string2);
- }
- };
+ /* private */ static final Comparator<String> STRING_COMPARATOR = new ICUStringCollator();
// ************ construction ************

Back to the top