Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/emf/org.eclipse.papyrus.infra.emf.types/src/org/eclipse/papyrus/infra/emf/types/converter/ObjectToIntegerConverter.java')
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.types/src/org/eclipse/papyrus/infra/emf/types/converter/ObjectToIntegerConverter.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.types/src/org/eclipse/papyrus/infra/emf/types/converter/ObjectToIntegerConverter.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.types/src/org/eclipse/papyrus/infra/emf/types/converter/ObjectToIntegerConverter.java
new file mode 100644
index 00000000000..2f0c6261b16
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.types/src/org/eclipse/papyrus/infra/emf/types/converter/ObjectToIntegerConverter.java
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.types.converter;
+
+import org.eclipse.core.databinding.conversion.Converter;
+import org.eclipse.core.databinding.conversion.IConverter;
+
+/**
+ * Converter from an object to an integer
+ */
+public class ObjectToIntegerConverter extends Converter implements IConverter {
+
+ /**
+ * Default constructor.
+ */
+ public ObjectToIntegerConverter() {
+ super(Object.class, Integer.class);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Integer convert(Object fromObject) {
+ if(fromObject == null) {
+ return null;
+ }
+
+ if(fromObject instanceof Integer) {
+ return (Integer)fromObject;
+ }
+
+ if(fromObject instanceof String) {
+ return Integer.parseInt((String)fromObject);
+ }
+
+ return null;
+ }
+
+}

Back to the top