Skip to content

Commit

Permalink
[2110] Representations now have a package attribute
Browse files Browse the repository at this point in the history
Representations now have a textual package attribute which is stored
as a DAnnotation on the corresponding DRepresentationDescriptor.
The package attribute is consumed by the capella project explorer
to show these packages as folders under the related semantic target.

Conflicts:
	core/plugins/org.polarsys.capella.core.diagram.helpers/src/org/polarsys/capella/core/diagram/helpers/DAnnotationHelper.java
	core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/sections/DiagramRepresentationPropertySection.java
	tests/plugins/org.polarsys.capella.test.rcptt/AllTests.suite
	tests/plugins/org.polarsys.capella.test.rcptt/pom.xml

Bug: 2110
Change-Id: I13844be98d03ddd6d13f8e1425804b40f0a55c17
Signed-off-by: Felix Dorner <felix.dorner@gmail.com>
  • Loading branch information
felixdo committed Sep 4, 2018
1 parent e17d9be commit 9436018
Show file tree
Hide file tree
Showing 23 changed files with 708 additions and 47 deletions.
Expand Up @@ -118,10 +118,10 @@ private int migrate(DRepresentation diagram, DRepresentationDescriptor descripto
int result = 0;

// Remove annotations from Initialize From Existing Diagram, since never used and tooled.
if (DAnnotationHelper.removeAnnotation(allocating_diagrams, diagram)) {
if (DAnnotationHelper.deleteAnnotation(allocating_diagrams, diagram)) {
result++;
}
if (DAnnotationHelper.removeAnnotation(allocated_diagrams, diagram)) {
if (DAnnotationHelper.deleteAnnotation(allocated_diagrams, diagram)) {
result++;
}

Expand Down
Expand Up @@ -125,7 +125,7 @@ public List<EObject> getContextualElements(DRepresentationDescriptor representat
public void setContextualElements(DRepresentationDescriptor representation, Collection<EObject> elements) {
if (representation != null) {
if ((elements == null) || (elements.size() == 0)) {
DAnnotationHelper.removeAnnotation(IRepresentationAnnotationConstants.ContextualElements, representation);
DAnnotationHelper.deleteAnnotation(IRepresentationAnnotationConstants.ContextualElements, representation);

} else {
DAnnotation annotation = DAnnotationHelper.getAnnotation(IRepresentationAnnotationConstants.ContextualElements, representation, true);
Expand Down
Expand Up @@ -10,6 +10,7 @@
*******************************************************************************/
package org.polarsys.capella.core.diagram.helpers;

import org.eclipse.sirius.business.api.helper.SiriusUtil;
import org.eclipse.sirius.viewpoint.description.DAnnotation;
import org.eclipse.sirius.viewpoint.description.DModelElement;
import org.eclipse.sirius.viewpoint.description.DescriptionFactory;
Expand All @@ -31,20 +32,6 @@ public static DAnnotation createAnnotation(final String source, DModelElement re
return annotation;
}

/**
* Remove the first annotation with a given source from a given model element
* @param source
* @param representation
*/
public static boolean removeAnnotation(String source, DModelElement representation) {
DAnnotation annotation = getAnnotation(source, representation, false);
if (annotation != null) {
representation.getEAnnotations().remove(annotation);
return true;
}
return false;
}

/**
* Get the first annotation with a given source from a given model element, optionally
* creating the annotation if none previously existed.
Expand All @@ -55,7 +42,7 @@ public static boolean removeAnnotation(String source, DModelElement representati
*/
public static DAnnotation getAnnotation(String source, DModelElement representation, boolean create) {
for (DAnnotation annotation : representation.getEAnnotations()) {
if (annotation.getSource() != null && annotation.getSource().equals(source)) {
if (annotation.getSource() != null && annotation.getSource().equals(source)) {
return annotation;
}
}
Expand All @@ -77,5 +64,19 @@ public static boolean hasAnnotation(String source, DModelElement representation)
return getAnnotation(source, representation, false) != null;
}


/**
* Delete the first annotation with a given source from a given model element
* @param source
* @param representation
* @return true if an annotation was deleted, false otherwise
*/
public static boolean deleteAnnotation(String source, DModelElement representation) {
DAnnotation annotation = getAnnotation(source, representation, false);
if (annotation != null) {
SiriusUtil.delete(annotation);
return true;
}
return false;
}

}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2017 THALES GLOBAL SERVICES.
* Copyright (c) 2006, 2018 THALES GLOBAL SERVICES.
* 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
Expand All @@ -13,23 +13,30 @@
import java.util.Collection;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.command.AbstractCommand;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.IdentityCommand;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.sirius.business.api.dialect.DialectManager;
import org.eclipse.sirius.business.api.helper.SiriusUtil;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.business.api.session.SessionManager;
import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.diagram.DiagramPackage;
import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.eclipse.sirius.viewpoint.ViewpointPackage;
import org.eclipse.sirius.viewpoint.description.DAnnotation;
import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
import org.eclipse.sirius.viewpoint.description.Viewpoint;
import org.polarsys.capella.common.helpers.EcoreUtil2;
import org.polarsys.capella.core.diagram.helpers.naming.DAnnotationSourceConstants;
import org.polarsys.capella.core.diagram.helpers.naming.DiagramDescriptionConstants;

/**
*
*/

public class DiagramHelper {

private static DiagramHelper instance;
Expand Down Expand Up @@ -164,5 +171,71 @@ public DRepresentation getRepresentation(DSemanticDecorator decorator) {
}
return (DRepresentation) EcoreUtil2.getFirstContainer(decorator, ViewpointPackage.Literals.DREPRESENTATION);
}

/**
* Get the package name of a representation descriptor.
* @param descriptor
* @return the package name, or null if the descriptor has no package
*/
public String getPackageName(DRepresentationDescriptor descriptor) {
String name = null;
DAnnotation annot = DAnnotationHelper.getAnnotation(DAnnotationSourceConstants.CAPELLA_DIAGRAM_PACKAGE, descriptor, false);
if (annot != null) {
name = annot.getDetails().get(DAnnotationSourceConstants.CAPELLA_DIAGRAM_PACKAGE_KEY);
}
return name;
}

/**
* Creates a command to set or clear the package name for a representation descriptor.
* Before creating a change command, inspect the current package name and if that is equal
* to the new name return null
*
* @param descriptor
* @param name the new package name, or null to clear the package
*/
public Command createSetPackageNameCommand(TransactionalEditingDomain domain, final DRepresentationDescriptor descriptor, final String name) {

//
// If package is changed re-create the whole annotation to force a notification
// from the descriptor which then causes a viewer refresh.
//
AbstractCommand command = null;
final DAnnotation annot = DAnnotationHelper.getAnnotation(DAnnotationSourceConstants.CAPELLA_DIAGRAM_PACKAGE, descriptor, false);

if (name != null) {

String currentValue = null;

if (annot != null) {
currentValue = annot.getDetails().get(DAnnotationSourceConstants.CAPELLA_DIAGRAM_PACKAGE_KEY);
}

if (currentValue == null || !currentValue.equals(name)) {
command = new RecordingCommand(domain) {
public void doExecute() {
if (annot != null) {
SiriusUtil.delete(annot);
}
DAnnotation annot = DAnnotationHelper.getAnnotation(DAnnotationSourceConstants.CAPELLA_DIAGRAM_PACKAGE, descriptor, true);
annot.getDetails().put(DAnnotationSourceConstants.CAPELLA_DIAGRAM_PACKAGE_KEY, name);
}
};
command.setLabel(Messages.DiagramHelper_0);
}

} else if ( annot != null) {
command = new RecordingCommand(domain) {
@Override
protected void doExecute() {
SiriusUtil.delete(annot);
}
};
command.setLabel(Messages.DiagramHelper_1);
}

return command;

}

}
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2018 THALES GLOBAL SERVICES.
* 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:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.diagram.helpers;

import org.eclipse.osgi.util.NLS;

public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.polarsys.capella.core.diagram.helpers.messages"; //$NON-NLS-1$
public static String DiagramHelper_0;
public static String DiagramHelper_1;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}

private Messages() {
}
}
Expand Up @@ -103,7 +103,7 @@ protected static void setAnnotation(DRepresentationDescriptor representation, St
if (!value.booleanValue()) {
DAnnotationHelper.getAnnotation(source, representation, true);
} else {
DAnnotationHelper.removeAnnotation(source, representation);
DAnnotationHelper.deleteAnnotation(source, representation);
}
}

Expand All @@ -118,7 +118,7 @@ protected static void setAnnotation(DRepresentationDescriptor representation, St
annotation.getDetails().put(key, value);

} else {
DAnnotationHelper.removeAnnotation(source, representation);
DAnnotationHelper.deleteAnnotation(source, representation);
}
}

Expand All @@ -129,7 +129,7 @@ protected static void setAnnotation(DRepresentationDescriptor representation, St
annotation.getReferences().add(value);

} else {
DAnnotationHelper.removeAnnotation(source, representation);
DAnnotationHelper.deleteAnnotation(source, representation);
}
}
}
@@ -0,0 +1,12 @@
###############################################################################
# Copyright (c) 2018 THALES GLOBAL SERVICES.
# 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:
# Thales - initial API and implementation
###############################################################################
DiagramHelper_0=Set representation package
DiagramHelper_1=Clear representation package
Expand Up @@ -20,6 +20,13 @@ public class DAnnotationSourceConstants {
* semantic model elements which are of some special interest to the
* related representation.
*/
public static final String CAPELLA_ELEMENT_OF_INTEREST = "https://www.polarsys.org/capella/dannotation/eoi";
public static final String CAPELLA_ELEMENT_OF_INTEREST = "https://www.polarsys.org/capella/dannotation/eoi"; //$NON-NLS-1$

/**
* Package annotation. Used on DRepresentationDescriptors to organize
* diagrams into packages.
*/
public static final String CAPELLA_DIAGRAM_PACKAGE = "https://www.polarsys.org/capella/dannotation/package"; //$NON-NLS-1$
public static final String CAPELLA_DIAGRAM_PACKAGE_KEY = "name"; //$NON-NLS-1$

}
Expand Up @@ -243,6 +243,9 @@
<instanceof value="org.eclipse.emf.ecore.EObject"/>
<adapt type="org.eclipse.emf.ecore.EObject"/>
<instanceof value="org.eclipse.sirius.business.api.session.Session"/>
<instanceof
value="org.polarsys.capella.core.platform.sirius.ui.navigator.viewer.RepresentationPackage">
</instanceof>
</or>
</possibleChildren>

Expand Down

0 comments on commit 9436018

Please sign in to comment.