Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/category/DiagramCategoryDescriptor.java179
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/category/DiagramCategoryRegistry.java156
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/command/NewPapyrusModelCommand.java106
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/DiagramKindContentProvider.java136
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/RepresentationKindComposite.java (renamed from plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/DiagramKindComposite.java)736
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/RepresentationKindContentProvider.java82
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/Messages.java41
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/messages.properties38
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/NewModelFilePage.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectArchitectureContextPage.java252
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectDiagramCategoryPage.java471
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectRepresentationKindPage.java (renamed from plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectDiagramKindPage.java)129
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/AbstractNewModelStorageProvider.java6
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/INewModelStorageProvider.java6
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/NewModelStorageProviderRegistry.java12
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/WorkspaceNewModelStorageProvider.java30
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/utils/SettingsHelper.java272
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateModelWizard.java1967
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateSeveralModelsWizard.java26
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/InitModelWizard.java478
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/NewPapyrusProjectWithMultiModelsWizard.java194
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/NewPapyrusProjectWizard.java316
22 files changed, 2461 insertions, 3174 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/category/DiagramCategoryDescriptor.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/category/DiagramCategoryDescriptor.java
deleted file mode 100644
index 7a1c1011211..00000000000
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/category/DiagramCategoryDescriptor.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010 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:
- * Tatiana Fesenko (CEA LIST) - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.wizards.category;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.papyrus.infra.core.editor.BackboneException;
-import org.eclipse.papyrus.infra.ui.extension.commands.IModelCreationCommand;
-
-/**
- * The Class DiagramCategoryDescriptor.
- */
-public class DiagramCategoryDescriptor {
-
- /** The my id. */
- private String myId;
-
- /** The my label. */
- private String myLabel;
-
- /** The my description. */
- private String myDescription;
-
- /** The my file extension. */
- private String myFileExtension;
-
- /** The my icon. */
- private ImageDescriptor myIcon;
-
- /** The instance. */
- private IModelCreationCommand instance;
-
- /** The my creation command class. */
- protected Class<? extends IModelCreationCommand> myCreationCommandClass;
-
- /**
- * Instantiates a new diagram category descriptor.
- *
- * @param id
- * the id
- * @param label
- * the label
- * @param creationCommandClass
- * the creation command class
- */
- public DiagramCategoryDescriptor(String id, String label, Class<? extends IModelCreationCommand> creationCommandClass) {
- myId = id;
- myLabel = label;
- myCreationCommandClass = creationCommandClass;
- }
-
- /**
- * Gets the id.
- *
- * @return the id
- */
- public String getId() {
- return myId;
- }
-
- /**
- * Gets the label.
- *
- * @return the label
- */
- public String getLabel() {
- return myLabel;
- }
-
- /**
- * constructor.
- *
- * @return the creation command
- * @throws BackboneException
- * the backbone exception
- */
- public IModelCreationCommand getCommand() throws BackboneException {
- if (instance == null) {
- instance = createCommand();
- }
-
- return instance;
- }
-
- /**
- * Creates the command.
- *
- * @return the i model creation command
- * @throws BackboneException
- * the backbone exception
- */
- private IModelCreationCommand createCommand() throws BackboneException {
- try {
- IModelCreationCommand command = myCreationCommandClass.newInstance();
- return command;
- } catch (SecurityException e) {
- // Lets propagate. This is an implementation problem that should be solved by
- // programmer.
- throw new RuntimeException(e);
- } catch (InstantiationException e) {
- // Lets propagate. This is an implementation problem that should be solved by
- // programmer.
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- // Lets propagate. This is an implementation problem that should be solved by
- // programmer.
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Gets the description.
- *
- * @return the description
- */
- public String getDescription() {
- return myDescription;
- }
-
- /**
- * Gets the icon.
- *
- * @return the icon
- */
- public ImageDescriptor getIcon() {
- return myIcon;
- }
-
- /**
- * Gets the file extension.
- *
- * @return the file extension
- */
- public String getExtensionPrefix() {
- return myFileExtension;
- }
-
- /**
- * Sets the description.
- *
- * @param description
- * the new description
- */
- public void setDescription(String description) {
- myDescription = description;
- }
-
- /**
- * Sets the icon.
- *
- * @param icon
- * the new icon
- */
- public void setIcon(ImageDescriptor icon) {
- myIcon = icon;
- }
-
- /**
- * Sets the file extension.
- *
- * @param fileExtension
- * the new file extension
- */
- public void setExtensionPrefix(String fileExtension) {
- myFileExtension = fileExtension;
- }
-
-
-} \ No newline at end of file
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/category/DiagramCategoryRegistry.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/category/DiagramCategoryRegistry.java
deleted file mode 100644
index 328b9a63447..00000000000
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/category/DiagramCategoryRegistry.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010 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:
- * Tatiana Fesenko (CEA LIST) - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.wizards.category;
-
-import static org.eclipse.papyrus.uml.diagram.wizards.Activator.log;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.papyrus.infra.core.extension.BadClassNameException;
-import org.eclipse.papyrus.infra.core.extension.ExtensionUtils;
-import org.eclipse.papyrus.infra.ui.extension.commands.IModelCreationCommand;
-import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-
-/**
- * The Class DiagramCategoryRegistry reads available DiagramCategories from plugin descriptors.
- */
-public class DiagramCategoryRegistry extends ExtensionUtils {
-
- /** The Constant CATEGORY_EXTENSION_POINT_NAME. */
- private static final String CATEGORY_EXTENSION_POINT_NAME = "org.eclipse.papyrus.infra.ui.papyrusDiagram"; //$NON-NLS-1$
-
- /** ID of the editor extension (schema filename). */
- public static final String CATEGORY_ELEMENT_NAME = "diagramCategory"; //$NON-NLS-1$
-
- /** The Constant CATEGORY_ID. */
- private static final String CATEGORY_ID = "id"; //$NON-NLS-1$
-
- /** The Constant CATEGORY_LABEL. */
- private static final String CATEGORY_LABEL = "label"; //$NON-NLS-1$
-
- /** The Constant CATEGORY_DESCRIPTION. */
- private static final String CATEGORY_DESCRIPTION = "description"; //$NON-NLS-1$
-
- /** The Constant CATEGORY_ICON. */
- private static final String CATEGORY_ICON = "icon"; //$NON-NLS-1$
-
- /** The Constant CATEGORY_CLASS. */
- private static final String CATEGORY_CLASS = "class"; //$NON-NLS-1$
-
- /** The Constant CATEGORY_FILE_EXTENSION_PREFIX. */
- private static final String CATEGORY_FILE_EXTENSION_PREFIX = "extensionPrefix"; //$NON-NLS-1$
-
- /** The diagram categories. */
- private static Map<String, DiagramCategoryDescriptor> diagramCategories;
-
- /** The our instance. */
- private static DiagramCategoryRegistry ourInstance;
-
- /**
- * Instantiates a new diagram category registry.
- */
- private DiagramCategoryRegistry() {
- }
-
- /**
- * Gets the single instance of DiagramCategoryRegistry.
- *
- * @return single instance of DiagramCategoryRegistry
- */
- public static DiagramCategoryRegistry getInstance() {
- if (ourInstance == null) {
- ourInstance = new DiagramCategoryRegistry();
- }
- return ourInstance;
- }
-
- /**
- * Gets the diagram categories.
- *
- * @return the diagram categories
- */
- public List<DiagramCategoryDescriptor> getDiagramCategories() {
- if (diagramCategories == null) {
- diagramCategories = buildDiagramCategories();
- }
- return new ArrayList<DiagramCategoryDescriptor>(diagramCategories.values());
- }
-
- /**
- * Gets the diagram category map.
- *
- * @return the diagram category map
- */
- public Map<String, DiagramCategoryDescriptor> getDiagramCategoryMap() {
- if (diagramCategories == null) {
- diagramCategories = buildDiagramCategories();
- }
- return diagramCategories;
- }
-
- /**
- * Builds the diagram categories.
- *
- * @return the hash map
- */
- public Map<String, DiagramCategoryDescriptor> buildDiagramCategories() {
- Map<String, DiagramCategoryDescriptor> result = new HashMap<String, DiagramCategoryDescriptor>();
-
- IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CATEGORY_EXTENSION_POINT_NAME);
- for (IExtension extension : extensionPoint.getExtensions()) {
- for (IConfigurationElement confElement : extension.getConfigurationElements()) {
- if (CATEGORY_ELEMENT_NAME.equals(confElement.getName())) {
- DiagramCategoryDescriptor diagramCategoryDescriptor;
- try {
- diagramCategoryDescriptor = buildCategoryDescriptor(confElement);
- result.put(diagramCategoryDescriptor.getId(), diagramCategoryDescriptor);
- } catch (BadClassNameException e) {
- log.error(Messages.DiagramCategoryRegistry_bad_class_name_of_category, e);
- }
- }
- }
- }
- return result;
- }
-
- /**
- * Builds the category descriptor.
- *
- * @param confElement
- * the conf element
- * @return the diagram category descriptor
- * @throws BadClassNameException
- * the bad class name exception
- */
- protected DiagramCategoryDescriptor buildCategoryDescriptor(IConfigurationElement confElement) throws BadClassNameException {
- Class<IModelCreationCommand> commandClazz = (Class<IModelCreationCommand>) parseClass(confElement, CATEGORY_CLASS, CATEGORY_ELEMENT_NAME);
- DiagramCategoryDescriptor diagramCategoryDescriptor = new DiagramCategoryDescriptor(confElement.getAttribute(CATEGORY_ID), confElement.getAttribute(CATEGORY_LABEL), commandClazz);
- diagramCategoryDescriptor.setDescription(confElement.getAttribute(CATEGORY_DESCRIPTION));
- diagramCategoryDescriptor.setExtensionPrefix(confElement.getAttribute(CATEGORY_FILE_EXTENSION_PREFIX));
- String iconPath = confElement.getAttribute(CATEGORY_ICON);
- if (iconPath != null) {
- diagramCategoryDescriptor.setIcon(AbstractUIPlugin.imageDescriptorFromPlugin(confElement.getNamespaceIdentifier(), iconPath));
- }
- return diagramCategoryDescriptor;
- }
-
-}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/command/NewPapyrusModelCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/command/NewPapyrusModelCommand.java
index 98b4ad0a95a..36c6c0ae486 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/command/NewPapyrusModelCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/command/NewPapyrusModelCommand.java
@@ -1,51 +1,55 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2013 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:
- * Tatiana Fesenko (CEA LIST) - Initial API and implementation
- * Christian W. Damus (CEA) - Support creating models in repositories (CDO)
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.wizards.command;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-
-/**
- * The Command to create a new Papyrus Model.
- */
-public class NewPapyrusModelCommand extends RecordingCommand {
-
- /** The my model set. */
- private final ModelSet myModelSet;
-
- /** The URI of the model to create. */
- private final URI myURI;
-
- /**
- * Instantiates a new new papyrus model command.
- *
- * @param modelSet
- * the di resource set
- * @param newURI
- * the URI of the new model's principal resource
- */
- public NewPapyrusModelCommand(ModelSet modelSet, URI newURI) {
- super(modelSet.getTransactionalEditingDomain());
- myModelSet = modelSet;
- myURI = newURI;
- }
-
- @Override
- protected void doExecute() {
- myModelSet.createModels(myURI);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2010, 2013 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:
+ * Tatiana Fesenko (CEA LIST) - Initial API and implementation
+ * Christian W. Damus (CEA) - Support creating models in repositories (CDO)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.wizards.command;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+
+/**
+ * The Command to create a new Papyrus Model.
+ */
+public class NewPapyrusModelCommand extends RecordingCommand {
+
+ /** The my model set. */
+ private final ModelSet myModelSet;
+
+ /** The URI of the model to create. */
+ private final URI myURI;
+
+ /**
+ * Instantiates a new new papyrus model command.
+ *
+ * @param modelSet
+ * the di resource set
+ * @param newURI
+ * the URI of the new model's principal resource
+ * @param contextId
+ * the id of the architecture context
+ * @param viewpointIds
+ * the ids of the architecture viewpoints
+ */
+ public NewPapyrusModelCommand(ModelSet modelSet, URI newURI) {
+ super(modelSet.getTransactionalEditingDomain());
+ myModelSet = modelSet;
+ myURI = newURI;
+ }
+
+ @Override
+ protected void doExecute() {
+ myModelSet.createModels(myURI);
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/DiagramKindContentProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/DiagramKindContentProvider.java
deleted file mode 100644
index af93c20da23..00000000000
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/DiagramKindContentProvider.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010 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:
- * Tatiana Fesenko (CEA LIST) - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.wizards.kind;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.papyrus.infra.viewpoints.configuration.Category;
-import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
-import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
-
-/**
- * The ContentProvider for DiagramCategory table.
- * Returns available diagram kinds for the given diagram category(ies).
- */
-public class DiagramKindContentProvider implements IStructuredContentProvider {
-
- private final Map<String, Collection<ViewPrototype>> prototypes;
-
- /**
- * Instantiates a new diagram kind content provider.
- *
- */
- public DiagramKindContentProvider() {
- Collection<ViewPrototype> vps = PolicyChecker.getCurrent().getAllPrototypes();
- this.prototypes = new HashMap<String, Collection<ViewPrototype>>();
- for (ViewPrototype vp : vps) {
- for (Category category : vp.getCategories()) {
- cache(category.getName(), vp);
- }
- }
- }
-
- /**
- * Stores the given diagram prototype in the cache
- *
- * @param prototype
- * The prototype to cache
- */
- private void cache(String category, ViewPrototype prototype) {
- if (!prototypes.containsKey(category)) {
- prototypes.put(category, new ArrayList<ViewPrototype>());
- }
- prototypes.get(category).add(prototype);
- }
-
- /**
- * Dispose.
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
- public void dispose() {
- prototypes.clear();
- }
-
- /**
- * Input changed.
- *
- * @param viewer
- * the viewer
- * @param oldInput
- * the old input
- * @param newInput
- * the new input
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- /**
- * Gets the elements.
- *
- * @param inputElement
- * the input element
- * @return the elements
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- if (inputElement instanceof Object[]) {
- List<ViewPrototype> result = new ArrayList<ViewPrototype>();
- for (Object next : (Object[]) inputElement) {
- if (next instanceof String) {
- String diagramCategory = (String) next;
- result.addAll(getPrototypes(diagramCategory));
- }
- }
- Collections.sort(result, new ViewPrototype.Comp());
- return result.toArray(new Object[result.size()]);
- }
- if (inputElement instanceof String) {
- String diagramCategory = (String) inputElement;
- List<ViewPrototype> result = getPrototypes(diagramCategory);
- return result.toArray(new Object[result.size()]);
- }
- return null;
- }
-
- /**
- * Gets the creation commands.
- *
- * @param diagramCategory
- * the diagram category
- * @return the creation commands
- */
- protected List<ViewPrototype> getPrototypes(String diagramCategory) {
- HashMap<String, ViewPrototype> result = new HashMap<String, ViewPrototype>();
- if (prototypes.containsKey(diagramCategory)) {
- // Look for all diagram kind of the category
- for (ViewPrototype prototype : prototypes.get(diagramCategory)) {
- String label = prototype.getLabel();
- // If the diagram is not contains in the result add it
- if (!result.containsKey(label)) {
- result.put(label, prototype);
- }
- }
- }
- return new ArrayList<ViewPrototype>(result.values());
- }
-}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/DiagramKindComposite.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/RepresentationKindComposite.java
index 537ba3e0d90..729c6feb436 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/DiagramKindComposite.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/RepresentationKindComposite.java
@@ -1,354 +1,382 @@
-/*****************************************************************************
- * 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:
- * Thibault Le Ouay (Sherpa Engineering) t.leouay@sherpa-eng.com - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.wizards.kind;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-//import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.CheckboxCellEditor;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.IBaseLabelProvider;
-import org.eclipse.jface.viewers.ICellEditorValidator;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.TextCellEditor;
-import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
-import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-
-
-public class DiagramKindComposite extends Composite {
-
- private static final Image CHECKED = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("org.eclipse.papyrus.uml.diagram.wizards", "icons/checked.gif"); //$NON-NLS-1$ //$NON-NLS-2$
-
- private static final Image UNCHECKED = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("org.eclipse.papyrus.uml.diagram.wizards", "icons/unchecked.gif"); //$NON-NLS-1$ //$NON-NLS-2$
-
- private Map<ViewPrototype, String> diagramNames = new HashMap<ViewPrototype, String>();
-
- List<String> listNames = new ArrayList<String>();
-
-
- private Map<ViewPrototype, Integer> selectedDiagrams = new HashMap<ViewPrototype, Integer>();
-
- public TableViewer viewer;
-
- private GridData gridData;
-
-
-
-
- public DiagramKindComposite(Composite parent) {
- super(parent, SWT.NONE);
- this.setLayout(new GridLayout());
- this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
- createTableViewer(this);
- }
-
- public void createTableViewer(final Composite container) {
-
- viewer = new TableViewer(container, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
- gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- viewer.getTable().setLayoutData(gridData);
-
- // viewer.setContentProvider(new ArrayContentProvider());
- final Table table = viewer.getTable();
- viewer.setContentProvider(new DiagramKindContentProvider());
- table.setHeaderVisible(true);
-
- // The check column
- TableViewerColumn colCheckbox = createTableViewerColumn("", 20, viewer); //$NON-NLS-1$
- colCheckbox.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- return ""; //$NON-NLS-1$
- }
-
- @Override
- public Image getImage(Object element) {
- if (selectedDiagrams.containsKey(element)) {
- return CHECKED;
- } else {
- return UNCHECKED;
- }
- }
-
- });
- colCheckbox.setEditingSupport(new EditingSupport(viewer) {
-
- private CheckboxCellEditor checkboxCellEditor;
-
- @Override
- protected void setValue(Object element, Object value) {
- if (checkboxCellEditor.getValue() == Boolean.TRUE) {
- selectedDiagrams.put((ViewPrototype) element, 1);
- } else {
- selectedDiagrams.remove(element);
- }
- viewer.update(element, null);
- }
-
- @Override
- protected Object getValue(Object element) {
- return selectedDiagrams.containsKey(element);
- }
-
- @Override
- protected CellEditor getCellEditor(Object element) {
- checkboxCellEditor = new CheckboxCellEditor(container, SWT.CHECK | SWT.READ_ONLY);
- return checkboxCellEditor;
- }
-
- @Override
- protected boolean canEdit(Object element) {
- return true;
- }
- });
- // no need to enable the resize on the check box column
- colCheckbox.getColumn().setResizable(false);
-
-
- // The Diagram name column
- TableViewerColumn colDiagramKind = createTableViewerColumn(Messages.DiagramKindComposite_0, 200, viewer);
- colDiagramKind.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- if (element instanceof ViewPrototype) {
- return ((ViewPrototype) element).getLabel();
- }
- return ""; //$NON-NLS-1$
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof ViewPrototype) {
- return ((ViewPrototype) element).getIcon();
- }
- return null;
- }
-
-
- });
-
-
- // the name of the diagram the user can edit it to set his onw name
- TableViewerColumn colDiagramName = createTableViewerColumn(Messages.DiagramKindComposite_2, 300, viewer);
- colDiagramName.setEditingSupport(new EditingSupport(viewer) {
-
- @Override
- protected void setValue(Object element, Object value) {
-
- diagramNames.put((ViewPrototype) element, (String) value);
- viewer.update(element, null);
-
- }
-
- @Override
- protected Object getValue(Object element) {
-
- if (diagramNames.containsKey(element)) {
- return diagramNames.get(element);
- }
- return ""; //$NON-NLS-1$
-
- }
-
- @Override
- protected CellEditor getCellEditor(Object element) {
- return new TextCellEditor(viewer.getTable());
- }
-
- @Override
- protected boolean canEdit(Object element) {
- return true;
- }
- });
- colDiagramName.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
-
- return diagramNames.get(element);
- }
- });
-
-
- // the quantity of the diagram the user would like to create
- TableViewerColumn colDiagramQuantity = createTableViewerColumn(Messages.DiagramKindComposite_3, 70, viewer);
- colDiagramQuantity.setEditingSupport(new EditingSupport(viewer) {
-
- @Override
- protected void setValue(Object element, Object value) {
- selectedDiagrams.put((ViewPrototype) element, Integer.parseInt((String) value));
- viewer.update(element, null);
- }
-
- @Override
- protected Object getValue(Object element) {
- if (selectedDiagrams.containsKey(element)) {
- return selectedDiagrams.get(element).toString();
- }
- return "0"; //$NON-NLS-1$
- }
-
- @Override
- protected CellEditor getCellEditor(Object element) {
- TextCellEditor textCellEditor = new TextCellEditor(viewer.getTable());
- textCellEditor.setValidator(new ICellEditorValidator() {
-
- @Override
- public String isValid(Object value) {
- if (!(value instanceof Integer)) {
- return null;
- }
- return value.toString();
- }
- });
- return textCellEditor;
- }
-
- @Override
- protected boolean canEdit(Object element) {
- return true;
- }
- });
- colDiagramQuantity.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- if (selectedDiagrams.containsKey(element)) {
- return selectedDiagrams.get(element).toString();
- }
- // return "0"; //$NON-NLS-1$
- return ""; //$NON-NLS-1$
- }
- });
-
-
- // TODO - The description of the diagram not yet implemented, should be implemented will generating the diagram
- // TableViewerColumn colDiagramDescription = createTableViewerColumn("Description", 400, viewer);
- // colDiagramDescription.setLabelProvider(new ColumnLabelProvider() {
- //
- // @Override
- // public String getText(Object element) {
- // return null;
- // }
- //
- // });
- viewer.addSelectionChangedListener(new ISelectionChangedListener() {
-
- @Override
- public void selectionChanged(SelectionChangedEvent event) {
- // if(selectedConfigs.size() > 0) {
- // setPageComplete(true);
- // } else {
- // setPageComplete(false);
- // }
- }
- });
-
- }
-
- /**
- * Constructor.
- *
- * @param title
- * @param bound
- * @param viewer
- * @return
- */
- private TableViewerColumn createTableViewerColumn(String title, int bound, TableViewer viewer) {
- final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
- final TableColumn column = viewerColumn.getColumn();
- column.setText(title);
- column.setWidth(bound);
- column.setResizable(true);
- column.setMoveable(false);
- return viewerColumn;
- }
-
-
- /**
- * Creates the diagram kind label provider.
- *
- * @return the i base label provider
- */
- protected IBaseLabelProvider createDiagramKindLabelProvider() {
- return new DiagramKindLabelProvider();
- }
-
-
- public void setInput(Object input) {
- viewer.setInput(input);
-
- // Resize the diagram table to minimize the space lost
- int tableItemHeight = viewer.getTable().getItemHeight();
- int tableItemCount = ((DiagramKindContentProvider) viewer.getContentProvider()).getElements(input).length;
- gridData.minimumHeight = tableItemHeight * Math.max(3, Math.round((tableItemCount / 2)));
- gridData.heightHint = tableItemHeight * Math.max(3, Math.round((tableItemCount / 2)));
-
- // Notifies the shell that the layout needs to be resized
- ((Composite) viewer.getControl()).layout(true, true);
- }
-
- public ArrayList<ViewPrototype> getCheckElement() {
- ArrayList<ViewPrototype> list = new ArrayList<ViewPrototype>();
- Set<Entry<ViewPrototype, Integer>> set = selectedDiagrams.entrySet();
- Iterator<Entry<ViewPrototype, Integer>> ite = set.iterator();
- while (ite.hasNext()) {
- Entry<ViewPrototype, Integer> me = ite.next();
- int nb = me.getValue();
- String tempname = diagramNames.get(me.getKey());
- // If the name field was not filled
- if (tempname == null || tempname.equalsIgnoreCase("")) {
- tempname = me.getKey().getLabel();
- }
-
- for (int i = 0; i < nb; i++) {
- list.add(me.getKey());
- if (nb > 1) {
- listNames.add(tempname + "_" + i); //$NON-NLS-1$
- } else {
- listNames.add(tempname);
- }
- }
- }
- return list;
- }
-
-
- /**
- * @return
- */
- public List<String> getDiagramName() {
- return listNames;
- }
-
-}
+/*****************************************************************************
+ * 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:
+ * Thibault Le Ouay (Sherpa Engineering) t.leouay@sherpa-eng.com - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.wizards.kind;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+//import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CheckboxCellEditor;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.jface.viewers.ICellEditorValidator;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.papyrus.infra.core.architecture.RepresentationKind;
+import org.eclipse.papyrus.uml.diagram.wizards.Activator;
+import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+
+
+public class RepresentationKindComposite extends Composite {
+
+ private static final Image CHECKED = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("org.eclipse.papyrus.uml.diagram.wizards", "icons/checked.gif"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ private static final Image UNCHECKED = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("org.eclipse.papyrus.uml.diagram.wizards", "icons/unchecked.gif"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ private Map<RepresentationKind, String> representationNames = new HashMap<RepresentationKind, String>();
+
+ List<String> listNames = new ArrayList<String>();
+
+
+ private Map<RepresentationKind, Integer> selectedRepresentations = new HashMap<RepresentationKind, Integer>();
+
+ public TableViewer viewer;
+
+ private GridData gridData;
+
+ private ImageRegistry imageRegistry;
+
+
+ public RepresentationKindComposite(Composite parent) {
+ super(parent, SWT.NONE);
+ this.setLayout(new GridLayout());
+ this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ createTableViewer(this);
+ imageRegistry = new ImageRegistry();
+ }
+
+ public void createTableViewer(final Composite container) {
+
+ viewer = new TableViewer(container, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ viewer.getTable().setLayoutData(gridData);
+
+ // viewer.setContentProvider(new ArrayContentProvider());
+ final Table table = viewer.getTable();
+ viewer.setContentProvider(new RepresentationKindContentProvider());
+ table.setHeaderVisible(true);
+
+ // The check column
+ TableViewerColumn colCheckbox = createTableViewerColumn("", 20, viewer); //$NON-NLS-1$
+ colCheckbox.setLabelProvider(new ColumnLabelProvider() {
+
+ @Override
+ public String getText(Object element) {
+ return ""; //$NON-NLS-1$
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ if (selectedRepresentations.containsKey(element)) {
+ return CHECKED;
+ } else {
+ return UNCHECKED;
+ }
+ }
+
+ });
+ colCheckbox.setEditingSupport(new EditingSupport(viewer) {
+
+ private CheckboxCellEditor checkboxCellEditor;
+
+ @Override
+ protected void setValue(Object element, Object value) {
+ if (checkboxCellEditor.getValue() == Boolean.TRUE) {
+ selectedRepresentations.put((RepresentationKind) element, 1);
+ } else {
+ selectedRepresentations.remove(element);
+ }
+ viewer.update(element, null);
+ }
+
+ @Override
+ protected Object getValue(Object element) {
+ return selectedRepresentations.containsKey(element);
+ }
+
+ @Override
+ protected CellEditor getCellEditor(Object element) {
+ checkboxCellEditor = new CheckboxCellEditor(container, SWT.CHECK | SWT.READ_ONLY);
+ return checkboxCellEditor;
+ }
+
+ @Override
+ protected boolean canEdit(Object element) {
+ return true;
+ }
+ });
+ // no need to enable the resize on the check box column
+ colCheckbox.getColumn().setResizable(false);
+
+
+ // The Diagram name column
+ TableViewerColumn colDiagramKind = createTableViewerColumn(Messages.RepresentationKindComposite_0, 200, viewer);
+ colDiagramKind.setLabelProvider(new ColumnLabelProvider() {
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof RepresentationKind) {
+ return ((RepresentationKind) element).getName();
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof RepresentationKind) {
+ return getIcon((RepresentationKind) element);
+ }
+ return null;
+ }
+
+
+ });
+
+
+ // the name of the diagram the user can edit it to set his onw name
+ TableViewerColumn colDiagramName = createTableViewerColumn(Messages.RepresentationKindComposite_2, 300, viewer);
+ colDiagramName.setEditingSupport(new EditingSupport(viewer) {
+
+ @Override
+ protected void setValue(Object element, Object value) {
+
+ representationNames.put((RepresentationKind) element, (String) value);
+ viewer.update(element, null);
+
+ }
+
+ @Override
+ protected Object getValue(Object element) {
+
+ if (representationNames.containsKey(element)) {
+ return representationNames.get(element);
+ }
+ return ""; //$NON-NLS-1$
+
+ }
+
+ @Override
+ protected CellEditor getCellEditor(Object element) {
+ return new TextCellEditor(viewer.getTable());
+ }
+
+ @Override
+ protected boolean canEdit(Object element) {
+ return true;
+ }
+ });
+ colDiagramName.setLabelProvider(new ColumnLabelProvider() {
+
+ @Override
+ public String getText(Object element) {
+
+ return representationNames.get(element);
+ }
+ });
+
+
+ // the quantity of the diagram the user would like to create
+ TableViewerColumn colDiagramQuantity = createTableViewerColumn(Messages.RepresentationKindComposite_3, 70, viewer);
+ colDiagramQuantity.setEditingSupport(new EditingSupport(viewer) {
+
+ @Override
+ protected void setValue(Object element, Object value) {
+ selectedRepresentations.put((RepresentationKind) element, Integer.parseInt((String) value));
+ viewer.update(element, null);
+ }
+
+ @Override
+ protected Object getValue(Object element) {
+ if (selectedRepresentations.containsKey(element)) {
+ return selectedRepresentations.get(element).toString();
+ }
+ return "0"; //$NON-NLS-1$
+ }
+
+ @Override
+ protected CellEditor getCellEditor(Object element) {
+ TextCellEditor textCellEditor = new TextCellEditor(viewer.getTable());
+ textCellEditor.setValidator(new ICellEditorValidator() {
+
+ @Override
+ public String isValid(Object value) {
+ if (!(value instanceof Integer)) {
+ return null;
+ }
+ return value.toString();
+ }
+ });
+ return textCellEditor;
+ }
+
+ @Override
+ protected boolean canEdit(Object element) {
+ return true;
+ }
+ });
+ colDiagramQuantity.setLabelProvider(new ColumnLabelProvider() {
+
+ @Override
+ public String getText(Object element) {
+ if (selectedRepresentations.containsKey(element)) {
+ return selectedRepresentations.get(element).toString();
+ }
+ // return "0"; //$NON-NLS-1$
+ return ""; //$NON-NLS-1$
+ }
+ });
+
+
+ // TODO - The description of the diagram not yet implemented, should be implemented will generating the diagram
+ // TableViewerColumn colDiagramDescription = createTableViewerColumn("Description", 400, viewer);
+ // colDiagramDescription.setLabelProvider(new ColumnLabelProvider() {
+ //
+ // @Override
+ // public String getText(Object element) {
+ // return null;
+ // }
+ //
+ // });
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ // if(selectedConfigs.size() > 0) {
+ // setPageComplete(true);
+ // } else {
+ // setPageComplete(false);
+ // }
+ }
+ });
+
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param title
+ * @param bound
+ * @param viewer
+ * @return
+ */
+ private TableViewerColumn createTableViewerColumn(String title, int bound, TableViewer viewer) {
+ final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
+ final TableColumn column = viewerColumn.getColumn();
+ column.setText(title);
+ column.setWidth(bound);
+ column.setResizable(true);
+ column.setMoveable(false);
+ return viewerColumn;
+ }
+
+
+ /**
+ * Creates the diagram kind label provider.
+ *
+ * @return the i base label provider
+ */
+ protected IBaseLabelProvider createDiagramKindLabelProvider() {
+ return new DiagramKindLabelProvider();
+ }
+
+
+ public void setInput(Object input) {
+ viewer.setInput(input);
+
+ // Resize the diagram table to minimize the space lost
+ int tableItemHeight = viewer.getTable().getItemHeight();
+ int tableItemCount = ((RepresentationKindContentProvider) viewer.getContentProvider()).getElements(input).length;
+ gridData.minimumHeight = tableItemHeight * Math.max(3, Math.round((tableItemCount / 2)));
+ gridData.heightHint = tableItemHeight * Math.max(3, Math.round((tableItemCount / 2)));
+
+ // Notifies the shell that the layout needs to be resized
+ ((Composite) viewer.getControl()).layout(true, true);
+ }
+
+ public ArrayList<RepresentationKind> getCheckElement() {
+ ArrayList<RepresentationKind> list = new ArrayList<RepresentationKind>();
+ Set<Entry<RepresentationKind, Integer>> set = selectedRepresentations.entrySet();
+ Iterator<Entry<RepresentationKind, Integer>> ite = set.iterator();
+ while (ite.hasNext()) {
+ Entry<RepresentationKind, Integer> me = ite.next();
+ int nb = me.getValue();
+ String tempname = representationNames.get(me.getKey());
+ // If the name field was not filled
+ if (tempname == null || tempname.equalsIgnoreCase("")) {
+ tempname = me.getKey().getName();
+ }
+
+ for (int i = 0; i < nb; i++) {
+ list.add(me.getKey());
+ if (nb > 1) {
+ listNames.add(tempname + "_" + i); //$NON-NLS-1$
+ } else {
+ listNames.add(tempname);
+ }
+ }
+ }
+ return list;
+ }
+
+
+ /**
+ * @return
+ */
+ public List<String> getDiagramName() {
+ return listNames;
+ }
+
+ private Image getIcon(final RepresentationKind kind) {
+ Image image = imageRegistry.get(kind.getIcon());
+ if (image == null) {
+ String uri = kind.getIcon();
+ if (uri != null) {
+ try {
+ ImageDescriptor descriptor = ImageDescriptor.createFromURL(new URL(uri));
+ imageRegistry.put(kind.getIcon(), descriptor);
+ image = imageRegistry.get(kind.getIcon());
+ } catch (MalformedURLException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+ return image;
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ imageRegistry.dispose();
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/RepresentationKindContentProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/RepresentationKindContentProvider.java
new file mode 100644
index 00000000000..9771247f34e
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/kind/RepresentationKindContentProvider.java
@@ -0,0 +1,82 @@
+/*****************************************************************************
+ * Copyright (c) 2010 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:
+ * Tatiana Fesenko (CEA LIST) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.wizards.kind;
+
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.infra.core.architecture.RepresentationKind;
+import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureViewpoint;
+import org.eclipse.papyrus.infra.architecture.ArchitectureDomainManager;
+
+/**
+ * The ContentProvider for DiagramCategory table.
+ * Returns available diagram kinds for the given diagram category(ies).
+ */
+public class RepresentationKindContentProvider implements IStructuredContentProvider {
+
+ /**
+ * Input changed.
+ *
+ * @param viewer
+ * the viewer
+ * @param oldInput
+ * the old input
+ * @param newInput
+ * the new input
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ /**
+ * Gets the elements.
+ *
+ * @param inputElement
+ * the input element
+ * @return the elements
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+ public Object[] getElements(Object inputElement) {
+ ArchitectureDomainManager manager = ArchitectureDomainManager.getInstance();
+ if (inputElement instanceof Object[]) {
+ Set<RepresentationKind> result = new TreeSet<RepresentationKind>(new Comparator<RepresentationKind>() {
+ @Override
+ public int compare(RepresentationKind o1, RepresentationKind o2) {
+ return o1.getName().compareTo(o2.getName());
+ }
+ });
+ for (Object next : (Object[]) inputElement) {
+ if (next instanceof String) {
+ String viewpointId = (String) next;
+ MergedArchitectureViewpoint viewpoint = manager.getArchitectureViewpointById(viewpointId);
+ result.addAll(viewpoint.getRepresentationKinds());
+ }
+ }
+ return result.toArray(new Object[result.size()]);
+ }
+ if (inputElement instanceof String) {
+ String viewpointId = (String) inputElement;
+ MergedArchitectureViewpoint viewpoint = manager.getArchitectureViewpointById(viewpointId);
+ Collection<RepresentationKind> result = viewpoint.getRepresentationKinds();
+ return result.toArray(new Object[result.size()]);
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/Messages.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/Messages.java
index e6286d0e35a..08c380636be 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/Messages.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/Messages.java
@@ -60,11 +60,11 @@ public class Messages extends NLS {
public static String DiagramCategoryRegistry_bad_class_name_of_category;
- public static String DiagramKindComposite_0;
+ public static String RepresentationKindComposite_0;
- public static String DiagramKindComposite_2;
+ public static String RepresentationKindComposite_2;
- public static String DiagramKindComposite_3;
+ public static String RepresentationKindComposite_3;
/** The Diagram kind label provider_undefined_element. */
public static String DiagramKindLabelProvider_undefined_element;
@@ -97,52 +97,47 @@ public class Messages extends NLS {
/** The Select diagram category page_cannot_find_category. */
- public static String SelectDiagramCategoryPage_cannot_find_category;
+ public static String SelectArchitectureContextPage_cannot_find_category;
/** The Select diagram category page_diagram_language_group. */
- public static String SelectDiagramCategoryPage_diagram_language_group;
+ public static String SelectArchitectureContextPage_diagram_language_group;
/** The Select diagram category page_select_language. */
- public static String SelectDiagramCategoryPage_select_language;
+ public static String SelectArchitectureContextPage_select_language;
/** The Select diagram category page_select_one_category. */
- public static String SelectDiagramCategoryPage_select_one_category;
+ public static String SelectArchitectureContextPage_select_one_category;
- public static String SelectDiagramCategoryPage_umlGroup;
-
- public static String SelectDiagramCategoryPage_dsmlGroup;
-
-
- public static String SelectDiagramKindPage_0;
+ public static String SelectRepresentationKindPage_0;
/** The Select diagram kind page_default_diagram_name. */
- public static String SelectDiagramKindPage_default_diagram_name;
+ public static String SelectRepresentationKindPage_default_diagram_name;
/** The Select diagram kind page_diagram_name_group. */
- public static String SelectDiagramKindPage_diagram_name_group;
+ public static String SelectRepresentationKindPage_diagram_name_group;
/** The Select diagram kind page_diagram_name_is_empty. */
- public static String SelectDiagramKindPage_diagram_name_is_empty;
+ public static String SelectRepresentationKindPage_diagram_name_is_empty;
/** The Select diagram kind page_load_template_group. */
- public static String SelectDiagramKindPage_load_template_group;
+ public static String SelectRepresentationKindPage_load_template_group;
/** The Select diagram kind page_page_desc. */
- public static String SelectDiagramKindPage_page_desc;
+ public static String SelectRepresentationKindPage_page_desc;
/** The Select diagram kind page_page_title. */
- public static String SelectDiagramKindPage_page_title;
+ public static String SelectRepresentationKindPage_page_title;
/** The Select diagram kind page_remember_current_selection_text. */
- public static String SelectDiagramKindPage_remember_current_selection_text;
+ public static String SelectRepresentationKindPage_remember_current_selection_text;
/** The Select diagram kind page_remember_current_selection_tooltip. */
- public static String SelectDiagramKindPage_remember_current_selection_tooltip;
+ public static String SelectRepresentationKindPage_remember_current_selection_tooltip;
/** The Select diagram kind page_select_kind_group. */
- public static String SelectDiagramKindPage_select_kind_group;
+ public static String SelectRepresentationKindPage_select_kind_group;
- public static String SelectDiagramKindPage_Set_Root_Name_Error;
+ public static String SelectRepresentationKindPage_Set_Root_Name_Error;
public static String ProfileChooserComposite_RegisteredProfilesDialog;
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/messages.properties b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/messages.properties
index ac436090969..6b98d0f0153 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/messages.properties
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/messages.properties
@@ -30,9 +30,9 @@ PapyrusProjectCreationPage_page_null_name_desc=The project's name is undefined,
DiagramCategoryRegistry_bad_class_name_of_category=Could not find implementation for a diagram category
-DiagramKindComposite_0=Diagram name
-DiagramKindComposite_2=Name
-DiagramKindComposite_3=Quantity
+RepresentationKindComposite_0=Representation name
+RepresentationKindComposite_2=Name
+RepresentationKindComposite_3=Quantity
DiagramKindLabelProvider_undefined_element=<undefined>
FileChooser_0=Browse workspace
@@ -46,25 +46,23 @@ NewModelFilePage_page_desc=Create a new {0} model
NewModelFilePage_page_same_case_desc=There already is a model with this name:
NewModelFilePage_set_a_container=Please select a valid container for the new model
-SelectDiagramCategoryPage_cannot_find_category=Could not find DiagramCategory for {0}
-SelectDiagramCategoryPage_diagram_language_group=Diagram Language:
-SelectDiagramCategoryPage_select_language=Select the language of the new diagrams
-SelectDiagramCategoryPage_select_one_category=Please select at least one category
-SelectDiagramCategoryPage_umlGroup=UML core:
-SelectDiagramCategoryPage_dsmlGroup=DSML:
+SelectArchitectureContextPage_cannot_find_category=Could not find Architecture Context for {0}
+SelectArchitectureContextPage_diagram_language_group=Architecture Context:
+SelectArchitectureContextPage_select_language=Select the context of the new representations
+SelectArchitectureContextPage_select_one_category=Please select at least one context
-SelectDiagramKindPage_0=Choose a profile to apply
-SelectDiagramKindPage_default_diagram_name=RootElement
-SelectDiagramKindPage_diagram_name_group=Root model element name:
-SelectDiagramKindPage_diagram_name_is_empty=The diagram name should not be empty.
-SelectDiagramKindPage_load_template_group=You can load a template:
-SelectDiagramKindPage_page_desc=Select root element name and diagram kind
-SelectDiagramKindPage_page_title=Initialization information
-SelectDiagramKindPage_remember_current_selection_text=Remember current selection
-SelectDiagramKindPage_remember_current_selection_tooltip=The current selection will be used when you open the wizard next time
-SelectDiagramKindPage_select_kind_group=Select a Diagram Kind:
-SelectDiagramKindPage_Set_Root_Name_Error=The Root model element name cannot be deduced from the current workspace selection
+SelectRepresentationKindPage_0=Choose a profile to apply
+SelectRepresentationKindPage_default_diagram_name=RootElement
+SelectRepresentationKindPage_diagram_name_group=Root model element name:
+SelectRepresentationKindPage_diagram_name_is_empty=The representation name should not be empty.
+SelectRepresentationKindPage_load_template_group=You can load a template:
+SelectRepresentationKindPage_page_desc=Select root element name and representation kind
+SelectRepresentationKindPage_page_title=Initialization information
+SelectRepresentationKindPage_remember_current_selection_text=Remember current selection
+SelectRepresentationKindPage_remember_current_selection_tooltip=The current selection will be used when you open the wizard next time
+SelectRepresentationKindPage_select_kind_group=Select a Representation Kind:
+SelectRepresentationKindPage_Set_Root_Name_Error=The Root model element name cannot be deduced from the current workspace selection
ProfileChooserComposite_RegisteredProfilesDialog=Registered Profile Selection
ProfileChooserComposite_WorkspaceSelectionButton=Browse Workspace
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/NewModelFilePage.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/NewModelFilePage.java
index f06726ac12f..ff2bff0e42a 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/NewModelFilePage.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/NewModelFilePage.java
@@ -110,7 +110,7 @@ public class NewModelFilePage extends WizardNewFileCreationPage {
*/
public IStatus diagramExtensionChanged(String newExtension) {
String currentExtension = getFileExtension();
- if (!currentExtension.equals(newExtension)) {
+ if (!currentExtension.equals(newExtension) && this.getControl() != null) {
// String oldFileName = getFileName();
String newFileName = NewModelFilePage.getUniqueFileName(getContainerFullPath(), getFileName().replace(currentExtension, ""), newExtension);
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectArchitectureContextPage.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectArchitectureContextPage.java
new file mode 100644
index 00000000000..7445713c287
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectArchitectureContextPage.java
@@ -0,0 +1,252 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.wizards.pages;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureContext;
+import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureViewpoint;
+import org.eclipse.papyrus.infra.architecture.ArchitectureDomainManager;
+import org.eclipse.papyrus.infra.ui.architecture.widgets.ArchitectureContextComposite;
+import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
+import org.eclipse.papyrus.uml.diagram.wizards.utils.SettingsHelper;
+import org.eclipse.papyrus.uml.diagram.wizards.wizards.CreateModelWizard;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Layout;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * @author melaasar
+ *
+ */
+public class SelectArchitectureContextPage extends WizardPage {
+
+ /** The Constant PAGE_ID. */
+ public static final String PAGE_ID = "SelectArchitectureContextPage"; //$NON-NLS-1$
+
+ private SettingsHelper settingsHelper;
+
+ private final boolean allowSeveralContexts;
+
+ private String[] selectedContexts;
+
+ private String[] selectedViewpoints;
+
+ public SelectArchitectureContextPage() {
+ this(false);
+ }
+
+ public SelectArchitectureContextPage(boolean allowSeveralContexts) {
+ super(PAGE_ID);
+ setTitle("Select Architecture Context");
+ setDescription("Select the architecture context(s) and viewpoints to apply to the Papyrus model");
+ this.allowSeveralContexts = allowSeveralContexts;
+ }
+
+ @Override
+ public void setWizard(IWizard newWizard) {
+ super.setWizard(newWizard);
+ settingsHelper = new SettingsHelper(getDialogSettings());
+
+ List<String> contextIds = asList(settingsHelper.getArchitectureContexts());
+ if (!allowSeveralContexts) {
+ String defaultContextId = ArchitectureDomainManager.getInstance().getDefaultArchitectureContextId();
+ if (defaultContextId != null)
+ contextIds = asList(defaultContextId);
+ else if (!contextIds.isEmpty())
+ contextIds = asList(contextIds.get(0));
+ else
+ contextIds = Collections.emptyList();
+ }
+
+ List<String> viewpoints = new ArrayList<String>();
+ for (Iterator<String> i = contextIds.iterator(); i.hasNext();) {
+ String contextId = i.next();
+ if (isVisibleContext(contextId)) {
+ MergedArchitectureContext context = ArchitectureDomainManager.getInstance().getArchitectureContextById(contextId);
+ for (MergedArchitectureViewpoint viewpoint : context.getViewpoints()) {
+ viewpoints.add(viewpoint.getId());
+ }
+ } else
+ i.remove();
+ }
+
+ selectedContexts = contextIds.toArray(new String[0]);
+ selectedViewpoints = viewpoints.toArray(new String[0]);
+ }
+
+ private <T> List<T> asList(T... elements) {
+ List<T> list = new ArrayList<T>();
+ for (T element : elements)
+ list.add(element);
+ return list;
+ }
+
+ private boolean isVisibleContext(String contextId) {
+ for (MergedArchitectureContext context : ArchitectureDomainManager.getInstance().getVisibleArchitectureContexts()) {
+ if (context.getId().equals(contextId))
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ *
+ * @param parent
+ */
+ @Override
+ public void createControl(Composite parent) {
+ Composite comp = createComposite(parent, 1, 1, GridData.FILL_BOTH, 0, 0);
+ ((GridData) comp.getLayoutData()).widthHint = 350;
+ createVerticalSpacer(comp, 1);
+ setControl(comp);
+
+ ArchitectureDomainManager manager = ArchitectureDomainManager.getInstance();
+ MergedArchitectureContext[] contexts;
+ //if (allowSeveralContexts || manager.getDefaultArchitectureContext() == null)
+ contexts = manager.getVisibleArchitectureContexts().toArray(new MergedArchitectureContext[0]);
+ //else
+ //contexts = new ArchitectureContext[] { manager.getDefaultArchitectureContext() };
+
+ final ArchitectureContextComposite acc = new ArchitectureContextComposite(comp, 1, 1, GridData.FILL_BOTH, 0, 0);
+ acc.setAllowSeveralContexts(allowSeveralContexts);
+ acc.setSelectedContexts(selectedContexts);
+ acc.setSelectedViewpoints(selectedViewpoints);
+ acc.setInput(contexts);
+ acc.setUpdater(new ArchitectureContextComposite.Updater() {
+ @Override
+ public void update() {
+ selectedContexts = acc.getSelectedContexts();
+ selectedViewpoints = acc.getSelectedViewpoints();
+ updateButtons();
+ }
+ });
+ updateButtons();
+ }
+
+ @Override
+ public void performHelp() {
+ PlatformUI.getWorkbench().getHelpSystem().displayHelp("org.eclipse.papyrus.uml.diagram.wizards.Category"); //$NON-NLS-1$
+ }
+
+ /**
+ * Gets the selected architecture contexts.
+ *
+ * @return the architecture contexts
+ */
+ public String[] getSelectedContexts() {
+ return selectedContexts;
+ }
+
+ /**
+ * Respond to completion of the wizard. Includes saving settings for the next
+ * invocation of the wizard.
+ *
+ * @since 2.0
+ */
+ public void performFinish() {
+ settingsHelper.saveArchitectureContexts(selectedContexts);
+ }
+
+ public String[] getSelectContexts() {
+ return selectedContexts;
+ }
+
+ public String[] getSelectViewpoints() {
+ return selectedViewpoints;
+ }
+
+ private void updateButtons() {
+ setPageComplete(selectedContexts.length!=0 && validatePage());
+ }
+
+ /**
+ * Validate page.
+ *
+ * @return true, if successful
+ */
+ protected boolean validatePage() {
+ setMessage(null);
+ setErrorMessage(null);
+ String[] categories = selectedContexts;
+ if (categories == null || categories.length == 0) {
+ setErrorMessage(Messages.SelectArchitectureContextPage_select_one_category);
+ return false;
+ }
+ if (!validateFileExtension(categories)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Validate file extension.
+ *
+ * @param categories
+ * the categories
+ * @return true, if successful
+ */
+ protected boolean validateFileExtension(String... contexts) {
+ IStatus status = ((CreateModelWizard) getWizard()).architectureContextChanged(contexts);
+ switch (status.getSeverity()) {
+ case Status.WARNING:
+ setMessage(status.getMessage(), IMessageProvider.WARNING);
+ break;
+ case IStatus.INFO:
+ setMessage(status.getMessage(), IMessageProvider.INFORMATION);
+ break;
+ }
+ return true;
+ }
+
+ private static Composite createComposite(Composite parent, int columns, int hspan, int fill, int marginwidth, int marginheight) {
+ Composite g = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(columns, false);
+ layout.marginWidth = marginwidth;
+ layout.marginHeight = marginheight;
+ g.setLayout(layout);
+ g.setFont(parent.getFont());
+ GridData gd = new GridData(fill);
+ gd.horizontalSpan = hspan;
+ g.setLayoutData(gd);
+ return g;
+ }
+
+ private static void createVerticalSpacer(Composite parent, int numlines) {
+ Label lbl = new Label(parent, SWT.NONE);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ Layout layout = parent.getLayout();
+ if (layout instanceof GridLayout) {
+ gd.horizontalSpan = ((GridLayout) parent.getLayout()).numColumns;
+ }
+ gd.heightHint = numlines;
+ lbl.setLayoutData(gd);
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectDiagramCategoryPage.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectDiagramCategoryPage.java
deleted file mode 100644
index d63a662ade0..00000000000
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectDiagramCategoryPage.java
+++ /dev/null
@@ -1,471 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2016 CEA LIST, 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:
- * Tatiana Fesenko (CEA LIST) - Initial API and implementation
- * Christian W. Damus - bugs 466850, 490936
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.wizards.pages;
-
-import java.text.Collator;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.IMessageProvider;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.wizard.IWizard;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.papyrus.uml.diagram.wizards.category.DiagramCategoryDescriptor;
-import org.eclipse.papyrus.uml.diagram.wizards.category.DiagramCategoryRegistry;
-import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
-import org.eclipse.papyrus.uml.diagram.wizards.utils.SettingsHelper;
-import org.eclipse.papyrus.uml.diagram.wizards.wizards.CreateModelWizard;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.ui.PlatformUI;
-
-
-/**
- * The Class SelectDiagramCategoryPage.
- */
-public class SelectDiagramCategoryPage extends WizardPage {
-
- /** The my diagram kind buttons. */
- final private List<Button> myDiagramKindButtons = new ArrayList<Button>();
-
- /** The diagram category. */
- private final List<String> mySelectedDiagramCategoryIds = new LinkedList<String>();
-
- /** The most recently selected category, even if multiple selection is permitted. */
- private String lastSelectedCategory;
-
- /** The Constant PAGE_ID. */
- public static final String PAGE_ID = "SelectDiagramCategory"; //$NON-NLS-1$
-
- /** The Constant DEFAULT_EXTENSION. */
- public static final String DEFAULT_EXTENSION = "uml"; //$NON-NLS-1$
-
- /** uml core languages label */
- private static final List<String> umlCore = Arrays.asList("UML", "Profile"); //$NON-NLS-1$ //$NON-NLS-2$
-
- /** The my allow several categories. */
- private final boolean myAllowSeveralCategories;
-
- private SettingsHelper settingsHelper;
-
- private final Collator collator = Collator.getInstance();
-
-
- /**
- * Instantiates a new select diagram category page.
- *
- */
- public SelectDiagramCategoryPage() {
- this(false);
- }
-
- /**
- * Instantiates a new select diagram category page.
- *
- * @param allowSeveralCategories
- * the allow several categories
- */
- public SelectDiagramCategoryPage(boolean allowSeveralCategories) {
- super(PAGE_ID);
- myAllowSeveralCategories = allowSeveralCategories;
- setTitle(Messages.SelectDiagramCategoryPage_select_language);
- }
-
- /**
- * Sets the wizard.
- *
- * @param newWizard
- * the new wizard
- * @see org.eclipse.jface.wizard.WizardPage#setWizard(org.eclipse.jface.wizard.IWizard)
- */
- @Override
- public void setWizard(IWizard newWizard) {
- super.setWizard(newWizard);
- settingsHelper = new SettingsHelper(getDialogSettings());
- String[] defaultDiagramCategory = settingsHelper.getDefaultDiagramCategories();
-
- if (defaultDiagramCategory != null && defaultDiagramCategory.length > 0) {
- String defaultSelection = Arrays.asList(defaultDiagramCategory).contains(DEFAULT_EXTENSION) ? DEFAULT_EXTENSION : defaultDiagramCategory[0];
- if (myAllowSeveralCategories) {
- setDefaultDiagramCategories(defaultDiagramCategory);
- } else {
- String previousSelection = settingsHelper.getPreviousSelection();
- // Retrieves the previous selection or the selects the default behavior
- if (settingsHelper.rememberCurrentSelection(getDialogSettings()) && previousSelection != null) {
- setDefaultDiagramCategories(new String[] { previousSelection });
- } else {
- setDefaultDiagramCategories(new String[] { defaultSelection });
- }
- }
- }
- }
-
- /**
- * Creates the control.
- *
- * @param parent
- * the parent
- * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
- */
- @Override
- public void createControl(Composite parent) {
- Composite plate = new Composite(parent, SWT.NONE);
- plate.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- GridLayout gridLayout = new GridLayout();
- gridLayout.marginWidth = 10;
- plate.setLayout(gridLayout);
- setControl(plate);
- createDiagramCategoryForm(plate);
-
- // Bug(466850): Do this later because the new-file page's resource group is not yet created
- plate.getDisplay().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- setPageComplete(validatePage());
- }
- });
- }
-
- @Override
- public void setVisible(boolean visible) {
- super.setVisible(visible);
-
- // re-validate in case the user changed the file name on previous page
- setPageComplete(validatePage());
- }
-
-
- /**
- * Gets the diagram categories.
- *
- * @return the diagram categories
- */
- public String[] getDiagramCategories() {
- return mySelectedDiagramCategoryIds.toArray(new String[mySelectedDiagramCategoryIds.size()]);
- }
-
- /**
- * Sets the default diagram categories.
- *
- * @param categories
- * the new default diagram categories
- */
- protected final void setDefaultDiagramCategories(String[] categories) {
- mySelectedDiagramCategoryIds.clear();
- mySelectedDiagramCategoryIds.addAll(Arrays.asList(categories));
- }
-
-
- /**
- * Validate page.
- *
- * @return true, if successful
- */
- protected boolean validatePage() {
- setMessage(null);
- setErrorMessage(null);
- String[] categories = getDiagramCategories();
- if (categories == null || categories.length == 0) {
- setErrorMessage(Messages.SelectDiagramCategoryPage_select_one_category);
- return false;
- }
- if (!validateFileExtension(categories)) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Validate file extension.
- *
- * @param categories
- * the categories
- * @return true, if successful
- */
- protected boolean validateFileExtension(String... categories) {
- IStatus status = ((CreateModelWizard) getWizard()).diagramCategoryChanged(categories);
- switch (status.getSeverity()) {
- // case Status.ERROR:
- // setErrorMessage(status.getMessage());
- // return false;
- case Status.WARNING:
- setMessage(status.getMessage(), IMessageProvider.WARNING);
- break;
- case IStatus.INFO:
- setMessage(status.getMessage(), IMessageProvider.INFORMATION);
- break;
- }
- return true;
- }
-
- /**
- * Gets the diagram category map.
- *
- * @return the diagram category map
- */
- protected Map<String, DiagramCategoryDescriptor> getDiagramCategoryMap() {
- return DiagramCategoryRegistry.getInstance().getDiagramCategoryMap();
- }
-
- /**
- * Creates the diagram language form.
- *
- * @param composite
- * the composite
- */
- private void createDiagramCategoryForm(Composite composite) {
- Group group = createGroup(composite, Messages.SelectDiagramCategoryPage_diagram_language_group);
-
- // To sort the different languages by name
- collator.setStrength(Collator.SECONDARY);
- Comparator<DiagramCategoryDescriptor> setComparator = new Comparator<DiagramCategoryDescriptor>() {
-
- @Override
- public int compare(DiagramCategoryDescriptor descriptor1, DiagramCategoryDescriptor descriptor2) {
- String button1Data = descriptor1.getLabel();
- String button2Data = descriptor2.getLabel();
- // Special consideration for the UML language as it should always be on top
- if (button2Data.equalsIgnoreCase(DEFAULT_EXTENSION)) {
- return 1;
- } else if (button1Data.equalsIgnoreCase(DEFAULT_EXTENSION)) {
- return -1;
- } else {
- // This if the usual sorting method
- return collator.compare(button1Data, button2Data);
- }
- }
-
- };
- // To store the different languages and display them
- SortedSet<DiagramCategoryDescriptor> descriptorUMLSet = new TreeSet<DiagramCategoryDescriptor>(setComparator);
- SortedSet<DiagramCategoryDescriptor> descriptorDSMLSet = new TreeSet<DiagramCategoryDescriptor>(setComparator);
-
- SelectionListener listener = new SelectionListener() {
-
- private SelectionEvent prevEvent;
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- if (e == prevEvent) {
- return;
- }
- Button selected = ((Button) e.widget);
- diagramCategorySelected((String) selected.getData(), selected.getSelection());
- setPageComplete(validatePage());
- prevEvent = e;
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- };
-
- for (DiagramCategoryDescriptor diagramCategoryDescriptor : getDiagramCategoryMap().values()) {
- String descriptorLabel = diagramCategoryDescriptor.getLabel();
- if (umlCore.contains(descriptorLabel)) {
- descriptorUMLSet.add(diagramCategoryDescriptor);
- } else {
- descriptorDSMLSet.add(diagramCategoryDescriptor);
- }
- }
-
- if (!descriptorUMLSet.isEmpty()) {
- Label coreLabel = new Label(group, SWT.NONE);
- coreLabel.setText(Messages.SelectDiagramCategoryPage_umlGroup);
- for (DiagramCategoryDescriptor diagramCategoryDescriptor : descriptorUMLSet) {
- Button button = createCategoryButton(diagramCategoryDescriptor, group);
- button.addSelectionListener(listener);
- myDiagramKindButtons.add(button);
- }
- }
-
- if (!descriptorDSMLSet.isEmpty()) {
- Label dsmlLabel = new Label(group, SWT.NONE);
- dsmlLabel.setText(Messages.SelectDiagramCategoryPage_dsmlGroup);
- for (DiagramCategoryDescriptor diagramCategoryDescriptor : descriptorDSMLSet) {
- Button button = createCategoryButton(diagramCategoryDescriptor, group);
- button.addSelectionListener(listener);
- myDiagramKindButtons.add(button);
- }
- }
-
- checkDiagramCategoryButtons();
- // Initialize the first selection upon opening the wizard
- setDefaultSelection(DEFAULT_EXTENSION);
- }
-
- /**
- * Sets the default language selection based on the DEFAULT_EXTENSION parameter
- *
- * @param defaultExtension
- */
- private void setDefaultSelection(String defaultExtension) {
- String previousSelection = settingsHelper.getPreviousSelection();
- String defaultSelection = previousSelection != null ? previousSelection : defaultExtension;
-
- for (Button button : myDiagramKindButtons) {
- if (defaultSelection.equalsIgnoreCase((String) button.getData())) {
- button.setSelection(true);
- diagramCategorySelected(defaultSelection, button.getSelection());
- }
- }
- }
-
- /**
- * Diagram category selected.
- *
- * @param category
- * the category
- * @param checked
- * the checked
- */
- protected void diagramCategorySelected(String category, boolean checked) {
- if (checked) {
- if (!mySelectedDiagramCategoryIds.contains(category)) {
- if (!myAllowSeveralCategories) {
- // Can only have one selection
- mySelectedDiagramCategoryIds.clear();
- }
- mySelectedDiagramCategoryIds.add(category);
- }
- lastSelectedCategory = category;
- } else {
- mySelectedDiagramCategoryIds.remove(category);
- lastSelectedCategory = mySelectedDiagramCategoryIds.isEmpty()
- ? null
- : mySelectedDiagramCategoryIds.get(mySelectedDiagramCategoryIds.size() - 1);
- }
-
- }
-
- /**
- * Check diagram category buttons.
- */
- protected void checkDiagramCategoryButtons() {
- checkButtonsFor(mySelectedDiagramCategoryIds.toArray(new String[mySelectedDiagramCategoryIds.size()]));
- }
-
- /**
- * Check buttons for.
- *
- * @param diagramCategories
- * the diagram categories
- */
- protected void checkButtonsFor(String... diagramCategories) {
- for (Button button : myDiagramKindButtons) {
- button.setSelection(false);
- }
- for (Button button : myDiagramKindButtons) {
- for (String diagramCategory : diagramCategories) {
- if (diagramCategory.equalsIgnoreCase((String) button.getData())) {
- button.setSelection(true);
- }
- }
- }
- }
-
- /**
- * Creates the category button.
- *
- * @param diagramCategoryDescriptor
- * the diagram category descriptor
- * @param group
- * the group
- * @return the button
- */
- private Button createCategoryButton(DiagramCategoryDescriptor diagramCategoryDescriptor, Group group) {
- Button button = new Button(group, myAllowSeveralCategories ? SWT.CHECK : SWT.RADIO);
- button.setText(diagramCategoryDescriptor.getLabel());
- button.setData(diagramCategoryDescriptor.getId());
- Image image = getImage(diagramCategoryDescriptor.getIcon());
- if (image != null) {
- button.setImage(image);
- }
- button.setToolTipText(diagramCategoryDescriptor.getDescription());
- return button;
- }
-
- /**
- * Gets the image.
- *
- * @param imageDescriptor
- * the image descriptor
- * @return the image
- */
- private static Image getImage(ImageDescriptor imageDescriptor) {
- if (imageDescriptor != null) {
- return new Image(null, imageDescriptor.getImageData());
- }
- return null;
- }
-
- /**
- * Creates the group.
- *
- * @param parent
- * the parent
- * @param name
- * the name
- * @return the group
- */
- private static Group createGroup(Composite parent, String name) {
- Group group = new Group(parent, SWT.NONE);
- group.setText(name);
- GridLayout layout = new GridLayout(1, false);
- layout.marginHeight = 5;
- layout.marginWidth = 5;
- group.setLayout(layout);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
- group.setLayoutData(data);
- return group;
- }
-
- @Override
- public void performHelp() {
- PlatformUI.getWorkbench().getHelpSystem().displayHelp("org.eclipse.papyrus.uml.diagram.wizards.Category"); //$NON-NLS-1$
-
- }
-
- /**
- * Respond to completion of the wizard. Includes saving settings for the next
- * invocation of the wizard.
- *
- * @since 2.0
- */
- public void performFinish() {
- // Notifies the settings file that the selection has been set and to what
- settingsHelper.setCurrentSelection(lastSelectedCategory);
- settingsHelper.saveRememberCurrentSelection(true);
-
- }
-}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectDiagramKindPage.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectRepresentationKindPage.java
index 90f48ab2ee9..24f81732563 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectDiagramKindPage.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectRepresentationKindPage.java
@@ -13,7 +13,9 @@
package org.eclipse.papyrus.uml.diagram.wizards.pages;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IAdaptable;
@@ -29,11 +31,13 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.papyrus.commands.CreationCommandRegistry;
import org.eclipse.papyrus.commands.ICreationCommandRegistry;
-import org.eclipse.papyrus.infra.viewpoints.configuration.Category;
-import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+import org.eclipse.papyrus.infra.core.architecture.RepresentationKind;
+import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureContext;
+import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureViewpoint;
+import org.eclipse.papyrus.infra.architecture.ArchitectureDomainManager;
import org.eclipse.papyrus.uml.diagram.wizards.Activator;
-import org.eclipse.papyrus.uml.diagram.wizards.kind.DiagramKindComposite;
import org.eclipse.papyrus.uml.diagram.wizards.kind.DiagramKindLabelProvider;
+import org.eclipse.papyrus.uml.diagram.wizards.kind.RepresentationKindComposite;
import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
import org.eclipse.papyrus.uml.diagram.wizards.profile.ProfileChooserComposite;
import org.eclipse.papyrus.uml.diagram.wizards.template.ModelTemplateDescription;
@@ -57,7 +61,7 @@ import org.eclipse.uml2.uml.NamedElement;
* @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
* @author Tatiana Fesenko
*/
-public class SelectDiagramKindPage extends WizardPage {
+public class SelectRepresentationKindPage extends WizardPage {
/** The Constant PAGE_ID. */
public static final String PAGE_ID = "SelectDiagramKind"; //$NON-NLS-1$
@@ -69,12 +73,12 @@ public class SelectDiagramKindPage extends WizardPage {
private SelectModelTemplateComposite selectTemplateComposite;
/** the select diagram Kind composite */
- private DiagramKindComposite diagramKindComposite;
+ private RepresentationKindComposite representationKindComposite;
private ProfileChooserComposite profileChooserComposite;
/** The my category provider. */
- private final CategoryProvider myCategoryProvider;
+ private final ViewpointProvider myViewpointProvider;
/** The allow templates. */
private final boolean allowTemplates;
@@ -90,11 +94,11 @@ public class SelectDiagramKindPage extends WizardPage {
/**
* Instantiates a new select diagram kind page.
*
- * @param categoryProvider
+ * @param viewpointProvider
* the category provider
*/
- public SelectDiagramKindPage(CategoryProvider categoryProvider) {
- this(true, categoryProvider, DEFAULT_CREATION_COMMAND_REGISTRY);
+ public SelectRepresentationKindPage(ViewpointProvider viewpointProvider) {
+ this(true, viewpointProvider, DEFAULT_CREATION_COMMAND_REGISTRY);
}
/**
@@ -102,17 +106,17 @@ public class SelectDiagramKindPage extends WizardPage {
*
* @param allowTemplates
* the allow templates
- * @param categoryProvider
+ * @param viewpointProvider
* the category provider
* @param creationCommandRegistry
* the creation command registry
*/
- public SelectDiagramKindPage(boolean allowTemplates, CategoryProvider categoryProvider, ICreationCommandRegistry creationCommandRegistry) {
+ public SelectRepresentationKindPage(boolean allowTemplates, ViewpointProvider viewpointProvider, ICreationCommandRegistry creationCommandRegistry) {
super(PAGE_ID);
- setTitle(Messages.SelectDiagramKindPage_page_title);
- setDescription(Messages.SelectDiagramKindPage_page_desc);
+ setTitle(Messages.SelectRepresentationKindPage_page_title);
+ setDescription(Messages.SelectRepresentationKindPage_page_desc);
this.allowTemplates = allowTemplates;
- myCategoryProvider = categoryProvider;
+ myViewpointProvider = viewpointProvider;
myCreationCommandRegistry = creationCommandRegistry;
}
@@ -127,24 +131,24 @@ public class SelectDiagramKindPage extends WizardPage {
Composite pageComposite = new Composite(parent, SWT.NONE);
pageComposite.setLayout(new GridLayout());
pageComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- String[] categories = getDiagramCategories();
+ String[] viewpoints = getViewpoints();
Composite nameFormComposite = new Composite(pageComposite, SWT.NONE);
nameFormComposite.setLayout(new GridLayout());
nameFormComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
createNameForm(nameFormComposite);
- Composite diagramKindComposite = new Composite(pageComposite, SWT.NONE);
- diagramKindComposite.setLayout(new GridLayout());
- diagramKindComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- createDiagramKindForm(diagramKindComposite);
- this.diagramKindComposite.setInput(categories);
+ Composite representationKindComposite = new Composite(pageComposite, SWT.NONE);
+ representationKindComposite.setLayout(new GridLayout());
+ representationKindComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ createPresentationKindForm(representationKindComposite);
+ this.representationKindComposite.setInput(viewpoints);
Composite modelTemplateComposite = new Composite(pageComposite, SWT.NONE);
modelTemplateComposite.setLayout(new GridLayout());
modelTemplateComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
createModelTemplateComposite(modelTemplateComposite);
- fillInTables(categories);
+ fillInTables(viewpoints);
Composite profileChooserComposite = new Composite(pageComposite, SWT.NONE);
profileChooserComposite.setLayout(new GridLayout());
@@ -160,7 +164,7 @@ public class SelectDiagramKindPage extends WizardPage {
* @param parent
*/
private void createProfileFileChooser(Composite parent) {
- Group group = createGroup(parent, Messages.SelectDiagramKindPage_0);
+ Group group = createGroup(parent, Messages.SelectRepresentationKindPage_0);
profileChooserComposite = new ProfileChooserComposite(group);
profileChooserComposite.getTextField().addModifyListener(new ModifyListener() {
@@ -197,7 +201,7 @@ public class SelectDiagramKindPage extends WizardPage {
public void setVisible(boolean visible) {
super.setVisible(visible);
if (visible) {
- fillInTables(getDiagramCategories());
+ fillInTables(getViewpoints());
validatePage();
// Deactivates the viewer if its contained list is empty
Combo templateCombo = selectTemplateComposite.getTemplateCombo();
@@ -216,15 +220,15 @@ public class SelectDiagramKindPage extends WizardPage {
/**
* Fill in tables.
*
- * @param categories
- * the categories
+ * @param viewpoints
+ * the viewpoints
*/
- private void fillInTables(String[] categories) {
- if (categories == null || categories.length == 0) {
+ private void fillInTables(String[] viewpoints) {
+ if (viewpoints == null || viewpoints.length == 0) {
return;
}
- diagramKindComposite.setInput(categories);
- selectTemplateComposite.setInput(categories);
+ representationKindComposite.setInput(viewpoints);
+ selectTemplateComposite.setInput(viewpoints);
getShell().pack(true);
}
@@ -267,12 +271,12 @@ public class SelectDiagramKindPage extends WizardPage {
}
/**
- * Gets the diagram category.
+ * Gets the viewpoints.
*
- * @return the diagram category
+ * @return the viewpoint
*/
- private String[] getDiagramCategories() {
- return myCategoryProvider.getCurrentCategories();
+ private String[] getViewpoints() {
+ return myViewpointProvider.getCurrentViewpoints();
}
@@ -282,7 +286,7 @@ public class SelectDiagramKindPage extends WizardPage {
* @return the new diagram name
*/
public List<String> getDiagramName() {
- return diagramKindComposite.getDiagramName();
+ return representationKindComposite.getDiagramName();
}
public String getRootElementName() {
@@ -299,24 +303,23 @@ public class SelectDiagramKindPage extends WizardPage {
}
/**
- * Gets the selected command descriptors.
+ * Gets the selected representation kinds for a given viewpoint
*
- * @param categoryId
- * the category id
- * @return the selected command descriptors
+ * @param contextId
+ * the architecture context id
+ * @return the selected repersentation kinds
*/
- public List<ViewPrototype> getSelectedPrototypes(String categoryId) {
- ViewPrototype[] selected = getSelectedPrototypes();
- List<ViewPrototype> commands = new ArrayList<ViewPrototype>();
- for (int i = 0; i < selected.length; i++) {
- for (Category category : selected[i].getCategories()) {
- if (category.getName().equals(categoryId)) {
- commands.add(selected[i]);
- break;
- }
- }
+ public List<RepresentationKind> getSelectedRepresentationKinds(String contextId) {
+ MergedArchitectureContext context = ArchitectureDomainManager.getInstance().getArchitectureContextById(contextId);
+ Set<RepresentationKind> allowedKinds = new HashSet<RepresentationKind>();
+ for (MergedArchitectureViewpoint viewpoint : context.getViewpoints())
+ allowedKinds.addAll(viewpoint.getRepresentationKinds());
+ List<RepresentationKind> selectedKinds = new ArrayList<RepresentationKind>();
+ for (RepresentationKind kind : getSelectedRepresentationKinds()) {
+ if (allowedKinds.contains(kind))
+ selectedKinds.add(kind);
}
- return commands;
+ return selectedKinds;
}
/**
@@ -326,7 +329,7 @@ public class SelectDiagramKindPage extends WizardPage {
* the composite
*/
private void createModelTemplateComposite(Composite composite) {
- Group group = createGroup(composite, Messages.SelectDiagramKindPage_load_template_group);
+ Group group = createGroup(composite, Messages.SelectRepresentationKindPage_load_template_group);
selectTemplateComposite = new SelectModelTemplateComposite(group);
}
@@ -336,9 +339,9 @@ public class SelectDiagramKindPage extends WizardPage {
* @param composite
* the composite
*/
- private void createDiagramKindForm(Composite composite) {
- Group group = createGroup(composite, Messages.SelectDiagramKindPage_select_kind_group);
- diagramKindComposite = new DiagramKindComposite(group);
+ private void createPresentationKindForm(Composite composite) {
+ Group group = createGroup(composite, Messages.SelectRepresentationKindPage_select_kind_group);
+ representationKindComposite = new RepresentationKindComposite(group);
}
/**
@@ -379,10 +382,10 @@ public class SelectDiagramKindPage extends WizardPage {
* the composite
*/
private void createNameForm(Composite composite) {
- Group group = createGroup(composite, Messages.SelectDiagramKindPage_diagram_name_group);
+ Group group = createGroup(composite, Messages.SelectRepresentationKindPage_diagram_name_group);
nameText = new Text(group, SWT.BORDER);
nameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- nameText.setText(Messages.SelectDiagramKindPage_default_diagram_name);
+ nameText.setText(Messages.SelectRepresentationKindPage_default_diagram_name);
ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
if (selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() > 0) {
@@ -407,7 +410,7 @@ public class SelectDiagramKindPage extends WizardPage {
}
}
} catch (Exception e) {
- this.setErrorMessage(Messages.SelectDiagramKindPage_Set_Root_Name_Error);
+ this.setErrorMessage(Messages.SelectRepresentationKindPage_Set_Root_Name_Error);
Activator.log.error(e);
}
}
@@ -440,7 +443,7 @@ public class SelectDiagramKindPage extends WizardPage {
} else {
// Resets the displayed message
this.setErrorMessage(null);
- this.setMessage(Messages.SelectDiagramKindPage_page_desc);
+ this.setMessage(Messages.SelectRepresentationKindPage_page_desc);
}
return true;
}
@@ -461,9 +464,9 @@ public class SelectDiagramKindPage extends WizardPage {
*
* @return the selected diagram kind descriptors
*/
- protected ViewPrototype[] getSelectedPrototypes() {
- List<ViewPrototype> checked = diagramKindComposite.getCheckElement();
- ViewPrototype[] result = checked.toArray(new ViewPrototype[checked.size()]);
+ protected RepresentationKind[] getSelectedRepresentationKinds() {
+ List<RepresentationKind> checked = representationKindComposite.getCheckElement();
+ RepresentationKind[] result = checked.toArray(new RepresentationKind[checked.size()]);
return result;
}
@@ -478,16 +481,16 @@ public class SelectDiagramKindPage extends WizardPage {
}
/**
- * The Interface CategoryProvider.
+ * The Interface ViewpointProvider.
*/
- public static interface CategoryProvider {
+ public static interface ViewpointProvider {
/**
* Gets the current categories.
*
* @return the current categories
*/
- String[] getCurrentCategories();
+ String[] getCurrentViewpoints();
}
public List<ModelTemplateDescription> getTemplateTransfo() {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/AbstractNewModelStorageProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/AbstractNewModelStorageProvider.java
index 57b6f267488..9bb947845ee 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/AbstractNewModelStorageProvider.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/AbstractNewModelStorageProvider.java
@@ -18,7 +18,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.ui.URIEditorInput;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramCategoryPage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectArchitectureContextPage;
import org.eclipse.papyrus.uml.diagram.wizards.wizards.CreateModelWizard;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
@@ -33,7 +33,7 @@ public abstract class AbstractNewModelStorageProvider implements INewModelStorag
// pass
}
- public IStatus validateDiagramCategories(String... newCategories) {
+ public IStatus validateArchitectureContexts(String... newContexts) {
return Status.OK_STATUS;
}
@@ -52,7 +52,7 @@ public abstract class AbstractNewModelStorageProvider implements INewModelStorag
return null;
}
- public SelectDiagramCategoryPage getDiagramCategoryPage() {
+ public SelectArchitectureContextPage getArchitectureContextPage() {
return null;
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/INewModelStorageProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/INewModelStorageProvider.java
index 8d9c93a1475..860356a8cf0 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/INewModelStorageProvider.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/INewModelStorageProvider.java
@@ -17,7 +17,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramCategoryPage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectArchitectureContextPage;
import org.eclipse.papyrus.uml.diagram.wizards.wizards.CreateModelWizard;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -48,7 +48,7 @@ public interface INewModelStorageProvider {
List<? extends IWizardPage> createPages();
- IStatus validateDiagramCategories(String... newCategories);
+ IStatus validateArchitectureContexts(String... newContexts);
/**
* Create the URI identifying a new model, as indicated by my wizard page
@@ -85,7 +85,7 @@ public interface INewModelStorageProvider {
*/
ISelectProviderPart createSelectProviderPart();
- SelectDiagramCategoryPage getDiagramCategoryPage();
+ SelectArchitectureContextPage getArchitectureContextPage();
//
// Nested types
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/NewModelStorageProviderRegistry.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/NewModelStorageProviderRegistry.java
index 3e0402f268f..b9dacc1501d 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/NewModelStorageProviderRegistry.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/NewModelStorageProviderRegistry.java
@@ -30,7 +30,7 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.papyrus.uml.diagram.wizards.Activator;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramCategoryPage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectArchitectureContextPage;
import org.eclipse.papyrus.uml.diagram.wizards.wizards.CreateModelWizard;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.services.IEvaluationService;
@@ -181,8 +181,8 @@ public class NewModelStorageProviderRegistry implements Iterable<NewModelStorage
return getInstance().createEditorInput(uri);
}
- public IStatus validateDiagramCategories(String... newCategories) {
- return getInstance().validateDiagramCategories(newCategories);
+ public IStatus validateArchitectureContexts(String... newContexts) {
+ return getInstance().validateArchitectureContexts(newContexts);
}
public ISelectProviderPart createSelectProviderPart() {
@@ -200,10 +200,10 @@ public class NewModelStorageProviderRegistry implements Iterable<NewModelStorage
}
}
- public SelectDiagramCategoryPage getDiagramCategoryPage() {
- return getInstance().getDiagramCategoryPage();
+ public SelectArchitectureContextPage getArchitectureContextPage() {
+ return getInstance().getArchitectureContextPage();
}
- }
+}
private static final class NullProvider extends AbstractNewModelStorageProvider {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/WorkspaceNewModelStorageProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/WorkspaceNewModelStorageProvider.java
index f0c46d56cfd..0594ca88dd4 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/WorkspaceNewModelStorageProvider.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/providers/WorkspaceNewModelStorageProvider.java
@@ -28,7 +28,7 @@ import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.papyrus.commands.Activator;
import org.eclipse.papyrus.uml.diagram.wizards.pages.NewDiagramForExistingModelPage;
import org.eclipse.papyrus.uml.diagram.wizards.pages.NewModelFilePage;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramCategoryPage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectArchitectureContextPage;
import org.eclipse.papyrus.uml.diagram.wizards.utils.WizardsHelper;
import org.eclipse.papyrus.uml.diagram.wizards.wizards.CreateModelWizard;
import org.eclipse.papyrus.uml.diagram.wizards.wizards.InitModelWizard;
@@ -43,7 +43,7 @@ public class WorkspaceNewModelStorageProvider extends AbstractNewModelStoragePro
/** New model file page for the file. */
private NewModelFilePage newModelFilePage;
- private SelectDiagramCategoryPage newDiagramCategoryPage;
+ private SelectArchitectureContextPage newSelectArchitectureContextPage;
public WorkspaceNewModelStorageProvider() {
super();
@@ -69,33 +69,33 @@ public class WorkspaceNewModelStorageProvider extends AbstractNewModelStoragePro
this.wizard = wizard;
newModelFilePage = createNewModelFilePage(selection);
- newDiagramCategoryPage = createNewDiagramCategoryPage(selection);
+ newSelectArchitectureContextPage = createNewArchitectureContextPage(selection);
}
@Override
public List<? extends IWizardPage> createPages() {
- if (newModelFilePage == null && newDiagramCategoryPage == null) {
+ if (newModelFilePage == null && newSelectArchitectureContextPage == null) {
return Collections.emptyList();
}
- return Arrays.asList(newDiagramCategoryPage, newModelFilePage);
+ return Arrays.asList(newSelectArchitectureContextPage, newModelFilePage);
}
@Override
- public IStatus validateDiagramCategories(String... newCategories) {
+ public IStatus validateArchitectureContexts(String... newContexts) {
if (newModelFilePage != null) {
- String firstCategory = newCategories.length > 0 ? newCategories[0] : null;
- if (newCategories.length > 0) {
+ String firstContext = newContexts.length > 0 ? newContexts[0] : null;
+ if (newContexts.length > 0) {
// 316943 - [Wizard] Wrong suffix for file name when creating a
// profile model
- return newModelFilePage.diagramExtensionChanged(wizard.getDiagramFileExtension(firstCategory));
+ return newModelFilePage.diagramExtensionChanged(wizard.getDiagramFileExtension(firstContext));
}
}
- return super.validateDiagramCategories(newCategories);
+ return super.validateArchitectureContexts(newContexts);
}
/**
@@ -152,18 +152,16 @@ public class WorkspaceNewModelStorageProvider extends AbstractNewModelStoragePro
// return (newFile == null) ? null :
}
- private SelectDiagramCategoryPage createNewDiagramCategoryPage(IStructuredSelection selection) {
+ private SelectArchitectureContextPage createNewArchitectureContextPage(IStructuredSelection selection) {
if (wizard.isCreateProjectWizard() || wizard.isCreateMultipleModelsWizard() || !wizard.isPapyrusRootWizard()) {
-
return null;
}
- return new SelectDiagramCategoryPage();
+ return new SelectArchitectureContextPage();
}
@Override
- public SelectDiagramCategoryPage getDiagramCategoryPage() {
- return this.newDiagramCategoryPage;
+ public SelectArchitectureContextPage getArchitectureContextPage() {
+ return this.newSelectArchitectureContextPage;
}
-
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/utils/SettingsHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/utils/SettingsHelper.java
index 1f28d479a92..c0784feb83a 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/utils/SettingsHelper.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/utils/SettingsHelper.java
@@ -1,216 +1,56 @@
-/*****************************************************************************
- * 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:
- * Thibault Le Ouay (Sherpa Engineering) t.leouay@sherpa-eng.com - Initial API and implementation
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.diagram.wizards.utils;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.StringTokenizer;
-
-import org.eclipse.jface.dialogs.IDialogSettings;
-
-
-public class SettingsHelper {
-
- /** The Constant DIAGRAM_KIND_SEPARATOR. */
- private static final String DIAGRAM_KIND_SEPARATOR = ","; //$NON-NLS-1$
-
- /** The Constant TEMPLATE_SEPARATOR. */
- private static final String TEMPLATE_SEPARATOR = ","; //$NON-NLS-1$
-
- /** The Constant SETTINGS_KEY_REMEMBER_CURRENT_SELECTION. */
- private static final String SETTINGS_KEY_REMEMBER_CURRENT_SELECTION = "RememberCurrentSelection"; //$NON-NLS-1$
-
- /** The Constant SETTINGS_KEY_DIAGRAM_KINDS. */
- private static final String SETTINGS_KEY_DIAGRAM_KINDS = "DiagramKindsFor_"; //$NON-NLS-1$
-
- /** The Constant SETTINGS_KEY_DIAGRAM_TEMPLATES. */
- private static final String SETTINGS_KEY_DIAGRAM_TEMPLATES = "DiagramTemplatesFor_"; //$NON-NLS-1$
-
- /** The Constant LAST_SELECTED_CATEGORY. */
- private static final String DIAGRAM_CATEGORIES = "diagramCategory"; //$NON-NLS-1$
-
- /** The Constant used to access the last selected category */
- private static final String SETTINGS_KEY_DIAGRAM_CATEGORY = "lastSelectedCategory"; //$NON-NLS-1$
-
- /** The my settings. */
- private final IDialogSettings mySettings;
-
- /**
- * Instantiates a new settings utils.
- *
- * @param settings
- * the settings
- */
- public SettingsHelper(IDialogSettings settings) {
- mySettings = settings;
- }
-
- /**
- * Gets the default diagram category.
- *
- * @return the default diagram category
- */
- public String[] getDefaultDiagramCategories() {
- return mySettings.getArray(DIAGRAM_CATEGORIES);
- }
-
- /**
- * Save default diagram category.
- *
- * @param categories
- * the categories
- */
- public void saveDefaultDiagramCategory(String[] categories) {
- mySettings.put(DIAGRAM_CATEGORIES, categories);
- }
-
- /**
- * Gets the default diagram kinds.
- *
- * @param category
- * the category
- * @return the default diagram kinds
- */
- public List<String> getDefaultDiagramKinds(String category) {
- String csl = mySettings.get(getKeyForDiagramKind(category));
- if (csl == null || csl.equals("")) { //$NON-NLS-1$
- return Collections.emptyList();
- }
- List<String> result = new ArrayList<String>();
- StringTokenizer tokenizer = new StringTokenizer(csl, DIAGRAM_KIND_SEPARATOR);
- while (tokenizer.hasMoreTokens()) {
- result.add(tokenizer.nextToken().trim());
- }
- return result;
- }
-
- /**
- * Save default diagram kinds.
- *
- * @param category
- * the category
- * @param kinds
- * the kinds
- */
- public void saveDefaultDiagramKinds(String category, List<String> kinds) {
- String value = ""; //$NON-NLS-1$
- for (String kind : kinds) {
- value += kind;
- value += DIAGRAM_KIND_SEPARATOR;
- }
- mySettings.put(getKeyForDiagramKind(category), value);
- }
-
- /**
- * Gets the default templates.
- *
- * @param category
- * the category
- * @return the default templates
- */
- public List<String> getDefaultTemplates(String category) {
- String csl = mySettings.get(getKeyForTemplate(category));
- if (csl == null || csl.equals("")) { //$NON-NLS-1$
- return Collections.emptyList();
- }
- List<String> result = new ArrayList<String>();
- StringTokenizer tokenizer = new StringTokenizer(csl, TEMPLATE_SEPARATOR);
- while (tokenizer.hasMoreTokens()) {
- result.add(tokenizer.nextToken().trim());
- }
- return result;
- }
-
- /**
- * Save default templates.
- *
- * @param category
- * the category
- * @param templates
- * the templates
- */
- public void saveDefaultTemplates(String category, List<String> templates) {
- String value = ""; //$NON-NLS-1$
- for (String template : templates) {
- value += template;
- value += TEMPLATE_SEPARATOR;
- }
- mySettings.put(getKeyForTemplate(category), value);
- }
-
- /**
- * Save remember current selection.
- *
- * @param remember
- * the remember
- */
- public void saveRememberCurrentSelection(boolean remember) {
- mySettings.put(SETTINGS_KEY_REMEMBER_CURRENT_SELECTION, remember);
- }
-
- /**
- * Remember current selection.
- *
- * @param settings
- * the settings
- * @return true, if successful
- */
- public boolean rememberCurrentSelection(IDialogSettings settings) {
- return mySettings.getBoolean(SETTINGS_KEY_REMEMBER_CURRENT_SELECTION);
- }
-
- /**
- * Puts the most recently selected category tag in the settings to retrieve it on the next execution
- *
- * @param category
- * The language tag
- */
- public void setCurrentSelection(String category) {
- mySettings.put(SETTINGS_KEY_DIAGRAM_CATEGORY, category);
- }
-
- /**
- * Retrieves the most recently selected category tag from the settings
- *
- * @return
- * The category tag
- */
- public String getPreviousSelection() {
- return mySettings.get(SETTINGS_KEY_DIAGRAM_CATEGORY);
- }
-
-
- /**
- * Gets the key for diagram kind.
- *
- * @param category
- * the category
- * @return the key for diagram kind
- */
- private String getKeyForDiagramKind(String category) {
- return SETTINGS_KEY_DIAGRAM_KINDS + category;
- }
-
- /**
- * Gets the key for template.
- *
- * @param category
- * the category
- * @return the key for template
- */
- private String getKeyForTemplate(String category) {
- return SETTINGS_KEY_DIAGRAM_TEMPLATES + category;
- }
-
-}
+/*****************************************************************************
+ * 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:
+ * Thibault Le Ouay (Sherpa Engineering) t.leouay@sherpa-eng.com - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.wizards.utils;
+
+import org.eclipse.jface.dialogs.IDialogSettings;
+
+
+public class SettingsHelper {
+
+ /** The Constant ARCHITECTURE_CONTEXTS. */
+ private static final String ARCHITECTURE_CONTEXTS = "architectureContexts"; //$NON-NLS-1$
+
+ /** The my settings. */
+ private final IDialogSettings mySettings;
+
+ /**
+ * Instantiates a new settings utils.
+ *
+ * @param settings
+ * the settings
+ */
+ public SettingsHelper(IDialogSettings settings) {
+ mySettings = settings;
+ }
+
+ /**
+ * Gets the saved architecture contexts.
+ *
+ * @return the saved architecture contexts
+ */
+ public String[] getArchitectureContexts() {
+ String[] contexts = mySettings.getArray(ARCHITECTURE_CONTEXTS);
+ return (contexts != null) ? contexts : new String[0];
+ }
+
+ /**
+ * Save the given architecture contexts.
+ *
+ * @param contexts
+ * the architecture contexts
+ */
+ public void saveArchitectureContexts(String[] contexts) {
+ mySettings.put(ARCHITECTURE_CONTEXTS, contexts);
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateModelWizard.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateModelWizard.java
index e58e8608847..fb9c9c50299 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateModelWizard.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateModelWizard.java
@@ -1,966 +1,1001 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2016 Obeo, CEA LIST, 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:
- * Obeo - initial API and implementation
- * Tatiana Fesenko(CEA) - [313179] Refactor CreateModelWizard
- * Saadia Dhouib (CEA LIST) - Implementation of loading diagrams from template files (.uml, .di , .notation)
- * Christian W. Damus (CEA) - create models by URI, not IFile (CDO)
- * Christian W. Damus (CEA) - Support creating models in repositories (CDO)
- * Christian W. Damus - bug 490936
- *
- *******************************************************************************/
-package org.eclipse.papyrus.uml.diagram.wizards.wizards;
-
-import static org.eclipse.papyrus.uml.diagram.wizards.Activator.log;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.common.command.CommandStack;
-import org.eclipse.emf.common.ui.URIEditorInput;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.jface.dialogs.IDialogSettings;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.papyrus.infra.core.editor.BackboneException;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModelUtils;
-import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager;
-import org.eclipse.papyrus.infra.core.services.ExtensionServicesRegistry;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.ui.extension.commands.IModelCreationCommand;
-import org.eclipse.papyrus.infra.ui.util.EditorUtils;
-import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
-import org.eclipse.papyrus.uml.diagram.wizards.Activator;
-import org.eclipse.papyrus.uml.diagram.wizards.category.DiagramCategoryDescriptor;
-import org.eclipse.papyrus.uml.diagram.wizards.category.DiagramCategoryRegistry;
-import org.eclipse.papyrus.uml.diagram.wizards.command.InitFromTemplateCommand;
-import org.eclipse.papyrus.uml.diagram.wizards.command.NewPapyrusModelCommand;
-import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.NewModelFilePage;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.PapyrusProjectCreationPage;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramCategoryPage;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramKindPage;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramKindPage.CategoryProvider;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectStorageProviderPage;
-import org.eclipse.papyrus.uml.diagram.wizards.providers.INewModelStorageProvider;
-import org.eclipse.papyrus.uml.diagram.wizards.providers.NewModelStorageProviderRegistry;
-import org.eclipse.papyrus.uml.diagram.wizards.providers.WorkspaceNewModelStorageProvider;
-import org.eclipse.papyrus.uml.diagram.wizards.template.ModelTemplateDescription;
-import org.eclipse.papyrus.uml.diagram.wizards.transformation.IGenerator;
-import org.eclipse.papyrus.uml.tools.commands.ApplyProfileCommand;
-import org.eclipse.papyrus.uml.tools.commands.RenameElementCommand;
-import org.eclipse.papyrus.uml.tools.model.UmlModel;
-import org.eclipse.papyrus.uml.tools.model.UmlUtils;
-import org.eclipse.ui.IEditorDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.INewWizard;
-import org.eclipse.ui.IURIEditorInput;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.ide.IDE;
-import org.eclipse.ui.services.IEvaluationService;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Profile;
-
-/**
- * Create new model file and initialize a selected diagram. This wizard create
- * several files :
- * <li>*.di : the DI file to store Di diagrams and references all external diagrams like GMF diagrams.</li>
- * <li>*.notation : the file to store pure GMF diagrams</li>
- * <li>*.uml : the standard UML file to store UML semantics elements. (Model,
- * Package, Class,...)</li>
- *
- * Those files can be used with the PapyrusEditor (see plugin.xml).
- */
-public class CreateModelWizard extends Wizard implements INewWizard {
-
- /** The Constant WIZARD_ID. */
- public static final String WIZARD_ID = "org.eclipse.papyrus.uml.diagram.wizards.createmodel"; //$NON-NLS-1$
-
- /** The Constant NEW_MODEL_SETTINGS. */
- public static final String NEW_MODEL_SETTINGS = "NewModelWizard"; //$NON-NLS-1$
-
- private SelectStorageProviderPage selectStorageProviderPage;
-
- /** Select kind of new diagram the wizard must create. */
- private SelectDiagramKindPage selectDiagramKindPage;
-
- /** The select diagram category page. */
- protected SelectDiagramCategoryPage selectDiagramCategoryPage;
-
- /** Current workbench. */
- private IWorkbench workbench;
-
- private NewModelStorageProviderRegistry storageProviderRegistry;
-
- private INewModelStorageProvider selectedStorageProvider;
-
- private Map<INewModelStorageProvider, List<IWizardPage>> providerPages = new java.util.HashMap<INewModelStorageProvider, List<IWizardPage>>();
-
- private Map<IWizardPage, INewModelStorageProvider> providersByPage = new java.util.HashMap<IWizardPage, INewModelStorageProvider>();
-
- private int startProviderPageIndex; // index of last page before provider pages
-
- private int endProviderPageIndex; // index of first page after provider pages
-
- protected IWizardPage newProjectPage;
-
- protected static final String EXTENSION_POINT_ID = "org.eclipse.papyrus.uml.diagram.wizards.templates"; //$NON-NLS-1$
-
- /**
- * Instantiates a new creates the model wizard.
- */
- public CreateModelWizard() {
- super();
- setWindowTitle(Messages.CreateModelWizard_new_papyrus_model_title);
- setDefaultPageImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/papyrus/PapyrusWizban_75x66.gif")); //$NON-NLS-1$
- // setHelpAvailable(true);
-
- }
-
- /**
- * Adds the pages.
- *
- * {@inheritDoc}
- */
- @Override
- public void addPages() {
- // ModelCreation: the selectDiagramCategoryPage exists
- if (selectedStorageProvider.getDiagramCategoryPage() == null) {
- addPageIfNotNull(selectDiagramCategoryPage);
- } else {
- addPageIfNotNull(selectedStorageProvider.getDiagramCategoryPage());
- }
-
- // The selectStorageProviderPage is only set if a model is created, cf initStorageProvider(IWorkbench, IStructuredSelection)
- // The storage page for a project, newProjectPage, is handled by the PapyrusProjectCreationPage
- addPageIfNotNull(selectStorageProviderPage);
- addPageIfNotNull(newProjectPage);
-
- startProviderPageIndex = getPageCount() - 1;
- for (INewModelStorageProvider next : getStorageProviders()) {
- List<IWizardPage> pageList = new java.util.ArrayList<IWizardPage>(3);
- for (IWizardPage page : next.createPages()) {
- if (page != null) {
- pageList.add(page);
- providersByPage.put(page, next);
- if (!page.equals(selectedStorageProvider.getDiagramCategoryPage())) {
- addPage(page);
- }
- }
- }
- providerPages.put(next, pageList);
- }
- endProviderPageIndex = getPageCount();
-
- addPageIfNotNull(selectDiagramKindPage);
- }
-
- protected void setNewProjectPage(IWizardPage page) {
- this.newProjectPage = page;
- }
-
- /**
- * Adds the page if not null.
- *
- * @param page
- * the page
- */
- protected final void addPageIfNotNull(IWizardPage page) {
- if (page != null) {
- addPage(page);
- }
- }
-
- public boolean isInitModelWizard() {
- return false;
- }
-
- public boolean isCreateProjectWizard() {
- return false;
- }
-
- public boolean isCreateMultipleModelsWizard() {
- return false;
- }
-
- /**
- * Inits the.
- *
- * @param workbench
- * the workbench
- * @param selection
- * the selection {@inheritDoc}
- */
- @Override
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- this.workbench = workbench;
-
- initStorageProvider(workbench, selection);
-
- IDialogSettings workbenchSettings = Activator.getDefault().getDialogSettings();
- IDialogSettings section = workbenchSettings.getSection(NEW_MODEL_SETTINGS);
- if (section == null) {
- section = workbenchSettings.addNewSection(NEW_MODEL_SETTINGS);
- }
- setDialogSettings(section);
-
- selectStorageProviderPage = createSelectStorageProviderPage();
-
- for (INewModelStorageProvider next : getStorageProviders()) {
- next.init(this, selection);
- }
-
- selectDiagramKindPage = createSelectDiagramKindPage();
- }
-
- /**
- * Perform finish.
- *
- * @return true, if successful {@inheritDoc}
- */
- @Override
- public boolean performFinish() {
- String[] diagramCategoryIds = getDiagramCategoryIds();
- if (diagramCategoryIds.length == 0) {
- return false;
- }
-
- SelectDiagramCategoryPage selectDiagramCategoryPage = getSelectDiagramCategoryPage();
- if (selectDiagramCategoryPage != null) {
- selectDiagramCategoryPage.performFinish();
- }
-
- String diagramCategoryId = diagramCategoryIds[0];
- final URI newURI = createNewModelURI(diagramCategoryId);
-
- createAndOpenPapyrusModel(newURI, diagramCategoryId);
-
- return true;
- }
-
- protected URI createNewModelURI(String diagramCategoryID) {
- return getSelectedStorageProvider().createNewModelURI(diagramCategoryID);
- }
-
- /**
- * Creates the and open papyrus model.
- *
- * @param modelSet
- * the di resource set
- * @param newURI
- * the URI of the new model's principal resource
- * @param diagramCategoryId
- * the diagram category id
- * @return true, if successful
- */
- protected boolean createAndOpenPapyrusModel(URI newURI, String diagramCategoryId) {
-
- if (newURI == null) {
- return false;
- }
-
- ServicesRegistry registry = createServicesRegistry();
- if (registry == null) {
- return false;
- }
-
- try {
- // have to create the model set and populate it with the DI model
- // before initializing other services that actually need the DI
- // model, such as the SashModel Manager service
- ModelSet modelSet = registry.getService(ModelSet.class);
-
- createPapyrusModels(modelSet, newURI);
-
- initServicesRegistry(registry);
-
- initDomainModel(modelSet, newURI, diagramCategoryId);
-
- initDiagramModel(modelSet, diagramCategoryId);
-
- initProfile(modelSet);
-
- initTemplate(modelSet);
-
- saveDiagram(modelSet);
-
- openDiagram(newURI);
-
- } catch (ServiceException e) {
- Activator.log.error(e);
- this.selectDiagramKindPage.setErrorMessage(e.getMessage());
- return false;
-
- } finally {
- try {
- registry.disposeRegistry();
- } catch (ServiceException ex) {
- // Ignore
- }
- }
-
- return true;
- }
-
- private void initProfile(ModelSet modelSet) {
- boolean isToApplyProfile = selectDiagramKindPage.getProfileURI() != null;
- boolean isProfileDefined = selectDiagramKindPage.getProfileDefinitionStatus().isOK();
- if (isToApplyProfile & isProfileDefined) {
- applyProfile(modelSet);
- }
- }
-
- private void initTemplate(ModelSet modelSet) {
- boolean isToInitFromTemplateTransfo = selectDiagramKindPage.getTemplateTransfo().size() > 0;
- if (isToInitFromTemplateTransfo) {
- applyTemplateTransfo(modelSet);
- }
- }
-
- protected ServicesRegistry createServicesRegistry() {
- ServicesRegistry result = null;
-
- try {
- result = new ExtensionServicesRegistry(org.eclipse.papyrus.infra.core.Activator.PLUGIN_ID);
- } catch (ServiceException e) {
- // couldn't create the registry? Fatal problem
- Activator.log.error(e);
- }
-
- try {
- // have to create the model set and populate it with the DI model
- // before initializing other services that actually need the DI
- // model, such as the SashModel Manager service
- result.startServicesByClassKeys(ModelSet.class);
- } catch (ServiceException ex) {
- // Ignore this exception: some services may not have been loaded,
- // which is probably normal at this point
- }
-
- return result;
- }
-
- protected void initServicesRegistry(ServicesRegistry registry) throws ServiceException {
- try {
- registry.startRegistry();
- } catch (ServiceException ex) {
- // Ignore this exception: some services may not have been loaded,
- // which is probably normal at this point
- }
-
- registry.getService(IPageManager.class);
- }
-
- /**
- * Gets the diagram category ids.
- *
- * @return the diagram category ids
- */
- protected String[] getDiagramCategoryIds() {
- SelectDiagramCategoryPage page = getSelectDiagramCategoryPage();
- if (page != null) {
- return page.getDiagramCategories();
- }
- return null;
- }
-
- private SelectDiagramCategoryPage getSelectDiagramCategoryPage() {
- return (selectDiagramCategoryPage != null)
- ? selectDiagramCategoryPage
- : (selectedStorageProvider != null)
- ? selectedStorageProvider.getDiagramCategoryPage()
- : null;
- }
-
- /**
- * Gets the diagram file extension.
- *
- * @param diagramCategoryId
- * the diagram category id
- * @return the diagram file extension
- */
- public String getDiagramFileExtension(String diagramCategoryId) {
- return getDiagramFileExtension(diagramCategoryId, NewModelFilePage.DEFAULT_DIAGRAM_EXTENSION);
- }
-
- /**
- * Gets the diagram file extension.
- *
- * @param categoryId
- * the category id
- * @param defaultExtension
- * the default extension
- * @return the diagram file extension
- */
- public String getDiagramFileExtension(String categoryId, String defaultExtension) {
- DiagramCategoryDescriptor diagramCategory = getDiagramCategoryMap().get(categoryId);
- String extensionPrefix = diagramCategory != null ? diagramCategory.getExtensionPrefix() : null;
- return (extensionPrefix != null) ? extensionPrefix + "." + defaultExtension : defaultExtension; //$NON-NLS-1$
- }
-
- /**
- * Creates the select diagram category page.
- *
- * @return the select diagram category page
- */
- protected SelectDiagramCategoryPage createSelectDiagramCategoryPage() {
- return new SelectDiagramCategoryPage();
- }
-
- /**
- * Creates the select diagram kind page.
- *
- * @return the select diagram kind page
- */
- protected SelectDiagramKindPage createSelectDiagramKindPage() {
- return new SelectDiagramKindPage(new CategoryProvider() {
-
- @Override
- public String[] getCurrentCategories() {
- return getDiagramCategoryIds();
- }
-
- });
- }
-
- /**
- * Inits the domain model.
- *
- * @param modelSet
- * the di resource set
- * @param newURI
- * the URI of the new model's principal resource
- * @param diagramCategoryId
- * the diagram category id
- */
- protected void initDomainModel(ModelSet modelSet, final URI newURI, String diagramCategoryId) {
-
- boolean isToInitFromTemplate = selectDiagramKindPage.getTemplatePath() != null;
- if (isToInitFromTemplate) {
- initDomainModelFromTemplate(modelSet);
- } else {
- createEmptyDomainModel(modelSet, diagramCategoryId);
- }
- }
-
- protected void applyProfile(ModelSet modelSet) {
- String profilePath = selectDiagramKindPage.getProfileURI();
- Resource resource = modelSet.getResource(URI.createURI(profilePath), true);
- Profile profileToApply = (Profile) resource.getContents().get(0);
-
- Resource myModelUMLResource = UmlUtils.getUmlResource(modelSet);
- org.eclipse.uml2.uml.Package manipulatedModel = (org.eclipse.uml2.uml.Package) myModelUMLResource.getContents().get(0);
-
- RecordingCommand applyProfileCommand = new ApplyProfileCommand(manipulatedModel, profileToApply, modelSet.getTransactionalEditingDomain());
- getCommandStack(modelSet).execute(applyProfileCommand);
- }
-
- protected void applyTemplateTransfo(ModelSet modelSet) {
- List<ModelTemplateDescription> templateList = selectDiagramKindPage.getTemplateTransfo();
- // // This is an example of the use of QVT Transformations
- // QVToGenerator generator = new QVToGenerator();
- //
- // for (final ModelTemplateDescription currentTemplate : templateList) {
- // // fetches the tranformation URI encoded in the extension point, if it has that attribute
- // // generator.setTransformationURI(URI.createPlatformPluginURI("org.eclipse.papyrus.uml.diagram.wizards/transforms/UMLCopyTemplateTransfo.qvto", true));//$NON-NLS-1$
- // generator.setTransformationURI(URI.createPlatformPluginURI(currentTemplate.getTransfoURI(), true));
- // generator.setModelSet(modelSet);
- // generator.setTemplateModel(currentTemplate.getUml_path());
- // generator.setPluginId(currentTemplate.getPluginId());
- // generator.execute();
- // }
-
- // This is an example of transformations without using the QVToGenerator
- // TODO make it prettier
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- // get all the extensions configured into the extension point corresponding to the 'templates' Point ID from the 'org.eclipse.papyrus.uml.diagram.wizards' plugin
- IExtension[] extensions = registry.getExtensionPoint(EXTENSION_POINT_ID).getExtensions();
-
- for (IExtension extension : extensions) {
- for (IConfigurationElement configElement : extension.getConfigurationElements()) {
- if ("template".equals(configElement.getName())) { //$NON-NLS-1$
- // not handled here
- } else if ("transformation".equals(configElement.getName())) { //$NON-NLS-1$
- for (ModelTemplateDescription currentTemplate : templateList) {
- if (currentTemplate.getName().equals(configElement.getAttribute("name"))) { //$NON-NLS-1$
- IGenerator iGenerator;
- try {
- iGenerator = (IGenerator) configElement.createExecutableExtension("Transformation"); //$NON-NLS-1$
- iGenerator.setModelSet(modelSet);
- iGenerator.execute();
- } catch (CoreException e) {
- Activator.log.error(e);
- }
- }
- }
-
- }
- }
- }
-
- }
-
- /**
- * Inits the domain model from template.
- *
- * @param modelSet
- * the di resource set
- */
- protected void initDomainModelFromTemplate(ModelSet modelSet) {
- getCommandStack(modelSet).execute(
- new InitFromTemplateCommand(modelSet.getTransactionalEditingDomain(), modelSet, selectDiagramKindPage.getTemplatePluginId(), selectDiagramKindPage.getTemplatePath(), selectDiagramKindPage.getNotationTemplatePath(), selectDiagramKindPage
- .getDiTemplatePath()));
- }
-
- /**
- * Creates the empty domain model.
- *
- * @param modelSet
- * the di resource set
- * @param diagramCategoryId
- * the diagram category id
- */
- protected void createEmptyDomainModel(ModelSet modelSet, String diagramCategoryId) {
- try {
- IModelCreationCommand creationCommand = getDiagramCategoryMap().get(diagramCategoryId).getCommand();
- creationCommand.createModel(modelSet);
- } catch (BackboneException e) {
- log.error(e);
- }
- }
-
- /**
- * Creates the papyrus models.
- *
- * @param modelSet
- * the di resource set
- * @param newURI
- * the URI of the new model's principal resource
- */
- protected void createPapyrusModels(ModelSet modelSet, URI newURI) {
- RecordingCommand command = new NewPapyrusModelCommand(modelSet, newURI);
- getCommandStack(modelSet).execute(command);
- }
-
-
- /**
- * Open diagram.
- *
- * @param newURI
- * the URI of the new model's principal resource
- */
- protected void openDiagram(final URI newURI) {
- IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
- if (page != null) {
- try {
- IEditorInput editorInput = createEditorInput(newURI);
- IDE.openEditor(page, editorInput, getPreferredEditorID(editorInput), true);
- } catch (PartInitException e) {
- log.error(e);
- }
- }
- }
-
- protected IEditorInput createEditorInput(URI uri) {
- return getSelectedStorageProvider().createEditorInput(uri);
- }
-
- protected String getPreferredEditorID(IEditorInput input) throws PartInitException {
- IEditorDescriptor desc;
-
- if (input instanceof IFileEditorInput) {
- desc = IDE.getEditorDescriptor(((IFileEditorInput) input).getFile());
- } else {
- // try to get a URI
- URI uri = null;
- if (input instanceof IURIEditorInput) {
- uri = URI.createURI(((IURIEditorInput) input).getURI().toString(), true);
- } else if (input instanceof URIEditorInput) {
- uri = ((URIEditorInput) input).getURI();
- }
-
- if (uri != null) {
- desc = IDE.getEditorDescriptor(uri.lastSegment());
- } else {
- // hope that the input name is the file name
- desc = IDE.getEditorDescriptor(input.getName());
- }
- }
-
- return (desc == null) ? "org.eclipse.papyrus.infra.core.papyrusEditor" : desc.getId(); //$NON-NLS-1$
- }
-
- /**
- * Inits the diagram model.
- *
- * @param modelSet
- * the di resource set
- * @param categoryId
- * the category id
- */
- protected void initDiagramModel(ModelSet modelSet, String categoryId) {
- initDiagrams(modelSet, categoryId);
- }
-
-
- /**
- * Save diagram.
- *
- * @param modelSet
- * the di resource set
- */
- private void saveDiagram(ModelSet modelSet) {
- // TODO verify that there are no conflicts with the existing files and the newly created one
- try {
- modelSet.save(new NullProgressMonitor());
- } catch (IOException e) {
- log.error(e);
- }
- }
-
- /**
- * Inits the diagrams.
- *
- * @param modelSet
- * the di resource set
- * @param categoryId
- * the category id
- */
- protected void initDiagrams(ModelSet modelSet, String categoryId) {
- initDiagrams(modelSet, null, categoryId);
- }
-
- /**
- * Inits the diagrams.
- *
- * @param resourceSet
- * the resource set
- * @param root
- * the root
- * @param categoryId
- * the category id
- */
- protected void initDiagrams(ModelSet resourceSet, EObject root, String categoryId) {
- UmlModel model = (UmlModel) resourceSet.getModel(UmlModel.MODEL_ID);
- EList<EObject> roots = model.getResource().getContents();
- if (!roots.isEmpty()) {
- root = roots.get(0);
- if (root instanceof NamedElement) {
- getCommandStack(resourceSet).execute(new RenameElementCommand(resourceSet.getTransactionalEditingDomain(), (NamedElement) root, getRootElementName()));
-
- }
-
- }
- List<ViewPrototype> creationCommands = getPrototypesFor(categoryId);
- List<String> diagramName = selectDiagramKindPage.getDiagramName();
- if (creationCommands.isEmpty()) {
- createEmptyDiagramEditor(resourceSet);
- } else {
- for (int i = 0; i < creationCommands.size(); i++) {
- creationCommands.get(i).instantiateOn(root, diagramName.get(i));
- }
- }
- }
-
- /**
- * Gets the diagram kinds for.
- *
- * @param categoryId
- * the category id
- * @return the diagram kinds for
- */
- protected List<ViewPrototype> getPrototypesFor(String categoryId) {
- return selectDiagramKindPage.getSelectedPrototypes(categoryId);
- }
-
-
- protected List<String> getDiagramNames() {
- return selectDiagramKindPage.getDiagramName();
- }
-
- protected String getRootElementName() {
- return selectDiagramKindPage.getRootElementName();
- }
-
- /**
- * Creates the empty diagram editor.
- *
- * @param modelSet
- * the model set
- */
- private void createEmptyDiagramEditor(ModelSet modelSet) {
- // Create an empty editor (no diagrams opened)
- // Geting an IPageMngr is enough to initialize the
- // SashSystem.
- EditorUtils.getIPageMngr(DiModelUtils.getDiResource(modelSet));
- }
-
- /**
- * Gets the command stack.
- *
- * @param modelSet
- * the model set
- * @return the command stack
- */
- protected final CommandStack getCommandStack(ModelSet modelSet) {
- return modelSet.getTransactionalEditingDomain().getCommandStack();
- }
-
- /**
- * Gets the diagram category map.
- *
- * @return the diagram category map
- */
- protected Map<String, DiagramCategoryDescriptor> getDiagramCategoryMap() {
- return DiagramCategoryRegistry.getInstance().getDiagramCategoryMap();
- }
-
- /**
- * Diagram category changed.
- *
- * @param newCategories
- * the new categories
- * @return the i status
- */
- public IStatus diagramCategoryChanged(String... newCategories) {
- return getSelectedStorageProvider().validateDiagramCategories(newCategories);
- }
-
- protected void initStorageProvider(IWorkbench workbench, IStructuredSelection selection) {
-
- NewModelStorageProviderRegistry registry = new NewModelStorageProviderRegistry(workbench.getService(IEvaluationService.class));
-
- // if we are creating a project, then it is in the workspace
- if (isCreateProjectWizard()) {
- this.selectedStorageProvider = new WorkspaceNewModelStorageProvider();
- } else {
- // look for a pre-determined selection
- INewModelStorageProvider firstProvider = null;
- for (INewModelStorageProvider next : registry) {
- if (firstProvider == null) {
- firstProvider = next;
- }
-
- // don't match on empty selections because there is
- // then no context to match against
- if (!selection.isEmpty() && next.canHandle(selection)) {
- this.selectedStorageProvider = next;
- break;
- }
- }
-
- // if the choice is pre-determined, don't show the selection page
- if (this.selectedStorageProvider == null) {
- this.selectedStorageProvider = firstProvider;
-
- // don't need the selection page if only one choice
- if (registry.size() > 1) {
- this.storageProviderRegistry = registry;
- }
- }
- }
- }
-
- protected SelectStorageProviderPage createSelectStorageProviderPage() {
- SelectStorageProviderPage result = (storageProviderRegistry == null) ? null : new SelectStorageProviderPage(storageProviderRegistry);
-
- if (result != null) {
- result.addSelectionChangedListener(new ISelectionChangedListener() {
-
- @Override
- public void selectionChanged(SelectionChangedEvent event) {
- INewModelStorageProvider provider = (INewModelStorageProvider) ((IStructuredSelection) event.getSelection()).getFirstElement();
- setSelectedStorageProvider(provider);
- }
- });
- }
-
- return result;
- }
-
- protected Iterable<? extends INewModelStorageProvider> getStorageProviders() {
- Iterable<? extends INewModelStorageProvider> result;
-
- if (storageProviderRegistry != null) {
- result = storageProviderRegistry;
- } else if (selectedStorageProvider != null) {
- result = Collections.singletonList(selectedStorageProvider);
- } else {
- result = Collections.emptyList();
- }
-
- return result;
- }
-
- protected INewModelStorageProvider getSelectedStorageProvider() {
- return selectedStorageProvider;
- }
-
- private void setSelectedStorageProvider(INewModelStorageProvider provider) {
- this.selectedStorageProvider = provider;
-
- // recompute next/previous buttons
- getContainer().updateButtons();
- }
-
- @Override
- public IWizardPage getNextPage(IWizardPage page) {
- final List<IWizardPage> allPages = Arrays.asList(getPages());
- IWizardPage result = null;
-
- INewModelStorageProvider provider = providersByPage.get(page);
- if (provider != null) {
- // it's contributed by a provider. Get the next in the list
- List<IWizardPage> pages = providerPages.get(provider);
- int index = pages.indexOf(page);
- if ((index >= 0) && (index < (pages.size() - 1))) {
- result = pages.get(index + 1);
- } else {
- // get the first page after the provider pages
- if (endProviderPageIndex < allPages.size()) {
- result = allPages.get(endProviderPageIndex);
- }
- }
- } else if (allPages.indexOf(page) == startProviderPageIndex) {
- // get the first page of the selected provider
- List<IWizardPage> pages = providerPages.get(getSelectedStorageProvider());
- if (!pages.isEmpty()) {
- result = pages.get(0);
- } else {
- // get the first page after the provider pages
- if (endProviderPageIndex < allPages.size()) {
- result = allPages.get(endProviderPageIndex);
- }
- }
- } else {
- // somewhere away from the boundary of the provider pages
- result = super.getNextPage(page);
- }
-
- return result;
- }
-
- @Override
- public IWizardPage getPreviousPage(IWizardPage page) {
- final List<IWizardPage> allPages = Arrays.asList(getPages());
- IWizardPage result = null;
-
- INewModelStorageProvider provider = providersByPage.get(page);
- if (provider != null) {
- // it's contributed by a provider. Get the previous in the list
- List<IWizardPage> pages = providerPages.get(provider);
- int index = pages.indexOf(page);
- if (index > 0) {
- result = pages.get(index - 1);
- } else {
- // get the last page before the provider pages
- if (startProviderPageIndex > 0) {
- result = allPages.get(startProviderPageIndex - 1);
- }
- }
- } else if (allPages.indexOf(page) == endProviderPageIndex) {
- // get the last page of the selected provider
- List<IWizardPage> pages = providerPages.get(getSelectedStorageProvider());
- if (!pages.isEmpty()) {
- result = pages.get(pages.size() - 1);
- } else {
- // get the last page before the provider pages
- if (startProviderPageIndex >= 0) {
- result = allPages.get(startProviderPageIndex);
- }
- }
- } else {
- // somewhere away from the boundary of the provider pages
- result = super.getPreviousPage(page);
- }
-
- return result;
- }
-
- @Override
- public boolean canFinish() {
- boolean result = true;
- final IWizardPage[] allPages = getPages();
-
- // only look at the universal pages and those contributed by the current
- // storage provider
-
- for (int i = 0; result && (i <= startProviderPageIndex); i++) {
- result = allPages[i].isPageComplete();
- }
-
- if (result) {
- for (IWizardPage next : providerPages.get(selectedStorageProvider)) {
- if (!next.isPageComplete()) {
- result = false;
- break;
- }
- }
- }
-
- for (int i = endProviderPageIndex; result && (i < allPages.length); i++) {
- result = allPages[i].isPageComplete();
- }
-
- // This takes care of the case problems when creating a model with the same name but different case
- for (IWizardPage page : allPages) {
- if (page instanceof NewModelFilePage) {
- return page.canFlipToNextPage();
- }
- if (page instanceof PapyrusProjectCreationPage) {
- return page.canFlipToNextPage();
- }
- }
-
- return result;
- }
-
- /**
- * Queries the user-presentable (translatable) name of the kind of model
- * that I create. For example, "Papyrus UML" or "Papyrus SysML".
- *
- * @return my model kind name
- */
- public String getModelKindName() {
- return "Papyrus"; //$NON-NLS-1$
- }
-
- @Deprecated
- protected void saveDiagramCategorySettings() {
-
- }
-
- public boolean isPapyrusRootWizard() {
- // this.getClass().getName().equals(anObject)
- return true;
- }
-
-
-}
+/*******************************************************************************
+ * Copyright (c) 2008, 2016 Obeo, CEA LIST, 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:
+ * Obeo - initial API and implementation
+ * Tatiana Fesenko(CEA) - [313179] Refactor CreateModelWizard
+ * Saadia Dhouib (CEA LIST) - Implementation of loading diagrams from template files (.uml, .di , .notation)
+ * Christian W. Damus (CEA) - create models by URI, not IFile (CDO)
+ * Christian W. Damus (CEA) - Support creating models in repositories (CDO)
+ * Christian W. Damus - bug 490936
+ *
+ *******************************************************************************/
+package org.eclipse.papyrus.uml.diagram.wizards.wizards;
+
+import static org.eclipse.papyrus.uml.diagram.wizards.Activator.log;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CommandStack;
+import org.eclipse.emf.common.ui.URIEditorInput;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.papyrus.infra.core.architecture.RepresentationKind;
+import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureContext;
+import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureViewpoint;
+import org.eclipse.papyrus.infra.architecture.representation.PapyrusRepresentationKind;
+import org.eclipse.papyrus.infra.architecture.ArchitectureDomainManager;
+import org.eclipse.papyrus.infra.architecture.ArchitectureDescriptionUtils;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModelUtils;
+import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager;
+import org.eclipse.papyrus.infra.core.services.ExtensionServicesRegistry;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.ui.util.EditorUtils;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+import org.eclipse.papyrus.uml.diagram.wizards.Activator;
+import org.eclipse.papyrus.uml.diagram.wizards.command.InitFromTemplateCommand;
+import org.eclipse.papyrus.uml.diagram.wizards.command.NewPapyrusModelCommand;
+import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.NewModelFilePage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.PapyrusProjectCreationPage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectArchitectureContextPage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectRepresentationKindPage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectRepresentationKindPage.ViewpointProvider;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectStorageProviderPage;
+import org.eclipse.papyrus.uml.diagram.wizards.providers.INewModelStorageProvider;
+import org.eclipse.papyrus.uml.diagram.wizards.providers.NewModelStorageProviderRegistry;
+import org.eclipse.papyrus.uml.diagram.wizards.providers.WorkspaceNewModelStorageProvider;
+import org.eclipse.papyrus.uml.diagram.wizards.template.ModelTemplateDescription;
+import org.eclipse.papyrus.uml.diagram.wizards.transformation.IGenerator;
+import org.eclipse.papyrus.uml.tools.commands.ApplyProfileCommand;
+import org.eclipse.papyrus.uml.tools.commands.RenameElementCommand;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.papyrus.uml.tools.model.UmlUtils;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IURIEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.services.IEvaluationService;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Profile;
+
+/**
+ * Create new model file and initialize a selected diagram. This wizard create
+ * several files :
+ * <li>*.di : the DI file to store Di diagrams and references all external diagrams like GMF diagrams.</li>
+ * <li>*.notation : the file to store pure GMF diagrams</li>
+ * <li>*.uml : the standard UML file to store UML semantics elements. (Model,
+ * Package, Class,...)</li>
+ *
+ * Those files can be used with the PapyrusEditor (see plugin.xml).
+ */
+public class CreateModelWizard extends Wizard implements INewWizard {
+
+ /** The Constant WIZARD_ID. */
+ public static final String WIZARD_ID = "org.eclipse.papyrus.uml.diagram.wizards.createmodel"; //$NON-NLS-1$
+
+ /** The Constant NEW_MODEL_SETTINGS. */
+ public static final String NEW_MODEL_SETTINGS = "NewModelWizard"; //$NON-NLS-1$
+
+ private SelectStorageProviderPage selectStorageProviderPage;
+
+ /** Select kind of new diagram the wizard must create. */
+ private SelectRepresentationKindPage selectRepresentationKindPage;
+
+ /** The select architecture context page. */
+ protected SelectArchitectureContextPage selectArchitectureContextPage;
+
+ /** Current workbench. */
+ private IWorkbench workbench;
+
+ private NewModelStorageProviderRegistry storageProviderRegistry;
+
+ private INewModelStorageProvider selectedStorageProvider;
+
+ private Map<INewModelStorageProvider, List<IWizardPage>> providerPages = new java.util.HashMap<INewModelStorageProvider, List<IWizardPage>>();
+
+ private Map<IWizardPage, INewModelStorageProvider> providersByPage = new java.util.HashMap<IWizardPage, INewModelStorageProvider>();
+
+ private int startProviderPageIndex; // index of last page before provider pages
+
+ private int endProviderPageIndex; // index of first page after provider pages
+
+ protected IWizardPage newProjectPage;
+
+ protected static final String EXTENSION_POINT_ID = "org.eclipse.papyrus.uml.diagram.wizards.templates"; //$NON-NLS-1$
+
+ /**
+ * Instantiates a new creates the model wizard.
+ */
+ public CreateModelWizard() {
+ super();
+ setWindowTitle(Messages.CreateModelWizard_new_papyrus_model_title);
+ setDefaultPageImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/papyrus/PapyrusWizban_75x66.gif")); //$NON-NLS-1$
+ // setHelpAvailable(true);
+
+ }
+
+ /**
+ * Adds the pages.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void addPages() {
+ // ModelCreation: the selectDiagramCategoryPage exists
+ if (selectedStorageProvider.getArchitectureContextPage() != null) {
+ addPageIfNotNull(selectedStorageProvider.getArchitectureContextPage());
+ } else {
+ addPageIfNotNull(selectArchitectureContextPage);
+ }
+
+ // The selectStorageProviderPage is only set if a model is created, cf initStorageProvider(IWorkbench, IStructuredSelection)
+ // The storage page for a project, newProjectPage, is handled by the PapyrusProjectCreationPage
+ addPageIfNotNull(selectStorageProviderPage);
+ addPageIfNotNull(newProjectPage);
+
+ startProviderPageIndex = getPageCount() - 1;
+ for (INewModelStorageProvider next : getStorageProviders()) {
+ List<IWizardPage> pageList = new java.util.ArrayList<IWizardPage>(3);
+ for (IWizardPage page : next.createPages()) {
+ if (page != null) {
+ pageList.add(page);
+ providersByPage.put(page, next);
+ if (!page.equals(selectedStorageProvider.getArchitectureContextPage())) {
+ addPage(page);
+ }
+ }
+ }
+ providerPages.put(next, pageList);
+ }
+ endProviderPageIndex = getPageCount();
+
+ addPageIfNotNull(selectRepresentationKindPage);
+ }
+
+ protected void setNewProjectPage(IWizardPage page) {
+ this.newProjectPage = page;
+ }
+
+ /**
+ * Adds the page if not null.
+ *
+ * @param page
+ * the page
+ */
+ protected final void addPageIfNotNull(IWizardPage page) {
+ if (page != null) {
+ addPage(page);
+ }
+ }
+
+ public boolean isInitModelWizard() {
+ return false;
+ }
+
+ public boolean isCreateProjectWizard() {
+ return false;
+ }
+
+ public boolean isCreateMultipleModelsWizard() {
+ return false;
+ }
+
+ /**
+ * Inits the.
+ *
+ * @param workbench
+ * the workbench
+ * @param selection
+ * the selection {@inheritDoc}
+ */
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.workbench = workbench;
+
+ initStorageProvider(workbench, selection);
+
+ IDialogSettings workbenchSettings = Activator.getDefault().getDialogSettings();
+ IDialogSettings section = workbenchSettings.getSection(NEW_MODEL_SETTINGS);
+ if (section == null) {
+ section = workbenchSettings.addNewSection(NEW_MODEL_SETTINGS);
+ }
+ setDialogSettings(section);
+
+ selectStorageProviderPage = createSelectStorageProviderPage();
+
+ for (INewModelStorageProvider next : getStorageProviders()) {
+ next.init(this, selection);
+ }
+
+ selectRepresentationKindPage = createSelectRepresentationKindPage();
+ }
+
+ /**
+ * Perform finish.
+ *
+ * @return true, if successful {@inheritDoc}
+ */
+ @Override
+ public boolean performFinish() {
+ String[] contextIds = getSelectedContexts();
+ if (contextIds.length == 0) {
+ return false;
+ }
+
+ SelectArchitectureContextPage selectArchitectureContextPage = getSelectArchitectureContextPage();
+ if (selectArchitectureContextPage != null) {
+ selectArchitectureContextPage.performFinish();
+ }
+
+ String contextId = contextIds[0];
+ final URI newURI = createNewModelURI(contextId);
+
+ String[] viewpointIds = getSelectedViewpoints(contextId);
+ createAndOpenPapyrusModel(newURI, contextId, viewpointIds);
+
+ return true;
+ }
+
+ protected URI createNewModelURI(String contextId) {
+ return getSelectedStorageProvider().createNewModelURI(contextId);
+ }
+
+ /**
+ * Creates the and open papyrus model.
+ *
+ * @param modelSet
+ * the di resource set
+ * @param newURI
+ * the URI of the new model's principal resource
+ * @param contextId
+ * the architecture context id
+ * @param viewpointIds
+ * the architecture viewpoint ids
+ * @return true, if successful
+ */
+ protected boolean createAndOpenPapyrusModel(URI newURI, String contextId, String[] viewpointIds) {
+
+ if (newURI == null) {
+ return false;
+ }
+
+ ServicesRegistry registry = createServicesRegistry();
+ if (registry == null) {
+ return false;
+ }
+
+ try {
+ // have to create the model set and populate it with the DI model
+ // before initializing other services that actually need the DI
+ // model, such as the SashModel Manager service
+ ModelSet modelSet = registry.getService(ModelSet.class);
+
+ createPapyrusModels(modelSet, newURI);
+
+ initServicesRegistry(registry);
+
+ initDomainModel(modelSet, contextId, viewpointIds);
+
+ initDiagramModel(modelSet, contextId);
+
+ initProfile(modelSet);
+
+ initTemplate(modelSet);
+
+ saveDiagram(modelSet);
+
+ openDiagram(newURI);
+
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ this.selectRepresentationKindPage.setErrorMessage(e.getMessage());
+ return false;
+
+ } finally {
+ try {
+ registry.disposeRegistry();
+ } catch (ServiceException ex) {
+ // Ignore
+ }
+ }
+
+ return true;
+ }
+
+ private void initProfile(ModelSet modelSet) {
+ boolean isToApplyProfile = selectRepresentationKindPage.getProfileURI() != null;
+ boolean isProfileDefined = selectRepresentationKindPage.getProfileDefinitionStatus().isOK();
+ if (isToApplyProfile & isProfileDefined) {
+ applyProfile(modelSet);
+ }
+ }
+
+ private void initTemplate(ModelSet modelSet) {
+ boolean isToInitFromTemplateTransfo = selectRepresentationKindPage.getTemplateTransfo().size() > 0;
+ if (isToInitFromTemplateTransfo) {
+ applyTemplateTransfo(modelSet);
+ }
+ }
+
+ protected ServicesRegistry createServicesRegistry() {
+ ServicesRegistry result = null;
+
+ try {
+ result = new ExtensionServicesRegistry(org.eclipse.papyrus.infra.core.Activator.PLUGIN_ID);
+ } catch (ServiceException e) {
+ // couldn't create the registry? Fatal problem
+ Activator.log.error(e);
+ }
+
+ try {
+ // have to create the model set and populate it with the DI model
+ // before initializing other services that actually need the DI
+ // model, such as the SashModel Manager service
+ result.startServicesByClassKeys(ModelSet.class);
+ } catch (ServiceException ex) {
+ // Ignore this exception: some services may not have been loaded,
+ // which is probably normal at this point
+ }
+
+ return result;
+ }
+
+ protected void initServicesRegistry(ServicesRegistry registry) throws ServiceException {
+ try {
+ registry.startRegistry();
+ } catch (ServiceException ex) {
+ // Ignore this exception: some services may not have been loaded,
+ // which is probably normal at this point
+ }
+
+ registry.getService(IPageManager.class);
+ }
+
+ /**
+ * Gets the selected context ids.
+ *
+ * @return the context ids
+ */
+ protected String[] getSelectedContexts() {
+ SelectArchitectureContextPage page = getSelectArchitectureContextPage();
+ if (page != null) {
+ return page.getSelectedContexts();
+ }
+ return null;
+ }
+
+ /**
+ * Gets the viewpoint ids.
+ *
+ * @return the viewpoint ids
+ */
+ protected String[] getSelectedViewpoints() {
+ SelectArchitectureContextPage page = getSelectArchitectureContextPage();
+ if (page != null) {
+ return page.getSelectViewpoints();
+ }
+ return null;
+ }
+
+ /**
+ * Gets the viewpoint ids.
+ *
+ * @return the viewpoint ids
+ */
+ protected String[] getSelectedViewpoints(String contextId) {
+ ArchitectureDomainManager manager = ArchitectureDomainManager.getInstance();
+ MergedArchitectureContext context = manager.getArchitectureContextById(contextId);
+ List<String> availableViewpoints = new ArrayList<String>();
+ for (MergedArchitectureViewpoint viewpoint : context.getViewpoints()) {
+ availableViewpoints.add(viewpoint.getId());
+ }
+ List<String> selectedViewpoints = Arrays.asList(getSelectedViewpoints());
+ selectedViewpoints.retainAll(availableViewpoints);
+ return selectedViewpoints.toArray(new String[0]);
+ }
+
+ private SelectArchitectureContextPage getSelectArchitectureContextPage() {
+ return (selectArchitectureContextPage != null)
+ ? selectArchitectureContextPage
+ : (selectedStorageProvider != null)
+ ? selectedStorageProvider.getArchitectureContextPage()
+ : null;
+ }
+
+ /**
+ * Gets the diagram file extension.
+ *
+ * @param diagramCategoryId
+ * the diagram category id
+ * @return the diagram file extension
+ */
+ public String getDiagramFileExtension(String contextId) {
+ return getDiagramFileExtension(contextId, NewModelFilePage.DEFAULT_DIAGRAM_EXTENSION);
+ }
+
+ /**
+ * Gets the diagram file extension.
+ *
+ * @param contextId
+ * the context id
+ * @param defaultExtension
+ * the default extension
+ * @return the diagram file extension
+ */
+ public String getDiagramFileExtension(String contextId, String defaultExtension) {
+ MergedArchitectureContext context = ArchitectureDomainManager.getInstance().getArchitectureContextById(contextId);
+ String extensionPrefix = context != null ? context.getExtensionPrefix() : null;
+ return (extensionPrefix != null) ? extensionPrefix + "." + defaultExtension : defaultExtension; //$NON-NLS-1$
+ }
+
+ /**
+ * Creates the select architecture context page.
+ *
+ * @return the select architecture context page
+ */
+ protected SelectArchitectureContextPage createSelectArchitectureContextPage() {
+ return new SelectArchitectureContextPage();
+ }
+
+ /**
+ * Creates the select representation kind page.
+ *
+ * @return the select representation kind page
+ */
+ protected SelectRepresentationKindPage createSelectRepresentationKindPage() {
+ return new SelectRepresentationKindPage(new ViewpointProvider() {
+
+ @Override
+ public String[] getCurrentViewpoints() {
+ return getSelectedViewpoints();
+ }
+
+ });
+ }
+
+ /**
+ * Inits the domain model.
+ *
+ * @param modelSet
+ * the di resource set
+ * @param contextId
+ * the architecture context id
+ * @param viewpointIds
+ * the architecture viewpoint ids
+ */
+ protected void initDomainModel(ModelSet modelSet, String contextId, String[] viewpointIds) {
+
+ boolean isToInitFromTemplate = selectRepresentationKindPage.getTemplatePath() != null;
+ if (isToInitFromTemplate) {
+ initDomainModelFromTemplate(modelSet);
+ } else {
+ createEmptyDomainModel(modelSet, contextId, viewpointIds);
+ }
+ }
+
+ protected void applyProfile(ModelSet modelSet) {
+ String profilePath = selectRepresentationKindPage.getProfileURI();
+ Resource resource = modelSet.getResource(URI.createURI(profilePath), true);
+ Profile profileToApply = (Profile) resource.getContents().get(0);
+
+ Resource myModelUMLResource = UmlUtils.getUmlResource(modelSet);
+ org.eclipse.uml2.uml.Package manipulatedModel = (org.eclipse.uml2.uml.Package) myModelUMLResource.getContents().get(0);
+
+ RecordingCommand applyProfileCommand = new ApplyProfileCommand(manipulatedModel, profileToApply, modelSet.getTransactionalEditingDomain());
+ getCommandStack(modelSet).execute(applyProfileCommand);
+ }
+
+ protected void applyTemplateTransfo(ModelSet modelSet) {
+ List<ModelTemplateDescription> templateList = selectRepresentationKindPage.getTemplateTransfo();
+ // // This is an example of the use of QVT Transformations
+ // QVToGenerator generator = new QVToGenerator();
+ //
+ // for (final ModelTemplateDescription currentTemplate : templateList) {
+ // // fetches the tranformation URI encoded in the extension point, if it has that attribute
+ // // generator.setTransformationURI(URI.createPlatformPluginURI("org.eclipse.papyrus.uml.diagram.wizards/transforms/UMLCopyTemplateTransfo.qvto", true));//$NON-NLS-1$
+ // generator.setTransformationURI(URI.createPlatformPluginURI(currentTemplate.getTransfoURI(), true));
+ // generator.setModelSet(modelSet);
+ // generator.setTemplateModel(currentTemplate.getUml_path());
+ // generator.setPluginId(currentTemplate.getPluginId());
+ // generator.execute();
+ // }
+
+ // This is an example of transformations without using the QVToGenerator
+ // TODO make it prettier
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ // get all the extensions configured into the extension point corresponding to the 'templates' Point ID from the 'org.eclipse.papyrus.uml.diagram.wizards' plugin
+ IExtension[] extensions = registry.getExtensionPoint(EXTENSION_POINT_ID).getExtensions();
+
+ for (IExtension extension : extensions) {
+ for (IConfigurationElement configElement : extension.getConfigurationElements()) {
+ if ("template".equals(configElement.getName())) { //$NON-NLS-1$
+ // not handled here
+ } else if ("transformation".equals(configElement.getName())) { //$NON-NLS-1$
+ for (ModelTemplateDescription currentTemplate : templateList) {
+ if (currentTemplate.getName().equals(configElement.getAttribute("name"))) { //$NON-NLS-1$
+ IGenerator iGenerator;
+ try {
+ iGenerator = (IGenerator) configElement.createExecutableExtension("Transformation"); //$NON-NLS-1$
+ iGenerator.setModelSet(modelSet);
+ iGenerator.execute();
+ } catch (CoreException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Inits the domain model from template.
+ *
+ * @param modelSet
+ * the di resource set
+ */
+ protected void initDomainModelFromTemplate(ModelSet modelSet) {
+ getCommandStack(modelSet).execute(
+ new InitFromTemplateCommand(modelSet.getTransactionalEditingDomain(), modelSet, selectRepresentationKindPage.getTemplatePluginId(), selectRepresentationKindPage.getTemplatePath(), selectRepresentationKindPage.getNotationTemplatePath(), selectRepresentationKindPage
+ .getDiTemplatePath()));
+ }
+
+ /**
+ * Creates the empty domain model.
+ *
+ * @param modelSet
+ * the di resource set
+ * @param contextId
+ * the architecture context id
+ * @param viewpointIds
+ * the architecture viewpoint ids
+ */
+ protected void createEmptyDomainModel(ModelSet modelSet, String contextId, String[] viewpointIds) {
+ try {
+ ArchitectureDescriptionUtils helper = new ArchitectureDescriptionUtils(modelSet);
+ Command command = helper.createNewModel(contextId, viewpointIds);
+ getCommandStack(modelSet).execute(command);
+ } catch (Exception e) {
+ log.error(e);
+ }
+ }
+
+ /**
+ * Creates the papyrus models.
+ *
+ * @param modelSet
+ * the di resource set
+ * @param newURI
+ * the URI of the new model's principal resource
+ */
+ protected void createPapyrusModels(ModelSet modelSet, URI newURIs) {
+ RecordingCommand command = new NewPapyrusModelCommand(modelSet, newURIs);
+ getCommandStack(modelSet).execute(command);
+ }
+
+
+ /**
+ * Open diagram.
+ *
+ * @param newURI
+ * the URI of the new model's principal resource
+ */
+ protected void openDiagram(final URI newURI) {
+ IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
+ if (page != null) {
+ try {
+ IEditorInput editorInput = createEditorInput(newURI);
+ IDE.openEditor(page, editorInput, getPreferredEditorID(editorInput), true);
+ } catch (PartInitException e) {
+ log.error(e);
+ }
+ }
+ }
+
+ protected IEditorInput createEditorInput(URI uri) {
+ return getSelectedStorageProvider().createEditorInput(uri);
+ }
+
+ protected String getPreferredEditorID(IEditorInput input) throws PartInitException {
+ IEditorDescriptor desc;
+
+ if (input instanceof IFileEditorInput) {
+ desc = IDE.getEditorDescriptor(((IFileEditorInput) input).getFile());
+ } else {
+ // try to get a URI
+ URI uri = null;
+ if (input instanceof IURIEditorInput) {
+ uri = URI.createURI(((IURIEditorInput) input).getURI().toString(), true);
+ } else if (input instanceof URIEditorInput) {
+ uri = ((URIEditorInput) input).getURI();
+ }
+
+ if (uri != null) {
+ desc = IDE.getEditorDescriptor(uri.lastSegment());
+ } else {
+ // hope that the input name is the file name
+ desc = IDE.getEditorDescriptor(input.getName());
+ }
+ }
+
+ return (desc == null) ? "org.eclipse.papyrus.infra.core.papyrusEditor" : desc.getId(); //$NON-NLS-1$
+ }
+
+ /**
+ * Inits the diagram model.
+ *
+ * @param modelSet
+ * the di resource set
+ * @param contextId
+ * the architecture context id
+ */
+ protected void initDiagramModel(ModelSet modelSet, String contextId) {
+ initDiagrams(modelSet, contextId);
+ }
+
+
+ /**
+ * Save diagram.
+ *
+ * @param modelSet
+ * the di resource set
+ */
+ private void saveDiagram(ModelSet modelSet) {
+ // TODO verify that there are no conflicts with the existing files and the newly created one
+ try {
+ modelSet.save(new NullProgressMonitor());
+ } catch (IOException e) {
+ log.error(e);
+ }
+ }
+
+ /**
+ * Inits the diagrams.
+ *
+ * @param modelSet
+ * the di resource set
+ * @param contextId
+ * the architecture context id
+ */
+ protected void initDiagrams(ModelSet modelSet, String contextId) {
+ initDiagrams(modelSet, null, contextId);
+ }
+
+ /**
+ * Inits the diagrams.
+ *
+ * @param resourceSet
+ * the resource set
+ * @param root
+ * the root
+ * @param contextId
+ * the architecture context id
+ */
+ protected void initDiagrams(ModelSet resourceSet, EObject root, String contextId) {
+ UmlModel model = (UmlModel) resourceSet.getModel(UmlModel.MODEL_ID);
+ EList<EObject> roots = model.getResource().getContents();
+ if (!roots.isEmpty()) {
+ root = roots.get(0);
+ if (root instanceof NamedElement) {
+ getCommandStack(resourceSet).execute(new RenameElementCommand(resourceSet.getTransactionalEditingDomain(), (NamedElement) root, getRootElementName()));
+
+ }
+
+ }
+ List<RepresentationKind> creationCommands = getRepresentationKindsFor(contextId);
+ List<String> diagramName = selectRepresentationKindPage.getDiagramName();
+ if (creationCommands.isEmpty()) {
+ createEmptyDiagramEditor(resourceSet);
+ } else {
+ for (int i = 0; i < creationCommands.size(); i++) {
+ RepresentationKind kind = creationCommands.get(i);
+ if (kind instanceof PapyrusRepresentationKind) {
+ ViewPrototype proto = ViewPrototype.get((PapyrusRepresentationKind)kind);
+ proto.instantiateOn(root, diagramName.get(i));
+ }
+ }
+ }
+ }
+
+ /**
+ * Gets the representation kinds for.
+ *
+ * @param contextId
+ * the architecture context id
+ * @return the repersentation kinds for
+ */
+ protected List<RepresentationKind> getRepresentationKindsFor(String contextId) {
+ return selectRepresentationKindPage.getSelectedRepresentationKinds(contextId);
+ }
+
+
+ protected List<String> getDiagramNames() {
+ return selectRepresentationKindPage.getDiagramName();
+ }
+
+ protected String getRootElementName() {
+ return selectRepresentationKindPage.getRootElementName();
+ }
+
+ /**
+ * Creates the empty diagram editor.
+ *
+ * @param modelSet
+ * the model set
+ */
+ private void createEmptyDiagramEditor(ModelSet modelSet) {
+ // Create an empty editor (no diagrams opened)
+ // Geting an IPageMngr is enough to initialize the
+ // SashSystem.
+ EditorUtils.getIPageMngr(DiModelUtils.getDiResource(modelSet));
+ }
+
+ /**
+ * Gets the command stack.
+ *
+ * @param modelSet
+ * the model set
+ * @return the command stack
+ */
+ protected final CommandStack getCommandStack(ModelSet modelSet) {
+ return modelSet.getTransactionalEditingDomain().getCommandStack();
+ }
+
+ /**
+ * Diagram category changed.
+ *
+ * @param newCategories
+ * the new categories
+ * @return the i status
+ */
+ public IStatus architectureContextChanged(String... newContexts) {
+ return getSelectedStorageProvider().validateArchitectureContexts(newContexts);
+ }
+
+ protected void initStorageProvider(IWorkbench workbench, IStructuredSelection selection) {
+
+ NewModelStorageProviderRegistry registry = new NewModelStorageProviderRegistry(workbench.getService(IEvaluationService.class));
+
+ // if we are creating a project, then it is in the workspace
+ if (isCreateProjectWizard()) {
+ this.selectedStorageProvider = new WorkspaceNewModelStorageProvider();
+ } else {
+ // look for a pre-determined selection
+ INewModelStorageProvider firstProvider = null;
+ for (INewModelStorageProvider next : registry) {
+ if (firstProvider == null) {
+ firstProvider = next;
+ }
+
+ // don't match on empty selections because there is
+ // then no context to match against
+ if (!selection.isEmpty() && next.canHandle(selection)) {
+ this.selectedStorageProvider = next;
+ break;
+ }
+ }
+
+ // if the choice is pre-determined, don't show the selection page
+ if (this.selectedStorageProvider == null) {
+ this.selectedStorageProvider = firstProvider;
+
+ // don't need the selection page if only one choice
+ if (registry.size() > 1) {
+ this.storageProviderRegistry = registry;
+ }
+ }
+ }
+ }
+
+ protected SelectStorageProviderPage createSelectStorageProviderPage() {
+ SelectStorageProviderPage result = (storageProviderRegistry == null) ? null : new SelectStorageProviderPage(storageProviderRegistry);
+
+ if (result != null) {
+ result.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ INewModelStorageProvider provider = (INewModelStorageProvider) ((IStructuredSelection) event.getSelection()).getFirstElement();
+ setSelectedStorageProvider(provider);
+ }
+ });
+ }
+
+ return result;
+ }
+
+ protected Iterable<? extends INewModelStorageProvider> getStorageProviders() {
+ Iterable<? extends INewModelStorageProvider> result;
+
+ if (storageProviderRegistry != null) {
+ result = storageProviderRegistry;
+ } else if (selectedStorageProvider != null) {
+ result = Collections.singletonList(selectedStorageProvider);
+ } else {
+ result = Collections.emptyList();
+ }
+
+ return result;
+ }
+
+ protected INewModelStorageProvider getSelectedStorageProvider() {
+ return selectedStorageProvider;
+ }
+
+ private void setSelectedStorageProvider(INewModelStorageProvider provider) {
+ this.selectedStorageProvider = provider;
+
+ // recompute next/previous buttons
+ getContainer().updateButtons();
+ }
+
+ @Override
+ public IWizardPage getNextPage(IWizardPage page) {
+ final List<IWizardPage> allPages = Arrays.asList(getPages());
+ IWizardPage result = null;
+
+ INewModelStorageProvider provider = providersByPage.get(page);
+ if (provider != null) {
+ // it's contributed by a provider. Get the next in the list
+ List<IWizardPage> pages = providerPages.get(provider);
+ int index = pages.indexOf(page);
+ if ((index >= 0) && (index < (pages.size() - 1))) {
+ result = pages.get(index + 1);
+ } else {
+ // get the first page after the provider pages
+ if (endProviderPageIndex < allPages.size()) {
+ result = allPages.get(endProviderPageIndex);
+ }
+ }
+ } else if (allPages.indexOf(page) == startProviderPageIndex) {
+ // get the first page of the selected provider
+ List<IWizardPage> pages = providerPages.get(getSelectedStorageProvider());
+ if (!pages.isEmpty()) {
+ result = pages.get(0);
+ } else {
+ // get the first page after the provider pages
+ if (endProviderPageIndex < allPages.size()) {
+ result = allPages.get(endProviderPageIndex);
+ }
+ }
+ } else {
+ // somewhere away from the boundary of the provider pages
+ result = super.getNextPage(page);
+ }
+
+ return result;
+ }
+
+ @Override
+ public IWizardPage getPreviousPage(IWizardPage page) {
+ final List<IWizardPage> allPages = Arrays.asList(getPages());
+ IWizardPage result = null;
+
+ INewModelStorageProvider provider = providersByPage.get(page);
+ if (provider != null) {
+ // it's contributed by a provider. Get the previous in the list
+ List<IWizardPage> pages = providerPages.get(provider);
+ int index = pages.indexOf(page);
+ if (index > 0) {
+ result = pages.get(index - 1);
+ } else {
+ // get the last page before the provider pages
+ if (startProviderPageIndex > 0) {
+ result = allPages.get(startProviderPageIndex - 1);
+ }
+ }
+ } else if (allPages.indexOf(page) == endProviderPageIndex) {
+ // get the last page of the selected provider
+ List<IWizardPage> pages = providerPages.get(getSelectedStorageProvider());
+ if (!pages.isEmpty()) {
+ result = pages.get(pages.size() - 1);
+ } else {
+ // get the last page before the provider pages
+ if (startProviderPageIndex >= 0) {
+ result = allPages.get(startProviderPageIndex);
+ }
+ }
+ } else {
+ // somewhere away from the boundary of the provider pages
+ result = super.getPreviousPage(page);
+ }
+
+ return result;
+ }
+
+ @Override
+ public boolean canFinish() {
+ boolean result = true;
+ final IWizardPage[] allPages = getPages();
+
+ // only look at the universal pages and those contributed by the current
+ // storage provider
+
+ for (int i = 0; result && (i <= startProviderPageIndex); i++) {
+ result = allPages[i].isPageComplete();
+ }
+
+ if (result) {
+ for (IWizardPage next : providerPages.get(selectedStorageProvider)) {
+ if (!next.isPageComplete()) {
+ result = false;
+ break;
+ }
+ }
+ }
+
+ for (int i = endProviderPageIndex; result && (i < allPages.length); i++) {
+ result = allPages[i].isPageComplete();
+ }
+
+ // This takes care of the case problems when creating a model with the same name but different case
+ for (IWizardPage page : allPages) {
+ if (page instanceof NewModelFilePage) {
+ return page.canFlipToNextPage();
+ }
+ if (page instanceof PapyrusProjectCreationPage) {
+ return page.canFlipToNextPage();
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Queries the user-presentable (translatable) name of the kind of model
+ * that I create. For example, "Papyrus UML" or "Papyrus SysML".
+ *
+ * @return my model kind name
+ */
+ public String getModelKindName() {
+ return "Papyrus"; //$NON-NLS-1$
+ }
+
+ @Deprecated
+ protected void saveDiagramCategorySettings() {
+
+ }
+
+ public boolean isPapyrusRootWizard() {
+ // this.getClass().getName().equals(anObject)
+ return true;
+ }
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateSeveralModelsWizard.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateSeveralModelsWizard.java
index d6c489cc154..ae39013c38f 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateSeveralModelsWizard.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateSeveralModelsWizard.java
@@ -30,8 +30,8 @@ import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.papyrus.uml.diagram.wizards.Activator;
import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
import org.eclipse.papyrus.uml.diagram.wizards.pages.NewModelFilePage;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramCategoryPage;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramKindPage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectArchitectureContextPage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectRepresentationKindPage;
import org.eclipse.ui.IWorkbench;
/**
@@ -65,7 +65,7 @@ public class CreateSeveralModelsWizard extends CreateModelWizard {
}
@Override
- public IStatus diagramCategoryChanged(String... newCategories) {
+ public IStatus architectureContextChanged(String... newCategories) {
// clean pages
List<String> newCategoriesList = Arrays.asList(newCategories);
Collection<String> keys = new HashSet<String>(myCategory2modelFilePageMap.keySet());
@@ -80,7 +80,7 @@ public class CreateSeveralModelsWizard extends CreateModelWizard {
myCategory2modelFilePageMap.put(newCategory, newPage);
}
}
- return super.diagramCategoryChanged(newCategories);
+ return super.architectureContextChanged(newCategories);
}
/**
@@ -107,7 +107,7 @@ public class CreateSeveralModelsWizard extends CreateModelWizard {
@Override
public IWizardPage getNextPage(IWizardPage page) {
String pageId = page.getName();
- if(SelectDiagramKindPage.PAGE_ID.equals(pageId)) {
+ if(SelectRepresentationKindPage.PAGE_ID.equals(pageId)) {
String nextKey = myCategory2modelFilePageMap.keySet().iterator().next();
return myCategory2modelFilePageMap.get(nextKey);
}
@@ -138,14 +138,9 @@ public class CreateSeveralModelsWizard extends CreateModelWizard {
return super.getPreviousPage(page);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.papyrus.uml.diagram.wizards.CreateModelWizard#createSelectDiagramCategoryPage()
- */
@Override
- protected SelectDiagramCategoryPage createSelectDiagramCategoryPage() {
- return new SelectDiagramCategoryPage(true);
+ protected SelectArchitectureContextPage createSelectArchitectureContextPage() {
+ return new SelectArchitectureContextPage(true);
}
/**
@@ -155,10 +150,11 @@ public class CreateSeveralModelsWizard extends CreateModelWizard {
*/
@Override
public boolean performFinish() {
- for(String category : getDiagramCategoryIds()) {
+ for(String contextId : getSelectedContexts()) {
- final URI newURI = createNewModelURI(category);
- createAndOpenPapyrusModel(newURI, category);
+ final URI newURI = createNewModelURI(contextId);
+ String[] viewpointIds = getSelectedViewpoints(contextId);
+ createAndOpenPapyrusModel(newURI, contextId, viewpointIds);
}
// saveDiagramCategorySettings();
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/InitModelWizard.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/InitModelWizard.java
index c76211cd3bb..5f079c750ec 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/InitModelWizard.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/InitModelWizard.java
@@ -1,239 +1,239 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2013 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:
- * Tatiana Fesenko (CEA LIST) - Initial API and implementation
- * Christian W. Damus (CEA) - Support creating models in repositories (CDO)
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.wizards.wizards;
-
-import static org.eclipse.papyrus.uml.diagram.wizards.utils.WizardsHelper.getSelectedResourceURI;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.uml.diagram.wizards.command.PapyrusModelFromExistingDomainModelCommand;
-import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.NewModelFilePage;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramKindPage;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramKindPage.CategoryProvider;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectRootElementPage;
-import org.eclipse.papyrus.uml.tools.model.UmlModel;
-import org.eclipse.ui.IWorkbench;
-
-/**
- *
- * The New Papyrus Model Wizard.
- * If being invoke on the *.uml file - initializes a new Papyrus diagram for the selected domain model.
- * If is selected is empty or in not uml - creates a new Papyrus Model.
- */
-public class InitModelWizard extends CreateModelWizard {
-
- /** Select the root element containing the new diagram. */
- private SelectRootElementPage selectRootElementPage;
-
- /** The is init from existing domain model. */
- private boolean isInitFromExistingDomainModel;
-
- @Override
- public boolean isInitModelWizard() {
- return true;
- }
-
- /**
- * Inits the.
- *
- * @param workbench
- * the workbench
- * @param selection
- * the selection {@inheritDoc}
- */
- @Override
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- URI uri = getSelectedResourceURI(selection);
- isInitFromExistingDomainModel = isSupportedDomainModelResource(uri);
- super.init(workbench, selection);
- selectRootElementPage = createSelectRootElementPage(selection);
- if (isCreateFromExistingDomainModel()) {
- // Init Model not Create a new one
- setWindowTitle(Messages.InitModelWizard_init_papyrus_diagram);
- }
- }
-
- /**
- * Creates the select root element page.
- *
- * @param selection
- * the initial workbench selection
- * @return the select root element page
- */
- protected SelectRootElementPage createSelectRootElementPage(IStructuredSelection selection) {
- if (!isCreateFromExistingDomainModel()) {
- // create model - nothing to choose from
- return null;
- }
- return new SelectRootElementPage(selection);
- }
-
- /**
- * Creates the select diagram kind page.
- *
- * @return the select diagram kind page {@inheritDoc}
- */
- @Override
- protected SelectDiagramKindPage createSelectDiagramKindPage() {
- if (isCreateFromExistingDomainModel()) {
- return new SelectDiagramKindPage(false, new CategoryProvider() {
-
- @Override
- public String[] getCurrentCategories() {
- return getDiagramCategoryIds();
- }
-
- }, SelectDiagramKindPage.DEFAULT_CREATION_COMMAND_REGISTRY);
- }
- ;
- return super.createSelectDiagramKindPage();
- }
-
- /**
- * Adds the pages.
- *
- * {@inheritDoc}
- */
- @Override
- public void addPages() {
- super.addPages();
- // remove the page from the view
- // addPageIfNotNull(selectRootElementPage);
- };
-
- /**
- * Returns true is the file can be served as a model model for the diagram.
- *
- * @param file
- * the file
- * @return true, if is supported domain model file
- */
- public static boolean isSupportedDomainModelFile(IFile file) {
- // if(file != null && UmlModel.UML_FILE_EXTENSION.equals(file.getFileExtension())){System.err.println("is SupportedDomainModelFile");}
- // else {System.err.println("not SupportedDomainModelFile");}
- return file != null && isSupportedDomainModelResource(URI.createPlatformResourceURI(file.getFullPath().toString(), true));
- }
-
- /**
- * Returns true if the resource can be served as a model model for the diagram.
- *
- * @param uri
- * the resource's URI
- * @return true, if is supported domain model resource
- */
- public static boolean isSupportedDomainModelResource(URI uri) {
- return (uri != null) && UmlModel.UML_FILE_EXTENSION.equals(uri.fileExtension());
- }
-
- /**
- * Checks if is supported domain model file.
- *
- * @param sselection
- * the sselection
- * @return true, if is supported domain model file
- */
- public static boolean isSupportedDomainModelFile(IStructuredSelection sselection) {
- URI uri = getSelectedResourceURI(sselection);
- return isSupportedDomainModelResource(uri);
- }
-
- /**
- * Creates the papyrus models.
- *
- * @param diResourceSet
- * the di resource set
- * @param newURI
- * the URI of the new model's principal resource
- */
- @Override
- protected void createPapyrusModels(ModelSet modelSet, URI newURI) {
- if (isCreateFromExistingDomainModel()) {
- RecordingCommand command = new PapyrusModelFromExistingDomainModelCommand(modelSet, newURI, getRoot());
- getCommandStack(modelSet).execute(command);
- } else {
- super.createPapyrusModels(modelSet, newURI);
- }
- }
-
- /**
- * Inits the domain model.
- *
- * @param diResourceSet
- * the di resource set
- * @param newURI
- * the URI of the new model's principal resource
- * @param diagramCategoryId
- * the diagram category id {@inheritDoc}
- */
- @Override
- protected void initDomainModel(ModelSet modelSet, final URI newURI, String diagramCategoryId) {
- if (isCreateFromExistingDomainModel()) {
- // do nothing
- } else {
- super.initDomainModel(modelSet, newURI, diagramCategoryId);
- }
- }
-
- /**
- * Inits the diagrams.
- *
- * @param diResourceSet
- * the di resource set
- * @param categoryId
- * the category id {@inheritDoc}
- */
- @Override
- protected void initDiagrams(ModelSet modelSet, String categoryId) {
- initDiagrams(modelSet, getRoot(), categoryId);
- }
-
- /**
- * Checks if is creates the from existing domain model.
- *
- * @return true, if is creates the from existing domain model
- */
- public boolean isCreateFromExistingDomainModel() {
- return isInitFromExistingDomainModel;
- }
-
- @Override
- public String getDiagramFileExtension(String diagramCategoryId) {
- if (isCreateFromExistingDomainModel()) {
- return NewModelFilePage.DEFAULT_DIAGRAM_EXTENSION;
- }
- return super.getDiagramFileExtension(diagramCategoryId);
- }
-
- /**
- * Gets the root.
- *
- * @return the root
- */
- private EObject getRoot() {
- if (selectRootElementPage != null) {
- // return selectRootElementPage.getModelElement();
- return SelectDiagramKindPage.getModelRoot();
- }
- return null;
- }
-
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2010, 2013 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:
+ * Tatiana Fesenko (CEA LIST) - Initial API and implementation
+ * Christian W. Damus (CEA) - Support creating models in repositories (CDO)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.wizards.wizards;
+
+import static org.eclipse.papyrus.uml.diagram.wizards.utils.WizardsHelper.getSelectedResourceURI;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.uml.diagram.wizards.command.PapyrusModelFromExistingDomainModelCommand;
+import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.NewModelFilePage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectRepresentationKindPage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectRepresentationKindPage.ViewpointProvider;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectRootElementPage;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.ui.IWorkbench;
+
+/**
+ *
+ * The New Papyrus Model Wizard.
+ * If being invoke on the *.uml file - initializes a new Papyrus diagram for the selected domain model.
+ * If is selected is empty or in not uml - creates a new Papyrus Model.
+ */
+public class InitModelWizard extends CreateModelWizard {
+
+ /** Select the root element containing the new diagram. */
+ private SelectRootElementPage selectRootElementPage;
+
+ /** The is init from existing domain model. */
+ private boolean isInitFromExistingDomainModel;
+
+ @Override
+ public boolean isInitModelWizard() {
+ return true;
+ }
+
+ /**
+ * Inits the.
+ *
+ * @param workbench
+ * the workbench
+ * @param selection
+ * the selection {@inheritDoc}
+ */
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ URI uri = getSelectedResourceURI(selection);
+ isInitFromExistingDomainModel = isSupportedDomainModelResource(uri);
+ super.init(workbench, selection);
+ selectRootElementPage = createSelectRootElementPage(selection);
+ if (isCreateFromExistingDomainModel()) {
+ // Init Model not Create a new one
+ setWindowTitle(Messages.InitModelWizard_init_papyrus_diagram);
+ }
+ }
+
+ /**
+ * Creates the select root element page.
+ *
+ * @param selection
+ * the initial workbench selection
+ * @return the select root element page
+ */
+ protected SelectRootElementPage createSelectRootElementPage(IStructuredSelection selection) {
+ if (!isCreateFromExistingDomainModel()) {
+ // create model - nothing to choose from
+ return null;
+ }
+ return new SelectRootElementPage(selection);
+ }
+
+ /**
+ * Creates the select diagram kind page.
+ *
+ * @return the select diagram kind page {@inheritDoc}
+ */
+ @Override
+ protected SelectRepresentationKindPage createSelectRepresentationKindPage() {
+ if (isCreateFromExistingDomainModel()) {
+ return new SelectRepresentationKindPage(false, new ViewpointProvider() {
+
+ @Override
+ public String[] getCurrentViewpoints() {
+ return getSelectedViewpoints();
+ }
+
+ }, SelectRepresentationKindPage.DEFAULT_CREATION_COMMAND_REGISTRY);
+ }
+ ;
+ return super.createSelectRepresentationKindPage();
+ }
+
+ /**
+ * Adds the pages.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void addPages() {
+ super.addPages();
+ // remove the page from the view
+ // addPageIfNotNull(selectRootElementPage);
+ };
+
+ /**
+ * Returns true is the file can be served as a model model for the diagram.
+ *
+ * @param file
+ * the file
+ * @return true, if is supported domain model file
+ */
+ public static boolean isSupportedDomainModelFile(IFile file) {
+ // if(file != null && UmlModel.UML_FILE_EXTENSION.equals(file.getFileExtension())){System.err.println("is SupportedDomainModelFile");}
+ // else {System.err.println("not SupportedDomainModelFile");}
+ return file != null && isSupportedDomainModelResource(URI.createPlatformResourceURI(file.getFullPath().toString(), true));
+ }
+
+ /**
+ * Returns true if the resource can be served as a model model for the diagram.
+ *
+ * @param uri
+ * the resource's URI
+ * @return true, if is supported domain model resource
+ */
+ public static boolean isSupportedDomainModelResource(URI uri) {
+ return (uri != null) && UmlModel.UML_FILE_EXTENSION.equals(uri.fileExtension());
+ }
+
+ /**
+ * Checks if is supported domain model file.
+ *
+ * @param sselection
+ * the sselection
+ * @return true, if is supported domain model file
+ */
+ public static boolean isSupportedDomainModelFile(IStructuredSelection sselection) {
+ URI uri = getSelectedResourceURI(sselection);
+ return isSupportedDomainModelResource(uri);
+ }
+
+ /**
+ * Creates the papyrus models.
+ *
+ * @param diResourceSet
+ * the di resource set
+ * @param newURI
+ * the URI of the new model's principal resource
+ */
+ @Override
+ protected void createPapyrusModels(ModelSet modelSet, URI newURI) {
+ if (isCreateFromExistingDomainModel()) {
+ RecordingCommand command = new PapyrusModelFromExistingDomainModelCommand(modelSet, newURI, getRoot());
+ getCommandStack(modelSet).execute(command);
+ } else {
+ super.createPapyrusModels(modelSet, newURI);
+ }
+ }
+
+ /**
+ * Inits the domain model.
+ *
+ * @param diResourceSet
+ * the di resource set
+ * @param contextId
+ * the architecture context id
+ * @param viewpointIds
+ * the architecture viewpoint ids
+ */
+ @Override
+ protected void initDomainModel(ModelSet modelSet, String contextId, String[] viewpointIds) {
+ if (isCreateFromExistingDomainModel()) {
+ // do nothing
+ } else {
+ super.initDomainModel(modelSet, contextId, viewpointIds);
+ }
+ }
+
+ /**
+ * Inits the diagrams.
+ *
+ * @param diResourceSet
+ * the di resource set
+ * @param contextName
+ * the architecture context name {@inheritDoc}
+ */
+ @Override
+ protected void initDiagrams(ModelSet modelSet, String contextName) {
+ initDiagrams(modelSet, getRoot(), contextName);
+ }
+
+ /**
+ * Checks if is creates the from existing domain model.
+ *
+ * @return true, if is creates the from existing domain model
+ */
+ public boolean isCreateFromExistingDomainModel() {
+ return isInitFromExistingDomainModel;
+ }
+
+ @Override
+ public String getDiagramFileExtension(String contextId) {
+ if (isCreateFromExistingDomainModel()) {
+ return NewModelFilePage.DEFAULT_DIAGRAM_EXTENSION;
+ }
+ return super.getDiagramFileExtension(contextId);
+ }
+
+ /**
+ * Gets the root.
+ *
+ * @return the root
+ */
+ private EObject getRoot() {
+ if (selectRootElementPage != null) {
+ // return selectRootElementPage.getModelElement();
+ return SelectRepresentationKindPage.getModelRoot();
+ }
+ return null;
+ }
+
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/NewPapyrusProjectWithMultiModelsWizard.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/NewPapyrusProjectWithMultiModelsWizard.java
index 9320d20d279..9b0c0338a3c 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/NewPapyrusProjectWithMultiModelsWizard.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/NewPapyrusProjectWithMultiModelsWizard.java
@@ -1,99 +1,95 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2013 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:
- * Tatiana Fesenko (CEA LIST) - Initial API and implementation
- * Christian W. Damus (CEA) - Support creating models in repositories (CDO)
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.wizards.wizards;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.papyrus.uml.diagram.wizards.Activator;
-import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramCategoryPage;
-
-/**
- * The Wizard creates a new Project and a several Papyrus Models of different categories inside it.
- */
-public class NewPapyrusProjectWithMultiModelsWizard extends NewPapyrusProjectWizard {
-
- /** The my do not create model for no diagrams. */
- private boolean myDoNotCreateModelForNoDiagrams;
-
- /** The Constant WIZARD_ID. */
- public static final String WIZARD_ID = "org.eclipse.papyrus.uml.diagram.wizards.createproject.several"; //$NON-NLS-1$
-
-
- /**
- * Instantiates a new new papyrus project with multi models wizard.
- */
- public NewPapyrusProjectWithMultiModelsWizard() {
- this(false);
- }
-
- /**
- * Instantiates a new new papyrus project with multi models wizard.
- *
- * @param doNotCreateModelForNoDiagrams
- * the do not create model for no diagrams
- */
- public NewPapyrusProjectWithMultiModelsWizard(boolean doNotCreateModelForNoDiagrams) {
- myDoNotCreateModelForNoDiagrams = doNotCreateModelForNoDiagrams;
- }
-
- @Override
- public boolean isCreateMultipleModelsWizard() {
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.papyrus.uml.diagram.wizards.CreateModelWizard#createSelectDiagramCategoryPage()
- */
- @Override
- protected SelectDiagramCategoryPage createSelectDiagramCategoryPage() {
- return new SelectDiagramCategoryPage(true);
- }
-
- /**
- * Perform finish.
- *
- * @return true, if successful {@inheritDoc}
- */
- @Override
- public boolean performFinish() {
- IProject newProjectHandle;
- try {
- newProjectHandle = createNewProject();
- } catch (CoreException e) {
- Activator.log.error(Messages.NewPapyrusProjectWithMultiModelsWizard_exception_on_project_opening, e);
- return false;
- }
- if (newProjectHandle == null) {
- return false;
- }
- for (String category : getDiagramCategoryIds()) {
- if (myDoNotCreateModelForNoDiagrams && getPrototypesFor(category).isEmpty()) {
- // don't create model
- continue;
- }
- final URI newURI = createNewModelURI(category);
- createAndOpenPapyrusModel(newURI, category);
- }
-
- // saveDiagramCategorySettings();
- // saveDiagramKindSettings();
- return true;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2010, 2013 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:
+ * Tatiana Fesenko (CEA LIST) - Initial API and implementation
+ * Christian W. Damus (CEA) - Support creating models in repositories (CDO)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.wizards.wizards;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.papyrus.uml.diagram.wizards.Activator;
+import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectArchitectureContextPage;
+
+/**
+ * The Wizard creates a new Project and a several Papyrus Models of different categories inside it.
+ */
+public class NewPapyrusProjectWithMultiModelsWizard extends NewPapyrusProjectWizard {
+
+ /** The my do not create model for no diagrams. */
+ private boolean myDoNotCreateModelForNoDiagrams;
+
+ /** The Constant WIZARD_ID. */
+ public static final String WIZARD_ID = "org.eclipse.papyrus.uml.diagram.wizards.createproject.several"; //$NON-NLS-1$
+
+
+ /**
+ * Instantiates a new new papyrus project with multi models wizard.
+ */
+ public NewPapyrusProjectWithMultiModelsWizard() {
+ this(false);
+ }
+
+ /**
+ * Instantiates a new new papyrus project with multi models wizard.
+ *
+ * @param doNotCreateModelForNoDiagrams
+ * the do not create model for no diagrams
+ */
+ public NewPapyrusProjectWithMultiModelsWizard(boolean doNotCreateModelForNoDiagrams) {
+ myDoNotCreateModelForNoDiagrams = doNotCreateModelForNoDiagrams;
+ }
+
+ @Override
+ public boolean isCreateMultipleModelsWizard() {
+ return true;
+ }
+
+ @Override
+ protected SelectArchitectureContextPage createSelectArchitectureContextPage() {
+ return new SelectArchitectureContextPage(true);
+ }
+
+ /**
+ * Perform finish.
+ *
+ * @return true, if successful {@inheritDoc}
+ */
+ @Override
+ public boolean performFinish() {
+ IProject newProjectHandle;
+ try {
+ newProjectHandle = createNewProject();
+ } catch (CoreException e) {
+ Activator.log.error(Messages.NewPapyrusProjectWithMultiModelsWizard_exception_on_project_opening, e);
+ return false;
+ }
+ if (newProjectHandle == null) {
+ return false;
+ }
+ for (String contextId : getSelectedContexts()) {
+ if (myDoNotCreateModelForNoDiagrams && getRepresentationKindsFor(contextId).isEmpty()) {
+ // don't create model
+ continue;
+ }
+ final URI newURI = createNewModelURI(contextId);
+ String[] viewpointIds = getSelectedViewpoints(contextId);
+ createAndOpenPapyrusModel(newURI, contextId, viewpointIds);
+ }
+
+ // saveDiagramCategorySettings();
+ // saveDiagramKindSettings();
+ return true;
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/NewPapyrusProjectWizard.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/NewPapyrusProjectWizard.java
index a379796461d..9b9a980f2fd 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/NewPapyrusProjectWizard.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/NewPapyrusProjectWizard.java
@@ -1,157 +1,159 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2013 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:
- * Tatiana Fesenko (CEA LIST) - Initial API and implementation
- * Christian W. Damus (CEA) - Support creating models in repositories (CDO)
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.wizards.wizards;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.uml.diagram.wizards.Activator;
-import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.PapyrusProjectCreationPage;
-import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramCategoryPage;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
-
-/**
- * The Wizard creates a new Project and a Papyrus Model inside it.
- */
-public class NewPapyrusProjectWizard extends CreateModelWizard {
-
- /** The Constant WIZARD_ID. */
- public static final String WIZARD_ID = "org.eclipse.papyrus.uml.diagram.wizards.createproject"; //$NON-NLS-1$
-
- /** The new project page. */
- private PapyrusProjectCreationPage myProjectPage;
-
- @Override
- public boolean isCreateProjectWizard() {
- return true;
- }
-
- /**
- * Inits the.
- *
- * @param workbench
- * the workbench
- * @param selection
- * the selection {@inheritDoc}
- */
- @Override
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- super.init(workbench, selection);
- setWindowTitle(Messages.NewPapyrusProjectWizard_new_papyrus_project);
- setMyProjectPage(new PapyrusProjectCreationPage(Messages.NewPapyrusProjectWizard_0));
- getMyProjectPage().setDescription(Messages.NewPapyrusProjectWizard_1);
- setDefaultPageImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/papyrus/PapyrusProjectWizban_75x66.gif")); //$NON-NLS-1$
- }
-
-
-
- /**
- * Adds the pages.
- *
- * {@inheritDoc}
- */
- @Override
- public void addPages() {
- // Gives the CreateModelWizard the newProjectPage to display it after the selectDiagramCategoryPage
- setNewProjectPage(getMyProjectPage());
-
- if (getDiagramCategoryIds() == null) {
- // If no one Overrides the id list then no specific behavior is expected
- // We therefore fall back to the original behavior: ask the user to pick a language
- selectDiagramCategoryPage = new SelectDiagramCategoryPage();
- }
-
- super.addPages();
- }
-
- /**
- * Perform finish.
- *
- * @return true, if successful {@inheritDoc}
- */
- @Override
- public boolean performFinish() {
- IProject newProjectHandle;
- try {
- newProjectHandle = createNewProject();
- } catch (CoreException e) {
- Activator.log.error(Messages.NewPapyrusProjectWizard_exception_on_opening, e);
- return false;
- }
- if (newProjectHandle == null) {
- return false;
- }
- return super.performFinish();
- }
-
- /**
- * Creates the new project.
- *
- * @return the i project
- * @throws CoreException
- * the core exception
- */
- protected IProject createNewProject() throws CoreException {
- // get a project handle
- final IProject project = getMyProjectPage().getProjectHandle();
-
- // get a project descriptor
- java.net.URI projectLocationURI = null;
- if (!getMyProjectPage().useDefaults()) {
- projectLocationURI = getMyProjectPage().getLocationURI();
- }
-
- NullProgressMonitor progressMonitor = new NullProgressMonitor();
- if (!project.exists()) {
- IProjectDescription projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName());
- if (projectLocationURI != null) {
- projectDescription.setLocationURI(projectLocationURI);
- }
- project.create(projectDescription, new SubProgressMonitor(progressMonitor, 1));
- project.open(new SubProgressMonitor(progressMonitor, 1));
- } else {
- project.open(new SubProgressMonitor(progressMonitor, 1));
- }
-
- return project;
- }
-
- @Override
- protected URI createNewModelURI(String categoryId) {
- IPath newFilePath = getMyProjectPage().getProjectHandle().getFullPath().append(getMyProjectPage().getFileName() + "." + getDiagramFileExtension(categoryId)); //$NON-NLS-1$
- return URI.createPlatformResourceURI(newFilePath.toString(), true);
- }
-
- public PapyrusProjectCreationPage getMyProjectPage() {
- return myProjectPage;
- }
-
- public void setMyProjectPage(PapyrusProjectCreationPage myProjectPage) {
- this.myProjectPage = myProjectPage;
- }
-
- protected WizardNewProjectCreationPage createNewProjectCreationPage() {
- return this.myProjectPage;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2010, 2013 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:
+ * Tatiana Fesenko (CEA LIST) - Initial API and implementation
+ * Christian W. Damus (CEA) - Support creating models in repositories (CDO)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.wizards.wizards;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.uml.diagram.wizards.Activator;
+import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.PapyrusProjectCreationPage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectArchitectureContextPage;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
+
+/**
+ * The Wizard creates a new Project and a Papyrus Model inside it.
+ */
+public class NewPapyrusProjectWizard extends CreateModelWizard {
+
+ /** The Constant WIZARD_ID. */
+ public static final String WIZARD_ID = "org.eclipse.papyrus.uml.diagram.wizards.createproject"; //$NON-NLS-1$
+
+ /** The new project page. */
+ private PapyrusProjectCreationPage myProjectPage;
+
+ @Override
+ public boolean isCreateProjectWizard() {
+ return true;
+ }
+
+ /**
+ * Inits the.
+ *
+ * @param workbench
+ * the workbench
+ * @param selection
+ * the selection {@inheritDoc}
+ */
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ super.init(workbench, selection);
+ setWindowTitle(Messages.NewPapyrusProjectWizard_new_papyrus_project);
+ setMyProjectPage(new PapyrusProjectCreationPage(Messages.NewPapyrusProjectWizard_0));
+ getMyProjectPage().setDescription(Messages.NewPapyrusProjectWizard_1);
+ setDefaultPageImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/papyrus/PapyrusProjectWizban_75x66.gif")); //$NON-NLS-1$
+ }
+
+
+
+ /**
+ * Adds the pages.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void addPages() {
+ // Gives the CreateModelWizard the newProjectPage to display it after the selectDiagramCategoryPage
+ setNewProjectPage(getMyProjectPage());
+
+ if (getSelectedContexts() == null) {
+ // If no one Overrides the id list then no specific behavior is expected
+ // We therefore fall back to the original behavior: ask the user to pick a language
+ selectArchitectureContextPage = new SelectArchitectureContextPage();
+ }
+
+ super.addPages();
+ }
+
+ /**
+ * Perform finish.
+ *
+ * @return true, if successful {@inheritDoc}
+ */
+ @Override
+ public boolean performFinish() {
+ IProject newProjectHandle;
+ try {
+ newProjectHandle = createNewProject();
+ } catch (CoreException e) {
+ Activator.log.error(Messages.NewPapyrusProjectWizard_exception_on_opening, e);
+ return false;
+ }
+ if (newProjectHandle == null) {
+ return false;
+ }
+ return super.performFinish();
+ }
+
+ /**
+ * Creates the new project.
+ *
+ * @return the i project
+ * @throws CoreException
+ * the core exception
+ */
+ protected IProject createNewProject() throws CoreException {
+ // get a project handle
+ final IProject project = getMyProjectPage().getProjectHandle();
+
+ // get a project descriptor
+ java.net.URI projectLocationURI = null;
+ if (!getMyProjectPage().useDefaults()) {
+ projectLocationURI = getMyProjectPage().getLocationURI();
+ }
+
+ IProjectDescription projectDescription = null;
+ NullProgressMonitor progressMonitor = new NullProgressMonitor();
+ if (!project.exists()) {
+ projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName());
+ if (projectLocationURI != null) {
+ projectDescription.setLocationURI(projectLocationURI);
+ }
+ project.create(projectDescription, new SubProgressMonitor(progressMonitor, 1));
+ project.open(new SubProgressMonitor(progressMonitor, 1));
+ } else {
+ // projectDescription = project.getDescription();
+ project.open(new SubProgressMonitor(progressMonitor, 1));
+ }
+
+ return project;
+ }
+
+ @Override
+ protected URI createNewModelURI(String categoryId) {
+ IPath newFilePath = getMyProjectPage().getProjectHandle().getFullPath().append(getMyProjectPage().getFileName() + "." + getDiagramFileExtension(categoryId)); //$NON-NLS-1$
+ return URI.createPlatformResourceURI(newFilePath.toString(), true);
+ }
+
+ public PapyrusProjectCreationPage getMyProjectPage() {
+ return myProjectPage;
+ }
+
+ public void setMyProjectPage(PapyrusProjectCreationPage myProjectPage) {
+ this.myProjectPage = myProjectPage;
+ }
+
+ protected WizardNewProjectCreationPage createNewProjectCreationPage() {
+ return this.myProjectPage;
+ }
+
+}

Back to the top