Skip to content

Commit

Permalink
[146] Remove Guava dependency in oes.editor.diagram
Browse files Browse the repository at this point in the history
Bug: #146
Signed-off-by: Pierre-Charles David <[email protected]>
  • Loading branch information
pcdavid committed Apr 16, 2024
1 parent 257a08f commit 5f5e1db
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.sirius.editor.diagram;singleton:=true
Bundle-Version: 7.4.1.qualifier
Bundle-Vendor: %providerName
Require-Bundle: com.google.guava;bundle-version="27.0",
org.eclipse.core.runtime;bundle-version="3.8.0",
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0",
org.eclipse.emf.edit.ui;bundle-version="2.3.1",
org.eclipse.sirius.common;bundle-version="7.4.1",
org.eclipse.sirius.common.ui;bundle-version="7.4.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2018 THALES GLOBAL SERVICES.
* 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,9 +15,9 @@
// Start of user code imports

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
Expand All @@ -36,9 +36,6 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;

// End of user code imports

/**
Expand Down Expand Up @@ -153,8 +150,7 @@ private boolean isActivated() {
protected List<?> getChoiceOfValues(List<?> currentValues) {
List<?> choiceOfValues = super.getChoiceOfValues(currentValues);
removeUnrelatedMappings(choiceOfValues);
Collection<?> collection = Collections2.filter(choiceOfValues, Predicates.instanceOf(AbstractNodeMapping.class));
return new ArrayList<Object>(collection);
return choiceOfValues.stream().filter(AbstractNodeMapping.class::isInstance).collect(Collectors.toCollection(ArrayList::new));
}

private void removeUnrelatedMappings(List<?> choiceOfValues) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2018 THALES GLOBAL SERVICES.
* Copyright (c) 2007, 2024 THALES GLOBAL SERVICES.
* 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,9 +15,9 @@
// Start of user code imports

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
Expand All @@ -36,9 +36,6 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;

// End of user code imports

/**
Expand Down Expand Up @@ -153,8 +150,7 @@ private boolean isActivated() {
protected List<?> getChoiceOfValues(List<?> currentValues) {
List<?> choiceOfValues = super.getChoiceOfValues(currentValues);
removeUnrelatedMappings(choiceOfValues);
Collection<?> collection = Collections2.filter(choiceOfValues, Predicates.instanceOf(AbstractNodeMapping.class));
return new ArrayList<Object>(collection);
return choiceOfValues.stream().filter(AbstractNodeMapping.class::isInstance).collect(Collectors.toCollection(ArrayList::new));
}

private void removeUnrelatedMappings(List<?> choiceOfValues) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2018 THALES GLOBAL SERVICES.
* 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 @@ -17,6 +17,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;

import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
Expand All @@ -35,11 +36,6 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;

// End of user code imports

/**
Expand Down Expand Up @@ -129,11 +125,11 @@ protected List<?> getChoiceOfValues() {

// Start of user code choice of values
if (!values.isEmpty()) {
Predicate<Object> predicate = Predicates.or(Predicates.instanceOf(EdgeMapping.class), Predicates.instanceOf(EdgeMappingImport.class));
Predicate<Object> predicate = object -> object instanceof EdgeMapping || object instanceof EdgeMappingImport;
if (eObject instanceof CreateEdgeView) {
values = Lists.newArrayList(Iterables.filter(values, predicate));
values = values.stream().filter(predicate).toList();
} else if (eObject instanceof CreateView) {
values = Lists.newArrayList(Iterables.filter(values, Predicates.not(predicate)));
values = values.stream().filter(Predicate.not(predicate)).toList();
}
}
// End of user code choice of values
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 - 2010 THALES GLOBAL SERVICES.
* 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 @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.editor.properties.sections.tool.containerdropdescription;

import java.util.ArrayList;

// Start of user code imports

import java.util.Iterator;
Expand All @@ -35,10 +37,6 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.UnmodifiableIterator;

// End of user code imports

/**
Expand Down Expand Up @@ -106,9 +104,13 @@ protected boolean getSortChoice() {
*/
@Override
protected List getChoiceOfValues() {
UnmodifiableIterator<org.eclipse.sirius.diagram.description.DragAndDropTargetDescription> filter = Iterators.filter(eObject.eResource().getResourceSet().getAllContents(),
DragAndDropTargetDescription.class);
return Lists.newArrayList(filter);
List<Object> result = new ArrayList<>();
eObject.eResource().getResourceSet().getAllContents().forEachRemaining(notifier -> {
if (notifier instanceof DragAndDropTargetDescription dndTarget) {
result.add(dndTarget);
}
});
return result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 - 2010 THALES GLOBAL SERVICES.
* 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 @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.editor.properties.sections.tool.deleteelementdescription;

import java.util.ArrayList;

// Start of user code imports

import java.util.Iterator;
Expand All @@ -25,6 +27,7 @@
import org.eclipse.emf.edit.domain.IEditingDomainProvider;
import org.eclipse.sirius.diagram.description.DescriptionPackage;
import org.eclipse.sirius.diagram.description.DiagramElementMapping;
import org.eclipse.sirius.diagram.description.DragAndDropTargetDescription;
import org.eclipse.sirius.diagram.description.tool.DeleteElementDescription;
import org.eclipse.sirius.editor.editorPlugin.SiriusEditor;
import org.eclipse.sirius.editor.properties.sections.common.AbstractEditorDialogWithListPropertySection;
Expand All @@ -35,10 +38,6 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.UnmodifiableIterator;

// End of user code imports

/**
Expand Down Expand Up @@ -106,8 +105,13 @@ protected boolean getSortChoice() {
*/
@Override
protected List getChoiceOfValues() {
UnmodifiableIterator<DiagramElementMapping> filter = Iterators.filter(eObject.eResource().getResourceSet().getAllContents(), DiagramElementMapping.class);
return Lists.newArrayList(filter);
List<Object> result = new ArrayList<>();
eObject.eResource().getResourceSet().getAllContents().forEachRemaining(notifier -> {
if (notifier instanceof DiagramElementMapping mapping) {
result.add(mapping);
}
});
return result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 - 2010 THALES GLOBAL SERVICES.
* 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 @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.editor.properties.sections.tool.directeditlabel;

import java.util.ArrayList;

// Start of user code imports

import java.util.Iterator;
Expand All @@ -35,10 +37,6 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.UnmodifiableIterator;

// End of user code imports

/**
Expand Down Expand Up @@ -135,8 +133,13 @@ protected boolean getSortChoice() {
*/
@Override
protected List getChoiceOfValues() {
UnmodifiableIterator<DiagramElementMapping> filter = Iterators.filter(eObject.eResource().getResourceSet().getAllContents(), DiagramElementMapping.class);
return Lists.newArrayList(filter);
List<Object> result = new ArrayList<>();
eObject.eResource().getResourceSet().getAllContents().forEachRemaining(notifier -> {
if (notifier instanceof DiagramElementMapping mapping) {
result.add(mapping);
}
});
return result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 - 2010 THALES GLOBAL SERVICES.
* 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 @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.editor.properties.sections.tool.reconnectedgedescription;

import java.util.ArrayList;

// Start of user code imports

import java.util.Iterator;
Expand All @@ -26,6 +28,7 @@
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.domain.IEditingDomainProvider;
import org.eclipse.sirius.diagram.description.DescriptionPackage;
import org.eclipse.sirius.diagram.description.DiagramElementMapping;
import org.eclipse.sirius.diagram.description.EdgeMapping;
import org.eclipse.sirius.diagram.description.tool.ReconnectEdgeDescription;
import org.eclipse.sirius.editor.editorPlugin.SiriusEditor;
Expand All @@ -37,10 +40,6 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.UnmodifiableIterator;

// End of user code imports

/**
Expand Down Expand Up @@ -108,8 +107,13 @@ protected boolean getSortChoice() {
*/
@Override
protected List getChoiceOfValues() {
UnmodifiableIterator<EdgeMapping> filter = Iterators.filter(eObject.eResource().getResourceSet().getAllContents(), EdgeMapping.class);
return Lists.newArrayList(filter);
List<Object> result = new ArrayList<>();
eObject.eResource().getResourceSet().getAllContents().forEachRemaining(notifier -> {
if (notifier instanceof EdgeMapping mapping) {
result.add(mapping);
}
});
return result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2015 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 All @@ -15,6 +15,7 @@
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Collectors;

import org.eclipse.emf.edit.command.CommandParameter;
import org.eclipse.jface.viewers.ISelection;
Expand All @@ -24,14 +25,10 @@
import org.eclipse.sirius.editor.tools.internal.menu.refactoring.RefactoringMenu;
import org.eclipse.ui.IEditorPart;

import com.google.common.base.Predicate;
import com.google.common.collect.Sets;

/**
* The menu for the refactoring actions.
*
* @author cbrun
*
*/
public class DiagramRefactoringMenu extends AbstractMenuBuilder {
@Override
Expand All @@ -58,12 +55,7 @@ private Collection generateRefactoringActions(final ISelection selection, final
allActions.add(new EdgeMappingRefactoringAction(editor, selection));

// We only add to the menu the actions that have a valid selection
return Sets.filter(allActions, new Predicate<AbstractEObjectRefactoringAction>() {

public boolean apply(AbstractEObjectRefactoringAction candidateAction) {
return candidateAction.isSelectionValid();
}
});
return allActions.stream().filter(AbstractEObjectRefactoringAction::isSelectionValid).collect(Collectors.toSet());
}

@Override
Expand Down

0 comments on commit 5f5e1db

Please sign in to comment.