Skip to content

Commit

Permalink
[cleanup] Remove Option/Options dependencies from GMFHelper
Browse files Browse the repository at this point in the history
All classes, using methods from GMFHelper with Option as return type,
have also been modified.
  • Loading branch information
lredor committed Sep 11, 2024
1 parent 7af7711 commit feb298f
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 121 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013, 2021 THALES GLOBAL SERVICES and others.
* Copyright (c) 2013, 2024 THALES GLOBAL SERVICES and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -12,13 +12,14 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.model.business.internal.query;

import java.util.Optional;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.sirius.diagram.DDiagramElementContainer;
import org.eclipse.sirius.diagram.DNodeContainer;
import org.eclipse.sirius.diagram.FlatContainerStyle;
import org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.base.Options;
import org.eclipse.sirius.viewpoint.description.style.LabelBorderStyleDescription;
import org.eclipse.sirius.viewpoint.description.style.StyleDescription;

Expand Down Expand Up @@ -94,14 +95,14 @@ public boolean isRegionInVerticalStack() {
*
* @return an {@link Option} with the found label border style if it exists.
*/
public Option<LabelBorderStyleDescription> getLabelBorderStyle() {
public Optional<LabelBorderStyleDescription> getLabelBorderStyle() {
if (container.getStyle() instanceof FlatContainerStyle) {
StyleDescription description = container.getStyle().getDescription();
if (description instanceof FlatContainerStyleDescription) {
FlatContainerStyleDescription fcsd = (FlatContainerStyleDescription) description;
return Options.newSome(fcsd.getLabelBorderStyle());
return Optional.ofNullable(fcsd.getLabelBorderStyle());
}
}
return Options.newNone();
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2018 THALES GLOBAL SERVICES and others.
* Copyright (c) 2012, 2024 THALES GLOBAL SERVICES and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.ui.business.internal.command;

import java.util.Optional;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
Expand All @@ -33,7 +35,6 @@
import org.eclipse.sirius.diagram.ui.internal.refresh.GMFHelper;
import org.eclipse.sirius.diagram.ui.provider.Messages;
import org.eclipse.sirius.diagram.ui.tools.internal.util.GMFNotationUtilities;
import org.eclipse.sirius.ext.base.Option;

/**
* Controls the movement of source and target edge anchor. Use to move vertical
Expand Down Expand Up @@ -92,8 +93,8 @@ protected void setComplementaryData(boolean sourceAnchorChanged, boolean targetA
} else {
// We are in reconnection (compute the sourceRefPoint using
// GMF model data)
Option<Rectangle> optionalSourceBounds = GMFHelper.getAbsoluteBounds(edge.getSource());
if (optionalSourceBounds.some()) {
Optional<Rectangle> optionalSourceBounds = GMFHelper.getAbsoluteBounds(edge.getSource());
if (optionalSourceBounds.isPresent()) {
sourceBounds = optionalSourceBounds.get();
}
}
Expand All @@ -117,8 +118,8 @@ protected void setComplementaryData(boolean sourceAnchorChanged, boolean targetA
} else {
// We are in reconnection (compute the sourceRefPoint using
// GMF model data)
Option<Rectangle> optionalTargetBounds = GMFHelper.getAbsoluteBounds(edge.getTarget());
if (optionalTargetBounds.some()) {
Optional<Rectangle> optionalTargetBounds = GMFHelper.getAbsoluteBounds(edge.getTarget());
if (optionalTargetBounds.isPresent()) {
targetBounds = optionalTargetBounds.get();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2022 THALES GLOBAL SERVICES and others.
* Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -13,6 +13,7 @@
package org.eclipse.sirius.diagram.ui.edit.api.part;

import java.util.Iterator;
import java.util.Optional;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.draw2d.IFigure;
Expand Down Expand Up @@ -59,7 +60,6 @@
import org.eclipse.sirius.diagram.ui.tools.api.layout.LayoutUtils;
import org.eclipse.sirius.diagram.ui.tools.api.policy.CompoundEditPolicy;
import org.eclipse.sirius.diagram.ui.tools.internal.ui.NoCopyDragEditPartsTrackerEx;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.gmf.runtime.diagram.ui.tools.RubberbandDragTracker;
import org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures.LabelBorderStyleIds;
import org.eclipse.sirius.viewpoint.description.style.LabelBorderStyleDescription;
Expand Down Expand Up @@ -267,8 +267,8 @@ protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
private boolean hasFullLabelBorder() {
EObject element = resolveSemanticElement();
if (element instanceof DDiagramElementContainer) {
Option<LabelBorderStyleDescription> labelBorderStyle = new DDiagramElementContainerExperimentalQuery((DDiagramElementContainer) element).getLabelBorderStyle();
return labelBorderStyle.some() && LabelBorderStyleIds.LABEL_FULL_BORDER_STYLE_FOR_CONTAINER_ID.equals(labelBorderStyle.get().getId());
Optional<LabelBorderStyleDescription> labelBorderStyle = new DDiagramElementContainerExperimentalQuery((DDiagramElementContainer) element).getLabelBorderStyle();
return labelBorderStyle.isPresent() && LabelBorderStyleIds.LABEL_FULL_BORDER_STYLE_FOR_CONTAINER_ID.equals(labelBorderStyle.get().getId());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2022 THALES GLOBAL SERVICES and others.
* Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -95,8 +96,6 @@
import org.eclipse.sirius.diagram.ui.tools.internal.layout.LayoutUtil;
import org.eclipse.sirius.diagram.ui.tools.internal.util.EditPartQuery;
import org.eclipse.sirius.diagram.ui.tools.internal.util.NotificationQuery;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.base.Options;
import org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures.AlphaDropShadowBorder;
import org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures.SiriusDefaultSizeNodeFigure;
import org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures.SiriusWrapLabel;
Expand Down Expand Up @@ -183,7 +182,7 @@ private List<AbstractDiagramElementContainerEditPart> getBrotherRegionParts() {
EditPart editPart = this;
//@formatter:off
@SuppressWarnings("unchecked")
List<AbstractDiagramElementContainerEditPart> regionParts = (List<AbstractDiagramElementContainerEditPart>) getParent().getChildren().stream()
List<AbstractDiagramElementContainerEditPart> regionParts = getParent().getChildren().stream()
.filter(ed -> ed instanceof AbstractDiagramElementContainerEditPart && !ed.equals(editPart))
.map(AbstractDiagramElementContainerEditPart.class::cast)
.collect(Collectors.toList());
Expand Down Expand Up @@ -491,6 +490,7 @@ public Dimension getDefaultDimension() {
* @return the default figure dimension of this edit part
* @deprecated Only here as security if user activates {@link LayoutUtil#isArrangeAtOpeningChangesDisabled()}.
*/
@Deprecated
public Dimension oldGetDefaultDimension() {
DDiagramElement dde = resolveDiagramElement();
Dimension defaultSize = LayoutUtils.NEW_DEFAULT_CONTAINER_DIMENSION;
Expand All @@ -513,8 +513,8 @@ protected NodeFigure createNodePlate() {
NodeFigure result;
DDiagramElement dde = resolveDiagramElement();
Dimension defaultSize = getDefaultDimension();
Option<LabelBorderStyleDescription> getLabelBorderStyle = getLabelBorderStyle(dde);
if (getLabelBorderStyle.some()) {
Optional<LabelBorderStyleDescription> getLabelBorderStyle = getLabelBorderStyle(dde);
if (getLabelBorderStyle.isPresent()) {
result = new ContainerWithTitleBlockFigure(getMapMode().DPtoLP(defaultSize.width), getMapMode().DPtoLP(defaultSize.height), dde, getLabelBorderStyle.get());
} else {
result = new SiriusDefaultSizeNodeFigure(getMapMode().DPtoLP(defaultSize.width), getMapMode().DPtoLP(defaultSize.height));
Expand All @@ -523,11 +523,11 @@ protected NodeFigure createNodePlate() {
return result;
}

private Option<LabelBorderStyleDescription> getLabelBorderStyle(DStylizable viewNode) {
private Optional<LabelBorderStyleDescription> getLabelBorderStyle(DStylizable viewNode) {
if (viewNode instanceof DDiagramElementContainer) {
return new DDiagramElementContainerExperimentalQuery((DDiagramElementContainer) viewNode).getLabelBorderStyle();
}
return Options.newNone();
return Optional.empty();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2023 THALES GLOBAL SERVICES and others.
* Copyright (c) 2009, 2024 THALES GLOBAL SERVICES and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -221,8 +221,8 @@ public IFigure createFigure() {
*/
protected void configureBorder(ResizableCompartmentFigure rcf) {
boolean shouldHaveBorder = isRegionContainerCompartment();
Option<LabelBorderStyleDescription> labelBorderStyle = getLabelBorderStyle();
if (labelBorderStyle.some()) {
Optional<LabelBorderStyleDescription> labelBorderStyle = getLabelBorderStyle();
if (labelBorderStyle.isPresent()) {
shouldHaveBorder = shouldHaveBorder || LabelBorderStyleIds.LABEL_FULL_BORDER_STYLE_FOR_CONTAINER_ID.equals(labelBorderStyle.get().getId());
}

Expand Down Expand Up @@ -266,8 +266,8 @@ protected void configureScrollPaneBorder(ScrollPane scrollPane, ContainerStyle o
}

boolean fullLabelBorder = false;
Option<LabelBorderStyleDescription> labelBorderStyle = getLabelBorderStyle();
if (labelBorderStyle.some()) {
Optional<LabelBorderStyleDescription> labelBorderStyle = getLabelBorderStyle();
if (labelBorderStyle.isPresent()) {
fullLabelBorder = LabelBorderStyleIds.LABEL_FULL_BORDER_STYLE_FOR_CONTAINER_ID.equals(labelBorderStyle.get().getId());
}

Expand Down Expand Up @@ -319,12 +319,12 @@ private boolean isCollapsed() {
return style == null ? false : style.isCollapsed();
}

private Option<LabelBorderStyleDescription> getLabelBorderStyle() {
private Optional<LabelBorderStyleDescription> getLabelBorderStyle() {
EObject element = resolveSemanticElement();
if (element instanceof DDiagramElementContainer) {
return new DDiagramElementContainerExperimentalQuery((DDiagramElementContainer) element).getLabelBorderStyle();
}
return Options.newNone();
return Optional.empty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2021 THALES GLOBAL SERVICES and others.
* Copyright (c) 2011, 2024 THALES GLOBAL SERVICES and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -68,7 +68,6 @@
import org.eclipse.sirius.diagram.ui.internal.edit.policies.RegionCollapseAwarePropertyHandlerEditPolicy;
import org.eclipse.sirius.diagram.ui.internal.operation.ComparisonHelper;
import org.eclipse.sirius.diagram.ui.tools.api.requests.RequestConstants;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures.LabelBorderStyleIds;
import org.eclipse.sirius.viewpoint.DRepresentationElement;
import org.eclipse.sirius.viewpoint.description.RepresentationElementMapping;
Expand Down Expand Up @@ -214,8 +213,8 @@ private boolean isLabelHidden() {
private boolean hasLabelBorderStyle() {
EObject element = resolveSemanticElement();
if (element instanceof DDiagramElementContainer) {
Option<LabelBorderStyleDescription> labelBorderStyle = new DDiagramElementContainerExperimentalQuery((DDiagramElementContainer) element).getLabelBorderStyle();
return labelBorderStyle.some() && !LabelBorderStyleIds.LABEL_FULL_BORDER_STYLE_FOR_CONTAINER_ID.equals(labelBorderStyle.get().getId());
Optional<LabelBorderStyleDescription> labelBorderStyle = new DDiagramElementContainerExperimentalQuery((DDiagramElementContainer) element).getLabelBorderStyle();
return labelBorderStyle.isPresent() && !LabelBorderStyleIds.LABEL_FULL_BORDER_STYLE_FOR_CONTAINER_ID.equals(labelBorderStyle.get().getId());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2020 THALES GLOBAL SERVICES and others.
* Copyright (c) 2014, 2024 THALES GLOBAL SERVICES and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -58,8 +58,6 @@
import org.eclipse.sirius.diagram.ui.internal.refresh.GMFHelper;
import org.eclipse.sirius.diagram.ui.tools.internal.routers.RectilinearEdgeUtil;
import org.eclipse.sirius.diagram.ui.tools.internal.util.GMFNotationUtilities;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.base.Options;
import org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper;
import org.eclipse.ui.IEditorPart;

Expand Down Expand Up @@ -207,10 +205,10 @@ private void centerEdgeEnds(CenteringStyle center, Routing routingValue) {

// We get the edge source and target nodes absolute bounds to
// compute absolute anchors coordinates
Option<Rectangle> sourceBounds = getAbsoluteSourceBounds(edgeSourceView);
Option<Rectangle> targetBounds = getAbsoluteTargetBounds(edgeTargetView);
Optional<Rectangle> sourceBounds = getAbsoluteSourceBounds(edgeSourceView);
Optional<Rectangle> targetBounds = getAbsoluteTargetBounds(edgeTargetView);

if (sourceBounds.some() && targetBounds.some()) {
if (sourceBounds.isPresent() && targetBounds.isPresent()) {

// Calculate the existing anchors absolute location
retrieveAndSetExistingAnchorsAbsoluteLocation(sourceBounds.get(), targetBounds.get());
Expand Down Expand Up @@ -249,7 +247,7 @@ private void centerEdgeEnds(CenteringStyle center, Routing routingValue) {
* true if it represents the edge source, false otherwise.
* @return the absolute bounds.
*/
private Option<Rectangle> getAbsoluteBounds(View gmfView, boolean isSource) {
private Optional<Rectangle> getAbsoluteBounds(View gmfView, boolean isSource) {
if (connectionEditPart != null) {
EditPart editPart = null;
if (isSource) {
Expand All @@ -258,24 +256,24 @@ private Option<Rectangle> getAbsoluteBounds(View gmfView, boolean isSource) {
editPart = connectionEditPart.getTarget();
}
if (editPart instanceof GraphicalEditPart) {
return Options.newSome(GraphicalHelper.getAbsoluteBoundsIn100Percent((GraphicalEditPart) editPart));
return Optional.ofNullable(GraphicalHelper.getAbsoluteBoundsIn100Percent((GraphicalEditPart) editPart));
}
}
return GMFHelper.getAbsoluteBounds(gmfView, true, true);
}

private Option<Rectangle> getAbsoluteSourceBounds(View edgeSourceView) {
Option<Rectangle> option = getAbsoluteBounds(edgeSourceView, true);
if (sourceFigureSize != null && option.some()) {
private Optional<Rectangle> getAbsoluteSourceBounds(View edgeSourceView) {
Optional<Rectangle> option = getAbsoluteBounds(edgeSourceView, true);
if (sourceFigureSize != null && option.isPresent()) {
Rectangle rectangle = option.get();
rectangle.setSize(sourceFigureSize);
}
return option;
}

private Option<Rectangle> getAbsoluteTargetBounds(View edgeTargetView) {
Option<Rectangle> option = getAbsoluteBounds(edgeTargetView, false);
if (targetFigureSize != null && option.some()) {
private Optional<Rectangle> getAbsoluteTargetBounds(View edgeTargetView) {
Optional<Rectangle> option = getAbsoluteBounds(edgeTargetView, false);
if (targetFigureSize != null && option.isPresent()) {
Rectangle rectangle = option.get();
rectangle.setSize(targetFigureSize);
}
Expand Down Expand Up @@ -517,7 +515,7 @@ private void setConnectionIfNull() {
if (connection != null || !useFigure) {
return;
}
Option<GraphicalEditPart> option = Options.newNone();
Optional<GraphicalEditPart> option = Optional.empty();
final IEditorPart editorPart = EclipseUIUtil.getActiveEditor();
if (editorPart instanceof DiagramEditor) {
option = GMFHelper.getGraphicalEditPart(edge, (DiagramEditor) editorPart);
Expand All @@ -533,14 +531,14 @@ private void setConnectionIfNull() {
if (object instanceof DiagramEditor) {
option = GMFHelper.getGraphicalEditPart(edge, (DiagramEditor) object);
}
if (option.some()) {
if (option.isPresent()) {
break;
}
}

}

if (option.some()) {
if (option.isPresent()) {
GraphicalEditPart editPart = option.get();
if (editPart instanceof DEdgeEditPart) {
connectionEditPart = (DEdgeEditPart) editPart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import org.eclipse.core.runtime.IAdaptable;
Expand Down Expand Up @@ -576,8 +577,8 @@ private LayoutDataResult updateAbstractDNode_ownedBorderedNodes_Bounds(View crea

if (size == null) {
if (new ViewQuery(createdView).isForNameEditPart()) {
Option<Rectangle> optionalRect = GMFHelper.getAbsoluteBounds(createdView);
if (optionalRect.some()) {
Optional<Rectangle> optionalRect = GMFHelper.getAbsoluteBounds(createdView);
if (optionalRect.isPresent()) {
size = optionalRect.get().getSize();
}
}
Expand Down
Loading

0 comments on commit feb298f

Please sign in to comment.