Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMélanie Bats2017-05-17 12:56:37 +0000
committerStéphane Bégaudeau2017-05-22 08:37:56 +0000
commit340869c5eb9b93346858bc310f1f70aede95c799 (patch)
tree6f2bd1cc0e0ecf3c2baced8ce84e1fdf592505a1
parentac18eee4a5ed1cb7e04cd4d39ce0d5a28947ceac (diff)
downloadorg.eclipse.eef-340869c5eb9b93346858bc310f1f70aede95c799.tar.gz
org.eclipse.eef-340869c5eb9b93346858bc310f1f70aede95c799.tar.xz
org.eclipse.eef-340869c5eb9b93346858bc310f1f70aede95c799.zip
[496076] Provide a default image for toolbar action
If the image expression is not set for a toolbar action a default image is provided. Bug: 496076 Change-Id: If67e2aaaed4196f06f1887a2545e2ac59dc5b2d9 Signed-off-by: Mélanie Bats <melanie.bats@obeo.fr>
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/EEFImageUtils.java2
-rw-r--r--plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/ToolbarAction.java25
2 files changed, 23 insertions, 4 deletions
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/EEFImageUtils.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/EEFImageUtils.java
index 4b3b2542c..2d311c293 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/EEFImageUtils.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/EEFImageUtils.java
@@ -62,7 +62,7 @@ public final class EEFImageUtils {
/**
* Retrieve an image descriptor from a string path as '/resource/folder/image.png'.
- *
+ *
* @param imgPath
* The image path
* @return The image descriptor
diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/ToolbarAction.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/ToolbarAction.java
index 9a011013e..f83eb947a 100644
--- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/ToolbarAction.java
+++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/ToolbarAction.java
@@ -16,11 +16,15 @@ import org.eclipse.eef.EEFToolbarAction;
import org.eclipse.eef.core.api.EditingContextAdapter;
import org.eclipse.eef.core.api.controllers.IEEFToolbarActionController;
import org.eclipse.eef.core.api.utils.EvalFactory;
+import org.eclipse.eef.ide.ui.internal.EEFIdeUiPlugin;
import org.eclipse.eef.ide.ui.internal.EEFImageUtils;
+import org.eclipse.eef.ide.ui.internal.Icons;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.sirius.common.interpreter.api.IInterpreter;
import org.eclipse.sirius.common.interpreter.api.IVariableManager;
+import org.eclipse.swt.graphics.Image;
/**
* An {@link Action} taking tooltip, image and behavior from an {@link EEFToolbarAction}.
@@ -83,17 +87,32 @@ public class ToolbarAction extends Action {
this.setToolTipText(actionTooltip);
String imageExpression = Optional.ofNullable(this.eefToolbarAction.getImageExpression()).orElse(""); //$NON-NLS-1$
- Object image = EvalFactory.of(interpreter, variableManager).logIfInvalidType(Object.class).evaluate(imageExpression);
+ Object imagePath = EvalFactory.of(interpreter, variableManager).logIfInvalidType(Object.class).evaluate(imageExpression);
// @formatter:off
- Optional.ofNullable(image).filter(String.class::isInstance)
+ Optional.ofNullable(imagePath)
+ .filter(String.class::isInstance)
.map(String.class::cast)
- .flatMap(EEFImageUtils::getImageDescriptor)
+ .map(this::computeImageDescriptor)
.ifPresent(this::setImageDescriptor);
// @formatter:on
}
/**
+ * Computes the image descriptor to use for the given image path.
+ *
+ * @param imagePath
+ * The path of the image
+ * @return The image descriptor for the image with the given path or a placeholder image if it could not be found
+ */
+ private ImageDescriptor computeImageDescriptor(String imagePath) {
+ return EEFImageUtils.getImageDescriptor(imagePath).orElseGet(() -> {
+ Image placeholderImage = EEFIdeUiPlugin.getPlugin().getImageRegistry().get(Icons.PLACEHOLDER);
+ return ImageDescriptor.createFromImage(placeholderImage);
+ });
+ }
+
+ /**
* {@inheritDoc}
*
* @see org.eclipse.jface.action.Action#run()

Back to the top