Commit 78ed91eb authored by Florian Hölzl's avatar Florian Hölzl

Kernel: IModelElementHandlerService: getFXIcon() method added.

This method replaces the getImage() method from SWT-based
implementation. The default image is "tooling.kernel.ui/icons/fix.png".

Issue-Ref: 3907
Issue-Url: https://af3-developer.fortiss.org/issues/3907Signed-off-by: Florian Hölzl's avatarFlorian Hoelzl <hoelzl@fortiss.org>
parent a9bd4661
GraphicUtils.java 4d471a310a52bda1c090f956dcdbe90775b12cb8 GREEN
GraphicUtils.java 46cfc991cd3ef787fec3f95751bc680d68479e26 YELLOW
JavaFXUtils.java db3cf28289109ffec64c8f96c7b2de779a977b3b GREEN
......@@ -28,21 +28,28 @@ import javafx.scene.paint.Color;
* @author munaro
*/
public class GraphicUtils {
/** The image cache of loaded images. */
private static final HashMap<String, Image> imageCache = new HashMap<>();
/** Returns the plugin-local URI string for the given resource. */
public static String getURIString(String pluginId, String localPath) {
if(!pluginId.endsWith("/") && !localPath.startsWith("/")) {
localPath = "/" + localPath;
}
return "platform:/plugin/" + pluginId + localPath;
}
/** Returns the Java FX Image load from the local path. */
/** Returns the Java FX Image loaded from the plugin's local path. */
public static Image getFXImage(String pluginId, String localPath) {
String uri = getURIString(pluginId, localPath);
if(uri == null) {
return null;
}
return getFXImageFromURI(uri);
}
/** Returns the Java FX Image loaded from the given URI. */
public static Image getFXImageFromURI(String uri) {
Image cacheImage = imageCache.get(uri);
if(cacheImage == null) {
InputStream in = null;
......
......@@ -4,7 +4,7 @@ IContextMenuMultiSelectionContributor.java 125b31dd38009bc2095b7e6bc860e946e39f5
IEditPartFactory.java 5729715847f553d95a5bad4a9211c7e6f458badd GREEN
IModelEditor.java 962d7f7758abc88bbc6064c8b4eb32da00abf8e8 GREEN
IModelEditorBinding.java d6896569cfe7eb0d7f0b8e4a71573c50e8c75329 GREEN
IModelElementHandler.java 21b4a96251e0267f156b4b8f2b95a97f6e81e646 GREEN
IModelElementHandler.java 86a8ec88b9679bbe7f53cfa8d1592bd862873f80 YELLOW
ITutorialStepUI.java b8aee2b95857484ab6ad9ecd55b5de9f0ea158e5 GREEN
ITutorialUIProvider.java aa0ff5db4d7ba0953e34edeb99f3e8279567e18f GREEN
ITutorialUIWhitelistProvider.java d703c1531c6ae7677c2d94cbc95d498dfa4a7e9b GREEN
......
......@@ -25,6 +25,8 @@ import org.fortiss.tooling.kernel.ui.extension.base.ModelElementHandlerBase;
import org.fortiss.tooling.kernel.ui.extension.base.NamedCommentedModelElementHandlerBase;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
import javafx.scene.Node;
/**
* A model element handler provides information about a specific type of model
* elements like name, description, icon and certain kinds of sub-elements.
......@@ -49,6 +51,9 @@ public interface IModelElementHandler<T extends EObject> extends IEObjectAware<T
/** Returns image descriptor to be used as icon image. */
ImageDescriptor getIconImageDescriptor(T element);
/** Returns the JavaFX icon of the model element. */
Node getFXIcon(T element);
/**
* Returns all children acting as nodes, which are usually displayed as edit
* parts by graphical editors and entries in the navigator tree.
......
......@@ -8,7 +8,7 @@ FXEditorBase.java 2e520be0bbae7d0aebdff70218a124dbe0896ce2 GREEN
IListPropertySection.java 8bb00fe7959583e794ff9437b7a77404c9a9e70f GREEN
LWFXEFEditorBase.java 2bd06235f20c18dc2e7d433700b2ad74a16664e2 GREEN
ModelEditorBindingBase.java c258cb0ea28d74440856cd2abf367408fbbc1279 GREEN
ModelElementHandlerBase.java 384727748f125c9d43f19d9c0eba4ba1be5a7a26 GREEN
ModelElementHandlerBase.java d08583ffdf78938a14caeb46124eda4ce5cac3e4 YELLOW
MultiEObjectActionBase.java 9e237d8ea640c4194e4877af4a9cfce88698e543 GREEN
NamedCommentedModelElementHandlerBase.java 681b98b50b362f01abb7a36f108f4f11b9e51829 GREEN
PropertySectionBase.java 20fb1daea544123ea941743aafeb9ac59daf5356 GREEN
......
......@@ -16,6 +16,7 @@
package org.fortiss.tooling.kernel.ui.extension.base;
import static java.util.Collections.emptyList;
import static org.fortiss.tooling.common.ui.javafx.util.GraphicUtils.getFXImageFromURI;
import java.util.HashMap;
import java.util.List;
......@@ -28,6 +29,9 @@ import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
import javafx.scene.Node;
import javafx.scene.image.ImageView;
/**
* Base implementation for {@link IModelElementHandler}s.
*
......@@ -40,7 +44,6 @@ import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
*/
public abstract class ModelElementHandlerBase<T extends EObject>
implements IModelElementHandler<T> {
/** Stores the icon image. */
private Map<ImageDescriptor, Image> iconImages = new HashMap<ImageDescriptor, Image>();
......@@ -76,6 +79,28 @@ public abstract class ModelElementHandlerBase<T extends EObject>
return iconImage;
}
/**
* Returns the URL to the JavaFX icon image.
*
* @param element
* the model element
* @return the URL of the icon
*/
protected String getFXIconURL(T element) {
return "platform:/plugin/org.fortiss.tooling.kernel.ui/icons/fix.png";
}
/** {@inheritDoc} */
@Override
public Node getFXIcon(T element) {
String uri = getFXIconURL(element);
if(uri == null) {
return null;
}
javafx.scene.image.Image img = getFXImageFromURI(uri);
return new ImageView(img);
}
/** The default implementation forwards the request by ignoring the model element. */
@Override
public ImageDescriptor getIconImageDescriptor(T element) {
......
......@@ -3,8 +3,8 @@ AllocationEditPartFactoryService.java 81bd227736013f1157ba9d0f79a9f3deefe10064 G
ContextMenuService.java ca3c899293f25b70ce8e5f0d86ca2f9683329d81 GREEN
EditPartFactoryService.java e9180c0020f1769d9e24ef3c08f9ca5599dbc5c3 GREEN
MarkerService.java 208f97f3ccabf0947702a17ddca23d8766a268f4 GREEN
ModelEditorBindingService.java 948fcdc298a74e366351ad8835a145af6cd238be GREEN
ModelElementHandlerService.java 07a30545ad687ff0fe13bf7a9348c41fb03e0b2c GREEN
ModelEditorBindingService.java 577f5db41abf240291434dbad6bc6b0fde1eeb2b YELLOW
ModelElementHandlerService.java eeb07f6926012aa98256d452d1e554a5486dc657 YELLOW
NavigatorService.java 2b1361eac805996e22e5409dafff9707fbac3376 GREEN
ToolingKernelUIInternal.java a70d19883dfb315d860233156d8524cf1ac2952f GREEN
TutorialUIService.java b1d632eca91b4feb583f3930cd6ee4722dd9bfed GREEN
......@@ -33,6 +33,8 @@ import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
import org.fortiss.tooling.kernel.ui.internal.introspection.items.ModelElementHandlerServiceIntrospectionDetailsItem;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
import javafx.scene.Node;
/**
* This class implements the {@link IModelElementHandlerService} interface. It
* requires a unique and singleton model element handler per model element
......@@ -145,6 +147,13 @@ public class ModelElementHandlerService
return handler == null ? null : handler.getIcon(modelElement);
}
/** {@inheritDoc} */
@Override
public Node getFXIcon(EObject modelElement) {
IModelElementHandler<EObject> handler = getModelElementHandler(modelElement);
return handler == null ? null : handler.getFXIcon(modelElement);
}
/** {@inheritDoc} */
@Override
public String getWrappedNameDescription(EObject modelElement) {
......
......@@ -4,6 +4,6 @@ IContextMenuService.java cfb6b8237b6cd2b0e461991a9ceb95969f330265 GREEN
IEditPartFactoryService.java c448bff63fb81f57037c9f1dc5319859c12d0c4d GREEN
IMarkerService.java d433e838e387dd2fe61b8dea7395ebb7203ae39b GREEN
IModelEditorBindingService.java ce2ae1957e2232bb0fac1d1d262103f9adfc5266 GREEN
IModelElementHandlerService.java c04c2876ccb8b3f8597c8e443f9c7c3db0945430 GREEN
IModelElementHandlerService.java 1ff2bda9054f6bbd4017fc0ddc118b7702196815 YELLOW
INavigatorService.java 8d2ffeb6f075d3abea904b84d8a40090d97837fd GREEN
ITutorialUIService.java 72707c60c3d23d8ffc5c579cb9b022bb614eb094 GREEN
......@@ -20,6 +20,8 @@ import org.eclipse.swt.graphics.Image;
import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
import org.fortiss.tooling.kernel.ui.internal.ModelElementHandlerService;
import javafx.scene.Node;
/**
* The model element handler service provides access to registered model element
* handlers.
......@@ -63,6 +65,12 @@ public interface IModelElementHandlerService {
*/
Image getIcon(EObject modelElement);
/**
* Returns the (JavaFX) icon of the model element (or <code>null</code> if no handler
* was found).
*/
Node getFXIcon(EObject modelElement);
/**
* Returns a wrapped string built from the name and description returned by
* the underlying handler.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment