### Eclipse Workspace Patch 1.0 #P org.eclipse.papyrus.views.properties Index: src/org/eclipse/papyrus/views/properties/xwt/XWTSection.java =================================================================== --- src/org/eclipse/papyrus/views/properties/xwt/XWTSection.java (revision 9762) +++ src/org/eclipse/papyrus/views/properties/xwt/XWTSection.java (working copy) @@ -44,15 +44,15 @@ */ public class XWTSection extends AbstractPropertySection implements IChangeListener { - private Section section; + private final Section section; private DataSource source; - private View view; + private final View view; private Composite self; - private DisplayEngine display; + private final DisplayEngine display; private Set constraints; Index: src/org/eclipse/papyrus/views/properties/runtime/DefaultDisplayEngine.java =================================================================== --- src/org/eclipse/papyrus/views/properties/runtime/DefaultDisplayEngine.java (revision 9762) +++ src/org/eclipse/papyrus/views/properties/runtime/DefaultDisplayEngine.java (working copy) @@ -47,13 +47,13 @@ */ public class DefaultDisplayEngine implements DisplayEngine { - private ILoadingContext loadingContext = new DefaultLoadingContext(getClass().getClassLoader()); + private final ILoadingContext loadingContext = new DefaultLoadingContext(getClass().getClassLoader()); - private Set displayedSections = new HashSet(); + private final Set displayedSections = new HashSet(); - private Set controls = new HashSet(); + private final Set controls = new HashSet(); - private boolean allowDuplicate; + private final boolean allowDuplicate; /** * Constructs a new DisplayEnginet that doesn't allow the duplication of sections Index: src/org/eclipse/papyrus/views/properties/widgets/MultiReferenceEditorWithPropertyView.java =================================================================== --- src/org/eclipse/papyrus/views/properties/widgets/MultiReferenceEditorWithPropertyView.java (revision 9762) +++ src/org/eclipse/papyrus/views/properties/widgets/MultiReferenceEditorWithPropertyView.java (working copy) @@ -19,21 +19,20 @@ import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.papyrus.views.properties.contexts.View; -import org.eclipse.papyrus.views.properties.runtime.ConfigurationManager; -import org.eclipse.papyrus.views.properties.runtime.EmbeddedDisplayEngine; import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory; import org.eclipse.papyrus.infra.widgets.editors.AbstractListEditor; import org.eclipse.papyrus.infra.widgets.editors.ICommitListener; import org.eclipse.papyrus.infra.widgets.editors.MultipleReferenceEditor; +import org.eclipse.papyrus.views.properties.contexts.View; +import org.eclipse.papyrus.views.properties.runtime.ConfigurationManager; +import org.eclipse.papyrus.views.properties.runtime.EmbeddedDisplayEngine; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -public class MultiReferenceEditorWithPropertyView extends AbstractListEditor - implements ISelectionChangedListener { +public class MultiReferenceEditorWithPropertyView extends AbstractListEditor implements ISelectionChangedListener { protected MultipleReferenceEditor multiReferenceEditor; @@ -44,17 +43,15 @@ public MultiReferenceEditorWithPropertyView(Composite parent, int style) { super(parent, style); // parent.setBackground(getDisplay().getSystemColor(SWT.COLOR_RED)); - ((GridLayout) getLayout()).numColumns++; + ((GridLayout)getLayout()).numColumns++; multiReferenceEditor = createMultipleReferenceEditor(style); multiReferenceEditor.addSelectionChangedListener(this); - multiReferenceEditor.setLayoutData(new GridData(SWT.BEGINNING, - SWT.FILL, false, true)); + multiReferenceEditor.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, true)); propertiesComposite = new Composite(this, style); propertiesComposite.setLayout(new FillLayout()); - propertiesComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, - true, true)); + propertiesComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); } /** @@ -116,7 +113,7 @@ @Override public void setModelObservable(IObservableList modelObservable) { multiReferenceEditor.setModelObservable(modelObservable); - if (!modelObservable.isEmpty()) { + if(!modelObservable.isEmpty()) { multiReferenceEditor.getViewer().setSelection(new StructuredSelection(modelObservable.get(0))); } } @@ -130,8 +127,7 @@ public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); - Set views = ConfigurationManager.instance.constraintEngine - .getViews(selection); + Set views = ConfigurationManager.instance.constraintEngine.getViews(selection); displayEngine.display(views, propertiesComposite, selection, SWT.NONE); this.layout(); propertiesComposite.layout(); #P org.eclipse.papyrus.uml.properties Index: src/org/eclipse/papyrus/uml/properties/modelelement/CommentModelElement.java =================================================================== --- src/org/eclipse/papyrus/uml/properties/modelelement/CommentModelElement.java (revision 0) +++ src/org/eclipse/papyrus/uml/properties/modelelement/CommentModelElement.java (working copy) @@ -0,0 +1,78 @@ +/***************************************************************************** + * Copyright (c) 2012 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sebastien Poissonnet (CEA LIST) sebastien.poissonnet@cea.fr + *****************************************************************************/ +package org.eclipse.papyrus.uml.properties.modelelement; + +import org.eclipse.core.databinding.observable.IObservable; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory; +import org.eclipse.papyrus.uml.properties.databinding.AppliedCommentsObservableList; +import org.eclipse.papyrus.views.properties.modelelement.EMFModelElement; +import org.eclipse.uml2.uml.Element; + +public class CommentModelElement extends EMFModelElement { + + private static final String APPLIED_COMMENTS_PROPERTY = "appliedComments"; + + public CommentModelElement(Element source, EditingDomain domain) { + super(source, domain); + } + + @Override + public boolean isOrdered(String propertyPath) { + if(APPLIED_COMMENTS_PROPERTY.equals(propertyPath)) { + return false; + } + return super.isOrdered(propertyPath); + } + + @Override + public boolean isUnique(String propertyPath) { + if(APPLIED_COMMENTS_PROPERTY.equals(propertyPath)) { + return true; + } + return super.isUnique(propertyPath); + } + + @Override + protected IObservable doGetObservable(String propertyPath) { + if(APPLIED_COMMENTS_PROPERTY.equals(propertyPath)) { + return new AppliedCommentsObservableList(domain, (Element)source); + } + return super.doGetObservable(propertyPath); + } + + @Override + public ReferenceValueFactory getValueFactory(String propertyPath) { + if(APPLIED_COMMENTS_PROPERTY.equals(propertyPath)) { + return super.getValueFactory("ownedComment"); + } + + return super.getValueFactory(propertyPath); + } + + @Override + public boolean getDirectCreation(String propertyPath) { + if(APPLIED_COMMENTS_PROPERTY.equals(propertyPath)) { + return true; + } + return super.getDirectCreation(propertyPath); + } + + @Override + public boolean isEditable(String propertyPath) { + if(APPLIED_COMMENTS_PROPERTY.equals(propertyPath)) { + return true; + } + return super.isEditable(propertyPath); + } + +} Index: src/org/eclipse/papyrus/uml/properties/widgets/CommentEditor.java =================================================================== --- src/org/eclipse/papyrus/uml/properties/widgets/CommentEditor.java (revision 0) +++ src/org/eclipse/papyrus/uml/properties/widgets/CommentEditor.java (working copy) @@ -0,0 +1,37 @@ +/***************************************************************************** + * Copyright (c) 2012 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sebastien Poissonnet (CEA LIST) sebastien.poissonnet@cea.fr + *****************************************************************************/ +package org.eclipse.papyrus.uml.properties.widgets; + +import org.eclipse.core.databinding.observable.list.IObservableList; +import org.eclipse.papyrus.uml.properties.providers.CommentContentProvider; +import org.eclipse.papyrus.views.properties.widgets.MultiReferenceEditorWithPropertyView; +import org.eclipse.swt.widgets.Composite; + +public class CommentEditor extends MultiReferenceEditorWithPropertyView { + + public CommentEditor(Composite parent, int style) { + super(parent, style); + } + + @Override + public void setModelObservable(IObservableList modelObservable) { + super.setModelObservable(modelObservable); + updateContentProvider(); + } + + + + private void updateContentProvider() { + multiReferenceEditor.getViewer().setContentProvider(new CommentContentProvider()); + } + +} Index: META-INF/MANIFEST.MF =================================================================== --- META-INF/MANIFEST.MF (revision 9790) +++ META-INF/MANIFEST.MF (working copy) @@ -55,4 +55,5 @@ org.eclipse.papyrus.uml.properties.util, org.eclipse.papyrus.uml.properties.widgets Bundle-Version: 0.9.1.qualifier +Import-Package: org.eclipse.papyrus.uml.properties.widgets Index: src/org/eclipse/papyrus/uml/properties/modelelement/CommentModelElementFactory.java =================================================================== --- src/org/eclipse/papyrus/uml/properties/modelelement/CommentModelElementFactory.java (revision 0) +++ src/org/eclipse/papyrus/uml/properties/modelelement/CommentModelElementFactory.java (working copy) @@ -0,0 +1,36 @@ +/***************************************************************************** + * Copyright (c) 2012 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sebastien Poissonnet (CEA LIST) sebastien.poissonnet@cea.fr + *****************************************************************************/ +package org.eclipse.papyrus.uml.properties.modelelement; + +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.uml.tools.utils.UMLUtil; +import org.eclipse.papyrus.views.properties.Activator; +import org.eclipse.papyrus.views.properties.contexts.DataContextElement; +import org.eclipse.papyrus.views.properties.modelelement.ModelElement; +import org.eclipse.papyrus.views.properties.modelelement.ModelElementFactory; +import org.eclipse.uml2.uml.Element; + +public class CommentModelElementFactory implements ModelElementFactory { + + public ModelElement createFromSource(Object source, DataContextElement context) { + Element umlSource = UMLUtil.resolveUMLElement(source); + if(umlSource == null) { + Activator.log.warn("Unable to resolve the selected element to a UML Element"); //$NON-NLS-1$ + return null; + } + + EditingDomain domain = EMFHelper.resolveEditingDomain(umlSource); + return new CommentModelElement(umlSource, domain); + } + +} Index: src/org/eclipse/papyrus/uml/properties/databinding/AppliedCommentsObservableList.java =================================================================== --- src/org/eclipse/papyrus/uml/properties/databinding/AppliedCommentsObservableList.java (revision 0) +++ src/org/eclipse/papyrus/uml/properties/databinding/AppliedCommentsObservableList.java (working copy) @@ -0,0 +1,218 @@ +/***************************************************************************** + * Copyright (c) 2012 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sebastien Poissonnet (CEA LIST) sebastien.poissonnet@cea.fr + *****************************************************************************/ +package org.eclipse.papyrus.uml.properties.databinding; + +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.ecore.EStructuralFeature.Setting; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; +import org.eclipse.papyrus.infra.emf.databinding.PapyrusObservableList; +import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; +import org.eclipse.uml2.common.util.UML2Util; +import org.eclipse.uml2.uml.Comment; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.UMLPackage; + +public class AppliedCommentsObservableList extends PapyrusObservableList { + + public AppliedCommentsObservableList(EditingDomain domain, Element source) { + super(getAppliedCommentsList(source), domain, source, UMLPackage.eINSTANCE.getElement_OwnedComment()); + } + + private static List getAppliedCommentsList(Element source) { + List result = new LinkedList(); + + Iterator it = UML2Util.getNonNavigableInverseReferences(source).iterator(); + while(it.hasNext()) { + Setting setting = it.next(); + if(setting.getEStructuralFeature() == UMLPackage.Literals.COMMENT__ANNOTATED_ELEMENT) { + if(setting.getEObject() instanceof Comment) { + Comment comment = (Comment)setting.getEObject(); + + // small bugfix... + // UML2Util.getNonNavigableInverseReferences returns more element than + // needed, especially elements that are not real ones + // so we must check if they are contained by the current resource or + // not... + boolean isProxy = false; + for(Element annotatedElement : comment.getAnnotatedElements()) { + if(annotatedElement.eResource() == null) { + isProxy = true; + } + } + + // this is the real element, not a ghost one. display it in the list + if(!isProxy) { + if(comment.getAnnotatedElements().contains(source)) { + result.add(comment); + } + } + + } + } + } + + return result; + } + + @Override + protected void refreshCacheList() { + if(isDisposed()) { + return; + } + wrappedList.clear(); + wrappedList.addAll(getAppliedCommentsList((Element)source)); + fireListChange(null); + } + + @Override + public Command getAddAllCommand(Collection values) { + throw new UnsupportedOperationException(); + // return super.getAddAllCommand(values); + } + + @Override + public Command getAddAllCommand(int index, Collection values) { + throw new UnsupportedOperationException(); + // return super.getAddAllCommand(index, values); + } + + @Override + public Command getAddCommand(int index, Object value) { + throw new UnsupportedOperationException(); + // return super.getAddCommand(index, value); + } + + @Override + public Command getAddCommand(Object value) { + Assert.isTrue(value instanceof Comment); + + Comment comment = (Comment)value; + + //Add the comment to source#ownedComment + CompoundCommand addAppliedCommentCommand = new CompoundCommand("Add applied comment"); + addAppliedCommentCommand.append(super.getAddCommand(value)); + + //Add the source element to comment#annotatedElement + // List values = new LinkedList(comment.getAnnotatedElements()); + // values.add((Element)source); + // + // SetRequest setRequest = new SetRequest(comment, UMLPackage.eINSTANCE.getComment_AnnotatedElement(), values); + // IElementEditService provider = getProvider(); + // + // addAppliedCommentCommand.append(getCommandFromRequests(provider, Collections.singletonList(setRequest))); + + + AddCommand addCommand = new AddCommand(editingDomain, comment, UMLPackage.eINSTANCE.getComment_AnnotatedElement(), source); + addAppliedCommentCommand.append(addCommand); + + return addAppliedCommentCommand; + } + + @Override + public Command getRemoveCommand(Object value) { + Assert.isTrue(value instanceof Comment); + + CompoundCommand removeAppliedCommentCommand = new CompoundCommand("Remove applied comment"); + Comment comment = (Comment)value; + + if(comment.getAnnotatedElements().size() <= 1) { + return super.getRemoveCommand(value); + } + + //Remove the source element to comment#annotatedElement + List values = new LinkedList(comment.getAnnotatedElements()); + values.remove(source); + SetRequest setRequest = new SetRequest(comment, UMLPackage.eINSTANCE.getComment_AnnotatedElement(), values); + IElementEditService provider = getProvider(); + + removeAppliedCommentCommand.append(getCommandFromRequests(provider, Collections.singletonList(setRequest))); + + + // if(editingDomain != null) { + // RemoveCommand command = new RemoveCommand(editingDomain, comment, UMLPackage.eINSTANCE.getComment_AnnotatedElement(), source); + // return command; + // } + + return removeAppliedCommentCommand; + } + + @Override + public Command getRemoveAllCommand(Collection values) { + + Iterator itr = values.iterator(); + Comment comment; + Element value; + List values_; + CompoundCommand removeAppliedCommentCommand = new CompoundCommand("Remove applied comment"); + + while(itr.hasNext()) { + value = (Element)itr.next(); + Assert.isTrue(value instanceof Comment); + comment = (Comment)value; + + if(comment.getAnnotatedElements().size() <= 1) { + removeAppliedCommentCommand.append(super.getRemoveCommand(value)); + } else { + values_ = new LinkedList(comment.getAnnotatedElements()); + values_.remove(source); + SetRequest setRequest = new SetRequest(comment, UMLPackage.eINSTANCE.getComment_AnnotatedElement(), values_); + IElementEditService provider = getProvider(); + + removeAppliedCommentCommand.append(getCommandFromRequests(provider, Collections.singletonList(setRequest))); + } + + } + + return removeAppliedCommentCommand; + } + + // + // Unsupported operations + // + + @Override + public Command getClearCommand() { + throw new UnsupportedOperationException(); + // return super.getClearCommand(); + } + + @Override + public List getMoveCommands(int oldIndex, int newIndex) { + throw new UnsupportedOperationException(); + // return super.getMoveCommands(oldIndex, newIndex); + } + + @Override + public Command getRemoveCommand(int index) { + throw new UnsupportedOperationException(); + // return super.getRemoveCommand(index); + } + + @Override + public Command getSetCommand(int index, Object value) { + throw new UnsupportedOperationException(); + // return super.getSetCommand(index, value); + } + + + +} Index: src/org/eclipse/papyrus/uml/properties/providers/CommentContentProvider.java =================================================================== --- src/org/eclipse/papyrus/uml/properties/providers/CommentContentProvider.java (revision 0) +++ src/org/eclipse/papyrus/uml/properties/providers/CommentContentProvider.java (working copy) @@ -0,0 +1,99 @@ +/***************************************************************************** + * Copyright (c) 2012 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sebastien Poissonnet (CEA LIST) sebastien.poissonnet@cea.fr + *****************************************************************************/ +package org.eclipse.papyrus.uml.properties.providers; + +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.emf.ecore.EStructuralFeature.Setting; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider; +import org.eclipse.uml2.common.util.UML2Util; +import org.eclipse.uml2.uml.Comment; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.UMLPackage; + +public class CommentContentProvider implements IHierarchicContentProvider { + + public Object[] getElements(Object inputElement) { + // Roots + if(inputElement instanceof Collection) { + return ((Collection)inputElement).toArray(); + } else if(inputElement instanceof Object[]) { + return (Object[])inputElement; + } + + return new Object[]{}; + } + + public Object[] getChildren(Object parentElement) { + // Comment's children + + List result = new LinkedList(); + + Iterator it = UML2Util.getNonNavigableInverseReferences((Element)parentElement).iterator(); + while(it.hasNext()) { + Setting setting = it.next(); + if(setting.getEStructuralFeature() == UMLPackage.Literals.COMMENT__ANNOTATED_ELEMENT) { + if(setting.getEObject() instanceof Comment) { + Comment comment = (Comment)setting.getEObject(); + + // small bugfix... + // UML2Util.getNonNavigableInverseReferences returns more element than + // needed, especially elements that are not real ones + // so we must check if they are contained by the current resource or + // not... + boolean isProxy = false; + for(Element annotatedElement : comment.getAnnotatedElements()) { + if(annotatedElement.eResource() == null) { + isProxy = true; + } + } + + // this is the real element, not a ghost one. display it in the list + if(!isProxy) { + if(comment.getAnnotatedElements().contains(parentElement)) { + result.add(comment); + } + } + + } + } + } + + return result.toArray(); + } + + public Object getParent(Object element) { + // useful ? + return null; + } + + public boolean hasChildren(Object element) { + return getChildren(element).length > 0; + } + + public void dispose() { + //Nothing + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + //Nothing + } + + public boolean isValidValue(Object element) { + return true; + } + +} Index: Model/Environment.xmi =================================================================== --- Model/Environment.xmi (revision 9790) +++ Model/Environment.xmi (working copy) @@ -1,19 +1,74 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + Index: src/org/eclipse/papyrus/uml/properties/widgets/CommentPropertyEditor.java =================================================================== --- src/org/eclipse/papyrus/uml/properties/widgets/CommentPropertyEditor.java (revision 0) +++ src/org/eclipse/papyrus/uml/properties/widgets/CommentPropertyEditor.java (working copy) @@ -0,0 +1,29 @@ +/***************************************************************************** + * Copyright (c) 2012 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sebastien Poissonnet (CEA LIST) sebastien.poissonnet@cea.fr + *****************************************************************************/ +package org.eclipse.papyrus.uml.properties.widgets; + +import org.eclipse.papyrus.views.properties.widgets.MultiReferenceEditorWithPropertyView; +import org.eclipse.papyrus.views.properties.widgets.MultiReferencePropertyEditorWithPropertyView; +import org.eclipse.swt.widgets.Composite; + +public class CommentPropertyEditor extends MultiReferencePropertyEditorWithPropertyView { + + public CommentPropertyEditor(Composite parent, int style) { + super(parent, style); + } + + @Override + protected MultiReferenceEditorWithPropertyView createMultiReferenceEditorWithPropertyView(Composite parent, int style) { + return new CommentEditor(parent, style); + } + +}