diff options
Diffstat (limited to 'plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus')
20 files changed, 1812 insertions, 0 deletions
diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/Activator.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/Activator.java new file mode 100644 index 00000000000..3ded343206d --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/Activator.java @@ -0,0 +1,80 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.toolsmiths.profilemigration.ui; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + /** + * The plug-in ID + */ + public static final String PLUGIN_ID = "org.eclipse.papyrus.toolsmiths.profilemigration.ui"; //$NON-NLS-1$ + + /** + * The shared instance + */ + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /** + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /** + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path + * + * @param path + * the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/Messages.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/Messages.java new file mode 100644 index 00000000000..b0b497de4c2 --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/Messages.java @@ -0,0 +1,63 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.toolsmiths.profilemigration.ui; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.papyrus.toolsmiths.profilemigration.ui.messages"; //$NON-NLS-1$ + public static String AbstractProfileMigrationDialog_description; + public static String AbstractProfileMigrationDialog_DoNotShowItAgain; + public static String AbstractProfileMigrationDialog_MigrateAction; + public static String AddPropertyToStereotypeDialog_Description; + public static String AddPropertyToStereotypeDialog_Title; + public static String ChangeIsAbstractFromStereotypeDialog_Description; + public static String ChangeIsAbstractFromStereotypeDialog_Title; + public static String ChangeIsStaticFeatureDialog_Description; + public static String ChangeIsStaticFeatureDialog_Title; + public static String ChangeLowerMultiplicityDialog_Description; + public static String ChangeLowerMultiplicityDialog_Title; + public static String ChangeUpperMultiplicityDialog_Description; + public static String ChangeUpperMultiplicityDialog_Title; + public static String DeleteEnumerationLiteralFromEnumerationDialog_Description; + public static String DeleteEnumerationLiteralFromEnumerationDialog_Title; + public static String MovePackageDialog_description; + public static String MovePackageDialog_title; + public static String MoveProfileDialog_description; + public static String MoveProfileDialog_title; + public static String MoveStereotypeDialog_content; + public static String MoveStereotypeDialog_description; + public static String MoveStereotypeDialog_No; + public static String MoveStereotypeDialog_title; + public static String MoveStereotypeDialog_Yes; + public static String ProfileMigrationPreferenceConstants_AddPropertyToStereotype; + public static String ProfileMigrationPreferenceConstants_ChangeIsStaticFeatureOfProperty; + public static String ProfileMigrationPreferenceConstants_ChangeLowerMultiplicityOfProperty; + public static String ProfileMigrationPreferenceConstants_ChangeUpperMultiplicityOfProperty; + public static String ProfileMigrationPreferenceConstants_DeleteEnumLiteralFromEnumeration; + public static String ProfileMigrationPreferenceConstants_PackageMove; + public static String ProfileMigrationPreferenceConstants_ProfileMove; + public static String ProfileMigrationPreferenceConstants_StereotypeMove; + public static String ProfileMigrationPreferenceConstants_SuperStereotypeBecomingAbstract; + public static String ProfileMigrationPreferencePage_FileInCached; + public static String ProfileMigrationPreferencePage_ShowDialogs; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/AbstractApplyNewProfileDialog.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/AbstractApplyNewProfileDialog.java new file mode 100644 index 00000000000..f96623b15fa --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/AbstractApplyNewProfileDialog.java @@ -0,0 +1,96 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs; + +import org.eclipse.osgi.util.NLS; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Messages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.uml2.uml.Profile; + +/** + * Abstract dialog to ask the user if he want to reapply a profile + */ +public abstract class AbstractApplyNewProfileDialog extends AbstractProfileMigrationDialog { + + private Button radioYes; + + private Button radioNo; + + private boolean reapply = false; + + /** + * The new profile to apply + */ + protected Profile newProfile; + + /** + * Constructor. + * + * @param shell + * the active shell + * @param title + * the title of the dialog + * @param prefConst + * the preference constant (show or not the dialog) + * @param newProfile + * the new profile to apply + */ + public AbstractApplyNewProfileDialog(Shell shell, String title, String prefConst, Profile newProfile) { + super(shell, title, prefConst); + this.newProfile = newProfile; + } + + /** + * @see org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs.AbstractProfileMigrationDialog#getMigrationActionSectionContent(org.eclipse.swt.widgets.Composite, org.eclipse.ui.forms.widgets.FormToolkit) + * + * @param body + * @param toolkit + */ + @Override + protected void getMigrationActionSectionContent(Composite body, FormToolkit toolkit) { + toolkit.createLabel(body, NLS.bind(Messages.MoveStereotypeDialog_content, newProfile.getName())); + radioYes = new Button(body, SWT.RADIO); + radioYes.setText(Messages.MoveStereotypeDialog_Yes); + radioYes.setSelection(true); + radioNo = new Button(body, SWT.RADIO); + radioNo.setText(Messages.MoveStereotypeDialog_No); + } + + /** + * @see org.eclipse.jface.dialogs.Dialog#okPressed() + */ + @Override + protected void okPressed() { + if (radioYes.getSelection()) { + reapply = true; + } else { + reapply = false; + } + super.okPressed(); + } + + /** + * @return the reapply + */ + public boolean isReapply() { + return reapply; + } + + +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/AbstractChangeMultiplicityDialog.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/AbstractChangeMultiplicityDialog.java new file mode 100644 index 00000000000..d541bf68336 --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/AbstractChangeMultiplicityDialog.java @@ -0,0 +1,88 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs; + +import java.util.List; +import java.util.Map; + +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.utils.EStructuralFeatureUtil; +import org.eclipse.papyrus.uml.properties.widgets.EStructuralFeatureEditor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; + +/** + * Abstract dialog to ask the user to add or remove value to slots to match with a new multiplicity + */ +public abstract class AbstractChangeMultiplicityDialog extends AbstractTabsProfileMigrationDialog { + + /** + * the property whose multiplicity change + */ + protected Property property; + + /** + * the old value of the modified multiplicity + */ + protected int oldValue; + + /** + * the new value of the modified multiplicity + */ + protected int newValue; + + /** + * Constructor. + * + * @param shell + * the active shell + * @param title + * the title of the dialog + * @param prefConst + * the preference constant (show or not the dialog) + * @param property + * the property whose multiplicity change + * @param oldValue + * the old value of the modified multiplicity + * @param newValue + * the new value of the modified multiplicity + * @param mapElementToStereotype + * the map of element with every stereotype application of stereotypes concerning by the modification + */ + public AbstractChangeMultiplicityDialog(Shell shell, String title, String prefConst, Property property, int oldValue, int newValue, Map<Element, List<Stereotype>> mapElementToStereotype) { + super(shell, title, prefConst, mapElementToStereotype); + this.property = property; + this.oldValue = oldValue; + this.newValue = newValue; + this.mapElementToStereotype = mapElementToStereotype; + } + + /** + * @see org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs.AbstractTabsProfileMigrationDialog#getMigrationActionTabContent(org.eclipse.swt.widgets.Composite, org.eclipse.uml2.uml.Element, org.eclipse.uml2.uml.Stereotype) + * + * @param body + * @param element + * @param stereotype + */ + @Override + protected void getMigrationActionTabContent(Composite body, Element element, Stereotype stereotype) { + EStructuralFeatureEditor editor = new EStructuralFeatureEditor(body, SWT.NONE); + EStructuralFeatureUtil.setValueToEditor(editor, element, property, stereotype); + } + +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/AbstractProfileMigrationDialog.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/AbstractProfileMigrationDialog.java new file mode 100644 index 00000000000..63541b280b4 --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/AbstractProfileMigrationDialog.java @@ -0,0 +1,216 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Activator; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Messages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.FillLayout; +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.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.forms.FormDialog; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.ScrolledForm; +import org.eclipse.ui.forms.widgets.Section; + +/** + * + * This abstract class is used to create dialog for asking action to the model designer + * + * -------------------------------------------- + * Title + * -------------------------------------------- + * Description Section (text) + * -------------------------------------------- + * Extra section (define by sub classes) + * -------------------------------------------- + * ButtonBar (Cancel | OK) + * -------------------------------------------- + */ +abstract public class AbstractProfileMigrationDialog extends FormDialog { + + private String title; + + private String prefConst; + + private Button checkBox; + + /** + * Constructor + * + * @param shell + * the active shell + * @param title + * the title of the dialog + * @param description + * the description of the problem + * @param prefConst + * the preference constant for the "do not show the dialog again" checkbox + */ + public AbstractProfileMigrationDialog(Shell shell, String title, String prefConst) { + super(shell); + this.title = title; + this.prefConst = prefConst; + } + + /** + * @see org.eclipse.ui.forms.FormDialog#createFormContent(org.eclipse.ui.forms.IManagedForm) + */ + @Override + protected void createFormContent(IManagedForm mform) { + mform.getForm().setText(title); + ScrolledForm scrolledForm = mform.getForm(); + FormToolkit toolkit = mform.getToolkit(); + Composite parent = scrolledForm.getBody(); + parent.setLayout(new GridLayout()); + createDescriptionSections(scrolledForm.getBody(), toolkit); + createMigrationActionSections(scrolledForm.getBody(), toolkit); + dontShowItAgainCheckbox(scrolledForm.getBody(), toolkit); + hookListeners(); + } + + /** + * Create the description section + * + * @param body + * the section's parent widget + * @param toolkit + * the form toolkit + */ + protected void createDescriptionSections(Composite body, FormToolkit toolkit) { + String lSectionTitle = getDecriptionSectionTitle(); + Section lSection = toolkit.createSection(body, ExpandableComposite.EXPANDED | ExpandableComposite.TITLE_BAR); + lSection.setLayoutData(new GridData(GridData.FILL_VERTICAL)); + if (lSectionTitle != null) { + lSection.setText(lSectionTitle); + } + ScrolledForm lInsideScrolledForm = toolkit.createScrolledForm(lSection); + lInsideScrolledForm.setExpandHorizontal(true); + lInsideScrolledForm.setExpandVertical(true); + Composite lBody = lInsideScrolledForm.getBody(); + GridLayout lLayout = new GridLayout(); + lLayout.numColumns = 1; + lBody.setLayout(lLayout); + if (getDecription() != null) { + toolkit.createLabel(lBody, getDecription(), SWT.WRAP); + } + lSection.setClient(lInsideScrolledForm); + } + + /** + * Get the description section title + * + * @return the description section title + */ + protected String getDecriptionSectionTitle() { + return Messages.AbstractProfileMigrationDialog_description; + } + + /** + * Get the description + * + * @return the description + */ + abstract protected String getDecription(); + + /** + * Create the migration action section + * + * @param body + * the section's parent widget + * @param toolkit + * the form toolkit + */ + protected void createMigrationActionSections(Composite body, FormToolkit toolkit) { + String lSectionTitle = getMigrationActionSectionTitle(); + Section lSection = toolkit.createSection(body, ExpandableComposite.EXPANDED | ExpandableComposite.TITLE_BAR); + lSection.setLayoutData(new GridData(GridData.FILL_BOTH)); + if (lSectionTitle != null) { + lSection.setText(lSectionTitle); + } + ScrolledForm lInsideScrolledForm = toolkit.createScrolledForm(lSection); + lInsideScrolledForm.setExpandHorizontal(true); + lInsideScrolledForm.setExpandVertical(true); + Composite lBody = lInsideScrolledForm.getBody(); + FillLayout lLayout = new FillLayout(); + lLayout.type = SWT.HORIZONTAL; + lBody.setLayout(lLayout); + getMigrationActionSectionContent(lBody, toolkit); + lInsideScrolledForm.reflow(true); + lSection.setClient(lInsideScrolledForm); + } + + /** + * Get the migration action section title + * + * @return the migration action section title + */ + protected String getMigrationActionSectionTitle() { + return Messages.AbstractProfileMigrationDialog_MigrateAction; + } + + /** + * Create the content of the migration action section + * + * @param body + * the section's parent widget + * @param toolkit + * the form toolkit + */ + abstract protected void getMigrationActionSectionContent(Composite body, FormToolkit toolkit); + + /** + * Create a checkbox for not displaying the popup again + * + * @param body + * @param toolkit + * @return the checkbox + */ + protected Control dontShowItAgainCheckbox(Composite body, FormToolkit toolkit) { + checkBox = toolkit.createButton(body, Messages.AbstractProfileMigrationDialog_DoNotShowItAgain, SWT.CHECK | SWT.LEFT); + return checkBox; + } + + /** + * Add listeners to widgets + */ + private void hookListeners() { + SelectionListener selectCreateListener = new SelectionAdapter() { + + /** + * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) + */ + @Override + public void widgetSelected(SelectionEvent e) { + if (e.getSource() instanceof Button) { + boolean doNotShow = ((Button) e.getSource()).getSelection(); + final IPreferenceStore prefStore = Activator.getDefault().getPreferenceStore(); + prefStore.putValue(prefConst, Boolean.toString(!doNotShow)); + } + } + }; + checkBox.addSelectionListener(selectCreateListener); + } +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/AbstractTabsProfileMigrationDialog.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/AbstractTabsProfileMigrationDialog.java new file mode 100644 index 00000000000..c45c2335012 --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/AbstractTabsProfileMigrationDialog.java @@ -0,0 +1,116 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs; + +import java.util.List; +import java.util.Map; + +import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Stereotype; + +/** + * Abstract dialog with the main structure for a dialog using tabs to display multiple stereotype application + * + * --------------------- + * tabs for each element owning a stereotype application concerning by the migration + * --------------------- + * tabs for each stereotype applied is the element concerning by the migration (if there is more than one) + * --------------------- + */ +public abstract class AbstractTabsProfileMigrationDialog extends AbstractProfileMigrationDialog { + + /** + * The map of element with every stereotype application of stereotypes concerning by the modification + */ + protected Map<Element, List<Stereotype>> mapElementToStereotype; + + /** + * Constructor. + * + * @param shell + * the shell + * @param title + * the title of the dialog + * @param prefConst + * the preference constant which correspond to this dialog display + * @param mapElementToStereotype + * the map of element with every stereotype application of stereotypes concerning by the modification + */ + public AbstractTabsProfileMigrationDialog(Shell shell, String title, String prefConst, Map<Element, List<Stereotype>> mapElementToStereotype) { + super(shell, title, prefConst); + this.mapElementToStereotype = mapElementToStereotype; + } + + @Override + protected void getMigrationActionSectionContent(Composite body, FormToolkit toolkit) { + TabFolder tabFolder = new TabFolder(body, SWT.NONE); + UMLLabelProvider labelProvider = new UMLLabelProvider(); + for (Element element : mapElementToStereotype.keySet()) { + TabItem tabItem = new TabItem(tabFolder, SWT.NONE); + tabItem.setText(labelProvider.getText(element)); + tabItem.setControl(getTabElementControl(element, tabFolder)); + } + } + + private Control getTabElementControl(Element element, TabFolder tabFolder) { + Composite composite = new Composite(tabFolder, SWT.NONE); + composite.setLayout(new FillLayout(SWT.HORIZONTAL)); + + // StructuralFeatureEditor initialization + if (!mapElementToStereotype.isEmpty()) { + List<Stereotype> stereotypes = mapElementToStereotype.get(element); + if (stereotypes.size() == 1) { + getMigrationActionTabContent(composite, element, stereotypes.get(0)); + } else if (stereotypes.size() > 1) { + TabFolder tabFolder2 = new TabFolder(composite, SWT.NONE); + UMLLabelProvider labelProvider = new UMLLabelProvider(); + for (Stereotype stereotype : stereotypes) { + TabItem tabItem = new TabItem(tabFolder2, SWT.NONE); + tabItem.setText(labelProvider.getText(stereotype)); + tabItem.setControl(getTabControlStereotype(element, stereotype, tabFolder2)); + } + } + } + return composite; + } + + private Control getTabControlStereotype(Element element, Stereotype stereotype, TabFolder tabFolder2) { + Composite composite = new Composite(tabFolder2, SWT.NONE); + composite.setLayout(new FillLayout(SWT.HORIZONTAL)); + getMigrationActionTabContent(composite, element, stereotype); + return composite; + } + + /** + * Create the content for each tab + * + * @param body + * the body + * @param element + * the element owning the stereotype application + * @param stereotype + * the stereotype applied + */ + protected abstract void getMigrationActionTabContent(Composite body, Element element, Stereotype stereotype); + +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/AddPropertyToStereotypeDialog.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/AddPropertyToStereotypeDialog.java new file mode 100644 index 00000000000..21bd57c7d3f --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/AddPropertyToStereotypeDialog.java @@ -0,0 +1,71 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs; + +import java.util.List; +import java.util.Map; + +import org.eclipse.osgi.util.NLS; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Messages; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.preferences.ProfileMigrationPreferenceConstants; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.utils.EStructuralFeatureUtil; +import org.eclipse.papyrus.uml.properties.widgets.EStructuralFeatureEditor; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; + +/** + * Dialog to ask the user to add value to slot corresponding to newly add property + */ +public class AddPropertyToStereotypeDialog extends AbstractTabsProfileMigrationDialog { + + private static final String DIALOG_TITLE = Messages.AddPropertyToStereotypeDialog_Title; + + private Stereotype stereotype; + + private Property property; + + /** + * Constructor. + * + * @param shell + * the active shell + * @param stereotype + * the stereotype owning the new property + * @param property + * the newly added property + * @param mapElementToStereotype + * the map of element with every stereotype application of stereotypes owning the new property (and sub stereotypes) + */ + public AddPropertyToStereotypeDialog(Shell shell, Stereotype stereotype, Property property, Map<Element, List<Stereotype>> mapElementToStereotype) { + super(shell, DIALOG_TITLE, ProfileMigrationPreferenceConstants.ADD_PROPERTY_TO_STEREOTYPE, mapElementToStereotype); + this.stereotype = stereotype; + this.property = property; + } + + @Override + protected String getDecription() { + return NLS.bind(Messages.AddPropertyToStereotypeDialog_Description, + new Object[] { property.getName(), stereotype.getName(), property.getLower(), property.getUpper() }); + } + + @Override + protected void getMigrationActionTabContent(Composite body, Element element, Stereotype stereotype) { + EStructuralFeatureEditor editor = new EStructuralFeatureEditor(body, 0); + EStructuralFeatureUtil.setValueToEditor(editor, element, property, stereotype); + } + +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/ChangeIsAbstractFromStereotypeDialog.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/ChangeIsAbstractFromStereotypeDialog.java new file mode 100644 index 00000000000..9d75f44a495 --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/ChangeIsAbstractFromStereotypeDialog.java @@ -0,0 +1,117 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.osgi.util.NLS; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Messages; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.preferences.ProfileMigrationPreferenceConstants; +import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Stereotype; + +/** + * Dialog to ask the user which sub stereotype he want to apply instead of the newly abstract stereotype + */ +public class ChangeIsAbstractFromStereotypeDialog extends AbstractTabsProfileMigrationDialog { + + private Stereotype abstractStereotype; + + private List<Stereotype> subStereotypes; + + private Map<Element, List<Stereotype>> result = new HashMap<>(); + + private Map<Element, TableViewer> tableViewer = new HashMap<>();; + + /** + * Constructor + * + * @param shell + * the active shell + * @param abstractStereotype + * the stereotype becoming abstract + * @param subStereotype + * the list of stereotype generalizing the abstractStereotype + * @param mapElementsToStereotpyes + * the map of element with every stereotype application of the stereotypes which has become abstract (and sub stereotypes) + */ + public ChangeIsAbstractFromStereotypeDialog(Shell shell, Stereotype abstractStereotype, List<Stereotype> subStereotype, Map<Element, List<Stereotype>> mapElementsToStereotpyes) { + super(shell, Messages.ChangeIsAbstractFromStereotypeDialog_Title, ProfileMigrationPreferenceConstants.SUPER_STEREOTYPE_BECOMING_ABSTRACT, mapElementsToStereotpyes); + this.abstractStereotype = abstractStereotype; + this.subStereotypes = subStereotype; + } + + /** + * @see org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs.AbstractProfileMigrationDialog#getDecription() + */ + @Override + protected String getDecription() { + return NLS.bind(Messages.ChangeIsAbstractFromStereotypeDialog_Description, abstractStereotype.getName()); + } + + @Override + protected void getMigrationActionTabContent(Composite body, Element element, Stereotype stereotype) { + TableViewer tv = new TableViewer(body, SWT.CHECK); + tv.setContentProvider(new IStructuredContentProvider() { + /** + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) + * + * @param inputElement + * @return the array of sub stereotype + */ + @Override + public Object[] getElements(Object inputElement) { + @SuppressWarnings("unchecked") + List<Stereotype> v = (List<Stereotype>) inputElement; + return v.toArray(); + } + }); + tv.setLabelProvider(new UMLLabelProvider()); + tv.setInput(subStereotypes); + tableViewer.put(element, tv); + } + + @Override + protected void okPressed() { + for (Entry<Element, TableViewer> entry : tableViewer.entrySet()) { + TableItem items[] = entry.getValue().getTable().getItems(); + List<Stereotype> checkedStereotypes = new ArrayList<>(); + for (TableItem item : items) { + if (item.getChecked()) { + checkedStereotypes.add((Stereotype) item.getData()); + } + } + result.put(entry.getKey(), checkedStereotypes); + } + super.okPressed(); + } + + /** + * @return The map linking the element to the list of stereotypes which should be applied on it + */ + public Map<Element, List<Stereotype>> getResult() { + return result; + } +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/ChangeIsStaticFeatureDialog.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/ChangeIsStaticFeatureDialog.java new file mode 100644 index 00000000000..b7c645bbff4 --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/ChangeIsStaticFeatureDialog.java @@ -0,0 +1,73 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs; + +import org.eclipse.osgi.util.NLS; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Messages; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.preferences.ProfileMigrationPreferenceConstants; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.utils.EStructuralFeatureUtil; +import org.eclipse.papyrus.uml.properties.widgets.EStructuralFeatureEditor; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; + +/** + * Dialog to ask the user to select the static value (common to every slot corresponding to the property) + */ +public class ChangeIsStaticFeatureDialog extends AbstractProfileMigrationDialog { + + private static final String DIALOG_TITLE = Messages.ChangeIsStaticFeatureDialog_Title; + + private Stereotype stereotype; + + private Property property; + + private Element element; + + private EStructuralFeatureEditor editor; + + /** + * Constructor. + * + * @param shell + * the active shell + * @param stereotype + * the owner of the property + * @param property + * the modified property + * @param element + * one element owning the stereotype + */ + public ChangeIsStaticFeatureDialog(Shell shell, Stereotype stereotype, Property property, Element element) { + super(shell, DIALOG_TITLE, ProfileMigrationPreferenceConstants.CHANGE_IS_STATIC_FEATURE_PROPERTY); + this.stereotype = stereotype; + this.property = property; + this.element = element; + } + + @Override + protected String getDecription() { + return NLS.bind(Messages.ChangeIsStaticFeatureDialog_Description, property.getName(), stereotype.getName()); + } + + @Override + protected void getMigrationActionSectionContent(Composite body, FormToolkit toolkit) { + editor = new EStructuralFeatureEditor(body, 0); + EStructuralFeatureUtil.setValueToEditor(editor, element, property, stereotype); + } + +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/ChangeLowerMultiplicityDialog.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/ChangeLowerMultiplicityDialog.java new file mode 100644 index 00000000000..aaf934432c9 --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/ChangeLowerMultiplicityDialog.java @@ -0,0 +1,62 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs; + +import java.util.List; +import java.util.Map; + +import org.eclipse.osgi.util.NLS; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Messages; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.preferences.ProfileMigrationPreferenceConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; + +/** + * Dialog to ask the user to modify the number of values to match with the new multiplicity + */ +public class ChangeLowerMultiplicityDialog extends AbstractChangeMultiplicityDialog { + + /** + * The title of the dialog + */ + private static final String DIALOG_TITLE = Messages.ChangeLowerMultiplicityDialog_Title; + + /** + * Constructor. + * + * @param shell + * the active shell + * @param property + * the property whose multiplicity change + * @param oldValue + * the old value of the modified multiplicity + * @param newValue + * the new value of the modified multiplicity + * @param mapElementToStereotype + * the map of element with every stereotype application of stereotypes owning the modified property (and sub stereotypes) + */ + public ChangeLowerMultiplicityDialog(Shell shell, Property property, int oldValue, int newValue, Map<Element, List<Stereotype>> mapElementToStereotype) { + super(shell, DIALOG_TITLE, ProfileMigrationPreferenceConstants.CHANGE_LOWER_MULTIPLICITY_PROPERTY, property, oldValue, newValue, mapElementToStereotype); + } + + @Override + protected String getDecription() { + return NLS.bind(Messages.ChangeLowerMultiplicityDialog_Description, new Object[] { property.getName(), ((NamedElement) property.getOwner()).getName(), oldValue == -1 ? "*" : oldValue, newValue == -1 ? "*" : newValue }); //$NON-NLS-1$ //$NON-NLS-2$ + } + +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/ChangeUpperMultiplicityDialog.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/ChangeUpperMultiplicityDialog.java new file mode 100644 index 00000000000..eca6e45d97f --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/ChangeUpperMultiplicityDialog.java @@ -0,0 +1,59 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs; + +import java.util.List; +import java.util.Map; + +import org.eclipse.osgi.util.NLS; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Messages; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.preferences.ProfileMigrationPreferenceConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; + +/** + * Dialog to ask the user to modify the number of values to match with the new multiplicity + */ +public class ChangeUpperMultiplicityDialog extends AbstractChangeMultiplicityDialog { + + private static final String DIALOG_TITLE = Messages.ChangeUpperMultiplicityDialog_Title; + + /** + * Constructor. + * + * @param shell + * the active shell + * @param property + * the property whose multiplicity change + * @param oldValue + * the old value of the modified multiplicity + * @param newValue + * the new value of the modified multiplicity + * @param mapElementToStereotype + * the map of element with every stereotype application of stereotypes owning the modified property (and sub stereotypes) + */ + public ChangeUpperMultiplicityDialog(Shell shell, Property property, int oldValue, int newValue, Map<Element, List<Stereotype>> mapElementToStereotype) { + super(shell, DIALOG_TITLE, ProfileMigrationPreferenceConstants.CHANGE_UPPER_MULTIPLICITY_PROPERTY, property, oldValue, newValue, mapElementToStereotype); + } + + @Override + protected String getDecription() { + return NLS.bind(Messages.ChangeUpperMultiplicityDialog_Description, new Object[] { property.getName(), ((NamedElement) property.getOwner()).getName(), oldValue == -1 ? "*" : oldValue, newValue == -1 ? "*" : newValue }); //$NON-NLS-1$ //$NON-NLS-2$ + } + +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/DeleteEnumerationLiteralFromEnumerationDialog.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/DeleteEnumerationLiteralFromEnumerationDialog.java new file mode 100644 index 00000000000..01e55d2aa63 --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/DeleteEnumerationLiteralFromEnumerationDialog.java @@ -0,0 +1,77 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs; + +import java.util.List; +import java.util.Map; + +import org.eclipse.osgi.util.NLS; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Messages; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.preferences.ProfileMigrationPreferenceConstants; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.utils.EStructuralFeatureUtil; +import org.eclipse.papyrus.uml.properties.widgets.EStructuralFeatureEditor; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Enumeration; +import org.eclipse.uml2.uml.EnumerationLiteral; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; + +/** + * Dialog to ask the user if he wants to modify values which was the deleted EnumerationLiteral + */ +public class DeleteEnumerationLiteralFromEnumerationDialog extends AbstractTabsProfileMigrationDialog { + + private static final String DIALOG_TITLE = Messages.DeleteEnumerationLiteralFromEnumerationDialog_Title; + + private Enumeration enumeration; + + private EnumerationLiteral enumerationLiteral; + + /** + * Constructor. + * + * @param shell + * the active shell + * @param enumeration + * the Enumeration owning the deleted EnumerationLiteral + * @param enumerationLiteral + * the deleted EnumerationLiteral + * @param mapElementToStereotype + * the map of element with every stereotype application of stereotypes owning a property type by the Enumeration (and sub stereotypes) + */ + public DeleteEnumerationLiteralFromEnumerationDialog(Shell shell, Enumeration enumeration, EnumerationLiteral enumerationLiteral, Map<Element, List<Stereotype>> mapElementToStereotype) { + super(shell, DIALOG_TITLE, ProfileMigrationPreferenceConstants.DELETE_ENUM_LITERAL_FROM_ENUMERATION, mapElementToStereotype); + this.enumeration = enumeration; + this.enumerationLiteral = enumerationLiteral; + } + + @Override + protected String getDecription() { + return NLS.bind(Messages.DeleteEnumerationLiteralFromEnumerationDialog_Description, enumerationLiteral.getName(), enumeration.getName()); + } + + @Override + protected void getMigrationActionTabContent(Composite body, Element element, Stereotype stereotype) { + for (Property property : stereotype.getAllAttributes()) { + if (property.getType() == enumeration) { + EStructuralFeatureEditor editor = new EStructuralFeatureEditor(body, 0); + EStructuralFeatureUtil.setValueToEditor(editor, element, property, stereotype); + } + } + } + +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/MovePackageDialog.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/MovePackageDialog.java new file mode 100644 index 00000000000..18c38f8dfca --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/MovePackageDialog.java @@ -0,0 +1,53 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs; + +import org.eclipse.osgi.util.NLS; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Messages; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.preferences.ProfileMigrationPreferenceConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.uml2.uml.Profile; + +/** + * Dialog to ask to user if he want to apply a profile or not + */ +public class MovePackageDialog extends AbstractApplyNewProfileDialog { + + private static String DIALOG_TITLE = Messages.MovePackageDialog_title; + + private org.eclipse.uml2.uml.Package movedPackage; + + /** + * Constructor. + * + * @param shell + * the active shell + * @param movedPackage + * the moved package + * @param newProfile + * the new profile to apply + */ + public MovePackageDialog(Shell shell, org.eclipse.uml2.uml.Package movedPackage, Profile newProfile) { + super(shell, DIALOG_TITLE, ProfileMigrationPreferenceConstants.PACKAGE_MOVE, newProfile); + this.movedPackage = movedPackage; + this.newProfile = newProfile; + } + + @Override + protected String getDecription() { + return NLS.bind(Messages.MovePackageDialog_description, movedPackage.getName(), newProfile.getName()); + } + +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/MoveProfileDialog.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/MoveProfileDialog.java new file mode 100644 index 00000000000..5c35222d35e --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/MoveProfileDialog.java @@ -0,0 +1,51 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs; + +import org.eclipse.osgi.util.NLS; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Messages; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.preferences.ProfileMigrationPreferenceConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.uml2.uml.Profile; + +/** + * Dialog to ask to user if he want to apply a profile or not + */ +public class MoveProfileDialog extends AbstractApplyNewProfileDialog { + + private static String DIALOG_TITLE = Messages.MoveProfileDialog_title; + + private Profile movedProfile; + + /** + * Constructor. + * + * @param shell + * the active shell + * @param movedProfile + * the moved profile + * @param newProfile + * the new profile to apply + */ + public MoveProfileDialog(Shell shell, Profile movedProfile, Profile newProfile) { + super(shell, DIALOG_TITLE, ProfileMigrationPreferenceConstants.PROFILE_MOVE, newProfile); + this.movedProfile = movedProfile; + } + + @Override + protected String getDecription() { + return NLS.bind(Messages.MoveProfileDialog_description, movedProfile.getName(), newProfile.getName()); + } + +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/MoveStereotypeDialog.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/MoveStereotypeDialog.java new file mode 100644 index 00000000000..be174dc8a72 --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/dialogs/MoveStereotypeDialog.java @@ -0,0 +1,56 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.dialogs; + +import org.eclipse.osgi.util.NLS; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Messages; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.preferences.ProfileMigrationPreferenceConstants; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.uml2.uml.Profile; +import org.eclipse.uml2.uml.Stereotype; + +/** + * Dialog to ask to user if he want to apply a profile or not + */ +public class MoveStereotypeDialog extends AbstractApplyNewProfileDialog { + + private static String DIALOG_TITLE = Messages.MoveStereotypeDialog_title; + + private Stereotype stereotype; + + private Profile newProfile; + + /** + * Constructor. + * + * @param shell + * the active shell + * @param stereotype + * the moved stereotype + * @param newProfile + * the new profile to apply + */ + public MoveStereotypeDialog(Shell shell, Stereotype stereotype, Profile newProfile) { + super(shell, DIALOG_TITLE, ProfileMigrationPreferenceConstants.STEREOTYPE_MOVE, newProfile); + this.stereotype = stereotype; + this.newProfile = newProfile; + } + + @Override + protected String getDecription() { + return NLS.bind(Messages.MoveStereotypeDialog_description, stereotype.getName(), newProfile.getName()); + } + +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/messages.properties b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/messages.properties new file mode 100644 index 00000000000..88eb34f0262 --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/messages.properties @@ -0,0 +1,35 @@ +AbstractProfileMigrationDialog_description=Description +AbstractProfileMigrationDialog_DoNotShowItAgain=Do not show this pop-up again +AbstractProfileMigrationDialog_MigrateAction=Migration Action +AddPropertyToStereotypeDialog_Description=The Property {0} has been added to the Stereotype {1}, but the multiplicity of this Property is [{2}..{3}] so a value is required and there is not default value. +AddPropertyToStereotypeDialog_Title=A Property is added to a Stereotype +ChangeIsAbstractFromStereotypeDialog_Description=The Stereotype {0} has become abstract so applications of this Stereotype will be deleted, you can select one or more sub Stereotypes as replacement. +ChangeIsAbstractFromStereotypeDialog_Title=A Stereotype has become abstract +ChangeIsStaticFeatureDialog_Description=The Property {0} of the Stereotype {1} has become static, you should select a value for every instance of this Property. +ChangeIsStaticFeatureDialog_Title=A Property has become static +ChangeLowerMultiplicityDialog_Description=The lower multiplicity of the Property {0} of the Stereotype {1} has been changed from {2} to {3}. You should add values to match with this constraint. +ChangeLowerMultiplicityDialog_Title=Modified lower multiplicity of Property +ChangeUpperMultiplicityDialog_Description=The upper multiplicity of the Property {0} of the Stereotype {1} has been changed from {2} to {3}. You should remove values to match with this constraint. +ChangeUpperMultiplicityDialog_Title=Modified upper multiplicity of Property +DeleteEnumerationLiteralFromEnumerationDialog_Description=The EnumerationLiteral {0} has been deleted from the Enumeration {1} you can replace it by a new EnumerationLiteral. +DeleteEnumerationLiteralFromEnumerationDialog_Title=An EnumerationLiteral has been deleted from an Enumeration +MovePackageDialog_description=The Package {0} has been moved into the Profile {1} which is not applied in the current model. +MovePackageDialog_title=A Package has been moved +MoveProfileDialog_description=The Profile {0} has been moved in the Profile {1}. +MoveProfileDialog_title=A Profile has been moved +MoveStereotypeDialog_content=Do you want to apply the Profile {0}? +MoveStereotypeDialog_description=The Stereotype {0} has been moved into the Profile {1} which is not applied in the current model. +MoveStereotypeDialog_No=no +MoveStereotypeDialog_title=A Stereotype is moved +MoveStereotypeDialog_Yes=yes +ProfileMigrationPreferenceConstants_AddPropertyToStereotype=A property has been added to a stereotype (when the multiplicity is greater than 1 and there is no default value) +ProfileMigrationPreferenceConstants_ChangeIsStaticFeatureOfProperty=IsStatic feature of Property has been modified +ProfileMigrationPreferenceConstants_ChangeLowerMultiplicityOfProperty=The lower multiplicity of Property has been modified +ProfileMigrationPreferenceConstants_ChangeUpperMultiplicityOfProperty=The upper multiplicity of Property has been modified +ProfileMigrationPreferenceConstants_DeleteEnumLiteralFromEnumeration=An EnumerationLiteral has been deleted from an Enumeration +ProfileMigrationPreferenceConstants_PackageMove=A Package has been moved into an unapplied Profile +ProfileMigrationPreferenceConstants_ProfileMove=A Profile has been moved into an unapplied Profile +ProfileMigrationPreferenceConstants_StereotypeMove=A Stereotype has been moved into an unapplied Profile +ProfileMigrationPreferenceConstants_SuperStereotypeBecomingAbstract=IsAbstract feature of Stereotype has been modified +ProfileMigrationPreferencePage_FileInCached=File names keep in cached +ProfileMigrationPreferencePage_ShowDialogs=Show dialog for these actions diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/preferences/ProfileMigrationInitializer.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/preferences/ProfileMigrationInitializer.java new file mode 100644 index 00000000000..826ad509500 --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/preferences/ProfileMigrationInitializer.java @@ -0,0 +1,54 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.preferences; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Activator; + +/** + * Initialize profile migration tool preferences + */ +public class ProfileMigrationInitializer extends AbstractPreferenceInitializer { + + /** + * Constructor. + * + */ + public ProfileMigrationInitializer() { + super(); + } + + /** + * Set default preference, true for all dialogs + */ + @Override + public void initializeDefaultPreferences() { + IPreferenceStore store = getPreferenceStore(); + for (String constPref : ProfileMigrationPreferenceConstants.mapPrefConstToLabel.keySet()) { + store.setDefault(constPref, true); + } + } + + /** + * Get the preference store + * + * @return the preference store + */ + protected IPreferenceStore getPreferenceStore() { + return Activator.getDefault().getPreferenceStore(); + } + +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/preferences/ProfileMigrationPreferenceConstants.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/preferences/ProfileMigrationPreferenceConstants.java new file mode 100644 index 00000000000..018da30aeab --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/preferences/ProfileMigrationPreferenceConstants.java @@ -0,0 +1,102 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.preferences; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Messages; + +/** + * Definition of preference constants for the profile migration tool + */ +abstract public class ProfileMigrationPreferenceConstants { + + /** + * Map the preference constant and the displayed label + */ + public static final Map<String, String> mapPrefConstToLabel = init(); + + + /** + * @return a map with the preference constant and the displayed label + */ + protected static Map<String, String> init() { + Map<String, String> map = new HashMap<>(); + map.put(ProfileMigrationPreferenceConstants.ADD_PROPERTY_TO_STEREOTYPE, + Messages.ProfileMigrationPreferenceConstants_AddPropertyToStereotype); + map.put(ProfileMigrationPreferenceConstants.SUPER_STEREOTYPE_BECOMING_ABSTRACT, + Messages.ProfileMigrationPreferenceConstants_SuperStereotypeBecomingAbstract); + map.put(ProfileMigrationPreferenceConstants.STEREOTYPE_MOVE, + Messages.ProfileMigrationPreferenceConstants_StereotypeMove); + map.put(ProfileMigrationPreferenceConstants.CHANGE_LOWER_MULTIPLICITY_PROPERTY, + Messages.ProfileMigrationPreferenceConstants_ChangeLowerMultiplicityOfProperty); + map.put(ProfileMigrationPreferenceConstants.CHANGE_UPPER_MULTIPLICITY_PROPERTY, + Messages.ProfileMigrationPreferenceConstants_ChangeUpperMultiplicityOfProperty); + map.put(ProfileMigrationPreferenceConstants.CHANGE_IS_STATIC_FEATURE_PROPERTY, + Messages.ProfileMigrationPreferenceConstants_ChangeIsStaticFeatureOfProperty); + map.put(ProfileMigrationPreferenceConstants.DELETE_ENUM_LITERAL_FROM_ENUMERATION, + Messages.ProfileMigrationPreferenceConstants_DeleteEnumLiteralFromEnumeration); + map.put(ProfileMigrationPreferenceConstants.PACKAGE_MOVE, + Messages.ProfileMigrationPreferenceConstants_PackageMove); + map.put(ProfileMigrationPreferenceConstants.PROFILE_MOVE, + Messages.ProfileMigrationPreferenceConstants_ProfileMove); + return map; + } + + /** + * Preference constant to show AddPropertyToStereotypeDialog + */ + public static final String ADD_PROPERTY_TO_STEREOTYPE = "AddPropertyToStereotype"; //$NON-NLS-1$ + + /** + * Preference constant to show ChangeIsAbstractFromStereotypeDialog + */ + public static final String SUPER_STEREOTYPE_BECOMING_ABSTRACT = "SuperStereotypeBecomingAbstract"; //$NON-NLS-1$ + + /** + * Preference constant to show MoveStereotypeDialog + */ + public static final String STEREOTYPE_MOVE = "StereotypeMove"; //$NON-NLS-1$ + + /** + * Preference constant to show ChangeLowerMultiplicityDialog + */ + public static final String CHANGE_LOWER_MULTIPLICITY_PROPERTY = "ChangeLowerMultiplicityOfProperty"; //$NON-NLS-1$ + + /** + * Preference constant to show ChangUpperMultiplicityDialog + */ + public static final String CHANGE_UPPER_MULTIPLICITY_PROPERTY = "ChangeUpperMultiplicityOfProperty"; //$NON-NLS-1$ + + /** + * Preference constant to show ChangeIsStaticFeatureDialog + */ + public static final String CHANGE_IS_STATIC_FEATURE_PROPERTY = "ChangeIsStaticFeatureOfProperty"; //$NON-NLS-1$ + + /** + * Preference constant to show DeleteEnumerationLiteralFromEnumerationDialog + */ + public static final String DELETE_ENUM_LITERAL_FROM_ENUMERATION = "DeleteEnumLiteralFromEnumeration"; //$NON-NLS-1$ + + /** + * Preference constant to show MovePackageDialog + */ + public static final String PACKAGE_MOVE = "PackageMove"; //$NON-NLS-1$ + + /** + * Preference constant to show MoveProfileDialog + */ + public static final String PROFILE_MOVE = "ProfileMove"; //$NON-NLS-1$ +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/preferences/ProfileMigrationPreferencePage.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/preferences/ProfileMigrationPreferencePage.java new file mode 100644 index 00000000000..e9ee859121a --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/preferences/ProfileMigrationPreferencePage.java @@ -0,0 +1,244 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.preferences; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; + +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.papyrus.infra.widgets.providers.CollectionContentProvider; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Activator; +import org.eclipse.papyrus.toolsmiths.profilemigration.ui.Messages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +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.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +/** + * Define the preference page for configuring the Profile migration tool + * + * ---------------------- + * list of check button to activate or not pop-up + * ---------------------- + * list of cached file with a remove button + * + */ +public class ProfileMigrationPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + + /** ID of delete button. */ + private static final int DELETE_BUTTON_ID = 1; + + /** Icon for delete action button. */ + private static final Image DELETE_ICON = AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.papyrus.infra.widgets", "icons/Delete_12x12.gif").createImage(); //$NON-NLS-1$ //$NON-NLS-2$ + + /** The list of files in cache */ + private static List<String> cachedFiles = new ArrayList<>(); + + /** The list of booleanFieldEditor one for each dialog type */ + private List<BooleanFieldEditor> booleanFieldEditor; + + /** The treeViewer to display cached files */ + private TreeViewer cachedFilesTreeViewer; + + /** The main container */ + private Composite mainContainer; + + /** + * Constructor. + * + */ + public ProfileMigrationPreferencePage() { + booleanFieldEditor = new ArrayList<>(); + } + + @Override + public void init(IWorkbench workbench) { + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + } + + @Override + protected Control createContents(Composite parent) { + mainContainer = parent; + createFieldEditors(); + + Group group = new Group(mainContainer, SWT.SCROLL_PAGE); + group.setLayout(new GridLayout()); + group.setText(Messages.ProfileMigrationPreferencePage_FileInCached); + createTreeActionButtons(group); + createCachedFilesPart(group); + + refreshTreeviewer(); + + initialize(); + checkState(); + + return mainContainer; + } + + @Override + protected void createFieldEditors() { + Group group = new Group(mainContainer, SWT.SCROLL_PAGE); + group.setLayout(new GridLayout()); + group.setText(Messages.ProfileMigrationPreferencePage_ShowDialogs); + for (Entry<String, String> entry : ProfileMigrationPreferenceConstants.mapPrefConstToLabel.entrySet()) { + BooleanFieldEditor editor = new BooleanFieldEditor(entry.getKey(), entry.getValue(), group); + booleanFieldEditor.add(editor); + addField(editor); + editor.setPreferenceStore(Activator.getDefault().getPreferenceStore()); + } + } + + + /** + * Create actions associate to tree viewer. + * + * @param parent + * Composite where action buttons will be added + */ + private void createTreeActionButtons(Composite parent) { + Composite buttonsPanel = new Composite(parent, SWT.NONE); + buttonsPanel.setLayout(new GridLayout()); + buttonsPanel.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, false, 1, 1)); + + createButton(buttonsPanel, DELETE_BUTTON_ID, DELETE_ICON, null); + + } + + /** + * Create cached file list + * + * @param parent + * Composite where the treeViewer will be added + */ + private void createCachedFilesPart(Composite parent) { + // Create viewer + cachedFilesTreeViewer = new TreeViewer(parent, SWT.BORDER); + + // Set standard collection content provider + cachedFilesTreeViewer.setContentProvider(CollectionContentProvider.instance); + cachedFilesTreeViewer.setLabelProvider(new LabelProvider()); + + // Set layout + Tree tree = cachedFilesTreeViewer.getTree(); + tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); + } + + /** + * Method to create a button with an icon and no label. + * + * @param parent + * the composite parent + * @param id + * the id of the new button + * @param icon + * an icon associate to the button (could be null) + * @param label + * a label associate to the button (could be null) + * @return the newly created button + */ + protected Button createButton(Composite parent, int id, Image icon, String label) { + ((GridLayout) parent.getLayout()).numColumns++; + Button button = new Button(parent, SWT.PUSH); + button.setFont(JFaceResources.getDialogFont()); + button.setData(new Integer(id)); + button.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent event) { + buttonPressed(); + } + }); + + if (label != null) { + button.setText(label); + } + if (icon != null) { + button.setImage(icon); + } + setButtonLayoutData(button); + return button; + } + + /** + * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) + * + * @param buttonId + */ + protected void buttonPressed() { + deleteAction(); + } + + /** + * Delete current selection of tree viewer. + */ + private void deleteAction() { + ISelection selection = cachedFilesTreeViewer.getSelection(); + + if (selection instanceof IStructuredSelection) { + Object selectedElement = ((IStructuredSelection) selection).getFirstElement(); + if (selectedElement instanceof String) { + cachedFiles.remove(selectedElement); + } + refreshTreeviewer(); + } + } + + /** + * Refresh content of tree viewer according to selected theme/ + * + * @param currentTheme + * Current theme + */ + private void refreshTreeviewer() { + // Set mirroring list as viewer input + cachedFilesTreeViewer.getTree().setEnabled(true); + cachedFilesTreeViewer.setInput(cachedFiles); + } + + /** + * Add file to the cache + * + * @param fileName + */ + public static void addFile(String fileName) { + cachedFiles.add(fileName); + } + + /** + * Get the cache file list + * + * @return the cache file list + */ + public static List<String> getCachedFiles() { + return cachedFiles; + } + +} diff --git a/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/utils/EStructuralFeatureUtil.java b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/utils/EStructuralFeatureUtil.java new file mode 100644 index 00000000000..99f765d67c8 --- /dev/null +++ b/plugins/toolsmiths/profilemigration/org.eclipse.papyrus.toolsmiths.profilemigration.ui/src/org/eclipse/papyrus/toolsmiths/profilemigration/ui/utils/EStructuralFeatureUtil.java @@ -0,0 +1,99 @@ +/***************************************************************************** + * Copyright (c) 2017 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: + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.toolsmiths.profilemigration.ui.utils; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.papyrus.infra.emf.utils.HistoryUtil; +import org.eclipse.papyrus.infra.properties.ui.providers.FeatureContentProvider; +import org.eclipse.papyrus.infra.ui.emf.providers.EMFGraphicalContentProvider; +import org.eclipse.papyrus.infra.ui.emf.providers.EMFLabelProvider; +import org.eclipse.papyrus.infra.ui.emf.utils.ProviderHelper; +import org.eclipse.papyrus.uml.properties.creation.UMLPropertyEditorFactory; +import org.eclipse.papyrus.uml.properties.widgets.EStructuralFeatureEditor; +import org.eclipse.papyrus.uml.tools.providers.UMLContainerContentProvider; +import org.eclipse.papyrus.uml.tools.providers.UMLContentProvider; +import org.eclipse.papyrus.uml.tools.providers.UMLFilteredLabelProvider; +import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider; +import org.eclipse.uml2.common.util.UML2Util; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; + +/** + * Util method to use EStructuralFeatureEditor + */ +public class EStructuralFeatureUtil { + + + /** + * Change displayed values according to the new element + * + * @param editor + * @param stereotypedElement + * @param property + * @param stereotype + * + */ + public static void setValueToEditor(EStructuralFeatureEditor editor, Element stereotypedElement, Property property, Stereotype stereotype) { + EObject stereotypeApplication = stereotypedElement.getStereotypeApplication(stereotype); + EStructuralFeature structuralFeature = getFeature(stereotypeApplication, property); + editor.setProviders(new UMLContentProvider(stereotypeApplication, structuralFeature, stereotype), new UMLLabelProvider()); + if (structuralFeature instanceof EReference) { + editor.setValueFactory(getUMLPropertyEditorFactory(stereotypeApplication, (EReference) structuralFeature)); + } + + editor.setFeatureToEdit(property.getName(), structuralFeature, stereotypeApplication); + + } + + /** + * Get the structural feature according to the stereotype application and the property + * + * @param stereotypeApplication + * @return + */ + private static EStructuralFeature getFeature(EObject stereotypeApplication, Property property) { + return stereotypeApplication.eClass().getEStructuralFeature(UML2Util.getValidJavaIdentifier(property.getName())); + } + + /** + * Get an UMLPropertyEditorFactory + * + * @param stereotypeApplication + * @param reference + * @return + */ + private static UMLPropertyEditorFactory getUMLPropertyEditorFactory(EObject stereotypeApplication, EReference reference) { + UMLPropertyEditorFactory factory = new UMLPropertyEditorFactory(reference); + EClass type = reference.getEReferenceType(); + + factory.setContainerLabelProvider(new UMLFilteredLabelProvider()); + factory.setReferenceLabelProvider(new EMFLabelProvider()); + + ITreeContentProvider contentProvider = new UMLContainerContentProvider(stereotypeApplication, reference); + + EMFGraphicalContentProvider provider = ProviderHelper.encapsulateProvider(contentProvider, stereotypeApplication.eResource().getResourceSet(), HistoryUtil.getHistoryID(stereotypeApplication, reference, "container")); //$NON-NLS-1$ + + factory.setContainerContentProvider(provider); + factory.setReferenceContentProvider(new FeatureContentProvider(type)); + + return factory; + } + +} |