Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPauline DEVILLE2018-06-29 13:39:47 +0000
committerNicolas FAUVERGUE2018-06-29 15:04:29 +0000
commit2770c42a6d121ea3e1edb94b6354a5c2b79e72f4 (patch)
treeed5ca4ae42b258f11b08f46ec6daef1dcc459937 /plugins
parent55095e6b32ca10711ce107807dce6c23e66e0183 (diff)
downloadorg.eclipse.papyrus-2770c42a6d121ea3e1edb94b6354a5c2b79e72f4.tar.gz
org.eclipse.papyrus-2770c42a6d121ea3e1edb94b6354a5c2b79e72f4.tar.xz
org.eclipse.papyrus-2770c42a6d121ea3e1edb94b6354a5c2b79e72f4.zip
Bug 493312 - [Wizard] Apply multiple profiles in new model wizard
Change-Id: I6e1d2f669a48d1abbec3721f33e74196028313e3 Signed-off-by: Pauline DEVILLE <pauline.deville@cea.fr>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/META-INF/MANIFEST.MF2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/pom.xml2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/messages.properties2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectRepresentationKindPage.java17
-rwxr-xr-xplugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/profile/ProfileChooserComposite.java214
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateModelWizard.java26
6 files changed, 212 insertions, 51 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/META-INF/MANIFEST.MF
index 352fe896318..276d9bfe151 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/META-INF/MANIFEST.MF
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/META-INF/MANIFEST.MF
@@ -25,7 +25,7 @@ Require-Bundle: org.eclipse.m2m.qvt.oml;bundle-version="[3.6.0,4.0.0)";visibilit
org.eclipse.papyrus.infra.architecture.representation;bundle-version="[1.0.0,3.0.0)"
Bundle-Vendor: %pluginProvider
Bundle-ActivationPolicy: lazy
-Bundle-Version: 3.0.200.qualifier
+Bundle-Version: 3.1.0.qualifier
Bundle-Name: %pluginName
Bundle-Localization: plugin
Bundle-Activator: org.eclipse.papyrus.uml.diagram.wizards.Activator
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/pom.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/pom.xml
index 6b0b52120ed..d2cac58c7e4 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/pom.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/pom.xml
@@ -7,6 +7,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.uml.diagram.wizards</artifactId>
- <version>3.0.200-SNAPSHOT</version>
+ <version>3.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ 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/messages/messages.properties b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/messages.properties
index f835b2faf50..572f571a181 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
@@ -53,7 +53,7 @@ SelectArchitectureContextPage_select_language=Select the context of the new repr
SelectArchitectureContextPage_select_one_category=Please select at least one context
-SelectRepresentationKindPage_0=Choose a profile to apply
+SelectRepresentationKindPage_0=Choose profiles to apply
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:
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectRepresentationKindPage.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectRepresentationKindPage.java
index c209de4fda1..e946977e572 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectRepresentationKindPage.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectRepresentationKindPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2017 Obeo, Christian W. Damus, and others.
+ * Copyright (c) 2008, 2017, 2018 Obeo, 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
@@ -10,6 +10,7 @@
* Tatiana Fesenko(CEA) - improved look&feel
* Saadia Dhouib (CEA LIST) - Implementation of loading diagrams from template files (.uml, .di , .notation)
* Christian W. Damus - bug 471453
+ * Pauline DEVILLE (CEA LIST) - Bug 493312 - [Wizard] Apply multiple profiles in new model wizard
*******************************************************************************/
package org.eclipse.papyrus.uml.diagram.wizards.pages;
@@ -183,11 +184,25 @@ public class SelectRepresentationKindPage extends WizardPage {
});
}
+ /**
+ * @deprecated Since 3.1
+ * Use getProfilesURI() instead
+ */
public String getProfileURI() {
return profileChooserComposite.getProfileURI();
}
/**
+ * Get choose profiles
+ * @return the list of selected profiles
+ *
+ * @since 3.1
+ */
+ public List<String> getProfilesURI() {
+ return profileChooserComposite.getProfilesURI();
+ }
+
+ /**
* Check that the provided path matches against a known Profile and that it is defined
*
* @return
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/profile/ProfileChooserComposite.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/profile/ProfileChooserComposite.java
index 18cab526b23..c90cf41ef4a 100755
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/profile/ProfileChooserComposite.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/profile/ProfileChooserComposite.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2015 CEA LIST and others.
+ * Copyright (c) 2015, 2018 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
@@ -8,12 +8,17 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * Pauline DEVILLE (CEA LIST) - Bug 493312 - [Wizard] Apply multiple profiles in new model wizard
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.wizards.profile;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
import java.util.LinkedList;
+import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IStatus;
@@ -49,6 +54,11 @@ import org.eclipse.uml2.uml.Profile;
*/
public class ProfileChooserComposite extends Composite {
+ /**
+ * @since 3.1
+ */
+ public static final String PROFILE_SEPARATOR = "\n"; //$NON-NLS-1$
+
private Text textField;
private Button workspaceButton;
@@ -57,14 +67,15 @@ public class ProfileChooserComposite extends Composite {
private LinkedList<ViewerFilter> filters;
- private IFile selectedFile;
-
private ElementTreeSelectionDialog treeDialog;
private boolean workspaceProfile;
private String[] workspaceFilters = new String[] { "profile.uml" }; //$NON-NLS-1$
+ private List<IFile> selectedFile;
+
+ private List<Object> selectedProfile;
/**
* Constructor.
@@ -73,6 +84,9 @@ public class ProfileChooserComposite extends Composite {
public ProfileChooserComposite(Composite parent) {
super(parent, SWT.NONE);
+ this.selectedFile = new ArrayList<>();
+ this.selectedProfile = new ArrayList<>();
+
this.setLayout(new GridLayout(2, true));
this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
@@ -90,37 +104,38 @@ public class ProfileChooserComposite extends Composite {
filters = new LinkedList<ViewerFilter>();
setFilterExtensions(workspaceFilters);
- textField = new Text(parent, SWT.BORDER);
+ textField = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
GridData fieldGrid = new GridData(SWT.FILL, SWT.FILL, true, false);
- fieldGrid.verticalAlignment = SWT.FILL;
+ fieldGrid.verticalSpan = 10;
fieldGrid.horizontalSpan = 2;
textField.setLayoutData(fieldGrid);
treeDialog = new ElementTreeSelectionDialog(getShell(), new ProfileChooserLabelProvider(), new ProfileChooserContentProvider());
treeDialog.setInput(RegisteredProfile.getRegisteredProfiles());
- treeDialog.setAllowMultiple(false);
+ treeDialog.setAllowMultiple(true);
treeDialog.setTitle(Messages.ProfileChooserComposite_RegisteredProfilesDialog);
SelectionListener selectionListener = new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
+ refreshListFromTextField(); // since we can modified the text field we have to refresh list to display selection
if (e.widget.equals(workspaceButton)) {
- workspaceProfile = true;
- IFile[] ifile = WorkspaceResourceDialog.openFileSelection(getShell(), null, null, false, new IFile[] { selectedFile }, filters);
+ IFile[] ifile = WorkspaceResourceDialog.openFileSelection(getShell(), null, null, true, selectedFile.toArray(), filters);
if (ifile.length > 0) {
- selectedFile = ifile[0];
- textField.setText(selectedFile.getFullPath().toString());
+ selectedFile = new ArrayList<>(Arrays.asList(ifile));
+ refreshTextField();
}
}
if (e.widget.equals(registeredButton)) {
- workspaceProfile = false;
+ treeDialog.setInitialSelections(selectedProfile.toArray());
treeDialog.open();
- IRegisteredProfile profile = (IRegisteredProfile) treeDialog.getFirstResult();
+ Object[] profiles = treeDialog.getResult();
- if (profile != null) {
- textField.setText(profile.getPath().toString());
+ if (profiles != null) {
+ selectedProfile = new ArrayList<>(Arrays.asList(profiles));
+ refreshTextField();
}
}
}
@@ -129,6 +144,7 @@ public class ProfileChooserComposite extends Composite {
public void widgetDefaultSelected(SelectionEvent e) {
// nothing to do
}
+
};
workspaceButton = new Button(parent, SWT.NONE);
@@ -145,40 +161,95 @@ public class ProfileChooserComposite extends Composite {
}
/**
- * Check that the provided path matches against a known Profile and that it is defined
+ * This method refresh selectedElement and selectedProfile according to the text field
+ *
+ * @since 3.1
+ */
+ private void refreshListFromTextField() {
+ if (textField.isDisposed()) {
+ return;
+ }
+
+ List<String> stringList = Arrays.asList(textField.getText().split(PROFILE_SEPARATOR));
+ Iterator<IFile> fileIterator = selectedFile.iterator();
+ while (fileIterator.hasNext()) {
+ IFile file = fileIterator.next();
+ if (!stringList.contains(file.getFullPath().toString().trim())) {
+ fileIterator.remove();
+ }
+ }
+
+ Iterator<Object> profileIterator = selectedProfile.iterator();
+ while (profileIterator.hasNext()) {
+ Object profile = profileIterator.next();
+ if (profile instanceof IRegisteredProfile) {
+ String profilePath = registeredProfileToString((IRegisteredProfile) profile);
+ if (!stringList.contains(profilePath)) {
+ profileIterator.remove();
+ }
+ }
+ }
+ }
+
+ /**
+ * This method refresh the text field according to the content of selectedProfile and selectedFile.
+ *
+ * @since 3.1
+ */
+ private void refreshTextField() {
+ StringBuilder builder = new StringBuilder();
+ for (Object profile : selectedProfile) {
+ if (profile instanceof IRegisteredProfile) {
+ builder.append(registeredProfileToString(((IRegisteredProfile) profile)));
+ builder.append(PROFILE_SEPARATOR);
+ }
+ }
+ for (IFile file : selectedFile) {
+ builder.append(fileProfileToString(file));
+ builder.append(PROFILE_SEPARATOR);
+ }
+ // remove last profile separator
+ if (!builder.toString().isEmpty()) {
+ builder.delete(builder.length() - 1, builder.length());
+ }
+ textField.setText(builder.toString());
+ }
+
+ /**
+ * Check that the provided path matches against a known Profile and that it is defined.
*
* @return
- * The IStatus of the fetched profile
+ * The IStatus of the fetched profile.
*/
public IStatus getProfileDefinitionStatus() {
ResourceSet resourceSet = Util.createTemporaryResourceSet();
-
try {
- String profilePath = getProfileURI();
- if (profilePath == null || profilePath.equalsIgnoreCase("")) {//$NON-NLS-1$
+ List<String> profilePath = getProfilesURI();
+ if (profilePath.isEmpty()) {
return Status.OK_STATUS;
}
- URI profileURI = URI.createURI(profilePath);
- Resource resource = resourceSet.getResource(profileURI, true);
+ for (String pp : profilePath) {
+ URI profileURI = URI.createURI(pp);
+ Resource resource = resourceSet.getResource(profileURI, true);
- if (resource == null) {
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.ProfileChooserComposite_ProfileStatus_NullResource);
- }
- if (resource.getContents().isEmpty()) {
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.ProfileChooserComposite_ProfileStatus_EmptyResource);
- }
+ if (resource == null) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.ProfileChooserComposite_ProfileStatus_NullResource);
+ }
+ if (resource.getContents().isEmpty()) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.ProfileChooserComposite_ProfileStatus_EmptyResource);
+ }
- EObject eObject = resource.getContents().get(0);
- if (!(eObject instanceof Profile)) {
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.ProfileChooserComposite_ProfileStatus_NotAProfile);
- }
+ EObject eObject = resource.getContents().get(0);
+ if (!(eObject instanceof Profile)) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.ProfileChooserComposite_ProfileStatus_NotAProfile);
+ }
- Profile profile = (Profile) eObject;
- if (!profile.isDefined()) {
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.ProfileChooserComposite_ProfileStatus_ProfileNotDefined);
+ Profile profile = (Profile) eObject;
+ if (!profile.isDefined()) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.ProfileChooserComposite_ProfileStatus_ProfileNotDefined);
+ }
}
-
return Status.OK_STATUS;
} catch (WrappedException ex) {
@@ -190,10 +261,13 @@ public class ProfileChooserComposite extends Composite {
}
/**
- * Gets the selected profile's path
+ * Gets the selected profile's path.
*
* @return
- * the selected profile's path
+ * the selected profile's path.
+ *
+ * @deprecated since 3.1
+ * Use getProfilesURI() instead.
*/
public String getProfileURI() {
if (textField.isDisposed()) {
@@ -212,6 +286,61 @@ public class ProfileChooserComposite extends Composite {
}
/**
+ * Gets selected profiles' path.
+ *
+ * @return
+ * the list of selected profile's path.
+ *
+ * @since 3.1
+ */
+ public List<String> getProfilesURI() {
+ List<String> result = new ArrayList<>();
+ List<String> stringList = new ArrayList<>();
+
+ if (textField.isDisposed()) {
+ return result;
+ }
+
+ String path = textField.getText();
+ if (path.trim().equals("")) { //$NON-NLS-1$
+ return result;
+ }
+
+ stringList = Arrays.asList(path.split(PROFILE_SEPARATOR));
+ for (String elt : stringList) {
+ result.add(elt.trim());
+ }
+
+ return result;
+ }
+
+ /**
+ * Get the text representing the file profile.
+ *
+ * @param file
+ * The file.
+ * @return text to display.
+ *
+ * @since 3.1
+ */
+ protected String fileProfileToString(IFile file) {
+ return file.getFullPath().toString();
+ }
+
+ /**
+ * Get the text representing the registered profile.
+ *
+ * @param registeredProfile
+ * The registered profile.
+ * @return text to display
+ *
+ * @since 3.1
+ */
+ protected String registeredProfileToString(IRegisteredProfile registeredProfile) {
+ return registeredProfile.getPath().toString();
+ }
+
+ /**
* Sets the file extensions that this FileChooser accepts
* Files that don't match one of these extensions will be hidden
*
@@ -227,4 +356,15 @@ public class ProfileChooserComposite extends Composite {
return textField;
}
+ /**
+ * @see org.eclipse.swt.widgets.Widget#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ super.dispose();
+ selectedFile.clear();
+ selectedProfile.clear();
+ }
+
}
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 5f50d214c8a..76c6a284f9b 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,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2017 Obeo, CEA LIST, Christian W. Damus, and others.
+ * Copyright (c) 2008, 2017, 2018 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
@@ -12,7 +12,8 @@
* Christian W. Damus (CEA) - create models by URI, not IFile (CDO)
* Christian W. Damus (CEA) - Support creating models in repositories (CDO)
* Christian W. Damus - bugs 490936, 471453
- *
+ * Pauline DEVILLE (CEA LIST) - Bug 493312 - [Wizard] Apply multiple profiles in new model wizard
+ *
*******************************************************************************/
package org.eclipse.papyrus.uml.diagram.wizards.wizards;
@@ -351,7 +352,7 @@ public class CreateModelWizard extends Wizard implements INewWizard {
}
private void initProfile(ModelSet modelSet) {
- boolean isToApplyProfile = selectRepresentationKindPage.getProfileURI() != null;
+ boolean isToApplyProfile = !selectRepresentationKindPage.getProfilesURI().isEmpty();
boolean isProfileDefined = selectRepresentationKindPage.getProfileDefinitionStatus().isOK();
if (isToApplyProfile & isProfileDefined) {
applyProfile(modelSet);
@@ -543,15 +544,20 @@ public class CreateModelWizard extends Wizard implements INewWizard {
}
protected void applyProfile(ModelSet modelSet) {
- String profilePath = selectRepresentationKindPage.getProfileURI();
- Resource resource = modelSet.getResource(URI.createURI(profilePath), true);
- Profile profileToApply = (Profile) resource.getContents().get(0);
+ List<String> profilePath = selectRepresentationKindPage.getProfilesURI();
+ CompoundCommand cc = new CompoundCommand();
+ for (String pp : profilePath) {
+ Resource resource = modelSet.getResource(URI.createURI(pp), 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);
+ 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);
+ cc.append(new ApplyProfileCommand(manipulatedModel, profileToApply, modelSet.getTransactionalEditingDomain()));
+ }
+ if (cc.canExecute()) {
+ getCommandStack(modelSet).execute(cc);
+ }
}
protected void applyTemplateTransfo(ModelSet modelSet) {

Back to the top