Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/adapters/ModelAdapterFactory.java')
-rw-r--r--plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/adapters/ModelAdapterFactory.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/adapters/ModelAdapterFactory.java b/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/adapters/ModelAdapterFactory.java
new file mode 100644
index 00000000000..3d90978cb8c
--- /dev/null
+++ b/plugins/infra/onefile/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/adapters/ModelAdapterFactory.java
@@ -0,0 +1,54 @@
+/*****************************************************************************
+ * Copyright (c) 2011, 2016 Atos Origin Integration, Christian W. Damus, and others.
+ *
+ * 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:
+ * Tristan Faure (Atos Origin Integration) tristan.faure@atosorigin.com - Initial API and implementation
+ * Christian W. Damus - bug 485220
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.onefile.model.adapters;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.mapping.ResourceMapping;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile;
+import org.eclipse.papyrus.infra.onefile.model.mapping.PapyrusResourceMapping;
+
+/**
+ * Adapter factory to adapt {@link IPapyrusFile}
+ *
+ * @author tristan.faure@atosorigin.com
+ */
+public class ModelAdapterFactory implements IAdapterFactory {
+
+ public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
+ if (ResourceMapping.class.equals(adapterType)) {
+ if (adaptableObject instanceof IPapyrusFile) {
+ return adapterType.cast(new PapyrusResourceMapping((IPapyrusFile) adaptableObject));
+ }
+ }
+ if (adapterType == IFile.class || adapterType == IResource.class) {
+ return adapterType.cast(((IPapyrusFile) adaptableObject).getMainFile());
+ }
+ if (Collection.class.equals(adapterType)) {
+ if (adaptableObject instanceof IPapyrusFile) {
+ return adapterType.cast(Arrays.asList(((IPapyrusFile) adaptableObject).getAssociatedResources()));
+ }
+ }
+ return null;
+ }
+
+ public Class<?>[] getAdapterList() {
+ return new Class[] { ResourceMapping.class, IFile.class, IResource.class, Collection.class };
+ }
+
+}

Back to the top