diff options
author | Nicolas FAUVERGUE | 2016-11-24 11:20:54 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-11-29 10:57:50 +0000 |
commit | b3141df23ca644573f8b2813ad8859722d418bd9 (patch) | |
tree | 6db261c6f918988a7117bfe93731af4ca17f0723 /plugins | |
parent | 6d4f41d7e479bfa607ffde18b16fe8ebdae561c2 (diff) | |
download | org.eclipse.papyrus-b3141df23ca644573f8b2813ad8859722d418bd9.tar.gz org.eclipse.papyrus-b3141df23ca644573f8b2813ad8859722d418bd9.tar.xz org.eclipse.papyrus-b3141df23ca644573f8b2813ad8859722d418bd9.zip |
Bug 496905: [Diagram][ModelExplorer][Table][Dialog] Papyrus must integrate
the internationalization feature provided by UML.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=496905
Commit of infra for internationalization.
Change-Id: I1b1859bf111e1ef7a7522212fbe639cf2bd13890
Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@all4tec.net>
Diffstat (limited to 'plugins')
203 files changed, 15925 insertions, 1493 deletions
diff --git a/plugins/editor/org.eclipse.papyrus.editor/META-INF/MANIFEST.MF b/plugins/editor/org.eclipse.papyrus.editor/META-INF/MANIFEST.MF index 72779849904..74335c6544c 100644 --- a/plugins/editor/org.eclipse.papyrus.editor/META-INF/MANIFEST.MF +++ b/plugins/editor/org.eclipse.papyrus.editor/META-INF/MANIFEST.MF @@ -2,7 +2,8 @@ Manifest-Version: 1.0 Export-Package: org.eclipse.papyrus.editor Require-Bundle: org.eclipse.gmf.runtime.diagram.ui;bundle-version="[1.8.0,2.0.0)", org.eclipse.papyrus.infra.ui;bundle-version="[2.0.0,3.0.0)";visibility:=reexport, - org.eclipse.papyrus.infra.emf;bundle-version="[2.0.0,3.0.0)" + org.eclipse.papyrus.infra.emf;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.infra.internationalization.utils;bundle-version="[1.0.0,2.0.0)" Bundle-Vendor: %providerName Bundle-ActivationPolicy: lazy Bundle-Version: 2.0.0.qualifier diff --git a/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/commands/RenameNestedEditorCommand.java b/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/commands/RenameNestedEditorCommand.java index 2f963b10320..ed198c75175 100644 --- a/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/commands/RenameNestedEditorCommand.java +++ b/plugins/editor/org.eclipse.papyrus.editor/src/org/eclipse/papyrus/editor/commands/RenameNestedEditorCommand.java @@ -1,124 +1,144 @@ -/**
- *
- */
-package org.eclipse.papyrus.editor.commands;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.editor.Activator;
-import org.eclipse.papyrus.infra.core.sasheditor.internal.SashWindowsContainer;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorPart;
-
-/**
- * A command to be used with the Eclipse Commands Framework.
- * This command is to be used with {@link SashWindowsContainer} implemented with the Di model.
- * This command allows to rename a nested editor.
- *
- * This command use a Transaction.
- * TODO Move to gmf adapter.
- *
- * @author cedric dumoulin
- *
- */
-public class RenameNestedEditorCommand extends AbstractHandler {
-
- /**
- * Check if the Command is enabled.
- */
- @Override
- public void setEnabled(Object evaluationContext) {
- // System.out.println("call to CloseDiagramCommand.setEnable(" + evaluationContext + ")");
- }
-
- /**
- * Execute the command. This method is called when the action is triggered.
- *
- */
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
-
- // try {
- // IEditorPart part = HandlerUtil.getActiveEditor(event);
- // IPageMngr pageMngr = (IPageMngr)part.getAdapter(IPageMngr.class);
- // ISashWindowsContainer container = (ISashWindowsContainer)part.getAdapter(ISashWindowsContainer.class);
- // IPage sashPage = container.getActiveSashWindowsPage();
- //
- // if(sashPage instanceof IEditorPage )
- // {
- // IEditorPage editorPage = (IEditorPage)sashPage;
- // execute(editorPage.getRawModel(), editorPage.getIEditorPart());
- // }
- // // Bug from sash Di to be corrected
- // if(pageIdentifier instanceof PageRef)
- // {
- // pageIdentifier = ((PageRef)pageIdentifier).getPageIdentifier();
- // }
- // execute(sashPage.getRawModel(), sashPage.);
- //
- // } catch (NullPointerException e) {
- // // PageMngr can't be found
- // return null;
- // }
-
-
-
- return null;
- }
-
- /**
- * Close selected page.
- *
- * @param pageMngr
- */
- public void execute(final Diagram diagram, final IEditorPart editorPart) {
- TransactionalEditingDomain editingDomain = null;
-
- if (editorPart instanceof IAdaptable) {
- ServicesRegistry registry = (ServicesRegistry) ((IAdaptable) editorPart).getAdapter(ServicesRegistry.class);
-
- if (registry == null) {
- editingDomain = (TransactionalEditingDomain) ((IAdaptable) editorPart).getAdapter(TransactionalEditingDomain.class);
- } else {
- try {
- editingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(registry);
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- }
- }
- }
-
-
- if (editingDomain != null) {
- InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), "Rename an existing diagram", "New name:", diagram.getName(), null);
- if (dialog.open() == Window.OK) {
- final String name = dialog.getValue();
- if (name != null && name.length() > 0) {
-
- Command command = new RecordingCommand(editingDomain) {
-
-
- @Override
- protected void doExecute() {
- diagram.setName(name);
- }
- };
-
- editingDomain.getCommandStack().execute(command);
- }
- }
- }
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2016 CEA LIST, Christian W. Damus, and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * + *****************************************************************************/ +package org.eclipse.papyrus.editor.commands; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.editor.Activator; +import org.eclipse.papyrus.infra.core.sasheditor.internal.SashWindowsContainer; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.core.services.ServicesRegistry; +import org.eclipse.papyrus.infra.core.utils.ServiceUtils; +import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalization; +import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalizationUtils; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IEditorPart; + +/** + * A command to be used with the Eclipse Commands Framework. + * This command is to be used with {@link SashWindowsContainer} implemented with the Di model. + * This command allows to rename a nested editor. + * + * This command use a Transaction. + * TODO Move to gmf adapter. + * + * @author cedric dumoulin + * + */ +public class RenameNestedEditorCommand extends AbstractHandler { + + /** + * Check if the Command is enabled. + */ + @Override + public void setEnabled(Object evaluationContext) { + // System.out.println("call to CloseDiagramCommand.setEnable(" + evaluationContext + ")"); + } + + /** + * Execute the command. This method is called when the action is triggered. + * + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + // try { + // IEditorPart part = HandlerUtil.getActiveEditor(event); + // IPageMngr pageMngr = (IPageMngr)part.getAdapter(IPageMngr.class); + // ISashWindowsContainer container = (ISashWindowsContainer)part.getAdapter(ISashWindowsContainer.class); + // IPage sashPage = container.getActiveSashWindowsPage(); + // + // if(sashPage instanceof IEditorPage ) + // { + // IEditorPage editorPage = (IEditorPage)sashPage; + // execute(editorPage.getRawModel(), editorPage.getIEditorPart()); + // } + // // Bug from sash Di to be corrected + // if(pageIdentifier instanceof PageRef) + // { + // pageIdentifier = ((PageRef)pageIdentifier).getPageIdentifier(); + // } + // execute(sashPage.getRawModel(), sashPage.); + // + // } catch (NullPointerException e) { + // // PageMngr can't be found + // return null; + // } + + + + return null; + } + + /** + * Close selected page. + * + * @param pageMngr + */ + public void execute(final Diagram diagram, final IEditorPart editorPart) { + TransactionalEditingDomain editingDomain = null; + + if (editorPart instanceof IAdaptable) { + ServicesRegistry registry = (ServicesRegistry) ((IAdaptable) editorPart).getAdapter(ServicesRegistry.class); + + if (registry == null) { + editingDomain = (TransactionalEditingDomain) ((IAdaptable) editorPart).getAdapter(TransactionalEditingDomain.class); + } else { + try { + editingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(registry); + } catch (ServiceException ex) { + Activator.log.error(ex); + } + } + } + + if (editingDomain != null) { + // If the diagram label is available, modify this one. + final String diagramLabel = LabelInternationalization.getInstance().getDiagramLabelWithoutName(diagram); + if(null != diagramLabel){ + InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), "Rename diagram label", "New label:", diagramLabel, null); //$NON-NLS-1$ //$NON-NLS-2$ + if (Window.OK == dialog.open()) { + final String label = dialog.getValue(); + editingDomain.getCommandStack().execute(LabelInternationalization.getInstance().getSetDiagramLabelCommand(editingDomain, diagram, label, null)); + } + }else{ + InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), "Rename an existing diagram", "New name:", diagram.getName(), null); //$NON-NLS-1$ //$NON-NLS-2$ + if (dialog.open() == Window.OK) { + final String name = dialog.getValue(); + if (name != null && name.length() > 0) { + + Command command = new RecordingCommand(editingDomain) { + + + @Override + protected void doExecute() { + diagram.setName(name); + } + }; + + editingDomain.getCommandStack().execute(command); + } + } + } + } + } + +} diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/META-INF/MANIFEST.MF b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/META-INF/MANIFEST.MF index 95629903d82..ebb63f5503d 100644 --- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/META-INF/MANIFEST.MF +++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/META-INF/MANIFEST.MF @@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.papyrus.emf.facet.custom.core;bundle-version="[2.0.0 org.eclipse.emf.edit.ui;bundle-version="[2.12.0,3.0.0)", org.eclipse.papyrus.emf.facet.util.swt;bundle-version="[1.2.0,2.0.0)", org.eclipse.papyrus.emf.facet.util.jface.ui;bundle-version="[1.2.0,2.0.0)", - org.eclipse.papyrus.emf.facet.common.ui;bundle-version="[1.2.0,2.0.0)" + org.eclipse.papyrus.emf.facet.common.ui;bundle-version="[1.2.0,2.0.0)", + org.eclipse.papyrus.infra.internationalization.edit;bundle-version="[1.0.0,2.0.0)" Bundle-Vendor: %Bundle-Vendor Bundle-ActivationPolicy: lazy Bundle-Version: 2.0.0.qualifier diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/query/LabelQuery.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/query/LabelQuery.java index 9961cae90ec..156d2ceab6a 100644 --- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/query/LabelQuery.java +++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/query/LabelQuery.java @@ -1,141 +1,144 @@ -/**
- * Copyright (c) 2011, 2014 Mia-Software, CEA, 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:
- * Gregoire Dupe (Mia-Software) - Bug 361794 - [Restructuring] EMF Facet customization meta-model
- * Gregoire Dupe (Mia-Software) - Bug 369987 - [Restructuring][Table] Switch to the new customization and facet framework
- * Gregoire Dupe (Mia-Software) - Bug 373078 - API Cleaning
- * Gregoire Dupe (Mia-Software) - Bug 375087 - [Table] ITableWidget.addColumn(List<ETypedElement>, List<FacetSet>)
- * Nicolas Bros (Mia-Software) - Bug 379683 - customizable Tree content provider
- * Christian W. Damus (CEA) - bug 410346
- */
-package org.eclipse.papyrus.emf.facet.custom.ui.internal.query;
-
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.ETypedElement;
-import org.eclipse.emf.ecore.util.FeatureMap;
-import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
-import org.eclipse.emf.edit.provider.IItemLabelProvider;
-import org.eclipse.emf.edit.provider.ReflectiveItemProvider;
-import org.eclipse.papyrus.emf.facet.efacet.core.IFacetManager;
-import org.eclipse.papyrus.emf.facet.efacet.core.exception.DerivedTypedElementException;
-import org.eclipse.papyrus.emf.facet.query.java.core.IJavaQuery2;
-import org.eclipse.papyrus.emf.facet.query.java.core.IParameterValueList2;
-import org.eclipse.papyrus.emf.facet.util.emf.core.ModelUtils;
-
-public class LabelQuery implements IJavaQuery2<EObject, String> {
-
- private static final String NAME = "name"; //$NON-NLS-1$
-
- public String evaluate(final EObject source,
- final IParameterValueList2 parameterValues,
- final IFacetManager facetManager)
- throws DerivedTypedElementException {
- ETypedElement sfParam = null;
- if (parameterValues != null) {
- sfParam = (ETypedElement) parameterValues
- .getParameterValueByName("eStructuralFeature").getValue(); //$NON-NLS-1$
- }
- String result = null;
- if (sfParam == null) {
- final ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(
- ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
-
- try {
- final IItemLabelProvider itemLabelProvider = (IItemLabelProvider) adapterFactory.adapt(source, IItemLabelProvider.class);
- // We don't want to use a ReflectiveItemProvider because it provides
- // a string prefixed with the eObject's meta-class name.
- if (itemLabelProvider instanceof ReflectiveItemProvider) {
- result = LabelQuery.getDefaultName(source);
- } else if (itemLabelProvider == null) {
- result = ModelUtils.getDefaultName(source);
- } else {
- result = itemLabelProvider.getText(source);
- }
- } finally {
- // Dispose the adapter factory because it added an adapter that would leak, as nobody else will ever use it
- adapterFactory.dispose();
- }
- } else {
- try {
- if (sfParam instanceof EAttribute && sfParam.getUpperBound() == 1) {
- final Object object = facetManager.getOrInvoke(source, sfParam, Object.class);
- final String objectLabel = getObjectLabel(object, facetManager);
- result = sfParam.getName() + " = " + objectLabel; //$NON-NLS-1$
- } else {
- result = sfParam.getName();
- }
- } catch (final Exception e) {
- throw new DerivedTypedElementException(e);
- }
- }
- return result;
- }
-
- private String getObjectLabel(final Object object,
- final IFacetManager facetManager)
- throws DerivedTypedElementException {
- String result;
- if (object instanceof EObject) {
- final EObject eObject = (EObject) object;
- result = evaluate(eObject, null, facetManager);
- } else {
- result = String.valueOf(object);
- }
- return result;
- }
-
- /**
- * @return a default name based on a string feature of the given {@link EObject}
- */
- // from org.eclipse.papyrus.emf.facet.infra.common.core.internal.utils.ModelUtils
- public static String getDefaultName(final EObject eObject) {
- String result = ""; //$NON-NLS-1$
- // find a feature that can be used as a name
- final EStructuralFeature feature = LabelQuery.getLabelFeature(eObject
- .eClass());
- if (feature != null) {
- result = (String) eObject.eGet(feature);
- }
- return result;
- }
-
- /**
- * This method searches for a structural feature that can be used as a name
- *
- * @param eClass
- * in which class to search a structural feature that can be used as
- * a name
- * @return an EStructuralFeature
- */
- // Copied from org.eclipse.emf.edit.provider.ReflectiveItemProvider to org.eclipse.papyrus.emf.facet.infra.common.core.internal.utils.ModelUtils
- // Copied from org.eclipse.papyrus.emf.facet.infra.common.core.internal.utils.ModelUtils
- private static EStructuralFeature getLabelFeature(final EClass eClass) {
- EAttribute result = null;
- for (final EAttribute eAttribute : eClass.getEAllAttributes()) {
- if (!eAttribute.isMany()
- && eAttribute.getEType().getInstanceClass() != FeatureMap.Entry.class) {
- if (LabelQuery.NAME.equalsIgnoreCase(eAttribute
- .getName())) {
- result = eAttribute;
- break;
- } else if (result == null) {
- result = eAttribute;
- } else if (eAttribute.getEAttributeType().getInstanceClass() == String.class
- && result.getEAttributeType().getInstanceClass() != String.class) {
- result = eAttribute;
- }
- }
- }
- return result;
- }
-
-}
+/** + * Copyright (c) 2011, 2014 Mia-Software, CEA, 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: + * Gregoire Dupe (Mia-Software) - Bug 361794 - [Restructuring] EMF Facet customization meta-model + * Gregoire Dupe (Mia-Software) - Bug 369987 - [Restructuring][Table] Switch to the new customization and facet framework + * Gregoire Dupe (Mia-Software) - Bug 373078 - API Cleaning + * Gregoire Dupe (Mia-Software) - Bug 375087 - [Table] ITableWidget.addColumn(List<ETypedElement>, List<FacetSet>) + * Nicolas Bros (Mia-Software) - Bug 379683 - customizable Tree content provider + * Christian W. Damus (CEA) - bug 410346 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + */ +package org.eclipse.papyrus.emf.facet.custom.ui.internal.query; + +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.ETypedElement; +import org.eclipse.emf.ecore.util.FeatureMap; +import org.eclipse.emf.edit.provider.ComposedAdapterFactory; +import org.eclipse.emf.edit.provider.IItemLabelProvider; +import org.eclipse.emf.edit.provider.ReflectiveItemProvider; +import org.eclipse.papyrus.emf.facet.efacet.core.IFacetManager; +import org.eclipse.papyrus.emf.facet.efacet.core.exception.DerivedTypedElementException; +import org.eclipse.papyrus.emf.facet.query.java.core.IJavaQuery2; +import org.eclipse.papyrus.emf.facet.query.java.core.IParameterValueList2; +import org.eclipse.papyrus.emf.facet.util.emf.core.ModelUtils; +import org.eclipse.papyrus.infra.internationalization.edit.provider.InternationalizationNotationItemProviderAdapterFactory; + +public class LabelQuery implements IJavaQuery2<EObject, String> { + + private static final String NAME = "name"; //$NON-NLS-1$ + + public String evaluate(final EObject source, + final IParameterValueList2 parameterValues, + final IFacetManager facetManager) + throws DerivedTypedElementException { + ETypedElement sfParam = null; + if (parameterValues != null) { + sfParam = (ETypedElement) parameterValues + .getParameterValueByName("eStructuralFeature").getValue(); //$NON-NLS-1$ + } + String result = null; + if (sfParam == null) { + final ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory( + ComposedAdapterFactory.Descriptor.Registry.INSTANCE); + adapterFactory.insertAdapterFactory(new InternationalizationNotationItemProviderAdapterFactory()); + + try { + final IItemLabelProvider itemLabelProvider = (IItemLabelProvider) adapterFactory.adapt(source, IItemLabelProvider.class); + // We don't want to use a ReflectiveItemProvider because it provides + // a string prefixed with the eObject's meta-class name. + if (itemLabelProvider instanceof ReflectiveItemProvider) { + result = LabelQuery.getDefaultName(source); + } else if (itemLabelProvider == null) { + result = ModelUtils.getDefaultName(source); + } else { + result = itemLabelProvider.getText(source); + } + } finally { + // Dispose the adapter factory because it added an adapter that would leak, as nobody else will ever use it + adapterFactory.dispose(); + } + } else { + try { + if (sfParam instanceof EAttribute && sfParam.getUpperBound() == 1) { + final Object object = facetManager.getOrInvoke(source, sfParam, Object.class); + final String objectLabel = getObjectLabel(object, facetManager); + result = sfParam.getName() + " = " + objectLabel; //$NON-NLS-1$ + } else { + result = sfParam.getName(); + } + } catch (final Exception e) { + throw new DerivedTypedElementException(e); + } + } + return result; + } + + private String getObjectLabel(final Object object, + final IFacetManager facetManager) + throws DerivedTypedElementException { + String result; + if (object instanceof EObject) { + final EObject eObject = (EObject) object; + result = evaluate(eObject, null, facetManager); + } else { + result = String.valueOf(object); + } + return result; + } + + /** + * @return a default name based on a string feature of the given {@link EObject} + */ + // from org.eclipse.papyrus.emf.facet.infra.common.core.internal.utils.ModelUtils + public static String getDefaultName(final EObject eObject) { + String result = ""; //$NON-NLS-1$ + // find a feature that can be used as a name + final EStructuralFeature feature = LabelQuery.getLabelFeature(eObject + .eClass()); + if (feature != null) { + result = (String) eObject.eGet(feature); + } + return result; + } + + /** + * This method searches for a structural feature that can be used as a name + * + * @param eClass + * in which class to search a structural feature that can be used as + * a name + * @return an EStructuralFeature + */ + // Copied from org.eclipse.emf.edit.provider.ReflectiveItemProvider to org.eclipse.papyrus.emf.facet.infra.common.core.internal.utils.ModelUtils + // Copied from org.eclipse.papyrus.emf.facet.infra.common.core.internal.utils.ModelUtils + private static EStructuralFeature getLabelFeature(final EClass eClass) { + EAttribute result = null; + for (final EAttribute eAttribute : eClass.getEAllAttributes()) { + if (!eAttribute.isMany() + && eAttribute.getEType().getInstanceClass() != FeatureMap.Entry.class) { + if (LabelQuery.NAME.equalsIgnoreCase(eAttribute + .getName())) { + result = eAttribute; + break; + } else if (result == null) { + result = eAttribute; + } else if (eAttribute.getEAttributeType().getInstanceClass() == String.class + && result.getEAttributeType().getInstanceClass() != String.class) { + result = eAttribute; + } + } + } + return result; + } + +} diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF b/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF index be0b3be7e36..8725c017613 100644 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF @@ -30,7 +30,7 @@ Require-Bundle: org.eclipse.emf.workspace;bundle-version="[1.5.0,2.0.0)", org.eclipse.core.resources;bundle-version="[3.11.0,4.0.0)";visibility:=reexport Bundle-Vendor: %providerName Bundle-ActivationPolicy: lazy -Bundle-Version: 2.2.0.qualifier +Bundle-Version: 2.3.0.qualifier Bundle-Name: %pluginName Bundle-Localization: plugin Bundle-Activator: org.eclipse.papyrus.infra.core.Activator diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/pom.xml b/plugins/infra/core/org.eclipse.papyrus.infra.core/pom.xml index 2524dc5f316..5511a52363f 100644 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core/pom.xml +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/pom.xml @@ -7,6 +7,6 @@ <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>org.eclipse.papyrus.infra.core</artifactId> - <version>2.2.0-SNAPSHOT</version> + <version>2.3.0-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project>
\ No newline at end of file diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModelWithSharedResource.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModelWithSharedResource.java index 884a997c7e4..2f2eaf40748 100644 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModelWithSharedResource.java +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AbstractModelWithSharedResource.java @@ -9,6 +9,7 @@ * Contributors: * LIFL - Initial API and implementation * Christian W. Damus - bugs 485220, 496299 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 * *****************************************************************************/ package org.eclipse.papyrus.infra.core.resource; @@ -46,8 +47,10 @@ public abstract class AbstractModelWithSharedResource<T extends EObject> extends /** * Model kind. + * + * @since 2.0 */ - private ModelKind modelKind; + protected ModelKind modelKind; /** * diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AdjunctResourceModelSnippet.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AdjunctResourceModelSnippet.java index 46a6003edc5..9b2709a4e9a 100644 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AdjunctResourceModelSnippet.java +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/AdjunctResourceModelSnippet.java @@ -8,6 +8,7 @@ * * Contributors: * Christian W. Damus - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 * *****************************************************************************/ @@ -89,16 +90,29 @@ public class AdjunctResourceModelSnippet implements IModelSnippet { if (converter.exists(adjunctURI, Collections.emptyMap())) { // Best effort load. This must not interfere with other // resource set operations - try { - resourceSet.getResource(adjunctURI, true); - } catch (Exception e) { - Activator.log.error( - String.format("Failed to load %s resource", model.getModelFileExtension()), //$NON-NLS-1$ - e); - } + loadResource(model, resourceSet, adjunctURI); } } } } + /** + * This allows to load the model. + * + * @param model The {@link EMFLogicalModel}. + * @param resourceSet The resource set. + * @param adjunctURI The adjunct URI. + * + * @since 2.3 + */ + protected void loadResource(final EMFLogicalModel model, final ResourceSet resourceSet, final URI adjunctURI){ + try { + resourceSet.getResource(adjunctURI, true); + } catch (final Exception e) { + Activator.log.error( + String.format("Failed to load %s resource", model.getModelFileExtension()), //$NON-NLS-1$ + e); + } + } + } diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java index 85a7c146bca..b66c3aa0526 100644 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java @@ -17,6 +17,7 @@ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 436952 * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 436998 * Christian W. Damus - bugs 436998, 468030, 485220 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 * *****************************************************************************/ package org.eclipse.papyrus.infra.core.resource; @@ -853,7 +854,14 @@ public class ModelSet extends ResourceSetImpl { return result; } - protected boolean deleteResource(URI uri) { + /** + * This allows to delete a resource from the uri. + * + * @param uri The uri of the resource to delete. + * @return <code>true</code> if the resource is deleted, <code>false</code> otherwise. + * @since 2.3 + */ + public boolean deleteResource(final URI uri) { boolean result = false; try { diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/PapyrusProjectScope.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/PapyrusProjectScope.java new file mode 100644 index 00000000000..635d3388e7f --- /dev/null +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/PapyrusProjectScope.java @@ -0,0 +1,124 @@ +/***************************************************************************** + * 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.infra.core.resource; + +import org.eclipse.core.internal.preferences.AbstractScope; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; + +/** + * This papyrus scope for the papyrus project preference store. + * This need to manage the preference for the papyrus project with the papyrus project name (to retrieve the correct name). + * + * @since 2.2 + */ +@SuppressWarnings("restriction") +public class PapyrusProjectScope extends AbstractScope { + + /** + * String constant (value of <code>"papyrusProject"</code>) used for the scope name for this preference scope. + */ + public static final String SCOPE = "papyrusProject"; //$NON-NLS-1$ + + /** + * The papyrus project name. + */ + private String papyrusProjectName; + + /** + * The context project. + */ + private IProject context; + + /** + * Constructor. + * + * @param project + * The project. + * @param papyrusProjectName + * The name of the '.di' file. + */ + public PapyrusProjectScope(final IProject project, final String papyrusProjectName) { + this.context = project; + this.papyrusProjectName = papyrusProjectName; + } + + /** + * Default path hierarchy for nodes is /<scope>/<qualifier>. + * + * @param qualifier The qualifier. + * @return The path hierarchy. + */ + @Override + public IEclipsePreferences getNode(final String qualifier) { + if (qualifier == null) + throw new IllegalArgumentException(); + final StringBuilder node = new StringBuilder(context.getName()); + node.append("/"); //$NON-NLS-1$ + node.append(papyrusProjectName); + return (IEclipsePreferences) Platform.getPreferencesService().getRootNode().node(SCOPE).node(node.toString()).node(qualifier); + } + + /** + * The papyrus scope name. + * + * @return The papyrus scope name. + */ + @Override + public String getName() { + return SCOPE; + } + + /** + * The location of the scope. + * + * @return The location of the scope. + */ + @Override + public IPath getLocation() { + // This must not be save + return null; + } + + /** + * This allows to determinate if the object in parameter is equals to the current. + * + * @param obj The object to compare. + * @return <code>true</code> if this is equals, <code>false</code> otherwise. + */ + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (!(obj instanceof PapyrusProjectScope)) + return false; + PapyrusProjectScope other = (PapyrusProjectScope) obj; + return context.equals(other.context) && papyrusProjectName.equals(other.papyrusProjectName); + } + + /** + * This allows to define the int hash code. + * + * @return The int representing the hascode. + */ + @Override + public int hashCode() { + return super.hashCode() + context.getFullPath().hashCode() + "/".hashCode() + papyrusProjectName.hashCode(); //$NON-NLS-1$ + } + +} diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/META-INF/MANIFEST.MF b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/META-INF/MANIFEST.MF index 0436405a78f..d858787d465 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/META-INF/MANIFEST.MF +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/META-INF/MANIFEST.MF @@ -6,7 +6,8 @@ Require-Bundle: org.eclipse.papyrus.infra.onefile;bundle-version="[2.0.0,3.0.0)" org.eclipse.gmf.runtime.common.core;bundle-version="[1.7.0,2.0.0)";visibility:=reexport, org.eclipse.papyrus.infra.emf.gmf;bundle-version="[1.2.0,2.0.0)", org.eclipse.papyrus.infra.core;bundle-version="[2.0.0,3.0.0)";visibility:=reexport, - org.eclipse.papyrus.infra.emf;bundle-version="[2.0.0,3.0.0)";visibility:=reexport + org.eclipse.papyrus.infra.emf;bundle-version="[2.0.0,3.0.0)";visibility:=reexport, + org.eclipse.pde.ui;bundle-version="[3.9.0,4.0.0)" Bundle-Vendor: %providerName Bundle-ActivationPolicy: lazy Bundle-Version: 3.0.0.qualifier diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/internal/ControlledResourceTracker.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/internal/ControlledResourceTracker.java index d99fc22337e..a3db4d85c2e 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/internal/ControlledResourceTracker.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/internal/ControlledResourceTracker.java @@ -9,6 +9,7 @@ * Contributors: * Christian W. Damus (CEA) - Initial API and implementation * Christian W. Damus - bugs 463631, 485220 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 * */ package org.eclipse.papyrus.infra.emf.readonly.internal; @@ -31,6 +32,7 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.emf.transaction.TransactionalEditingDomainEvent; import org.eclipse.emf.transaction.TransactionalEditingDomainListener; import org.eclipse.emf.transaction.util.TransactionUtil; +import org.eclipse.pde.internal.ui.util.LocaleUtil; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Iterables; @@ -45,6 +47,7 @@ import com.google.common.collect.Sets; * is necessary to ensure that the ephemeral states during controlling and uncontrolling a sub-model don't fool the editing domain into thinking * we're making changes to a read-only resource, triggering roll-back. */ +@SuppressWarnings("restriction") public class ControlledResourceTracker extends AdapterImpl implements TransactionalEditingDomainListener { // A resource may be a sub-unit of multiple parent units (it can have multiple roots that are @@ -108,7 +111,7 @@ public class ControlledResourceTracker extends AdapterImpl implements Transactio for (URI next = units.poll(); next != null; next = units.poll()) { if (isRoot(next)) { - result.add(next); + result.add(getFinalURI(uri, next)); } else { Iterables.addAll(units, get(next)); } @@ -116,6 +119,37 @@ public class ControlledResourceTracker extends AdapterImpl implements Transactio return result; } + + /** + * Get the URI modified if necessary (for example, the properties file can have a locale at the end of the file). + * + * @param uri + * The URI of a resource that potentially is in a sub-model unit. + * @param initialURI + * The initial URI of the sub model unit. + * @return The modified URI (or not modified if don't needed). + */ + private URI getFinalURI(final URI uri, final URI initialURI) { + URI result = initialURI; + + // If this is a properties file, check if a locale is available at the end of the URI + if (uri.fileExtension().equals("properties")) { //$NON-NLS-1$ + // Get the last segment + final String lastSegment = initialURI.lastSegment(); + // Try to remove existing localization + final String withoutLocalization = LocaleUtil.trimLocalization(lastSegment); + + // If the initial last segment and the segment without localization are not equals, localization exist + if (!lastSegment.equals(withoutLocalization)) { + // Remove the last segment + result = initialURI.trimSegments(1); + // Add the modified last segment + result = result.appendSegment(withoutLocalization); + } + } + + return result; + } /** * Queries whether the given URI (without extension, thus representing the set of Papyrus resources comprising diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/commands/AddEAnnotationDetailCommand.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/commands/AddEAnnotationDetailCommand.java new file mode 100644 index 00000000000..4b490bccf42 --- /dev/null +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/commands/AddEAnnotationDetailCommand.java @@ -0,0 +1,69 @@ +/***************************************************************************** + * Copyright (c) 2015 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.infra.emf.commands; + +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; + +/** + * This allows to add a detail into the annotation. + */ +public class AddEAnnotationDetailCommand extends RecordingCommand { + + /** + * The owner annotation. + */ + private EAnnotation eAnnotation; + + /** + * The key to add. + */ + private String detailKey; + + /** + * The value of the detail key. + */ + private String value; + + /** + * Constructor. + * + * @param domain + * The editing domain. + * @param annotation + * The owner annotation. + * @param detailKey + * The key to add. + * @param value + * The value of the detail key. + */ + public AddEAnnotationDetailCommand(final TransactionalEditingDomain domain, final EAnnotation annotation, final String detailKey, final String value) { + super(domain); + this.eAnnotation = annotation; + this.detailKey = detailKey; + this.value = value; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.transaction.RecordingCommand#doExecute() + */ + @Override + protected void doExecute() { + eAnnotation.getDetails().put(detailKey, value); + } + +} diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/commands/AddToResourceCommand.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/commands/AddToResourceCommand.java index 76f2b533692..9daa7d391c3 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/commands/AddToResourceCommand.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/commands/AddToResourceCommand.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2012 CEA LIST. + * Copyright (c) 2016 CEA LIST. * * * All rights reserved. This program and the accompanying materials @@ -8,21 +8,24 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation * *****************************************************************************/ package org.eclipse.papyrus.infra.emf.commands; -import org.eclipse.emf.common.command.AbstractCommand; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; /** - * * This command allows to add an EObject to a resource - * */ -public class AddToResourceCommand extends AbstractCommand { +public class AddToResourceCommand extends AbstractTransactionalCommand { /** * the resource @@ -38,63 +41,27 @@ public class AddToResourceCommand extends AbstractCommand { * * Constructor. * + * @param domain + * The editing domain. * @param resource * the resource * @param toAdd * the object to add to the resource */ - public AddToResourceCommand(final Resource resource, final EObject toAdd) { + public AddToResourceCommand(final TransactionalEditingDomain domain, final Resource resource, final EObject toAdd) { + super(domain, "Add an object to a resource", null); this.resource = resource; this.toAdd = toAdd; - setLabel("Add an object to a resource"); - } - - /** - * - * @see org.eclipse.emf.common.command.Command#execute() - * - */ - public void execute() { - this.resource.getContents().add(this.toAdd); } /** - * - * @see org.eclipse.emf.common.command.Command#redo() - * - */ - public void redo() { - execute(); - } - - /** - * - * @see org.eclipse.emf.common.command.AbstractCommand#prepare() - * + * {@inheritDoc} + * + * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) */ @Override - protected boolean prepare() { - return true; - } - - - /** - * - * @see org.eclipse.emf.common.command.AbstractCommand#undo() - * - */ - @Override - public void undo() { - this.resource.getContents().remove(this.toAdd); - } - - /** - * - * @see org.eclipse.emf.common.command.AbstractCommand#canExecute() - * - */ - @Override - public boolean canExecute() { - return super.canExecute() && this.resource != null; + protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { + this.resource.getContents().add(this.toAdd); + return CommandResult.newOKCommandResult(); } } diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/META-INF/MANIFEST.MF b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/META-INF/MANIFEST.MF index 1926a6e9290..f4286b65a70 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/META-INF/MANIFEST.MF +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/META-INF/MANIFEST.MF @@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.emf.edit.ui;bundle-version="[2.12.0,3.0.0)";visibili org.eclipse.papyrus.emf.facet.custom.core;bundle-version="[2.0.0,3.0.0)";visibility:=reexport, org.eclipse.papyrus.infra.emf.readonly;bundle-version="[3.0.0,4.0.0)", org.eclipse.papyrus.infra.onefile;bundle-version="[2.0.0,3.0.0)", - org.eclipse.papyrus.infra.ui;bundle-version="[2.0.0,3.0.0)";visibility:=reexport + org.eclipse.papyrus.infra.ui;bundle-version="[2.0.0,3.0.0)";visibility:=reexport, + org.eclipse.papyrus.infra.internationalization.utils;bundle-version="[1.0.0,2.0.0)" Bundle-Vendor: %pluginProvider Bundle-ActivationPolicy: lazy Bundle-Version: 2.0.0.qualifier diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/internal/emf/readonly/handlers/ReferencedModelReadOnlyHandler.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/internal/emf/readonly/handlers/ReferencedModelReadOnlyHandler.java index d08fdc7296f..62b05b49265 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/internal/emf/readonly/handlers/ReferencedModelReadOnlyHandler.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/internal/emf/readonly/handlers/ReferencedModelReadOnlyHandler.java @@ -9,6 +9,7 @@ * Contributors: * Christian W. Damus (CEA) - Initial API and implementation * Christian W. Damus - bug 463631 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 * */ package org.eclipse.papyrus.infra.ui.internal.emf.readonly.handlers; @@ -188,7 +189,8 @@ public class ReferencedModelReadOnlyHandler extends AbstractReadOnlyHandler impl Set<URI> rootURIs = resolveRootResourceURIs(modelSet, uri); if (!rootURIs.isEmpty()) { - result = modelSet.isUserModelResource(rootURIs.iterator().next()) + URI next = rootURIs.iterator().next(); + result = modelSet.isUserModelResource(next) && !rootURIs.contains(modelSet.getURIWithoutExtension()); } } diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/META-INF/MANIFEST.MF index a3d544e8994..247d2fbd75d 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/META-INF/MANIFEST.MF +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/META-INF/MANIFEST.MF @@ -5,7 +5,8 @@ Require-Bundle: org.eclipse.emf.transaction.ui;bundle-version="[1.4.0,2.0.0)", org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="[1.2.0,2.0.0)";visibility:=reexport, org.eclipse.gmf.runtime.diagram.ui.resources.editor;bundle-version="[1.7.0,2.0.0)", org.eclipse.papyrus.infra.ui;bundle-version="[2.0.0,3.0.0)";visibility:=reexport, - org.eclipse.papyrus.infra.emf.gmf;bundle-version="[1.2.0,2.0.0)";visibility:=reexport + org.eclipse.papyrus.infra.emf.gmf;bundle-version="[1.2.0,2.0.0)";visibility:=reexport, + org.eclipse.papyrus.infra.internationalization.utils;bundle-version="[1.0.0,2.0.0)" Export-Package: org.eclipse.papyrus.commands, org.eclipse.papyrus.commands.util, org.eclipse.papyrus.commands.wrappers diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/RenameDiagramHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/RenameDiagramHandler.java index 2ed0050da80..775298271b8 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/RenameDiagramHandler.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.commands/src/org/eclipse/papyrus/commands/RenameDiagramHandler.java @@ -1,218 +1,232 @@ -/*****************************************************************************
- * Copyright (c) 2013, 2016 Cedric Dumoulin, Christian W. Damus, and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- * Christian W. Damus - bug 485220
- *
- *****************************************************************************/
-package org.eclipse.papyrus.commands;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.expressions.IEvaluationContext;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.commands.messages.Messages;
-import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.ui.util.ServiceUtilsForIEvaluationContext;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorPart;
-
-/**
- * This handler allows to rename a gmf diagram.
- * The handler is activated when the current selection denote a gmf diagram.
- *
- * <br>
- * There is another RenameHandler in Papyrus (for modelexplorer):
- * /org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/handlers/RenameDiagramHandler.java
- *
- * @author cedric dumoulin
- *
- */
-public class RenameDiagramHandler extends AbstractHandler {
-
- /**
- * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- * @param event
- * @return
- * @throws ExecutionException
- *
- */
- public Object execute(ExecutionEvent event) throws ExecutionException {
- executeTransaction(event);
-
- return null;
- }
-
- /**
- * Execute as transaction
- *
- * @param event
- */
- private void executeTransaction(ExecutionEvent event) {
-
- // Get requested objects
- final Diagram notationDiagramHelper;
- TransactionalEditingDomain editingDomain;
- try {
- IEvaluationContext context = getIEvaluationContext(event);
- notationDiagramHelper = lookupNotationDiagramChecked(context);
- editingDomain = lookupTransactionalEditingDomain(context);
- } catch (NotFoundException e) {
- // silently fails
- return;
- } catch (ServiceException e) {
- // silently fails
- return;
- }
-
- // Open the dialog to ask the new name
- String currentName = notationDiagramHelper.getName();
- String newName = null;
- InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), Messages.RenameDiagramHandler_RenameAnExistingDiagram, Messages.RenameDiagramHandler_NewName, currentName, null);
- if (dialog.open() == Window.OK) {
- newName = dialog.getValue();
- if (newName == null || newName.length() <= 0) {
- return;
- }
- } else {
- // cancelled
- return;
- }
-
- final String name = newName;
- Command cmd = new RecordingCommand(editingDomain, getCommandName()) {
-
- @Override
- protected void doExecute() {
- // Rename the diagram !
- notationDiagramHelper.setName(name);
- }
-
-
- };
-
- editingDomain.getCommandStack().execute(cmd);
-
- }
-
- /**
- * Get the name used in the {@link RecordingCommand}. This name will be visible in
- * undo/redo.
- *
- * @return The command name to show.
- */
- public String getCommandName() {
- return Messages.RenameDiagramHandler_RenameDiagram;
- }
-
- protected IEvaluationContext getIEvaluationContext(ExecutionEvent event) throws NotFoundException {
- try {
- return (IEvaluationContext) event.getApplicationContext();
- } catch (ClassCastException e) {
- throw new NotFoundException("IEvaluationContext can't be found."); //$NON-NLS-1$
- }
-
- }
-
- // /**
- // *
- // * @return
- // * @throws NotFoundException
- // */
- // protected LayerStackMngr lookupLayerStackMngrChecked() throws NotFoundException {
- //
- // return lookupLayersViewChecked().getLayerStackMngrChecked();
- //
- // }
-
- /**
- * Get the notation diagram helper.
- * This method can be used from {@link #execute(ExecutionEvent)} or {@link #setEnabled(Object)}.
- *
- * @return The
- * @throws NotFoundException
- * @throws ServiceException
- */
- protected Diagram lookupNotationDiagramChecked(IEvaluationContext context) throws NotFoundException, ServiceException {
-
-
- // Get page from the event !
- IEditorPart editor = ServiceUtilsForIEvaluationContext.getInstance().getService(ISashWindowsContainer.class, context).getActiveEditor();
-
- if (!(editor instanceof DiagramDocumentEditor)) {
- throw new NotFoundException("Selected editor do not contains Diagram"); //$NON-NLS-1$
- }
- DiagramDocumentEditor diagramEditor = (DiagramDocumentEditor) editor;
-
- Diagram diagram = diagramEditor.getDiagram();
- if (diagram == null) {
- throw new NotFoundException("Selected editor do not contains Diagram"); //$NON-NLS-1$
- }
-
- // Return a new instance of the Helper
- return diagram;
- }
-
- /**
- * Try to lookup the TransactionalEditingDomain.
- *
- * @return
- * @throws ServiceException
- * If the Editing domain can't be found.
- */
- protected TransactionalEditingDomain lookupTransactionalEditingDomain(IEvaluationContext context) throws ServiceException {
-
- // Get page from the event !
- // IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
-
- return ServiceUtilsForIEvaluationContext.getInstance().getTransactionalEditingDomain(context);
- }
-
- /**
- * Called by framework. Need to set the enabled flag.
- *
- * @see org.eclipse.core.commands.AbstractHandler#setEnabled(java.lang.Object)
- *
- * @param evaluationContext
- */
- @Override
- public void setEnabled(Object evaluationContext) {
-
- if (!(evaluationContext instanceof IEvaluationContext)) {
- setBaseEnabled(false);
- return;
- }
-
- IEvaluationContext context = (IEvaluationContext) evaluationContext;
-
- try {
- // Try to get the diagram
- lookupNotationDiagramChecked(context);
-
- // ok, we got it.
- setBaseEnabled(true);
-
- } catch (ServiceException e) {
- // Can't find ServiceRegistry: disable
- setBaseEnabled(false);
- } catch (NotFoundException e) {
- // Can't find ServiceRegistry: disable
- setBaseEnabled(false);
- }
-
- }
-}
+/***************************************************************************** + * Copyright (c) 2013, 2016 Cedric Dumoulin, Christian W. Damus, and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation + * Christian W. Damus - bug 485220 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * + *****************************************************************************/ +package org.eclipse.papyrus.commands; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.commands.messages.Messages; +import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalization; +import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalizationPreferencesUtils; +import org.eclipse.papyrus.infra.ui.util.ServiceUtilsForIEvaluationContext; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IEditorPart; + +/** + * This handler allows to rename a gmf diagram. + * The handler is activated when the current selection denote a gmf diagram. + * + * <br> + * There is another RenameHandler in Papyrus (for modelexplorer): + * /org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/handlers/RenameDiagramHandler.java + * + * @author cedric dumoulin + * + */ +public class RenameDiagramHandler extends AbstractHandler { + + /** + * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) + * @param event + * @return + * @throws ExecutionException + * + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + executeTransaction(event); + + return null; + } + + /** + * Execute as transaction + * + * @param event + */ + private void executeTransaction(ExecutionEvent event) { + + // Get requested objects + final Diagram notationDiagramHelper; + TransactionalEditingDomain editingDomain; + try { + IEvaluationContext context = getIEvaluationContext(event); + notationDiagramHelper = lookupNotationDiagramChecked(context); + editingDomain = lookupTransactionalEditingDomain(context); + } catch (NotFoundException e) { + // silently fails + return; + } catch (ServiceException e) { + // silently fails + return; + } + + // If the diagram label is available, modify this one. + Command cmd = null; + final String diagramLabel = LabelInternationalization.getInstance().getDiagramLabelWithoutName(notationDiagramHelper); + if(null != diagramLabel && LabelInternationalizationPreferencesUtils.getInternationalizationPreference(notationDiagramHelper)){ + InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), "Rename diagram label", "New label:", diagramLabel, null); //$NON-NLS-1$ //$NON-NLS-2$ + if (Window.OK == dialog.open()) { + final String label = dialog.getValue(); + cmd = LabelInternationalization.getInstance().getSetDiagramLabelCommand(editingDomain, notationDiagramHelper, label, null); + } + }else{ + // Open the dialog to ask the new name + String currentName = notationDiagramHelper.getName(); + String newName = null; + InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), Messages.RenameDiagramHandler_RenameAnExistingDiagram, Messages.RenameDiagramHandler_NewName, currentName, null); + if (dialog.open() == Window.OK) { + newName = dialog.getValue(); + if (newName == null || newName.length() <= 0) { + return; + } + } else { + // cancelled + return; + } + + final String name = newName; + cmd = new RecordingCommand(editingDomain, getCommandName()) { + + @Override + protected void doExecute() { + // Rename the diagram ! + notationDiagramHelper.setName(name); + } + + + }; + } + + editingDomain.getCommandStack().execute(cmd); + + } + + /** + * Get the name used in the {@link RecordingCommand}. This name will be visible in + * undo/redo. + * + * @return The command name to show. + */ + public String getCommandName() { + return Messages.RenameDiagramHandler_RenameDiagram; + } + + protected IEvaluationContext getIEvaluationContext(ExecutionEvent event) throws NotFoundException { + try { + return (IEvaluationContext) event.getApplicationContext(); + } catch (ClassCastException e) { + throw new NotFoundException("IEvaluationContext can't be found."); //$NON-NLS-1$ + } + + } + + // /** + // * + // * @return + // * @throws NotFoundException + // */ + // protected LayerStackMngr lookupLayerStackMngrChecked() throws NotFoundException { + // + // return lookupLayersViewChecked().getLayerStackMngrChecked(); + // + // } + + /** + * Get the notation diagram helper. + * This method can be used from {@link #execute(ExecutionEvent)} or {@link #setEnabled(Object)}. + * + * @return The + * @throws NotFoundException + * @throws ServiceException + */ + protected Diagram lookupNotationDiagramChecked(IEvaluationContext context) throws NotFoundException, ServiceException { + + + // Get page from the event ! + IEditorPart editor = ServiceUtilsForIEvaluationContext.getInstance().getService(ISashWindowsContainer.class, context).getActiveEditor(); + + if (!(editor instanceof DiagramDocumentEditor)) { + throw new NotFoundException("Selected editor do not contains Diagram"); //$NON-NLS-1$ + } + DiagramDocumentEditor diagramEditor = (DiagramDocumentEditor) editor; + + Diagram diagram = diagramEditor.getDiagram(); + if (diagram == null) { + throw new NotFoundException("Selected editor do not contains Diagram"); //$NON-NLS-1$ + } + + // Return a new instance of the Helper + return diagram; + } + + /** + * Try to lookup the TransactionalEditingDomain. + * + * @return + * @throws ServiceException + * If the Editing domain can't be found. + */ + protected TransactionalEditingDomain lookupTransactionalEditingDomain(IEvaluationContext context) throws ServiceException { + + // Get page from the event ! + // IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); + + return ServiceUtilsForIEvaluationContext.getInstance().getTransactionalEditingDomain(context); + } + + /** + * Called by framework. Need to set the enabled flag. + * + * @see org.eclipse.core.commands.AbstractHandler#setEnabled(java.lang.Object) + * + * @param evaluationContext + */ + @Override + public void setEnabled(Object evaluationContext) { + + if (!(evaluationContext instanceof IEvaluationContext)) { + setBaseEnabled(false); + return; + } + + IEvaluationContext context = (IEvaluationContext) evaluationContext; + + try { + // Try to get the diagram + lookupNotationDiagramChecked(context); + + // ok, we got it. + setBaseEnabled(true); + + } catch (ServiceException e) { + // Can't find ServiceRegistry: disable + setBaseEnabled(false); + } catch (NotFoundException e) { + // Can't find ServiceRegistry: disable + setBaseEnabled(false); + } + + } +} diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF index ddf6a8377e7..501ee1c8008 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/META-INF/MANIFEST.MF @@ -68,7 +68,8 @@ Require-Bundle: org.eclipse.emf.ecore.edit;bundle-version="[2.9.0,3.0.0)", org.eclipse.papyrus.infra.services.edit.ui;bundle-version="[3.0.0,4.0.0)";visibility:=reexport, org.eclipse.papyrus.infra.emf.gmf, org.eclipse.papyrus.infra.ui;bundle-version="[2.0.0,3.0.0)", - org.eclipse.papyrus.infra.core;bundle-version="[2.2.0,3.0.0)" + org.eclipse.papyrus.infra.core;bundle-version="[2.2.0,3.0.0)", + org.eclipse.papyrus.infra.internationalization.utils;bundle-version="[1.0.0,2.0.0)" Bundle-Vendor: %providerName Bundle-ActivationPolicy: lazy Bundle-ClassPath: . diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/META-INF/MANIFEST.MF index 1d5325c5559..35c570d064d 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/META-INF/MANIFEST.MF +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/META-INF/MANIFEST.MF @@ -3,7 +3,8 @@ Require-Bundle: org.eclipse.papyrus.infra.hyperlink;bundle-version="[3.0.0,4.0.0 org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="[3.0.0,4.0.0)";visibility:=reexport, org.eclipse.papyrus.infra.gmfdiag.navigation;bundle-version="[2.0.0,3.0.0)";visibility:=reexport, org.eclipse.papyrus.infra.gmfdiag.preferences;bundle-version="[3.0.0,4.0.0)", - org.eclipse.papyrus.infra.gmfdiag.dnd;bundle-version="[1.2.0,2.0.0)" + org.eclipse.papyrus.infra.gmfdiag.dnd;bundle-version="[1.2.0,2.0.0)", + org.eclipse.papyrus.infra.internationalization.utils;bundle-version="[1.0.0,2.0.0)" Export-Package: org.eclipse.papyrus.infra.gmfdiag.hyperlink, org.eclipse.papyrus.infra.gmfdiag.hyperlink.editpolicies, org.eclipse.papyrus.infra.gmfdiag.hyperlink.helper, diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/ui/AdvancedHLManager.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/ui/AdvancedHLManager.java index aa68cc88e94..c93e62acfcd 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/ui/AdvancedHLManager.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.hyperlink/src/org/eclipse/papyrus/infra/gmfdiag/hyperlink/ui/AdvancedHLManager.java @@ -12,6 +12,8 @@ * Arthur Daussy (Atos) arthur.daussy@atos.net - Bug 363827 - [Improvement] Diagram creation, remember the latest tab chosen * Vincent Lorenzo (CEA-LIST) Vincent.lorenzo@cea.fr (refactoring of the hyperlink) * Christian W. Damus - bug 488965 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 + * *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.hyperlink.ui; @@ -30,6 +32,7 @@ import org.eclipse.papyrus.infra.gmfdiag.hyperlink.object.HyperLinkEditor; import org.eclipse.papyrus.infra.hyperlink.helper.HyperLinkHelperFactory; import org.eclipse.papyrus.infra.hyperlink.ui.AbstractHyperLinkTab; import org.eclipse.papyrus.infra.hyperlink.ui.HyperLinkManagerShell; +import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalization; import org.eclipse.papyrus.infra.ui.editorsfactory.IPageIconsRegistry; import org.eclipse.swt.widgets.Shell; @@ -81,7 +84,7 @@ public class AdvancedHLManager extends HyperLinkManagerShell { HyperLinkEditor hyperLinkEditor = new HyperLinkEditor(); hyperLinkEditor.setObject(diagrams.get(i)); hyperLinkEditor.setIsDefault(true); - hyperLinkEditor.setTooltipText(diagrams.get(i).getName()); + hyperLinkEditor.setTooltipText(LabelInternationalization.getInstance().getDiagramLabel(diagrams.get(i))); hyperLinkDiagrams.add(hyperLinkEditor); } return hyperLinkDiagrams; diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/META-INF/MANIFEST.MF index 60578c27e04..6c76cfaf435 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/META-INF/MANIFEST.MF +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/META-INF/MANIFEST.MF @@ -3,7 +3,8 @@ Require-Bundle: org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="[3.0.0, org.eclipse.papyrus.infra.emf;bundle-version="[2.0.0,3.0.0)", org.eclipse.papyrus.infra.emf;bundle-version="[2.0.0,3.0.0)", org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="[3.0.0,4.0.0)", - org.eclipse.papyrus.views.modelexplorer;bundle-version="[3.0.0,4.0.0)" + org.eclipse.papyrus.views.modelexplorer;bundle-version="[3.0.0,4.0.0)", + org.eclipse.papyrus.infra.internationalization.utils;bundle-version="[1.0.0,2.0.0)" Bundle-Vendor: %providerName Bundle-ActivationPolicy: lazy Bundle-Version: 1.2.0.qualifier diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/handlers/RenameDiagramHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/handlers/RenameDiagramHandler.java index c8b292288bb..a318f4d1a89 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/handlers/RenameDiagramHandler.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.modelexplorer/src/org/eclipse/papyrus/infra/gmfdiag/modelexplorer/handlers/RenameDiagramHandler.java @@ -10,6 +10,7 @@ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation * Christian W. Damus - bug 485220 * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Bug 497289 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 * *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.modelexplorer.handlers; @@ -31,6 +32,8 @@ import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.window.Window; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; import org.eclipse.papyrus.infra.gmfdiag.modelexplorer.messages.Messages; +import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalization; +import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalizationPreferencesUtils; import org.eclipse.papyrus.views.modelexplorer.DirectEditorEditingSupport; import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; import org.eclipse.swt.widgets.Display; @@ -51,18 +54,27 @@ public class RenameDiagramHandler extends AbstractDiagramCommandHandler { if (editingDomain != null && diagrams.size() == 1) { final Diagram diag = diagrams.get(0); - final String currentName = diag.getName(); - if (currentName != null) { - - AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(editingDomain, "RenameDiagramCommand", null) { //$NON-NLS-1$ - + + final String diagramLabel = LabelInternationalization.getInstance().getDiagramLabelWithoutName(diag); + if(null != diagramLabel && LabelInternationalizationPreferencesUtils.getInternationalizationPreference(diag)){ + AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(editingDomain, "ChangeDiagramLabelCommand", null) { //$NON-NLS-1$ + + /** + * + * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) + * + * @param monitor + * @param info + * @return + * @throws ExecutionException + */ @Override - protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), Messages.RenameDiagramHandler_RenameAnExistingDiagram, Messages.RenameDiagramHandler_NewName, currentName, null); - if (dialog.open() == Window.OK) { - final String name = dialog.getValue(); - if (name != null && name.length() > 0) { - diag.setName(name); + protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { + InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), "Rename diagram label...", "New label:", diagramLabel, null); //$NON-NLS-1$ //$NON-NLS-2$ + if (Window.OK == dialog.open()) { + final String label = dialog.getValue(); + if (label != null && label.length() > 0) { + LabelInternationalization.getInstance().setDiagramLabel(diag, label, null); } return CommandResult.newOKCommandResult(); } else { @@ -71,6 +83,28 @@ public class RenameDiagramHandler extends AbstractDiagramCommandHandler { } }; return new GMFtoEMFCommandWrapper(cmd); + }else{ + final String currentName = diag.getName(); + if (currentName != null) { + + AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(editingDomain, "RenameDiagramCommand", null) { //$NON-NLS-1$ + + @Override + protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { + InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), Messages.RenameDiagramHandler_RenameAnExistingDiagram, Messages.RenameDiagramHandler_NewName, currentName, null); + if (dialog.open() == Window.OK) { + final String name = dialog.getValue(); + if (name != null && name.length() > 0) { + diag.setName(name); + } + return CommandResult.newOKCommandResult(); + } else { + return CommandResult.newCancelledCommandResult(); + } + } + }; + return new GMFtoEMFCommandWrapper(cmd); + } } } return UnexecutableCommand.INSTANCE; diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/META-INF/MANIFEST.MF index 219350da220..76b8f339ba2 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/META-INF/MANIFEST.MF +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/META-INF/MANIFEST.MF @@ -4,7 +4,9 @@ Export-Package: org.eclipse.papyrus.infra.gmfdiag.properties.extension, Require-Bundle: org.eclipse.papyrus.infra.properties.ui;bundle-version="[2.0.0,3.0.0)";visibility:=reexport, org.eclipse.core.databinding.beans;bundle-version="[1.3.0,2.0.0)", org.eclipse.papyrus.infra.gmfdiag.preferences;bundle-version="[3.0.0,4.0.0)", - org.eclipse.papyrus.infra.gmfdiag.canonical;bundle-version="[2.0.0,3.0.0)" + org.eclipse.papyrus.infra.gmfdiag.canonical;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.infra.internationalization.utils;bundle-version="[1.0.0,2.0.0)", + org.eclipse.papyrus.infra.internationalization;bundle-version="[1.0.0,2.0.0)" Bundle-Vendor: %Bundle-Vendor Bundle-ActivationPolicy: lazy;exclude:="org.eclipse.papyrus.infra.gmfdiag.properties.constraint" Bundle-Version: 3.0.0.qualifier diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/model/notation/ui/SingleDiagram.xwt b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/model/notation/ui/SingleDiagram.xwt index 840b846b6db..db294948335 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/model/notation/ui/SingleDiagram.xwt +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/model/notation/ui/SingleDiagram.xwt @@ -11,6 +11,7 @@ <ppel:PropertiesLayout numColumns="1"></ppel:PropertiesLayout> </Composite.layout> <ppe:StringEditor input="{Binding}" property="notation:Diagram:name"></ppe:StringEditor> + <ppe:StringEditor input="{Binding}" property="notation:Diagram:label"></ppe:StringEditor> <ppe:ReferenceLabel input="{Binding}" property="notation:View:prototype" readOnly="true" customLabel="View Type"></ppe:ReferenceLabel> <ppe:ReferenceDialog input="{Binding}" property="notation:View:owner" customLabel="Owner"></ppe:ReferenceDialog> <ppe:ReferenceDialog input="{Binding}" property="notation:View:element" customLabel="Root element"></ppe:ReferenceDialog> diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/databinding/DiagramLabelObservableValue.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/databinding/DiagramLabelObservableValue.java new file mode 100644 index 00000000000..3b1ddfc7109 --- /dev/null +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/databinding/DiagramLabelObservableValue.java @@ -0,0 +1,219 @@ +/***************************************************************************** + * 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.infra.gmfdiag.properties.databinding; + +import org.eclipse.core.databinding.observable.Diffs; +import org.eclipse.core.databinding.observable.IObserving; +import org.eclipse.core.databinding.observable.Realm; +import org.eclipse.core.databinding.observable.value.AbstractObservableValue; +import org.eclipse.core.databinding.observable.value.ValueDiff; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.papyrus.infra.gmfdiag.properties.Activator; +import org.eclipse.papyrus.infra.internationalization.InternationalizationEntry; +import org.eclipse.papyrus.infra.internationalization.InternationalizationPackage; +import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalization; +import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalizationUtils; +import org.eclipse.papyrus.infra.tools.databinding.ReferenceCountedObservable; + +/** + * The observable value for the label of the {@link Diagram}. + */ +@SuppressWarnings("rawtypes") +public class DiagramLabelObservableValue extends AbstractObservableValue implements IObserving, ReferenceCountedObservable { + + /** + * The support reference counting on behalf of an {@code observable}. + */ + private final ReferenceCountedObservable.Support refCount = new ReferenceCountedObservable.Support(this); + + /** + * The diagram instance. + */ + protected Diagram diagram; + + /** + * The editing domain on which the commands will be executed. + */ + protected EditingDomain domain; + + /** + * The listener for the entry modification. + */ + protected Adapter listener; + + /** + * The internationalization entry corresponding to the diagram. + */ + protected InternationalizationEntry entry; + + /** + * Constructor. + * + * @param diagram + * The diagram. + * @param domain + * The editing domain. + */ + public DiagramLabelObservableValue(final Diagram diagram, final EditingDomain domain) { + this(Realm.getDefault(), diagram, domain); + } + + /** + * Constructor. + * + * @param realm + * The current Realm. + * @param diagram + * The diagram. + * @param domain + * The editing domain. + */ + public DiagramLabelObservableValue(final Realm realm, final Diagram diagram, final EditingDomain domain) { + super(realm); + this.diagram = diagram; + this.domain = domain; + this.entry = LabelInternationalizationUtils.getInternationalizationEntry(diagram, diagram); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.AbstractObservable#dispose() + */ + @Override + public synchronized void dispose() { + if (null != listener) { + entry.eAdapters().remove(listener); + listener = null; + } + + entry = null; + diagram = null; + super.dispose(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.IObserving#getObserved() + */ + public Object getObserved() { + return diagram; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.ChangeManager#firstListenerAdded() + */ + @Override + protected void firstListenerAdded() { + if (null != entry) { + if (null == listener) { + listener = new AdapterImpl() { + @Override + public void notifyChanged(Notification notification) { + if (InternationalizationPackage.eINSTANCE.getInternationalizationEntry_Value() == notification.getFeature() && !notification.isTouch()) { + final ValueDiff diff = Diffs.createValueDiff(notification.getOldValue(), notification.getNewValue()); + getRealm().exec(new Runnable() { + @SuppressWarnings("unchecked") + public void run() { + fireValueChange(diff); + } + }); + } + } + }; + } + entry.eAdapters().add(listener); + } + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doGetValue() + */ + @Override + protected Object doGetValue() { + return LabelInternationalization.getInstance().getDiagramLabelWithoutName(diagram); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doSetValue(java.lang.Object) + */ + @Override + protected void doSetValue(final Object value) { + try { + + // Remove the listener on entry + if (null != entry && null != listener) { + entry.eAdapters().remove(listener); + } + + final Command emfCommand = LabelInternationalization.getInstance().getSetDiagramLabelCommand(domain, diagram, (String) value, null); + domain.getCommandStack().execute(emfCommand); + + // Get the entry after the modification and try to apply listener if possible + this.entry = LabelInternationalizationUtils.getInternationalizationEntry(diagram, diagram); + firstListenerAdded(); + } catch (Exception ex) { + Activator.log.error(ex); + } + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType() + */ + public Object getValueType() { + return null; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.tools.databinding.ReferenceCountedObservable#retain() + */ + public void retain() { + refCount.retain(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.tools.databinding.ReferenceCountedObservable#release() + */ + public void release() { + refCount.release(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.tools.databinding.ReferenceCountedObservable#autorelease() + */ + public void autorelease() { + refCount.autorelease(); + } + +} diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java index 27f0fb0c118..4d4cefbddf0 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/src/org/eclipse/papyrus/infra/gmfdiag/properties/modelelement/GMFModelElement.java @@ -10,6 +10,7 @@ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 454891 * Christian W. Damus - bug 485220 + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905 * *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.properties.modelelement; @@ -34,9 +35,11 @@ import org.eclipse.papyrus.infra.gmfdiag.common.databinding.GMFObservableList; import org.eclipse.papyrus.infra.gmfdiag.common.databinding.GMFObservableValue; import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils; import org.eclipse.papyrus.infra.gmfdiag.properties.Activator; +import org.eclipse.papyrus.infra.gmfdiag.properties.databinding.DiagramLabelObservableValue; import org.eclipse.papyrus.infra.gmfdiag.properties.databinding.GradientObservableValue; import org.eclipse.papyrus.infra.gmfdiag.properties.provider.ModelContentProvider; import org.eclipse.papyrus.infra.gmfdiag.properties.util.LegacyOwnerObservable; +import org.eclipse.papyrus.infra.internationalization.utils.utils.InternationalizationConstants; import org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElement; import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService; import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker; @@ -81,15 +84,23 @@ public class GMFModelElement extends EMFModelElement { @Override protected boolean isFeatureEditable(String propertyPath) { - if (propertyPath.endsWith("owner")) { - return true; + boolean result = true; + if(InternationalizationConstants.LABEL_PROPERTY_PATH.equals(propertyPath)){ //$NON-NLS-1$ + result = true; + }else if (propertyPath.endsWith("owner")) { //$NON-NLS-1$ + result = true; + }else{ + result = super.isFeatureEditable(propertyPath); } - return super.isFeatureEditable(propertyPath); + return result; } @Override protected IObservable doGetObservable(String propertyPath) { - if (propertyPath.endsWith("owner")) { + if(InternationalizationConstants.LABEL_PROPERTY_PATH.equals(propertyPath)){ //$NON-NLS-1$ + Diagram diagram = (Diagram) source; + return new DiagramLabelObservableValue(diagram, getDomain()); + }else if (propertyPath.endsWith("owner")) { Diagram diagram = (Diagram) source; Style style = diagram.getStyle(StylePackage.Literals.PAPYRUS_VIEW_STYLE); if (style != null) { @@ -198,7 +209,7 @@ public class GMFModelElement extends EMFModelElement { } return super.getContentProvider(propertyPath); } - + /** * Gets the root EObject from the given one * diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/.classpath b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/.classpath new file mode 100644 index 00000000000..eca7bdba8f0 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/.project b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/.project new file mode 100644 index 00000000000..ae67e3eb938 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/.project @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.papyrus.infra.editor.welcome.internationalization</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.oomph.version.VersionBuilder</name> + <arguments> + <dictionary> + <key>check.maven.pom</key> + <value>true</value> + </dictionary> + <dictionary> + <key>ignore.lower.bound.dependency.ranges</key> + <value>true</value> + </dictionary> + <dictionary> + <key>release.path</key> + <value>/org.eclipse.papyrus.releng.main.release/release.xml</value> + </dictionary> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature> + <nature>org.eclipse.oomph.version.VersionNature</nature> + </natures> +</projectDescription> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/.settings/org.eclipse.jdt.core.prefs b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..8ddd9a88d57 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,296 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 +org.eclipse.jdt.core.formatter.align_type_members_on_columns=false +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_assignment=0 +org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 +org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 +org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_after_package=1 +org.eclipse.jdt.core.formatter.blank_lines_before_field=0 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 +org.eclipse.jdt.core.formatter.blank_lines_before_method=1 +org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 +org.eclipse.jdt.core.formatter.blank_lines_before_package=0 +org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 +org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 +org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false +org.eclipse.jdt.core.formatter.comment.format_block_comments=true +org.eclipse.jdt.core.formatter.comment.format_header=false +org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true +org.eclipse.jdt.core.formatter.comment.format_line_comments=true +org.eclipse.jdt.core.formatter.comment.format_source_code=true +org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true +org.eclipse.jdt.core.formatter.comment.indent_root_tags=true +org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert +org.eclipse.jdt.core.formatter.comment.line_length=260 +org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true +org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true +org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false +org.eclipse.jdt.core.formatter.compact_else_if=true +org.eclipse.jdt.core.formatter.continuation_indentation=2 +org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off +org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on +org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false +org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true +org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_empty_lines=false +org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true +org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false +org.eclipse.jdt.core.formatter.indentation.size=4 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert +org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert +org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.join_lines_in_comments=false +org.eclipse.jdt.core.formatter.join_wrapped_lines=false +org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.lineSplit=260 +org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false +org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=5 +org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true +org.eclipse.jdt.core.formatter.tabulation.char=tab +org.eclipse.jdt.core.formatter.tabulation.size=4 +org.eclipse.jdt.core.formatter.use_on_off_tags=false +org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true +org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true +org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/.settings/org.eclipse.jdt.ui.prefs b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 00000000000..954281dbc31 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,68 @@ +cleanup.add_default_serial_version_id=true +cleanup.add_generated_serial_version_id=false +cleanup.add_missing_annotations=true +cleanup.add_missing_deprecated_annotations=true +cleanup.add_missing_methods=false +cleanup.add_missing_nls_tags=false +cleanup.add_missing_override_annotations=true +cleanup.add_missing_override_annotations_interface_methods=true +cleanup.add_serial_version_id=false +cleanup.always_use_blocks=true +cleanup.always_use_parentheses_in_expressions=false +cleanup.always_use_this_for_non_static_field_access=false +cleanup.always_use_this_for_non_static_method_access=false +cleanup.convert_functional_interfaces=false +cleanup.convert_to_enhanced_for_loop=false +cleanup.correct_indentation=false +cleanup.format_source_code=false +cleanup.format_source_code_changes_only=false +cleanup.insert_inferred_type_arguments=false +cleanup.make_local_variable_final=true +cleanup.make_parameters_final=false +cleanup.make_private_fields_final=true +cleanup.make_type_abstract_if_missing_method=false +cleanup.make_variable_declarations_final=false +cleanup.never_use_blocks=false +cleanup.never_use_parentheses_in_expressions=true +cleanup.organize_imports=false +cleanup.qualify_static_field_accesses_with_declaring_class=false +cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +cleanup.qualify_static_member_accesses_with_declaring_class=true +cleanup.qualify_static_method_accesses_with_declaring_class=false +cleanup.remove_private_constructors=true +cleanup.remove_redundant_type_arguments=true +cleanup.remove_trailing_whitespaces=true +cleanup.remove_trailing_whitespaces_all=true +cleanup.remove_trailing_whitespaces_ignore_empty=false +cleanup.remove_unnecessary_casts=true +cleanup.remove_unnecessary_nls_tags=true +cleanup.remove_unused_imports=true +cleanup.remove_unused_local_variables=false +cleanup.remove_unused_private_fields=true +cleanup.remove_unused_private_members=false +cleanup.remove_unused_private_methods=true +cleanup.remove_unused_private_types=true +cleanup.sort_members=false +cleanup.sort_members_all=false +cleanup.use_anonymous_class_creation=false +cleanup.use_blocks=true +cleanup.use_blocks_only_for_return_and_throw=false +cleanup.use_lambda=true +cleanup.use_parentheses_in_expressions=false +cleanup.use_this_for_non_static_field_access=false +cleanup.use_this_for_non_static_field_access_only_if_necessary=true +cleanup.use_this_for_non_static_method_access=false +cleanup.use_this_for_non_static_method_access_only_if_necessary=true +cleanup.use_type_arguments=false +cleanup_profile=_Papyrus +cleanup_settings_version=2 +eclipse.preferences.version=1 +formatter_profile=_Papyrus +formatter_settings_version=12 +org.eclipse.jdt.ui.ignorelowercasenames=true +org.eclipse.jdt.ui.importorder=java;javax;org;com; +org.eclipse.jdt.ui.javadoc=true +org.eclipse.jdt.ui.ondemandthreshold=99 +org.eclipse.jdt.ui.staticondemandthreshold=99 +org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="false" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * Constructor.\n *\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*****************************************************************************\n * Copyright (c) ${year} CEA LIST and others.\n * \n * All rights reserved. This program and the accompanying materials\n * are made available under the terms of the Eclipse Public License v1.0\n * which accompanies this distribution, and is available at\n * http\://www.eclipse.org/legal/epl-v10.html\n *\n * Contributors\:\n * CEA LIST - Initial API and implementation\n * \n *****************************************************************************/\n</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/**\n * ${see_to_overridden}\n *\n * ${tags}\n */</template><template autoinsert\="false" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${see_to_target}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/.settings/org.eclipse.pde.api.tools.prefs b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/.settings/org.eclipse.pde.api.tools.prefs new file mode 100644 index 00000000000..23fb95e120f --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/.settings/org.eclipse.pde.api.tools.prefs @@ -0,0 +1,98 @@ +ANNOTATION_ELEMENT_TYPE_ADDED_METHOD_WITHOUT_DEFAULT_VALUE=Error +ANNOTATION_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error +ANNOTATION_ELEMENT_TYPE_REMOVED_FIELD=Error +ANNOTATION_ELEMENT_TYPE_REMOVED_METHOD=Error +ANNOTATION_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error +API_COMPONENT_ELEMENT_TYPE_REMOVED_API_TYPE=Error +API_COMPONENT_ELEMENT_TYPE_REMOVED_REEXPORTED_API_TYPE=Error +API_COMPONENT_ELEMENT_TYPE_REMOVED_REEXPORTED_TYPE=Error +API_COMPONENT_ELEMENT_TYPE_REMOVED_TYPE=Error +API_USE_SCAN_FIELD_SEVERITY=Error +API_USE_SCAN_METHOD_SEVERITY=Error +API_USE_SCAN_TYPE_SEVERITY=Error +CLASS_ELEMENT_TYPE_ADDED_METHOD=Error +CLASS_ELEMENT_TYPE_ADDED_RESTRICTIONS=Error +CLASS_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error +CLASS_ELEMENT_TYPE_CHANGED_CONTRACTED_SUPERINTERFACES_SET=Error +CLASS_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error +CLASS_ELEMENT_TYPE_CHANGED_NON_ABSTRACT_TO_ABSTRACT=Error +CLASS_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error +CLASS_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error +CLASS_ELEMENT_TYPE_REMOVED_CONSTRUCTOR=Error +CLASS_ELEMENT_TYPE_REMOVED_FIELD=Error +CLASS_ELEMENT_TYPE_REMOVED_METHOD=Error +CLASS_ELEMENT_TYPE_REMOVED_SUPERCLASS=Error +CLASS_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error +CLASS_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error +CONSTRUCTOR_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error +CONSTRUCTOR_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error +CONSTRUCTOR_ELEMENT_TYPE_CHANGED_VARARGS_TO_ARRAY=Error +CONSTRUCTOR_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error +ENUM_ELEMENT_TYPE_CHANGED_CONTRACTED_SUPERINTERFACES_SET=Error +ENUM_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error +ENUM_ELEMENT_TYPE_REMOVED_ENUM_CONSTANT=Error +ENUM_ELEMENT_TYPE_REMOVED_FIELD=Error +ENUM_ELEMENT_TYPE_REMOVED_METHOD=Error +ENUM_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error +FIELD_ELEMENT_TYPE_ADDED_VALUE=Error +FIELD_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error +FIELD_ELEMENT_TYPE_CHANGED_FINAL_TO_NON_FINAL_STATIC_CONSTANT=Error +FIELD_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error +FIELD_ELEMENT_TYPE_CHANGED_NON_STATIC_TO_STATIC=Error +FIELD_ELEMENT_TYPE_CHANGED_STATIC_TO_NON_STATIC=Error +FIELD_ELEMENT_TYPE_CHANGED_TYPE=Error +FIELD_ELEMENT_TYPE_CHANGED_VALUE=Error +FIELD_ELEMENT_TYPE_REMOVED_TYPE_ARGUMENT=Error +FIELD_ELEMENT_TYPE_REMOVED_VALUE=Error +ILLEGAL_EXTEND=Warning +ILLEGAL_IMPLEMENT=Warning +ILLEGAL_INSTANTIATE=Warning +ILLEGAL_OVERRIDE=Warning +ILLEGAL_REFERENCE=Warning +INTERFACE_ELEMENT_TYPE_ADDED_FIELD=Ignore +INTERFACE_ELEMENT_TYPE_ADDED_METHOD=Error +INTERFACE_ELEMENT_TYPE_ADDED_RESTRICTIONS=Error +INTERFACE_ELEMENT_TYPE_ADDED_SUPER_INTERFACE_WITH_METHODS=Error +INTERFACE_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error +INTERFACE_ELEMENT_TYPE_CHANGED_CONTRACTED_SUPERINTERFACES_SET=Error +INTERFACE_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error +INTERFACE_ELEMENT_TYPE_REMOVED_FIELD=Error +INTERFACE_ELEMENT_TYPE_REMOVED_METHOD=Error +INTERFACE_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error +INTERFACE_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error +INVALID_ANNOTATION=Ignore +INVALID_JAVADOC_TAG=Ignore +INVALID_REFERENCE_IN_SYSTEM_LIBRARIES=Ignore +LEAK_EXTEND=Warning +LEAK_FIELD_DECL=Warning +LEAK_IMPLEMENT=Warning +LEAK_METHOD_PARAM=Warning +LEAK_METHOD_RETURN_TYPE=Warning +METHOD_ELEMENT_TYPE_ADDED_RESTRICTIONS=Error +METHOD_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error +METHOD_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error +METHOD_ELEMENT_TYPE_CHANGED_NON_ABSTRACT_TO_ABSTRACT=Error +METHOD_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error +METHOD_ELEMENT_TYPE_CHANGED_NON_STATIC_TO_STATIC=Error +METHOD_ELEMENT_TYPE_CHANGED_STATIC_TO_NON_STATIC=Error +METHOD_ELEMENT_TYPE_CHANGED_VARARGS_TO_ARRAY=Error +METHOD_ELEMENT_TYPE_REMOVED_ANNOTATION_DEFAULT_VALUE=Error +METHOD_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error +MISSING_EE_DESCRIPTIONS=Error +TYPE_PARAMETER_ELEMENT_TYPE_ADDED_CLASS_BOUND=Error +TYPE_PARAMETER_ELEMENT_TYPE_ADDED_INTERFACE_BOUND=Error +TYPE_PARAMETER_ELEMENT_TYPE_CHANGED_CLASS_BOUND=Error +TYPE_PARAMETER_ELEMENT_TYPE_CHANGED_INTERFACE_BOUND=Error +TYPE_PARAMETER_ELEMENT_TYPE_REMOVED_CLASS_BOUND=Error +TYPE_PARAMETER_ELEMENT_TYPE_REMOVED_INTERFACE_BOUND=Error +UNUSED_PROBLEM_FILTERS=Warning +automatically_removed_unused_problem_filters=Enabled +eclipse.preferences.version=1 +incompatible_api_component_version=Error +incompatible_api_component_version_include_major_without_breaking_change=Disabled +incompatible_api_component_version_include_minor_without_api_change=Disabled +invalid_since_tag_version=Error +malformed_since_tag=Error +missing_since_tag=Warning +report_api_breakage_when_major_version_incremented=Disabled +report_resolution_errors_api_component=Warning diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/META-INF/MANIFEST.MF b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..2dd006251fb --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/META-INF/MANIFEST.MF @@ -0,0 +1,28 @@ +Manifest-Version: 1.0 +Export-Package: org.eclipse.papyrus.infra.editor.welcome.internationalization, + org.eclipse.papyrus.infra.editor.welcome.internationalization.modelelements, + org.eclipse.papyrus.infra.editor.welcome.internationalization.widgets, + org.eclipse.papyrus.infra.editor.welcome.internationalization.widgets.editors +Require-Bundle: org.eclipse.emf.ecore;bundle-version="[2.12.0,3.0.0)";visibility:=reexport, + org.eclipse.ui;bundle-version="[3.107.0,4.0.0)";visibility:=reexport, + org.eclipse.core.databinding.observable;bundle-version="[1.6.0,2.0.0)";visibility:=reexport, + org.eclipse.nebula.widgets.nattable.core;bundle-version="[1.4.0,2.0.0)";visibility:=reexport, + org.eclipse.nebula.widgets.nattable.extension.glazedlists;bundle-version="[1.4.0,2.0.0)", + ca.odell.glazedlists;bundle-version="[1.9.0,2.0.0)";visibility:=reexport, + org.eclipse.papyrus.infra.services.navigation;bundle-version="[3.0.0,4.0.0)", + org.eclipse.papyrus.infra.properties.ui;bundle-version="[2.0.0,3.0.0)";visibility:=reexport, + org.eclipse.papyrus.infra.editor.welcome;bundle-version="[1.2.0,2.0.0)", + org.eclipse.papyrus.infra.internationalization;bundle-version="[1.0.0,2.0.0)", + org.eclipse.papyrus.infra.internationalization.common;bundle-version="[1.0.0,2.0.0)", + org.eclipse.papyrus.infra.internationalization.ui;bundle-version="[1.0.0,2.0.0)", + org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="[3.0.0,4.0.0)" +Bundle-Vendor: %providerName +Bundle-ActivationPolicy: lazy +Bundle-Version: 1.0.0.qualifier +Bundle-ClassPath: . +Bundle-Localization: plugin +Bundle-Name: %pluginName +Bundle-Activator: org.eclipse.papyrus.infra.editor.welcome.internationalization.Activator +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: org.eclipse.papyrus.infra.editor.welcome.internationalization;singleton:=true +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/about.html b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/about.html new file mode 100644 index 00000000000..dd3c089a94c --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>November 14, 2008</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/build.properties b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/build.properties new file mode 100644 index 00000000000..631423469dc --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/build.properties @@ -0,0 +1,22 @@ +# +# Copyright (c) 2015 Christian W. Damus and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Christian W. Damus - Initial API and implementation +# + +bin.includes = META-INF/,\ + .,\ + about.html,\ + plugin.properties,\ + model/,\ + plugin.xml +output.. = bin/ +src.includes = about.html +source.. = src/ +bin.. = bin/ diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/model/environment.xmi b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/model/environment.xmi new file mode 100644 index 00000000000..f0090784c71 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/model/environment.xmi @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="ASCII"?> +<environment:Environment + xmi:version="2.0" + xmlns:xmi="http://www.omg.org/XMI" + xmlns:environment="http://www.eclipse.org/papyrus/properties/environment/0.9"> + <modelElementFactories + name="InternationalizationWelcomeModelElementFactory" + factoryClass="org.eclipse.papyrus.infra.editor.welcome.internationalization.modelelements.InternationalizationWelcomeModelElementFactory"/> + <namespaces + name="ppewi" + value="org.eclipse.papyrus.infra.editor.welcome.internationalization.widgets"/> +</environment:Environment> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/model/general/internationalization.ctx b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/model/general/internationalization.ctx new file mode 100644 index 00000000000..04954fd8771 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/model/general/internationalization.ctx @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="ASCII"?> +<contexts:Context xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:constraints="http://www.eclipse.org/papyrus/constraints/0.9" xmlns:contexts="http://www.eclipse.org/papyrus/properties/contexts/0.9" xmi:id="_MPALcI7eEeWNa5T2Agi7uA" name="welcome-internationalization" label="Internationalization"> + <tabs xmi:id="_SsfbQcElEeS_u7hIvAIReA" label="Internationalization" id="internationalization" category="org.eclipse.papyrus" priority="75"> + <sections xmi:id="_SsgCV8ElEeS_u7hIvAIReA" name="Single Languages" sectionFile="ui/SingleInternationalization.xwt"> + <widget href="ui/SingleInternationalization.xwt#/"/> + </sections> + </tabs> + <views xmi:id="_Ssiem8ElEeS_u7hIvAIReA" name="Single Languages" sections="_SsgCV8ElEeS_u7hIvAIReA" automaticContext="true" datacontexts="_SsmJGsElEeS_u7hIvAIReA"> + <constraints xsi:type="constraints:SimpleConstraint" xmi:id="_SskT2cElEeS_u7hIvAIReA" name="isWelcomeElement"> + <constraintType href="ppe:/environment/org.eclipse.papyrus.infra.editor.welcome/model/environment.xmi#//@constraintTypes.0"/> + <properties xsi:type="constraints:ValueProperty" xmi:id="_SskT2sElEeS_u7hIvAIReA" name="metaclassName" value="Welcome"/> + </constraints> + </views> + <dataContexts xmi:id="_SsmI-cElEeS_u7hIvAIReA" name="welcomeInternationalization" label="Welcome"> + <elements xmi:id="_SsmJGsElEeS_u7hIvAIReA" name="Internationalization"> + <properties xmi:id="_SsmJG8ElEeS_u7hIvAIReA" name="privateStorage" label="Private storage" type="Boolean" description="Determinates where the internationalization preference must be stored"/> + <properties xmi:id="_SsmJG8ElEeS_u7hIvAIReB" name="useInternationalization" label="Use internationalization" type="Boolean" description="Determinates if the internationalization must be used in the papyrus project"/> + <properties xmi:id="_SsmJG8ElEeS_u7hIvAIReC" name="language" label="Language" description="The language used for the internationalization"/> + </elements> + <modelElementFactory href="ppe:/environment/org.eclipse.papyrus.infra.editor.welcome.internationalization/model/environment.xmi#//@modelElementFactories.0"/> + </dataContexts> +</contexts:Context> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/model/general/ui/SingleInternationalization.xwt b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/model/general/ui/SingleInternationalization.xwt new file mode 100644 index 00000000000..66a074b448a --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/model/general/ui/SingleInternationalization.xwt @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Composite + xmlns:ppewi="clr-namespace:org.eclipse.papyrus.infra.editor.welcome.internationalization.widgets" + xmlns:x="http://www.eclipse.org/xwt" xmlns:ppe="clr-namespace:org.eclipse.papyrus.infra.properties.ui.widgets" + xmlns="http://www.eclipse.org/xwt/presentation" + xmlns:ppel="clr-namespace:org.eclipse.papyrus.infra.properties.ui.widgets.layout" + xmlns:j="clr-namespace:java.lang"> + <Composite.layout> + <ppel:PropertiesLayout></ppel:PropertiesLayout> + </Composite.layout> + <ppe:BooleanCheckbox input="{Binding}" + property="welcomeInternationalization:Internationalization:privateStorage"></ppe:BooleanCheckbox> + <ppe:BooleanCheckbox input="{Binding}" + property="welcomeInternationalization:Internationalization:useInternationalization"></ppe:BooleanCheckbox> + <ppewi:LanguageDialog input="{Binding}" + property="welcomeInternationalization:Internationalization:language"></ppewi:LanguageDialog> +</Composite>
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/plugin.properties b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/plugin.properties new file mode 100644 index 00000000000..556958d2ac1 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/plugin.properties @@ -0,0 +1,4 @@ +# + +pluginName=Papyrus Internationalization for Editor Welcome Page +providerName=Eclipse Modeling Project diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/plugin.xml b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/plugin.xml new file mode 100644 index 00000000000..e5b77e9ba22 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/plugin.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.2"?> + +<plugin> + <extension + point="org.eclipse.papyrus.infra.properties.contexts"> + <context + contextModel="model/general/internationalization.ctx"> + </context> + </extension> + <extension + point="org.eclipse.papyrus.infra.properties.environments"> + <environment + environmentModel="model/environment.xmi"> + </environment> + </extension> + <extension + point="org.eclipse.papyrus.infra.properties.ui.context"> + <preferencePageBinding + context="welcome-internationalization" + page="org.eclipse.papyrus.infra.editor.welcome.content"> + </preferencePageBinding> + </extension> +</plugin> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/pom.xml b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/pom.xml new file mode 100644 index 00000000000..b0450dffe5c --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/pom.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.eclipse.papyrus</groupId> + <artifactId>org.eclipse.papyrus.infra-internationalization</artifactId> + <version>0.0.1-SNAPSHOT</version> + </parent> + <artifactId>org.eclipse.papyrus.infra.editor.welcome.internationalization</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>eclipse-plugin</packaging> +</project> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/Activator.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/Activator.java new file mode 100644 index 00000000000..06e75c1c076 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/Activator.java @@ -0,0 +1,77 @@ +/***************************************************************************** + * 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.infra.editor.welcome.internationalization; + +import org.eclipse.papyrus.infra.core.log.LogHelper; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle. + */ +public class Activator extends AbstractUIPlugin { + + /** + * The plug-in ID. + */ + public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.editor.welcome.internationalization"; //$NON-NLS-1$ + + /** + * The shared instance. + */ + private static Activator plugin; + + /** + * The log helper. + */ + public static LogHelper log; + + /** + * The constructor + */ + public Activator() { + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(final BundleContext context) throws Exception { + super.start(context); + plugin = this; + log = new LogHelper(this); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(final BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/modelelements/InternationalizationWelcomeModelElement.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/modelelements/InternationalizationWelcomeModelElement.java new file mode 100644 index 00000000000..8696a73b925 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/modelelements/InternationalizationWelcomeModelElement.java @@ -0,0 +1,115 @@ +/***************************************************************************** + * 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.infra.editor.welcome.internationalization.modelelements; + +import org.eclipse.core.databinding.observable.IObservable; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElement; + +/** + * The internationalization welcome model element. + */ +public class InternationalizationWelcomeModelElement extends EMFModelElement { + + /** + * The private storage identifier. + */ + private final String PRIVATE_STORAGE = "privateStorage"; //$NON-NLS-1$ + + /** + * The useInternationalization identifier. + */ + private final String USE_INTERNATIONALIZATION = "useInternationalization"; //$NON-NLS-1$ + + /** + * The language identifier. + */ + private final String LANGUAGE = "language"; //$NON-NLS-1$ + + /** + * Constructor. + * + * @param source + * The source eObject. + * @param domain + * The current editing domain. + */ + public InternationalizationWelcomeModelElement(final EObject source, final EditingDomain domain) { + super(source, domain); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElement#doGetObservable(java.lang.String) + */ + @Override + protected IObservable doGetObservable(final String propertyPath) { + IObservable result = null; + + switch (propertyPath) { + case PRIVATE_STORAGE: + result = new PrivateInternationalizationPreferenceObservableValue(domain); + break; + case USE_INTERNATIONALIZATION: + result = new UseInternationalizationObservableValue(domain); + break; + case LANGUAGE: + result = new LanguageObservableValue(domain); + break; + default: + break; + } + + return null != result ? result : super.doGetObservable(propertyPath); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElement#isFeatureEditable(java.lang.String) + */ + @Override + protected boolean isFeatureEditable(final String propertyPath) { + boolean result; + + switch (propertyPath) { + case PRIVATE_STORAGE: + result = true; + break; + case USE_INTERNATIONALIZATION: + result = true; + break; + case LANGUAGE: + result = true; + break; + default: + result = super.isFeatureEditable(propertyPath); + break; + } + + return result; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.properties.ui.modelelement.EMFModelElement#isElementEditable() + */ + @Override + protected boolean isElementEditable() { + return true; + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/modelelements/InternationalizationWelcomeModelElementFactory.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/modelelements/InternationalizationWelcomeModelElementFactory.java new file mode 100644 index 00000000000..5dd2bdcc913 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/modelelements/InternationalizationWelcomeModelElementFactory.java @@ -0,0 +1,51 @@ +/***************************************************************************** + * 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.infra.editor.welcome.internationalization.modelelements; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.papyrus.infra.editor.welcome.internationalization.Activator; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.infra.properties.contexts.DataContextElement; +import org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractEMFModelElementFactory; + +/** + * The internationalization welcome model element factory for the welcome properties of the internationalization. + */ +public class InternationalizationWelcomeModelElementFactory extends AbstractEMFModelElementFactory<InternationalizationWelcomeModelElement> { + + /** + * Constructor. + */ + public InternationalizationWelcomeModelElementFactory() { + super(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractModelElementFactory#doCreateFromSource(java.lang.Object, org.eclipse.papyrus.infra.properties.contexts.DataContextElement) + */ + @Override + protected InternationalizationWelcomeModelElement doCreateFromSource(final Object sourceElement, final DataContextElement context) { + final EObject source = EMFHelper.getEObject(sourceElement); + if (null == source) { + Activator.log.warn("Unable to resolve the selected element to an EObject"); //$NON-NLS-1$ + return null; + } + + final EditingDomain domain = EMFHelper.resolveEditingDomain(source); + return new InternationalizationWelcomeModelElement(source, domain); + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/modelelements/LanguageObservableValue.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/modelelements/LanguageObservableValue.java new file mode 100644 index 00000000000..062a8556070 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/modelelements/LanguageObservableValue.java @@ -0,0 +1,174 @@ +/***************************************************************************** + * 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.infra.editor.welcome.internationalization.modelelements; + +import org.eclipse.core.databinding.observable.IObserving; +import org.eclipse.core.databinding.observable.value.AbstractObservableValue; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.command.UnexecutableCommand; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.emf.commands.AddEAnnotationDetailCommand; +import org.eclipse.papyrus.infra.emf.commands.AddToResourceCommand; +import org.eclipse.papyrus.infra.emf.commands.RemoveEAnnotationDetailCommand; +import org.eclipse.papyrus.infra.emf.commands.RemoveFromResourcecommand; +import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; +import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource; +import org.eclipse.papyrus.infra.internationalization.common.command.LocaleInternationalizationPreferenceCommand; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationAnnotationResourceUtils; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesConstants; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesUtils; +import org.eclipse.papyrus.infra.internationalization.modelresource.InternationalizationPreferenceModel; +import org.eclipse.papyrus.infra.internationalization.ui.Activator; +import org.eclipse.papyrus.infra.internationalization.utils.InternationalizationPreferenceModelUtils; + +/** + * The observable value for the language internationalization preference and annotation detail. + */ +public class LanguageObservableValue extends AbstractObservableValue<String> implements IObserving { + + /** + * The editing domain to execute the command. + */ + private EditingDomain domain; + + /** + * Constructor. + * + * @param domain + * The editing domain. + */ + public LanguageObservableValue(final EditingDomain domain) { + super(); + this.domain = domain; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.IObserving#getObserved() + */ + @Override + public Object getObserved() { + final InternationalizationPreferenceModel model = InternationalizationPreferenceModelUtils.getInternationalizationPreferenceModel((ModelSet) domain.getResourceSet()); + return model.getPrivateResourceURI(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType() + */ + @Override + public Object getValueType() { + return String.class; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doGetValue() + */ + @Override + protected String doGetValue() { + final InternationalizationPreferenceModel model = InternationalizationPreferenceModelUtils.getInternationalizationPreferenceModel((ModelSet) domain.getResourceSet()); + return InternationalizationPreferencesUtils.getLocalePreference(model.getPrivateResourceURI()).toString(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doSetValue(java.lang.Object) + */ + @Override + protected void doSetValue(final String value) { + final Command command = getSetCommand(value); + domain.getCommandStack().execute(command); + } + + /** + * Returns the command used to edit the value. + * + * @param value + * The new value + * @return + * The Set command used to edit the value + */ + protected Command getSetCommand(final String value) { + boolean needCreateAnnotation = true; + + final InternationalizationPreferenceModel model = InternationalizationPreferenceModelUtils.getInternationalizationPreferenceModel((ModelSet) domain.getResourceSet()); + final Resource resource = model.getResource(); + + // Search the internationalization annotation in the notation resource + EAnnotation annotation = InternationalizationAnnotationResourceUtils.getInternationalizationAnnotation(resource); + + final CompoundCommand compoundCommand = new CompoundCommand("Create internationalization command"); //$NON-NLS-1$ + + if (null != annotation) { + if (annotation.getDetails().containsKey(InternationalizationPreferencesConstants.LANGUAGE_PREFERENCE)) { + try { + final TransactionalEditingDomain domainForResource = ServiceUtilsForResource.getInstance().getTransactionalEditingDomain(resource); + + // Remove the details from annotation + compoundCommand.append(new RemoveEAnnotationDetailCommand(domainForResource, annotation, InternationalizationPreferencesConstants.LANGUAGE_PREFERENCE)); + + // If the detail is the only one, delete the annotation + if (1 == annotation.getDetails().size()) { + compoundCommand.append(new RemoveFromResourcecommand(domainForResource, resource, annotation)); + } else { + needCreateAnnotation = false; + } + } catch (final ServiceException e) { + Activator.log.error(e); + } + } else { + needCreateAnnotation = false; + } + } + + if (null != value) { + // Create the annotation if the internationalization value + // is not false + if (needCreateAnnotation) { + annotation = EcoreFactory.eINSTANCE.createEAnnotation(); + annotation + .setSource(InternationalizationPreferencesConstants.INTERNATIONALIZATION_ANNOTATION_LABEL); + annotation.getDetails().put(InternationalizationPreferencesConstants.LANGUAGE_PREFERENCE, + value); + compoundCommand.append(new GMFtoEMFCommandWrapper(new AddToResourceCommand(((ModelSet) resource.getResourceSet()).getTransactionalEditingDomain(), resource, annotation))); + } else { + try { + final TransactionalEditingDomain domainForResource = ServiceUtilsForResource.getInstance().getTransactionalEditingDomain(resource); + + compoundCommand.append(new AddEAnnotationDetailCommand(domainForResource, annotation, InternationalizationPreferencesConstants.LANGUAGE_PREFERENCE, value)); + } catch (final ServiceException e) { + Activator.log.error(e); + } + } + + // Manage the preference by command + compoundCommand.append(new LocaleInternationalizationPreferenceCommand(model.getPrivateResourceURI(), + value)); + } + + return !compoundCommand.getCommandList().isEmpty() ? compoundCommand : UnexecutableCommand.INSTANCE; + } +}
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/modelelements/PrivateInternationalizationPreferenceObservableValue.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/modelelements/PrivateInternationalizationPreferenceObservableValue.java new file mode 100644 index 00000000000..8ec4e6ad70b --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/modelelements/PrivateInternationalizationPreferenceObservableValue.java @@ -0,0 +1,171 @@ +/***************************************************************************** + * 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.infra.editor.welcome.internationalization.modelelements; + +import static org.eclipse.core.databinding.observable.Diffs.createValueDiff; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Objects; + +import org.eclipse.core.databinding.observable.Diffs; +import org.eclipse.core.databinding.observable.Realm; +import org.eclipse.core.databinding.observable.value.AbstractObservableValue; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.editor.welcome.internationalization.Activator; +import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceSet; +import org.eclipse.papyrus.infra.internationalization.commands.InternationalizationPreferenceCommandFactory; +import org.eclipse.papyrus.infra.internationalization.modelresource.InternationalizationPreferenceModel; +import org.eclipse.papyrus.infra.internationalization.utils.InternationalizationPreferenceModelUtils; +import org.eclipse.papyrus.infra.ui.editor.IMultiDiagramEditor; + +/** + * Encapsulation of the "shared layout" property of the Papyrus Editor. + */ +public class PrivateInternationalizationPreferenceObservableValue extends AbstractObservableValue<Boolean> implements PropertyChangeListener { + + /** + * The internationalization preference model. + */ + private InternationalizationPreferenceModel internationalizationPrefModel; + + /** + * The current editing domain. + */ + protected final EditingDomain domain; + + /** + * Constructor. + * + * @param domain + * The current editing domain. + */ + public PrivateInternationalizationPreferenceObservableValue(final EditingDomain domain) { + this(Realm.getDefault(), domain); + } + + /** + * Constructor. + * + * @param realm + * The {@link Realm}. + * @param domain + * The current editing domain. + */ + public PrivateInternationalizationPreferenceObservableValue(final Realm realm, final EditingDomain domain) { + super(realm); + + this.domain = domain; + + internationalizationPrefModel = InternationalizationPreferenceModelUtils.getInternationalizationPreferenceModel((ModelSet) domain.getResourceSet()); + if (null != internationalizationPrefModel) { + internationalizationPrefModel.addPropertyChangeListener(InternationalizationPreferenceModel.PROPERTY_LEGACY_MODE, this); + } + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.AbstractObservable#dispose() + */ + @Override + public synchronized void dispose() { + if (null != internationalizationPrefModel) { + internationalizationPrefModel.removePropertyChangeListener(InternationalizationPreferenceModel.PROPERTY_LEGACY_MODE, this); + internationalizationPrefModel = null; + } + + super.dispose(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doGetValue() + */ + @Override + protected Boolean doGetValue() { + return internationalizationPrefModel.isLegacyMode(); + } + + /** + * Get the command for the private storage. + * + * @param factory + * The factory to create the command. + * @return The command to manage the private storage. + */ + protected Command getToggleCommand(final InternationalizationPreferenceCommandFactory factory) { + return factory.createTogglePrivateStorageCommand(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType() + */ + @Override + public Object getValueType() { + return Boolean.class; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doSetValue(java.lang.Object) + */ + @Override + protected void doSetValue(final Boolean value) { + Boolean oldValue = getValue(); + if (!Objects.equals(oldValue, value)) { + IMultiDiagramEditor editor; + + try { + editor = ServiceUtilsForResourceSet.getInstance().getService(IMultiDiagramEditor.class, domain.getResourceSet()); + final ModelSet modelSet = (ModelSet) editor.getAdapter(EditingDomain.class).getResourceSet(); + final Command command = getToggleCommand(new InternationalizationPreferenceCommandFactory(modelSet)); + if (command.canExecute()) { + // Don't do this in an undoable command on the history + try { + domain.getCommandStack().execute(command); + fireValueChange(Diffs.createValueDiff(oldValue, value)); + } catch (Exception e) { + Activator.log.error("Failed to toggle editor page layout option", e); //$NON-NLS-1$ + } + } + } catch (final ServiceException e) { + throw new IllegalStateException("No editor available in the service registry", e); //$NON-NLS-1$ + } + } + } + + /** + * {@inheritDoc} + * + * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) + */ + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getSource() == internationalizationPrefModel) { + switch (evt.getPropertyName()) { + case InternationalizationPreferenceModel.PROPERTY_LEGACY_MODE: + fireValueChange(createValueDiff(!(Boolean) evt.getOldValue(), !(Boolean) evt.getNewValue())); + break; + } + } + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/modelelements/UseInternationalizationObservableValue.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/modelelements/UseInternationalizationObservableValue.java new file mode 100644 index 00000000000..d90e174f181 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/modelelements/UseInternationalizationObservableValue.java @@ -0,0 +1,165 @@ +/***************************************************************************** + * 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.infra.editor.welcome.internationalization.modelelements; + +import org.eclipse.core.databinding.observable.value.AbstractObservableValue; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.command.UnexecutableCommand; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.emf.commands.AddEAnnotationDetailCommand; +import org.eclipse.papyrus.infra.emf.commands.AddToResourceCommand; +import org.eclipse.papyrus.infra.emf.commands.RemoveEAnnotationDetailCommand; +import org.eclipse.papyrus.infra.emf.commands.RemoveFromResourcecommand; +import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; +import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource; +import org.eclipse.papyrus.infra.internationalization.common.command.UseInternationalizationPreferenceCommand; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationAnnotationResourceUtils; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesConstants; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesUtils; +import org.eclipse.papyrus.infra.internationalization.modelresource.InternationalizationPreferenceModel; +import org.eclipse.papyrus.infra.internationalization.ui.Activator; +import org.eclipse.papyrus.infra.internationalization.utils.InternationalizationPreferenceModelUtils; + +/** + * The observable value for the use internationalization preference and annotation detail. + */ +public class UseInternationalizationObservableValue extends AbstractObservableValue<Boolean> { + + /** + * The editing domain to execute the command. + */ + private EditingDomain domain; + + /** + * Constructor. + * + * @param domain + * The editing domain. + */ + public UseInternationalizationObservableValue(final EditingDomain domain) { + super(); + this.domain = domain; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType() + */ + @Override + public Object getValueType() { + return Boolean.class; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doGetValue() + */ + @Override + protected Boolean doGetValue() { + final InternationalizationPreferenceModel model = InternationalizationPreferenceModelUtils.getInternationalizationPreferenceModel((ModelSet) domain.getResourceSet()); + return InternationalizationPreferencesUtils.getInternationalizationPreference(model.getPrivateResourceURI()); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doSetValue(java.lang.Object) + */ + @Override + protected void doSetValue(final Boolean value) { + final Command command = getSetCommand(value); + domain.getCommandStack().execute(command); + } + + /** + * Returns the command used to edit the value. + * + * @param value + * The new value + * @return + * The Set command used to edit the value + */ + protected Command getSetCommand(final Boolean value) { + boolean needCreateAnnotation = true; + + final InternationalizationPreferenceModel model = InternationalizationPreferenceModelUtils.getInternationalizationPreferenceModel((ModelSet) domain.getResourceSet()); + final Resource resource = model.getResource(); + + // Search the internationalization annotation in the notation resource + EAnnotation annotation = InternationalizationAnnotationResourceUtils.getInternationalizationAnnotation(resource); + + final CompoundCommand compoundCommand = new CompoundCommand("Create internationalization command"); //$NON-NLS-1$ + + if (null != annotation) { + if (annotation.getDetails().containsKey(InternationalizationPreferencesConstants.USE_DETAIL_ANNOTATION_LABEL)) { + try { + final TransactionalEditingDomain domainForResource = ServiceUtilsForResource.getInstance().getTransactionalEditingDomain(resource); + + // Remove the details from annotation + compoundCommand.append(new RemoveEAnnotationDetailCommand(domainForResource, annotation, InternationalizationPreferencesConstants.USE_DETAIL_ANNOTATION_LABEL)); + + // If the detail is the only one, delete the annotation + if (1 == annotation.getDetails().size()) { + compoundCommand.append(new RemoveFromResourcecommand(domainForResource, resource, annotation)); + } else { + needCreateAnnotation = false; + } + } catch (final ServiceException e) { + Activator.log.error(e); + } + + // Remove the preference by command + compoundCommand.append(new UseInternationalizationPreferenceCommand(model.getPrivateResourceURI(), false)); + } else { + needCreateAnnotation = false; + } + } + + if (value) { + // Create the annotation if the internationalization value + // is not false + if (needCreateAnnotation) { + annotation = EcoreFactory.eINSTANCE.createEAnnotation(); + annotation.setSource(InternationalizationPreferencesConstants.INTERNATIONALIZATION_ANNOTATION_LABEL); + annotation.getDetails().put( + InternationalizationPreferencesConstants.USE_DETAIL_ANNOTATION_LABEL, + Boolean.toString(value)); + compoundCommand.append(new GMFtoEMFCommandWrapper(new AddToResourceCommand(((ModelSet) resource.getResourceSet()).getTransactionalEditingDomain(), resource, annotation))); + } else { + try { + final TransactionalEditingDomain domainForResource = ServiceUtilsForResource.getInstance().getTransactionalEditingDomain(resource); + + compoundCommand.append(new AddEAnnotationDetailCommand(domainForResource, annotation, InternationalizationPreferencesConstants.USE_DETAIL_ANNOTATION_LABEL, Boolean.toString(value))); + } catch (final ServiceException e) { + Activator.log.error(e); + } + } + + // Manage the preference by command + compoundCommand.append(new UseInternationalizationPreferenceCommand(model.getPrivateResourceURI(), + value)); + } + + return !compoundCommand.getCommandList().isEmpty() ? compoundCommand : UnexecutableCommand.INSTANCE; + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/widgets/LanguageDialog.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/widgets/LanguageDialog.java new file mode 100644 index 00000000000..240b2ed864f --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/widgets/LanguageDialog.java @@ -0,0 +1,55 @@ +/***************************************************************************** + * 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.infra.editor.welcome.internationalization.widgets; + +import org.eclipse.papyrus.infra.properties.ui.widgets.AbstractPropertyEditor; +import org.eclipse.swt.widgets.Composite; + +/** + * The language property dialog widget for the internationalization. + */ +public class LanguageDialog extends AbstractPropertyEditor { + + /** + * The LanguageDialog widget. + */ + protected org.eclipse.papyrus.infra.editor.welcome.internationalization.widgets.editors.LanguageDialog editor; + + /** + * Constructor. + * + * @param parent + * The composite in which the widget will be displayed. + * @param style + * The style for the widget. + */ + public LanguageDialog(final Composite parent, final int style) { + setEditor(createLanguageDialogEditor(parent, style)); + } + + /** + * Creates the language dialog. + * + * @param parent + * The composite in which the widget will be displayed. + * @param style + * The style for the widget. + * @return The language dialog. + */ + protected org.eclipse.papyrus.infra.editor.welcome.internationalization.widgets.editors.LanguageDialog createLanguageDialogEditor( + final Composite parent, final int style) { + return editor = new org.eclipse.papyrus.infra.editor.welcome.internationalization.widgets.editors.LanguageDialog(parent, style); + } + +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/widgets/editors/LanguageDialog.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/widgets/editors/LanguageDialog.java new file mode 100644 index 00000000000..c5a7a4820c7 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.editor.welcome.internationalization/src/org/eclipse/papyrus/infra/editor/welcome/internationalization/widgets/editors/LanguageDialog.java @@ -0,0 +1,266 @@ +/***************************************************************************** + * 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.infra.editor.welcome.internationalization.widgets.editors; + +import java.util.Locale; + +import org.eclipse.core.databinding.observable.IObserving; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.emf.common.util.URI; +import org.eclipse.jface.fieldassist.ControlDecoration; +import org.eclipse.jface.fieldassist.FieldDecorationRegistry; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesUtils; +import org.eclipse.papyrus.infra.internationalization.ui.dialogs.InternationalizationDialog; +import org.eclipse.papyrus.infra.widgets.Activator; +import org.eclipse.papyrus.infra.widgets.editors.AbstractValueEditor; +import org.eclipse.papyrus.infra.widgets.messages.Messages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +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.Shell; +import org.eclipse.swt.widgets.Widget; + +/** + * This allows to define the language editor. + */ +public class LanguageDialog extends AbstractValueEditor implements SelectionListener { + + /** + * The CLabel displaying the current value. + */ + protected final CLabel currentValueLabel; + + /** + * The Button used to modify the value. + */ + protected Button modifyValuesButton; + + /** + * The dialog used to select the internationalization value. + */ + protected final InternationalizationDialog dialog; + + /** + * The current value for this editor + */ + protected Object value; + + /** + * Boolean to determinate if the editors are read-only. + */ + protected boolean readOnly; + + /** + * Constructs a new LanguageDialog in the given parent Composite. The style + * will be applied to the CLabel displaying the current value. + * + * @param parent + * The parent composite. + * @param style + * The style of the composites. + */ + public LanguageDialog(final Composite parent, final int style) { + super(parent, style); + final GridData gridData = getDefaultLayoutData(); + + currentValueLabel = factory.createCLabel(this, null, factory.getBorderStyle() | style); + currentValueLabel.setLayoutData(gridData); + currentValueLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mouseDoubleClick(MouseEvent e) { + editAction(); + } + + }); + + dialog = createDialog(parent.getShell()); + + createButton(); + updateControls(); + controlDecoration = new ControlDecoration(currentValueLabel, SWT.TOP | SWT.LEFT); + + gridData.horizontalIndent = FieldDecorationRegistry.getDefault().getMaximumDecorationWidth(); + } + + /** + * This allows to create the internationalization language dialog. + * + * @param shell + * The parent shell. + * @return The created dialog. + */ + protected InternationalizationDialog createDialog(final Shell shell) { + return new InternationalizationDialog(shell, null, false); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.widgets.editors.AbstractValueEditor#setModelObservable(org.eclipse.core.databinding.observable.value.IObservableValue) + */ + @SuppressWarnings("rawtypes") + @Override + public void setModelObservable(final IObservableValue modelProperty) { + super.setModelObservable(modelProperty); + + if (modelProperty instanceof IObserving) { + Object observed = ((IObserving) modelProperty).getObserved(); + if (observed instanceof URI) { + URI resourceURI = (URI) observed; + dialog.setResourceURI(resourceURI); + + final String localeAsString = InternationalizationPreferencesUtils.getLocalePreference(resourceURI).toString(); + currentValueLabel.setText(localeAsString); + } + } + } + + /** + * This allow to create the buttons. + */ + protected void createButton() { + ((GridLayout) getLayout()).numColumns += 1; + + modifyValuesButton = factory.createButton(this, null, SWT.PUSH); + modifyValuesButton.setImage(Activator.getDefault().getImage("/icons/Edit_12x12.gif")); //$NON-NLS-1$ + modifyValuesButton.setToolTipText(Messages.ReferenceDialog_EditValue); + modifyValuesButton.addSelectionListener(this); + } + + /** + * The action executed when the "edit" button is selected Edits the object + * that is currently selected + */ + protected void editAction() { + int result = dialog.open(); + if (Window.OK == result) { + final Locale newValue = dialog.getLocaleValue(); + if (null != newValue) { + setValue(newValue.toString()); + } + } + } + + /** + * This allows to update the controls. + */ + protected void updateControls() { + modifyValuesButton.setEnabled(!readOnly); + } + + /** + * This allows to update the label text. + */ + protected void updateLabel() { + currentValueLabel.setText((String) getValue()); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.widgets.editors.AbstractValueEditor#getValue() + */ + @Override + public Object getValue() { + if (modelProperty != null) { + return modelProperty.getValue(); + } + return value; + } + + /** + * Set the value. + * + * @param value + * The value to set. + */ + @SuppressWarnings("unchecked") + protected void setValue(final Object value) { + this.value = value; + try { + if (modelProperty != null) { + modelProperty.setValue(value); + } + } catch (Exception e) { + // Do nothing + } + + updateLabel(); + commit(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.widgets.editors.AbstractEditor#getEditableType() + */ + @Override + public Object getEditableType() { + return Object.class; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.widgets.editors.AbstractEditor#setReadOnly(boolean) + */ + @Override + public void setReadOnly(final boolean readOnly) { + this.readOnly = readOnly; + updateControls(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.widgets.editors.AbstractEditor#isReadOnly() + */ + @Override + public boolean isReadOnly() { + return readOnly; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) + */ + @Override + public void widgetSelected(final SelectionEvent e) { + Widget widget = e.widget; + if (widget == modifyValuesButton) { + editAction(); + } + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) + */ + @Override + public void widgetDefaultSelected(final SelectionEvent e) { + // Do nothing + } + +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/.classpath b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/.classpath new file mode 100644 index 00000000000..eca7bdba8f0 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/.project b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/.project new file mode 100644 index 00000000000..89db6d88791 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/.project @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.papyrus.infra.internationalization.common</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.oomph.version.VersionBuilder</name> + <arguments> + <dictionary> + <key>check.maven.pom</key> + <value>true</value> + </dictionary> + <dictionary> + <key>ignore.lower.bound.dependency.ranges</key> + <value>true</value> + </dictionary> + <dictionary> + <key>release.path</key> + <value>/org.eclipse.papyrus.releng.main.release/release.xml</value> + </dictionary> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.oomph.version.VersionNature</nature> + <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature> + </natures> +</projectDescription> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/.settings/org.eclipse.jdt.core.prefs b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..0c68a61dca8 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/META-INF/MANIFEST.MF b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..d0413afa7d4 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.infra.internationalization.common;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-ClassPath: . +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: org.eclipse.papyrus.infra.internationalization.common, + org.eclipse.papyrus.infra.internationalization.common.command, + org.eclipse.papyrus.infra.internationalization.common.editor, + org.eclipse.papyrus.infra.internationalization.common.utils +Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.12.0,4.0.0)", + org.eclipse.emf.ecore;bundle-version="[2.12.0,3.0.0)";visibility:=reexport, + org.eclipse.papyrus.infra.core.log;bundle-version="[1.2.0,2.0.0)", + org.eclipse.ui.workbench;bundle-version="[3.108.0,4.0.0)", + org.eclipse.papyrus.infra.ui;bundle-version="[2.0.0,3.0.0)", + org.eclipse.jface;bundle-version="[3.12.0,4.0.0)" +Bundle-ActivationPolicy: lazy +Bundle-Activator: org.eclipse.papyrus.infra.internationalization.common.Activator diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/about.html b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/about.html new file mode 100644 index 00000000000..598b3684879 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>May 12, 2008</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/build.properties b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/build.properties new file mode 100644 index 00000000000..2964bc2d7b1 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/build.properties @@ -0,0 +1,11 @@ +# + +bin.includes = .,\ + META-INF/,\ + about.html,\ + plugin.xml,\ + plugin.properties +jars.compile.order = . +source.. = src/ +output.. = bin/ +src.includes = about.html diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/plugin.properties b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/plugin.properties new file mode 100644 index 00000000000..a4775a24081 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/plugin.properties @@ -0,0 +1,4 @@ +# + +pluginName = Papyrus Internationalization Common +providerName = Eclipse Modeling Project diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/plugin.xml b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/plugin.xml new file mode 100644 index 00000000000..7ac51d15095 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/plugin.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> + +<!-- +--> + +<plugin> + +</plugin> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/pom.xml b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/pom.xml new file mode 100644 index 00000000000..8f8eae08258 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/pom.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>org.eclipse.papyrus.infra-internationalization</artifactId> + <groupId>org.eclipse.papyrus</groupId> + <version>0.0.1-SNAPSHOT</version> + </parent> + <artifactId>org.eclipse.papyrus.infra.internationalization.common</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>eclipse-plugin</packaging> +</project>
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/Activator.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/Activator.java new file mode 100644 index 00000000000..ae1975d5007 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/Activator.java @@ -0,0 +1,153 @@ +/***************************************************************************** + * 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.infra.internationalization.common; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.papyrus.infra.core.log.LogHelper; +import org.eclipse.papyrus.infra.core.resource.PapyrusProjectScope; +import org.eclipse.papyrus.infra.ui.preferences.PapyrusScopedPreferenceStore; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.ui.preferences.ScopedPreferenceStore; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle. + */ +public class Activator extends AbstractUIPlugin { + + /** + * The plug-in ID. + */ + public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.internationalization.common"; //$NON-NLS-1$ + + /** + * The internationalization preference node label. + */ + public static final String INTERNATIONALIZATION_NODE_LABEL = "internationalization"; //$NON-NLS-1$ + + /** + * The shared instance. + */ + private static Activator plugin; + + /** + * The log helper. + */ + public static LogHelper log; + + /** + * Storage for preferences. Use a list of preference store (one preference + * store by internationalization of a project). + */ + private List<IPreferenceStore> preferencesStore; + + /** + * The constructor + */ + public Activator() { + preferencesStore = new ArrayList<IPreferenceStore>(0); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(final BundleContext context) throws Exception { + super.start(context); + plugin = this; + log = new LogHelper(this); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(final BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Get the preference store and create it if necessary. + * + * @param project + * The current project + * @param papyrusProjectName + * The current papyrus project name. + * @return The preference store. + */ + public IPreferenceStore getInternationalizationPreferenceStore(final IProject project, + final String papyrusProjectName) { + IPreferenceStore result = null; + final IScopeContext scope = new PapyrusProjectScope(project, papyrusProjectName); + if (!preferencesStore.isEmpty()) { + final IEclipsePreferences scopePreferenceNode = scope.getNode(INTERNATIONALIZATION_NODE_LABEL); + final Iterator<IPreferenceStore> preferenceStoreIterator = preferencesStore.iterator(); + while (preferenceStoreIterator.hasNext() && null == result) { + final IPreferenceStore preferenceStore = preferenceStoreIterator.next(); + if (preferenceStore instanceof PapyrusScopedPreferenceStore) { + final IEclipsePreferences[] preferenceNodes = ((PapyrusScopedPreferenceStore) preferenceStore) + .getPreferenceNodes(false); + for (int index = 0; index < preferenceNodes.length && null == result; index++) { + if (preferenceNodes[index].equals(scopePreferenceNode)) { + result = preferenceStore; + } + } + } + } + } + + if (null == result) { + result = new PapyrusScopedPreferenceStore(scope, INTERNATIONALIZATION_NODE_LABEL); + preferencesStore.add(result); // $NON-NLS-1$ + } + + return result; + } + + /** + * Get the first preference store if existing, else a scoped preference + * store must be created and added to the list of preferences store. + * + * @return The preference store. + */ + public IPreferenceStore getInternationalizationPreferenceStore() { + // Create the preference store lazily. + if (preferencesStore.isEmpty()) { + preferencesStore.add(new ScopedPreferenceStore(InstanceScope.INSTANCE, getBundle().getSymbolicName())); + } + return preferencesStore.get(0); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/command/LocaleInternationalizationPreferenceCommand.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/command/LocaleInternationalizationPreferenceCommand.java new file mode 100644 index 00000000000..4d907295efc --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/command/LocaleInternationalizationPreferenceCommand.java @@ -0,0 +1,98 @@ +/***************************************************************************** + * 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.infra.internationalization.common.command; + +import org.eclipse.emf.common.command.AbstractCommand; +import org.eclipse.emf.common.util.URI; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesUtils; + +/** + * The command to modify the internationalization preference. We can't use the + * RecordingCommand because the modification are not applied to a resource + * directly. + */ +public class LocaleInternationalizationPreferenceCommand extends AbstractCommand { + + /** + * The current resource URI corresponding to the internationalization + * preference. + */ + protected URI resourceURI; + + /** + * The new language value. + */ + protected String newLanguageValue; + + /** + * The old language value. + */ + protected String oldLanguageValue; + + /** + * Constructor. + * + * @param resourceURI + * The current resource URI. + * @param newLanguageValue + * The new language value. + */ + public LocaleInternationalizationPreferenceCommand(final URI resourceURI, final String newLanguageValue) { + super("Modify locale internationalization preference"); //$NON-NLS-1$ + this.resourceURI = resourceURI; + this.newLanguageValue = newLanguageValue; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.Command#execute() + */ + @Override + public void execute() { + oldLanguageValue = InternationalizationPreferencesUtils.getLocalePreference(resourceURI).toString(); + InternationalizationPreferencesUtils.setLanguagePreference(resourceURI, newLanguageValue); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.AbstractCommand#undo() + */ + @Override + public void undo() { + InternationalizationPreferencesUtils.setLanguagePreference(resourceURI, oldLanguageValue); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.Command#redo() + */ + @Override + public void redo() { + InternationalizationPreferencesUtils.setLanguagePreference(resourceURI, newLanguageValue); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.AbstractCommand#prepare() + */ + @Override + protected boolean prepare() { + return null != resourceURI; + } + +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/command/UseInternationalizationPreferenceCommand.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/command/UseInternationalizationPreferenceCommand.java new file mode 100644 index 00000000000..887e31d851c --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/command/UseInternationalizationPreferenceCommand.java @@ -0,0 +1,98 @@ +/***************************************************************************** + * 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.infra.internationalization.common.command; + +import org.eclipse.emf.common.command.AbstractCommand; +import org.eclipse.emf.common.util.URI; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesUtils; + +/** + * The command to modify the internationalization preference. We can't use the + * RecordingCommand because the modification are not applied to a resource + * directly. + */ +public class UseInternationalizationPreferenceCommand extends AbstractCommand { + + /** + * The current resource URI corresponding to the internationalization + * preference. + */ + protected URI resourceURI; + + /** + * The new boolean value. + */ + protected boolean newBooleanValue; + + /** + * The old boolean value. + */ + protected boolean oldBooleanValue; + + /** + * Constructor. + * + * @param resourceURI + * The current resource URI. + * @param newBooleanValue + * The new boolean value. + */ + public UseInternationalizationPreferenceCommand(final URI resourceURI, final boolean newBooleanValue) { + super("Modify use internationalization preference"); //$NON-NLS-1$ + this.resourceURI = resourceURI; + this.newBooleanValue = newBooleanValue; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.Command#execute() + */ + @Override + public void execute() { + oldBooleanValue = InternationalizationPreferencesUtils.getInternationalizationPreference(resourceURI); + InternationalizationPreferencesUtils.setInternationalizationPreference(resourceURI, newBooleanValue); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.AbstractCommand#undo() + */ + @Override + public void undo() { + InternationalizationPreferencesUtils.setInternationalizationPreference(resourceURI, oldBooleanValue); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.Command#redo() + */ + @Override + public void redo() { + InternationalizationPreferencesUtils.setInternationalizationPreference(resourceURI, newBooleanValue); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.AbstractCommand#prepare() + */ + @Override + protected boolean prepare() { + return null != resourceURI; + } + +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/editor/IInternationalizationEditor.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/editor/IInternationalizationEditor.java new file mode 100644 index 00000000000..40b46182a1f --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/editor/IInternationalizationEditor.java @@ -0,0 +1,34 @@ +/***************************************************************************** + * 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.infra.internationalization.common.editor; + +/** + * Interface to define if the editor support the internationalization and the corresponding label modification. + */ +public interface IInternationalizationEditor { + + /** + * This allows to modify the part name. + * + * @param name + * The new name of the editor. + */ + public void modifyPartName(final String name); + + /** + * This allows to refresh the editor part. + */ + public void refreshEditorPart(); + +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationAnnotationResourceUtils.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationAnnotationResourceUtils.java new file mode 100644 index 00000000000..5da45e6d9fd --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationAnnotationResourceUtils.java @@ -0,0 +1,49 @@ +/***************************************************************************** + * 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.infra.internationalization.common.utils; + +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; + +/** + * Define the utils method corresponding to the internationalization annotation + * and its resource. + */ +public class InternationalizationAnnotationResourceUtils { + + /** + * This allows to get the annotation corresponding to the + * internationalization in the resource in parameter if exists. + * + * @param resource + * The resource to check + * @return The internationalization annotation if exists, <code>null</code> + * otherwise. + */ + public static EAnnotation getInternationalizationAnnotation(final Resource resource) { + EAnnotation result = null; + + for (final EObject objectContent : resource.getContents()) { + if (objectContent instanceof EAnnotation + && InternationalizationPreferencesConstants.INTERNATIONALIZATION_ANNOTATION_LABEL + .equals(((EAnnotation) objectContent).getSource())) { + result = (EAnnotation) objectContent; + } + } + + return result; + } + +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferencesConstants.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferencesConstants.java new file mode 100644 index 00000000000..b7bf90ed5c0 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferencesConstants.java @@ -0,0 +1,41 @@ +/***************************************************************************** + * 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.infra.internationalization.common.utils; + +/** + * This class defines the constants for the internationalization preferences. + */ +public class InternationalizationPreferencesConstants { + + /** + * The internationalization preference label. + */ + public static final String USE_INTERNATIONALIZATION_PREFERENCE = "useInternationalization"; //$NON-NLS-1$ + + /** + * The label for the internationalization annotation. + */ + public static final String INTERNATIONALIZATION_ANNOTATION_LABEL = "Internationalization"; //$NON-NLS-1$ + + /** + * The label of the internationalization annotation detail. + */ + public static final String USE_DETAIL_ANNOTATION_LABEL = "use"; //$NON-NLS-1$ + + /** + * The language preference name. + */ + public static final String LANGUAGE_PREFERENCE = "language"; //$NON-NLS-1$ + +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferencesUtils.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferencesUtils.java new file mode 100644 index 00000000000..58cb94f1f35 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/InternationalizationPreferencesUtils.java @@ -0,0 +1,296 @@ +/***************************************************************************** + * 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.infra.internationalization.common.utils; + +import java.util.Locale; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Path; +import org.eclipse.emf.common.CommonPlugin; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.papyrus.infra.internationalization.common.Activator; + +/** + * The internationalization preference utils methods which allow to get or + * change the internationalization preference value. + */ +public class InternationalizationPreferencesUtils { + + /** + * Get the preference store for the project containing the {@link EObject} + * in parameter. + * + * @param eObject + * The eObject. + * @return The preference store for the project containing the EObject. + */ + public static IPreferenceStore getPreferenceStore(final EObject eObject) { + return getPreferenceStore(getRootContainer(eObject).eResource()); + } + + /** + * Get the preference store for the project containing the {@link Resource} + * in parameter. + * + * @param resource + * The resource. + * @return The preference store for the project containing the Resource. + */ + public static IPreferenceStore getPreferenceStore(final Resource resource) { + IPreferenceStore result = null; + + if (null != resource) { + result = getPreferenceStore(resource.getURI()); + } + + return result; + } + + /** + * Get the preference store for the project containing the resource + * {@link URI} in parameter. + * + * @param resource + * The resource. + * @return The preference store for the project containing the resource URI. + */ + public static IPreferenceStore getPreferenceStore(final URI uri) { + IPreferenceStore result = null; + + if (null != uri) { + final String filePathString = CommonPlugin.resolve(uri).toFileString(); + + if (null != filePathString) { + final IFile resourceFile = ResourcesPlugin.getWorkspace().getRoot() + .getFileForLocation(new Path(filePathString)); + + if (null != resourceFile) { + final IProject currentProject = resourceFile.getProject(); + final String papyrusProjectName = uri.trimFileExtension().lastSegment(); + + if (null != currentProject && !papyrusProjectName.isEmpty()) { + result = Activator.getDefault().getInternationalizationPreferenceStore(currentProject, + papyrusProjectName); + } + } + } + } + + return result; + } + + /** + * This allows to modify the internationalization preference value. + * + * @param eObject + * The {@link EObject) corresponding (to get its resource). + * @param value + * The new preference value. + */ + public static void setInternationalizationPreference(final EObject eObject, final boolean value) { + setInternationalizationPreference(getRootContainer(eObject).eResource(), value); + } + + /** + * This allows to modify the internationalization preference value. + * + * @param resource + * The {@link Resource) to get the papyrus project preferences. + * @param value + * The new preference value. + */ + public static void setInternationalizationPreference(final Resource resource, final boolean value) { + setInternationalizationPreference(resource.getURI(), value); + } + + /** + * This allows to modify the internationalization preference value. + * + * @param resourceURI + * The resource URI to get the papyrus project preferences. + * @param value + * The new preference value. + */ + public static void setInternationalizationPreference(final URI resourceURI, final boolean value) { + final IPreferenceStore preferenceStore = getPreferenceStore(resourceURI); + + if (null != preferenceStore) { + preferenceStore.setValue(InternationalizationPreferencesConstants.USE_INTERNATIONALIZATION_PREFERENCE, + value); + } + } + + /** + * This allows to get the internationalization preference value. + * + * @param eObject + * The {@link EObject) corresponding (to get its resource). + * @return <code>true</code> if the preference value is set to true, + * <code>false</code> otherwise. + */ + public static boolean getInternationalizationPreference(final EObject eObject) { + boolean result = false; + if(null != eObject.eResource()){ + result = getInternationalizationPreference(getRootContainer(eObject).eResource()); + } + return result; + } + + /** + * This allows to get the internationalization preference value. + * + * @param resource + * The {@link Resource) to get the papyrus project preferences. + * @return <code>true</code> if the preference value is set to true, + * <code>false</code> otherwise. + */ + public static boolean getInternationalizationPreference(final Resource resource) { + return getInternationalizationPreference(resource.getURI()); + } + + /** + * This allows to get the internationalization preference value. + * + * @param resourceURI + * The resource URI to get the papyrus project preferences. + * @return <code>true</code> if the preference value is set to true, + * <code>false</code> otherwise. + */ + public static boolean getInternationalizationPreference(final URI resourceURI) { + boolean result = false; + + final IPreferenceStore preferenceStore = getPreferenceStore(resourceURI); + + if (null != preferenceStore && preferenceStore + .contains(InternationalizationPreferencesConstants.USE_INTERNATIONALIZATION_PREFERENCE)) { + result = preferenceStore + .getBoolean(InternationalizationPreferencesConstants.USE_INTERNATIONALIZATION_PREFERENCE); + } + + return result; + } + + /** + * Get the language preference (create it with the current locale if not + * existing). + * + * @param resource + * The {@link Resource) to get the papyrus project preferences. + * @return The language in the preferences. + */ + private static String getLanguagePreference(final URI uri) { + String result = null; + + final IPreferenceStore preferenceStore = getPreferenceStore(uri); + if (null != preferenceStore + && preferenceStore.contains(InternationalizationPreferencesConstants.LANGUAGE_PREFERENCE)) { + result = preferenceStore.getString(InternationalizationPreferencesConstants.LANGUAGE_PREFERENCE); + } + + return result; + } + + /** + * Get the locale preference created from the language preference. + * + * @param eObject + * The {@link EObject) corresponding (to get its resource). + * @return The locale preference. + */ + public static Locale getLocalePreference(final EObject eObject) { + return getLocalePreference(getRootContainer(eObject).eResource().getURI()); + } + + /** + * Get the locale preference created from the language preference. + * + * @param resource + * The {@link Resource) to get the papyrus project preferences. + * @return The locale preference. + */ + public static Locale getLocalePreference(final URI uri) { + final String localePreference = getLanguagePreference(uri); + + Locale result = null; + + if (null != localePreference) { + result = LocaleNameResolver.getLocaleFromString(localePreference); + } else { + result = Locale.getDefault(); + } + + return result; + } + + /** + * This allows to set the language preference. + * + * @param eObject + * The {@link EObject) corresponding (to get its resource). + * @param language + * The language to set. + */ + public static void setLanguagePreference(final EObject eObject, final String language) { + setLanguagePreference(getRootContainer(eObject).eResource(), language); + } + + /** + * This allows to set the language preference. + * + * @param resource + * The {@link Resource) to get the papyrus project preferences. + * @param language + * The language to set. + */ + public static void setLanguagePreference(final Resource resource, final String language) { + setLanguagePreference(resource.getURI(), language); + } + + /** + * This allows to set the language preference. + * + * @param resourceURI + * The resource URI to get the papyrus project preferences. + * @param language + * The language to set. + */ + public static void setLanguagePreference(final URI resourceURI, final String language) { + final IPreferenceStore preferenceStore = getPreferenceStore(resourceURI); + + if (null != preferenceStore) { + preferenceStore.setValue(InternationalizationPreferencesConstants.LANGUAGE_PREFERENCE, language); + } + } + + /** + * This allows to get the root container of the EObject in parameter. + * + * @param eObject The initial EObject. + * @return The root container. + */ + protected static EObject getRootContainer(final EObject eObject){ + EObject rootContainer = eObject; + + while(null != rootContainer.eContainer()){ + rootContainer = rootContainer.eContainer(); + } + + return rootContainer; + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/LocaleNameResolver.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/LocaleNameResolver.java new file mode 100644 index 00000000000..699266d0fbf --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.common/src/org/eclipse/papyrus/infra/internationalization/common/utils/LocaleNameResolver.java @@ -0,0 +1,57 @@ +/***************************************************************************** + * 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.infra.internationalization.common.utils; + +import java.util.Locale; + +/** + * This allows to manage easily name for the locale. + */ +public class LocaleNameResolver { + + /** + * The underscore constant. + */ + public static final String UNDERSCORE = "_"; //$NON-NLS-1$ + + /** + * This allows to get the corresponding locale from a text. + * + * @param initialString + * The initial string representing a locale. + * @return The locale corresponding locale from the text in parameter. + */ + public static final Locale getLocaleFromString(final String initialString) { + String language = ""; //$NON-NLS-1$ + String country = ""; //$NON-NLS-1$ + String variant = ""; //$NON-NLS-1$ + + if (initialString.contains(UNDERSCORE)) { + language = initialString.substring(0, initialString.indexOf(UNDERSCORE)); + final String substringFirstUnderscore = initialString.substring(initialString.indexOf(UNDERSCORE) + 1, + initialString.length()); + if (substringFirstUnderscore.contains(UNDERSCORE)) { + country = substringFirstUnderscore.substring(0, substringFirstUnderscore.indexOf(UNDERSCORE)); + variant = substringFirstUnderscore.substring(substringFirstUnderscore.indexOf(UNDERSCORE) + 1, + substringFirstUnderscore.length()); + } else { + country = substringFirstUnderscore; + } + } else { + language = initialString; + } + + return new Locale(language, country, variant); + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/.classpath b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/.classpath new file mode 100644 index 00000000000..eca7bdba8f0 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/.project b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/.project new file mode 100644 index 00000000000..e931db8e813 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/.project @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.papyrus.infra.internationalization.controlmode</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.oomph.version.VersionBuilder</name> + <arguments> + <dictionary> + <key>check.maven.pom</key> + <value>true</value> + </dictionary> + <dictionary> + <key>ignore.lower.bound.dependency.ranges</key> + <value>true</value> + </dictionary> + <dictionary> + <key>release.path</key> + <value>/org.eclipse.papyrus.releng.main.release/release.xml</value> + </dictionary> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.oomph.version.VersionNature</nature> + <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature> + </natures> +</projectDescription> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/.settings/org.eclipse.jdt.core.prefs b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..0c68a61dca8 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/META-INF/MANIFEST.MF b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..7822dbc9d6f --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.infra.internationalization.controlmode;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-ClassPath: . +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: org.eclipse.papyrus.infra.internationalization.controlmode, + org.eclipse.papyrus.infra.internationalization.controlmode.commands, + org.eclipse.papyrus.infra.internationalization.controlmode.participants +Require-Bundle: org.eclipse.emf.ecore;bundle-version="[2.12.0,3.0.0)";visibility:=reexport, + org.eclipse.ui.workbench;bundle-version="[3.108.0,4.0.0)", + org.eclipse.ui;bundle-version="[3.107.0,4.0.0)", + org.eclipse.papyrus.infra.services.controlmode;bundle-version="[1.5.0,2.0.0)", + org.eclipse.papyrus.infra.internationalization;bundle-version="[1.0.0,2.0.0)", + org.eclipse.papyrus.infra.internationalization.common;bundle-version="[1.0.0,2.0.0)", + org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="[3.0.0,4.0.0)", + org.eclipse.papyrus.infra.nattable.model;bundle-version="[2.0.0,3.0.0)" +Bundle-ActivationPolicy: lazy +Bundle-Activator: org.eclipse.papyrus.infra.internationalization.controlmode.Activator diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/about.html b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/about.html new file mode 100644 index 00000000000..598b3684879 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>May 12, 2008</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/build.properties b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/build.properties new file mode 100644 index 00000000000..98e56b2cd5e --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/build.properties @@ -0,0 +1,9 @@ +bin.includes = .,\ + META-INF/,\ + about.html,\ + plugin.xml,\ + plugin.properties +jars.compile.order = . +source.. = src/ +output.. = bin/ +src.includes = about.html diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/plugin.properties b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/plugin.properties new file mode 100644 index 00000000000..eac8c610fc4 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/plugin.properties @@ -0,0 +1,4 @@ +# + +pluginName = Papyrus Internationalization Control mode +providerName = Eclipse Modeling Project diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/plugin.xml b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/plugin.xml new file mode 100644 index 00000000000..4e0e90e1adc --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/plugin.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> + +<!-- +--> + +<plugin> + <extension + point="org.eclipse.papyrus.infra.services.controlmode.participant"> + <participant + class="org.eclipse.papyrus.infra.internationalization.controlmode.participants.InternationalizationAnnotationControlParticipant"> + </participant> + <participant + class="org.eclipse.papyrus.infra.internationalization.controlmode.participants.PropertiesControlParticipant"> + </participant> + <participant + class="org.eclipse.papyrus.infra.internationalization.controlmode.participants.PropertiesUncontrolParticipant"> + </participant> + </extension> + + +</plugin> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/pom.xml b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/pom.xml new file mode 100644 index 00000000000..9a7c2a022c7 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/pom.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>org.eclipse.papyrus.infra-internationalization</artifactId> + <groupId>org.eclipse.papyrus</groupId> + <version>0.0.1-SNAPSHOT</version> + </parent> + <artifactId>org.eclipse.papyrus.infra.internationalization.controlmode</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>eclipse-plugin</packaging> +</project>
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/Activator.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/Activator.java new file mode 100644 index 00000000000..45547a86cce --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/Activator.java @@ -0,0 +1,78 @@ +/***************************************************************************** + * 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.infra.internationalization.controlmode; + +import org.eclipse.papyrus.infra.core.log.LogHelper; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle. + */ +public class Activator extends AbstractUIPlugin { + + /** + * The plug-in ID. + */ + public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.internationalization.controlmode"; //$NON-NLS-1$ + + /** + * The shared instance. + */ + private static Activator plugin; + + /** + * The log helper. + */ + public static LogHelper log; + + /** + * The constructor + */ + public Activator() { + super(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(final BundleContext context) throws Exception { + super.start(context); + plugin = this; + log = new LogHelper(this); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(final BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/commands/ControlPropertiesCommand.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/commands/ControlPropertiesCommand.java new file mode 100644 index 00000000000..096bb538d35 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/commands/ControlPropertiesCommand.java @@ -0,0 +1,328 @@ +/***************************************************************************** + * 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.infra.internationalization.controlmode.commands; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.emf.common.util.TreeIterator; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel; +import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils; +import org.eclipse.papyrus.infra.internationalization.InternationalizationEntry; +import org.eclipse.papyrus.infra.internationalization.InternationalizationFactory; +import org.eclipse.papyrus.infra.internationalization.InternationalizationLibrary; +import org.eclipse.papyrus.infra.internationalization.controlmode.Activator; +import org.eclipse.papyrus.infra.internationalization.controlmode.utils.ControlPropertiesUtils; +import org.eclipse.papyrus.infra.internationalization.modelresource.InternationalizationModelResource; +import org.eclipse.papyrus.infra.internationalization.utils.PropertiesFilesUtils; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; +import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest; +import org.eclipse.papyrus.infra.services.controlmode.commands.AbstractControlCommand; + +/** + * The control command for the properties files. + */ +public class ControlPropertiesCommand extends AbstractControlCommand { + + /** + * The Constant COMMAND_TITLE. + */ + private static final String COMMAND_TITLE = "Properties control command"; //$NON-NLS-1$ + + /** + * The old internationalization model resource. + */ + private InternationalizationModelResource internationalizationModelResource = null; + + /** + * The old notation resource. + */ + private Resource oldNotationResource = null; + + /** + * Constructor. + * + * @param request + * The request. + */ + public ControlPropertiesCommand(final ControlModeRequest request) { + this(COMMAND_TITLE, request); + } + + /** + * Constructor. + * + * @param commandTitle + * The command title. + * @param request + * The request. + */ + public ControlPropertiesCommand(final String commandTitle, final ControlModeRequest request) { + super(commandTitle, null, request); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, + * org.eclipse.core.runtime.IAdaptable) + */ + @Override + protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) + throws ExecutionException { + + final Set<Resource> createdResources = new HashSet<Resource>(); + + @SuppressWarnings("unchecked") + final Map<Locale, Resource> createdPropertiesResources = (Map<Locale, Resource>) getRequest() + .getParameter(ControlPropertiesUtils.CREATED_PROPERTIES_RESOURCES); + for (final Locale locale : createdPropertiesResources.keySet()) { + // Get the new properties resource for the locale + final Resource newPropertiesResource = createdPropertiesResources.get(locale); + if (null == newPropertiesResource) { + return CommandResult.newErrorCommandResult("The properties model has not been created"); //$NON-NLS-1$ + } + + InternationalizationLibrary library = null; + for (final EObject objectContant : newPropertiesResource.getContents()) { + if (objectContant instanceof InternationalizationLibrary) { + library = (InternationalizationLibrary) objectContant; + } + } + + if (null == library) { + // The library does not exist, create it and add entries + library = InternationalizationFactory.eINSTANCE.createInternationalizationLibrary(); + newPropertiesResource.getContents().add(library); + } + + final List<InternationalizationEntry> entries = getInternationalizationEntries(locale); + if (!entries.isEmpty()) { + + // The library exists, just add entries + for (final InternationalizationEntry entry : entries) { + library.getEntries().add(EcoreUtil.copy(entry)); + } + + final Resource oldPropertiesResource = getOldPropertiesResource(locale); + final InternationalizationLibrary oldLibrary = (InternationalizationLibrary) oldPropertiesResource + .getContents().get(0); + + oldLibrary.getEntries().removeAll(entries); + } + + createdResources.add(newPropertiesResource); + } + + return CommandResult.newOKCommandResult(createdResources); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doRedo(org.eclipse.core.runtime.IProgressMonitor, + * org.eclipse.core.runtime.IAdaptable) + */ + @Override + protected IStatus doRedo(final IProgressMonitor monitor, IAdaptable info) throws ExecutionException { + return doExecuteWithResult(monitor, info).getStatus(); + } + + /** + * Get the internationalization entries for the diagrams and the tables of + * objects in sub model. + * + * @param locale + * The current locale to manage. + * @return The internationalization entries. + * @throws ExecutionException + * The possible execution exception. + */ + protected List<InternationalizationEntry> getInternationalizationEntries(final Locale locale) + throws ExecutionException { + final List<InternationalizationEntry> entries = new ArrayList<InternationalizationEntry>(); + + getInternationalizationModelResource(); + + if (null != internationalizationModelResource) { + + // Search the EObject labels to control + final EObject targetObject = getRequest().getTargetObject(); + + InternationalizationEntry entryForKey = internationalizationModelResource + .getEntryForKey(getOldPropertiesURI(), targetObject, locale); + if (null != entryForKey) { + entries.add(entryForKey); + } + + final TreeIterator<EObject> eAllContents = EcoreUtil.getAllProperContents(targetObject, true); + while (eAllContents.hasNext()) { + final EObject content = eAllContents.next(); + entryForKey = internationalizationModelResource.getEntryForKey(getOldPropertiesURI(), content, locale); + if (null != entryForKey) { + entries.add(entryForKey); + } + } + + final Resource oldNotationResource = getOldNotationResource(); + + // Search the diagrams labels to control + for (final Diagram diagram : NotationUtils.getDiagrams(oldNotationResource, + getRequest().getTargetObject())) { + entryForKey = internationalizationModelResource.getEntryForKey(getOldPropertiesURI(), diagram, locale); + if (null != entryForKey) { + entries.add(entryForKey); + } + } + + // Search the tables labels to control + for (final Table table : getTables(oldNotationResource, getRequest().getTargetObject())) { + entryForKey = internationalizationModelResource.getEntryForKey(getOldPropertiesURI(), table, locale); + if (null != entryForKey) { + entries.add(entryForKey); + } + } + } + + return entries; + } + + /** + * Gets the all the tables contained in the specified ancestor eObject. + * + * @param notationResource + * The notation resource where search tables. + * @param eObject + * The table to search in notation resource. + * + * @return all the contained tables. + */ + protected List<Table> getTables(final Resource notationResource, final EObject eObject) { + final List<Table> tables = new LinkedList<Table>(); + if (null != notationResource) { + for (final EObject obj : notationResource.getContents()) { + if (obj instanceof Table) { + Table table = (Table) obj; + if (EcoreUtil.isAncestor(eObject, table.getOwner())) { + tables.add(table); + } + } + } + } + return tables; + } + + /** + * Gets the old internationalization model resource. + * + * @return the old internationalization model resource. + */ + protected InternationalizationModelResource getInternationalizationModelResource() { + + if (null == internationalizationModelResource) { + try { + internationalizationModelResource = (InternationalizationModelResource) getRequest().getModelSet() + .getModelChecked(InternationalizationModelResource.MODEL_ID); + } catch (Exception e) { + Activator.log.error("Unable to retrieve old properties resource", e); //$NON-NLS-1$ + } + } + + return internationalizationModelResource; + } + + /** + * Gets the old properties resource. + * + * @param locale + * The current locale to manage. + * @return the old properties resource. + */ + private Resource getOldPropertiesResource(final Locale locale) { + Resource resource = null; + + getInternationalizationModelResource(); + + try { + resource = internationalizationModelResource.getResourceForURIAndLocale(getOldPropertiesURI(), locale); + } catch (Exception e) { + Activator.log.error("Unable to retrieve old notation resource", e); //$NON-NLS-1$ + } + + return resource; + } + + /** + * Get the old properties URI for request. + * + * @return The old properties resource URI. + * @throws ExecutionException + * The exception when the notation resource is not found. + */ + protected URI getOldPropertiesURI() throws ExecutionException { + URI uri = getRequest().getSourceURI(); + if (null != uri) { + return uri.trimFileExtension().appendFileExtension(PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION); + } + throw new ExecutionException("Unable to retreive URI of the old properties model"); //$NON-NLS-1$ + } + + /** + * Gets the old notation resource. + * + * @return the old notation resource + */ + private Resource getOldNotationResource() { + + if (null == oldNotationResource) { + try { + oldNotationResource = getRequest().getModelSet().getResource(getOldNotationURI(), true); + } catch (Exception e) { + Activator.log.error("Unable to retrieve old notation resource", e); //$NON-NLS-1$ + } + } + + return oldNotationResource; + } + + /** + * Get the old notation URI for request. + * + * @return The old notation resource URI. + * @throws ExecutionException + * The exception when the notation resource is not found. + */ + protected URI getOldNotationURI() throws ExecutionException { + URI uri = getRequest().getSourceURI(); + if (null != uri) { + return uri.trimFileExtension().appendFileExtension(NotationModel.NOTATION_FILE_EXTENSION); + } + throw new ExecutionException("Unable to retreive URI of the old notation model"); //$NON-NLS-1$ + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/commands/CreatePropertiesControlResourceCommand.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/commands/CreatePropertiesControlResourceCommand.java new file mode 100644 index 00000000000..e571b0c2d38 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/commands/CreatePropertiesControlResourceCommand.java @@ -0,0 +1,257 @@ +/***************************************************************************** + * 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.infra.internationalization.controlmode.commands; + +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.core.resource.NotFoundException; +import org.eclipse.papyrus.infra.internationalization.common.utils.LocaleNameResolver; +import org.eclipse.papyrus.infra.internationalization.controlmode.utils.ControlPropertiesUtils; +import org.eclipse.papyrus.infra.internationalization.modelresource.InternationalizationModelResource; +import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest; +import org.eclipse.papyrus.infra.services.controlmode.commands.CreateControlResource; + +/** + * Command used to create new controlled properties resource. This command will + * create the new resources. It will also handle correctly undo and redo. + */ +public class CreatePropertiesControlResourceCommand extends CreateControlResource { + + /** + * The locale to add in the file name. + */ + private Locale locale; + + /** + * The created resource. We need it to remove it for undo command. + */ + private Resource createdResource; + + /** + * The internationalization model resource. + */ + private InternationalizationModelResource internationalizationModelResource; + + /** + * Constructor. + * + * @param request + * {@link ControlModeRequest} used to compute the command + * @param newFileExtension + * File extension use to create the resource. If not specified + * then it should be already provided in the {@link URI} + * @param locale + * The locale to add in the file name. + */ + public CreatePropertiesControlResourceCommand(final ControlModeRequest request, final String newFileExtension, + final Locale locale) { + super(request, newFileExtension); + this.locale = locale; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.commands.AbstractControlResourceCommand#getTargetUri() + */ + @Override + public URI getTargetUri() { + return getModifiedURI(getRequest().getNewURI()); + } + + /** + * Get the URI with the locale if not null and the extension if not null. + * + * @param initialURI + * The initial URI. + * @return The modified URI. + */ + protected URI getModifiedURI(final URI initialURI) { + URI targetURI = initialURI; + if (null != locale) { + // Get the existing file extension + final String existingFileExtension = targetURI.fileExtension(); + // Get the last segment + String lastSegment = targetURI.trimFileExtension().lastSegment(); + // Add the locale to the last segment + lastSegment = lastSegment + LocaleNameResolver.UNDERSCORE + locale.toString(); + // Replace the last segment (managing file extension + targetURI = targetURI.trimFileExtension().trimSegments(1).appendSegment(lastSegment) + .appendFileExtension(existingFileExtension); + } + if (null != newFileExtension) { + targetURI = targetURI.trimFileExtension().appendFileExtension(newFileExtension); + } + return targetURI; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.commands.CreateControlResource#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, + * org.eclipse.core.runtime.IAdaptable) + */ + @SuppressWarnings("unchecked") + @Override + protected CommandResult doExecuteWithResult(final IProgressMonitor progressMonitor, final IAdaptable info) + throws ExecutionException { + final CommandResult res = super.doExecuteWithResult(progressMonitor, info); + + // Get the created resource + createdResource = getRequest().getTargetResource(newFileExtension); + + // Manage a map of created properties resources, because several + // properties resources can be created + if (null == getRequest().getParameter(ControlPropertiesUtils.CREATED_PROPERTIES_RESOURCES)) { + getRequest().setParameter(ControlPropertiesUtils.CREATED_PROPERTIES_RESOURCES, + new HashMap<Locale, Resource>()); + } + ((Map<Locale, Resource>) getRequest().getParameter(ControlPropertiesUtils.CREATED_PROPERTIES_RESOURCES)) + .put(locale, createdResource); + + // Add the resource to the internationalization model resource + final InternationalizationModelResource modelResource = getInternationalizationModelResource(); + if (null != modelResource) { + modelResource.addResourceToModel(getRequest().getNewURI().trimFileExtension(), createdResource, locale); + } + + return res; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.commands.CreateControlResource#doUndo(org.eclipse.core.runtime.IProgressMonitor, + * org.eclipse.core.runtime.IAdaptable) + */ + @Override + protected IStatus doUndo(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { + getRequest().setTargetResource(createdResource, getFileExtension()); + + // Unload and remove the resource from the internationalization model + // resource + final InternationalizationModelResource modelResource = getInternationalizationModelResource(); + if (null != modelResource) { + modelResource.unload(createdResource); + modelResource.getResources().remove(createdResource); + } + + return super.doUndo(monitor, info); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.commands.CreateControlResource#doRedo(org.eclipse.core.runtime.IProgressMonitor, + * org.eclipse.core.runtime.IAdaptable) + */ + @Override + protected IStatus doRedo(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { + getRequest().setTargetResource(createdResource, getFileExtension()); + final IStatus result = super.doRedo(monitor, info); + + // Add the resource to the internationalization model resource + final InternationalizationModelResource modelResource = getInternationalizationModelResource(); + if (null != modelResource) { + modelResource.addResourceToModel(getRequest().getNewURI().trimFileExtension(), createdResource, locale); + } + + return result; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.commands.CreateControlResource#getNewURI() + */ + @Override + protected URI getNewURI() { + return getModifiedURI(getRequest().getNewURI()); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.commands.CreateControlResource#getTargetResrource(org.eclipse.emf.ecore.EObject) + */ + @Override + protected Resource getTargetResrource(final EObject objectToUncontrol) { + Resource resultResource = null; + URI targetURI = null; + + if (null != objectToUncontrol) { + targetURI = objectToUncontrol.eResource().getURI().trimFileExtension(); + if (null != locale) { + String lastSegment = targetURI.lastSegment(); + lastSegment = lastSegment + LocaleNameResolver.UNDERSCORE + locale.toString(); + targetURI = targetURI.trimSegments(1).appendSegment(lastSegment); + } + targetURI = targetURI.appendFileExtension(getFileExtension()); + } + + if (null != targetURI) { + final InternationalizationModelResource modelResource = getInternationalizationModelResource(); + if (null != modelResource) { + resultResource = modelResource.getResourceForURIAndLocale(objectToUncontrol.eResource().getURI() + .trimFileExtension().appendFileExtension(getFileExtension()), locale); + } + } + + return resultResource; + } + + /** + * Get the internationalization model resource. + * + * @return The internationalization model resource. + */ + protected InternationalizationModelResource getInternationalizationModelResource() { + if (null == internationalizationModelResource) { + final ModelSet modelSet = getRequest().getModelSet(); + if (null != modelSet) { + try { + internationalizationModelResource = (InternationalizationModelResource) modelSet + .getModelChecked(InternationalizationModelResource.MODEL_ID); + } catch (final NotFoundException e) { + // Do nothing + } + } + } + + return internationalizationModelResource; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.workspace.AbstractEMFOperation#dispose() + */ + @Override + public void dispose() { + internationalizationModelResource = null; + createdResource = null; + locale = null; + super.dispose(); + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/commands/InternationalizationAnnotationControlCommand.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/commands/InternationalizationAnnotationControlCommand.java new file mode 100644 index 00000000000..9642cd7bcec --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/commands/InternationalizationAnnotationControlCommand.java @@ -0,0 +1,111 @@ +/***************************************************************************** + * 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.infra.internationalization.controlmode.commands; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesConstants; +import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest; +import org.eclipse.papyrus.infra.services.controlmode.commands.AbstractControlCommand; + +/** + * The internationalization annotation in the notation file must be copied in + * the new controlled file. + */ +public class InternationalizationAnnotationControlCommand extends AbstractControlCommand { + + /** + * The Constant COMMAND_TITLE. + */ + private static final String COMMAND_TITLE = "Annotation internationalization control command"; //$NON-NLS-1$ + + /** + * The old notation resource. + */ + private Resource oldNotationResource = null; + + /** + * Constructor. + * + * @param request + * The request. + * @param oldNotationResource + * The old notation resource. + */ + public InternationalizationAnnotationControlCommand(final ControlModeRequest request, + final Resource oldNotationResource) { + super(COMMAND_TITLE, null, request); + this.oldNotationResource = oldNotationResource; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, + * org.eclipse.core.runtime.IAdaptable) + */ + @Override + protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) + throws ExecutionException { + CommandResult commandResult = null; + + // Check if the old notation resource is not null + if (null == oldNotationResource) { + commandResult = CommandResult.newErrorCommandResult( + String.format("The source %s model does not exist", NotationModel.NOTATION_FILE_EXTENSION)); //$NON-NLS-1$ + } else { + // Get the new notation resource and check if this is not null + final Resource newNotationResource = getTargetResource(); + if (null == newNotationResource) { + commandResult = CommandResult.newErrorCommandResult("The notation model has not been created"); //$NON-NLS-1$ + } else { + EAnnotation annotation = null; + + // Search about the internationalization preference + for (final EObject objectContent : oldNotationResource.getContents()) { + if (objectContent instanceof EAnnotation + && InternationalizationPreferencesConstants.INTERNATIONALIZATION_ANNOTATION_LABEL + .equals(((EAnnotation) objectContent).getSource())) { + annotation = EcoreUtil.copy((EAnnotation) objectContent); + } + } + + // If the annotation exists, add a copy for the new notation + // resource + if (null != annotation) { + newNotationResource.getContents().add(annotation); + commandResult = CommandResult.newOKCommandResult(newNotationResource); + } + } + } + + return null != commandResult ? commandResult : CommandResult.newOKCommandResult(); + } + + /** + * Retrieve the target resource from the request + * + * @return The target resource. + */ + protected Resource getTargetResource() { + return request.getTargetResource(NotationModel.NOTATION_FILE_EXTENSION); + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/commands/RemovePropertiesControlResourceCommand.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/commands/RemovePropertiesControlResourceCommand.java new file mode 100644 index 00000000000..2b90119a6ff --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/commands/RemovePropertiesControlResourceCommand.java @@ -0,0 +1,243 @@ +/***************************************************************************** + * 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.infra.internationalization.controlmode.commands; + +import java.util.Locale; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.core.resource.NotFoundException; +import org.eclipse.papyrus.infra.internationalization.common.utils.LocaleNameResolver; +import org.eclipse.papyrus.infra.internationalization.modelresource.InternationalizationModelResource; +import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest; +import org.eclipse.papyrus.infra.services.controlmode.commands.RemoveControlResourceCommand; +import org.eclipse.papyrus.infra.services.controlmode.messages.Messages; + +/** + * Command used to create new controlled properties resource. This command will + * create the new resources. It will also handle correctly undo and redo. + */ +public class RemovePropertiesControlResourceCommand extends RemoveControlResourceCommand { + + /** + * The resource to remove. We need it to remove it for undo command. + */ + private Resource resourceToRemove; + + /** + * The locale to add in the file name. + */ + private Locale locale; + + /** + * The internationalization model resource. + */ + private InternationalizationModelResource internationalizationModelResource; + + /** + * Constructor. + * + * @param request + * {@link ControlModeRequest} used to compute the command + * @param newFileExtension + * File extension use to create the resource. If not specified + * then it should be already provided in the {@link URI} + * @param resourceToRemove + * The resource to remove. + * @param locale + * The locale to add in the file name. + */ + public RemovePropertiesControlResourceCommand(final ControlModeRequest request, final String fileExtension, + final Resource resourceToRemove, final Locale locale) { + super(request, fileExtension); + this.resourceToRemove = resourceToRemove; + this.locale = locale; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.commands.RemoveControlResourceCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, + * org.eclipse.core.runtime.IAdaptable) + */ + @Override + protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) + throws ExecutionException { + CommandResult commandResult = null; + EObject objectToControl = getRequest().getTargetObject(); + if (null == objectToControl) { + commandResult = CommandResult.newErrorCommandResult(CONTROL_OBJECT_ERROR); + } else { + ModelSet modelSet = getRequest().getModelSet(); + if (null == modelSet) { + commandResult = CommandResult.newErrorCommandResult(RESOURCESET_ERROR); + } else { + + // Delete resource back-end on save + modelSet.getResourcesToDeleteOnSave().add(resourceToRemove.getURI()); + + // Save source and target resource + Resource targetResource = getTargetResource(objectToControl); + if (null == targetResource) { + commandResult = CommandResult + .newErrorCommandResult(Messages.getString(TARGET_RESOURCE_ERROR, getFileExtension())); + } else { + + // The target resource needs to be saved else the resolution + // will not operate + targetResource.setModified(true); + + getRequest().setTargetResource(targetResource, getFileExtension()); + getRequest().setSourceResource(resourceToRemove, getFileExtension()); + + // remove resource set + modelSet.getResources().remove(resourceToRemove); + + // Unload and remove the resource from the + // internationalization model resource + final InternationalizationModelResource modelResource = getInternationalizationModelResource(); + if (null != modelResource) { + modelResource.unload(resourceToRemove.getURI()); + modelResource.getResources().remove(resourceToRemove); + } + + commandResult = CommandResult.newOKCommandResult(); + } + } + } + + return commandResult; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.commands.RemoveControlResourceCommand#doUndo(org.eclipse.core.runtime.IProgressMonitor, + * org.eclipse.core.runtime.IAdaptable) + */ + @Override + protected IStatus doUndo(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { + final IStatus result = super.doUndo(monitor, info); + + // Add the resource to the internationalization model resource + final InternationalizationModelResource modelResource = getInternationalizationModelResource(); + if (null != modelResource) { + modelResource.addResourceToModel(getRequest().getSourceURI().trimFileExtension(), resourceToRemove, locale); + } + + return result; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.commands.RemoveControlResourceCommand#getSourceResource() + */ + @Override + protected Resource getSourceResource() { + return resourceToRemove; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.commands.RemoveControlResourceCommand#doRedo(org.eclipse.core.runtime.IProgressMonitor, + * org.eclipse.core.runtime.IAdaptable) + */ + @Override + protected IStatus doRedo(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException { + final IStatus result = super.doRedo(monitor, info); + + // Unload and remove the resource from the internationalization model + // resource + final InternationalizationModelResource modelResource = getInternationalizationModelResource(); + if (null != modelResource) { + modelResource.unload(resourceToRemove.getURI()); + modelResource.getResources().remove(resourceToRemove); + } + + return result; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.commands.RemoveControlResourceCommand#getTargetResource(org.eclipse.emf.ecore.EObject) + */ + @Override + protected Resource getTargetResource(final EObject objectToUncontrol) { + Resource resultResource = null; + URI targetURI = null; + + if (null != objectToUncontrol) { + targetURI = objectToUncontrol.eResource().getURI().trimFileExtension(); + if (null != locale) { + String lastSegment = targetURI.lastSegment(); + lastSegment = lastSegment + LocaleNameResolver.UNDERSCORE + locale.toString(); + targetURI = targetURI.trimSegments(1).appendSegment(lastSegment); + } + targetURI = targetURI.appendFileExtension(getFileExtension()); + } + + if (null != targetURI) { + InternationalizationModelResource modelResource = getInternationalizationModelResource(); + if (null != modelResource) { + resultResource = modelResource.getResourceForURIAndLocale(objectToUncontrol.eResource().getURI() + .trimFileExtension().appendFileExtension(getFileExtension()), locale); + } + } + + return resultResource; + } + + /** + * Get the internationalization model resource. + * + * @return The internationalization model resource. + */ + protected InternationalizationModelResource getInternationalizationModelResource() { + if (null == internationalizationModelResource) { + final ModelSet modelSet = getRequest().getModelSet(); + if (null != modelSet) { + try { + internationalizationModelResource = (InternationalizationModelResource) modelSet + .getModelChecked(InternationalizationModelResource.MODEL_ID); + } catch (final NotFoundException e) { + // Do nothing + } + } + } + + return internationalizationModelResource; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.workspace.AbstractEMFOperation#dispose() + */ + @Override + public void dispose() { + internationalizationModelResource = null; + resourceToRemove = null; + locale = null; + super.dispose(); + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/participants/InternationalizationAnnotationControlParticipant.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/participants/InternationalizationAnnotationControlParticipant.java new file mode 100644 index 00000000000..4d2ebf01c6e --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/participants/InternationalizationAnnotationControlParticipant.java @@ -0,0 +1,183 @@ +/***************************************************************************** + * 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.infra.internationalization.controlmode.participants; + +import java.util.Iterator; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesConstants; +import org.eclipse.papyrus.infra.internationalization.controlmode.Activator; +import org.eclipse.papyrus.infra.internationalization.controlmode.commands.InternationalizationAnnotationControlCommand; +import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest; +import org.eclipse.papyrus.infra.services.controlmode.participants.IControlCommandParticipant; +import org.eclipse.papyrus.infra.services.controlmode.participants.IUncontrolCommandParticipant; + +/** + * The internationalization annotation control participant for the preference + * annotation. + */ +public class InternationalizationAnnotationControlParticipant + implements IControlCommandParticipant, IUncontrolCommandParticipant { + + /** + * The Constant PARTICIPANT_ID. + */ + private static final String PARTICIPANT_ID = "org.eclipse.papyrus.infra.internationalization.controlmode.InternationalizationAnnotationControlParticipant"; //$NON-NLS-1$ + + /** + * Constructor. + */ + public InternationalizationAnnotationControlParticipant() { + + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlModeParticipant#getID() + */ + @Override + public String getID() { + return PARTICIPANT_ID; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlModeParticipant#getPriority() + */ + @Override + public int getPriority() { + return 20; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IUncontrolCommandParticipant#provideUnControlCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest) + */ + @Override + public boolean provideUnControlCommand(final ControlModeRequest request) { + return false; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IUncontrolCommandParticipant#getPreUncontrolCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest) + */ + @Override + public ICommand getPreUncontrolCommand(final ControlModeRequest request) { + return null; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IUncontrolCommandParticipant#getPostUncontrolCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest) + */ + @Override + public ICommand getPostUncontrolCommand(final ControlModeRequest request) { + // Don't create the notation resource since it is already handled + return null; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlCommandParticipant#provideControlCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest) + */ + @Override + public boolean provideControlCommand(final ControlModeRequest request) { + boolean result = false; + + // Check if the annotation for the internationalization is in the + // notation file + final Iterator<EObject> objectContentsIterator = getSourceResource(request).getContents().iterator(); + while (objectContentsIterator.hasNext() && !result) { + EObject objectContent = objectContentsIterator.next(); + if (objectContent instanceof EAnnotation + && InternationalizationPreferencesConstants.INTERNATIONALIZATION_ANNOTATION_LABEL + .equals(((EAnnotation) objectContent).getSource())) { + result = true; + } + } + + return result; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlCommandParticipant#getPreControlCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest) + */ + @Override + public ICommand getPreControlCommand(final ControlModeRequest request) { + // Don't create the notation resource since it is already handled + return null; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlCommandParticipant#getPostControlCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest) + */ + @Override + public ICommand getPostControlCommand(final ControlModeRequest request) { + return new InternationalizationAnnotationControlCommand(request, getSourceResource(request)); + } + + /** + * Gets the old notation resource. + * + * @param request + * The control request. + * @return the old notation resource. + */ + protected Resource getSourceResource(final ControlModeRequest request) { + Resource oldNotationResource = null; + + try { + oldNotationResource = request.getModelSet().getResource(getOldNotationURI(request), true); + } catch (Exception e) { + Activator.log.error("Unable to retrieve old notation resource", e); //$NON-NLS-1$ + } + + return oldNotationResource; + } + + /** + * Get the old notation URI for request. + * + * @param request + * The control request. + * @return The old notation resource. + * @throws ExecutionException + * The exception when the notation resource is not found. + */ + protected URI getOldNotationURI(final ControlModeRequest request) throws ExecutionException { + URI uri = request.getSourceURI(); + + if (null != uri) { + return uri.trimFileExtension().appendFileExtension(NotationModel.NOTATION_FILE_EXTENSION); + } + throw new ExecutionException("Unable to retreive URI of the old notation model"); //$NON-NLS-1$ + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/participants/PropertiesControlParticipant.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/participants/PropertiesControlParticipant.java new file mode 100644 index 00000000000..45a6a1eb09a --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/participants/PropertiesControlParticipant.java @@ -0,0 +1,159 @@ +/***************************************************************************** + * 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.infra.internationalization.controlmode.participants; + +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand; +import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.core.resource.NotFoundException; +import org.eclipse.papyrus.infra.internationalization.controlmode.commands.ControlPropertiesCommand; +import org.eclipse.papyrus.infra.internationalization.controlmode.commands.CreatePropertiesControlResourceCommand; +import org.eclipse.papyrus.infra.internationalization.modelresource.InternationalizationModelResource; +import org.eclipse.papyrus.infra.internationalization.utils.PropertiesFilesUtils; +import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest; +import org.eclipse.papyrus.infra.services.controlmode.participants.IControlCommandParticipant; + +/** + * The control participant for the properties files. + */ +public class PropertiesControlParticipant implements IControlCommandParticipant { + + /** + * The Constant PARTICIPANT_ID. + */ + private static final String PARTICIPANT_ID = "org.eclipse.papyrus.infra.internationalization.controlmode.PropertiesControlParticipant"; //$NON-NLS-1$ + + /** + * The internationalization model resource. + */ + private InternationalizationModelResource internationalizationModelResource; + + /** + * Constructor. + */ + public PropertiesControlParticipant() { + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlModeParticipant#getID() + */ + @Override + public String getID() { + return PARTICIPANT_ID; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlModeParticipant#getPriority() + */ + @Override + public int getPriority() { + return 40; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlCommandParticipant#provideControlCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest) + */ + @Override + public boolean provideControlCommand(final ControlModeRequest request) { + boolean result = false; + + final EObject objectToControl = request.getTargetObject(); + if (null != objectToControl) { + // If there is no properties resource in the old resource, then + // there's nothing to do + final InternationalizationModelResource modelResource = getInternationalizationModelResource(request); + final Map<Locale, Resource> localesAndResourcesForURI = modelResource + .getLocalesAndResourcesForURI(request.getSourceURI().trimFileExtension() + .appendFileExtension(PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION)); + + result = null != localesAndResourcesForURI && !localesAndResourcesForURI.isEmpty(); + } + + return result; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlCommandParticipant#getPreControlCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest) + */ + @Override + public ICommand getPreControlCommand(final ControlModeRequest request) { + ICommand resultCommand = UnexecutableCommand.INSTANCE; + + // Get the used locale to determinate the properties file to create + final InternationalizationModelResource modelResource = getInternationalizationModelResource(request); + if (null != modelResource) { + final Set<Locale> locales = modelResource.getAvailablePropertiesLocales(request.getSourceURI()); + + resultCommand = new CompositeTransactionalCommand(request.getEditingDomain(), "Create properties files"); //$NON-NLS-1$ + + // Loop on each locale to create associated properties file + for (final Locale currentLocale : locales) { + ((CompositeTransactionalCommand) resultCommand).add(new CreatePropertiesControlResourceCommand(request, + PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION, currentLocale)); + } + } + + return resultCommand; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlCommandParticipant#getPostControlCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest) + */ + @Override + public ICommand getPostControlCommand(final ControlModeRequest request) { + + // Dispose the internationalizationModelResource + internationalizationModelResource = null; + + return new ControlPropertiesCommand(request); + } + + /** + * Get the internationalization model resource. + * + * @return The internationalization model resource. + */ + protected InternationalizationModelResource getInternationalizationModelResource(final ControlModeRequest request) { + if (null == internationalizationModelResource && null != request) { + final ModelSet modelSet = request.getModelSet(); + if (null != modelSet) { + try { + internationalizationModelResource = (InternationalizationModelResource) modelSet + .getModelChecked(InternationalizationModelResource.MODEL_ID); + } catch (final NotFoundException e) { + // Do nothing + } + } + } + + return internationalizationModelResource; + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/participants/PropertiesUncontrolParticipant.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/participants/PropertiesUncontrolParticipant.java new file mode 100644 index 00000000000..007f94cc02f --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/participants/PropertiesUncontrolParticipant.java @@ -0,0 +1,249 @@ +/***************************************************************************** + * 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.infra.internationalization.controlmode.participants; + +import java.util.Locale; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand; +import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.core.resource.NotFoundException; +import org.eclipse.papyrus.infra.internationalization.controlmode.commands.ControlPropertiesCommand; +import org.eclipse.papyrus.infra.internationalization.controlmode.commands.CreatePropertiesControlResourceCommand; +import org.eclipse.papyrus.infra.internationalization.controlmode.commands.RemovePropertiesControlResourceCommand; +import org.eclipse.papyrus.infra.internationalization.controlmode.utils.ControlPropertiesUtils; +import org.eclipse.papyrus.infra.internationalization.modelresource.InternationalizationModelResource; +import org.eclipse.papyrus.infra.internationalization.utils.PropertiesFilesUtils; +import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest; +import org.eclipse.papyrus.infra.services.controlmode.participants.IUncontrolCommandParticipant; + +/** + * The uncontrol participant for the properties files. + */ +public class PropertiesUncontrolParticipant implements IUncontrolCommandParticipant { + + /** + * The Constant PARTICIPANT_ID. + */ + private static final String PARTICIPANT_ID = "org.eclipse.papyrus.infra.internationalization.controlmode.PropertiesUncontrolParticipant"; //$NON-NLS-1$ + + /** + * The internationalization model resource. + */ + private InternationalizationModelResource internationalizationModelResource; + + /** + * Constructor. + */ + public PropertiesUncontrolParticipant() { + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlModeParticipant#getID() + */ + @Override + public String getID() { + return PARTICIPANT_ID; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IControlModeParticipant#getPriority() + */ + @Override + public int getPriority() { + return 70; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IUncontrolCommandParticipant#provideUnControlCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest) + */ + @Override + public boolean provideUnControlCommand(final ControlModeRequest request) { + boolean result = false; + + final EObject objectToUncontrol = request.getTargetObject(); + if (null != objectToUncontrol) { + // If there is no properties resource in the old resource, then + // there's nothing to do + final InternationalizationModelResource modelResource = getInternationalizationModelResource(request); + final Map<Locale, Resource> localesAndResourcesForURI = modelResource + .getLocalesAndResourcesForURI(request.getSourceURI().trimFileExtension() + .appendFileExtension(PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION)); + + result = null != localesAndResourcesForURI && !localesAndResourcesForURI.isEmpty(); + } + + return result; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IUncontrolCommandParticipant#getPreUncontrolCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest) + */ + @Override + public ICommand getPreUncontrolCommand(final ControlModeRequest request) { + boolean result = setPropertiesTargetRequest(request); + + CompositeTransactionalCommand compositeCommand = null; + + if (result) { + compositeCommand = new CompositeTransactionalCommand(request.getEditingDomain(), "Uncontrol command"); //$NON-NLS-1$ + + // Before modify properties files, check that new properties files are available + final URI newPropertiesURI = request.getNewURI().trimFileExtension() + .appendFileExtension(PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION); + final URI sourcePropertiesURI = request.getSourceURI().trimFileExtension() + .appendFileExtension(PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION); + final ModelSet modelSet = request.getModelSet(); + + if (null != modelSet) { + + final InternationalizationModelResource modelResource = getInternationalizationModelResource(request); + if (null != modelResource) { + final Map<Locale, Resource> newLocalesAndResources = modelResource + .getLocalesAndResourcesForURI(newPropertiesURI); + final Map<Locale, Resource> sourceLocalesAndResources = modelResource + .getLocalesAndResourcesForURI(sourcePropertiesURI); + + for(final Locale sourceLocale : sourceLocalesAndResources.keySet()){ + if(!newLocalesAndResources.containsKey(sourceLocale)){ + // The locale is not existing for the new properties resources, we need to create it + compositeCommand.add(new CreatePropertiesControlResourceCommand(request, + PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION, sourceLocale)); + } + } + } + } + + compositeCommand.add(new ControlPropertiesCommand(request)); + } + + return null != compositeCommand ? compositeCommand : UnexecutableCommand.INSTANCE; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.services.controlmode.participants.IUncontrolCommandParticipant#getPostUncontrolCommand(org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest) + */ + @Override + public ICommand getPostUncontrolCommand(final ControlModeRequest request) { + ICommand commandResult = UnexecutableCommand.INSTANCE; + + final Map<Locale, Resource> result = getPropertiesSourceRequest(request); + if (null != result && !result.isEmpty()) { + final CompositeTransactionalCommand compositeCommand = new CompositeTransactionalCommand( + request.getEditingDomain(), "Remove properties resources"); //$NON-NLS-1$ + + for (final Entry<Locale, Resource> entry : result.entrySet()) { + compositeCommand.add(new RemovePropertiesControlResourceCommand(request, + PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION, entry.getValue(), entry.getKey())); + } + + commandResult = compositeCommand; + } + + // Dispose the internationationalizationModelResource + internationalizationModelResource = null; + + return commandResult; + } + + /** + * Init target request to have the properties resources references. + * + * @param request + * The request. + */ + protected boolean setPropertiesTargetRequest(final ControlModeRequest request) { + boolean result = false; + final URI propertiesURI = request.getNewURI().trimFileExtension() + .appendFileExtension(PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION); + final ModelSet modelSet = request.getModelSet(); + + if (null != modelSet) { + + final InternationalizationModelResource modelResource = getInternationalizationModelResource(request); + if (null != modelResource) { + final Map<Locale, Resource> localesAndResources = modelResource + .getLocalesAndResourcesForURI(propertiesURI); + + if (!localesAndResources.isEmpty()) { + request.setParameter(ControlPropertiesUtils.CREATED_PROPERTIES_RESOURCES, localesAndResources); + // Nothing to do but everything is ok + result = true; + } + } + } + + return result; + } + + /** + * Init source request to have the properties resources references. + * + * @param request + * The request. + */ + protected Map<Locale, Resource> getPropertiesSourceRequest(final ControlModeRequest request) { + Map<Locale, Resource> result = null; + final URI propertiesURI = request.getSourceURI().trimFileExtension() + .appendFileExtension(PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION); + final ModelSet modelSet = request.getModelSet(); + + if (null != modelSet) { + final InternationalizationModelResource modelResource = getInternationalizationModelResource(request); + if (null != modelResource) { + result = modelResource.getLocalesAndResourcesForURI(propertiesURI); + } + } + + return result; + } + + /** + * Get the internationalization model resource. + * + * @return The internationalization model resource. + */ + protected InternationalizationModelResource getInternationalizationModelResource(final ControlModeRequest request) { + if (null == internationalizationModelResource && null != request) { + final ModelSet modelSet = request.getModelSet(); + if (null != modelSet) { + try { + internationalizationModelResource = (InternationalizationModelResource) modelSet + .getModelChecked(InternationalizationModelResource.MODEL_ID); + } catch (final NotFoundException e) { + // Do nothing + } + } + } + + return internationalizationModelResource; + } + +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/utils/ControlPropertiesUtils.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/utils/ControlPropertiesUtils.java new file mode 100644 index 00000000000..11c4e3975da --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.controlmode/src/org/eclipse/papyrus/infra/internationalization/controlmode/utils/ControlPropertiesUtils.java @@ -0,0 +1,25 @@ +/***************************************************************************** + * 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.infra.internationalization.controlmode.utils; + +/** + * The control properties utils class. + */ +public class ControlPropertiesUtils { + + /** + * The created properties resources constant. + */ + public static final String CREATED_PROPERTIES_RESOURCES = "createdPropertiesResources"; //$NON-NLS-1$ +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/.classpath b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/.classpath new file mode 100644 index 00000000000..8dd013afc8b --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/.classpath @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src-gen"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/.project b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/.project new file mode 100644 index 00000000000..9b31b5cc1c8 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/.project @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.papyrus.infra.internationalization.edit</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.oomph.version.VersionBuilder</name> + <arguments> + <dictionary> + <key>check.maven.pom</key> + <value>true</value> + </dictionary> + <dictionary> + <key>ignore.lower.bound.dependency.ranges</key> + <value>true</value> + </dictionary> + <dictionary> + <key>release.path</key> + <value>/org.eclipse.papyrus.releng.main.release/release.xml</value> + </dictionary> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.oomph.version.VersionNature</nature> + <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature> + </natures> +</projectDescription> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/META-INF/MANIFEST.MF b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..a4b66a677b2 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.infra.internationalization.edit;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-ClassPath: . +Bundle-Activator: org.eclipse.papyrus.infra.internationalization.provider.InternationalizationEditPlugin$Implementation +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: org.eclipse.papyrus.infra.internationalization.edit.provider, + org.eclipse.papyrus.infra.internationalization.provider +Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.12.0,4.0.0)", + org.eclipse.papyrus.infra.internationalization;bundle-version="[1.0.0,2.0.0)";visibility:=reexport, + org.eclipse.emf.edit;bundle-version="[2.12.0,3.0.0)";visibility:=reexport, + org.eclipse.gmf.runtime.notation.edit;bundle-version="[1.7.0,2.0.0)";visibility:=reexport, + org.eclipse.papyrus.infra.internationalization.utils;bundle-version="[1.0.0,2.0.0)" +Bundle-ActivationPolicy: lazy diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/about.html b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/about.html new file mode 100644 index 00000000000..598b3684879 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>May 12, 2008</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/build.properties b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/build.properties new file mode 100644 index 00000000000..60f476a9c04 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/build.properties @@ -0,0 +1,12 @@ +# + +bin.includes = .,\ + icons/,\ + META-INF/,\ + about.html,\ + plugin.xml,\ + plugin.properties +jars.compile.order = . +source.. = src-gen/,\ + src/ +output.. = bin/
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/icons/full/obj16/InternationalizationEntry.gif b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/icons/full/obj16/InternationalizationEntry.gif Binary files differnew file mode 100644 index 00000000000..5a9bc7514fa --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/icons/full/obj16/InternationalizationEntry.gif diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/icons/full/obj16/InternationalizationLibrary.gif b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/icons/full/obj16/InternationalizationLibrary.gif Binary files differnew file mode 100644 index 00000000000..48e3cf22687 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/icons/full/obj16/InternationalizationLibrary.gif diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/plugin.properties b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/plugin.properties new file mode 100644 index 00000000000..632eac41a11 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/plugin.properties @@ -0,0 +1,25 @@ +# + +pluginName = Papyrus Internationalization Edit Support +providerName = Eclipse Modeling Project + +_UI_CreateChild_text = {0} +_UI_CreateChild_text2 = {1} {0} +_UI_CreateChild_text3 = {1} +_UI_CreateChild_tooltip = Create New {0} Under {1} Feature +_UI_CreateChild_description = Create a new child of type {0} for the {1} feature of the selected {2}. +_UI_CreateSibling_description = Create a new sibling of type {0} for the selected {2}, under the {1} feature of their parent. + +_UI_PropertyDescriptor_description = The {0} of the {1} + +_UI_InternationalizationLibrary_type = Library +_UI_InternationalizationEntry_type = Entry +_UI_Unknown_type = Object + +_UI_Unknown_datatype= Value + +_UI_InternationalizationLibrary_entries_feature = Entries +_UI_InternationalizationEntry_key_feature = Key +_UI_InternationalizationEntry_value_feature = Value +_UI_Unknown_feature = Unspecified + diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/plugin.xml b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/plugin.xml new file mode 100644 index 00000000000..d00f5dc6637 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/plugin.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> + +<!-- +--> + +<plugin> + + <extension point="org.eclipse.emf.edit.itemProviderAdapterFactories"> + <!-- @generated Internationalization --> + <factory + uri="http://www.eclipse.org/papyrus/internationalization/model" + class="org.eclipse.papyrus.infra.internationalization.provider.InternationalizationItemProviderAdapterFactory" + supportedTypes= + "org.eclipse.emf.edit.provider.IEditingDomainItemProvider + org.eclipse.emf.edit.provider.IStructuredItemContentProvider + org.eclipse.emf.edit.provider.ITreeItemContentProvider + org.eclipse.emf.edit.provider.IItemLabelProvider + org.eclipse.emf.edit.provider.IItemPropertySource"/> + </extension> + +</plugin> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/pom.xml b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/pom.xml new file mode 100644 index 00000000000..e94fe7a47e9 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/pom.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>org.eclipse.papyrus.infra-internationalization</artifactId> + <groupId>org.eclipse.papyrus</groupId> + <version>0.0.1-SNAPSHOT</version> + </parent> + <artifactId>org.eclipse.papyrus.infra.internationalization.edit</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>eclipse-plugin</packaging> +</project>
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/src-gen/org/eclipse/papyrus/infra/internationalization/provider/InternationalizationEditPlugin.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/src-gen/org/eclipse/papyrus/infra/internationalization/provider/InternationalizationEditPlugin.java new file mode 100644 index 00000000000..e424a72a7a3 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/src-gen/org/eclipse/papyrus/infra/internationalization/provider/InternationalizationEditPlugin.java @@ -0,0 +1,96 @@ +/** + * 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.infra.internationalization.provider; + +import org.eclipse.emf.common.EMFPlugin; + +import org.eclipse.emf.common.util.ResourceLocator; + +/** + * This is the central singleton for the Internationalization edit plugin. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ +public final class InternationalizationEditPlugin extends EMFPlugin { + /** + * Keep track of the singleton. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final InternationalizationEditPlugin INSTANCE = new InternationalizationEditPlugin(); + + /** + * Keep track of the singleton. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private static Implementation plugin; + + /** + * Create the instance. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public InternationalizationEditPlugin() { + super(new ResourceLocator[] {}); + } + + /** + * Returns the singleton instance of the Eclipse plugin. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the singleton instance. + * @generated + */ + @Override + public ResourceLocator getPluginResourceLocator() { + return plugin; + } + + /** + * Returns the singleton instance of the Eclipse plugin. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the singleton instance. + * @generated + */ + public static Implementation getPlugin() { + return plugin; + } + + /** + * The actual implementation of the Eclipse <b>Plugin</b>. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static class Implementation extends EclipsePlugin { + /** + * Creates an instance. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public Implementation() { + super(); + + // Remember the static instance. + // + plugin = this; + } + } + +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/src-gen/org/eclipse/papyrus/infra/internationalization/provider/InternationalizationEntryItemProvider.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/src-gen/org/eclipse/papyrus/infra/internationalization/provider/InternationalizationEntryItemProvider.java new file mode 100644 index 00000000000..7be66df9f88 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/src-gen/org/eclipse/papyrus/infra/internationalization/provider/InternationalizationEntryItemProvider.java @@ -0,0 +1,171 @@ +/** + * 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.infra.internationalization.provider; + +import java.util.Collection; +import java.util.List; + +import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.common.notify.Notification; + +import org.eclipse.emf.common.util.ResourceLocator; + +import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; +import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; +import org.eclipse.emf.edit.provider.IItemLabelProvider; +import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; +import org.eclipse.emf.edit.provider.IItemPropertySource; +import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; +import org.eclipse.emf.edit.provider.ITreeItemContentProvider; +import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; +import org.eclipse.emf.edit.provider.ItemProviderAdapter; +import org.eclipse.emf.edit.provider.ViewerNotification; + +import org.eclipse.papyrus.infra.internationalization.InternationalizationEntry; +import org.eclipse.papyrus.infra.internationalization.InternationalizationPackage; + +/** + * This is the item provider adapter for a {@link org.eclipse.papyrus.infra.internationalization.InternationalizationEntry} object. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ +public class InternationalizationEntryItemProvider extends ItemProviderAdapter implements IEditingDomainItemProvider, + IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource { + /** + * This constructs an instance from a factory and a notifier. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public InternationalizationEntryItemProvider(AdapterFactory adapterFactory) { + super(adapterFactory); + } + + /** + * This returns the property descriptors for the adapted class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) { + if (itemPropertyDescriptors == null) { + super.getPropertyDescriptors(object); + + addKeyPropertyDescriptor(object); + addValuePropertyDescriptor(object); + } + return itemPropertyDescriptors; + } + + /** + * This adds a property descriptor for the Key feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected void addKeyPropertyDescriptor(Object object) { + itemPropertyDescriptors + .add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), + getResourceLocator(), getString("_UI_InternationalizationEntry_key_feature"), //$NON-NLS-1$ + getString("_UI_PropertyDescriptor_description", "_UI_InternationalizationEntry_key_feature", //$NON-NLS-1$//$NON-NLS-2$ + "_UI_InternationalizationEntry_type"), //$NON-NLS-1$ + InternationalizationPackage.Literals.INTERNATIONALIZATION_ENTRY__KEY, true, false, false, + ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null)); + } + + /** + * This adds a property descriptor for the Value feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected void addValuePropertyDescriptor(Object object) { + itemPropertyDescriptors + .add(createItemPropertyDescriptor(((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), + getResourceLocator(), getString("_UI_InternationalizationEntry_value_feature"), //$NON-NLS-1$ + getString("_UI_PropertyDescriptor_description", "_UI_InternationalizationEntry_value_feature", //$NON-NLS-1$//$NON-NLS-2$ + "_UI_InternationalizationEntry_type"), //$NON-NLS-1$ + InternationalizationPackage.Literals.INTERNATIONALIZATION_ENTRY__VALUE, true, false, false, + ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null)); + } + + /** + * This returns InternationalizationEntry.gif. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public Object getImage(Object object) { + return overlayImage(object, getResourceLocator().getImage("full/obj16/InternationalizationEntry")); //$NON-NLS-1$ + } + + /** + * This returns the label text for the adapted class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public String getText(Object object) { + Object labelValue = ((InternationalizationEntry) object).getKey(); + String label = labelValue == null ? null : labelValue.toString(); + return label == null || label.length() == 0 ? getString("_UI_InternationalizationEntry_type") : //$NON-NLS-1$ + getString("_UI_InternationalizationEntry_type") + " " + label; //$NON-NLS-1$ //$NON-NLS-2$ + } + + /** + * This handles model notifications by calling {@link #updateChildren} to update any cached + * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void notifyChanged(Notification notification) { + updateChildren(notification); + + switch (notification.getFeatureID(InternationalizationEntry.class)) { + case InternationalizationPackage.INTERNATIONALIZATION_ENTRY__KEY: + case InternationalizationPackage.INTERNATIONALIZATION_ENTRY__VALUE: + fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true)); + return; + } + super.notifyChanged(notification); + } + + /** + * This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children + * that can be created under this object. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) { + super.collectNewChildDescriptors(newChildDescriptors, object); + } + + /** + * Return the resource locator for this item provider's resources. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public ResourceLocator getResourceLocator() { + return InternationalizationEditPlugin.INSTANCE; + } + +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/src-gen/org/eclipse/papyrus/infra/internationalization/provider/InternationalizationItemProviderAdapterFactory.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/src-gen/org/eclipse/papyrus/infra/internationalization/provider/InternationalizationItemProviderAdapterFactory.java new file mode 100644 index 00000000000..1b0fabfb979 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/src-gen/org/eclipse/papyrus/infra/internationalization/provider/InternationalizationItemProviderAdapterFactory.java @@ -0,0 +1,243 @@ +/** + * 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.infra.internationalization.provider; + +import java.util.ArrayList; +import java.util.Collection; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.Notifier; + +import org.eclipse.emf.edit.provider.ChangeNotifier; +import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; +import org.eclipse.emf.edit.provider.ComposedAdapterFactory; +import org.eclipse.emf.edit.provider.IChangeNotifier; +import org.eclipse.emf.edit.provider.IDisposable; +import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; +import org.eclipse.emf.edit.provider.IItemLabelProvider; +import org.eclipse.emf.edit.provider.IItemPropertySource; +import org.eclipse.emf.edit.provider.INotifyChangedListener; +import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; +import org.eclipse.emf.edit.provider.ITreeItemContentProvider; + +import org.eclipse.papyrus.infra.internationalization.util.InternationalizationAdapterFactory; + +/** + * This is the factory that is used to provide the interfaces needed to support Viewers. + * The adapters generated by this factory convert EMF adapter notifications into calls to {@link #fireNotifyChanged fireNotifyChanged}. + * The adapters also support Eclipse property sheets. + * Note that most of the adapters are shared among multiple instances. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ +public class InternationalizationItemProviderAdapterFactory extends InternationalizationAdapterFactory + implements ComposeableAdapterFactory, IChangeNotifier, IDisposable { + /** + * This keeps track of the root adapter factory that delegates to this adapter factory. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected ComposedAdapterFactory parentAdapterFactory; + + /** + * This is used to implement {@link org.eclipse.emf.edit.provider.IChangeNotifier}. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected IChangeNotifier changeNotifier = new ChangeNotifier(); + + /** + * This keeps track of all the supported types checked by {@link #isFactoryForType isFactoryForType}. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected Collection<Object> supportedTypes = new ArrayList<>(); + + /** + * This constructs an instance. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public InternationalizationItemProviderAdapterFactory() { + supportedTypes.add(IEditingDomainItemProvider.class); + supportedTypes.add(IStructuredItemContentProvider.class); + supportedTypes.add(ITreeItemContentProvider.class); + supportedTypes.add(IItemLabelProvider.class); + supportedTypes.add(IItemPropertySource.class); + } + + /** + * This keeps track of the one adapter used for all {@link org.eclipse.papyrus.infra.internationalization.InternationalizationLibrary} instances. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected InternationalizationLibraryItemProvider internationalizationLibraryItemProvider; + + /** + * This creates an adapter for a {@link org.eclipse.papyrus.infra.internationalization.InternationalizationLibrary}. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public Adapter createInternationalizationLibraryAdapter() { + if (internationalizationLibraryItemProvider == null) { + internationalizationLibraryItemProvider = new InternationalizationLibraryItemProvider(this); + } + + return internationalizationLibraryItemProvider; + } + + /** + * This keeps track of the one adapter used for all {@link org.eclipse.papyrus.infra.internationalization.InternationalizationEntry} instances. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected InternationalizationEntryItemProvider internationalizationEntryItemProvider; + + /** + * This creates an adapter for a {@link org.eclipse.papyrus.infra.internationalization.InternationalizationEntry}. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public Adapter createInternationalizationEntryAdapter() { + if (internationalizationEntryItemProvider == null) { + internationalizationEntryItemProvider = new InternationalizationEntryItemProvider(this); + } + + return internationalizationEntryItemProvider; + } + + /** + * This returns the root adapter factory that contains this factory. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public ComposeableAdapterFactory getRootAdapterFactory() { + return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory(); + } + + /** + * This sets the composed adapter factory that contains this factory. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) { + this.parentAdapterFactory = parentAdapterFactory; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public boolean isFactoryForType(Object type) { + return supportedTypes.contains(type) || super.isFactoryForType(type); + } + + /** + * This implementation substitutes the factory itself as the key for the adapter. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public Adapter adapt(Notifier notifier, Object type) { + return super.adapt(notifier, this); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public Object adapt(Object object, Object type) { + if (isFactoryForType(type)) { + Object adapter = super.adapt(object, type); + if (!(type instanceof Class<?>) || (((Class<?>) type).isInstance(adapter))) { + return adapter; + } + } + + return null; + } + + /** + * This adds a listener. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void addListener(INotifyChangedListener notifyChangedListener) { + changeNotifier.addListener(notifyChangedListener); + } + + /** + * This removes a listener. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void removeListener(INotifyChangedListener notifyChangedListener) { + changeNotifier.removeListener(notifyChangedListener); + } + + /** + * This delegates to {@link #changeNotifier} and to {@link #parentAdapterFactory}. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void fireNotifyChanged(Notification notification) { + changeNotifier.fireNotifyChanged(notification); + + if (parentAdapterFactory != null) { + parentAdapterFactory.fireNotifyChanged(notification); + } + } + + /** + * This disposes all of the item providers created by this factory. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void dispose() { + if (internationalizationLibraryItemProvider != null) { + internationalizationLibraryItemProvider.dispose(); + } + if (internationalizationEntryItemProvider != null) { + internationalizationEntryItemProvider.dispose(); + } + } + +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/src-gen/org/eclipse/papyrus/infra/internationalization/provider/InternationalizationLibraryItemProvider.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/src-gen/org/eclipse/papyrus/infra/internationalization/provider/InternationalizationLibraryItemProvider.java new file mode 100644 index 00000000000..0f216466b71 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/src-gen/org/eclipse/papyrus/infra/internationalization/provider/InternationalizationLibraryItemProvider.java @@ -0,0 +1,141 @@ +/** + * 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.infra.internationalization.provider; + +import java.util.Collection; +import java.util.List; + +import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.common.notify.Notification; + +import org.eclipse.emf.common.util.ResourceLocator; + +import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; +import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; +import org.eclipse.emf.edit.provider.IItemLabelProvider; +import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; +import org.eclipse.emf.edit.provider.IItemPropertySource; +import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; +import org.eclipse.emf.edit.provider.ITreeItemContentProvider; +import org.eclipse.emf.edit.provider.ItemProviderAdapter; + +import org.eclipse.papyrus.infra.internationalization.InternationalizationPackage; + +/** + * This is the item provider adapter for a {@link org.eclipse.papyrus.infra.internationalization.InternationalizationLibrary} object. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ +public class InternationalizationLibraryItemProvider extends ItemProviderAdapter implements IEditingDomainItemProvider, + IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource { + /** + * This constructs an instance from a factory and a notifier. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public InternationalizationLibraryItemProvider(AdapterFactory adapterFactory) { + super(adapterFactory); + } + + /** + * This returns the property descriptors for the adapted class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) { + if (itemPropertyDescriptors == null) { + super.getPropertyDescriptors(object); + + addEntriesPropertyDescriptor(object); + } + return itemPropertyDescriptors; + } + + /** + * This adds a property descriptor for the Entries feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected void addEntriesPropertyDescriptor(Object object) { + itemPropertyDescriptors.add(createItemPropertyDescriptor( + ((ComposeableAdapterFactory) adapterFactory).getRootAdapterFactory(), getResourceLocator(), + getString("_UI_InternationalizationLibrary_entries_feature"), //$NON-NLS-1$ + getString("_UI_PropertyDescriptor_description", "_UI_InternationalizationLibrary_entries_feature", //$NON-NLS-1$//$NON-NLS-2$ + "_UI_InternationalizationLibrary_type"), //$NON-NLS-1$ + InternationalizationPackage.Literals.INTERNATIONALIZATION_LIBRARY__ENTRIES, true, false, true, null, + null, null)); + } + + /** + * This returns InternationalizationLibrary.gif. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public Object getImage(Object object) { + return overlayImage(object, getResourceLocator().getImage("full/obj16/InternationalizationLibrary")); //$NON-NLS-1$ + } + + /** + * This returns the label text for the adapted class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public String getText(Object object) { + return getString("_UI_InternationalizationLibrary_type"); //$NON-NLS-1$ + } + + /** + * This handles model notifications by calling {@link #updateChildren} to update any cached + * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void notifyChanged(Notification notification) { + updateChildren(notification); + super.notifyChanged(notification); + } + + /** + * This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children + * that can be created under this object. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) { + super.collectNewChildDescriptors(newChildDescriptors, object); + } + + /** + * Return the resource locator for this item provider's resources. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public ResourceLocator getResourceLocator() { + return InternationalizationEditPlugin.INSTANCE; + } + +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/src/org/eclipse/papyrus/infra/internationalization/edit/provider/InternationalizationNotationItemProviderAdapterFactory.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/src/org/eclipse/papyrus/infra/internationalization/edit/provider/InternationalizationNotationItemProviderAdapterFactory.java new file mode 100644 index 00000000000..0837214f7ed --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.edit/src/org/eclipse/papyrus/infra/internationalization/edit/provider/InternationalizationNotationItemProviderAdapterFactory.java @@ -0,0 +1,57 @@ +/***************************************************************************** + * 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.infra.internationalization.edit.provider; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.NotationEditPlugin; +import org.eclipse.gmf.runtime.notation.provider.DiagramItemProvider; +import org.eclipse.gmf.runtime.notation.provider.NotationItemProviderAdapterFactory; +import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalization; + +/** + * This allows to re-implement the diagram adapter for the label + * internationalization call. + */ +public class InternationalizationNotationItemProviderAdapterFactory extends NotationItemProviderAdapterFactory { + + /** + * Constructor. + */ + public InternationalizationNotationItemProviderAdapterFactory() { + super(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.gmf.runtime.notation.provider.NotationItemProviderAdapterFactory#createDiagramAdapter() + */ + @Override + public Adapter createDiagramAdapter() { + if (diagramItemProvider == null) { + diagramItemProvider = new DiagramItemProvider(this) { + @Override + public String getText(Object object) { + String label = LabelInternationalization.getInstance().getDiagramLabel((Diagram) object); + return label == null || label.length() == 0 + ? NotationEditPlugin.INSTANCE.getString("_UI_Diagram_type", true) //$NON-NLS-1$ + : NotationEditPlugin.INSTANCE.getString("_UI_Diagram_type", true) + " " + label; //$NON-NLS-1$ //$NON-NLS-2$ + } + }; + } + + return (Adapter) diagramItemProvider; + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/.classpath b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/.classpath new file mode 100644 index 00000000000..eca7bdba8f0 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/.project b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/.project new file mode 100644 index 00000000000..215b0c7400b --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/.project @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.papyrus.infra.internationalization.ui</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.oomph.version.VersionBuilder</name> + <arguments> + <dictionary> + <key>check.maven.pom</key> + <value>true</value> + </dictionary> + <dictionary> + <key>ignore.lower.bound.dependency.ranges</key> + <value>true</value> + </dictionary> + <dictionary> + <key>release.path</key> + <value>/org.eclipse.papyrus.releng.main.release/release.xml</value> + </dictionary> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.oomph.version.VersionNature</nature> + <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature> + </natures> +</projectDescription> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/.settings/org.eclipse.jdt.core.prefs b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..0c68a61dca8 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/META-INF/MANIFEST.MF b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..bd14dc1bd0a --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.infra.internationalization.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-ClassPath: . +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: org.eclipse.papyrus.infra.internationalization.ui, + org.eclipse.papyrus.infra.internationalization.ui.dialogs, + org.eclipse.papyrus.infra.internationalization.ui.handlers +Require-Bundle: org.eclipse.emf.ecore;bundle-version="[2.12.0,3.0.0)", + org.eclipse.ui.workbench;bundle-version="[3.108.0,4.0.0)", + org.eclipse.ui;bundle-version="[3.107.0,4.0.0)", + org.eclipse.papyrus.infra.core.log;bundle-version="[1.2.0,2.0.0)", + org.eclipse.papyrus.infra.ui;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.infra.emf;bundle-version="[2.2.0,3.0.0)", + org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="[3.0.0,4.0.0)", + org.eclipse.papyrus.infra.internationalization.common;bundle-version="[1.0.0,2.0.0)" +Bundle-ActivationPolicy: lazy +Bundle-Activator: org.eclipse.papyrus.infra.internationalization.ui.Activator diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/about.html b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/about.html new file mode 100644 index 00000000000..598b3684879 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>May 12, 2008</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/build.properties b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/build.properties new file mode 100644 index 00000000000..2964bc2d7b1 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/build.properties @@ -0,0 +1,11 @@ +# + +bin.includes = .,\ + META-INF/,\ + about.html,\ + plugin.xml,\ + plugin.properties +jars.compile.order = . +source.. = src/ +output.. = bin/ +src.includes = about.html diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/plugin.properties b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/plugin.properties new file mode 100644 index 00000000000..383429a1252 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/plugin.properties @@ -0,0 +1,4 @@ +# + +pluginName = Papyrus Internationalization UI +providerName = Eclipse Modeling Project diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/plugin.xml b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/plugin.xml new file mode 100644 index 00000000000..490fd5dec9a --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/plugin.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> + +<!-- +--> + +<plugin> + + <extension + point="org.eclipse.ui.commands"> + <command + defaultHandler="org.eclipse.papyrus.infra.internationalization.ui.handlers.InternationalizationCommandHandler" + description="This allows to internationalize the NamedElements, Diagrams and Tables" + id="org.eclipse.papyrus.infra.internationalization.activeInternationalization" + name="Configure internationalization"> + <!--state + class="org.eclipse.papyrus.infra.internationalization.ui.handlers.InternationalizationToggleState" + id="org.eclipse.ui.commands.toggleState"> + </state--> + </command> + </extension> + +</plugin> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/pom.xml b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/pom.xml new file mode 100644 index 00000000000..5bf9055d118 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/pom.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>org.eclipse.papyrus.infra-internationalization</artifactId> + <groupId>org.eclipse.papyrus</groupId> + <version>0.0.1-SNAPSHOT</version> + </parent> + <artifactId>org.eclipse.papyrus.infra.internationalization.ui</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>eclipse-plugin</packaging> +</project>
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/src/org/eclipse/papyrus/infra/internationalization/ui/Activator.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/src/org/eclipse/papyrus/infra/internationalization/ui/Activator.java new file mode 100644 index 00000000000..c7d97b28686 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/src/org/eclipse/papyrus/infra/internationalization/ui/Activator.java @@ -0,0 +1,77 @@ +/***************************************************************************** + * 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.infra.internationalization.ui; + +import org.eclipse.papyrus.infra.core.log.LogHelper; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle. + */ +public class Activator extends AbstractUIPlugin { + + /** + * The plug-in ID. + */ + public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.internationalization.ui"; //$NON-NLS-1$ + + /** + * The shared instance. + */ + private static Activator plugin; + + /** + * The log helper. + */ + public static LogHelper log; + + /** + * The constructor + */ + public Activator() { + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(final BundleContext context) throws Exception { + super.start(context); + plugin = this; + log = new LogHelper(this); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(final BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/src/org/eclipse/papyrus/infra/internationalization/ui/dialogs/InternationalizationDialog.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/src/org/eclipse/papyrus/infra/internationalization/ui/dialogs/InternationalizationDialog.java new file mode 100644 index 00000000000..0d99705fd8d --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/src/org/eclipse/papyrus/infra/internationalization/ui/dialogs/InternationalizationDialog.java @@ -0,0 +1,251 @@ +/***************************************************************************** + * 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.infra.internationalization.ui.dialogs; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.Locale; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.jface.dialogs.TrayDialog; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesUtils; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + +/** + * The dialog to manage the internationalization configuration. This will + * contains: - Checkbox to determinate if the internationalization must be used + * or not - Viewer to select the language of the internationalization + */ +public class InternationalizationDialog extends TrayDialog { + + /** + * The resource URI corresponding to the papyrus model. This is needed to + * get the preference of the papyrus model. + */ + private URI resourceURI; + + /** + * The viewer for the language selection. + */ + protected TableViewer tableViewer; + + /** + * The widget to manage the use internationalization value. + */ + protected Button useInternationalizationButton; + + /** + * Keep the internationalization use value after the dialog closed. + */ + protected boolean useInternationalizationValue; + + /** + * Keep the locale value after the dialog closed. + */ + protected Locale localeValue; + + /** + * Boolean to determinate if the use internationalization must be displayed. + */ + private boolean displayUse; + + /** + * Constructor. + * + * @param parentShell + * The parent shell. + * @param resourceURI + * The resource URI corresponding to the papyrus model (need to + * get preference of the papyrus model). + * @param displayUse + * Boolean to determinate if the use internationalization must be + * displayed. + */ + public InternationalizationDialog(final Shell parentShell, final URI resourceURI, final boolean displayUse) { + super(parentShell); + setResourceURI(resourceURI); + this.displayUse = displayUse; + } + + /** + * This allows to set the resource URI. + * + * @param resourceURI + * The resource URI to set. + */ + public void setResourceURI(final URI resourceURI) { + this.resourceURI = resourceURI; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createDialogArea(final Composite parent) { + final Composite composite = (Composite) super.createDialogArea(parent); + final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.widthHint = 300; + data.heightHint = 300; + composite.setLayoutData(data); + + getShell().setText("Configure internationalization"); //$NON-NLS-1$ + getShell().setImage(org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("/icons/papyrus.png")); //$NON-NLS-1$ + + if (displayUse()) { + createUseInternationalization(composite); + } + createLanguage(composite); + initializeValues(); + + return composite; + } + + /** + * Determinates if the use internationalization checkbox must be displayed. + * + * @return <code>true</code> if this will be displayed, <code>false</code> + * otherwise. + */ + protected boolean displayUse() { + return displayUse; + } + + /** + * This allows to create the checkbox which manage the use + * internationalization button. + * + * @param parent + * The parent composite. + */ + protected void createUseInternationalization(final Composite parent) { + useInternationalizationButton = new Button(parent, SWT.CHECK); + useInternationalizationButton.setText("Use internationalization"); + } + + /** + * This allows to create the viewer to select the language which be used for + * the internationalization. + * + * @param parent + * The parent composite. + */ + protected void createLanguage(final Composite parent) { + // Create the viewer and the grid data + tableViewer = new TableViewer(parent, SWT.BORDER); + final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + data.minimumHeight = 200; + data.minimumWidth = 100; + tableViewer.getTable().setLayoutData(data); + + // Set its label and content providers + tableViewer.setContentProvider(new ArrayContentProvider()); + tableViewer.setLabelProvider(new LabelProvider()); + + // Set the input with the available locales + final List<Locale> availableLocales = Arrays.asList(Locale.getAvailableLocales()); + availableLocales.sort(new Comparator<Locale>() { + + @Override + public int compare(final Locale arg0, final Locale arg1) { + return arg0.toString().compareTo(arg1.toString()); + } + + }); + tableViewer.setInput(availableLocales); + + // Add a double click listener to close the dialog on double click + tableViewer.addDoubleClickListener(new IDoubleClickListener() { + + @Override + public void doubleClick(DoubleClickEvent event) { + setReturnCode(OK); + close(); + } + }); + } + + /** + * This allows to initialize the values of fields. + */ + protected void initializeValues() { + if (displayUse()) { + // Manage the selection change for the internationalization use + // button + useInternationalizationButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent e) { + useInternationalizationValue = useInternationalizationButton.getSelection(); + } + }); + // Initialize the boolean value from the preference of papyrus model + final boolean useInternationalization = InternationalizationPreferencesUtils + .getInternationalizationPreference(resourceURI); + useInternationalizationButton.setSelection(useInternationalization); + useInternationalizationValue = useInternationalization; + } + + // Manage the selection change for locale + tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(final SelectionChangedEvent event) { + final ISelection selection = event.getSelection(); + final Locale localeSelected = (Locale) ((StructuredSelection) selection).getFirstElement(); + localeValue = localeSelected; + } + }); + // Initialize the locale value from the preference of papyrus model + final Locale locale = InternationalizationPreferencesUtils.getLocalePreference(resourceURI); + tableViewer.setSelection(new StructuredSelection(locale)); + tableViewer.reveal(locale); + } + + /** + * Get the use internationalization button value. + * + * @return The use internationalization button value. + */ + public boolean getUseInternationalizationValue() { + return useInternationalizationValue; + } + + /** + * Get the locale value to use for the internationalization. + * + * @return The locale value. + */ + public Locale getLocaleValue() { + return localeValue; + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/src/org/eclipse/papyrus/infra/internationalization/ui/handlers/InternationalizationCommandHandler.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/src/org/eclipse/papyrus/infra/internationalization/ui/handlers/InternationalizationCommandHandler.java new file mode 100644 index 00000000000..93ad0a6650d --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.ui/src/org/eclipse/papyrus/infra/internationalization/ui/handlers/InternationalizationCommandHandler.java @@ -0,0 +1,167 @@ +/***************************************************************************** + * 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.infra.internationalization.ui.handlers; + +import java.util.Iterator; +import java.util.Locale; + +import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.command.UnexecutableCommand; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.emf.commands.AddToResourceCommand; +import org.eclipse.papyrus.infra.emf.commands.RemoveFromResourcecommand; +import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; +import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource; +import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel; +import org.eclipse.papyrus.infra.internationalization.common.command.LocaleInternationalizationPreferenceCommand; +import org.eclipse.papyrus.infra.internationalization.common.command.UseInternationalizationPreferenceCommand; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesConstants; +import org.eclipse.papyrus.infra.internationalization.ui.Activator; +import org.eclipse.papyrus.infra.internationalization.ui.dialogs.InternationalizationDialog; +import org.eclipse.papyrus.infra.ui.command.AbstractCommandHandler; +import org.eclipse.ui.PlatformUI; + +/** + * The handler for the internationalization. + */ +public class InternationalizationCommandHandler extends AbstractCommandHandler { + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.ui.command.AbstractCommandHandler#getCommand(org.eclipse.core.expressions.IEvaluationContext) + */ + @Override + protected Command getCommand(final IEvaluationContext context) { + Command resultCommand = UnexecutableCommand.INSTANCE; + + final EObject selectedElement = getSelectedElement(); + + final URI neededURIResource = getRootNotationURI(selectedElement); + + Resource notationResource = null; + final Iterator<Resource> resources = selectedElement.eResource().getResourceSet().getResources().iterator(); + while (resources.hasNext() && null == notationResource) { + final Resource resource = resources.next(); + if (neededURIResource.equals(resource.getURI())) { // $NON-NLS-1$ + notationResource = resource; + } + } + + if (null != notationResource) { + final InternationalizationDialog dialog = new InternationalizationDialog( + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), notationResource.getURI(), true); + + if (Window.OK == dialog.open()) { + + final boolean useInternationalizationValue = dialog.getUseInternationalizationValue(); + final Locale localeValue = dialog.getLocaleValue(); + + EAnnotation annotation = null; + + // Search the internationalization annotation in the notation + // resource + for (final EObject objectContent : notationResource.getContents()) { + if (objectContent instanceof EAnnotation + && InternationalizationPreferencesConstants.INTERNATIONALIZATION_ANNOTATION_LABEL + .equals(((EAnnotation) objectContent).getSource())) { + annotation = (EAnnotation) objectContent; + } + } + + final CompoundCommand compoundCommand = new CompoundCommand("Create internationalization command"); //$NON-NLS-1$ + + if (null != annotation) { + // Remove the existing annotation + try { + compoundCommand.append(new RemoveFromResourcecommand( + ServiceUtilsForResource.getInstance().getTransactionalEditingDomain(notationResource), + notationResource, annotation)); + } catch (final ServiceException e) { + Activator.log.error(e); + } + compoundCommand + .append(new UseInternationalizationPreferenceCommand(notationResource.getURI(), false)); + } + + if (useInternationalizationValue && null != localeValue) { + // Create the annotation if the internationalization value + // is not false + annotation = EcoreFactory.eINSTANCE.createEAnnotation(); + annotation + .setSource(InternationalizationPreferencesConstants.INTERNATIONALIZATION_ANNOTATION_LABEL); + if (useInternationalizationValue) { + annotation.getDetails().put( + InternationalizationPreferencesConstants.USE_DETAIL_ANNOTATION_LABEL, + Boolean.toString(useInternationalizationValue)); + compoundCommand.append(new UseInternationalizationPreferenceCommand(notationResource.getURI(), + useInternationalizationValue)); + } + if (null != localeValue) { + annotation.getDetails().put(InternationalizationPreferencesConstants.LANGUAGE_PREFERENCE, + localeValue.toString()); + compoundCommand.append(new LocaleInternationalizationPreferenceCommand( + notationResource.getURI(), localeValue.toString())); + } + compoundCommand.append(new GMFtoEMFCommandWrapper(new AddToResourceCommand( + ((ModelSet) notationResource.getResourceSet()).getTransactionalEditingDomain(), + notationResource, annotation))); + } + + if (!compoundCommand.isEmpty()) { + resultCommand = compoundCommand; + } + } + } + + return resultCommand; + } + + /** + * Get the root notation URI (this allows to manage the control mode + * elements) + * + * @param selectedObject + * The initial selected object. + * @return The {@link URI} of the root notation. + */ + protected URI getRootNotationURI(final EObject selectedObject) { + // Get the root container of the selected object + final EObject rootContainer = EcoreUtil.getRootContainer(selectedObject); + + URI rootURI = rootContainer.eResource().getURI(); + // Remove the file extension and add the notation file extension + return rootURI.trimFileExtension().appendFileExtension(NotationModel.NOTATION_FILE_EXTENSION); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.ui.command.AbstractCommandHandler#setEnabled(java.lang.Object) + */ + @Override + public void setEnabled(final Object evaluationContext) { + setBaseEnabled(true); + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/.classpath b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/.classpath new file mode 100644 index 00000000000..eca7bdba8f0 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/.project b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/.project new file mode 100644 index 00000000000..8fd4ddeebb4 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/.project @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.papyrus.infra.internationalization.utils</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.oomph.version.VersionBuilder</name> + <arguments> + <dictionary> + <key>check.maven.pom</key> + <value>true</value> + </dictionary> + <dictionary> + <key>ignore.lower.bound.dependency.ranges</key> + <value>true</value> + </dictionary> + <dictionary> + <key>release.path</key> + <value>/org.eclipse.papyrus.releng.main.release/release.xml</value> + </dictionary> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.oomph.version.VersionNature</nature> + <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature> + </natures> +</projectDescription> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/.settings/org.eclipse.jdt.core.prefs b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..0c68a61dca8 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/META-INF/MANIFEST.MF b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..bb0ec4e2ce5 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/META-INF/MANIFEST.MF @@ -0,0 +1,25 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.infra.internationalization.utils;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-ClassPath: . +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: org.eclipse.papyrus.infra.internationalization.utils.commands, + org.eclipse.papyrus.infra.internationalization.utils.utils +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.emf.ecore;visibility:=reexport, + org.eclipse.ui.workbench, + org.eclipse.papyrus.infra.core.log;bundle-version="[1.2.0,2.0.0)", + org.eclipse.papyrus.infra.core;bundle-version="[2.0.0,3.0.0)", + org.eclipse.gmf.runtime.notation.edit;bundle-version="[1.7.0,2.0.0)", + org.eclipse.papyrus.infra.nattable.model;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.infra.internationalization;bundle-version="[1.0.0,2.0.0)", + org.eclipse.papyrus.infra.emf;bundle-version="[2.2.0,3.0.0)", + org.eclipse.jface;bundle-version="[3.12.0,4.0.0)", + org.eclipse.papyrus.infra.ui;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.infra.internationalization.common;bundle-version="[1.0.0,2.0.0)" +Bundle-ActivationPolicy: lazy +Bundle-Activator: org.eclipse.papyrus.infra.internationalization.utils.Activator diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/about.html b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/about.html new file mode 100644 index 00000000000..598b3684879 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>May 12, 2008</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/build.properties b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/build.properties new file mode 100644 index 00000000000..2964bc2d7b1 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/build.properties @@ -0,0 +1,11 @@ +# + +bin.includes = .,\ + META-INF/,\ + about.html,\ + plugin.xml,\ + plugin.properties +jars.compile.order = . +source.. = src/ +output.. = bin/ +src.includes = about.html diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/plugin.properties b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/plugin.properties new file mode 100644 index 00000000000..eb11be415db --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/plugin.properties @@ -0,0 +1,4 @@ +# + +pluginName = Papyrus Internationalization Utils +providerName = Eclipse Modeling Project diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/plugin.xml b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/plugin.xml new file mode 100644 index 00000000000..7ac51d15095 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/plugin.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> + +<!-- +--> + +<plugin> + +</plugin> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/pom.xml b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/pom.xml new file mode 100644 index 00000000000..b2e0417717d --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/pom.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>org.eclipse.papyrus.infra-internationalization</artifactId> + <groupId>org.eclipse.papyrus</groupId> + <version>0.0.1-SNAPSHOT</version> + </parent> + <artifactId>org.eclipse.papyrus.infra.internationalization.utils</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>eclipse-plugin</packaging> +</project>
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/Activator.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/Activator.java new file mode 100644 index 00000000000..a3ea85f70bd --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/Activator.java @@ -0,0 +1,77 @@ +/***************************************************************************** + * 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.infra.internationalization.utils; + +import org.eclipse.papyrus.infra.core.log.LogHelper; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle. + */ +public class Activator extends AbstractUIPlugin { + + /** + * The plug-in ID. + */ + public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.internationalization.utils"; //$NON-NLS-1$ + + /** + * The shared instance. + */ + private static Activator plugin; + + /** + * The log helper. + */ + public static LogHelper log; + + /** + * The constructor + */ + public Activator() { + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(final BundleContext context) throws Exception { + super.start(context); + plugin = this; + log = new LogHelper(this); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(final BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/commands/InternationalizationPasteCommand.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/commands/InternationalizationPasteCommand.java new file mode 100644 index 00000000000..704df3599d4 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/commands/InternationalizationPasteCommand.java @@ -0,0 +1,84 @@ +/***************************************************************************** + * 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.infra.internationalization.utils.commands; + +import java.util.Locale; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.papyrus.infra.internationalization.utils.utils.LabelInternationalizationUtils; + +/** + * A Command to set the internationalization of the object for the locale. + */ +public class InternationalizationPasteCommand extends RecordingCommand { + + /** + * The prefix to add. + */ + public static final String COPY_OF = "CopyOf_"; //$NON-NLS-1$ + + + /** + * The object to set the label. + */ + private EObject eObject; + + /** + * The label for the object. + */ + private String newLabel; + + /** + * The locale for the internationalization label for object. + */ + private Locale locale; + + /** + * + * Constructor. + * + * @param domain The editing domain. + * @param eObject The object to set the label. + * @param initialLabel The label for the object. + * @param locale The locale for the internationalization label for object. + */ + public InternationalizationPasteCommand(final TransactionalEditingDomain domain, final EObject eObject, final String initialLabel, final Locale locale) { + super(domain); + this.eObject = eObject; + this.newLabel = getNewLabel(initialLabel); + this.locale = locale; + } + + /** + * Get the label modified from the initial label. + * + * @param initialLabel The initial label. + * @return The modified label. + */ + private String getNewLabel(final String initialLabel){ + return new StringBuilder(COPY_OF).append(initialLabel).toString(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.transaction.RecordingCommand#doExecute() + */ + @Override + protected void doExecute() { + LabelInternationalizationUtils.setLabel(eObject, newLabel, locale); + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/InternationalizationConstants.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/InternationalizationConstants.java new file mode 100644 index 00000000000..01f51b23270 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/InternationalizationConstants.java @@ -0,0 +1,30 @@ +/***************************************************************************** + * 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.infra.internationalization.utils.utils; + +/** + * This class defines the constants for the internationalization. + */ +public class InternationalizationConstants { + + /** + * The label property path. + */ + public static final String LABEL_PROPERTY_PATH = "label"; //$NON-NLS-1$ + + /** + * The keyword property path. + */ + public static final String KEYWORD_PROPERTY_PATH = "keyword"; //$NON-NLS-1$ +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalization.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalization.java new file mode 100644 index 00000000000..257cca4d333 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalization.java @@ -0,0 +1,229 @@ +/***************************************************************************** + * 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.infra.internationalization.utils.utils; + +import java.util.Locale; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesUtils; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; + +/** + * The internationalization label manager. + */ +public class LabelInternationalization { + + /** + * The singleton instance. + */ + private static LabelInternationalization instance; + + /** + * Constructor. + */ + protected LabelInternationalization() { + + } + + /** + * Get the singleton instance (create it if not existing). + * + * @return The singleton instance. + */ + public static LabelInternationalization getInstance() { + if (null == instance) { + instance = new LabelInternationalization(); + } + return instance; + } + + /** + * This allows to get the label of the diagram without the getName when the + * label is null. + * + * @param diagram + * The diagram. + * @return The label of the diagram. + */ + public String getDiagramLabelWithoutName(final Diagram diagram) { + return getDiagramLabelWithoutName(diagram, true); + } + + /** + * This allows to get the label of the diagram without the getName when the + * label is null. + * + * @param diagram + * The diagram. + * @param localize + * Boolean to determinate if the locale must be used. + * @return The label of the diagram. + */ + public String getDiagramLabelWithoutName(final Diagram diagram, final boolean localize) { + return LabelInternationalizationUtils.getLabelWithoutSubstract(diagram, localize); + } + + /** + * This allows to get the label of the diagram. + * + * @param diagram + * The diagram. + * @return The label of the diagram or the name if the label is null. + */ + public String getDiagramLabel(final Diagram diagram) { + return getDiagramLabel(diagram, true); + } + + /** + * This allows to get the label of the diagram. + * + * @param diagram + * The diagram. + * @param localize + * Boolean to determinate if the locale must be used. + * @return The label of the diagram or the name if the label is null. + */ + public String getDiagramLabel(final Diagram diagram, final boolean localize) { + String result = null; + if (null != diagram.eResource() && InternationalizationPreferencesUtils.getInternationalizationPreference(diagram)) { + result = getDiagramLabelWithoutName(diagram, localize); + } + return null != result ? result : diagram.getName(); + } + + /** + * This allows to set the diagram label. + * + * @param diagram + * The diagram. + * @param value + * The label value. + * @param locale + * The locale for which set the value (if <code>null</code> set + * it for the current locale). + */ + public void setDiagramLabel(final Diagram diagram, final String value, final Locale locale) { + LabelInternationalizationUtils.setLabel(diagram, value, locale); + } + + /** + * This allows to get the set diagram label command. + * + * @param domain + * The editing domain to use. + * @param diagram + * The diagram. + * @param value + * The value to set. + * @param locale + * The locale for which set the value (if <code>null</code> set + * it for the current locale). + * @return The command which allow to set the diagram label. + */ + public Command getSetDiagramLabelCommand(final EditingDomain domain, final Diagram diagram, final String value, + final Locale locale) { + return LabelInternationalizationUtils.getSetLabelCommand(domain, diagram, value, locale); + } + + /** + * This allows to get the label of the table without the getName when the + * label is null. + * + * @param table + * The table. + * @return The label of the table. + */ + public String getTableLabelWithoutName(final Table table) { + return getTableLabelWithoutName(table, true); + } + + /** + * This allows to get the label of the table without the getName when the + * label is null. + * + * @param table + * The table. + * @param localize + * Boolean to determinate if the locale must be used. + * @return The label of the table. + */ + public String getTableLabelWithoutName(final Table table, final boolean localize) { + return LabelInternationalizationUtils.getLabelWithoutSubstract(table, localize); + } + + /** + * This allows to get the label of the table. + * + * @param table + * The table. + * @return The label of the table or the name if the label is null. + */ + public String getTableLabel(final Table table) { + return getTableLabel(table, true); + } + + /** + * This allows to get the label of the table. + * + * @param table + * The table. + * @param localize + * Boolean to determinate if the locale must be used. + * @return The label of the table or the name if the label is null. + */ + public String getTableLabel(final Table table, final boolean localize) { + String result = null; + if (null != table.eResource() && InternationalizationPreferencesUtils.getInternationalizationPreference(table)) { + result = getTableLabelWithoutName(table, localize); + } + return null != result ? result : table.getName(); + } + + /** + * This allows to set the table label. + * + * @param table + * The table. + * @param value + * The label value. + * @param locale + * The locale for which set the value (if <code>null</code> set + * it for the current locale). + */ + public void setTableLabel(final Table table, final String value, final Locale locale) { + LabelInternationalizationUtils.setLabel(table, value, locale); + } + + /** + * This allows to get the set table label command. + * + * @param domain + * The editing domain to use. + * @param table + * The table. + * @param value + * The value to set. + * @param locale + * The locale for which set the value (if <code>null</code> set + * it for the current locale). + * @return The command which allow to set the table label. + */ + public Command getSetTableLabelCommand(final EditingDomain domain, final Table table, final String value, + final Locale locale) { + return LabelInternationalizationUtils.getSetLabelCommand(domain, table, value, locale); + } + +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationPreferencesUtils.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationPreferencesUtils.java new file mode 100644 index 00000000000..8ef77d9c261 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationPreferencesUtils.java @@ -0,0 +1,64 @@ +/***************************************************************************** + * 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.infra.internationalization.utils.utils; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesUtils; + +/** + * Open the label internationalization preferences to the others plugins with the utils plugin. + */ +public class LabelInternationalizationPreferencesUtils { + + /** + * This allows to modify the internationalization preference value. + * + * @param eObject The {@link EObject) corresponding (to get its resource). + * @param value The new preference value. + */ + public static void setInternationalizationPreference(final EObject eObject, final boolean value){ + InternationalizationPreferencesUtils.setInternationalizationPreference(eObject, value); + } + + /** + * This allows to modify the internationalization preference value. + * + * @param resource The {@link Resource) to get the papyrus project preferences. + * @param value The new preference value. + */ + public static void setInternationalizationPreference(final Resource resource, final boolean value){ + InternationalizationPreferencesUtils.setInternationalizationPreference(resource, value); + } + + /** + * This allows to get the internationalization preference value. + * + * @param eObject The {@link EObject) corresponding (to get its resource). + * @return <code>true</code> if the preference value is set to true, <code>false</code> otherwise. + */ + public static boolean getInternationalizationPreference(final EObject eObject){ + return InternationalizationPreferencesUtils.getInternationalizationPreference(eObject); + } + + /** + * This allows to get the internationalization preference value. + * + * @param resource The {@link Resource) to get the papyrus project preferences. + * @return <code>true</code> if the preference value is set to true, <code>false</code> otherwise. + */ + public static boolean getInternationalizationPreference(final Resource resource){ + return InternationalizationPreferencesUtils.getInternationalizationPreference(resource); + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationUtils.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationUtils.java new file mode 100644 index 00000000000..ee57125a72a --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization.utils/src/org/eclipse/papyrus/infra/internationalization/utils/utils/LabelInternationalizationUtils.java @@ -0,0 +1,259 @@ +/***************************************************************************** + * 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.infra.internationalization.utils.utils; + +import java.util.HashSet; +import java.util.Locale; +import java.util.Set; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.UnexecutableCommand; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.core.resource.NotFoundException; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.core.services.ServicesRegistry; +import org.eclipse.papyrus.infra.core.utils.ServiceUtils; +import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceSet; +import org.eclipse.papyrus.infra.internationalization.InternationalizationEntry; +import org.eclipse.papyrus.infra.internationalization.common.editor.IInternationalizationEditor; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesUtils; +import org.eclipse.papyrus.infra.internationalization.modelresource.InternationalizationModelResource; + +/** + * This allows to manage the utils methods for the internationalization. + */ +public class LabelInternationalizationUtils { + + /** + * This allows to get the label without getting name if the label is null. + * + * @param eObject + * The object. + * @param localize + * Boolean to determinate if the localize must be used or not. + * @return The label of the object. + */ + public static String getLabelWithoutSubstract(final EObject eObject, final boolean localize) { + String result = null; + + try { + final InternationalizationModelResource internationalizationResource = getInternationalizationModelResource( + eObject.eResource()); + + if (null != internationalizationResource) { + result = internationalizationResource.getValueForEntryKey(eObject.eResource().getURI(), eObject); + } + } catch (final Exception e) { + // Do nothing + } + + return result; + } + + /** + * This allows to set the label. + * + * @param eObject + * The object. + * @param value + * The value to set. + * @param locale + * The locale for which set the value (if <code>null</code> set + * it for the current locale). + */ + public static void setLabel(final EObject eObject, final String value, final Locale locale) { + try { + final InternationalizationModelResource internationalizationResource = getInternationalizationModelResource( + eObject.eResource()); + + if (null != internationalizationResource) { + + Locale localeToUse = locale; + if (null == localeToUse) { + localeToUse = InternationalizationPreferencesUtils.getLocalePreference(eObject); + } + + internationalizationResource.setValue(eObject.eResource().getURI(), eObject, value, localeToUse); + } + } catch (final Exception e) { + // Do nothing + } + } + + /** + * This allows to get the set label command. + * + * @param domain + * The editing domain to use. + * @param eObject + * The object. + * @param value + * The value to set. + * @param locale + * The locale for which set the value (if <code>null</code> set + * it for the current locale). + * @return The command which allow to set the label. + */ + public static Command getSetLabelCommand(final EditingDomain domain, final EObject eObject, final String value, + final Locale locale) { + Command resultCommand = null; + try { + final InternationalizationModelResource internationalizationResource = getInternationalizationModelResource( + eObject.eResource()); + + if (null != internationalizationResource) { + + Locale localeToUse = locale; + if (null == localeToUse) { + localeToUse = InternationalizationPreferencesUtils.getLocalePreference(eObject); + } + + resultCommand = internationalizationResource.getSetValueCommand(domain, eObject.eResource().getURI(), + eObject, value, localeToUse); + } + } catch (final Exception e) { + // Do nothing + } + return null != resultCommand ? resultCommand : UnexecutableCommand.INSTANCE; + } + + /** + * This allows to get the {@link InternationalizationEntry} corresponding to + * the object and the key. + * + * @param eObject + * The object to search. + * @param key + * The key to search in the internationalization library. + * @return The corresponding {@link InternationalizationEntry}. + */ + public static InternationalizationEntry getInternationalizationEntry(final EObject eObject, final Object key) { + InternationalizationEntry resultEntry = null; + + try { + final InternationalizationModelResource internationalizationResource = getInternationalizationModelResource( + eObject.eResource()); + + if (null != internationalizationResource) { + resultEntry = internationalizationResource.getEntryForKey(eObject.eResource().getURI(), key, + InternationalizationPreferencesUtils.getLocalePreference(eObject)); + } + } catch (final Exception e) { + // Do nothing + } + + return resultEntry; + } + + /** + * This allows to get the {@link InternationalizationEntry} corresponding to + * the object and the key. + * + * @param eObject + * The object to search. + * @param key + * The key to search in the internationalization library. + * @param locale + * The locale of which get the value + * @return The corresponding {@link InternationalizationEntry}. + */ + public static InternationalizationEntry getInternationalizationEntry(final EObject eObject, final Object key, + final Locale locale) { + InternationalizationEntry resultEntry = null; + + try { + final InternationalizationModelResource internationalizationResource = getInternationalizationModelResource( + eObject.eResource()); + + if (null != internationalizationResource) { + + Locale localeToUse = locale; + if (null == localeToUse) { + localeToUse = InternationalizationPreferencesUtils.getLocalePreference(eObject); + } + + resultEntry = internationalizationResource.getEntryForKey(eObject.eResource().getURI(), key, locale); + } + } catch (final Exception e) { + // Do nothing + } + + return resultEntry; + } + + /** + * Get the available locales for the resource. + * + * @param resource + * The resource. + * @return The available locales of loaded properties files for resource. + */ + public static Set<Locale> getAvailableLocales(final Resource resource) { + Set<Locale> locales = null; + + try { + final InternationalizationModelResource internationalizationResource = getInternationalizationModelResource( + resource); + + locales = internationalizationResource.getAvailablePropertiesLocales(resource.getURI()); + } catch (final Exception e) { + // Do nothing + } + + return null != locales ? locales : new HashSet<Locale>(); + } + + /** + * Get the internationalizationModelResource from the model set. + * + * @param resource + * The initial resource. + * @return The internationalization model resource. + * @throws ServiceException + * The service registry exception. + * @throws NotFoundException + * The model not found exception. + */ + public static InternationalizationModelResource getInternationalizationModelResource(final Resource resource) + throws ServiceException, NotFoundException { + final ServicesRegistry servicesRegistry = ServiceUtilsForResourceSet.getInstance() + .getServiceRegistry(resource.getResourceSet()); + final ModelSet modelSet = ServiceUtils.getInstance().getModelSet(servicesRegistry); + return (InternationalizationModelResource) modelSet.getModelChecked(InternationalizationModelResource.MODEL_ID); + } + + /** + * This allows to manage part label synchronizer for the object + * corresponding to the editor part. + * + * @param eObject + * The EObject (seems to be Table or Diagram). + * @param editorPart + * The editor part corresponding to the EObject. + */ + public static void managePartLabelSynchronizer(final EObject eObject, + final IInternationalizationEditor editorPart) { + try { + final InternationalizationModelResource internationalizationResource = getInternationalizationModelResource( + eObject.eResource()); + + internationalizationResource.addEditorPartForEObject(eObject, editorPart); + } catch (final Exception e) { + // Do nothing + } + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/.classpath b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/.classpath new file mode 100644 index 00000000000..e7a4ca0c29c --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/.classpath @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src-gen"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/.project b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/.project new file mode 100644 index 00000000000..b85a6de555c --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/.project @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.papyrus.infra.internationalization</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.oomph.version.VersionBuilder</name> + <arguments> + <dictionary> + <key>check.maven.pom</key> + <value>true</value> + </dictionary> + <dictionary> + <key>ignore.lower.bound.dependency.ranges</key> + <value>true</value> + </dictionary> + <dictionary> + <key>release.path</key> + <value>/org.eclipse.papyrus.releng.main.release/release.xml</value> + </dictionary> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.oomph.version.VersionNature</nature> + <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature> + </natures> +</projectDescription> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/.settings/org.eclipse.core.resources.prefs b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000000..a8dcccbdbbf --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +encoding//src/site/mediawiki/internationalizationDev-toc.xml=utf-8 +encoding//src/site/mediawiki/internationalizationDev.html=UTF-8 +encoding//target/site/generated-eclipse-help/internationalizationDev-toc.xml=utf-8 +encoding//target/site/generated-eclipse-help/internationalizationDev.html=UTF-8 diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/.settings/org.eclipse.jdt.core.prefs b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..0c68a61dca8 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/META-INF/MANIFEST.MF b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..311910f0ab1 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/META-INF/MANIFEST.MF @@ -0,0 +1,29 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.infra.internationalization;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-ClassPath: . +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: org.eclipse.papyrus.infra.internationalization, + org.eclipse.papyrus.infra.internationalization.commands, + org.eclipse.papyrus.infra.internationalization.modelresource, + org.eclipse.papyrus.infra.internationalization.modelsnippet, + org.eclipse.papyrus.infra.internationalization.util, + org.eclipse.papyrus.infra.internationalization.utils +Require-Bundle: org.eclipse.emf.ecore;bundle-version="[2.12.0,3.0.0)";visibility:=reexport, + org.eclipse.ui.workbench;bundle-version="[3.108.0,4.0.0)", + org.eclipse.papyrus.infra.nattable.model;bundle-version="[2.0.0,3.0.0)", + org.eclipse.papyrus.infra.core.log;bundle-version="[1.2.0,2.0.0)", + org.eclipse.papyrus.infra.core;bundle-version="[2.3.0,3.0.0)", + org.eclipse.gmf.runtime.notation.edit;bundle-version="[1.7.0,2.0.0)", + org.eclipse.papyrus.infra.emf;bundle-version="[2.2.0,3.0.0)", + org.eclipse.papyrus.infra.internationalization.common;bundle-version="[1.0.0,2.0.0)", + org.eclipse.jface;bundle-version="[3.12.0,4.0.0)", + org.eclipse.papyrus.infra.emf.gmf;bundle-version="[1.2.0,2.0.0)", + org.eclipse.help;bundle-version="[3.8.0,4.0.0)", + org.eclipse.papyrus.infra.doc;bundle-version="[1.2.0,2.0.0)" +Bundle-ActivationPolicy: lazy +Bundle-Activator: org.eclipse.papyrus.infra.internationalization.Activator diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/about.html b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/about.html new file mode 100644 index 00000000000..598b3684879 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>May 12, 2008</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/build.properties b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/build.properties new file mode 100644 index 00000000000..cc3850cb555 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/build.properties @@ -0,0 +1,13 @@ +# + +bin.includes = .,\ + model/,\ + META-INF/,\ + about.html,\ + plugin.xml,\ + plugin.properties +jars.compile.order = . +source.. = src-gen/,\ + src/ +output.. = bin/ +src.includes = about.html diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/model/Internationalization.ecore b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/model/Internationalization.ecore new file mode 100644 index 00000000000..462ae055ec6 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/model/Internationalization.ecore @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="internationalization" nsURI="http://www.eclipse.org/papyrus/internationalization/model" + nsPrefix="internationalization"> + <eClassifiers xsi:type="ecore:EClass" name="InternationalizationLibrary"> + <eStructuralFeatures xsi:type="ecore:EReference" name="entries" upperBound="-1" + eType="#//InternationalizationEntry"/> + </eClassifiers> + <eClassifiers xsi:type="ecore:EClass" name="InternationalizationEntry"> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="key" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EJavaObject"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> + </eClassifiers> +</ecore:EPackage> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/model/Internationalization.genmodel b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/model/Internationalization.genmodel new file mode 100644 index 00000000000..dfe7a13c995 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/model/Internationalization.genmodel @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<genmodel:GenModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" + xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" copyrightText="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" + modelDirectory="/org.eclipse.papyrus.infra.internationalization/src-gen" editDirectory="/org.eclipse.papyrus.infra.internationalization.edit/src-gen" + modelPluginID="org.eclipse.papyrus.infra.internationalization" modelName="Internationalization" + nonNLSMarkers="true" rootExtendsClass="org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container" + codeFormatting="true" importerID="org.eclipse.emf.importer.ecore" complianceLevel="8.0" + copyrightFields="false" providerRootExtendsClass="" operationReflection="true" + importOrganizing="true" cleanup="true"> + <foreignModel>Internationalization.ecore</foreignModel> + <genPackages prefix="Internationalization" basePackage="org.eclipse.papyrus.infra" + disposableProviderFactory="true" ecorePackage="Internationalization.ecore#/"> + <genClasses ecoreClass="Internationalization.ecore#//InternationalizationLibrary"> + <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference Internationalization.ecore#//InternationalizationLibrary/entries"/> + </genClasses> + <genClasses ecoreClass="Internationalization.ecore#//InternationalizationEntry"> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute Internationalization.ecore#//InternationalizationEntry/key"/> + <genFeatures createChild="false" ecoreFeature="ecore:EAttribute Internationalization.ecore#//InternationalizationEntry/value"/> + </genClasses> + </genPackages> +</genmodel:GenModel> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/plugin.properties b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/plugin.properties new file mode 100644 index 00000000000..bb233bea040 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/plugin.properties @@ -0,0 +1,4 @@ +# + +pluginName = Papyrus Internationalization +providerName = Eclipse Modeling Project diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/plugin.xml b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/plugin.xml new file mode 100644 index 00000000000..189b4a897ee --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/plugin.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> + +<!-- +--> + +<plugin> + + <extension point="org.eclipse.emf.ecore.generated_package"> + <!-- @generated Internationalization --> + <package + uri="http://www.eclipse.org/papyrus/internationalization/model" + class="org.eclipse.papyrus.infra.internationalization.InternationalizationPackage" + genModel="model/Internationalization.genmodel"/> + </extension> + <extension + point="org.eclipse.papyrus.infra.core.model"> + <model + classname="org.eclipse.papyrus.infra.internationalization.modelresource.InternationalizationPreferenceModel" + description="Model for internationalization preference" + fileExtension="internationalization"> + </model> + </extension> + <extension + point="org.eclipse.help.toc"> + <toc + file="target/site/generated-eclipse-help/internationalizationDev-toc.xml" + primary="false"> + </toc> + </extension> + +</plugin> diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/pom.xml b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/pom.xml new file mode 100644 index 00000000000..19dc71f2eef --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/pom.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>org.eclipse.papyrus.infra-internationalization</artifactId> + <groupId>org.eclipse.papyrus</groupId> + <version>0.0.1-SNAPSHOT</version> + </parent> + <artifactId>org.eclipse.papyrus.infra.internationalization</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>eclipse-plugin</packaging> + + <build> + <plugins> + <plugin> + <groupId>org.eclipse.mylyn.docs</groupId> + <artifactId>org.eclipse.mylyn.wikitext.core.maven</artifactId> + <configuration> + <sourceFolder>src/site/mediawiki</sourceFolder> + <outputFolder>${project.build.directory}/site/generated-eclipse-help</outputFolder> + <!-- copyrightNotice>${help.copyrightNotice}</copyrightNotice> + <title>${help.documentTitle}</title--> + <multipleOutputFiles>false</multipleOutputFiles> + <navigationImages>true</navigationImages> + <formatOutput>true</formatOutput> + <htmlFilenameFormat>$1.html</htmlFilenameFormat> + <xmlFilenameFormat>$1-toc.xml</xmlFilenameFormat> + <helpPrefix>target/site/generated-eclipse-help</helpPrefix> + <!-- stylesheetUrls> + <param>styles/main.css</param> + </stylesheetUrls--> + </configuration> + <executions> + <execution> + <goals> + <goal>eclipse-help</goal> + </goals> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.eclipse.mylyn.docs</groupId> + <artifactId>org.eclipse.mylyn.wikitext.mediawiki.core</artifactId> + <version>${mylyn.wikitext.version}</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> +</project>
\ No newline at end of file diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/InternationalizationEntry.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/InternationalizationEntry.java new file mode 100644 index 00000000000..8c2faecd9c9 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/InternationalizationEntry.java @@ -0,0 +1,86 @@ +/** + * 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.infra.internationalization; + +import org.eclipse.emf.ecore.EObject; + +/** + * <!-- begin-user-doc --> + * A representation of the model object '<em><b>Entry</b></em>'. + * <!-- end-user-doc --> + * + * <p> + * The following features are supported: + * </p> + * <ul> + * <li>{@link org.eclipse.papyrus.infra.internationalization.InternationalizationEntry#getKey <em>Key</em>}</li> + * <li>{@link org.eclipse.papyrus.infra.internationalization.InternationalizationEntry#getValue <em>Value</em>}</li> + * </ul> + * + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationPackage#getInternationalizationEntry() + * @model + * @generated + */ +public interface InternationalizationEntry extends EObject { + /** + * Returns the value of the '<em><b>Key</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Key</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Key</em>' attribute. + * @see #setKey(Object) + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationPackage#getInternationalizationEntry_Key() + * @model required="true" + * @generated + */ + Object getKey(); + + /** + * Sets the value of the '{@link org.eclipse.papyrus.infra.internationalization.InternationalizationEntry#getKey <em>Key</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Key</em>' attribute. + * @see #getKey() + * @generated + */ + void setKey(Object value); + + /** + * Returns the value of the '<em><b>Value</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Value</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Value</em>' attribute. + * @see #setValue(String) + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationPackage#getInternationalizationEntry_Value() + * @model required="true" + * @generated + */ + String getValue(); + + /** + * Sets the value of the '{@link org.eclipse.papyrus.infra.internationalization.InternationalizationEntry#getValue <em>Value</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Value</em>' attribute. + * @see #getValue() + * @generated + */ + void setValue(String value); + +} // InternationalizationEntry diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/InternationalizationFactory.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/InternationalizationFactory.java new file mode 100644 index 00000000000..4d5c13fac54 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/InternationalizationFactory.java @@ -0,0 +1,61 @@ +/** + * 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.infra.internationalization; + +import org.eclipse.emf.ecore.EFactory; + +/** + * <!-- begin-user-doc --> + * The <b>Factory</b> for the model. + * It provides a create method for each non-abstract class of the model. + * <!-- end-user-doc --> + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationPackage + * @generated + */ +public interface InternationalizationFactory extends EFactory { + /** + * The singleton instance of the factory. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + InternationalizationFactory eINSTANCE = org.eclipse.papyrus.infra.internationalization.impl.InternationalizationFactoryImpl + .init(); + + /** + * Returns a new object of class '<em>Library</em>'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return a new object of class '<em>Library</em>'. + * @generated + */ + InternationalizationLibrary createInternationalizationLibrary(); + + /** + * Returns a new object of class '<em>Entry</em>'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return a new object of class '<em>Entry</em>'. + * @generated + */ + InternationalizationEntry createInternationalizationEntry(); + + /** + * Returns the package supported by this factory. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the package supported by this factory. + * @generated + */ + InternationalizationPackage getInternationalizationPackage(); + +} //InternationalizationFactory diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/InternationalizationLibrary.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/InternationalizationLibrary.java new file mode 100644 index 00000000000..c591a85a255 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/InternationalizationLibrary.java @@ -0,0 +1,51 @@ +/** + * 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.infra.internationalization; + +import org.eclipse.emf.common.util.EList; + +import org.eclipse.emf.ecore.EObject; + +/** + * <!-- begin-user-doc --> + * A representation of the model object '<em><b>Library</b></em>'. + * <!-- end-user-doc --> + * + * <p> + * The following features are supported: + * </p> + * <ul> + * <li>{@link org.eclipse.papyrus.infra.internationalization.InternationalizationLibrary#getEntries <em>Entries</em>}</li> + * </ul> + * + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationPackage#getInternationalizationLibrary() + * @model + * @generated + */ +public interface InternationalizationLibrary extends EObject { + /** + * Returns the value of the '<em><b>Entries</b></em>' reference list. + * The list contents are of type {@link org.eclipse.papyrus.infra.internationalization.InternationalizationEntry}. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Entries</em>' reference list isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Entries</em>' reference list. + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationPackage#getInternationalizationLibrary_Entries() + * @model + * @generated + */ + EList<InternationalizationEntry> getEntries(); + +} // InternationalizationLibrary diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/InternationalizationPackage.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/InternationalizationPackage.java new file mode 100644 index 00000000000..8e3da3cc47b --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/InternationalizationPackage.java @@ -0,0 +1,274 @@ +/** + * 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.infra.internationalization; + +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; + +/** + * <!-- begin-user-doc --> + * The <b>Package</b> for the model. + * It contains accessors for the meta objects to represent + * <ul> + * <li>each class,</li> + * <li>each feature of each class,</li> + * <li>each operation of each class,</li> + * <li>each enum,</li> + * <li>and each data type</li> + * </ul> + * <!-- end-user-doc --> + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationFactory + * @model kind="package" + * @generated + */ +public interface InternationalizationPackage extends EPackage { + /** + * The package name. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + String eNAME = "internationalization"; //$NON-NLS-1$ + + /** + * The package namespace URI. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + String eNS_URI = "http://www.eclipse.org/papyrus/internationalization/model"; //$NON-NLS-1$ + + /** + * The package namespace name. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + String eNS_PREFIX = "internationalization"; //$NON-NLS-1$ + + /** + * The singleton instance of the package. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + InternationalizationPackage eINSTANCE = org.eclipse.papyrus.infra.internationalization.impl.InternationalizationPackageImpl + .init(); + + /** + * The meta object id for the '{@link org.eclipse.papyrus.infra.internationalization.impl.InternationalizationLibraryImpl <em>Library</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.papyrus.infra.internationalization.impl.InternationalizationLibraryImpl + * @see org.eclipse.papyrus.infra.internationalization.impl.InternationalizationPackageImpl#getInternationalizationLibrary() + * @generated + */ + int INTERNATIONALIZATION_LIBRARY = 0; + + /** + * The feature id for the '<em><b>Entries</b></em>' reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + int INTERNATIONALIZATION_LIBRARY__ENTRIES = 0; + + /** + * The number of structural features of the '<em>Library</em>' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + int INTERNATIONALIZATION_LIBRARY_FEATURE_COUNT = 1; + + /** + * The number of operations of the '<em>Library</em>' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + int INTERNATIONALIZATION_LIBRARY_OPERATION_COUNT = 0; + + /** + * The meta object id for the '{@link org.eclipse.papyrus.infra.internationalization.impl.InternationalizationEntryImpl <em>Entry</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.papyrus.infra.internationalization.impl.InternationalizationEntryImpl + * @see org.eclipse.papyrus.infra.internationalization.impl.InternationalizationPackageImpl#getInternationalizationEntry() + * @generated + */ + int INTERNATIONALIZATION_ENTRY = 1; + + /** + * The feature id for the '<em><b>Key</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + int INTERNATIONALIZATION_ENTRY__KEY = 0; + + /** + * The feature id for the '<em><b>Value</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + int INTERNATIONALIZATION_ENTRY__VALUE = 1; + + /** + * The number of structural features of the '<em>Entry</em>' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + int INTERNATIONALIZATION_ENTRY_FEATURE_COUNT = 2; + + /** + * The number of operations of the '<em>Entry</em>' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + int INTERNATIONALIZATION_ENTRY_OPERATION_COUNT = 0; + + /** + * Returns the meta object for class '{@link org.eclipse.papyrus.infra.internationalization.InternationalizationLibrary <em>Library</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for class '<em>Library</em>'. + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationLibrary + * @generated + */ + EClass getInternationalizationLibrary(); + + /** + * Returns the meta object for the reference list '{@link org.eclipse.papyrus.infra.internationalization.InternationalizationLibrary#getEntries <em>Entries</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the reference list '<em>Entries</em>'. + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationLibrary#getEntries() + * @see #getInternationalizationLibrary() + * @generated + */ + EReference getInternationalizationLibrary_Entries(); + + /** + * Returns the meta object for class '{@link org.eclipse.papyrus.infra.internationalization.InternationalizationEntry <em>Entry</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for class '<em>Entry</em>'. + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationEntry + * @generated + */ + EClass getInternationalizationEntry(); + + /** + * Returns the meta object for the attribute '{@link org.eclipse.papyrus.infra.internationalization.InternationalizationEntry#getKey <em>Key</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the attribute '<em>Key</em>'. + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationEntry#getKey() + * @see #getInternationalizationEntry() + * @generated + */ + EAttribute getInternationalizationEntry_Key(); + + /** + * Returns the meta object for the attribute '{@link org.eclipse.papyrus.infra.internationalization.InternationalizationEntry#getValue <em>Value</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the attribute '<em>Value</em>'. + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationEntry#getValue() + * @see #getInternationalizationEntry() + * @generated + */ + EAttribute getInternationalizationEntry_Value(); + + /** + * Returns the factory that creates the instances of the model. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the factory that creates the instances of the model. + * @generated + */ + InternationalizationFactory getInternationalizationFactory(); + + /** + * <!-- begin-user-doc --> + * Defines literals for the meta objects that represent + * <ul> + * <li>each class,</li> + * <li>each feature of each class,</li> + * <li>each operation of each class,</li> + * <li>each enum,</li> + * <li>and each data type</li> + * </ul> + * <!-- end-user-doc --> + * @generated + */ + interface Literals { + /** + * The meta object literal for the '{@link org.eclipse.papyrus.infra.internationalization.impl.InternationalizationLibraryImpl <em>Library</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.papyrus.infra.internationalization.impl.InternationalizationLibraryImpl + * @see org.eclipse.papyrus.infra.internationalization.impl.InternationalizationPackageImpl#getInternationalizationLibrary() + * @generated + */ + EClass INTERNATIONALIZATION_LIBRARY = eINSTANCE.getInternationalizationLibrary(); + + /** + * The meta object literal for the '<em><b>Entries</b></em>' reference list feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EReference INTERNATIONALIZATION_LIBRARY__ENTRIES = eINSTANCE.getInternationalizationLibrary_Entries(); + + /** + * The meta object literal for the '{@link org.eclipse.papyrus.infra.internationalization.impl.InternationalizationEntryImpl <em>Entry</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.papyrus.infra.internationalization.impl.InternationalizationEntryImpl + * @see org.eclipse.papyrus.infra.internationalization.impl.InternationalizationPackageImpl#getInternationalizationEntry() + * @generated + */ + EClass INTERNATIONALIZATION_ENTRY = eINSTANCE.getInternationalizationEntry(); + + /** + * The meta object literal for the '<em><b>Key</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EAttribute INTERNATIONALIZATION_ENTRY__KEY = eINSTANCE.getInternationalizationEntry_Key(); + + /** + * The meta object literal for the '<em><b>Value</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EAttribute INTERNATIONALIZATION_ENTRY__VALUE = eINSTANCE.getInternationalizationEntry_Value(); + + } + +} //InternationalizationPackage diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/impl/InternationalizationEntryImpl.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/impl/InternationalizationEntryImpl.java new file mode 100644 index 00000000000..f71b6742ccb --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/impl/InternationalizationEntryImpl.java @@ -0,0 +1,236 @@ +/** + * 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.infra.internationalization.impl; + +import org.eclipse.emf.common.notify.Notification; + +import org.eclipse.emf.ecore.EClass; + +import org.eclipse.emf.ecore.impl.ENotificationImpl; +import org.eclipse.emf.ecore.impl.MinimalEObjectImpl; + +import org.eclipse.papyrus.infra.internationalization.InternationalizationEntry; +import org.eclipse.papyrus.infra.internationalization.InternationalizationPackage; + +/** + * <!-- begin-user-doc --> + * An implementation of the model object '<em><b>Entry</b></em>'. + * <!-- end-user-doc --> + * <p> + * The following features are implemented: + * </p> + * <ul> + * <li>{@link org.eclipse.papyrus.infra.internationalization.impl.InternationalizationEntryImpl#getKey <em>Key</em>}</li> + * <li>{@link org.eclipse.papyrus.infra.internationalization.impl.InternationalizationEntryImpl#getValue <em>Value</em>}</li> + * </ul> + * + * @generated + */ +public class InternationalizationEntryImpl extends MinimalEObjectImpl.Container implements InternationalizationEntry { + /** + * The default value of the '{@link #getKey() <em>Key</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getKey() + * @generated + * @ordered + */ + protected static final Object KEY_EDEFAULT = null; + + /** + * The cached value of the '{@link #getKey() <em>Key</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getKey() + * @generated + * @ordered + */ + protected Object key = KEY_EDEFAULT; + + /** + * The default value of the '{@link #getValue() <em>Value</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getValue() + * @generated + * @ordered + */ + protected static final String VALUE_EDEFAULT = null; + + /** + * The cached value of the '{@link #getValue() <em>Value</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getValue() + * @generated + * @ordered + */ + protected String value = VALUE_EDEFAULT; + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected InternationalizationEntryImpl() { + super(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + protected EClass eStaticClass() { + return InternationalizationPackage.Literals.INTERNATIONALIZATION_ENTRY; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public Object getKey() { + return key; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void setKey(Object newKey) { + Object oldKey = key; + key = newKey; + if (eNotificationRequired()) { + eNotify(new ENotificationImpl(this, Notification.SET, + InternationalizationPackage.INTERNATIONALIZATION_ENTRY__KEY, oldKey, key)); + } + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public String getValue() { + return value; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void setValue(String newValue) { + String oldValue = value; + value = newValue; +// if (eNotificationRequired()) { + eNotify(new ENotificationImpl(this, Notification.SET, + InternationalizationPackage.INTERNATIONALIZATION_ENTRY__VALUE, oldValue, value)); +// } + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public Object eGet(int featureID, boolean resolve, boolean coreType) { + switch (featureID) { + case InternationalizationPackage.INTERNATIONALIZATION_ENTRY__KEY: + return getKey(); + case InternationalizationPackage.INTERNATIONALIZATION_ENTRY__VALUE: + return getValue(); + } + return super.eGet(featureID, resolve, coreType); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void eSet(int featureID, Object newValue) { + switch (featureID) { + case InternationalizationPackage.INTERNATIONALIZATION_ENTRY__KEY: + setKey(newValue); + return; + case InternationalizationPackage.INTERNATIONALIZATION_ENTRY__VALUE: + setValue((String) newValue); + return; + } + super.eSet(featureID, newValue); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void eUnset(int featureID) { + switch (featureID) { + case InternationalizationPackage.INTERNATIONALIZATION_ENTRY__KEY: + setKey(KEY_EDEFAULT); + return; + case InternationalizationPackage.INTERNATIONALIZATION_ENTRY__VALUE: + setValue(VALUE_EDEFAULT); + return; + } + super.eUnset(featureID); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public boolean eIsSet(int featureID) { + switch (featureID) { + case InternationalizationPackage.INTERNATIONALIZATION_ENTRY__KEY: + return KEY_EDEFAULT == null ? key != null : !KEY_EDEFAULT.equals(key); + case InternationalizationPackage.INTERNATIONALIZATION_ENTRY__VALUE: + return VALUE_EDEFAULT == null ? value != null : !VALUE_EDEFAULT.equals(value); + } + return super.eIsSet(featureID); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public String toString() { + if (eIsProxy()) { + return super.toString(); + } + + StringBuffer result = new StringBuffer(super.toString()); + result.append(" (key: "); //$NON-NLS-1$ + result.append(key); + result.append(", value: "); //$NON-NLS-1$ + result.append(value); + result.append(')'); + return result.toString(); + } + +} //InternationalizationEntryImpl diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/impl/InternationalizationFactoryImpl.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/impl/InternationalizationFactoryImpl.java new file mode 100644 index 00000000000..e9b99631670 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/impl/InternationalizationFactoryImpl.java @@ -0,0 +1,120 @@ +/** + * 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.infra.internationalization.impl; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; + +import org.eclipse.emf.ecore.impl.EFactoryImpl; + +import org.eclipse.emf.ecore.plugin.EcorePlugin; + +import org.eclipse.papyrus.infra.internationalization.*; + +/** + * <!-- begin-user-doc --> + * An implementation of the model <b>Factory</b>. + * <!-- end-user-doc --> + * @generated + */ +public class InternationalizationFactoryImpl extends EFactoryImpl implements InternationalizationFactory { + /** + * Creates the default factory implementation. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static InternationalizationFactory init() { + try { + InternationalizationFactory theInternationalizationFactory = (InternationalizationFactory) EPackage.Registry.INSTANCE + .getEFactory(InternationalizationPackage.eNS_URI); + if (theInternationalizationFactory != null) { + return theInternationalizationFactory; + } + } catch (Exception exception) { + EcorePlugin.INSTANCE.log(exception); + } + return new InternationalizationFactoryImpl(); + } + + /** + * Creates an instance of the factory. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public InternationalizationFactoryImpl() { + super(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public EObject create(EClass eClass) { + switch (eClass.getClassifierID()) { + case InternationalizationPackage.INTERNATIONALIZATION_LIBRARY: + return createInternationalizationLibrary(); + case InternationalizationPackage.INTERNATIONALIZATION_ENTRY: + return createInternationalizationEntry(); + default: + throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier"); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public InternationalizationLibrary createInternationalizationLibrary() { + InternationalizationLibraryImpl internationalizationLibrary = new InternationalizationLibraryImpl(); + return internationalizationLibrary; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public InternationalizationEntry createInternationalizationEntry() { + InternationalizationEntryImpl internationalizationEntry = new InternationalizationEntryImpl(); + return internationalizationEntry; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public InternationalizationPackage getInternationalizationPackage() { + return (InternationalizationPackage) getEPackage(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @deprecated + * @generated + */ + @Deprecated + public static InternationalizationPackage getPackage() { + return InternationalizationPackage.eINSTANCE; + } + +} //InternationalizationFactoryImpl diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/impl/InternationalizationLibraryImpl.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/impl/InternationalizationLibraryImpl.java new file mode 100644 index 00000000000..d8bc0cd67a4 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/impl/InternationalizationLibraryImpl.java @@ -0,0 +1,146 @@ +/** + * 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.infra.internationalization.impl; + +import java.util.Collection; + +import org.eclipse.emf.common.util.EList; + +import org.eclipse.emf.ecore.EClass; + +import org.eclipse.emf.ecore.impl.MinimalEObjectImpl; + +import org.eclipse.emf.ecore.util.EObjectResolvingEList; + +import org.eclipse.papyrus.infra.internationalization.InternationalizationEntry; +import org.eclipse.papyrus.infra.internationalization.InternationalizationLibrary; +import org.eclipse.papyrus.infra.internationalization.InternationalizationPackage; + +/** + * <!-- begin-user-doc --> + * An implementation of the model object '<em><b>Library</b></em>'. + * <!-- end-user-doc --> + * <p> + * The following features are implemented: + * </p> + * <ul> + * <li>{@link org.eclipse.papyrus.infra.internationalization.impl.InternationalizationLibraryImpl#getEntries <em>Entries</em>}</li> + * </ul> + * + * @generated + */ +public class InternationalizationLibraryImpl extends MinimalEObjectImpl.Container + implements InternationalizationLibrary { + /** + * The cached value of the '{@link #getEntries() <em>Entries</em>}' reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getEntries() + * @generated + * @ordered + */ + protected EList<InternationalizationEntry> entries; + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected InternationalizationLibraryImpl() { + super(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + protected EClass eStaticClass() { + return InternationalizationPackage.Literals.INTERNATIONALIZATION_LIBRARY; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public EList<InternationalizationEntry> getEntries() { + if (entries == null) { + entries = new EObjectResolvingEList<>(InternationalizationEntry.class, this, + InternationalizationPackage.INTERNATIONALIZATION_LIBRARY__ENTRIES); + } + return entries; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public Object eGet(int featureID, boolean resolve, boolean coreType) { + switch (featureID) { + case InternationalizationPackage.INTERNATIONALIZATION_LIBRARY__ENTRIES: + return getEntries(); + } + return super.eGet(featureID, resolve, coreType); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @SuppressWarnings("unchecked") + @Override + public void eSet(int featureID, Object newValue) { + switch (featureID) { + case InternationalizationPackage.INTERNATIONALIZATION_LIBRARY__ENTRIES: + getEntries().clear(); + getEntries().addAll((Collection<? extends InternationalizationEntry>) newValue); + return; + } + super.eSet(featureID, newValue); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void eUnset(int featureID) { + switch (featureID) { + case InternationalizationPackage.INTERNATIONALIZATION_LIBRARY__ENTRIES: + getEntries().clear(); + return; + } + super.eUnset(featureID); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public boolean eIsSet(int featureID) { + switch (featureID) { + case InternationalizationPackage.INTERNATIONALIZATION_LIBRARY__ENTRIES: + return entries != null && !entries.isEmpty(); + } + return super.eIsSet(featureID); + } + +} //InternationalizationLibraryImpl diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/impl/InternationalizationPackageImpl.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/impl/InternationalizationPackageImpl.java new file mode 100644 index 00000000000..197e2e23368 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/impl/InternationalizationPackageImpl.java @@ -0,0 +1,252 @@ +/** + * Copyright (c) 2016 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Initial API and implementation + */ +package org.eclipse.papyrus.infra.internationalization.impl; + +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; + +import org.eclipse.emf.ecore.impl.EPackageImpl; + +import org.eclipse.papyrus.infra.internationalization.InternationalizationEntry; +import org.eclipse.papyrus.infra.internationalization.InternationalizationFactory; +import org.eclipse.papyrus.infra.internationalization.InternationalizationLibrary; +import org.eclipse.papyrus.infra.internationalization.InternationalizationPackage; + +/** + * <!-- begin-user-doc --> + * An implementation of the model <b>Package</b>. + * <!-- end-user-doc --> + * @generated + */ +public class InternationalizationPackageImpl extends EPackageImpl implements InternationalizationPackage { + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private EClass internationalizationLibraryEClass = null; + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private EClass internationalizationEntryEClass = null; + + /** + * Creates an instance of the model <b>Package</b>, registered with + * {@link org.eclipse.emf.ecore.EPackage.Registry EPackage.Registry} by the package + * package URI value. + * <p>Note: the correct way to create the package is via the static + * factory method {@link #init init()}, which also performs + * initialization of the package, or returns the registered package, + * if one already exists. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.emf.ecore.EPackage.Registry + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationPackage#eNS_URI + * @see #init() + * @generated + */ + private InternationalizationPackageImpl() { + super(eNS_URI, InternationalizationFactory.eINSTANCE); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private static boolean isInited = false; + + /** + * Creates, registers, and initializes the <b>Package</b> for this model, and for any others upon which it depends. + * + * <p>This method is used to initialize {@link InternationalizationPackage#eINSTANCE} when that field is accessed. + * Clients should not invoke it directly. Instead, they should simply access that field to obtain the package. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #eNS_URI + * @see #createPackageContents() + * @see #initializePackageContents() + * @generated + */ + public static InternationalizationPackage init() { + if (isInited) { + return (InternationalizationPackage) EPackage.Registry.INSTANCE + .getEPackage(InternationalizationPackage.eNS_URI); + } + + // Obtain or create and register package + InternationalizationPackageImpl theInternationalizationPackage = (InternationalizationPackageImpl) (EPackage.Registry.INSTANCE + .get(eNS_URI) instanceof InternationalizationPackageImpl ? EPackage.Registry.INSTANCE.get(eNS_URI) + : new InternationalizationPackageImpl()); + + isInited = true; + + // Create package meta-data objects + theInternationalizationPackage.createPackageContents(); + + // Initialize created meta-data + theInternationalizationPackage.initializePackageContents(); + + // Mark meta-data to indicate it can't be changed + theInternationalizationPackage.freeze(); + + // Update the registry and return the package + EPackage.Registry.INSTANCE.put(InternationalizationPackage.eNS_URI, theInternationalizationPackage); + return theInternationalizationPackage; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public EClass getInternationalizationLibrary() { + return internationalizationLibraryEClass; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public EReference getInternationalizationLibrary_Entries() { + return (EReference) internationalizationLibraryEClass.getEStructuralFeatures().get(0); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public EClass getInternationalizationEntry() { + return internationalizationEntryEClass; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public EAttribute getInternationalizationEntry_Key() { + return (EAttribute) internationalizationEntryEClass.getEStructuralFeatures().get(0); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public EAttribute getInternationalizationEntry_Value() { + return (EAttribute) internationalizationEntryEClass.getEStructuralFeatures().get(1); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public InternationalizationFactory getInternationalizationFactory() { + return (InternationalizationFactory) getEFactoryInstance(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private boolean isCreated = false; + + /** + * Creates the meta-model objects for the package. This method is + * guarded to have no affect on any invocation but its first. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void createPackageContents() { + if (isCreated) { + return; + } + isCreated = true; + + // Create classes and their features + internationalizationLibraryEClass = createEClass(INTERNATIONALIZATION_LIBRARY); + createEReference(internationalizationLibraryEClass, INTERNATIONALIZATION_LIBRARY__ENTRIES); + + internationalizationEntryEClass = createEClass(INTERNATIONALIZATION_ENTRY); + createEAttribute(internationalizationEntryEClass, INTERNATIONALIZATION_ENTRY__KEY); + createEAttribute(internationalizationEntryEClass, INTERNATIONALIZATION_ENTRY__VALUE); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private boolean isInitialized = false; + + /** + * Complete the initialization of the package and its meta-model. This + * method is guarded to have no affect on any invocation but its first. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void initializePackageContents() { + if (isInitialized) { + return; + } + isInitialized = true; + + // Initialize package + setName(eNAME); + setNsPrefix(eNS_PREFIX); + setNsURI(eNS_URI); + + // Create type parameters + + // Set bounds for type parameters + + // Add supertypes to classes + + // Initialize classes, features, and operations; add parameters + initEClass(internationalizationLibraryEClass, InternationalizationLibrary.class, "InternationalizationLibrary", //$NON-NLS-1$ + !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); + initEReference(getInternationalizationLibrary_Entries(), this.getInternationalizationEntry(), null, "entries", //$NON-NLS-1$ + null, 0, -1, InternationalizationLibrary.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, + !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + + initEClass(internationalizationEntryEClass, InternationalizationEntry.class, "InternationalizationEntry", //$NON-NLS-1$ + !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); + initEAttribute(getInternationalizationEntry_Key(), ecorePackage.getEJavaObject(), "key", null, 1, 1, //$NON-NLS-1$ + InternationalizationEntry.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, + IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getInternationalizationEntry_Value(), ecorePackage.getEString(), "value", null, 1, 1, //$NON-NLS-1$ + InternationalizationEntry.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, + IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + + // Create resource + createResource(eNS_URI); + } + +} //InternationalizationPackageImpl diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/util/InternationalizationAdapterFactory.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/util/InternationalizationAdapterFactory.java new file mode 100644 index 00000000000..9bb7a09f475 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/util/InternationalizationAdapterFactory.java @@ -0,0 +1,147 @@ +/** + * 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.infra.internationalization.util; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notifier; + +import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl; + +import org.eclipse.emf.ecore.EObject; + +import org.eclipse.papyrus.infra.internationalization.*; + +/** + * <!-- begin-user-doc --> + * The <b>Adapter Factory</b> for the model. + * It provides an adapter <code>createXXX</code> method for each class of the model. + * <!-- end-user-doc --> + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationPackage + * @generated + */ +public class InternationalizationAdapterFactory extends AdapterFactoryImpl { + /** + * The cached model package. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected static InternationalizationPackage modelPackage; + + /** + * Creates an instance of the adapter factory. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public InternationalizationAdapterFactory() { + if (modelPackage == null) { + modelPackage = InternationalizationPackage.eINSTANCE; + } + } + + /** + * Returns whether this factory is applicable for the type of the object. + * <!-- begin-user-doc --> + * This implementation returns <code>true</code> if the object is either the model's package or is an instance object of the model. + * <!-- end-user-doc --> + * @return whether this factory is applicable for the type of the object. + * @generated + */ + @Override + public boolean isFactoryForType(Object object) { + if (object == modelPackage) { + return true; + } + if (object instanceof EObject) { + return ((EObject) object).eClass().getEPackage() == modelPackage; + } + return false; + } + + /** + * The switch that delegates to the <code>createXXX</code> methods. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected InternationalizationSwitch<Adapter> modelSwitch = new InternationalizationSwitch<Adapter>() { + @Override + public Adapter caseInternationalizationLibrary(InternationalizationLibrary object) { + return createInternationalizationLibraryAdapter(); + } + + @Override + public Adapter caseInternationalizationEntry(InternationalizationEntry object) { + return createInternationalizationEntryAdapter(); + } + + @Override + public Adapter defaultCase(EObject object) { + return createEObjectAdapter(); + } + }; + + /** + * Creates an adapter for the <code>target</code>. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param target the object to adapt. + * @return the adapter for the <code>target</code>. + * @generated + */ + @Override + public Adapter createAdapter(Notifier target) { + return modelSwitch.doSwitch((EObject) target); + } + + /** + * Creates a new adapter for an object of class '{@link org.eclipse.papyrus.infra.internationalization.InternationalizationLibrary <em>Library</em>}'. + * <!-- begin-user-doc --> + * This default implementation returns null so that we can easily ignore cases; + * it's useful to ignore a case when inheritance will catch all the cases anyway. + * <!-- end-user-doc --> + * @return the new adapter. + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationLibrary + * @generated + */ + public Adapter createInternationalizationLibraryAdapter() { + return null; + } + + /** + * Creates a new adapter for an object of class '{@link org.eclipse.papyrus.infra.internationalization.InternationalizationEntry <em>Entry</em>}'. + * <!-- begin-user-doc --> + * This default implementation returns null so that we can easily ignore cases; + * it's useful to ignore a case when inheritance will catch all the cases anyway. + * <!-- end-user-doc --> + * @return the new adapter. + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationEntry + * @generated + */ + public Adapter createInternationalizationEntryAdapter() { + return null; + } + + /** + * Creates a new adapter for the default case. + * <!-- begin-user-doc --> + * This default implementation returns null. + * <!-- end-user-doc --> + * @return the new adapter. + * @generated + */ + public Adapter createEObjectAdapter() { + return null; + } + +} //InternationalizationAdapterFactory diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/util/InternationalizationSwitch.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/util/InternationalizationSwitch.java new file mode 100644 index 00000000000..8b059e257c4 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src-gen/org/eclipse/papyrus/infra/internationalization/util/InternationalizationSwitch.java @@ -0,0 +1,145 @@ +/** + * 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.infra.internationalization.util; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; + +import org.eclipse.emf.ecore.util.Switch; + +import org.eclipse.papyrus.infra.internationalization.*; + +/** + * <!-- begin-user-doc --> + * The <b>Switch</b> for the model's inheritance hierarchy. + * It supports the call {@link #doSwitch(EObject) doSwitch(object)} + * to invoke the <code>caseXXX</code> method for each class of the model, + * starting with the actual class of the object + * and proceeding up the inheritance hierarchy + * until a non-null result is returned, + * which is the result of the switch. + * <!-- end-user-doc --> + * @see org.eclipse.papyrus.infra.internationalization.InternationalizationPackage + * @generated + */ +public class InternationalizationSwitch<T> extends Switch<T> { + /** + * The cached model package + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected static InternationalizationPackage modelPackage; + + /** + * Creates an instance of the switch. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public InternationalizationSwitch() { + if (modelPackage == null) { + modelPackage = InternationalizationPackage.eINSTANCE; + } + } + + /** + * Checks whether this is a switch for the given package. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param ePackage the package in question. + * @return whether this is a switch for the given package. + * @generated + */ + @Override + protected boolean isSwitchFor(EPackage ePackage) { + return ePackage == modelPackage; + } + + /** + * Calls <code>caseXXX</code> for each class of the model until one returns a non null result; it yields that result. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the first non-null result returned by a <code>caseXXX</code> call. + * @generated + */ + @Override + protected T doSwitch(int classifierID, EObject theEObject) { + switch (classifierID) { + case InternationalizationPackage.INTERNATIONALIZATION_LIBRARY: { + InternationalizationLibrary internationalizationLibrary = (InternationalizationLibrary) theEObject; + T result = caseInternationalizationLibrary(internationalizationLibrary); + if (result == null) { + result = defaultCase(theEObject); + } + return result; + } + case InternationalizationPackage.INTERNATIONALIZATION_ENTRY: { + InternationalizationEntry internationalizationEntry = (InternationalizationEntry) theEObject; + T result = caseInternationalizationEntry(internationalizationEntry); + if (result == null) { + result = defaultCase(theEObject); + } + return result; + } + default: + return defaultCase(theEObject); + } + } + + /** + * Returns the result of interpreting the object as an instance of '<em>Library</em>'. + * <!-- begin-user-doc --> + * This implementation returns null; + * returning a non-null result will terminate the switch. + * <!-- end-user-doc --> + * @param object the target of the switch. + * @return the result of interpreting the object as an instance of '<em>Library</em>'. + * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) + * @generated + */ + public T caseInternationalizationLibrary(InternationalizationLibrary object) { + return null; + } + + /** + * Returns the result of interpreting the object as an instance of '<em>Entry</em>'. + * <!-- begin-user-doc --> + * This implementation returns null; + * returning a non-null result will terminate the switch. + * <!-- end-user-doc --> + * @param object the target of the switch. + * @return the result of interpreting the object as an instance of '<em>Entry</em>'. + * @see #doSwitch(org.eclipse.emf.ecore.EObject) doSwitch(EObject) + * @generated + */ + public T caseInternationalizationEntry(InternationalizationEntry object) { + return null; + } + + /** + * Returns the result of interpreting the object as an instance of '<em>EObject</em>'. + * <!-- begin-user-doc --> + * This implementation returns null; + * returning a non-null result will terminate the switch, but this is the last case anyway. + * <!-- end-user-doc --> + * @param object the target of the switch. + * @return the result of interpreting the object as an instance of '<em>EObject</em>'. + * @see #doSwitch(org.eclipse.emf.ecore.EObject) + * @generated + */ + @Override + public T defaultCase(EObject object) { + return null; + } + +} //InternationalizationSwitch diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/Activator.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/Activator.java new file mode 100644 index 00000000000..05322b0895b --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/Activator.java @@ -0,0 +1,77 @@ +/***************************************************************************** + * 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.infra.internationalization; + +import org.eclipse.papyrus.infra.core.log.LogHelper; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle. + */ +public class Activator extends AbstractUIPlugin { + + /** + * The plug-in ID. + */ + public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.internationalization"; //$NON-NLS-1$ + + /** + * The shared instance. + */ + private static Activator plugin; + + /** + * The log helper. + */ + public static LogHelper log; + + /** + * The constructor + */ + public Activator() { + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(final BundleContext context) throws Exception { + super.start(context); + plugin = this; + log = new LogHelper(this); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(final BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/commands/InternationalizationPreferenceCommandFactory.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/commands/InternationalizationPreferenceCommandFactory.java new file mode 100644 index 00000000000..5e7dd422b96 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/commands/InternationalizationPreferenceCommandFactory.java @@ -0,0 +1,211 @@ +/***************************************************************************** + * 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.infra.internationalization.commands; + +import java.util.Collection; + +import org.eclipse.emf.common.command.AbstractCommand; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.UnexecutableCommand; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationAnnotationResourceUtils; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesConstants; +import org.eclipse.papyrus.infra.internationalization.modelresource.InternationalizationPreferenceModel; +import org.eclipse.papyrus.infra.internationalization.utils.InternationalizationPreferenceModelUtils; + +/** + * The internationalization preference command factory that allows to manage the + * legacy of the storage. + */ +public class InternationalizationPreferenceCommandFactory { + + /** + * The model set. + */ + private final ModelSet modelSet; + + /** + * Constructor. + * + * @param modelSet + * The model set. + */ + public InternationalizationPreferenceCommandFactory(final ModelSet modelSet) { + super(); + + this.modelSet = modelSet; + } + + /** + * Creates a command that toggles whether the sash model is stored in the + * private workspace metadata area or in the shared {@code *.di} file. + * + * @return a toggle command for the private layout storage + */ + public Command createTogglePrivateStorageCommand() { + Command result = UnexecutableCommand.INSTANCE; + + final InternationalizationPreferenceModel internationalizationPrefModel = InternationalizationPreferenceModelUtils + .getInternationalizationPreferenceModel(modelSet); + if (null != internationalizationPrefModel) { + result = new AbstractToggleCommand("Toggle Private Editor Layout") { //$NON-NLS-1$ + + @Override + public void execute() { + + final EAnnotation annotationToMove = InternationalizationAnnotationResourceUtils + .getInternationalizationAnnotation(internationalizationPrefModel.getResource()); + + // We don't record changes in the internationalization + // preference model for undo/redo, + // so we cannot assume that any changes to the current page + // selections are undoable in the usual way + if (!internationalizationPrefModel.isLegacyMode()) { + final Resource internationalizationPrefResource = annotationToMove.eResource(); + final URI sharedURI = internationalizationPrefModel.getPrivateResourceURI(); + + // Move the contents into the notation model. If the + // notation resource isn't loaded, give up because + // something is seriously wrong in that case + final Resource notationResource = modelSet.getResource(sharedURI, false); + if (null != notationResource && notationResource.isLoaded()) { + moveContents(internationalizationPrefResource, notationResource, annotationToMove); + + if (internationalizationPrefResource.getContents().isEmpty()) { + // Schedule deletion on save + modelSet.getResourcesToDeleteOnSave().add(internationalizationPrefResource.getURI()); + } + } + } else { + Resource internationalizationPrefResource; + final URI privateURI = internationalizationPrefModel.getSharedResourceURI(); + + // Move the contents into the internationalization + // preference model. If the internationalization + // preference resource isn't loaded or doesn't exist, it + // will have to be handled + if (modelSet.getURIConverter().exists(privateURI, null)) { + internationalizationPrefResource = modelSet.getResource(privateURI, true); + } else { + internationalizationPrefResource = modelSet.createResource(privateURI); + } + + // In case we had marked it for deletion, earlier + modelSet.getResourcesToDeleteOnSave().remove(privateURI); + + final Resource notationResource = annotationToMove.eResource(); + moveContents(notationResource, internationalizationPrefResource, annotationToMove); + } + + // Re-load from the new resource. Snippets might find this + // odd, but it would be even more odd for there to be any + // snippets on this model + internationalizationPrefModel.loadModel(modelSet.getURIWithoutExtension()); + } + }; + } + + return result; + } + + /** + * Move the annotation from the first resource into the second one. + * + * @param fromResource + * The resource containing the annotation to move into the second + * resource. + * @param toResource + * The resource where move the annotation. + * @param annotation + * The annotation to move from first resource into the second + * one. + */ + protected void moveContents(final Resource fromResource, final Resource toResource, final EAnnotation annotation) { + EObject toReplace = null; + + final Collection<EObject> existingAnnotations = EcoreUtil.getObjectsByType(toResource.getContents(), + annotation.eClass()); + if (null != existingAnnotations && existingAnnotations.isEmpty()) { + for (final EObject existingAnnotation : existingAnnotations) { + if (existingAnnotation instanceof EAnnotation && ((EAnnotation) existingAnnotation).getSource() + .equals(InternationalizationPreferencesConstants.INTERNATIONALIZATION_ANNOTATION_LABEL)) { + toReplace = existingAnnotation; + } + } + } + + if (null != toReplace) { + EcoreUtil.replace(toReplace, annotation); + } else { + toResource.getContents().add(annotation); + } + } + + /** + * The command for the toggle action. We don't need recording command here + * because this is managed by properties API that will be wrapped as + * recording command. + */ + private static abstract class AbstractToggleCommand extends AbstractCommand { + + /** + * Constructor. + * + * @param label + * The label of the command. + */ + public AbstractToggleCommand(final String label) { + super(label); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.AbstractCommand#prepare() + */ + @Override + protected boolean prepare() { + // Nothing to prepare + return true; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.AbstractCommand#undo() + */ + @Override + public void undo() { + // The command modified a boolean value so the undo will do the + // contrary of the previous command + execute(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.Command#redo() + */ + @Override + public void redo() { + execute(); + } + } + +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/commands/ResetNameCommand.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/commands/ResetNameCommand.java new file mode 100644 index 00000000000..246f8de4201 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/commands/ResetNameCommand.java @@ -0,0 +1,108 @@ +/***************************************************************************** + * 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.infra.internationalization.commands; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.edit.EMFEditPlugin; +import org.eclipse.emf.edit.command.AbstractOverrideableCommand; +import org.eclipse.emf.edit.domain.EditingDomain; + +/** + * This allows to define a command to reset the feature value needed. + */ +public class ResetNameCommand extends AbstractOverrideableCommand { + + /** + * The owner to modify. + */ + private EObject owner; + + /** + * The feature tu reset. + */ + private EStructuralFeature feature; + + /** + * This caches the label. + */ + protected static final String LABEL = EMFEditPlugin.INSTANCE.getString("_UI_SetCommand_label"); + + /** + * This caches the description. + */ + protected static final String DESCRIPTION = EMFEditPlugin.INSTANCE.getString("_UI_SetCommand_description"); + + /** + * Constructor. + * + * @param domain + * The current editing domain. + * @param owner + * The owner to modify. + * @param feature + * The feature to reset. + */ + public ResetNameCommand(final EditingDomain domain, final EObject owner, final EStructuralFeature feature) { + super(domain, LABEL, DESCRIPTION); + + this.owner = owner; + this.feature = feature; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.common.command.AbstractCommand#prepare() + */ + @Override + protected boolean prepare() { + return null != this.owner.eClass().getEStructuralFeature(feature.getFeatureID()) + && null != this.owner.eGet(this.feature); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.edit.command.AbstractOverrideableCommand#doExecute() + */ + @Override + public void doExecute() { + final Object oldValue = this.owner.eGet(this.feature); + this.owner.eSet(feature, null); + this.owner.eSet(feature, oldValue); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.edit.command.AbstractOverrideableCommand#doUndo() + */ + @Override + public void doUndo() { + final Object oldValue = this.owner.eGet(this.feature); + this.owner.eSet(feature, null); + this.owner.eSet(feature, oldValue); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.edit.command.AbstractOverrideableCommand#doRedo() + */ + @Override + public void doRedo() { + doExecute(); + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/commands/ResetNameTransactionalCommand.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/commands/ResetNameTransactionalCommand.java new file mode 100644 index 00000000000..c473974144e --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/commands/ResetNameTransactionalCommand.java @@ -0,0 +1,89 @@ +/***************************************************************************** + * 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.infra.internationalization.commands; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.edit.EMFEditPlugin; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; + +/** + * This allows to define a command to reset the feature value needed. + */ +public class ResetNameTransactionalCommand extends AbstractTransactionalCommand { + + /** + * The owner to modify. + */ + private EObject owner; + + /** + * The feature tu reset. + */ + private EStructuralFeature feature; + + /** + * This caches the label. + */ + protected static final String LABEL = EMFEditPlugin.INSTANCE.getString("_UI_SetCommand_label"); + + /** + * Constructor. + * + * @param domain + * The current editing domain. + * @param owner + * The owner to modify. + * @param feature + * The feature to reset. + */ + public ResetNameTransactionalCommand(final TransactionalEditingDomain domain, final EObject owner, + final EStructuralFeature feature) { + super(domain, LABEL, null); + + this.owner = owner; + this.feature = feature; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.core.commands.operations.AbstractOperation#canExecute() + */ + @Override + public boolean canExecute() { + return null != this.owner.eClass().getEStructuralFeature(feature.getFeatureID()) + && null != this.owner.eGet(this.feature); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, + * org.eclipse.core.runtime.IAdaptable) + */ + @Override + protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) + throws ExecutionException { + final Object oldValue = this.owner.eGet(this.feature); + this.owner.eSet(feature, null); + this.owner.eSet(feature, oldValue); + return CommandResult.newOKCommandResult(this.owner); + } +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/modelresource/AbstractInternationalizationPreferenceModelProvider.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/modelresource/AbstractInternationalizationPreferenceModelProvider.java new file mode 100644 index 00000000000..f733e324b07 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/modelresource/AbstractInternationalizationPreferenceModelProvider.java @@ -0,0 +1,78 @@ +/***************************************************************************** + * 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.infra.internationalization.modelresource; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.core.resource.sasheditor.ISashModelProvider; + +/** + * A partial implementation of the {@link ISashModelProvider} protocol. + */ +public abstract class AbstractInternationalizationPreferenceModelProvider + implements IInternationalizationPreferenceModelProvider { + + /** + * The model set managed. + */ + private ModelSet modelSet; + + /** + * Constructor. + */ + public AbstractInternationalizationPreferenceModelProvider() { + super(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.internationalization.modelresource.IInternationalizationPreferenceModelProvider#initialize(org.eclipse.papyrus.infra.core.resource.ModelSet) + */ + @Override + public void initialize(final ModelSet modelSet) { + this.modelSet = modelSet; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.internationalization.modelresource.IInternationalizationPreferenceModelProvider#dispose() + */ + @Override + public void dispose() { + modelSet = null; + } + + /** + * Get the model set. + * + * @return The model set. + */ + protected ModelSet getModelSet() { + return modelSet; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.internationalization.modelresource.IInternationalizationPreferenceModelProvider#loadInternationalizationPreferenceModel(org.eclipse.emf.common.util.URI) + */ + @Override + public Resource loadInternationalizationPreferenceModel(final URI internationalizationPrefModelURI) { + return modelSet.getResource(internationalizationPrefModelURI, true); + } + +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/modelresource/IInternationalizationPreferenceModelProvider.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/modelresource/IInternationalizationPreferenceModelProvider.java new file mode 100644 index 00000000000..7d70008b620 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/modelresource/IInternationalizationPreferenceModelProvider.java @@ -0,0 +1,56 @@ +/***************************************************************************** + * 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.infra.internationalization.modelresource; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.papyrus.infra.core.resource.ModelSet; + +/** + * This is the IInternationalizationPreferenceModelProvider type. + */ +public interface IInternationalizationPreferenceModelProvider { + + /** + * Get the internationalization preference model URI from the user model + * URI. + * + * @param userModelURI + * The initial user model URI. + * @return The internationalization preference model URI. + */ + public URI getInternationalizationPreferenceModelURI(final URI userModelURI); + + /** + * This allows to initialize the model provider. + * + * @param modelSet + * The current model set. + */ + public void initialize(final ModelSet modelSet); + + /** + * This allows to load the internationalization preference model. + * + * @param internationalizationPrefModelURI + * The internationalization preference model URI. + * @return The loaded resource. + */ + public Resource loadInternationalizationPreferenceModel(final URI internationalizationPrefModelURI); + + /** + * This allows to manage the dispose of the model provider. + */ + public void dispose(); +} diff --git a/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/modelresource/InternationalizationModelResource.java b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/modelresource/InternationalizationModelResource.java new file mode 100644 index 00000000000..1158f1e67f0 --- /dev/null +++ b/plugins/infra/internationalization/org.eclipse.papyrus.infra.internationalization/src/org/eclipse/papyrus/infra/internationalization/modelresource/InternationalizationModelResource.java @@ -0,0 +1,1494 @@ +/***************************************************************************** + * 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.infra.internationalization.modelresource; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.Set; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.emf.common.command.AbstractCommand; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.URIConverter; +import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.command.RemoveCommand; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource; +import org.eclipse.papyrus.infra.core.resource.IModel; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.emf.commands.AddToResourceCommand; +import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; +import org.eclipse.papyrus.infra.internationalization.Activator; +import org.eclipse.papyrus.infra.internationalization.InternationalizationEntry; +import org.eclipse.papyrus.infra.internationalization.InternationalizationFactory; +import org.eclipse.papyrus.infra.internationalization.InternationalizationLibrary; +import org.eclipse.papyrus.infra.internationalization.InternationalizationPackage; +import org.eclipse.papyrus.infra.internationalization.commands.ResetNameCommand; +import org.eclipse.papyrus.infra.internationalization.commands.ResetNameTransactionalCommand; +import org.eclipse.papyrus.infra.internationalization.common.editor.IInternationalizationEditor; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesConstants; +import org.eclipse.papyrus.infra.internationalization.common.utils.InternationalizationPreferencesUtils; +import org.eclipse.papyrus.infra.internationalization.common.utils.LocaleNameResolver; +import org.eclipse.papyrus.infra.internationalization.utils.EntryPartLabelSynchronizer; +import org.eclipse.papyrus.infra.internationalization.utils.PreferencePartLabelSynchronizer; +import org.eclipse.papyrus.infra.internationalization.utils.PropertiesFilesUtils; +import org.eclipse.papyrus.infra.internationalization.utils.QualifiedNameUtils; +import org.eclipse.papyrus.infra.internationalization.utils.ResourceBundleAndURI; +import org.eclipse.papyrus.infra.nattable.model.nattable.Table; +import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.NattableconfigurationPackage; + +/** + * This allows to manage the internationalization resource. + */ +public class InternationalizationModelResource extends AbstractModelWithSharedResource<InternationalizationLibrary> + implements IModel { + + /** + * Model ID. + */ + public static final String MODEL_ID = "org.eclipse.papyrus.infra.internationalization.resource.InternationalizationModel"; //$NON-NLS-1$ + + /** + * The '_labelDiagram_' prefix of each diagram entry. + */ + protected static final String LABEL_DIAGRAM_PREFIX_QN = "_labelDiagram_"; //$NON-NLS-1$ + + /** + * The '_labelTable_' prefix of each table entry. + */ + protected static final String LABEL_TABLE_PREFIX_QN = "_labelTable_"; //$NON-NLS-1$ + + /** + * The '_label_' prefix of each entry. + */ + public static final String LABEL_PREFIX = "_label_"; //$NON-NLS-1$ + + /** + * The notation extension file (cannot use the + * NotationModel.NOTATION_FILE_EXTENSION because of dependencies cycle). + */ + protected static final String NOTATION_FILE_EXTENSION = "notation"; //$NON-NLS-1$ + + /** + * The map of the loaded resource by the initial URI and by locale. + */ + protected Map<URI, Map<Locale, Resource>> propertiesByLocale = null; + + /** + * Set to keep deleted objects. Those ones must be ignored at the + * {{@link #saveModel()} to avoid exceptions. + * + * The delete of objects does not remove the entries corresponding because + * at the undo, the internationalization values must be not retrieve. + */ + protected Set<EObject> deletedObjects = null; + + /** + * The adapter for the object (to avoid multiple creation for the same + * object). + */ + protected Map<EObject, Adapter> adapters = null; + + /** + * This map allows to keep the editor part for an EObject when it is needed + * to create the InternationalizationEntry and finally the + * PartLabelSynchronizer. + */ + protected Map<EObject, IInternationalizationEditor> editorPartByEObject = null; + + /** + * Save of the created PartLabelSynchronizer to manage the dispose of those + * ones. + */ + protected Map<EObject, Map<InternationalizationEntry, EntryPartLabelSynchronizer>> entriesLabelSynchronizerByEObject = null; + + /** + * Save the preference part label synchronizer corresponding to the object + * of editor part. + */ + protected Map<EObject, PreferencePartLabelSynchronizer> preferencePartLabelSynchronizers = null; + + /** + * Constructor. + */ + public InternationalizationModelResource() { + super(); + propertiesByLocale = new HashMap<URI, Map<Locale, Resource>>(); + + Activator.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() { + + @Override + public void propertyChange(final PropertyChangeEvent event) { + if (event.getProperty().equals(InternationalizationPreferencesConstants.LANGUAGE_PREFERENCE)) { + Iterator<Resource> resourcesIterator = new HashSet<Resource>(getResources()).iterator(); + while (resourcesIterator.hasNext()) { + final Resource resource = resourcesIterator.next(); + loadModel(getInitialURIForResource(resource).trimFileExtension()); + } + } + } + + }); + deletedObjects = new HashSet<EObject>(); + adapters = new HashMap<EObject, Adapter>(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource#loadModel(org.eclipse.emf.common.util.URI) + */ + @Override + public void loadModel(final URI uriWithoutExtension) { + loadModel(uriWithoutExtension, true); + } + + /** + * Attach the model to its resource if this is not already done. + * + * @param uriWithoutExtension + * The uri of the resource to manage. + * @param needToLoadOtherProperties + * Boolean to determinate if the other properties in the project + * have to bo loaded or not. + */ + public void loadModel(final URI uriWithoutExtension, final boolean needToLoadOtherProperties) { + // Compute model URI + final URI uri = uriWithoutExtension.appendFileExtension(getModelFileExtension()); + + if (needToBeLoaded(uri)) { + + resourceURI = uri; + + final Locale locale = InternationalizationPreferencesUtils.getLocalePreference(uriWithoutExtension); + + try { + + resource = loadResource(uri, locale); + + // We need to do even if the resource is null + if (needToLoadOtherProperties) { + resourceURI = uri; + + String existingResourceLoadedName = ""; + if (null != resource) { + existingResourceLoadedName = resource.getURI().lastSegment(); + } + + // We need to load other properties files in the same + // folders + loadOthersPropertiesFiles(uri, existingResourceLoadedName); + } + + } catch (final Exception ex) { + Activator.log.error(ex); + } + } + } + + /** + * This allows to define if the uri file was already loaded. + * + * @param uri + * The uri of the file to load. + * @return <code>true</code> if the file was already loaded. + * <code>false</code> otherwise. + */ + protected boolean needToBeLoaded(final URI uri) { + return !propertiesByLocale.containsKey(uri); + } + + /** + * This allows to add the resource in parameter in the model resources. + * + * @param uri + * The uri of the resource. + * @param resource + * The resource to add. + * @param locale + * The locale to use. + */ + public void addResourceToModel(final URI uri, final Resource resource, final Locale locale) { + resourceURI = uri.trimFileExtension().appendFileExtension(getModelFileExtension()); + configureResource(resource, locale); + } + + /** + * This allows to load others properties files in the project. + * + * @param uri + * The {@link URI}. + * @param loadedResourceFile + * The properties file already loaded. + */ + protected void loadOthersPropertiesFiles(final URI uri, final String loadedResourceFile) { + final URI uriWithoutExtension = uri.trimFileExtension(); + final String modelName = uriWithoutExtension.segment(uriWithoutExtension.segmentCount() - 1); + final URI folderURI = uriWithoutExtension.trimSegments(1); + + // Calculate the project folder + IProject projectFolder = null; + if (folderURI.isPlatformResource()) { + final String uriPlatformString = folderURI.toPlatformString(true); + projectFolder = ResourcesPlugin.getWorkspace().getRoot().getProject(uriPlatformString.substring(1)); + } + + if (null != projectFolder) { + final String extension = "." + getModelFileExtension(); //$NON-NLS-1$ + try { + // Loop on project resources to check about other properties + // file + for (final IResource resourceEntry : projectFolder.members()) { + // Check if the file starts with the name of the model and + // finish with properties + if (resourceEntry.getName().startsWith(modelName) && resourceEntry.getName().endsWith(extension)) { // $NON-NLS-1$ + + // Remove the extension of the file + final String fileNAmeWithoutExtension = resourceEntry.getName().substring(0, + resourceEntry.getName().length() - extension.length()); + // Remove the model name + String possibleLocale = fileNAmeWithoutExtension.substring(modelName.length()); + + // Check this is not the current loaded file of locale + if (!resourceEntry.getName().equals(loadedResourceFile) || possibleLocale.isEmpty()) { + + // This is modelName.properties + if (possibleLocale.isEmpty() && null == getResourceForURIAndLocale(uri, new Locale(""))) { //$NON-NLS-1$ + final URI newURI = folderURI.appendSegment(fileNAmeWithoutExtension) + .appendFileExtension(getModelFileExtension()); + loadResource(newURI, new Locale("")); //$NON-NLS-1$ + // This can be a possible properties locale file + } else if (possibleLocale.startsWith(LocaleNameResolver.UNDERSCORE)) { // $NON-NLS-1$ + possibleLocale = possibleLocale.substring(1); + Locale localeFound = null; + + // Check about possible locale in available + // locales + final Iterator<Locale> availableLocales = Arrays.asList(Locale.getAvailableLocales()) + .iterator(); + while (availableLocales.hasNext() && null == localeFound) { + final Locale currentAvailableLocale = availableLocales.next(); + + if (currentAvailableLocale.toString().equals(possibleLocale)) { + localeFound = currentAvailableLocale; + } + } + + // The file contains a locale, load it + if (null != localeFound) { + loadResource(uri, localeFound); + } + } + + } + } + } + } catch (final CoreException e) { + Activator.log.error(e); + } + } + } + + /** + * This method allows to load the resource (or create it if necessary) and + * load the internationalization content. + * + * @param uri + * The {@link URI}. + * @param locale + * The current locale to use. + * @return The resource loaded. + */ + protected Resource loadResource(final URI uri, final Locale locale) { + Resource resource = null; + + final ResourceBundleAndURI resourceBundleAndURI = PropertiesFilesUtils.getResourceBundle(uri, locale); + if (null != resourceBundleAndURI) { + + // Look for the resource + resource = getResourceSet().getResource(resourceBundleAndURI.getUri(), false); + + // Check if model is loaded. + if (null != resource) { + configureResource(resource, locale); + } else { + // model is not loaded, do it. + // Create Resource of appropriate type + resource = modelSet.createResource(resourceBundleAndURI.getUri()); + + configureResource(resource, locale); + + // call registered snippets + startSnippets(); + } + + loadInternationalizationContent(uri, locale); + } + + return resource; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource#createModel(org.eclipse.emf.common.util.URI) + */ + @Override + public void createModel(final URI uriWithoutExtension) { + super.createModel(uriWithoutExtension); + + final URI uri = uriWithoutExtension.appendFileExtension(getModelFileExtension()); + final Locale locale = InternationalizationPreferencesUtils.getLocalePreference(this.resource.getURI()); + final Resource resource = this.resource; + + // Fill the properties by locale map + if (null == propertiesByLocale.get(resourceURI)) { + propertiesByLocale.put(resourceURI, new HashMap<Locale, Resource>()); + } + propertiesByLocale.get(resourceURI).put(locale, resource); + + // Calculate the internationalization content + loadInternationalizationContent(uri, locale); + + resource.setModified(true); + + try { + saveResource(resource); + } catch (final IOException e) { + Activator.log.error(e); + } + } + + /** + * This allows to configure the resource. + * + * @param resourceToConfigure + * The resource to configure. + * @param locale + * The locale to manage. + */ + protected void configureResource(final Resource resourceToConfigure, final Locale locale) { + super.configureResource(resourceToConfigure); + // Add the resource to the resource properties classified by their + // locale + if (null == propertiesByLocale.get(resourceURI)) { + propertiesByLocale.put(resourceURI, new HashMap<Locale, Resource>()); + } + propertiesByLocale.get(resourceURI).put(locale, resourceToConfigure); + } + + /** + * This allows to load internationalization content of properties file into + * the current resource. + * + * @param uri + * The URI of the properties file with the extension. + * @param locale + * The locale to use. + */ + protected void loadInternationalizationContent(final URI uri, final Locale locale) { + final Resource resource = getResourceForURIAndLocale(uri, locale); + + if (null != resource && resource.getContents().isEmpty()) { + final ResourceBundleAndURI resourceBundleAndURI = PropertiesFilesUtils + .getResourceBundle(uri.trimFileExtension().appendFileExtension(getModelFileExtension()), locale); + if (null != resourceBundleAndURI && null != resourceBundleAndURI.getResourceBundle()) { + // Create the internationalization library to set to the + // resource contents + final InternationalizationLibrary library = InternationalizationFactory.eINSTANCE + .createInternationalizationLibrary(); + final Enumeration<String> keys = resourceBundleAndURI.getResourceBundle().getKeys(); + + // Loop on existing keys + while (keys.hasMoreElements()) { + // Create an entry for each key + final InternationalizationEntry entry = InternationalizationFactory.eINSTANCE + .createInternationalizationEntry(); + String key = (String) keys.nextElement(); + if (key.startsWith(LABEL_DIAGRAM_PREFIX_QN)) { + final String keyWithoutPrefix = key.substring(LABEL_DIAGRAM_PREFIX_QN.length()); + final String qualifiedName = keyWithoutPrefix.substring(0, + keyWithoutPrefix.indexOf(LABEL_PREFIX)); + final String diagramName = keyWithoutPrefix + .substring(keyWithoutPrefix.indexOf(LABEL_PREFIX) + LABEL_PREFIX.length()); + + final Resource notationResource = modelSet.getResource( + uri.trimFileExtension().appendFileExtension(NOTATION_FILE_EXTENSION), true); + + if (null != notationResource && null != notationResource.getContents() + && !notationResource.getContents().isEmpty()) { + final Diagram foundDiagram = QualifiedNameUtils.getDiagram(notationResource, diagramName, + qualifiedName); + entry.setKey(foundDiagram); + addModifiedAdapter(foundDiagram, resource); + } + + } else if (key.startsWith(LABEL_TABLE_PREFIX_QN)) { + final String keyWithoutPrefix = key.substring(LABEL_TABLE_PREFIX_QN.length()); + final String qualifiedName = keyWithoutPrefix.substring(0, + keyWithoutPrefix.indexOf(LABEL_PREFIX)); + final String tableName = keyWithoutPrefix + .substring(keyWithoutPrefix.indexOf(LABEL_PREFIX) + LABEL_PREFIX.length()); + + final Resource umlResource = modelSet.getResource( + uri.trimFileExtension().appendFileExtension(NOTATION_FILE_EXTENSION), true); + + if (null != umlResource && null != umlResource.getContents() + && !umlResource.getContents().isEmpty()) { + final Table foundTable = QualifiedNameUtils.getTable(umlResource, tableName, qualifiedName); + entry.setKey(foundTable); + addModifiedAdapter(foundTable, resource); + } + } else { + entry.setKey(key); + } + entry.setValue(resourceBundleAndURI.getResourceBundle().getString(key)); + // Add the entry to the library + library.getEntries().add(entry); + } + + final GMFtoEMFCommandWrapper command = new GMFtoEMFCommandWrapper(new AddToResourceCommand( + ((ModelSet) resource.getResourceSet()).getTransactionalEditingDomain(), resource, library)); + command.execute(); + } + resource.setModified(false); + } + } + + /** + * This allows to create the properties resource corresponding to the uri in + * parameter. + * + * @param uri + * The URI of the properties resource to create. + * @param locale + * The locale to manage. + * @return The created resource. + */ + protected Resource createResource(final URI uri, final Locale locale) { + // The properties uri (cast the file extension to the needed one) + URI propertiesURI = uri.trimFileExtension().appendFileExtension(getModelFileExtension()); + resourceURI = propertiesURI; + + // The created properties resource need to have the locale in last + // segment (example: test_en_EN.properties) + String lastSegment = propertiesURI.trimFileExtension().lastSegment(); + lastSegment = lastSegment + LocaleNameResolver.UNDERSCORE + locale.toString(); + propertiesURI = propertiesURI.trimSegments(1); + propertiesURI = propertiesURI.appendSegment(lastSegment); + propertiesURI = propertiesURI.appendFileExtension(getModelFileExtension()); + + // Create the resource needed + final Resource resultResource = modelSet.createResource(propertiesURI); + configureResource(resultResource, locale); + + // Create the internationalization library in the resource content + createInternationalizationContent(resultResource); + + // call registered snippets + startSnippets(); + + resource = resultResource; + + return resultResource; + } + + /** + * This allows to create the internationalization library for the resource + * content. + * + * @param resource + * The resource where add the internationalization library. + */ + protected void createInternationalizationContent(final Resource resource) { + if (null != resource) { + // Create the library + final InternationalizationLibrary library = InternationalizationFactory.eINSTANCE + .createInternationalizationLibrary(); + + // Create the resource content command and execute it + final GMFtoEMFCommandWrapper command = new GMFtoEMFCommandWrapper(new AddToResourceCommand( + ((ModelSet) resource.getResourceSet()).getTransactionalEditingDomain(), resource, library)); + command.execute(); + } + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource#saveModel() + */ + @Override + public void saveModel() throws IOException { + // Save into the properties files + + for (final Resource resource : getResources()) { + saveResource(resource); + } + } + + /** + * This allows to save the resource. + * + * @param resource + * The resource to save. + * @throws IOException + * The input output file exception. + */ + protected void saveResource(final Resource resource) throws IOException { + final ModelSet set = getModelManager(); + if (null != resource && set.shouldSave(resource) && !resource.getContents().isEmpty()) { + // It is needed to manage the save of properties by a simple output + // stream because the resource bundle cannot be modified + final Properties properties = new Properties(); + + final InternationalizationLibrary library = (InternationalizationLibrary) resource.getContents().get(0); + + // Add all the entries into properties (need this properties to save + // easier the properties file) + for (final InternationalizationEntry entry : library.getEntries()) { + if (!deletedObjects.contains(entry.getKey()) && !entry.getValue().isEmpty()) { + properties.setProperty(getKey(entry), entry.getValue()); + } + } + + final Locale locale = getLocaleForResource(resource); + + // Get the URI of properties file used (with locale or not) + final URI resourceURI = PropertiesFilesUtils.getResourceBundleURIFromResourceURI(resource.getURI(), locale); + + // This allows to save the properties into the properties file + final URIConverter uriConverter = new ExtensibleURIConverterImpl(); + properties.store(uriConverter.createOutputStream(resourceURI), null); + resource.setModified(false); + } + } + + /** + * This allows to add an adapter to the EOBject to modified the properties + * resource when the EObject has changed. + * + * @param eObject + * The EObject. + * @param resource + * The associated resource. + */ + protected void addModifiedAdapter(final EObject eObject, final Resource resource) { + if (!adapters.containsKey(eObject)) { + Adapter modifiedAdapter = new Adapter() { + + @Override + public void setTarget(final Notifier newTarget) { + // Do nothing + } + + @Override + public void notifyChanged(final Notification notification) { + // If this is a remove, add the old value to the deleted + // objects + if (Notification.REMOVE == notification.getEventType() + || Notification.REMOVE_MANY == notification.getEventType()) { + Object oldValue = notification.getOldValue(); + + if (oldValue instanceof EObject) { + deletedObjects.add((EObject) oldValue); + } + // If this is an add, remove the new value from the + // deleted objects if existing + } else if (Notification.ADD == notification.getEventType() + || Notification.ADD_MANY == notification.getEventType()) { + Object newValue = notification.getNewValue(); + + if (newValue instanceof EObject && deletedObjects.contains(newValue)) { + deletedObjects.remove((EObject) newValue); + } + } + + // The resource is modified (not directly but need to be + // saved) + if (null != eObject.eResource() + && null != getLocalesAndResourcesForURI(eObject.eResource().getURI())) { + for (final Resource res : getLocalesAndResourcesForURI(eObject.eResource().getURI()).values()) { + res.setModified(true); + } + } else { + resource.setModified(true); + } + } + + @Override + public boolean isAdapterForType(Object type) { + return false; + } + + @Override + public Notifier getTarget() { + return null; + } + }; + eObject.eAdapters().add(modifiedAdapter); + adapters.put(eObject, modifiedAdapter); + } + } + + /** + * This allows to get the entry key (can be override to get element string + * identifier instead of string key). + * + * @param entry + * The internationalization entry. + * @return The key as String. + */ + protected String getKey(final InternationalizationEntry entry) { + final StringBuilder result = new StringBuilder(); + if (entry.getKey() instanceof Diagram) { + result.append(LABEL_DIAGRAM_PREFIX_QN); + final Diagram diagram = (Diagram) entry.getKey(); + final EObject diagramContainer = diagram.getElement(); + result.append(QualifiedNameUtils.getQualifiedName(diagramContainer)); + result.append(LABEL_PREFIX); + result.append(diagram.getName()); + } else if (entry.getKey() instanceof Table) { + result.append(LABEL_TABLE_PREFIX_QN); + final Table table = (Table) entry.getKey(); + final EObject tableContainer = table.getOwner(); + result.append(QualifiedNameUtils.getQualifiedName(tableContainer)); + result.append(LABEL_PREFIX); + result.append(table.getName()); + } else { + result.append((String) entry.getKey()); + } + return result.toString(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.core.resource.AbstractModelWithSharedResource#isModelRoot(org.eclipse.emf.ecore.EObject) + */ + @Override + protected boolean isModelRoot(final EObject object) { + return object instanceof InternationalizationLibrary; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.core.resource.AbstractBaseModel#getModelFileExtension() + */ + @Override + public String getModelFileExtension() { + return PropertiesFilesUtils.PROPERTIES_FILE_EXTENSION; + } + + /** + * Open this method. {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.core.resource.AbstractModel#getModelManager() + */ + @Override + public ModelSet getModelManager() { + return super.getModelManager(); + } + + /** + * Open this method. {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.core.resource.EMFLogicalModel#isRelatedResource(org.eclipse.emf.ecore.resource.Resource) + */ + @Override + public boolean isRelatedResource(final Resource resource) { + return super.isRelatedResource(resource); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.core.resource.AbstractModel#getIdentifier() + */ + @Override + public String getIdentifier() { + return MODEL_ID; + } + + /** + * Get the value for the key in parameter. + * + * @param uri + * The uri of the resource where search the key. + * @param key + * The key to search. + * @param locale + * The locale of which to get value. + * @return The value of the key. + */ + public String getValueForEntryKey(final URI uri, final Object key, final Locale locale) { + InternationalizationEntry entry = getEntryForKey(uri, key, locale); + return null != entry ? entry.getValue() : null; + } + + /** + * Get the value for the key in parameter. + * + * @param uri + * The uri of the resource where search the key. + * @param key + * The key to search. + * @return The value of the key. + */ + public String getValueForEntryKey(final URI uri, final EObject key) { + InternationalizationEntry entry = getEntryForKey(uri, key, + InternationalizationPreferencesUtils.getLocalePreference(key)); + return null != entry ? entry.getValue() : null; + } + + /** + * Get the entry for the key in parameter. + * + * @param uri + * The uri of the resource where search the key. + * @param key + * The key to search. + * @param locale + * The locale of which to get value. + * @return The entry of the key. + */ + public InternationalizationEntry getEntryForKey(final URI uri, final Object key, final Locale locale) { + InternationalizationEntry result = null; + + Resource resource = getResourceForURIAndLocale(uri, locale); + + // If the resource for the locale is not found, search for a properties + // without locale + if (null == resource) { + resource = getResourceForURIAndLocale(uri, new Locale("")); //$NON-NLS-1$ + } + + if (null != resource) { + final InternationalizationLibrary library = getModelRoot(resource); + + if (null != library) { + final Iterator<InternationalizationEntry> entries = library.getEntries().iterator(); + + // Iterate on entries to get the value of the key in parameter + while (entries.hasNext() && null == result) { + final InternationalizationEntry entry = entries.next(); + if (entry.getKey().equals(key)) { + result = entry; + } + } + } + } + + return result; + } + + /** + * This allows to get the command to set internationalization value. + * + * @param domain + * The current editing domain. + * @param uri + * The uri of the resource where search the key. + * @param key + * The key to search. + * @param value + * The new value. + * @param locale + * The locale for which to set the value. + * @return The command to set the internationalization value. + */ + public Command getSetValueCommand(final EditingDomain domain, final URI uri, final EObject key, final String value, + final Locale locale) { + Command resultCommand = null; + + // Get the resource where add/modify the entry corresponding to the key + final Resource resource = getResourceForURIAndLocale(uri, locale); + final InternationalizationLibrary library = getModelRoot(resource); + + if (null != library) { + final Iterator<InternationalizationEntry> entries = library.getEntries().iterator(); + + // Search on existing entries if the key already exists. + // In this case, just modify the value + while (entries.hasNext() && null == resultCommand) { + final InternationalizationEntry entry = entries.next(); + if (entry.getKey().equals(key)) { + if (null == value || value.isEmpty()) { + // If the value is null or empty, remove the entry + resultCommand = new CompoundCommand("Remove entry"); //$NON-NLS-1$ + ((CompoundCommand) resultCommand).append(new RemoveCommand(domain, library, + InternationalizationPackage.eINSTANCE.getInternationalizationLibrary_Entries(), entry)); + if (entry.getKey() instanceof EObject) { + Command setNameValueCommand = getSetNameValueCommand(domain, (EObject) entry.getKey()); + if (null != setNameValueCommand) { + ((CompoundCommand) resultCommand).append(setNameValueCommand); + } + } + resource.setModified(true); + } else { + resultCommand = new CompoundCommand("Set entry value"); //$NON-NLS-1$ + ((CompoundCommand) resultCommand).append(new SetCommand(domain, entry, + InternationalizationPackage.eINSTANCE.getInternationalizationEntry_Value(), value)); + if (entry.getKey() instanceof EObject) { + Command setNameValueCommand = getSetNameValueCommand(domain, (EObject) entry.getKey()); + if (null != setNameValueCommand) { + ((CompoundCommand) resultCommand).append(setNameValueCommand); + } + } + resource.setModified(true); + } + } + } + } + + // If the key does not exist, create an entry + if (null == resultCommand) { + final InternationalizationEntry entry = InternationalizationFactory.eINSTANCE + .createInternationalizationEntry(); + entry.setKey(key); + entry.setValue(value); + + if (null == resource) { + // If the resource does not exist, create it and add entry to + // the library + resultCommand = new CompoundCommand("Create entry"); //$NON-NLS-1$ + ((CompoundCommand) resultCommand).append(new CreatePropertiesResourceCommand(uri, entry, + InternationalizationPreferencesUtils.getLocalePreference(key))); + Command setNameValueCommand = getSetNameValueCommand(domain, (EObject) entry.getKey()); + if (null != setNameValueCommand) { + ((CompoundCommand) resultCommand).append(setNameValueCommand); + } + } else { + resultCommand = new CompoundCommand("Create entry"); //$NON-NLS-1$ + ((CompoundCommand) resultCommand).append(new AddCommand(domain, library, + InternationalizationPackage.eINSTANCE.getInternationalizationLibrary_Entries(), entry)); + Command setNameValueCommand = getSetNameValueCommand(domain, (EObject) entry.getKey()); + if (null != setNameValueCommand) { + ((CompoundCommand) resultCommand).append(setNameValueCommand); + } + resource.setModified(true); + } + + // If the created entry is an entry corresponding to an object who's + // depending to Editor part, we need to create the + // PartLabelSynchronizer + if (null != editorPartByEObject && editorPartByEObject.containsKey(key)) { + if (null != resultCommand) { + final Command tmpCommand = resultCommand; + resultCommand = new CompoundCommand("Change label value"); //$NON-NLS-1$ + ((CompoundCommand) resultCommand).append(tmpCommand); + ((CompoundCommand) resultCommand).append(new AbstractCommand() { + + @Override + public void execute() { + addPartLabelSynchronizerForEntry(key, entry); + } + + @Override + protected boolean prepare() { + return true; + } + + @Override + public void undo() { + // Do nothing + } + + @Override + public void redo() { + // Do nothing + } + }); + } + } + } + + return resultCommand; + } + + /** + * This allows to add or update value of property with key in parameter. + * + * @param uri + * The uri of the resource where search the key. + * @param key + * The key to search. + * @param value + * The new value. + * @param locale + * The locale for which set the value. + */ + public void setValue(final URI uri, final EObject key, final String value, final Locale locale) { + + // Get the resource where add/modify the entry corresponding to the key + Resource resource = getResourceForURIAndLocale(uri, locale); + if (null == resource) { + // If the resource does not exist, create it + resource = createResource(uri, InternationalizationPreferencesUtils.getLocalePreference(key)); + } + + final InternationalizationLibrary library = getModelRoot(resource); + + final Iterator<InternationalizationEntry> entries = library.getEntries().iterator(); + boolean hasFound = false; + + // Search on existing entries if the key already exists. + // In this case, just modify the value + while (entries.hasNext() && !hasFound) { + final InternationalizationEntry entry = entries.next(); + if (entry.getKey().equals(key)) { + if (null == value || value.isEmpty()) { + // If the value is null or empty, remove the entry + entries.remove(); + } else { + entry.setValue(value); + if (entry.getKey() instanceof EObject) { + setNameValue((EObject) entry.getKey()); + } + } + hasFound = true; + } + } + + // If the key does not exist, create an entry + if (!hasFound) { + final InternationalizationEntry entry = InternationalizationFactory.eINSTANCE + .createInternationalizationEntry(); + entry.setKey(key); + entry.setValue(value); + library.getEntries().add(entry); + setNameValue(entry); + + // If the created entry is an entry corresponding to an object who's + // depending to Editor part, we need to create the + // PartLabelSynchronizer + if (editorPartByEObject.containsKey(key)) { + addPartLabelSynchronizerForEntry(key, entry); + } + } + resource.setModified(true); + } + + /** + * This allows to modify the name of the entry object when the label value + * is modified to notify all the name listeners. When the label change, all + * the name listeners need to be called. + * + * @param domain + * The current editing domain. + * @param eObject + * The eObject of the label to modify. + * @return |