From b82e6e300f10da43dfa6a2c547ff4179c97fbc52 Mon Sep 17 00:00:00 2001 From: Nicolas FAUVERGUE Date: Mon, 30 May 2016 12:55:00 +0200 Subject: bug 492873 - [Table] The Create Table Configuration menu appears everywhere bug 493756 - [Table] Edit table configuration calls same wizard as "create..." bug 493756 - [Table] Papyrus must provide the Table creation Wizard in the New Dialog Change-Id: Ie708c6a515ffd0498b45cd961d2e3c075e938b0b Signed-off-by: Nicolas FAUVERGUE Signed-off-by: Vincent LORENZO --- .../META-INF/MANIFEST.MF | 4 +- .../plugin.properties | 2 + .../plugin.xml | 51 +- .../nattableconfiguration/Activator.java | 44 +- .../CreateNattableConfigurationWizard.java | 329 ----------- .../ediiton/FeatureFillingConfigurationDialog.java | 244 -------- .../ediiton/PasteEObjectConfigurationDialog.java | 302 ---------- .../ediiton/TreeFillingConfigurationDialog.java | 646 --------------------- .../edition/FeatureFillingConfigurationDialog.java | 244 ++++++++ .../edition/PasteEObjectConfigurationDialog.java | 302 ++++++++++ .../edition/TreeFillingConfigurationDialog.java | 646 +++++++++++++++++++++ .../CreateTableConfigurationWizardHandler.java | 131 ----- ...ditExistingTableConfigurationWizardHandler.java | 60 ++ ...tableConfigurationFieldsNattableWizardPage.java | 5 +- .../NattableConfigurationFileCreationPage.java | 119 ++++ .../NattableConfigurationProjectCreationPage.java | 150 ----- .../pages/RowConfigurationWizardPage.java | 6 +- .../pages/SlaveConfigurationWizardPage.java | 8 +- .../utils/NattableConfigurationConstants.java | 2 +- .../CreateAndEditTableConfigurationWizard.java | 181 ++++++ .../CreateNattableConfigurationProjectWizard.java | 223 +++++++ .../wizards/EditTableConfigurationWizard.java | 231 ++++++++ .../utils/NattableConfigurationConstants.java | 26 + 23 files changed, 2079 insertions(+), 1877 deletions(-) delete mode 100644 plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/CreateNattableConfigurationWizard.java delete mode 100644 plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/ediiton/FeatureFillingConfigurationDialog.java delete mode 100644 plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/ediiton/PasteEObjectConfigurationDialog.java delete mode 100644 plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/ediiton/TreeFillingConfigurationDialog.java create mode 100644 plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/edition/FeatureFillingConfigurationDialog.java create mode 100644 plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/edition/PasteEObjectConfigurationDialog.java create mode 100644 plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/edition/TreeFillingConfigurationDialog.java delete mode 100644 plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/handlers/CreateTableConfigurationWizardHandler.java create mode 100644 plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/handlers/EditExistingTableConfigurationWizardHandler.java create mode 100644 plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/NattableConfigurationFileCreationPage.java delete mode 100644 plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/NattableConfigurationProjectCreationPage.java create mode 100644 plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/wizards/CreateAndEditTableConfigurationWizard.java create mode 100644 plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/wizards/CreateNattableConfigurationProjectWizard.java create mode 100644 plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/wizards/EditTableConfigurationWizard.java create mode 100644 plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NattableConfigurationConstants.java (limited to 'plugins') diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/META-INF/MANIFEST.MF b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/META-INF/MANIFEST.MF index a83429a55d6..fb17f681eec 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/META-INF/MANIFEST.MF +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/META-INF/MANIFEST.MF @@ -31,12 +31,12 @@ Require-Bundle: org.eclipse.ui, Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.papyrus.customization.nattableconfiguration, - org.eclipse.papyrus.customization.nattableconfiguration.ediiton, + org.eclipse.papyrus.customization.nattableconfiguration.edition, org.eclipse.papyrus.customization.nattableconfiguration.handlers, org.eclipse.papyrus.customization.nattableconfiguration.helper, org.eclipse.papyrus.customization.nattableconfiguration.messages, org.eclipse.papyrus.customization.nattableconfiguration.pages, org.eclipse.papyrus.customization.nattableconfiguration.utils Bundle-Vendor: %Bundle-Vendor -Bundle-Description: %pluginDescription +Bundle-Description: %Bundle-Description Bundle-Localization: plugin diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/plugin.properties b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/plugin.properties index cc6699a143b..e1812e03f29 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/plugin.properties +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/plugin.properties @@ -1,3 +1,5 @@ #Properties file for org.eclipse.papyrus.uml.nattable Bundle-Vendor = Eclipse Modeling Project Bundle-Name = Customization of Nattable Configuration + +Bundle-Description = This plugin provides the Wizard used to create a new project with a Papyrus Table Configuration, to create a new Papyrus Table Configuration inside an existing project and the handler to edit an exiting table configuration \ No newline at end of file diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/plugin.xml b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/plugin.xml index ed60a1a92d0..baaf57e1f28 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/plugin.xml +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/plugin.xml @@ -7,16 +7,7 @@ allPopups="true" locationURI="popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu"> - - - - - - - - + defaultHandler="org.eclipse.papyrus.customization.nattableconfiguration.handlers.EditExistingTableConfigurationWizardHandler" + id="org.eclipse.papyrus.infra.nattable.edit.configuration.wizard" + name="Edit Table Configuration Wizard"> + + + + + + diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/Activator.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/Activator.java index fcc41eb71b9..347b9c03825 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/Activator.java +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/Activator.java @@ -15,6 +15,7 @@ package org.eclipse.papyrus.customization.nattableconfiguration; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.papyrus.infra.core.log.LogHelper; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -33,6 +34,8 @@ public class Activator extends AbstractUIPlugin { */ private static Activator plugin; + + public static LogHelper log; /** * The constructor */ @@ -48,6 +51,7 @@ public class Activator extends AbstractUIPlugin { public void start(final BundleContext context) throws Exception { super.start(context); plugin = this; + log = new LogHelper(this); } /** @@ -70,45 +74,5 @@ public class Activator extends AbstractUIPlugin { return plugin; } - /** - * Logs a warning message in the plugin log - * - * @param message - * the message to log - */ - public static void logWarning(final String message) { - getDefault().getLog().log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, message)); - } - - /** - * Logs an error message in the plugin log - * - * @param message - * the message to log - */ - public static void logError(final String message) { - getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, message)); - } - - /** - * Logs an information message in the plugin log - * - * @param message - * the message to log - */ - public static void logInfo(final String message) { - getDefault().getLog().log(new Status(IStatus.INFO, Activator.PLUGIN_ID, message)); - } - - /** - * Logs an error message in the plugin log - * - * @param exception - * the exception to log - */ - public static void logException(final Exception exception) { - getDefault().getLog().log( - new Status(IStatus.ERROR, Activator.PLUGIN_ID, exception.getLocalizedMessage(), exception)); - } } diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/CreateNattableConfigurationWizard.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/CreateNattableConfigurationWizard.java deleted file mode 100644 index 333cf33e55d..00000000000 --- a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/CreateNattableConfigurationWizard.java +++ /dev/null @@ -1,329 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2016 CEA LIST and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation - * - *****************************************************************************/ - -package org.eclipse.papyrus.customization.nattableconfiguration; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.jface.dialogs.DialogSettings; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.papyrus.customization.nattableconfiguration.helper.TableConfigurationHelper; -import org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages; -import org.eclipse.papyrus.customization.nattableconfiguration.pages.ColumnConfigurationWizardPage; -import org.eclipse.papyrus.customization.nattableconfiguration.pages.EditGenericNattableConfigurationFieldsNattableWizardPage; -import org.eclipse.papyrus.customization.nattableconfiguration.pages.NattableConfigurationProjectCreationPage; -import org.eclipse.papyrus.customization.nattableconfiguration.pages.RowConfigurationWizardPage; -import org.eclipse.papyrus.customization.nattableconfiguration.pages.SlaveConfigurationWizardPage; -import org.eclipse.papyrus.customization.nattableconfiguration.utils.NattableConfigurationConstants; -import org.eclipse.papyrus.infra.core.services.ServiceException; -import org.eclipse.papyrus.infra.core.services.ServicesRegistry; -import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceSet; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.TableConfiguration; -import org.eclipse.papyrus.infra.nattable.wizard.AbstractTableWizard; -import org.eclipse.pde.internal.ui.wizards.IProjectProvider; -import org.eclipse.pde.internal.ui.wizards.plugin.NewProjectCreationOperation; -import org.eclipse.pde.internal.ui.wizards.plugin.PluginContentPage; -import org.eclipse.pde.internal.ui.wizards.plugin.PluginFieldData; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.PlatformUI; - -/** - * The wizard to manage the nattable configuration. - */ -public class CreateNattableConfigurationWizard extends AbstractTableWizard { - - /** - * The dot string. - */ - private static final String DOT = "."; //$NON-NLS-1$ - - /** - * The generate plugin activator setting. - */ - private static final String GENERATE_PlUGIN_ACTIVATOR = "generatePluginActivator"; //$NON-NLS-1$ - - /** - * The ui plugin setting. - */ - private static final String UI_PLUGIN = "uiPlugin"; //$NON-NLS-1$ - - /** - * The edited table configuration - */ - private final TableConfiguration configuration; - - /** - * The initial resource selected. - */ - private Resource initialResource; - - /** - * the edited Table Configuration Helper; - */ - private TableConfigurationHelper helper; - - /** - * Boolean to determinate if this is a project creation or just an edition. - */ - private boolean isProjectCreation = false; - - /** - * The page for the project creation. - */ - private NattableConfigurationProjectCreationPage nattableConfigurationProjectCreationPage; - - /** - * The project provider. - */ - private IProjectProvider projectProvider; - - /** - * The content page for the project creation. - */ - protected PluginContentPage contentPage; - - /** - * The fields data to manage the project creation - */ - private PluginFieldData pluginData; - - /** - * Constructor. - * - * @param configuration - * The edited table configuration. - * @param initialResource - * The initial nattable configuration resource. - */ - public CreateNattableConfigurationWizard(final TableConfiguration configuration, final Resource initialResource) { - this.configuration = configuration; - this.helper = new TableConfigurationHelper(this.configuration); - final ImageDescriptor desc = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImageDescriptor(Activator.PLUGIN_ID, NattableConfigurationConstants.ICON_WIZBAN_PATH); - setDefaultPageImageDescriptor(desc); - setWindowTitle(Messages.CreateNattableConfigurationWizard_WizardTitke); - setForcePreviousAndNextButtons(true); - - this.initialResource = initialResource; - - isProjectCreation = null == this.initialResource; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.jface.wizard.Wizard#addPages() - */ - @Override - public void addPages() { - if (isProjectCreation) { - - pluginData = new PluginFieldData(); - - nattableConfigurationProjectCreationPage = new NattableConfigurationProjectCreationPage(pluginData, new StructuredSelection()); - addPage(nattableConfigurationProjectCreationPage); - - projectProvider = new IProjectProvider() { - @Override - public String getProjectName() { - return nattableConfigurationProjectCreationPage.getProjectName(); - } - - @Override - public IProject getProject() { - return nattableConfigurationProjectCreationPage.getProjectHandle(); - } - - @Override - public IPath getLocationPath() { - return nattableConfigurationProjectCreationPage.getLocationPath(); - } - }; - - contentPage = new PluginContentPage("page2", projectProvider, nattableConfigurationProjectCreationPage, pluginData); //$NON-NLS-1$ - - addPage(contentPage); - } - addPage(new EditGenericNattableConfigurationFieldsNattableWizardPage(this.helper)); - addPage(new RowConfigurationWizardPage(this.helper)); - addPage(new ColumnConfigurationWizardPage(this.helper)); - addPage(new SlaveConfigurationWizardPage(this.helper)); - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.jface.wizard.Wizard#getDialogSettings() - */ - @Override - public IDialogSettings getDialogSettings() { - DialogSettings dialogSettings = new DialogSettings(""); //$NON-NLS-1$ - dialogSettings.put(GENERATE_PlUGIN_ACTIVATOR, true); - dialogSettings.put(UI_PLUGIN, false); - return dialogSettings; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.jface.wizard.Wizard#performFinish() - */ - @Override - public boolean performFinish() { - boolean result = false; - - IProject createdProject = null; - - if (isProjectCreation) { - try { - - // Create the project - getContainer().run(false, true, new NewProjectCreationOperation(pluginData, projectProvider, null)); - - createdProject = projectProvider.getProject(); - - // Set the project into the working sets - final IWorkingSet[] workingSets = nattableConfigurationProjectCreationPage.getSelectedWorkingSets(); - if (0 < workingSets.length) { - PlatformUI.getWorkbench().getWorkingSetManager().addToWorkingSets(createdProject, workingSets); - } - - // Copy the about file - copyAboutFile(createdProject); - - StringBuilder nattableConfigurationFileName = new StringBuilder(nattableConfigurationProjectCreationPage.getNattableConfigurationFileName()); - - // Check if the file has the nattable configuration extension file, else add it - if (!nattableConfigurationFileName.toString().contains(DOT) - || !NattableConfigurationConstants.NATTABLE_CONFIGURATION_EXTENSION_FILE.equals(nattableConfigurationFileName.toString().substring(nattableConfigurationFileName.lastIndexOf(DOT) + 1))) { - nattableConfigurationFileName.append(DOT); - nattableConfigurationFileName.append(NattableConfigurationConstants.NATTABLE_CONFIGURATION_EXTENSION_FILE); - } - - final ResourceSet set = new ResourceSetImpl(); - final StringBuilder nattableConfFileURI = new StringBuilder(); - nattableConfFileURI.append(createdProject.getLocation()); - nattableConfFileURI.append(NattableConfigurationConstants.CONFIG_FOLDER); - nattableConfFileURI.append(nattableConfigurationFileName); - initialResource = set.createResource(URI.createFileURI(nattableConfFileURI.toString())); - initialResource.getContents().add(configuration); - - result = true; - } catch (final InvocationTargetException e) { - Activator.logException(e); - } catch (final InterruptedException e) { - Activator.logException(e); - } - } else if (null != initialResource) { - ServicesRegistry registry; - try { - registry = ServiceUtilsForResourceSet.getInstance().getServiceRegistry(initialResource.getResourceSet()); - final TransactionalEditingDomain editingDomain = registry.getService(TransactionalEditingDomain.class); - - final CommandStack commandStack = editingDomain.getCommandStack(); - commandStack.execute(new RecordingCommand(editingDomain) { - - @Override - protected void doExecute() { - // Save DiagramDialog at proper position - if (null != initialResource) { - initialResource.getContents().clear(); - initialResource.getContents().add(configuration); - } - } - }); - - result = true; - } catch (final ServiceException e) { - Activator.logException(e); - } - } - - final Map saveOptions = new HashMap(); - saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER); - saveOptions.put(Resource.OPTION_LINE_DELIMITER, Resource.OPTION_LINE_DELIMITER_UNSPECIFIED); - - try { - initialResource.save(saveOptions); - } catch (final IOException e) { - Activator.logException(e); - result = false; - } - - return result; - } - - /** - * This allows to copy the about file in the created project. - * - * @param createdProject - * The created project. - */ - protected void copyAboutFile(final IProject createdProject) { - InputStream inputStream = null; - OutputStream outputStream = null; - try { - final URL url = Activator.getDefault().getBundle().getResource(NattableConfigurationConstants.ABOUT_FILE_NAME); - inputStream = url.openStream(); - - final File newAboutFile = new File(createdProject.getLocation().toOSString() + File.separator + NattableConfigurationConstants.ABOUT_FILE_NAME); - newAboutFile.createNewFile(); - - outputStream = new FileOutputStream(newAboutFile); - - int read = 0; - byte[] bytes = new byte[1024]; - - while ((read = inputStream.read(bytes)) != -1) { - outputStream.write(bytes, 0, read); - } - } catch (final IOException e) { - Activator.logException(e); - } finally { - if (null != inputStream) { - try { - inputStream.close(); - } catch (final IOException e) { - Activator.logException(e); - } - } - if (null != outputStream) { - try { - // outputStream.flush(); - outputStream.close(); - } catch (final IOException e) { - Activator.logException(e); - } - - } - } - } -} diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/ediiton/FeatureFillingConfigurationDialog.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/ediiton/FeatureFillingConfigurationDialog.java deleted file mode 100644 index 7cce581b193..00000000000 --- a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/ediiton/FeatureFillingConfigurationDialog.java +++ /dev/null @@ -1,244 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2016 CEA LIST and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation - * - *****************************************************************************/ - -package org.eclipse.papyrus.customization.nattableconfiguration.ediiton; - -import java.util.Collections; - -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.EcorePackage; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages; -import org.eclipse.papyrus.customization.nattableconfiguration.utils.NattableConfigurationConstants; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.EStructuralFeatureValueFillingConfiguration; -import org.eclipse.papyrus.infra.nattable.utils.StringComparator; -import org.eclipse.papyrus.infra.widgets.Activator; -import org.eclipse.papyrus.infra.widgets.editors.ITreeSelectorDialog; -import org.eclipse.papyrus.infra.widgets.editors.TreeSelectorDialog; -import org.eclipse.papyrus.infra.widgets.providers.FlattenableRestrictedFilteredContentProvider; -import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider; -import org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector; -import org.eclipse.papyrus.uml.nattable.provider.UMLFeatureRestrictedContentProvider; -import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -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.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.dialogs.SelectionDialog; - -/** - * The dialog which allow to edit the feature filling configuration features. - */ -public class FeatureFillingConfigurationDialog extends SelectionDialog { - - /** - * A copy of initial feature filling configuration to modify with this dialog. - */ - protected final EStructuralFeatureValueFillingConfiguration modifiedFeatureFillingConf; - - /** - * The label provider for the UML elements. - */ - protected final ILabelProvider labelProvider = new UMLLabelProvider(); - - /** - * The CLabel composite for the listen feature. - */ - protected CLabel listenFeatureText; - - /** - * The browse button which allow to edit the listen feature. - */ - protected Button browseValuesButton; - - /** - * The delete button which allow to unset the listen feature value. - */ - protected Button deleteValuesButton; - - /** - * Constructor. - * - * @param parentShell - * The parent shell of the dialog. - * @param featureFillingConf - * The initial feature filling configuration to edit. - */ - public FeatureFillingConfigurationDialog(final Shell parentShell, final EStructuralFeatureValueFillingConfiguration featureFillingConf) { - super(parentShell); - this.modifiedFeatureFillingConf = EcoreUtil.copy(featureFillingConf); - setTitle(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.FeatureFillingConfigurationDialog_featureFillingConfigurationDialogName); - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.jface.dialogs.Dialog#create() - */ - @Override - public void create() { - super.create(); - getShell().setImage(Activator.getDefault().getImage(NattableConfigurationConstants.PAPYRUS_ICON_PATH)); - - final Composite parent = new Composite((Composite) getDialogArea(), SWT.NONE); - parent.setLayout(new GridLayout(4, false)); - parent.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); - getShell().setSize(600, 400); - - // Create the fields - createFields(parent); - - getShell().pack(); - Point size = getShell().getSize(); - int minWidth = 600; - if (size.x < minWidth) { - size.x = minWidth; - } - getShell().setSize(size); - } - - /** - * This allows to create the fields to edit the feature filling configuration. - * - * @param parent - * The parent composite. - */ - protected void createFields(final Composite parent) { - // Create the listen feature labels and dialog - final Label listenFeatureLabel = new Label(parent, SWT.NONE); - listenFeatureLabel.setText(Messages.FeatureFillingConfigurationDialog_listenFeature); - listenFeatureLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); - listenFeatureText = new CLabel(parent, SWT.BORDER); - listenFeatureText.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); - browseValuesButton = new Button(parent, SWT.PUSH); - browseValuesButton.setImage(Activator.getDefault().getImage(NattableConfigurationConstants.BROWSE_ICON_PATH)); - browseValuesButton.setToolTipText(org.eclipse.papyrus.infra.widgets.messages.Messages.ReferenceDialog_EditValue); - browseValuesButton.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(final SelectionEvent e) { - browseAction(modifiedFeatureFillingConf.getListenFeature()); - } - }); - - deleteValuesButton = new Button(parent, SWT.PUSH); - deleteValuesButton.setImage(Activator.getDefault().getImage(NattableConfigurationConstants.DELETE_ICON_PATH)); - deleteValuesButton.setToolTipText(org.eclipse.papyrus.infra.widgets.messages.Messages.ReferenceDialog_UnsetValue); - deleteValuesButton.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(final SelectionEvent e) { - setListenFeature(null); - } - }); - - setListenFeature(modifiedFeatureFillingConf.getListenFeature()); - } - - /** - * The action executed when the "browse" button is selected Choose a value - * from a selection of already created objects. - * - * @param value - * The initial value of the listen feature. - */ - protected void browseAction(final Object value) { - final ITreeSelectorDialog dialog = new TreeSelectorDialog(getShell()) { - @Override - protected void initViewerAndProvider() { - super.initViewerAndProvider(); - // Set a comparator to sort the tree viewer - getViewer().setComparator(new ViewerComparator(new StringComparator()));// should always be string element - } - }; - dialog.setTitle(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.FeatureFillingConfigurationDialog_listenFeatureDialogName); - - final UMLFeatureRestrictedContentProvider contentProvider = new UMLFeatureRestrictedContentProvider(null, false); - final ReferenceSelector selector = new ReferenceSelector(false) { - - @Override - public void createControls(Composite parent) { - super.createControls(parent); - this.treeViewer.setComparator(new ViewerComparator(new StringComparator()));// should always be string element - } - }; - - selector.setLabelProvider(labelProvider); - selector.setContentProvider(contentProvider); - final ITreeContentProvider treeContentProvider = new FlattenableRestrictedFilteredContentProvider((IRestrictedContentProvider) contentProvider, selector) { - - @Override - public boolean isValidValue(final Object element) { - // EMF dependency, must not be done here, it should be better with a new content provider service - return element instanceof EReference && ((EReference) element).isMany() && element != EcorePackage.eINSTANCE.getEModelElement_EAnnotations(); - } - }; - - dialog.setContentProvider(treeContentProvider); - dialog.setLabelProvider(labelProvider); - if (null != value) { - dialog.setInitialElementSelections(Collections.singletonList(value)); - } - int result = dialog.open(); - if (Window.OK == result) { - Object[] newValue = dialog.getResult(); - if (null == newValue) { - return; - } - - if (0 == newValue.length) { - setListenFeature(null); - } else { - setListenFeature((EStructuralFeature) newValue[0]); - } - } - } - - /** - * This allows to set the listen feature and refresh the button corresponding to the listen feature value. - * - * @param structuralFeature - * The structural feature to set. - */ - protected void setListenFeature(final EStructuralFeature structuralFeature) { - if (null == modifiedFeatureFillingConf.getListenFeature() || !structuralFeature.equals(modifiedFeatureFillingConf.getListenFeature())) { - modifiedFeatureFillingConf.setListenFeature(structuralFeature); - } - listenFeatureText.setImage(labelProvider.getImage(modifiedFeatureFillingConf.getListenFeature())); - listenFeatureText.setText(labelProvider.getText(modifiedFeatureFillingConf.getListenFeature())); - - deleteValuesButton.setEnabled(null != structuralFeature); - } - - /** - * Returns the modified feature filling configuration. - * - * @return The modified feature filling configuration. - */ - public EStructuralFeatureValueFillingConfiguration getModifiedFeatureFillingConfiguration() { - return modifiedFeatureFillingConf; - } - -} diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/ediiton/PasteEObjectConfigurationDialog.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/ediiton/PasteEObjectConfigurationDialog.java deleted file mode 100644 index 5cda8eeacc8..00000000000 --- a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/ediiton/PasteEObjectConfigurationDialog.java +++ /dev/null @@ -1,302 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2016 CEA LIST and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation - * - *****************************************************************************/ - -package org.eclipse.papyrus.customization.nattableconfiguration.ediiton; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.EcorePackage; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.gmf.runtime.emf.type.core.IElementType; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.customization.nattableconfiguration.utils.NattableConfigurationConstants; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.PasteEObjectConfiguration; -import org.eclipse.papyrus.infra.nattable.utils.StringComparator; -import org.eclipse.papyrus.infra.services.edit.utils.ElementTypeUtils; -import org.eclipse.papyrus.infra.widgets.Activator; -import org.eclipse.papyrus.infra.widgets.editors.ITreeSelectorDialog; -import org.eclipse.papyrus.infra.widgets.editors.TreeSelectorDialog; -import org.eclipse.papyrus.infra.widgets.providers.FlattenableRestrictedFilteredContentProvider; -import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider; -import org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector; -import org.eclipse.papyrus.uml.nattable.provider.UMLFeatureRestrictedContentProvider; -import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.dialogs.SelectionDialog; - -/** - * The dialog which allow to edit the paste configuration features. - */ -public class PasteEObjectConfigurationDialog extends SelectionDialog { - - /** - * A copy of initial paste configuration to modify with this dialog. - */ - protected final PasteEObjectConfiguration modifiedPasteConfiguration; - - /** - * The label provider for the UML elements. - */ - protected final ILabelProvider labelProvider = new UMLLabelProvider(); - - /** - * The CLabel composite for the containment feature. - */ - protected CLabel containmentFeatureText; - - /** - * The browse button which allow to edit the containment feature. - */ - protected Button browseValuesButton; - - /** - * The delete button which allow to unset the containment feature value. - */ - protected Button deleteValuesButton; - - /** - * Constructor. - * - * @param parentShell - * The parent shell of the dialog. - * @param pasteConfiguration - * The initial paste configuration to edit. - */ - public PasteEObjectConfigurationDialog(final Shell parentShell, final PasteEObjectConfiguration pasteConfiguration) { - super(parentShell); - this.modifiedPasteConfiguration = EcoreUtil.copy(pasteConfiguration); - setTitle(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.PasteEObjectConfigurationDialog_pasteEObjectConfigurationDialogName); - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.jface.dialogs.Dialog#create() - */ - @Override - public void create() { - super.create(); - getShell().setImage(Activator.getDefault().getImage(NattableConfigurationConstants.PAPYRUS_ICON_PATH)); - - final Composite parent = new Composite((Composite) getDialogArea(), SWT.NONE); - parent.setLayout(new GridLayout(4, false)); - parent.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); - getShell().setSize(600, 400); - - // Create the fields - createFields(parent); - - getShell().pack(); - Point size = getShell().getSize(); - int minWidth = 600; - if (size.x < minWidth) { - size.x = minWidth; - } - getShell().setSize(size); - } - - /** - * This allows to create the fields to edit the paste configuration. - * - * @param parent - * The parent composite. - */ - protected void createFields(final Composite parent) { - // Create the detached mode checkbox - final Label detachedModeLabel = new Label(parent, SWT.NONE); - detachedModeLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.PasteEObjectConfigurationDialog_detachedModeLabel); - detachedModeLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); - final Button detachedModeButton = new Button(parent, SWT.CHECK); - detachedModeButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1)); - detachedModeButton.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(final SelectionEvent e) { - modifiedPasteConfiguration.setDetachedMode(detachedModeButton.getSelection()); - } - }); - detachedModeButton.setSelection(modifiedPasteConfiguration.isDetachedMode()); - - // Create the pasted element id combo box - final Label pastedElementIdLabel = new Label(parent, SWT.NONE); - pastedElementIdLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.PasteEObjectConfigurationDialog_pastedElementIdLabel); - pastedElementIdLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); - final Combo pastedElementIdCombo = new Combo(parent, SWT.READ_ONLY); - pastedElementIdCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1)); - pastedElementIdCombo.addModifyListener(new ModifyListener() { - - @Override - public void modifyText(ModifyEvent e) { - modifiedPasteConfiguration.setPastedElementId(pastedElementIdCombo.getText()); - } - }); - - final Collection possibleValues = ElementTypeUtils.getAllExistingElementTypes(); - final List possibleValuesAsString = new ArrayList(possibleValues.size()); - - int indexToSelect = -1; - int index = 0; - - for (final IElementType elementType : possibleValues) { - possibleValuesAsString.add(elementType.getDisplayName()); - if (elementType.getDisplayName().equals(modifiedPasteConfiguration.getPastedElementId())) { - indexToSelect = index; - } - index++; - } - - pastedElementIdCombo.setItems((String[]) possibleValuesAsString.toArray(new String[possibleValuesAsString.size()])); - if (-1 != indexToSelect) { - pastedElementIdCombo.select(indexToSelect); - } - - // Create the containment feature labels and dialog - final Label containmentFeatureLabel = new Label(parent, SWT.NONE); - containmentFeatureLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.PasteEObjectConfigurationDialog_containmentFeatureLabel); - containmentFeatureLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); - containmentFeatureText = new CLabel(parent, SWT.BORDER); - containmentFeatureText.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); - browseValuesButton = new Button(parent, SWT.PUSH); - browseValuesButton.setImage(Activator.getDefault().getImage(NattableConfigurationConstants.BROWSE_ICON_PATH)); - browseValuesButton.setToolTipText(org.eclipse.papyrus.infra.widgets.messages.Messages.ReferenceDialog_EditValue); - browseValuesButton.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(final SelectionEvent e) { - browseAction(modifiedPasteConfiguration.getPasteElementContainementFeature()); - } - }); - - deleteValuesButton = new Button(parent, SWT.PUSH); - deleteValuesButton.setImage(Activator.getDefault().getImage(NattableConfigurationConstants.DELETE_ICON_PATH)); - deleteValuesButton.setToolTipText(org.eclipse.papyrus.infra.widgets.messages.Messages.ReferenceDialog_UnsetValue); - deleteValuesButton.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(final SelectionEvent e) { - setPasteElementContainementFeature(null); - } - }); - - setPasteElementContainementFeature(modifiedPasteConfiguration.getPasteElementContainementFeature()); - - // TODO : Post actions - } - - /** - * The action executed when the "browse" button is selected Choose a value - * from a selection of already created objects. - * - * @param value - * The initial value of the containment feature. - */ - protected void browseAction(final Object value) { - ITreeSelectorDialog dialog = new TreeSelectorDialog(getShell()) { - @Override - protected void initViewerAndProvider() { - super.initViewerAndProvider(); - // Set a comparator to sort the tree viewer - getViewer().setComparator(new ViewerComparator(new StringComparator()));// should always be string element - } - }; - dialog.setTitle(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.PasteEObjectConfigurationDialog_containmentFeatureDialogName); - - final UMLFeatureRestrictedContentProvider contentProvider = new UMLFeatureRestrictedContentProvider(null, false); - final ReferenceSelector selector = new ReferenceSelector(false) { - - @Override - public void createControls(final Composite parent) { - super.createControls(parent); - this.treeViewer.setComparator(new ViewerComparator(new StringComparator()));// should always be string element - } - }; - - selector.setLabelProvider(labelProvider); - selector.setContentProvider(contentProvider); - final ITreeContentProvider treeContentProvider = new FlattenableRestrictedFilteredContentProvider((IRestrictedContentProvider) contentProvider, selector) { - - @Override - public boolean isValidValue(final Object element) { - // EMF dependency, must not be done here, it should be better with a new content provider service - return element instanceof EReference && ((EReference) element).isMany() && element != EcorePackage.eINSTANCE.getEModelElement_EAnnotations(); - } - }; - - dialog.setContentProvider(treeContentProvider); - dialog.setLabelProvider(labelProvider); - if (null != value) { - dialog.setInitialElementSelections(Collections.singletonList(value)); - } - int result = dialog.open(); - if (Window.OK == result) { - Object[] newValue = dialog.getResult(); - if (null == newValue) { - return; - } - - if (0 == newValue.length) { - setPasteElementContainementFeature(null); - } else { - Object selectedValue = newValue[0]; - setPasteElementContainementFeature((EStructuralFeature) selectedValue); - } - } - } - - /** - * This allows to set the containment feature and refresh the button corresponding to the containment feature value. - * - * @param structuralFeature - * The structural feature to set. - */ - protected void setPasteElementContainementFeature(final EStructuralFeature structuralFeature) { - if (null == modifiedPasteConfiguration.getPasteElementContainementFeature() || !structuralFeature.equals(modifiedPasteConfiguration.getPasteElementContainementFeature())) { - modifiedPasteConfiguration.setPasteElementContainementFeature(structuralFeature); - } - containmentFeatureText.setImage(labelProvider.getImage(modifiedPasteConfiguration.getPasteElementContainementFeature())); - containmentFeatureText.setText(labelProvider.getText(modifiedPasteConfiguration.getPasteElementContainementFeature())); - - deleteValuesButton.setEnabled(null != structuralFeature); - } - - /** - * Returns the modified paste configuration. - * - * @return The modified paste configuration. - */ - public PasteEObjectConfiguration getModifiedPasteEObjectConfiguration() { - return modifiedPasteConfiguration; - } - -} diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/ediiton/TreeFillingConfigurationDialog.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/ediiton/TreeFillingConfigurationDialog.java deleted file mode 100644 index d7cc9139848..00000000000 --- a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/ediiton/TreeFillingConfigurationDialog.java +++ /dev/null @@ -1,646 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2016 CEA LIST and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation - * - *****************************************************************************/ - -package org.eclipse.papyrus.customization.nattableconfiguration.ediiton; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EOperation; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.EcorePackage; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages; -import org.eclipse.papyrus.customization.nattableconfiguration.utils.NameSimplifier; -import org.eclipse.papyrus.customization.nattableconfiguration.utils.NattableConfigurationConstants; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EObjectAxis; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EOperationAxis; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EStructuralFeatureAxis; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.FeatureIdAxis; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.NattableaxisFactory; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.PasteEObjectConfiguration; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TreeFillingConfiguration; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattablelabelprovider.ILabelProviderConfiguration; -import org.eclipse.papyrus.infra.nattable.utils.StringComparator; -import org.eclipse.papyrus.infra.widgets.Activator; -import org.eclipse.papyrus.infra.widgets.editors.ITreeSelectorDialog; -import org.eclipse.papyrus.infra.widgets.editors.TreeSelectorDialog; -import org.eclipse.papyrus.infra.widgets.providers.FlattenableRestrictedFilteredContentProvider; -import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider; -import org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector; -import org.eclipse.papyrus.uml.nattable.provider.UMLFeatureRestrictedContentProvider; -import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.custom.StackLayout; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.dialogs.SelectionDialog; - -/** - * The dialog which allow to edit the tree filling configuration features. - */ -public class TreeFillingConfigurationDialog extends SelectionDialog { - - /** - * The list of possible axis creation. - */ - protected final static List possibleAxisCreation = new ArrayList(); - - static { - possibleAxisCreation.add("EObjectAxis"); //$NON-NLS-1$ - possibleAxisCreation.add("EOperationAxis"); //$NON-NLS-1$ - possibleAxisCreation.add("EStructuralFeatureAxis"); //$NON-NLS-1$ - possibleAxisCreation.add("FeatureIdAxis"); //$NON-NLS-1$ - possibleAxisCreation.add("ObjectAxis"); //$NON-NLS-1$ - } - - - /** - * A copy of initial tree filling configuration to modify with this dialog. - */ - protected final TreeFillingConfiguration modifiedTreefillingConfiguration; - - /** - * The list of existing label provider configurations for the tree filling configuration label provider reference. - */ - protected final List existingLabelProviderConfigurations; - - /** - * The list of existing paste configurations for the tree filling configuration paste configuration reference. - */ - protected final List existingPasteConfigurations; - - /** - * The label provider for the UML elements. - */ - protected final ILabelProvider labelProvider = new UMLLabelProvider(); - - /** - * The stack layout which allow to display the correct element composite corresponding to the type of axis. - */ - protected StackLayout stackLayout; - - /** - * The parent element composite which contains the stack layout. - */ - protected Composite compositeElement; - - /** - * The composite for the element referenced from the axis. - */ - protected Composite compositeElementReference; - - /** - * The composite for the string element from the axis. - */ - protected Composite compositeElementString; - - /** - * The CLabel composite for the element reference. - */ - protected CLabel elementCLabel; - - /** - * The CLabel composite for the element string. - */ - protected Text elementText; - - /** - * The browse button which allow to edit the element. - */ - protected Button browseValuesButton; - - /** - * The delete button which allow to unset the element value. - */ - protected Button deleteValuesButton; - - /** - * Constructor. - * - * @param parentShell - * The parent shell of the dialog. - * @param treefillingConfiguration - * The initial tree filling configuration to edit. - * @param existingLabelProvidersConfiguration - * The list of existing label provider configurations for the tree filling configuration label provider reference. - * @param existingPasteConfigurations - * The list of existing paste configurations for the tree filling configuration paste configuration reference. - */ - public TreeFillingConfigurationDialog(final Shell parentShell, final TreeFillingConfiguration treefillingConfiguration, final List existingLabelProvidersConfiguration, - final List existingPasteConfigurations) { - super(parentShell); - this.modifiedTreefillingConfiguration = EcoreUtil.copy(treefillingConfiguration); - this.existingLabelProviderConfigurations = existingLabelProvidersConfiguration; - this.existingPasteConfigurations = existingPasteConfigurations; - setTitle(Messages.TreeFillingConfigurationDialog_treeFillingConfigurationDialogName); - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.jface.dialogs.Dialog#create() - */ - @Override - public void create() { - super.create(); - getShell().setImage(Activator.getDefault().getImage(NattableConfigurationConstants.PAPYRUS_ICON_PATH)); - - final Composite parent = new Composite((Composite) getDialogArea(), SWT.NONE); - parent.setLayout(new GridLayout(4, false)); - parent.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); - getShell().setSize(600, 400); - - // Create the fields - createFields(parent); - - getShell().pack(); - Point size = getShell().getSize(); - int minWidth = 600; - if (size.x < minWidth) { - size.x = minWidth; - } - getShell().setSize(size); - } - - /** - * This allows to create the fields to edit the tree filling configuration. - * - * @param parent - * The parent composite. - */ - protected void createFields(final Composite parent) { - // Create the depth level combo - createDepthLevelCombo(parent); - - // Create the label provider configuration combo - createLabelProviderCombo(parent); - - // Create the paste configuration combo - createPasteConfigurationCombo(parent); - - // Create the axis group management - createAxisGroup(parent); - - setAxisUsedAsAxisProvider(modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider()); - if (null != modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider()) { - setAxisElement(modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider().getElement()); - } - - } - - /** - * This allows to create the depth level combo. - * - * @param parent - * The parent composite. - */ - protected void createDepthLevelCombo(final Composite parent) { - final Label depthLabel = new Label(parent, SWT.NONE); - depthLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_depthLabel); - depthLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); - final Combo depthCombo = new Combo(parent, SWT.READ_ONLY); - depthCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1)); - depthCombo.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(final SelectionEvent e) { - modifiedTreefillingConfiguration.setDepth(Integer.valueOf(depthCombo.getText())); - } - }); - final Collection possiblesDepth = new ArrayList(10); - for (int i = 0; i < 10; i++) { - possiblesDepth.add(String.valueOf(i)); - } - depthCombo.setItems((String[]) possiblesDepth.toArray(new String[possiblesDepth.size()])); - depthCombo.select(modifiedTreefillingConfiguration.getDepth()); - } - - /** - * This allows to create the label provider combo. - * - * @param parent - * The parent composite. - */ - protected void createLabelProviderCombo(final Composite parent) { - final Label labelProviderConfigurationLabel = new Label(parent, SWT.NONE); - labelProviderConfigurationLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_labelProviderLabel); - labelProviderConfigurationLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); - final Combo labelProviderConfigurationCombo = new Combo(parent, SWT.READ_ONLY); - labelProviderConfigurationCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1)); - labelProviderConfigurationCombo.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(final SelectionEvent e) { - if (labelProviderConfigurationCombo.getText().isEmpty()) { - modifiedTreefillingConfiguration.setLabelProvider(null); - } else { - modifiedTreefillingConfiguration.setLabelProvider(existingLabelProviderConfigurations.get(labelProviderConfigurationCombo.getSelectionIndex() - 1)); - } - } - }); - - final List labelProviders = new ArrayList(existingLabelProviderConfigurations.size()); - for (final ILabelProviderConfiguration existingLabelProviderConf : existingLabelProviderConfigurations) { - final String className = existingLabelProviderConf.getClass().getSimpleName(); - if (NameSimplifier.labelProviderConfigurationNames.containsKey(className)) { - final String shortLabelProviderName = NameSimplifier.labelProviderConfigurationNames.get(className); - String finalShortLabelProviderName = shortLabelProviderName; - int index = 1; - while (labelProviders.contains(finalShortLabelProviderName)) { - final StringBuilder builder = new StringBuilder(); - builder.append(shortLabelProviderName); - builder.append("_"); //$NON-NLS-1$ - builder.append(index); - finalShortLabelProviderName = builder.toString(); - index++; - } - labelProviders.add(finalShortLabelProviderName); - } - } - - labelProviderConfigurationCombo.setItems((String[]) labelProviders.toArray(new String[labelProviders.size()])); - if (null != modifiedTreefillingConfiguration.getLabelProvider()) { - int index = existingLabelProviderConfigurations.indexOf(modifiedTreefillingConfiguration.getLabelProvider()); - labelProviderConfigurationCombo.select(index); - } - } - - /** - * This allows to create the paste configuration combo. - * - * @param parent - * The parent composite. - */ - protected void createPasteConfigurationCombo(final Composite parent) { - final Label pasteConfigurationLabel = new Label(parent, SWT.NONE); - pasteConfigurationLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_pasteConfigurationLabel); - pasteConfigurationLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); - final Combo pasteConfigurationCombo = new Combo(parent, SWT.READ_ONLY); - pasteConfigurationCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1)); - pasteConfigurationCombo.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(final SelectionEvent e) { - if (pasteConfigurationCombo.getText().isEmpty()) { - modifiedTreefillingConfiguration.setPasteConfiguration(null); - } else { - modifiedTreefillingConfiguration.setPasteConfiguration(existingPasteConfigurations.get(pasteConfigurationCombo.getSelectionIndex() - 1)); - } - } - }); - - final List pasteConfigurations = new ArrayList(existingPasteConfigurations.size()); - pasteConfigurations.add(""); //$NON-NLS-1$ - for (final PasteEObjectConfiguration existingPasteConf : existingPasteConfigurations) { - final StringBuilder builder = new StringBuilder(); - builder.append("Paste Conf: '"); //$NON-NLS-1$ - builder.append(existingPasteConf.getPastedElementId()); - builder.append("' in '"); //$NON-NLS-1$ - builder.append(existingPasteConf.getPasteElementContainementFeature().getName()); - builder.append("'"); //$NON-NLS-1$ - pasteConfigurations.add(builder.toString()); - } - - pasteConfigurationCombo.setItems((String[]) pasteConfigurations.toArray(new String[pasteConfigurations.size()])); - if (null != modifiedTreefillingConfiguration.getPasteConfiguration()) { - int index = existingPasteConfigurations.indexOf(modifiedTreefillingConfiguration.getPasteConfiguration()); - pasteConfigurationCombo.select(index); - } - } - - /** - * This allows to create the axis group. - * - * @param parent - * The parent composite. - */ - protected void createAxisGroup(final Composite parent) { - final Group axisGroup = new Group(parent, SWT.NONE); - axisGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 4, 1)); - axisGroup.setLayout(new GridLayout(4, false)); - axisGroup.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_axisUsedAsAxisProviderLabel); - - // Create the paste configuration combo - final Label axisTypeLabel = new Label(axisGroup, SWT.NONE); - axisTypeLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_typeLabel); - axisTypeLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); - final Combo axisTypeCombo = new Combo(axisGroup, SWT.READ_ONLY); - axisTypeCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1)); - axisTypeCombo.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(final SelectionEvent e) { - final IAxis existingAxis = modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider(); - - if (axisTypeCombo.getText().isEmpty() && null != existingAxis) { - setAxisUsedAsAxisProvider(null); - } else { - if (null == existingAxis || !existingAxis.getClass().getSimpleName().substring(0, existingAxis.getClass().getSimpleName().length() - 4).equals(axisTypeCombo.getText())) { - IAxis recreatedAxis = null; - if ("EObjectAxis".equals(axisTypeCombo.getText())) { //$NON-NLS-1$ - recreatedAxis = NattableaxisFactory.eINSTANCE.createEObjectAxis(); - } else if ("EOperationAxis".equals(axisTypeCombo.getText())) { //$NON-NLS-1$ - recreatedAxis = NattableaxisFactory.eINSTANCE.createEOperationAxis(); - } else if ("EStructuralFeatureAxis".equals(axisTypeCombo.getText())) { //$NON-NLS-1$ - recreatedAxis = NattableaxisFactory.eINSTANCE.createEStructuralFeatureAxis(); - } else if ("FeatureIdAxis".equals(axisTypeCombo.getText())) { //$NON-NLS-1$ - recreatedAxis = NattableaxisFactory.eINSTANCE.createFeatureIdAxis(); - } else if ("ObjectAxis".equals(axisTypeCombo.getText())) { //$NON-NLS-1$ - recreatedAxis = NattableaxisFactory.eINSTANCE.createObjectIdAxis(); - } - - if (null != existingAxis) { - recreatedAxis.setAlias(existingAxis.getAlias()); - } - - setAxisUsedAsAxisProvider(recreatedAxis); - } - } - } - }); - - // Add the possibility to reset it - final List possiblesAxis = new ArrayList(possibleAxisCreation); - possiblesAxis.add(0, ""); //$NON-NLS-1$ - - axisTypeCombo.setItems((String[]) possiblesAxis.toArray(new String[possiblesAxis.size()])); - boolean foundAxis = false; - - // Manage the initial value corresponding to the current axis used - if (null != modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider()) { - final IAxis existingAxis = modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider(); - final String existingAxisClassName = existingAxis.getClass().getSimpleName().substring(0, existingAxis.getClass().getSimpleName().length() - 4); - - for (int index = 0; index < possiblesAxis.size() && !foundAxis; index++) { - final String axisClass = possiblesAxis.get(index); - - if (existingAxisClassName.equals(axisClass)) { - axisTypeCombo.select(index); - foundAxis = true; - } - } - } else { - axisTypeCombo.select(0); - } - - // Create the stack layout to display the composite string element or the reference element - stackLayout = new StackLayout(); - - // The parent composite for the element value - compositeElement = new Composite(axisGroup, SWT.NONE); - compositeElement.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1)); - compositeElement.setLayout(stackLayout); - - // Create the composite element reference for the element reference (contrary to String value) - compositeElementReference = new Composite(compositeElement, SWT.NONE); - compositeElementReference.setLayout(new GridLayout(4, false)); - // Create the element labels and dialog for the reference - final Label elementLabel = new Label(compositeElementReference, SWT.NONE); - elementLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_elementLabel); - elementLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); - elementCLabel = new CLabel(compositeElementReference, SWT.BORDER); - elementCLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); - browseValuesButton = new Button(compositeElementReference, SWT.PUSH); - browseValuesButton.setImage(Activator.getDefault().getImage(NattableConfigurationConstants.BROWSE_ICON_PATH)); - browseValuesButton.setToolTipText(org.eclipse.papyrus.infra.widgets.messages.Messages.ReferenceDialog_EditValue); - browseValuesButton.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(final SelectionEvent e) { - Object element = null; - final IAxis existingAxis = modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider(); - - if (existingAxis instanceof EObjectAxis) { - element = ((EObjectAxis) existingAxis).getElement(); - } else if (existingAxis instanceof EStructuralFeatureAxis) { - element = ((EStructuralFeatureAxis) existingAxis).getElement(); - } else if (existingAxis instanceof EOperationAxis) { - element = ((EOperationAxis) existingAxis).getElement(); - } - browseAction(element); - } - }); - - deleteValuesButton = new Button(compositeElementReference, SWT.PUSH); - deleteValuesButton.setImage(Activator.getDefault().getImage(NattableConfigurationConstants.DELETE_ICON_PATH)); - deleteValuesButton.setToolTipText(org.eclipse.papyrus.infra.widgets.messages.Messages.ReferenceDialog_UnsetValue); - deleteValuesButton.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(final SelectionEvent e) { - setAxisElement(null); - } - }); - - // Create the composite element reference for the element reference (contrary to String value) - compositeElementString = new Composite(compositeElement, SWT.NONE); - compositeElementString.setLayout(new GridLayout(4, false)); - // Create the element label and the text for the string value - final Label secondElementLabel = new Label(compositeElementString, SWT.NONE); - secondElementLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_elementLabel); - secondElementLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); - elementText = new Text(compositeElementString, SWT.BORDER); - elementText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); - elementText.addModifyListener(new ModifyListener() { - - @Override - public void modifyText(final ModifyEvent e) { - setAxisElement(elementText.getText()); - } - }); - } - - /** - * The action executed when the "browse" button is selected Choose a value - * from a selection of already created objects - */ - protected void browseAction(final Object value) { - final ITreeSelectorDialog dialog = new TreeSelectorDialog(getShell()) { - @Override - protected void initViewerAndProvider() { - super.initViewerAndProvider(); - // Set a comparator to sort the tree viewer - getViewer().setComparator(new ViewerComparator(new StringComparator()));// should always be string element - } - }; - dialog.setTitle(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_elementDialogName); - - final UMLFeatureRestrictedContentProvider contentProvider = new UMLFeatureRestrictedContentProvider(null, false) { - - @Override - public Object[] getChildren(final Object parentElement) { - List childrenList = Arrays.asList(super.getChildren(parentElement)); - if (parentElement instanceof EClass) { - childrenList = new ArrayList(childrenList); - final EClass eClass = (EClass) parentElement; - if (isIgnoringInheritedElements()) { - childrenList.addAll(eClass.getEOperations()); - } else { - childrenList.addAll(eClass.getEAllOperations()); - } - childrenList.remove(EcorePackage.eINSTANCE.getEModelElement_EAnnotations()); - } - return childrenList.toArray(); - } - }; - final ReferenceSelector selector = new ReferenceSelector(false) { - - @Override - public void createControls(Composite parent) { - super.createControls(parent); - this.treeViewer.setComparator(new ViewerComparator(new StringComparator()));// should always be string element - } - }; - - selector.setLabelProvider(labelProvider); - selector.setContentProvider(contentProvider); - final ITreeContentProvider treeContentProvider = new FlattenableRestrictedFilteredContentProvider((IRestrictedContentProvider) contentProvider, selector) { - - @Override - public boolean isValidValue(final Object element) { - return isTypeNeeded(element); - } - }; - - dialog.setContentProvider(treeContentProvider); - dialog.setLabelProvider(labelProvider); - if (null != value) { - dialog.setInitialElementSelections(Collections.singletonList(value)); - } - int result = dialog.open(); - if (Window.OK == result) { - Object[] newValue = dialog.getResult(); - if (null == newValue) { - return; - } - - if (0 == newValue.length) { - setAxisElement(null); - } else { - setAxisElement(newValue[0]); - } - } - } - - /** - * This allows to check if the element in dialog must be used for the axis element. - * - * @param element - * The element selected to check. - * @return true if the element can be set to the axis, false otherwise. - */ - protected boolean isTypeNeeded(final Object element) { - boolean result = false; - - final IAxis existingAxis = modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider(); - if (null != existingAxis) { - result = element != EcorePackage.eINSTANCE.getEModelElement_EAnnotations(); - - // Depending to the axis, objects displayed are not the same - if (existingAxis instanceof EObjectAxis && result) { - result = element instanceof EClass; - } else if (existingAxis instanceof EStructuralFeatureAxis && result) { - result = element instanceof EStructuralFeature; - } else if (existingAxis instanceof EOperationAxis && result) { - result = element instanceof EOperation; - } - } - - return result; - } - - /** - * This allows to set the axis and refresh the button corresponding to the axis value. - * - * @param newAxis - * The axis to set to the tree filling configuration. - */ - protected void setAxisUsedAsAxisProvider(final IAxis newAxis) { - if (null == modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider() || !modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider().equals(newAxis)) { - modifiedTreefillingConfiguration.setAxisUsedAsAxisProvider(newAxis); - } - - // This allows to refresh the composite to display for the axis element value - stackLayout.topControl = newAxis instanceof FeatureIdAxis ? compositeElementString : compositeElementReference; - compositeElement.layout(); - if (stackLayout.topControl.equals(compositeElementString)) { - elementText.setText(null != newAxis && null != newAxis.getElement() ? ((FeatureIdAxis) newAxis).getElement() : ""); //$NON-NLS-1$ - } - - setAxisElement(null != newAxis ? newAxis.getElement() : null); - } - - /** - * This allows to set the axis and refresh the button corresponding to the axis value. - * - * @param newAxis - * The axis to set to the tree filling configuration. - */ - protected void setAxisElement(final Object element) { - final IAxis existingAxis = modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider(); - if (null != existingAxis) { - if (existingAxis instanceof EObjectAxis && (null == element || element instanceof EObject)) { - ((EObjectAxis) existingAxis).setElement((EObject) element); - } else if (existingAxis instanceof EStructuralFeatureAxis && (null == element || element instanceof EStructuralFeature)) { - ((EStructuralFeatureAxis) existingAxis).setElement((EStructuralFeature) element); - } else if (existingAxis instanceof EOperationAxis && (null == element || element instanceof EOperation)) { - ((EOperationAxis) existingAxis).setElement((EOperation) element); - } else if (existingAxis instanceof FeatureIdAxis && (null == element || element instanceof String)) { - ((FeatureIdAxis) existingAxis).setElement((String) element); - } - } - - // Manage the enabling and displayed composites - if (stackLayout.topControl.equals(compositeElementReference)) { - elementCLabel.setEnabled(null != existingAxis); - elementCLabel.setImage(labelProvider.getImage(element)); - elementCLabel.setText(labelProvider.getText(element)); - - browseValuesButton.setEnabled(null != existingAxis); - deleteValuesButton.setEnabled(null != existingAxis && null != element); - } - } - - /** - * Returns the modified tree filling configuration. - * - * @return The modified tree filling configuration. - */ - public TreeFillingConfiguration getModifiedTreeFillingConfiguration() { - return modifiedTreefillingConfiguration; - } -} diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/edition/FeatureFillingConfigurationDialog.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/edition/FeatureFillingConfigurationDialog.java new file mode 100644 index 00000000000..045d11569a2 --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/edition/FeatureFillingConfigurationDialog.java @@ -0,0 +1,244 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.customization.nattableconfiguration.edition; + +import java.util.Collections; + +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.EcorePackage; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages; +import org.eclipse.papyrus.customization.nattableconfiguration.utils.NattableConfigurationConstants; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.EStructuralFeatureValueFillingConfiguration; +import org.eclipse.papyrus.infra.nattable.utils.StringComparator; +import org.eclipse.papyrus.infra.widgets.Activator; +import org.eclipse.papyrus.infra.widgets.editors.ITreeSelectorDialog; +import org.eclipse.papyrus.infra.widgets.editors.TreeSelectorDialog; +import org.eclipse.papyrus.infra.widgets.providers.FlattenableRestrictedFilteredContentProvider; +import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider; +import org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector; +import org.eclipse.papyrus.uml.nattable.provider.UMLFeatureRestrictedContentProvider; +import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +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.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.dialogs.SelectionDialog; + +/** + * The dialog which allow to edit the feature filling configuration features. + */ +public class FeatureFillingConfigurationDialog extends SelectionDialog { + + /** + * A copy of initial feature filling configuration to modify with this dialog. + */ + protected final EStructuralFeatureValueFillingConfiguration modifiedFeatureFillingConf; + + /** + * The label provider for the UML elements. + */ + protected final ILabelProvider labelProvider = new UMLLabelProvider(); + + /** + * The CLabel composite for the listen feature. + */ + protected CLabel listenFeatureText; + + /** + * The browse button which allow to edit the listen feature. + */ + protected Button browseValuesButton; + + /** + * The delete button which allow to unset the listen feature value. + */ + protected Button deleteValuesButton; + + /** + * Constructor. + * + * @param parentShell + * The parent shell of the dialog. + * @param featureFillingConf + * The initial feature filling configuration to edit. + */ + public FeatureFillingConfigurationDialog(final Shell parentShell, final EStructuralFeatureValueFillingConfiguration featureFillingConf) { + super(parentShell); + this.modifiedFeatureFillingConf = EcoreUtil.copy(featureFillingConf); + setTitle(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.FeatureFillingConfigurationDialog_featureFillingConfigurationDialogName); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.dialogs.Dialog#create() + */ + @Override + public void create() { + super.create(); + getShell().setImage(Activator.getDefault().getImage(NattableConfigurationConstants.PAPYRUS_ICON_PATH)); + + final Composite parent = new Composite((Composite) getDialogArea(), SWT.NONE); + parent.setLayout(new GridLayout(4, false)); + parent.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); + getShell().setSize(600, 400); + + // Create the fields + createFields(parent); + + getShell().pack(); + Point size = getShell().getSize(); + int minWidth = 600; + if (size.x < minWidth) { + size.x = minWidth; + } + getShell().setSize(size); + } + + /** + * This allows to create the fields to edit the feature filling configuration. + * + * @param parent + * The parent composite. + */ + protected void createFields(final Composite parent) { + // Create the listen feature labels and dialog + final Label listenFeatureLabel = new Label(parent, SWT.NONE); + listenFeatureLabel.setText(Messages.FeatureFillingConfigurationDialog_listenFeature); + listenFeatureLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + listenFeatureText = new CLabel(parent, SWT.BORDER); + listenFeatureText.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + browseValuesButton = new Button(parent, SWT.PUSH); + browseValuesButton.setImage(Activator.getDefault().getImage(NattableConfigurationConstants.BROWSE_ICON_PATH)); + browseValuesButton.setToolTipText(org.eclipse.papyrus.infra.widgets.messages.Messages.ReferenceDialog_EditValue); + browseValuesButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent e) { + browseAction(modifiedFeatureFillingConf.getListenFeature()); + } + }); + + deleteValuesButton = new Button(parent, SWT.PUSH); + deleteValuesButton.setImage(Activator.getDefault().getImage(NattableConfigurationConstants.DELETE_ICON_PATH)); + deleteValuesButton.setToolTipText(org.eclipse.papyrus.infra.widgets.messages.Messages.ReferenceDialog_UnsetValue); + deleteValuesButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent e) { + setListenFeature(null); + } + }); + + setListenFeature(modifiedFeatureFillingConf.getListenFeature()); + } + + /** + * The action executed when the "browse" button is selected Choose a value + * from a selection of already created objects. + * + * @param value + * The initial value of the listen feature. + */ + protected void browseAction(final Object value) { + final ITreeSelectorDialog dialog = new TreeSelectorDialog(getShell()) { + @Override + protected void initViewerAndProvider() { + super.initViewerAndProvider(); + // Set a comparator to sort the tree viewer + getViewer().setComparator(new ViewerComparator(new StringComparator()));// should always be string element + } + }; + dialog.setTitle(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.FeatureFillingConfigurationDialog_listenFeatureDialogName); + + final UMLFeatureRestrictedContentProvider contentProvider = new UMLFeatureRestrictedContentProvider(null, false); + final ReferenceSelector selector = new ReferenceSelector(false) { + + @Override + public void createControls(Composite parent) { + super.createControls(parent); + this.treeViewer.setComparator(new ViewerComparator(new StringComparator()));// should always be string element + } + }; + + selector.setLabelProvider(labelProvider); + selector.setContentProvider(contentProvider); + final ITreeContentProvider treeContentProvider = new FlattenableRestrictedFilteredContentProvider((IRestrictedContentProvider) contentProvider, selector) { + + @Override + public boolean isValidValue(final Object element) { + // EMF dependency, must not be done here, it should be better with a new content provider service + return element instanceof EReference && ((EReference) element).isMany() && element != EcorePackage.eINSTANCE.getEModelElement_EAnnotations(); + } + }; + + dialog.setContentProvider(treeContentProvider); + dialog.setLabelProvider(labelProvider); + if (null != value) { + dialog.setInitialElementSelections(Collections.singletonList(value)); + } + int result = dialog.open(); + if (Window.OK == result) { + Object[] newValue = dialog.getResult(); + if (null == newValue) { + return; + } + + if (0 == newValue.length) { + setListenFeature(null); + } else { + setListenFeature((EStructuralFeature) newValue[0]); + } + } + } + + /** + * This allows to set the listen feature and refresh the button corresponding to the listen feature value. + * + * @param structuralFeature + * The structural feature to set. + */ + protected void setListenFeature(final EStructuralFeature structuralFeature) { + if (null == modifiedFeatureFillingConf.getListenFeature() || !structuralFeature.equals(modifiedFeatureFillingConf.getListenFeature())) { + modifiedFeatureFillingConf.setListenFeature(structuralFeature); + } + listenFeatureText.setImage(labelProvider.getImage(modifiedFeatureFillingConf.getListenFeature())); + listenFeatureText.setText(labelProvider.getText(modifiedFeatureFillingConf.getListenFeature())); + + deleteValuesButton.setEnabled(null != structuralFeature); + } + + /** + * Returns the modified feature filling configuration. + * + * @return The modified feature filling configuration. + */ + public EStructuralFeatureValueFillingConfiguration getModifiedFeatureFillingConfiguration() { + return modifiedFeatureFillingConf; + } + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/edition/PasteEObjectConfigurationDialog.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/edition/PasteEObjectConfigurationDialog.java new file mode 100644 index 00000000000..4be86896f1a --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/edition/PasteEObjectConfigurationDialog.java @@ -0,0 +1,302 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.customization.nattableconfiguration.edition; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.EcorePackage; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.gmf.runtime.emf.type.core.IElementType; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.customization.nattableconfiguration.utils.NattableConfigurationConstants; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.PasteEObjectConfiguration; +import org.eclipse.papyrus.infra.nattable.utils.StringComparator; +import org.eclipse.papyrus.infra.services.edit.utils.ElementTypeUtils; +import org.eclipse.papyrus.infra.widgets.Activator; +import org.eclipse.papyrus.infra.widgets.editors.ITreeSelectorDialog; +import org.eclipse.papyrus.infra.widgets.editors.TreeSelectorDialog; +import org.eclipse.papyrus.infra.widgets.providers.FlattenableRestrictedFilteredContentProvider; +import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider; +import org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector; +import org.eclipse.papyrus.uml.nattable.provider.UMLFeatureRestrictedContentProvider; +import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.dialogs.SelectionDialog; + +/** + * The dialog which allow to edit the paste configuration features. + */ +public class PasteEObjectConfigurationDialog extends SelectionDialog { + + /** + * A copy of initial paste configuration to modify with this dialog. + */ + protected final PasteEObjectConfiguration modifiedPasteConfiguration; + + /** + * The label provider for the UML elements. + */ + protected final ILabelProvider labelProvider = new UMLLabelProvider(); + + /** + * The CLabel composite for the containment feature. + */ + protected CLabel containmentFeatureText; + + /** + * The browse button which allow to edit the containment feature. + */ + protected Button browseValuesButton; + + /** + * The delete button which allow to unset the containment feature value. + */ + protected Button deleteValuesButton; + + /** + * Constructor. + * + * @param parentShell + * The parent shell of the dialog. + * @param pasteConfiguration + * The initial paste configuration to edit. + */ + public PasteEObjectConfigurationDialog(final Shell parentShell, final PasteEObjectConfiguration pasteConfiguration) { + super(parentShell); + this.modifiedPasteConfiguration = EcoreUtil.copy(pasteConfiguration); + setTitle(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.PasteEObjectConfigurationDialog_pasteEObjectConfigurationDialogName); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.dialogs.Dialog#create() + */ + @Override + public void create() { + super.create(); + getShell().setImage(Activator.getDefault().getImage(NattableConfigurationConstants.PAPYRUS_ICON_PATH)); + + final Composite parent = new Composite((Composite) getDialogArea(), SWT.NONE); + parent.setLayout(new GridLayout(4, false)); + parent.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); + getShell().setSize(600, 400); + + // Create the fields + createFields(parent); + + getShell().pack(); + Point size = getShell().getSize(); + int minWidth = 600; + if (size.x < minWidth) { + size.x = minWidth; + } + getShell().setSize(size); + } + + /** + * This allows to create the fields to edit the paste configuration. + * + * @param parent + * The parent composite. + */ + protected void createFields(final Composite parent) { + // Create the detached mode checkbox + final Label detachedModeLabel = new Label(parent, SWT.NONE); + detachedModeLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.PasteEObjectConfigurationDialog_detachedModeLabel); + detachedModeLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + final Button detachedModeButton = new Button(parent, SWT.CHECK); + detachedModeButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1)); + detachedModeButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent e) { + modifiedPasteConfiguration.setDetachedMode(detachedModeButton.getSelection()); + } + }); + detachedModeButton.setSelection(modifiedPasteConfiguration.isDetachedMode()); + + // Create the pasted element id combo box + final Label pastedElementIdLabel = new Label(parent, SWT.NONE); + pastedElementIdLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.PasteEObjectConfigurationDialog_pastedElementIdLabel); + pastedElementIdLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + final Combo pastedElementIdCombo = new Combo(parent, SWT.READ_ONLY); + pastedElementIdCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1)); + pastedElementIdCombo.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + modifiedPasteConfiguration.setPastedElementId(pastedElementIdCombo.getText()); + } + }); + + final Collection possibleValues = ElementTypeUtils.getAllExistingElementTypes(); + final List possibleValuesAsString = new ArrayList(possibleValues.size()); + + int indexToSelect = -1; + int index = 0; + + for (final IElementType elementType : possibleValues) { + possibleValuesAsString.add(elementType.getDisplayName()); + if (elementType.getDisplayName().equals(modifiedPasteConfiguration.getPastedElementId())) { + indexToSelect = index; + } + index++; + } + + pastedElementIdCombo.setItems((String[]) possibleValuesAsString.toArray(new String[possibleValuesAsString.size()])); + if (-1 != indexToSelect) { + pastedElementIdCombo.select(indexToSelect); + } + + // Create the containment feature labels and dialog + final Label containmentFeatureLabel = new Label(parent, SWT.NONE); + containmentFeatureLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.PasteEObjectConfigurationDialog_containmentFeatureLabel); + containmentFeatureLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + containmentFeatureText = new CLabel(parent, SWT.BORDER); + containmentFeatureText.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + browseValuesButton = new Button(parent, SWT.PUSH); + browseValuesButton.setImage(Activator.getDefault().getImage(NattableConfigurationConstants.BROWSE_ICON_PATH)); + browseValuesButton.setToolTipText(org.eclipse.papyrus.infra.widgets.messages.Messages.ReferenceDialog_EditValue); + browseValuesButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent e) { + browseAction(modifiedPasteConfiguration.getPasteElementContainementFeature()); + } + }); + + deleteValuesButton = new Button(parent, SWT.PUSH); + deleteValuesButton.setImage(Activator.getDefault().getImage(NattableConfigurationConstants.DELETE_ICON_PATH)); + deleteValuesButton.setToolTipText(org.eclipse.papyrus.infra.widgets.messages.Messages.ReferenceDialog_UnsetValue); + deleteValuesButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent e) { + setPasteElementContainementFeature(null); + } + }); + + setPasteElementContainementFeature(modifiedPasteConfiguration.getPasteElementContainementFeature()); + + // TODO : Post actions + } + + /** + * The action executed when the "browse" button is selected Choose a value + * from a selection of already created objects. + * + * @param value + * The initial value of the containment feature. + */ + protected void browseAction(final Object value) { + ITreeSelectorDialog dialog = new TreeSelectorDialog(getShell()) { + @Override + protected void initViewerAndProvider() { + super.initViewerAndProvider(); + // Set a comparator to sort the tree viewer + getViewer().setComparator(new ViewerComparator(new StringComparator()));// should always be string element + } + }; + dialog.setTitle(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.PasteEObjectConfigurationDialog_containmentFeatureDialogName); + + final UMLFeatureRestrictedContentProvider contentProvider = new UMLFeatureRestrictedContentProvider(null, false); + final ReferenceSelector selector = new ReferenceSelector(false) { + + @Override + public void createControls(final Composite parent) { + super.createControls(parent); + this.treeViewer.setComparator(new ViewerComparator(new StringComparator()));// should always be string element + } + }; + + selector.setLabelProvider(labelProvider); + selector.setContentProvider(contentProvider); + final ITreeContentProvider treeContentProvider = new FlattenableRestrictedFilteredContentProvider((IRestrictedContentProvider) contentProvider, selector) { + + @Override + public boolean isValidValue(final Object element) { + // EMF dependency, must not be done here, it should be better with a new content provider service + return element instanceof EReference && ((EReference) element).isMany() && element != EcorePackage.eINSTANCE.getEModelElement_EAnnotations(); + } + }; + + dialog.setContentProvider(treeContentProvider); + dialog.setLabelProvider(labelProvider); + if (null != value) { + dialog.setInitialElementSelections(Collections.singletonList(value)); + } + int result = dialog.open(); + if (Window.OK == result) { + Object[] newValue = dialog.getResult(); + if (null == newValue) { + return; + } + + if (0 == newValue.length) { + setPasteElementContainementFeature(null); + } else { + Object selectedValue = newValue[0]; + setPasteElementContainementFeature((EStructuralFeature) selectedValue); + } + } + } + + /** + * This allows to set the containment feature and refresh the button corresponding to the containment feature value. + * + * @param structuralFeature + * The structural feature to set. + */ + protected void setPasteElementContainementFeature(final EStructuralFeature structuralFeature) { + if (null == modifiedPasteConfiguration.getPasteElementContainementFeature() || !structuralFeature.equals(modifiedPasteConfiguration.getPasteElementContainementFeature())) { + modifiedPasteConfiguration.setPasteElementContainementFeature(structuralFeature); + } + containmentFeatureText.setImage(labelProvider.getImage(modifiedPasteConfiguration.getPasteElementContainementFeature())); + containmentFeatureText.setText(labelProvider.getText(modifiedPasteConfiguration.getPasteElementContainementFeature())); + + deleteValuesButton.setEnabled(null != structuralFeature); + } + + /** + * Returns the modified paste configuration. + * + * @return The modified paste configuration. + */ + public PasteEObjectConfiguration getModifiedPasteEObjectConfiguration() { + return modifiedPasteConfiguration; + } + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/edition/TreeFillingConfigurationDialog.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/edition/TreeFillingConfigurationDialog.java new file mode 100644 index 00000000000..adfda5c7c68 --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/edition/TreeFillingConfigurationDialog.java @@ -0,0 +1,646 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.customization.nattableconfiguration.edition; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EOperation; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.EcorePackage; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages; +import org.eclipse.papyrus.customization.nattableconfiguration.utils.NameSimplifier; +import org.eclipse.papyrus.customization.nattableconfiguration.utils.NattableConfigurationConstants; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EObjectAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EOperationAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.EStructuralFeatureAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.FeatureIdAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.IAxis; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.NattableaxisFactory; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.PasteEObjectConfiguration; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TreeFillingConfiguration; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattablelabelprovider.ILabelProviderConfiguration; +import org.eclipse.papyrus.infra.nattable.utils.StringComparator; +import org.eclipse.papyrus.infra.widgets.Activator; +import org.eclipse.papyrus.infra.widgets.editors.ITreeSelectorDialog; +import org.eclipse.papyrus.infra.widgets.editors.TreeSelectorDialog; +import org.eclipse.papyrus.infra.widgets.providers.FlattenableRestrictedFilteredContentProvider; +import org.eclipse.papyrus.infra.widgets.providers.IRestrictedContentProvider; +import org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector; +import org.eclipse.papyrus.uml.nattable.provider.UMLFeatureRestrictedContentProvider; +import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.SelectionDialog; + +/** + * The dialog which allow to edit the tree filling configuration features. + */ +public class TreeFillingConfigurationDialog extends SelectionDialog { + + /** + * The list of possible axis creation. + */ + protected final static List possibleAxisCreation = new ArrayList(); + + static { + possibleAxisCreation.add("EObjectAxis"); //$NON-NLS-1$ + possibleAxisCreation.add("EOperationAxis"); //$NON-NLS-1$ + possibleAxisCreation.add("EStructuralFeatureAxis"); //$NON-NLS-1$ + possibleAxisCreation.add("FeatureIdAxis"); //$NON-NLS-1$ + possibleAxisCreation.add("ObjectAxis"); //$NON-NLS-1$ + } + + + /** + * A copy of initial tree filling configuration to modify with this dialog. + */ + protected final TreeFillingConfiguration modifiedTreefillingConfiguration; + + /** + * The list of existing label provider configurations for the tree filling configuration label provider reference. + */ + protected final List existingLabelProviderConfigurations; + + /** + * The list of existing paste configurations for the tree filling configuration paste configuration reference. + */ + protected final List existingPasteConfigurations; + + /** + * The label provider for the UML elements. + */ + protected final ILabelProvider labelProvider = new UMLLabelProvider(); + + /** + * The stack layout which allow to display the correct element composite corresponding to the type of axis. + */ + protected StackLayout stackLayout; + + /** + * The parent element composite which contains the stack layout. + */ + protected Composite compositeElement; + + /** + * The composite for the element referenced from the axis. + */ + protected Composite compositeElementReference; + + /** + * The composite for the string element from the axis. + */ + protected Composite compositeElementString; + + /** + * The CLabel composite for the element reference. + */ + protected CLabel elementCLabel; + + /** + * The CLabel composite for the element string. + */ + protected Text elementText; + + /** + * The browse button which allow to edit the element. + */ + protected Button browseValuesButton; + + /** + * The delete button which allow to unset the element value. + */ + protected Button deleteValuesButton; + + /** + * Constructor. + * + * @param parentShell + * The parent shell of the dialog. + * @param treefillingConfiguration + * The initial tree filling configuration to edit. + * @param existingLabelProvidersConfiguration + * The list of existing label provider configurations for the tree filling configuration label provider reference. + * @param existingPasteConfigurations + * The list of existing paste configurations for the tree filling configuration paste configuration reference. + */ + public TreeFillingConfigurationDialog(final Shell parentShell, final TreeFillingConfiguration treefillingConfiguration, final List existingLabelProvidersConfiguration, + final List existingPasteConfigurations) { + super(parentShell); + this.modifiedTreefillingConfiguration = EcoreUtil.copy(treefillingConfiguration); + this.existingLabelProviderConfigurations = existingLabelProvidersConfiguration; + this.existingPasteConfigurations = existingPasteConfigurations; + setTitle(Messages.TreeFillingConfigurationDialog_treeFillingConfigurationDialogName); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.dialogs.Dialog#create() + */ + @Override + public void create() { + super.create(); + getShell().setImage(Activator.getDefault().getImage(NattableConfigurationConstants.PAPYRUS_ICON_PATH)); + + final Composite parent = new Composite((Composite) getDialogArea(), SWT.NONE); + parent.setLayout(new GridLayout(4, false)); + parent.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); + getShell().setSize(600, 400); + + // Create the fields + createFields(parent); + + getShell().pack(); + Point size = getShell().getSize(); + int minWidth = 600; + if (size.x < minWidth) { + size.x = minWidth; + } + getShell().setSize(size); + } + + /** + * This allows to create the fields to edit the tree filling configuration. + * + * @param parent + * The parent composite. + */ + protected void createFields(final Composite parent) { + // Create the depth level combo + createDepthLevelCombo(parent); + + // Create the label provider configuration combo + createLabelProviderCombo(parent); + + // Create the paste configuration combo + createPasteConfigurationCombo(parent); + + // Create the axis group management + createAxisGroup(parent); + + setAxisUsedAsAxisProvider(modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider()); + if (null != modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider()) { + setAxisElement(modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider().getElement()); + } + + } + + /** + * This allows to create the depth level combo. + * + * @param parent + * The parent composite. + */ + protected void createDepthLevelCombo(final Composite parent) { + final Label depthLabel = new Label(parent, SWT.NONE); + depthLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_depthLabel); + depthLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + final Combo depthCombo = new Combo(parent, SWT.READ_ONLY); + depthCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1)); + depthCombo.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent e) { + modifiedTreefillingConfiguration.setDepth(Integer.valueOf(depthCombo.getText())); + } + }); + final Collection possiblesDepth = new ArrayList(10); + for (int i = 0; i < 10; i++) { + possiblesDepth.add(String.valueOf(i)); + } + depthCombo.setItems((String[]) possiblesDepth.toArray(new String[possiblesDepth.size()])); + depthCombo.select(modifiedTreefillingConfiguration.getDepth()); + } + + /** + * This allows to create the label provider combo. + * + * @param parent + * The parent composite. + */ + protected void createLabelProviderCombo(final Composite parent) { + final Label labelProviderConfigurationLabel = new Label(parent, SWT.NONE); + labelProviderConfigurationLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_labelProviderLabel); + labelProviderConfigurationLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + final Combo labelProviderConfigurationCombo = new Combo(parent, SWT.READ_ONLY); + labelProviderConfigurationCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1)); + labelProviderConfigurationCombo.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent e) { + if (labelProviderConfigurationCombo.getText().isEmpty()) { + modifiedTreefillingConfiguration.setLabelProvider(null); + } else { + modifiedTreefillingConfiguration.setLabelProvider(existingLabelProviderConfigurations.get(labelProviderConfigurationCombo.getSelectionIndex() - 1)); + } + } + }); + + final List labelProviders = new ArrayList(existingLabelProviderConfigurations.size()); + for (final ILabelProviderConfiguration existingLabelProviderConf : existingLabelProviderConfigurations) { + final String className = existingLabelProviderConf.getClass().getSimpleName(); + if (NameSimplifier.labelProviderConfigurationNames.containsKey(className)) { + final String shortLabelProviderName = NameSimplifier.labelProviderConfigurationNames.get(className); + String finalShortLabelProviderName = shortLabelProviderName; + int index = 1; + while (labelProviders.contains(finalShortLabelProviderName)) { + final StringBuilder builder = new StringBuilder(); + builder.append(shortLabelProviderName); + builder.append("_"); //$NON-NLS-1$ + builder.append(index); + finalShortLabelProviderName = builder.toString(); + index++; + } + labelProviders.add(finalShortLabelProviderName); + } + } + + labelProviderConfigurationCombo.setItems((String[]) labelProviders.toArray(new String[labelProviders.size()])); + if (null != modifiedTreefillingConfiguration.getLabelProvider()) { + int index = existingLabelProviderConfigurations.indexOf(modifiedTreefillingConfiguration.getLabelProvider()); + labelProviderConfigurationCombo.select(index); + } + } + + /** + * This allows to create the paste configuration combo. + * + * @param parent + * The parent composite. + */ + protected void createPasteConfigurationCombo(final Composite parent) { + final Label pasteConfigurationLabel = new Label(parent, SWT.NONE); + pasteConfigurationLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_pasteConfigurationLabel); + pasteConfigurationLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + final Combo pasteConfigurationCombo = new Combo(parent, SWT.READ_ONLY); + pasteConfigurationCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1)); + pasteConfigurationCombo.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent e) { + if (pasteConfigurationCombo.getText().isEmpty()) { + modifiedTreefillingConfiguration.setPasteConfiguration(null); + } else { + modifiedTreefillingConfiguration.setPasteConfiguration(existingPasteConfigurations.get(pasteConfigurationCombo.getSelectionIndex() - 1)); + } + } + }); + + final List pasteConfigurations = new ArrayList(existingPasteConfigurations.size()); + pasteConfigurations.add(""); //$NON-NLS-1$ + for (final PasteEObjectConfiguration existingPasteConf : existingPasteConfigurations) { + final StringBuilder builder = new StringBuilder(); + builder.append("Paste Conf: '"); //$NON-NLS-1$ + builder.append(existingPasteConf.getPastedElementId()); + builder.append("' in '"); //$NON-NLS-1$ + builder.append(existingPasteConf.getPasteElementContainementFeature().getName()); + builder.append("'"); //$NON-NLS-1$ + pasteConfigurations.add(builder.toString()); + } + + pasteConfigurationCombo.setItems((String[]) pasteConfigurations.toArray(new String[pasteConfigurations.size()])); + if (null != modifiedTreefillingConfiguration.getPasteConfiguration()) { + int index = existingPasteConfigurations.indexOf(modifiedTreefillingConfiguration.getPasteConfiguration()); + pasteConfigurationCombo.select(index); + } + } + + /** + * This allows to create the axis group. + * + * @param parent + * The parent composite. + */ + protected void createAxisGroup(final Composite parent) { + final Group axisGroup = new Group(parent, SWT.NONE); + axisGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 4, 1)); + axisGroup.setLayout(new GridLayout(4, false)); + axisGroup.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_axisUsedAsAxisProviderLabel); + + // Create the paste configuration combo + final Label axisTypeLabel = new Label(axisGroup, SWT.NONE); + axisTypeLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_typeLabel); + axisTypeLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + final Combo axisTypeCombo = new Combo(axisGroup, SWT.READ_ONLY); + axisTypeCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1)); + axisTypeCombo.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent e) { + final IAxis existingAxis = modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider(); + + if (axisTypeCombo.getText().isEmpty() && null != existingAxis) { + setAxisUsedAsAxisProvider(null); + } else { + if (null == existingAxis || !existingAxis.getClass().getSimpleName().substring(0, existingAxis.getClass().getSimpleName().length() - 4).equals(axisTypeCombo.getText())) { + IAxis recreatedAxis = null; + if ("EObjectAxis".equals(axisTypeCombo.getText())) { //$NON-NLS-1$ + recreatedAxis = NattableaxisFactory.eINSTANCE.createEObjectAxis(); + } else if ("EOperationAxis".equals(axisTypeCombo.getText())) { //$NON-NLS-1$ + recreatedAxis = NattableaxisFactory.eINSTANCE.createEOperationAxis(); + } else if ("EStructuralFeatureAxis".equals(axisTypeCombo.getText())) { //$NON-NLS-1$ + recreatedAxis = NattableaxisFactory.eINSTANCE.createEStructuralFeatureAxis(); + } else if ("FeatureIdAxis".equals(axisTypeCombo.getText())) { //$NON-NLS-1$ + recreatedAxis = NattableaxisFactory.eINSTANCE.createFeatureIdAxis(); + } else if ("ObjectAxis".equals(axisTypeCombo.getText())) { //$NON-NLS-1$ + recreatedAxis = NattableaxisFactory.eINSTANCE.createObjectIdAxis(); + } + + if (null != existingAxis) { + recreatedAxis.setAlias(existingAxis.getAlias()); + } + + setAxisUsedAsAxisProvider(recreatedAxis); + } + } + } + }); + + // Add the possibility to reset it + final List possiblesAxis = new ArrayList(possibleAxisCreation); + possiblesAxis.add(0, ""); //$NON-NLS-1$ + + axisTypeCombo.setItems((String[]) possiblesAxis.toArray(new String[possiblesAxis.size()])); + boolean foundAxis = false; + + // Manage the initial value corresponding to the current axis used + if (null != modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider()) { + final IAxis existingAxis = modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider(); + final String existingAxisClassName = existingAxis.getClass().getSimpleName().substring(0, existingAxis.getClass().getSimpleName().length() - 4); + + for (int index = 0; index < possiblesAxis.size() && !foundAxis; index++) { + final String axisClass = possiblesAxis.get(index); + + if (existingAxisClassName.equals(axisClass)) { + axisTypeCombo.select(index); + foundAxis = true; + } + } + } else { + axisTypeCombo.select(0); + } + + // Create the stack layout to display the composite string element or the reference element + stackLayout = new StackLayout(); + + // The parent composite for the element value + compositeElement = new Composite(axisGroup, SWT.NONE); + compositeElement.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1)); + compositeElement.setLayout(stackLayout); + + // Create the composite element reference for the element reference (contrary to String value) + compositeElementReference = new Composite(compositeElement, SWT.NONE); + compositeElementReference.setLayout(new GridLayout(4, false)); + // Create the element labels and dialog for the reference + final Label elementLabel = new Label(compositeElementReference, SWT.NONE); + elementLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_elementLabel); + elementLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + elementCLabel = new CLabel(compositeElementReference, SWT.BORDER); + elementCLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + browseValuesButton = new Button(compositeElementReference, SWT.PUSH); + browseValuesButton.setImage(Activator.getDefault().getImage(NattableConfigurationConstants.BROWSE_ICON_PATH)); + browseValuesButton.setToolTipText(org.eclipse.papyrus.infra.widgets.messages.Messages.ReferenceDialog_EditValue); + browseValuesButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent e) { + Object element = null; + final IAxis existingAxis = modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider(); + + if (existingAxis instanceof EObjectAxis) { + element = ((EObjectAxis) existingAxis).getElement(); + } else if (existingAxis instanceof EStructuralFeatureAxis) { + element = ((EStructuralFeatureAxis) existingAxis).getElement(); + } else if (existingAxis instanceof EOperationAxis) { + element = ((EOperationAxis) existingAxis).getElement(); + } + browseAction(element); + } + }); + + deleteValuesButton = new Button(compositeElementReference, SWT.PUSH); + deleteValuesButton.setImage(Activator.getDefault().getImage(NattableConfigurationConstants.DELETE_ICON_PATH)); + deleteValuesButton.setToolTipText(org.eclipse.papyrus.infra.widgets.messages.Messages.ReferenceDialog_UnsetValue); + deleteValuesButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent e) { + setAxisElement(null); + } + }); + + // Create the composite element reference for the element reference (contrary to String value) + compositeElementString = new Composite(compositeElement, SWT.NONE); + compositeElementString.setLayout(new GridLayout(4, false)); + // Create the element label and the text for the string value + final Label secondElementLabel = new Label(compositeElementString, SWT.NONE); + secondElementLabel.setText(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_elementLabel); + secondElementLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + elementText = new Text(compositeElementString, SWT.BORDER); + elementText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); + elementText.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(final ModifyEvent e) { + setAxisElement(elementText.getText()); + } + }); + } + + /** + * The action executed when the "browse" button is selected Choose a value + * from a selection of already created objects + */ + protected void browseAction(final Object value) { + final ITreeSelectorDialog dialog = new TreeSelectorDialog(getShell()) { + @Override + protected void initViewerAndProvider() { + super.initViewerAndProvider(); + // Set a comparator to sort the tree viewer + getViewer().setComparator(new ViewerComparator(new StringComparator()));// should always be string element + } + }; + dialog.setTitle(org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages.TreeFillingConfigurationDialog_elementDialogName); + + final UMLFeatureRestrictedContentProvider contentProvider = new UMLFeatureRestrictedContentProvider(null, false) { + + @Override + public Object[] getChildren(final Object parentElement) { + List childrenList = Arrays.asList(super.getChildren(parentElement)); + if (parentElement instanceof EClass) { + childrenList = new ArrayList(childrenList); + final EClass eClass = (EClass) parentElement; + if (isIgnoringInheritedElements()) { + childrenList.addAll(eClass.getEOperations()); + } else { + childrenList.addAll(eClass.getEAllOperations()); + } + childrenList.remove(EcorePackage.eINSTANCE.getEModelElement_EAnnotations()); + } + return childrenList.toArray(); + } + }; + final ReferenceSelector selector = new ReferenceSelector(false) { + + @Override + public void createControls(Composite parent) { + super.createControls(parent); + this.treeViewer.setComparator(new ViewerComparator(new StringComparator()));// should always be string element + } + }; + + selector.setLabelProvider(labelProvider); + selector.setContentProvider(contentProvider); + final ITreeContentProvider treeContentProvider = new FlattenableRestrictedFilteredContentProvider((IRestrictedContentProvider) contentProvider, selector) { + + @Override + public boolean isValidValue(final Object element) { + return isTypeNeeded(element); + } + }; + + dialog.setContentProvider(treeContentProvider); + dialog.setLabelProvider(labelProvider); + if (null != value) { + dialog.setInitialElementSelections(Collections.singletonList(value)); + } + int result = dialog.open(); + if (Window.OK == result) { + Object[] newValue = dialog.getResult(); + if (null == newValue) { + return; + } + + if (0 == newValue.length) { + setAxisElement(null); + } else { + setAxisElement(newValue[0]); + } + } + } + + /** + * This allows to check if the element in dialog must be used for the axis element. + * + * @param element + * The element selected to check. + * @return true if the element can be set to the axis, false otherwise. + */ + protected boolean isTypeNeeded(final Object element) { + boolean result = false; + + final IAxis existingAxis = modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider(); + if (null != existingAxis) { + result = element != EcorePackage.eINSTANCE.getEModelElement_EAnnotations(); + + // Depending to the axis, objects displayed are not the same + if (existingAxis instanceof EObjectAxis && result) { + result = element instanceof EClass; + } else if (existingAxis instanceof EStructuralFeatureAxis && result) { + result = element instanceof EStructuralFeature; + } else if (existingAxis instanceof EOperationAxis && result) { + result = element instanceof EOperation; + } + } + + return result; + } + + /** + * This allows to set the axis and refresh the button corresponding to the axis value. + * + * @param newAxis + * The axis to set to the tree filling configuration. + */ + protected void setAxisUsedAsAxisProvider(final IAxis newAxis) { + if (null == modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider() || !modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider().equals(newAxis)) { + modifiedTreefillingConfiguration.setAxisUsedAsAxisProvider(newAxis); + } + + // This allows to refresh the composite to display for the axis element value + stackLayout.topControl = newAxis instanceof FeatureIdAxis ? compositeElementString : compositeElementReference; + compositeElement.layout(); + if (stackLayout.topControl.equals(compositeElementString)) { + elementText.setText(null != newAxis && null != newAxis.getElement() ? ((FeatureIdAxis) newAxis).getElement() : ""); //$NON-NLS-1$ + } + + setAxisElement(null != newAxis ? newAxis.getElement() : null); + } + + /** + * This allows to set the axis and refresh the button corresponding to the axis value. + * + * @param newAxis + * The axis to set to the tree filling configuration. + */ + protected void setAxisElement(final Object element) { + final IAxis existingAxis = modifiedTreefillingConfiguration.getAxisUsedAsAxisProvider(); + if (null != existingAxis) { + if (existingAxis instanceof EObjectAxis && (null == element || element instanceof EObject)) { + ((EObjectAxis) existingAxis).setElement((EObject) element); + } else if (existingAxis instanceof EStructuralFeatureAxis && (null == element || element instanceof EStructuralFeature)) { + ((EStructuralFeatureAxis) existingAxis).setElement((EStructuralFeature) element); + } else if (existingAxis instanceof EOperationAxis && (null == element || element instanceof EOperation)) { + ((EOperationAxis) existingAxis).setElement((EOperation) element); + } else if (existingAxis instanceof FeatureIdAxis && (null == element || element instanceof String)) { + ((FeatureIdAxis) existingAxis).setElement((String) element); + } + } + + // Manage the enabling and displayed composites + if (stackLayout.topControl.equals(compositeElementReference)) { + elementCLabel.setEnabled(null != existingAxis); + elementCLabel.setImage(labelProvider.getImage(element)); + elementCLabel.setText(labelProvider.getText(element)); + + browseValuesButton.setEnabled(null != existingAxis); + deleteValuesButton.setEnabled(null != existingAxis && null != element); + } + } + + /** + * Returns the modified tree filling configuration. + * + * @return The modified tree filling configuration. + */ + public TreeFillingConfiguration getModifiedTreeFillingConfiguration() { + return modifiedTreefillingConfiguration; + } +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/handlers/CreateTableConfigurationWizardHandler.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/handlers/CreateTableConfigurationWizardHandler.java deleted file mode 100644 index c7d4bc59db9..00000000000 --- a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/handlers/CreateTableConfigurationWizardHandler.java +++ /dev/null @@ -1,131 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2016 CEA LIST and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation - * - *****************************************************************************/ - -package org.eclipse.papyrus.customization.nattableconfiguration.handlers; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.internal.resources.File; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.papyrus.customization.nattableconfiguration.CreateNattableConfigurationWizard; -import org.eclipse.papyrus.customization.nattableconfiguration.utils.NattableConfigurationConstants; -import org.eclipse.papyrus.infra.nattable.handler.AbstractTableHandler; -import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.NattableaxisconfigurationFactory; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TableHeaderAxisConfiguration; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.NattableconfigurationFactory; -import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.TableConfiguration; -import org.eclipse.papyrus.infra.nattable.utils.TableEditingDomainUtils; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.handlers.HandlerUtil; - -/** - * The handler of the nattable configuration wwizard. - */ -public class CreateTableConfigurationWizardHandler extends AbstractTableHandler { - - /** - * {@inheritDoc} - * - * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) - */ - @Override - public Object execute(final ExecutionEvent event) throws ExecutionException { - - final String selectionParameter = event.getParameter("org.eclipse.papyrus.customization.nattableconfiguration.configurationParemeter"); //$NON-NLS-1$ - - Resource resourceSelected = null; - - if(null != selectionParameter && selectionParameter.equals("nattableconfiguration")){ //$NON-NLS-1$ - final ISelection currentSelection = HandlerUtil.getCurrentSelection(event); - resourceSelected = getSelectedResource(currentSelection); - } - - final TableConfiguration configuration = getEditedTableConfiguration(resourceSelected); - final CreateNattableConfigurationWizard wizard = new CreateNattableConfigurationWizard(configuration, resourceSelected); - final WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard); - dialog.open(); - return null; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.papyrus.infra.nattable.handler.AbstractTableHandler#setEnabled(java.lang.Object) - */ - @Override - public void setEnabled(final Object evaluationContext) { - super.setEnabled(evaluationContext); - setBaseEnabled(true); - } - - protected Resource getSelectedResource(final ISelection currentSelection) { - Resource resource = null; - - if (currentSelection instanceof StructuredSelection && 1 == ((StructuredSelection) currentSelection).size()) { - final Object selectedElement = ((StructuredSelection) currentSelection).getFirstElement(); - if (selectedElement instanceof File && NattableConfigurationConstants.NATTABLE_CONFIGURATION_EXTENSION_FILE.equals(((File) selectedElement).getFileExtension())) { - - INattableModelManager manager = null; - final IEditorPart currentPart = getActivePart().getSite().getPage().getActiveEditor(); - if (null != currentPart) { - manager = (INattableModelManager) currentPart.getAdapter(INattableModelManager.class); - } - - if (null != manager) { - resource = TableEditingDomainUtils.getTableEditingDomain(manager.getTable()).getResourceSet().getResource(URI.createFileURI(((File) selectedElement).getLocation().toString()), true); - } - } - } - - return resource; - } - - /** - * Get the edited table configuration. - * - * @return - * the edited table configuration. - */ - protected TableConfiguration getEditedTableConfiguration(final Resource resource) { - TableConfiguration configuration = null; - - boolean isCreation = true; - - if (null != resource) { - if (!resource.getContents().isEmpty() && resource.getContents().get(0) instanceof TableConfiguration) { - configuration = EcoreUtil.copy((TableConfiguration) resource.getContents().get(0)); - isCreation = false; - } - } - - if (isCreation) { - // 1. create the configuration itself - configuration = NattableconfigurationFactory.eINSTANCE.createTableConfiguration(); - - // 2. create the row and the column header axis configuration - final TableHeaderAxisConfiguration rowHeaderAxisConfiguration = NattableaxisconfigurationFactory.eINSTANCE.createTableHeaderAxisConfiguration(); - final TableHeaderAxisConfiguration columnHeaderAxisConfiguration = NattableaxisconfigurationFactory.eINSTANCE.createTableHeaderAxisConfiguration(); - configuration.setColumnHeaderAxisConfiguration(columnHeaderAxisConfiguration); - configuration.setRowHeaderAxisConfiguration(rowHeaderAxisConfiguration); - } - - return configuration; - } -} diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/handlers/EditExistingTableConfigurationWizardHandler.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/handlers/EditExistingTableConfigurationWizardHandler.java new file mode 100644 index 00000000000..d227167e975 --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/handlers/EditExistingTableConfigurationWizardHandler.java @@ -0,0 +1,60 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr - Initial API and implementation and Bug 49356 + *****************************************************************************/ + +package org.eclipse.papyrus.customization.nattableconfiguration.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.papyrus.customization.nattableconfiguration.wizards.EditTableConfigurationWizard; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * The handler used to edit an existing table configuration + */ +public class EditExistingTableConfigurationWizardHandler extends AbstractHandler { + + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + final EditTableConfigurationWizard wizard = new EditTableConfigurationWizard(); + ISelection selection = HandlerUtil.getCurrentSelection(event); + if (selection instanceof StructuredSelection) { + wizard.init(PlatformUI.getWorkbench(), (IStructuredSelection) selection); + final WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard); + dialog.open(); + } + return null; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.nattable.handler.AbstractTableHandler#setEnabled(java.lang.Object) + */ + @Override + public void setEnabled(final Object evaluationContext) { + super.setEnabled(evaluationContext); + setBaseEnabled(true); + } +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/EditGenericNattableConfigurationFieldsNattableWizardPage.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/EditGenericNattableConfigurationFieldsNattableWizardPage.java index d5884a115d0..29630976bac 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/EditGenericNattableConfigurationFieldsNattableWizardPage.java +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/EditGenericNattableConfigurationFieldsNattableWizardPage.java @@ -8,6 +8,7 @@ * * Contributors: * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation + * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr - Bug 493756 * *****************************************************************************/ @@ -86,8 +87,8 @@ public class EditGenericNattableConfigurationFieldsNattableWizardPage extends Ab public void createControl(final Composite parent) { setPageComplete(isPageComplete()); final Composite container = new Composite(parent, SWT.BORDER); - container.setLayout(new GridLayout(2, false)); - + container.setLayout(new GridLayout(1, false)); + container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); // Create the table group and its grid data final Group tableGroup = new Group(container, SWT.NONE); tableGroup.setLayout(new GridLayout(2, false)); diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/NattableConfigurationFileCreationPage.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/NattableConfigurationFileCreationPage.java new file mode 100644 index 00000000000..c6b2fc8a482 --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/NattableConfigurationFileCreationPage.java @@ -0,0 +1,119 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.customization.nattableconfiguration.pages; + +import org.eclipse.papyrus.customization.nattableconfiguration.helper.TableConfigurationHelper; +import org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; + +/** + * This page allows to edit the name of the Papyrus Table configuration to create + * + */ +public class NattableConfigurationFileCreationPage extends EditGenericNattableConfigurationFieldsNattableWizardPage { + /** + * The nattable configuration file name text composite. + */ + private Text nattableConfigurationFileName; + + /** + * The file name modify listener. + */ + private Listener fileNameModifyListener = new Listener() { + + @Override + public void handleEvent(final Event e) { + setPageComplete(canFlipToNextPage()); + } + }; + + /** + * Constructor. + * + * @param helper + */ + public NattableConfigurationFileCreationPage(TableConfigurationHelper helper) { + super(helper); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + @Override + public void createControl(final Composite parent) { + Composite container = new Composite(parent, SWT.BORDER); + final GridLayout gridLayout = new GridLayout(1, false); + container.setLayout(gridLayout); + container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + final Group group = createGroup(container, Messages.NattableConfigurationProjectCreationPage_nattableConfigurationFileNameLabel); + nattableConfigurationFileName = new Text(group, SWT.BORDER); + nattableConfigurationFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + nattableConfigurationFileName.addListener(SWT.Modify, fileNameModifyListener); + super.createControl(container); + setControl(container); + } + + /** + * Creates the group. + * + * @param parent + * the parent + * @param name + * the name + * @return the group + */ + private static Group createGroup(final Composite parent, final String name) { + final Group group = new Group(parent, SWT.NONE); + group.setText(name); + final GridLayout layout = new GridLayout(1, true); + layout.marginHeight = 5; + layout.marginWidth = 5; + group.setLayout(layout); + final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + group.setLayoutData(data); + return group; + } + + /** + * @see org.eclipse.papyrus.customization.nattableconfiguration.pages.EditGenericNattableConfigurationFieldsNattableWizardPage#isPageComplete() + * + * @return + */ + @Override + public boolean isPageComplete() { + if (null != nattableConfigurationFileName) { + if ("".equals(nattableConfigurationFileName.getText())) { //$NON-NLS-1$ + this.setErrorMessage("Set nattable configuration file name"); //$NON-NLS-1$ + return false; + } + } + + return super.isPageComplete(); + } + + public String getNattableConfigurationFileName() { + return nattableConfigurationFileName.getText(); + } + +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/NattableConfigurationProjectCreationPage.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/NattableConfigurationProjectCreationPage.java deleted file mode 100644 index e9fe7cb0bfc..00000000000 --- a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/NattableConfigurationProjectCreationPage.java +++ /dev/null @@ -1,150 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2016 CEA LIST and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation - * - *****************************************************************************/ - -package org.eclipse.papyrus.customization.nattableconfiguration.pages; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages; -import org.eclipse.pde.internal.ui.wizards.plugin.AbstractFieldData; -import org.eclipse.pde.internal.ui.wizards.plugin.NewProjectCreationPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Text; - -/** - * This allows to initialise the nattable configuration creation by getting the name of the plugin to create and the nattable configuration name. - */ -public class NattableConfigurationProjectCreationPage extends NewProjectCreationPage { - - /** - * The nattable configuration file name text composite. - */ - private Text nattableConfigurationFileName; - - /** - * The file name modify listener. - */ - private Listener fileNameModifyListener = new Listener() { - - @Override - public void handleEvent(final Event e) { - setPageComplete(canFlipToNextPage()); - } - }; - - /** - * Constructor. - * - * @param helper - * The table configuration helper. - */ - public NattableConfigurationProjectCreationPage(final AbstractFieldData data, final IStructuredSelection selection) { - super(Messages.NattableConfigurationProjectCreationPage_pageName, data, false, selection); - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) - */ - @Override - public void createControl(final Composite parent) { - - super.createControl(parent); - final Composite composite = (Composite) getControl(); - composite.setLayoutData(new GridData(SWT.FILL, SWT.DOWN, true, false)); - final GridLayout gridLayout = new GridLayout(1, false); - composite.setLayout(gridLayout); - setControl(composite); - final Group group = createGroup(composite, Messages.NattableConfigurationProjectCreationPage_nattableConfigurationFileNameLabel); - nattableConfigurationFileName = new Text(group, SWT.BORDER); - nattableConfigurationFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - nattableConfigurationFileName.addListener(SWT.Modify, fileNameModifyListener); - setPageComplete(false); - } - - /** - * Creates the group. - * - * @param parent - * the parent - * @param name - * the name - * @return the group - */ - private static Group createGroup(final Composite parent, final String name) { - final Group group = new Group(parent, SWT.NONE); - group.setText(name); - final GridLayout layout = new GridLayout(1, true); - layout.marginHeight = 5; - layout.marginWidth = 5; - group.setLayout(layout); - final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); - group.setLayoutData(data); - return group; - } - - @Override - protected boolean validatePage() { - if (null != nattableConfigurationFileName) { - if ("".equals(nattableConfigurationFileName.getText())) { //$NON-NLS-1$ - this.setErrorMessage("Set nattable configuration file name"); //$NON-NLS-1$ - return false; - } - } - - return super.validatePage(); - } - - public String getNattableConfigurationFileName() { - return nattableConfigurationFileName.getText(); - } - - /** - * This method is used to avoid case conflicts between existing and newly created projects - * - * @see org.eclipse.jface.wizard.WizardPage#canFlipToNextPage() - * - * @return - */ - @Override - public boolean canFlipToNextPage() { - // retrieve the selected elements and get its children - boolean canFlip = true; - - final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - if (canFlip) { - for (IProject iproject : projects) { - if (this.getProjectName().equalsIgnoreCase(iproject.getName())) { - canFlip = false; - this.setErrorMessage("There already is a project with this name: " + iproject.getName()); //$NON-NLS-1$ - // A conflict has been found, no need to go further - break; - } - } - } - - if (!validatePage()) { - canFlip = false; - } - - return canFlip; - } -} diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/RowConfigurationWizardPage.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/RowConfigurationWizardPage.java index fba5fc0a08b..9828c661c4e 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/RowConfigurationWizardPage.java +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/RowConfigurationWizardPage.java @@ -41,9 +41,9 @@ import org.eclipse.jface.viewers.TreeColumnViewerLabelProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewerColumn; import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.customization.nattableconfiguration.ediiton.FeatureFillingConfigurationDialog; -import org.eclipse.papyrus.customization.nattableconfiguration.ediiton.PasteEObjectConfigurationDialog; -import org.eclipse.papyrus.customization.nattableconfiguration.ediiton.TreeFillingConfigurationDialog; +import org.eclipse.papyrus.customization.nattableconfiguration.edition.FeatureFillingConfigurationDialog; +import org.eclipse.papyrus.customization.nattableconfiguration.edition.PasteEObjectConfigurationDialog; +import org.eclipse.papyrus.customization.nattableconfiguration.edition.TreeFillingConfigurationDialog; import org.eclipse.papyrus.customization.nattableconfiguration.helper.TableConfigurationHelper; import org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages; import org.eclipse.papyrus.customization.nattableconfiguration.utils.NameSimplifier; diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/SlaveConfigurationWizardPage.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/SlaveConfigurationWizardPage.java index 360cf0f6b39..b14e7d8a584 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/SlaveConfigurationWizardPage.java +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/pages/SlaveConfigurationWizardPage.java @@ -681,8 +681,8 @@ public class SlaveConfigurationWizardPage extends AbstractTableConfigurationWiza protected SlaveObjectAxisProvider getSlaveObjectAxisProvider(final TableConfiguration configuration) { SlaveObjectAxisProvider slave = null; - // Try to get an existing master axis provider - if (0 < configuration.getRowAxisProviders().size()) { + // Try to get an existing slave axis provider + if (0 < configuration.getColumnAxisProviders().size()) { final Iterator columnAxisProvidersIterator = configuration.getColumnAxisProviders().iterator(); while (columnAxisProvidersIterator.hasNext() && null == slave) { AbstractAxisProvider axisProvider = columnAxisProvidersIterator.next(); @@ -705,13 +705,13 @@ public class SlaveConfigurationWizardPage extends AbstractTableConfigurationWiza protected SlaveObjectAxisProvider getOrCreateSlaveObjectAxisProvider(final TableConfiguration configuration) { SlaveObjectAxisProvider slave = getSlaveObjectAxisProvider(configuration); - // The master doesn't exist, create it + // The slave doesn't exist, create it if (null == slave) { slave = NattableaxisproviderFactory.eINSTANCE.createSlaveObjectAxisProvider(); configuration.getColumnAxisProviders().add(slave); } - // Set the master as default row axis provider if this is not already done + // Set the slave as default row axis provider if this is not already done if (null == configuration.getDefaultColumnAxisProvider()) { configuration.setDefaultColumnAxisProvider(slave); } diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/utils/NattableConfigurationConstants.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/utils/NattableConfigurationConstants.java index c1257afc4cb..aaa7c6e7961 100644 --- a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/utils/NattableConfigurationConstants.java +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/utils/NattableConfigurationConstants.java @@ -28,7 +28,7 @@ public class NattableConfigurationConstants { /** * The extension for the nattable configuration file. */ - public static final String NATTABLE_CONFIGURATION_EXTENSION_FILE = "nattableconfiguration"; //$NON-NLS-1$ + public static final String NATTABLE_CONFIGURATION_EXTENSION_FILE = org.eclipse.papyrus.infra.nattable.utils.NattableConfigurationConstants.NATTABLE_CONFIGURATION_EXTENSION_FILE; /** * The config folder path. diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/wizards/CreateAndEditTableConfigurationWizard.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/wizards/CreateAndEditTableConfigurationWizard.java new file mode 100644 index 00000000000..41f87ff6888 --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/wizards/CreateAndEditTableConfigurationWizard.java @@ -0,0 +1,181 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.customization.nattableconfiguration.wizards; + +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.papyrus.customization.nattableconfiguration.Activator; +import org.eclipse.papyrus.customization.nattableconfiguration.pages.NattableConfigurationFileCreationPage; +import org.eclipse.papyrus.customization.nattableconfiguration.utils.NattableConfigurationConstants; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.NattableaxisconfigurationFactory; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.TableHeaderAxisConfiguration; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.NattableconfigurationFactory; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.TableConfiguration; +import org.eclipse.papyrus.infra.tools.util.FileUtils; +import org.eclipse.ui.IWorkbench; + +/** + * The wizard used to create and edit a Papyrus Table configuration in an existing project + * + */ +public class CreateAndEditTableConfigurationWizard extends EditTableConfigurationWizard { + + /** + * the page used to create the table configuration + */ + private NattableConfigurationFileCreationPage page = null; + + /** + * the initial selection done by the used on which the wizard has been called + */ + private Object firstSelectedElement; + + /** + * + * @see org.eclipse.papyrus.customization.nattableconfiguration.wizards.EditTableConfigurationWizard#addEditNattableConfigurationPage() + * + */ + protected void addEditNattableConfigurationPage() { + addPage(this.page = new NattableConfigurationFileCreationPage(this.helper)); + } + + /** + * Get the edited table configuration. + * + * @return + * the edited table configuration. + */ + protected TableConfiguration getEditedTableConfiguration(final Resource resource) { + // 1. create the configuration itself + TableConfiguration configuration = NattableconfigurationFactory.eINSTANCE.createTableConfiguration(); + + // 2. create the row and the column header axis configuration + final TableHeaderAxisConfiguration rowHeaderAxisConfiguration = NattableaxisconfigurationFactory.eINSTANCE.createTableHeaderAxisConfiguration(); + final TableHeaderAxisConfiguration columnHeaderAxisConfiguration = NattableaxisconfigurationFactory.eINSTANCE.createTableHeaderAxisConfiguration(); + configuration.setColumnHeaderAxisConfiguration(columnHeaderAxisConfiguration); + configuration.setRowHeaderAxisConfiguration(rowHeaderAxisConfiguration); + return configuration; + } + + /** + * @see org.eclipse.papyrus.customization.nattableconfiguration.wizards.EditTableConfigurationWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) + * + * @param workbench + * @param selection + */ + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + super.init(workbench, selection); + if (selection instanceof StructuredSelection) { + this.firstSelectedElement = selection.getFirstElement(); + } + } + + /** + * @see org.eclipse.papyrus.customization.nattableconfiguration.wizards.EditTableConfigurationWizard#performFinish() + * + * @return + */ + @Override + public boolean performFinish() { + StringBuilder nattableConfigurationFileName = new StringBuilder(this.page.getNattableConfigurationFileName()); + + // Check if the file has the nattable configuration extension file, else add it + + if (!nattableConfigurationFileName.toString().contains(FileUtils.DOT_STRING) + || !NattableConfigurationConstants.NATTABLE_CONFIGURATION_EXTENSION_FILE.equals(nattableConfigurationFileName.toString().substring(nattableConfigurationFileName.lastIndexOf(FileUtils.DOT_STRING) + 1))) { + nattableConfigurationFileName.append(FileUtils.DOT_STRING); + nattableConfigurationFileName.append(NattableConfigurationConstants.NATTABLE_CONFIGURATION_EXTENSION_FILE); + } + + final ResourceSet set = new ResourceSetImpl(); + final StringBuilder nattableConfFileURI = new StringBuilder(); + nattableConfFileURI.append(getPathForTableConfigurationCreation()); + nattableConfFileURI.append(nattableConfigurationFileName); + this.initialResource = set.createResource(URI.createFileURI(nattableConfFileURI.toString())); + // the configuration is added into the resource in the super class + // initialResource.getContents().add(configuration); + boolean result = super.performFinish(); + refreshProject(); + return result; + } + + /** + * + * @return + * the location to use to create the new Papyrus Table Configuration. + * The location will be the folder selected by the user or for others selections, a folfer called {@link NattableConfigurationConstants#CONFIG_FOLDER} in others cases + */ + protected String getPathForTableConfigurationCreation() { + String location = null; + if (this.firstSelectedElement instanceof IFolder) { + String projectLocation = ((IFolder) this.firstSelectedElement).getLocation().toString(); + StringBuilder builder = new StringBuilder(projectLocation); + builder.append(FileUtils.SLASH_STRING); + location = builder.toString(); + } else if (this.firstSelectedElement instanceof IResource) { + String projectLocation = getProjectLocation(); + StringBuilder builder = new StringBuilder(projectLocation); + builder.append(NattableConfigurationConstants.CONFIG_FOLDER); + location = builder.toString(); + } + return location; + } + + /** + * This method allows to refresh the project (required to display the created table configuration) + */ + protected final void refreshProject() { + try { + getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); + } catch (CoreException e) { + Activator.log.error(e); + } + } + + /** + * + * @return + * the project in which is created the table configuration + */ + protected IProject getProject() { + IProject project = null; + if (this.firstSelectedElement instanceof org.eclipse.core.internal.resources.Resource) { + project = ((org.eclipse.core.internal.resources.Resource) firstSelectedElement).getProject(); + } + return project; + } + + /** + * + * @return + * the location of the project + */ + protected String getProjectLocation() { + IProject project = getProject(); + if (null != project) { + return project.getLocation().toString(); + } + return null; + } +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/wizards/CreateNattableConfigurationProjectWizard.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/wizards/CreateNattableConfigurationProjectWizard.java new file mode 100644 index 00000000000..b4380c784d5 --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/wizards/CreateNattableConfigurationProjectWizard.java @@ -0,0 +1,223 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation + * Vincent LORENZO (CEA-LIST) vincent.lorenzo@cea.fr - Bug 493756 + *****************************************************************************/ + +package org.eclipse.papyrus.customization.nattableconfiguration.wizards; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.papyrus.customization.nattableconfiguration.Activator; +import org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages; +import org.eclipse.papyrus.customization.nattableconfiguration.utils.NattableConfigurationConstants; +import org.eclipse.pde.internal.ui.wizards.IProjectProvider; +import org.eclipse.pde.internal.ui.wizards.plugin.NewProjectCreationOperation; +import org.eclipse.pde.internal.ui.wizards.plugin.NewProjectCreationPage; +import org.eclipse.pde.internal.ui.wizards.plugin.PluginContentPage; +import org.eclipse.pde.internal.ui.wizards.plugin.PluginFieldData; +import org.eclipse.ui.IWorkbenchWizard; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.PlatformUI; + +/** + * The wizard used to create a Papyrus Table Configuration Project + */ +public class CreateNattableConfigurationProjectWizard extends CreateAndEditTableConfigurationWizard implements IWorkbenchWizard { + + + /** + * The page for the project creation. + */ + private NewProjectCreationPage nattableConfigurationProjectCreationPage; + + /** + * The project provider. + */ + private IProjectProvider projectProvider; + + /** + * The content page for the project creation. + */ + protected PluginContentPage contentPage; + + /** + * The fields data to manage the project creation + */ + private PluginFieldData pluginData; + + /** + * @see org.eclipse.papyrus.customization.nattableconfiguration.EditTableConfigurationWizard#addPages() + * + */ + @Override + public void addPages() { + pluginData = new PluginFieldData(); + + nattableConfigurationProjectCreationPage = new NewProjectCreationPage(Messages.NattableConfigurationProjectCreationPage_pageName, pluginData, false,new StructuredSelection()); + addPage(nattableConfigurationProjectCreationPage); + + projectProvider = new IProjectProvider() { + @Override + public String getProjectName() { + return nattableConfigurationProjectCreationPage.getProjectName(); + } + + @Override + public IProject getProject() { + return nattableConfigurationProjectCreationPage.getProjectHandle(); + } + + @Override + public IPath getLocationPath() { + return nattableConfigurationProjectCreationPage.getLocationPath(); + } + }; + + contentPage = new PluginContentPage("page2", projectProvider, nattableConfigurationProjectCreationPage, pluginData); //$NON-NLS-1$ + + addPage(contentPage); + super.addPages(); + } + + + + + /** + * @see org.eclipse.papyrus.customization.nattableconfiguration.EditTableConfigurationWizard#performFinish() + * + * @return + */ + @Override + public boolean performFinish() { + boolean result = false; + + IProject createdProject = null; + + try { + + // Create the project + getContainer().run(false, true, new NewProjectCreationOperation(pluginData, projectProvider, null)); + + createdProject = getProject(); + + // Set the project into the working sets + final IWorkingSet[] workingSets = nattableConfigurationProjectCreationPage.getSelectedWorkingSets(); + if (0 < workingSets.length) { + PlatformUI.getWorkbench().getWorkingSetManager().addToWorkingSets(createdProject, workingSets); + } + + // Copy the about file + copyAboutFile(createdProject); + result = super.performFinish(); + } catch (final InvocationTargetException e) { + Activator.log.error(e); + } catch (final InterruptedException e) { + Activator.log.error(e); + } + + if (result) { + result = saveResource(); + } + refreshProject(); + return result; + } + + /** + * This allows to get the project created folder. + * {@inheritDoc} + * + * @see org.eclipse.papyrus.customization.nattableconfiguration.wizards.CreateAndEditTableConfigurationWizard#getPathForTableConfigurationCreation() + */ + @Override + protected String getPathForTableConfigurationCreation() { + final String projectLocation = getProjectLocation(); + final StringBuilder builder = new StringBuilder(projectLocation); + builder.append(NattableConfigurationConstants.CONFIG_FOLDER); + + return builder.toString(); + } + + /** + * This allows to copy the about file in the created project. + * + * @param createdProject + * The created project. + */ + protected void copyAboutFile(final IProject createdProject) { + InputStream inputStream = null; + OutputStream outputStream = null; + try { + final URL url = Activator.getDefault().getBundle().getResource(NattableConfigurationConstants.ABOUT_FILE_NAME); + inputStream = url.openStream(); + + final java.io.File newAboutFile = new java.io.File(createdProject.getLocation().toOSString() + java.io.File.separator + NattableConfigurationConstants.ABOUT_FILE_NAME); + newAboutFile.createNewFile(); + + outputStream = new FileOutputStream(newAboutFile); + + int read = 0; + byte[] bytes = new byte[1024]; + + while ((read = inputStream.read(bytes)) != -1) { + outputStream.write(bytes, 0, read); + } + } catch (final IOException e) { + Activator.log.error(e); + } finally { + if (null != inputStream) { + try { + inputStream.close(); + } catch (final IOException e) { + Activator.log.error(e); + } + } + if (null != outputStream) { + try { + // outputStream.flush(); + outputStream.close(); + } catch (final IOException e) { + Activator.log.error(e); + } + + } + } + } + + + /** + * @see org.eclipse.papyrus.customization.nattableconfiguration.wizards.CreateAndEditTableConfigurationWizard#getProject() + * + * @return + */ + @Override + protected IProject getProject() { + return this.projectProvider.getProject(); + } + + /** + * @see org.eclipse.papyrus.customization.nattableconfiguration.wizards.CreateAndEditTableConfigurationWizard#getProjectLocation() + * + * @return + */ + @Override + protected String getProjectLocation() { + IProject createdProject = getProject(); + return createdProject.getLocation().toString(); + } +} diff --git a/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/wizards/EditTableConfigurationWizard.java b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/wizards/EditTableConfigurationWizard.java new file mode 100644 index 00000000000..3bd3bf34759 --- /dev/null +++ b/plugins/customization/org.eclipse.papyrus.customization.nattableconfiguration/src/org/eclipse/papyrus/customization/nattableconfiguration/wizards/EditTableConfigurationWizard.java @@ -0,0 +1,231 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.customization.nattableconfiguration.wizards; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.internal.resources.File; +import org.eclipse.core.runtime.Assert; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.jface.dialogs.DialogSettings; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.papyrus.customization.nattableconfiguration.Activator; +import org.eclipse.papyrus.customization.nattableconfiguration.helper.TableConfigurationHelper; +import org.eclipse.papyrus.customization.nattableconfiguration.messages.Messages; +import org.eclipse.papyrus.customization.nattableconfiguration.pages.ColumnConfigurationWizardPage; +import org.eclipse.papyrus.customization.nattableconfiguration.pages.EditGenericNattableConfigurationFieldsNattableWizardPage; +import org.eclipse.papyrus.customization.nattableconfiguration.pages.RowConfigurationWizardPage; +import org.eclipse.papyrus.customization.nattableconfiguration.pages.SlaveConfigurationWizardPage; +import org.eclipse.papyrus.customization.nattableconfiguration.utils.NattableConfigurationConstants; +import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.TableConfiguration; +import org.eclipse.papyrus.infra.nattable.utils.TableEditingDomainUtils; +import org.eclipse.papyrus.infra.nattable.wizard.AbstractTableWizard; +import org.eclipse.papyrus.infra.ui.util.WorkbenchPartHelper; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWizard; + +/** + * The wizard to edit an existing TableConfiguration file + */ +public class EditTableConfigurationWizard extends AbstractTableWizard implements IWorkbenchWizard { + + /** + * The generate plugin activator setting. + */ + private static final String GENERATE_PlUGIN_ACTIVATOR = "generatePluginActivator"; //$NON-NLS-1$ + + /** + * The ui plugin setting. + */ + private static final String UI_PLUGIN = "uiPlugin"; //$NON-NLS-1$ + + /** + * The edited table configuration + */ + protected TableConfiguration configuration; + + /** + * The initial resource selected. + */ + protected Resource initialResource; + + /** + * the edited Table Configuration Helper; + */ + protected TableConfigurationHelper helper; + + + /** + * + * Constructor. + * + * Thi sconstructor is used when we create a new Papyrus Table Configuration Poject from the wizard Dialog + * + */ + public EditTableConfigurationWizard() { + final ImageDescriptor desc = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImageDescriptor(Activator.PLUGIN_ID, NattableConfigurationConstants.ICON_WIZBAN_PATH); + setDefaultPageImageDescriptor(desc); + setWindowTitle(Messages.CreateNattableConfigurationWizard_WizardTitke); + setForcePreviousAndNextButtons(true); + } + + /** + * @see org.eclipse.papyrus.infra.nattable.wizard.AbstractTableWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) + * + * @param workbench + * @param selection + */ + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + super.init(workbench, selection); + this.initialResource = getSelectedResource(selection); + this.configuration = getEditedTableConfiguration(this.initialResource); + Assert.isNotNull(this.configuration); + this.helper = new TableConfigurationHelper(configuration); + } + + /** + * + * @param currentSelection + * the current selection + * @return + * the resource if it already exist or null; + */ + protected Resource getSelectedResource(final ISelection currentSelection) { + Resource resource = null; + + if (currentSelection instanceof StructuredSelection && 1 == ((StructuredSelection) currentSelection).size()) { + final Object selectedElement = ((StructuredSelection) currentSelection).getFirstElement(); + if (selectedElement instanceof File && NattableConfigurationConstants.NATTABLE_CONFIGURATION_EXTENSION_FILE.equals(((File) selectedElement).getFileExtension())) { + + INattableModelManager manager = null; + // TODO required ? + final IEditorPart currentPart = WorkbenchPartHelper.getCurrentActiveWorkbenchPart().getSite().getPage().getActiveEditor(); + if (null != currentPart) { + manager = (INattableModelManager) currentPart.getAdapter(INattableModelManager.class); + } + + if (null != manager) { + resource = TableEditingDomainUtils.getTableEditingDomain(manager.getTable()).getResourceSet().getResource(URI.createFileURI(((File) selectedElement).getLocation().toString()), true); + } else { + final ResourceSet set = new ResourceSetImpl(); + resource = set.getResource(URI.createFileURI(((File) selectedElement).getLocation().toString()), true); + } + } + } + + return resource; + } + + /** + * Get the edited table configuration. + * + * @return + * the edited table configuration. + */ + protected TableConfiguration getEditedTableConfiguration(final Resource resource) { + TableConfiguration configuration = null; + if (null != resource) { + if (!resource.getContents().isEmpty() && resource.getContents().get(0) instanceof TableConfiguration) { + configuration = EcoreUtil.copy((TableConfiguration) resource.getContents().get(0)); + } + } + return configuration; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.wizard.Wizard#addPages() + */ + @Override + public void addPages() { + addEditNattableConfigurationPage(); + addPage(new RowConfigurationWizardPage(this.helper)); + addPage(new ColumnConfigurationWizardPage(this.helper)); + addPage(new SlaveConfigurationWizardPage(this.helper)); + } + + protected void addEditNattableConfigurationPage(){ + addPage(new EditGenericNattableConfigurationFieldsNattableWizardPage(this.helper)); + } + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.wizard.Wizard#getDialogSettings() + */ + @Override + public IDialogSettings getDialogSettings() { + DialogSettings dialogSettings = new DialogSettings(""); //$NON-NLS-1$ + dialogSettings.put(GENERATE_PlUGIN_ACTIVATOR, true); + dialogSettings.put(UI_PLUGIN, false); + return dialogSettings; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.wizard.Wizard#performFinish() + */ + @Override + public boolean performFinish() { + + boolean result = false; + + // The resource is modified directly without command (undo/redo impossible) + // Save DiagramDialog at proper position + if (null != this.initialResource) { + this.initialResource.getContents().clear(); + this.initialResource.getContents().add(this.configuration); + result = true; + } + if (result) { + result = saveResource(); + } + + return result; + } + + /** + * + * @return + * true if the resource has been properly saved + */ + protected final boolean saveResource() { + boolean result = true; + final Map saveOptions = new HashMap(); + saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER); + saveOptions.put(Resource.OPTION_LINE_DELIMITER, Resource.OPTION_LINE_DELIMITER_UNSPECIFIED); + + try { + initialResource.save(saveOptions); + } catch (final IOException e) { + Activator.log.error(e); + result = false; + } + return result; + } +} diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NattableConfigurationConstants.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NattableConfigurationConstants.java new file mode 100644 index 00000000000..37c2559be2c --- /dev/null +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/utils/NattableConfigurationConstants.java @@ -0,0 +1,26 @@ +/***************************************************************************** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.nattable.utils; + +/** + * @author VL222926 + * + */ +public class NattableConfigurationConstants { + + /** + * The extension for the nattable configuration file. + */ + public static final String NATTABLE_CONFIGURATION_EXTENSION_FILE = "nattableconfiguration"; //$NON-NLS-1$ +} -- cgit v1.2.3