Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModelUtils.java')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModelUtils.java118
1 files changed, 118 insertions, 0 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModelUtils.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModelUtils.java
new file mode 100644
index 00000000000..47e8445b93c
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModelUtils.java
@@ -0,0 +1,118 @@
+/**
+ *
+ */
+package org.eclipse.papyrus.infra.core.resource.sasheditor;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.ModelUtils;
+import org.eclipse.papyrus.infra.core.resource.uml.UmlUtils;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
+
+/**
+ * Set of utility methods linked to Trace for ControlMode
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class SashModelUtils {
+
+ /**
+ * Gets the SashModel for the currently selected editor. <br>
+ * Warning: This method is designed to be call from ui.handlers. It is not
+ * designed to be call from Editors. This method can return null if called
+ * during the MultiEditor initialization.
+ *
+ * @see ServiceUtilsForActionHandlers.getInstance().getModelSet()
+ *
+ * @return The {@link SashModel} of the current editor, or null if not
+ * found.
+ */
+ public static SashModel getSashModel() {
+
+ try {
+ return (SashModel)ServiceUtilsForActionHandlers.getInstance().getModelSet().getModel(SashModel.MODEL_ID);
+ } catch (ServiceException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Gets the SashModel for the currently selected editor. <br>
+ * Warning: This method is designed to be call from ui.handlers. It is not
+ * designed to be call from Editors. This method can return null if called
+ * during the MultiEditor initialization.
+ *
+ * @see ServiceUtilsForActionHandlers.getInstance().getModelSet()
+ *
+ * @return The {@link SashModel} of the current editor, or null if not
+ * found.
+ * @throws ServiceException
+ * If an error occurs while getting or starting the service.
+ */
+ public static SashModel getSashModelChecked() throws ServiceException {
+
+ return (SashModel)ServiceUtilsForActionHandlers.getInstance().getModelSet().getModel(SashModel.MODEL_ID);
+ }
+
+ /**
+ * Gets the SashModel from the {@link ModelSet}. <br>
+ *
+ * @param modelsManager
+ * The modelManager containing the requested model.
+ *
+ * @return The {@link SashModel} registered in modelManager, or null if not
+ * found.
+ */
+ public static SashModel getSashModel(ModelSet modelsManager) {
+
+ return (SashModel)modelsManager.getModel(SashModel.MODEL_ID);
+ }
+
+ /**
+ * Gets the SashModel from the {@link ModelSet}. <br>
+ *
+ * @param ServicesRegistry
+ * The servie registry under which the ModelSet is registered.
+ *
+ * @return The {@link SashModel} registered in modelManager, or null if not
+ * found.
+ */
+ public static SashModel getSashModel(ServicesRegistry servicesRegistry) {
+
+ try {
+ return (SashModel)ModelUtils.getModelSetChecked(servicesRegistry).getModel(SashModel.MODEL_ID);
+ } catch (ServiceException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Gets the SashModel from the {@link ModelSet}. <br>
+ *
+ * @param ServicesRegistry
+ * The servie registry under which the ModelSet is registered.
+ *
+ * @return The {@link SashModel} registered in modelManager, or null if not
+ * found.
+ * @throws ServiceException
+ * If the service can't be returned.
+ */
+ public static SashModel getSashModelChecked(ServicesRegistry servicesRegistry) throws ServiceException {
+
+ return (SashModel)ModelUtils.getModelSetChecked(servicesRegistry).getModel(SashModel.MODEL_ID);
+ }
+
+ /**
+ * Retrieve the uri of the initial di opened
+ *
+ * @param modelSet
+ * @return FIXME improve how to get the initial model opened
+ */
+ public static URI getInitialURI(ModelSet modelSet) {
+ return UmlUtils.getUmlModel(modelSet).getResourceURI().trimFileExtension().appendFileExtension(SashModel.MODEL_FILE_EXTENSION);
+ }
+
+}

Back to the top