Skip to content

Commit

Permalink
[558032] Fix Show/Hide Title Block Tool (#296)
Browse files Browse the repository at this point in the history
* [558032] Fix Show/Hide Title Block Tool

Bug: 558032
Change-Id: Ie3d9e523d9496ca57e64cfd8aaa001cd7a6f4002
Signed-off-by: Sandu Postaru <[email protected]>

* [558032] Add refresh for create and insert/remove tools

Bug: 558032
Change-Id: I12d75d3ab8fb3bc1fd9edc1f38a1c44c8e7fc4dc
Signed-off-by: Philippe DUL <[email protected]>

Co-authored-by: Philippe DUL <[email protected]>
  • Loading branch information
sandupostaru and pdulth authored Jun 30, 2020
1 parent f100533 commit d7173b4
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4655,9 +4655,11 @@
<firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="var:containerView">
<subModelOperations xsi:type="tool_1:If" conditionExpression="aql:self.isValidCreateDiagramTitleBlock()">
<subModelOperations xsi:type="tool_1:ChangeContext" browseExpression="aql:self.createDiagramTitleBlock()"/>
<subModelOperations xsi:type="tool_1:ChangeContext" browseExpression="aql:containerView.getDiagramContainer().forceRefresh()"/>
</subModelOperations>
<subModelOperations xsi:type="tool_1:If" conditionExpression="aql:self.isValidCreateElementTitleBlock()">
<subModelOperations xsi:type="tool_1:ChangeContext" browseExpression="aql:self.createElementTitleBlock(diagram)"/>
<subModelOperations xsi:type="tool_1:ChangeContext" browseExpression="aql:containerView.getDiagramContainer().forceRefresh()"/>
</subModelOperations>
</firstModelOperations>
</initialOperation>
Expand Down Expand Up @@ -4715,6 +4717,7 @@
</subModelOperations>
<subModelOperations xsi:type="tool_1:If" conditionExpression="aql:not (selectedTitleBlocks = 'WIZARD_CANCELED')">
<subModelOperations xsi:type="tool_1:ChangeContext" browseExpression="aql:elementView.showHideTitleBlocks(selectedTitleBlocks)"/>
<subModelOperations xsi:type="tool_1:ChangeContext" browseExpression="aql:elementView.getDiagramContainer().forceRefresh()"/>
</subModelOperations>
</firstModelOperations>
</initialOperation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -40,6 +42,7 @@
import org.eclipse.sirius.diagram.description.filter.FilterDescription;
import org.eclipse.sirius.diagram.ui.business.api.helper.graphicalfilters.CompositeFilterApplicationBuilder;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.eclipse.sirius.viewpoint.description.DAnnotation;
import org.eclipse.swt.widgets.Display;
import org.polarsys.capella.common.ef.command.AbstractCommand;
Expand Down Expand Up @@ -804,48 +807,89 @@ public String getTitleBockCellLabel(DAnnotation cell) {
return cell.getDetails().get(TitleBlockHelper.CONTENT);
}

/**
* show or hide a Title Block depending on given type (DIAGRAM_TITLE_BLOCK or ELEMENT_TITLE_BLOCK). selectedTypes are
* the elements that shall be displayed
*
* @param elementView
* @param selectedTitleBlocks
* @param type
* @return String the label of the content cell
*/
public EObject showHideTitleBlocks(final EObject elementView, Collection<DAnnotation> selectedTitleBlocks) {
DDiagram diagram = CapellaServices.getService().getDiagramContainer(elementView);
Map<DAnnotation, DDiagramElement> existingTitleBlocks = new HashMap<>();
if (elementView instanceof EdgeTarget) {
// we want to show/hide the Title Block associated to elementView
List<DAnnotation> elementTitleBlocks = getAssociatedElementTitleBlocks((EdgeTarget) elementView);
elementTitleBlocks.stream().forEach(
tb -> existingTitleBlocks.put(tb, DiagramServices.getDiagramServices().getDiagramElement(diagram, tb)));
public EObject showHideTitleBlocks(EObject targetView, Collection<DAnnotation> titleBlockUserSelection) {

DDiagram diagram = CapellaServices.getService().getDiagramContainer(targetView);
Map<DAnnotation, Collection<DSemanticDecorator>> existingTitleBlocksToViews = Collections.emptyMap();

if (targetView instanceof EdgeTarget) {
existingTitleBlocksToViews = getTitleBLocksToViewsMap((EdgeTarget) targetView, diagram);
} else {
// we want to show/hide one or more Title Blocks in the diagram
for (DDiagramElement aContainer : diagram.getDiagramElements()) {
if ((aContainer.getTarget() instanceof DAnnotation)
&& TitleBlockHelper.isTitleBlock((DAnnotation) aContainer.getTarget())) {
DAnnotation annotation = (DAnnotation) aContainer.getTarget();
if (annotation.getSource() != null)
existingTitleBlocks.put(annotation, aContainer);
existingTitleBlocksToViews = getTitleBLocksToViewsMap(diagram);
}

hideTitleBlocks(titleBlockUserSelection, existingTitleBlocksToViews);

showTitleBlocks(targetView, diagram, titleBlockUserSelection, existingTitleBlocksToViews);

return targetView;
}

private Map<DAnnotation, Collection<DSemanticDecorator>> getTitleBLocksToViewsMap(EdgeTarget targetView,
DDiagram diagram) {
DiagramServices diagramServices = DiagramServices.getDiagramServices();
Map<DAnnotation, Collection<DSemanticDecorator>> existingTitleBlocksToViews = new HashMap<>();

List<DAnnotation> associatedTitleBlocks = getAssociatedElementTitleBlocks(targetView);
for (DAnnotation titleBLock : associatedTitleBlocks) {
Collection<DSemanticDecorator> titleBlockViews = diagramServices.getDiagramElements(diagram, titleBLock);
existingTitleBlocksToViews.put(titleBLock, titleBlockViews);
}

return existingTitleBlocksToViews;
}

private Map<DAnnotation, Collection<DSemanticDecorator>> getTitleBLocksToViewsMap(DDiagram diagram) {
Map<DAnnotation, Collection<DSemanticDecorator>> existingTitleBlocksToViews = new HashMap<>();

for (DDiagramElement diagramElement : diagram.getDiagramElements()) {
EObject target = diagramElement.getTarget();
if (target instanceof DAnnotation) {
DAnnotation annotation = (DAnnotation) target;
if (TitleBlockHelper.isTitleBlock(annotation) && annotation.getSource() != null) {
existingTitleBlocksToViews.computeIfAbsent(annotation, key -> new HashSet<>()).add(diagramElement);
}
}
}

for (Entry<DAnnotation, DDiagramElement> me : existingTitleBlocks.entrySet()) {
if (!selectedTitleBlocks.contains(me.getKey())) {
DiagramServices.getDiagramServices().removeContainerView(me.getValue());
return existingTitleBlocksToViews;
}

private void hideTitleBlocks(Collection<DAnnotation> titleBlockUserSelection,
Map<DAnnotation, Collection<DSemanticDecorator>> existingTitleBlocksToViews) {

DiagramServices diagramServices = DiagramServices.getDiagramServices();

for (Entry<DAnnotation, Collection<DSemanticDecorator>> existingEntry : existingTitleBlocksToViews.entrySet()) {
DAnnotation existingTitleBlock = existingEntry.getKey();

if (!titleBlockUserSelection.contains(existingTitleBlock)) {
Collection<DSemanticDecorator> titleBlockViews = existingEntry.getValue();

for (DSemanticDecorator view : titleBlockViews) {
if (view instanceof DEdge) {
diagramServices.removeEdgeView((DEdge) view);
} else {
diagramServices.removeContainerView(view);
}
}
}
}
for (DAnnotation tb : selectedTitleBlocks) {
if (!existingTitleBlocks.containsKey(tb)) {
createTitleBlockView(tb, diagram, elementView);
checkTitleBlocksFilters(diagram, TitleBlockHelper.isDiagramTitleBlock(tb) ? TitleBlockHelper.DIAGRAM_TITLE_BLOCK
: TitleBlockHelper.ELEMENT_TITLE_BLOCK);
}

private void showTitleBlocks(EObject targetView, DDiagram diagram, Collection<DAnnotation> titleBlockUserSelection,
Map<DAnnotation, Collection<DSemanticDecorator>> existingTitleBlocksToViews) {

for (DAnnotation selectedTitleBLock : titleBlockUserSelection) {
if (!existingTitleBlocksToViews.containsKey(selectedTitleBLock)) {
String titleBlockType = TitleBlockHelper.isDiagramTitleBlock(selectedTitleBLock)
? TitleBlockHelper.DIAGRAM_TITLE_BLOCK
: TitleBlockHelper.ELEMENT_TITLE_BLOCK;

createTitleBlockView(selectedTitleBLock, diagram, targetView);
checkTitleBlocksFilters(diagram, titleBlockType);
}
}
return elementView;
}

/**
Expand Down

0 comments on commit d7173b4

Please sign in to comment.