diff options
15 files changed, 141 insertions, 114 deletions
diff --git a/plugins/org.eclipse.eef.common/META-INF/MANIFEST.MF b/plugins/org.eclipse.eef.common/META-INF/MANIFEST.MF index b2273391f..a677e1d86 100644 --- a/plugins/org.eclipse.eef.common/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.eef.common/META-INF/MANIFEST.MF @@ -14,6 +14,5 @@ Export-Package: org.eclipse.eef.common.api;version="2.0.0", Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.0.0,4.0.0)", org.eclipse.emf.common;bundle-version="[2.8.0,3.0.0)", org.eclipse.emf.ecore;bundle-version="[2.8.0,3.0.0)" -Import-Package: com.google.common.collect;version="[15.0.0,16.0.0)" Bundle-ActivationPolicy: lazy Bundle-Activator: org.eclipse.eef.common.internal.EEFCommonPlugin$Implementation diff --git a/plugins/org.eclipse.eef.common/src/org/eclipse/eef/common/api/utils/Util.java b/plugins/org.eclipse.eef.common/src/org/eclipse/eef/common/api/utils/Util.java index 66dc27a11..6dbf3197d 100644 --- a/plugins/org.eclipse.eef.common/src/org/eclipse/eef/common/api/utils/Util.java +++ b/plugins/org.eclipse.eef.common/src/org/eclipse/eef/common/api/utils/Util.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Obeo. + * Copyright (c) 2016, 2017 Obeo. * 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 @@ -10,12 +10,10 @@ *******************************************************************************/ package org.eclipse.eef.common.api.utils; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - +import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.List; +import java.util.stream.Collectors; /** * Shared utility methods. @@ -58,7 +56,7 @@ public final class Util { } /** - * Returns the given object as an iterable and filer it with the given type. If the object is a single object, the + * Returns the given object as a collection and filter it with the given type. If the object is a single object, the * we will return a collection containing said object, it the object is already a collection, we will return a new * collection with all its elements. * @@ -68,17 +66,26 @@ public final class Util { * The class of the result wanted * @param <T> * The type of the result wanted - * @return An iterable + * @return A collection */ - public static <T> Iterable<T> asIterable(Object rawValue, Class<T> clazz) { - final Iterable<T> result; + public static <T> Collection<T> asCollection(Object rawValue, Class<T> clazz) { + final Collection<T> result; if (rawValue instanceof Collection<?>) { - result = Lists.newArrayList(Iterables.filter((Collection<?>) rawValue, clazz)); + // @formatter:off + result = ((Collection<?>) rawValue).stream() + .filter(clazz::isInstance) + .map(clazz::cast) + .collect(Collectors.toList()); + // @formatter:on } else if (clazz.isInstance(rawValue)) { result = Collections.singleton(clazz.cast(rawValue)); } else if (rawValue != null && rawValue.getClass().isArray()) { - List<Object> list = Lists.newArrayList((Object[]) rawValue); - result = Lists.newArrayList(Iterables.filter(list, clazz)); + // @formatter:off + result = Arrays.stream((Object[]) rawValue) + .filter(clazz::isInstance) + .map(clazz::cast) + .collect(Collectors.toList()); + // @formatter:on } else { result = Collections.emptySet(); } diff --git a/plugins/org.eclipse.eef.core/META-INF/MANIFEST.MF b/plugins/org.eclipse.eef.core/META-INF/MANIFEST.MF index 89b49dad5..9321f2776 100644 --- a/plugins/org.eclipse.eef.core/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.eef.core/META-INF/MANIFEST.MF @@ -9,9 +9,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.0.0,4.0.0)", org.eclipse.emf.ecore;bundle-version="[2.8.0,3.0.0)", org.eclipse.eef.common;bundle-version="[2.0.0,3.0.0)", org.eclipse.emf.edit;bundle-version="[2.8.0,3.0.0)" -Import-Package: com.google.common.base;version="[15.0.0,16.0.0)", - com.google.common.collect;version="[15.0.0,16.0.0)", - org.eclipse.eef;version="[2.0.0,3.0.0)", +Import-Package: org.eclipse.eef;version="[2.0.0,3.0.0)", org.eclipse.sirius.common.interpreter.api;version="1.0.0" Export-Package: org.eclipse.eef.core.api;version="2.0.0", org.eclipse.eef.core.api.controllers;version="2.0.0", diff --git a/plugins/org.eclipse.eef.core/build.properties b/plugins/org.eclipse.eef.core/build.properties index 778d60958..ba7344421 100644 --- a/plugins/org.eclipse.eef.core/build.properties +++ b/plugins/org.eclipse.eef.core/build.properties @@ -1,4 +1,4 @@ -# Copyright (c) 2015 Obeo. +# Copyright (c) 2015, 2017 Obeo. # 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 @@ -12,5 +12,4 @@ bin.includes = META-INF/,\ about.html,\ plugin.properties javacProjectSettings = true -additional.bundles = com.google.guava src.includes = about.html diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/DomainClassPredicate.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/DomainClassPredicate.java index 6470c4f2e..1ae4a49c9 100644 --- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/DomainClassPredicate.java +++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/DomainClassPredicate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2016 Obeo. + * Copyright (c) 2015, 2017 Obeo. * 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 @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.eef.core.internal; -import com.google.common.base.Predicate; +import java.util.function.Predicate; import org.eclipse.eef.common.api.utils.Util; import org.eclipse.eef.core.api.IEEFDomainClassTester; @@ -47,7 +47,7 @@ public class DomainClassPredicate implements Predicate<Object> { } @Override - public boolean apply(Object input) { + public boolean test(Object input) { if (input instanceof EObject) { return this.domainClassTester.eInstanceOf((EObject) input, domainClassName); } diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFPageImpl.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFPageImpl.java index 88df54891..44e1c38e7 100644 --- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFPageImpl.java +++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFPageImpl.java @@ -10,9 +10,8 @@ *******************************************************************************/ package org.eclipse.eef.core.internal; -import com.google.common.collect.Iterables; - import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.function.Consumer; @@ -106,13 +105,12 @@ public class EEFPageImpl implements EEFPage { .evaluate(preconditionExpression); if (preconditionValid == null || preconditionValid.booleanValue()) { Consumer<Object> consumer = (value) -> { - DomainClassPredicate domainClassPredicate = new DomainClassPredicate(eefGroupDescription.getDomainClass(), domainClassTester); - Iterable<Object> iterable = Util.asIterable(value, Object.class); - Iterable<Object> objects = Iterables.filter(iterable, domainClassPredicate); - objects.forEach(object -> { - IVariableManager childVariableManager = EEFPageImpl.this.getVariableManager().createChild(); + Collection<Object> objectCollection = Util.asCollection(value, Object.class); + objectCollection.stream().filter(new DomainClassPredicate(eefGroupDescription.getDomainClass(), domainClassTester)) + .forEach(object -> { + IVariableManager childVariableManager = this.getVariableManager().createChild(); childVariableManager.put(EEFExpressionUtils.SELF, object); - EEFGroupImpl eefGroupImpl = new EEFGroupImpl(EEFPageImpl.this, eefGroupDescription, childVariableManager, interpreter); + EEFGroupImpl eefGroupImpl = new EEFGroupImpl(this, eefGroupDescription, childVariableManager, interpreter); this.eefGroups.add(eefGroupImpl); }); }; diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFViewImpl.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFViewImpl.java index 0cbd6b985..f442f0f80 100644 --- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFViewImpl.java +++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/EEFViewImpl.java @@ -10,12 +10,12 @@ *******************************************************************************/ package org.eclipse.eef.core.internal; -import com.google.common.collect.Iterables; - import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.function.Consumer; +import java.util.stream.Collectors; import org.eclipse.eef.EEFPageDescription; import org.eclipse.eef.EEFViewDescription; @@ -105,9 +105,9 @@ public class EEFViewImpl implements EEFView { .evaluate(preconditionExpression); if (preconditionValid == null || preconditionValid.booleanValue()) { Consumer<Object> consumer = (value) -> { - DomainClassPredicate domainClassPredicate = new DomainClassPredicate(eefPageDescription.getDomainClass(), domainClassTester); - Iterable<Object> iterable = Util.asIterable(value, Object.class); - Iterable<Object> objects = Iterables.filter(iterable, domainClassPredicate); + Collection<Object> objectCollection = Util.asCollection(value, Object.class); + List<Object> objects = objectCollection.stream() + .filter(new DomainClassPredicate(eefPageDescription.getDomainClass(), domainClassTester)).collect(Collectors.toList()); boolean isUnique = true; Iterator<Object> iterator = objects.iterator(); @@ -117,7 +117,7 @@ public class EEFViewImpl implements EEFView { if (isUnique && iterator.hasNext()) { isUnique = false; } - EEFPageImpl ePage = createPage(eefPageDescription, object, isUnique); + EEFPageImpl ePage = this.createPage(eefPageDescription, object, isUnique); ePage.initialize(); this.eefPages.add(ePage); } @@ -186,7 +186,7 @@ public class EEFViewImpl implements EEFView { // All your update process for EEFPages need to be updated. It's not simple in any way or shape, I know. for (final EEFPage eefPage : this.eefPages) { - Consumer<Object> pageConsumer = (value) -> Util.asIterable(value, Object.class).forEach(pageSemanticCandidate -> { + Consumer<Object> pageConsumer = (value) -> Util.asCollection(value, Object.class).forEach(pageSemanticCandidate -> { eefPage.getVariableManager().put(EEFExpressionUtils.SELF, pageSemanticCandidate); }); @@ -199,7 +199,7 @@ public class EEFViewImpl implements EEFView { for (final EEFGroup eefGroup : groups) { // FIXME We need only one semantic candidate, so we just take the last one available as self // as we did for the pages just before - Consumer<Object> groupConsumer = (value) -> Util.asIterable(value, Object.class).forEach(groupSemanticCandidate -> { + Consumer<Object> groupConsumer = (value) -> Util.asCollection(value, Object.class).forEach(groupSemanticCandidate -> { eefGroup.getVariableManager().put(EEFExpressionUtils.SELF, groupSemanticCandidate); }); diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFSelectController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFSelectController.java index 92fccc0d1..42e536247 100644 --- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFSelectController.java +++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFSelectController.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.eef.core.internal.controllers; -import com.google.common.collect.Iterators; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -101,7 +99,7 @@ public class EEFSelectController extends AbstractEEFWidgetController implements if (value instanceof Iterable<?>) { List<Object> candidates = new ArrayList<Object>(); - Iterators.addAll(candidates, ((Iterable<?>) value).iterator()); + ((Iterable<?>) value).forEach(candidates::add); Optional.ofNullable(this.newCandidatesConsumer).ifPresent(consumer -> { consumer.accept(candidates); diff --git a/plugins/org.eclipse.eef.ide.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.eef.ide.ui/META-INF/MANIFEST.MF index 42c4763aa..d5ee84517 100644 --- a/plugins/org.eclipse.eef.ide.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.eef.ide.ui/META-INF/MANIFEST.MF @@ -5,9 +5,7 @@ Bundle-SymbolicName: org.eclipse.eef.ide.ui;singleton:=true Bundle-Version: 2.0.0.qualifier Bundle-Vendor: %providerName Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Import-Package: com.google.common.base;version="15.0.0", - com.google.common.collect;version="15.0.0", - org.eclipse.sirius.common.interpreter.api;version="1.0.0" +Import-Package: org.eclipse.sirius.common.interpreter.api;version="1.0.0" Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.7.0,4.0.0)", org.eclipse.emf.common;bundle-version="[2.8.0,3.0.0)", org.eclipse.emf.ecore;bundle-version="[2.8.0,3.0.0)", diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFControlSwitch.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFControlSwitch.java index 0119e06f4..82833d79f 100644 --- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFControlSwitch.java +++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFControlSwitch.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Obeo. + * Copyright (c) 2016, 2017 Obeo. * 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 @@ -244,7 +244,7 @@ public class EEFControlSwitch { Object iterableExpressionResult = EvalFactory.of(this.interpreter, variableManager).logIfBlank(iterableEAttribute) .evaluate(iterableExpression); - for (Object object : Util.asIterable(iterableExpressionResult, Object.class)) { + for (Object object : Util.asCollection(iterableExpressionResult, Object.class)) { Map<String, Object> switchExpressionVariables = new HashMap<String, Object>(); switchExpressionVariables.put(EEFExpressionUtils.SELF, variableManager.getVariables().get(EEFExpressionUtils.SELF)); switchExpressionVariables.put(EEFExpressionUtils.INPUT, variableManager.getVariables().get(EEFExpressionUtils.INPUT)); diff --git a/plugins/org.eclipse.eef.properties.ui.legacy/META-INF/MANIFEST.MF b/plugins/org.eclipse.eef.properties.ui.legacy/META-INF/MANIFEST.MF index c87b5b0bc..7c1d538d1 100644 --- a/plugins/org.eclipse.eef.properties.ui.legacy/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.eef.properties.ui.legacy/META-INF/MANIFEST.MF @@ -10,8 +10,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", org.eclipse.ui;bundle-version="[3.0.0,4.0.0)", org.eclipse.ui.views.properties.tabbed;bundle-version="[3.5.0,4.0.0)", org.eclipse.eef.properties.ui;bundle-version="[2.0.0,3.0.0)", - org.eclipse.eef.common.ui;bundle-version="[2.0.0,3.0.0)", - com.google.guava;bundle-version="[11.0.2,22.0.0)" + org.eclipse.eef.common.ui;bundle-version="[2.0.0,3.0.0)" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Bundle-Localization: plugin diff --git a/plugins/org.eclipse.eef.properties.ui.legacy/src/org/eclipse/eef/properties/ui/legacy/internal/extension/impl/LegacyPropertyContributorRegistry.java b/plugins/org.eclipse.eef.properties.ui.legacy/src/org/eclipse/eef/properties/ui/legacy/internal/extension/impl/LegacyPropertyContributorRegistry.java index 37313007a..eb511a74f 100644 --- a/plugins/org.eclipse.eef.properties.ui.legacy/src/org/eclipse/eef/properties/ui/legacy/internal/extension/impl/LegacyPropertyContributorRegistry.java +++ b/plugins/org.eclipse.eef.properties.ui.legacy/src/org/eclipse/eef/properties/ui/legacy/internal/extension/impl/LegacyPropertyContributorRegistry.java @@ -10,12 +10,14 @@ *******************************************************************************/ package org.eclipse.eef.properties.ui.legacy.internal.extension.impl; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; - import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; import org.eclipse.eef.properties.ui.legacy.internal.extension.IItemDescriptor; import org.eclipse.eef.properties.ui.legacy.internal.extension.IItemRegistry; @@ -32,7 +34,7 @@ public class LegacyPropertyContributorRegistry implements IItemRegistry { /** * The map of the identifier of the description to the {@link IItemDescriptor}. */ - private Multimap<String, IItemDescriptor> id2descriptors = ArrayListMultimap.create(); + private Map<String, List<IItemDescriptor>> id2descriptors = new HashMap<>(); /** * Get property categories. @@ -40,14 +42,16 @@ public class LegacyPropertyContributorRegistry implements IItemRegistry { * @return List of categories */ public List<String> getPropertyCategories() { - List<String> legacyPropertyCategories = new ArrayList<String>(); - Collection<IItemDescriptor> values = this.id2descriptors.values(); - for (IItemDescriptor itemDescriptor : values) { - if (itemDescriptor instanceof LegacyPropertyContributorItemDescriptor) { - legacyPropertyCategories.addAll(((LegacyPropertyContributorItemDescriptor) itemDescriptor).getCategories()); - } - } - return legacyPropertyCategories; + // @formatter:off + return this.id2descriptors.values().stream() + .filter(Objects::nonNull) + .flatMap(List::stream) + .filter(LegacyPropertyContributorItemDescriptor.class::isInstance) + .map(LegacyPropertyContributorItemDescriptor.class::cast) + .map(LegacyPropertyContributorItemDescriptor::getCategories) + .flatMap(List::stream) + .collect(Collectors.toList()); + // @formatter:on } /** @@ -58,18 +62,20 @@ public class LegacyPropertyContributorRegistry implements IItemRegistry { * @return Type mapper */ public ITypeMapper getTypeMapper(String contributorId) { - Collection<IItemDescriptor> values = this.id2descriptors.values(); - for (IItemDescriptor itemDescriptor : values) { - if (itemDescriptor instanceof LegacyPropertyContributorItemDescriptor) { - if (contributorId != null && contributorId.equals(itemDescriptor.getId())) { - ITypeMapper legacyPropertyTypeMapper = ((LegacyPropertyContributorItemDescriptor) itemDescriptor).getTypeMapper(); - if (legacyPropertyTypeMapper != null) { - return legacyPropertyTypeMapper; - } - } - } - } - return null; + // @formatter:off + Collection<IItemDescriptor> values = this.id2descriptors.values().stream() + .filter(Objects::nonNull) + .flatMap(List::stream) + .collect(Collectors.toList()); + + return values.stream().filter(LegacyPropertyContributorItemDescriptor.class::isInstance) + .map(LegacyPropertyContributorItemDescriptor.class::cast) + .filter(itemDescriptor -> contributorId != null && contributorId.equals(itemDescriptor.getId())) + .map(LegacyPropertyContributorItemDescriptor::getTypeMapper) + .filter(Objects::nonNull) + .findFirst() + .orElse(null); + // @formatter:on } /** @@ -80,20 +86,20 @@ public class LegacyPropertyContributorRegistry implements IItemRegistry { * @return Section descriptor provider */ public ISectionDescriptorProvider getSectionDescriptorProvider(String contributorId) { + // @formatter:off + Collection<IItemDescriptor> values = this.id2descriptors.values().stream() + .filter(Objects::nonNull) + .flatMap(List::stream) + .collect(Collectors.toList()); - Collection<IItemDescriptor> values = this.id2descriptors.values(); - for (IItemDescriptor itemDescriptor : values) { - if (itemDescriptor instanceof LegacyPropertyContributorItemDescriptor) { - if (contributorId != null && contributorId.equals(itemDescriptor.getId())) { - ISectionDescriptorProvider legacyPropertySectionDescriptorProvider = ((LegacyPropertyContributorItemDescriptor) itemDescriptor) - .getSectionDescriptorProvider(); - if (legacyPropertySectionDescriptorProvider != null) { - return legacyPropertySectionDescriptorProvider; - } - } - } - } - return null; + return values.stream().filter(LegacyPropertyContributorItemDescriptor.class::isInstance) + .map(LegacyPropertyContributorItemDescriptor.class::cast) + .filter(itemDescriptor -> contributorId != null && contributorId.equals(itemDescriptor.getId())) + .map(LegacyPropertyContributorItemDescriptor::getSectionDescriptorProvider) + .filter(Objects::nonNull) + .findFirst() + .orElse(null); + // @formatter:on } /** @@ -103,11 +109,11 @@ public class LegacyPropertyContributorRegistry implements IItemRegistry { */ @Override public IItemDescriptor add(IItemDescriptor itemDescriptor) { - boolean result = this.id2descriptors.put(itemDescriptor.getId(), itemDescriptor); - if (result) { - return itemDescriptor; - } - return null; + List<IItemDescriptor> descriptors = this.id2descriptors.getOrDefault(itemDescriptor.getId(), new ArrayList<>()); + descriptors.add(itemDescriptor); + this.id2descriptors.put(itemDescriptor.getId(), descriptors); + + return itemDescriptor; } /** @@ -127,6 +133,6 @@ public class LegacyPropertyContributorRegistry implements IItemRegistry { */ @Override public boolean remove(String id) { - return !this.id2descriptors.removeAll(id).isEmpty(); + return Optional.ofNullable(this.id2descriptors.remove(id)).isPresent(); } } diff --git a/plugins/org.eclipse.eef.properties.ui.legacy/src/org/eclipse/eef/properties/ui/legacy/internal/extension/impl/LegacyPropertySectionRegistry.java b/plugins/org.eclipse.eef.properties.ui.legacy/src/org/eclipse/eef/properties/ui/legacy/internal/extension/impl/LegacyPropertySectionRegistry.java index 618b2e3fd..e5bbd1271 100644 --- a/plugins/org.eclipse.eef.properties.ui.legacy/src/org/eclipse/eef/properties/ui/legacy/internal/extension/impl/LegacyPropertySectionRegistry.java +++ b/plugins/org.eclipse.eef.properties.ui.legacy/src/org/eclipse/eef/properties/ui/legacy/internal/extension/impl/LegacyPropertySectionRegistry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Obeo. + * Copyright (c) 2015, 2017 Obeo. * 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 @@ -10,14 +10,14 @@ *******************************************************************************/ package org.eclipse.eef.properties.ui.legacy.internal.extension.impl; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; - import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; import org.eclipse.eef.properties.ui.api.IEEFSectionDescriptor; import org.eclipse.eef.properties.ui.api.IEEFTypeMapper; @@ -39,7 +39,7 @@ public class LegacyPropertySectionRegistry implements IItemRegistry { /** * The map of the identifier of the description to the {@link LegacyPropertySectionItemDescriptor}. */ - private Multimap<String, IItemDescriptor> id2descriptors = ArrayListMultimap.create(); + private Map<String, List<IItemDescriptor>> id2descriptors = new HashMap<>(); /** * Get the property sections. @@ -76,7 +76,12 @@ public class LegacyPropertySectionRegistry implements IItemRegistry { // Else read the section from the configuration if (values.isEmpty()) { - values = this.id2descriptors.values(); + // @formatter:off + values = this.id2descriptors.values().stream() + .filter(Objects::nonNull) + .flatMap(List::stream) + .collect(Collectors.toList()); + // @formatter:on } for (IItemDescriptor itemDescriptor : values) { @@ -99,8 +104,14 @@ public class LegacyPropertySectionRegistry implements IItemRegistry { */ @Override public IItemDescriptor add(IItemDescriptor descriptor) { - this.id2descriptors.put(descriptor.getId(), descriptor); - return descriptor; + List<IItemDescriptor> descriptors = this.id2descriptors.getOrDefault(descriptor.getId(), new ArrayList<>()); + boolean result = descriptors.add(descriptor); + this.id2descriptors.put(descriptor.getId(), descriptors); + + if (result) { + return descriptor; + } + return null; } /** @@ -110,7 +121,8 @@ public class LegacyPropertySectionRegistry implements IItemRegistry { */ @Override public boolean remove(String id) { - return !this.id2descriptors.removeAll(id).isEmpty(); + List<IItemDescriptor> descriptors = Optional.ofNullable(this.id2descriptors.remove(id)).orElseGet(ArrayList::new); + return !descriptors.isEmpty(); } /** diff --git a/plugins/org.eclipse.eef.properties.ui.legacy/src/org/eclipse/eef/properties/ui/legacy/internal/extension/impl/LegacyPropertyTabRegistry.java b/plugins/org.eclipse.eef.properties.ui.legacy/src/org/eclipse/eef/properties/ui/legacy/internal/extension/impl/LegacyPropertyTabRegistry.java index d53b7d187..1f8fcfc47 100644 --- a/plugins/org.eclipse.eef.properties.ui.legacy/src/org/eclipse/eef/properties/ui/legacy/internal/extension/impl/LegacyPropertyTabRegistry.java +++ b/plugins/org.eclipse.eef.properties.ui.legacy/src/org/eclipse/eef/properties/ui/legacy/internal/extension/impl/LegacyPropertyTabRegistry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Obeo. + * Copyright (c) 2015, 2017 Obeo. * 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 @@ -10,15 +10,17 @@ *******************************************************************************/ package org.eclipse.eef.properties.ui.legacy.internal.extension.impl; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; import org.eclipse.eef.properties.ui.api.IEEFTabDescriptor; import org.eclipse.eef.properties.ui.legacy.internal.EEFPropertiesUiLegacyPlugin; @@ -40,7 +42,7 @@ public class LegacyPropertyTabRegistry implements IItemRegistry { /** * The map of the identifier of the description to the {@link LegacyPropertyTabItemDescriptor}. */ - private Multimap<String, IItemDescriptor> id2descriptors = ArrayListMultimap.create(); + private Map<String, List<IItemDescriptor>> id2descriptors = new HashMap<>(); /** * Get the property tabs. @@ -217,7 +219,12 @@ public class LegacyPropertyTabRegistry implements IItemRegistry { */ private List<IEEFTabDescriptor> readTabDescriptors(String contributorId) { List<IEEFTabDescriptor> eefTabDescriptors = new ArrayList<IEEFTabDescriptor>(); - Collection<IItemDescriptor> values = this.id2descriptors.values(); + // @formatter:off + Collection<IItemDescriptor> values = this.id2descriptors.values().stream() + .filter(Objects::nonNull) + .flatMap(List::stream) + .collect(Collectors.toList()); + // @formatter:on for (IItemDescriptor itemDescriptor : values) { if (itemDescriptor instanceof LegacyPropertyTabItemDescriptor) { LegacyPropertyTabItemDescriptor eefTabDescriptor = (LegacyPropertyTabItemDescriptor) itemDescriptor; @@ -237,7 +244,10 @@ public class LegacyPropertyTabRegistry implements IItemRegistry { */ @Override public IItemDescriptor add(IItemDescriptor descriptor) { - boolean result = this.id2descriptors.put(descriptor.getId(), descriptor); + List<IItemDescriptor> descriptors = this.id2descriptors.getOrDefault(descriptor.getId(), new ArrayList<>()); + boolean result = descriptors.add(descriptor); + this.id2descriptors.put(descriptor.getId(), descriptors); + if (result) { return descriptor; } @@ -251,7 +261,8 @@ public class LegacyPropertyTabRegistry implements IItemRegistry { */ @Override public boolean remove(String id) { - return !this.id2descriptors.removeAll(id).isEmpty(); + List<IItemDescriptor> descriptors = Optional.ofNullable(this.id2descriptors.remove(id)).orElseGet(ArrayList::new); + return !descriptors.isEmpty(); } /** @@ -268,10 +279,13 @@ public class LegacyPropertyTabRegistry implements IItemRegistry { * Disposes this registry. */ public void dispose() { - for (IItemDescriptor desc : id2descriptors.values()) { - if (desc instanceof LegacyPropertyTabItemDescriptor) { - ((LegacyPropertyTabItemDescriptor) desc).dispose(); - } - } + // @formatter:off + this.id2descriptors.values().stream() + .filter(Objects::nonNull) + .flatMap(List::stream) + .filter(LegacyPropertyTabItemDescriptor.class::isInstance) + .map(LegacyPropertyTabItemDescriptor.class::cast) + .forEach(LegacyPropertyTabItemDescriptor::dispose); + // @formatter:on } } diff --git a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/META-INF/MANIFEST.MF b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/META-INF/MANIFEST.MF index fb7df3723..5b7bcd2ad 100644 --- a/samples/org.eclipse.eef.sample.custom.widget.colorpicker/META-INF/MANIFEST.MF +++ b/samples/org.eclipse.eef.sample.custom.widget.colorpicker/META-INF/MANIFEST.MF @@ -24,8 +24,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.7.0,4.0.0)", org.eclipse.eef.core;bundle-version="[2.0.0,3.0.0)", org.eclipse.eef.common;bundle-version="[2.0.0,3.0.0)", org.eclipse.eef.common.ui;bundle-version="[2.0.0,3.0.0)", - org.eclipse.eef.ide.ui;bundle-version="[2.0.0,3.0.0)", - com.google.guava;bundle-version="[15.0.0,16.0.0)" + org.eclipse.eef.ide.ui;bundle-version="[2.0.0,3.0.0)" Bundle-Localization: plugin Bundle-ActivationPolicy: lazy Bundle-Activator: org.eclipse.eef.sample.custom.widget.colorpicker.ColorPickerPlugin$Implementation |