Skip to content

Commit

Permalink
[1966] Add Selection Description in the View DSL
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#1966
Signed-off-by: Michaël Charfadi <michael.charfadi@obeosoft.com>
  • Loading branch information
mcharfadi committed May 17, 2023
1 parent dbabc68 commit 09a2b45
Show file tree
Hide file tree
Showing 23 changed files with 1,103 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The filter button inside the filter bar allows to filter (hide) all visible tree
image:doc/screenshots/filterBarFilterButton.png[Filter Bar Filter Button,30%,30%]

- https://github.com/eclipse-sirius/sirius-components/issues/1830[#1830] [layout] This feature is experimental and can be activated on a diagram by adding "__EXPERIMENTAL" to its name. The new algorithm does the minimum possible to place node without overlap.
- https://github.com/eclipse-sirius/sirius-components/issues/1966[#1966] Add Selection Description in the View DSL

=== Improvements

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Obeo.
* Copyright (c) 2019, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -49,6 +49,8 @@
@Service
public class ObjectService implements IObjectService {

public static final String DEFAULT_ICON_PATH = "/icons/svg/Default.svg";

private static final String DEFAULT_LABEL_FEATURE = "name";

private static final String ID_SEPARATOR = "#";
Expand Down Expand Up @@ -167,7 +169,7 @@ public String getImagePath(Object object) {
}
}
}
return null;
return DEFAULT_ICON_PATH;
}

private String getImageRelativePath(String imageFullPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ViewerNotification;
import org.eclipse.sirius.components.view.NodeTool;
import org.eclipse.sirius.components.view.ViewFactory;
import org.eclipse.sirius.components.view.ViewPackage;

/**
* This is the item provider adapter for a {@link org.eclipse.sirius.components.view.NodeTool} object. <!--
Expand Down Expand Up @@ -50,6 +54,36 @@ public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
return this.itemPropertyDescriptors;
}

/**
* This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an
* {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or
* {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}. <!-- begin-user-doc --> <!--
* end-user-doc -->
*
* @generated NOT
*/
@Override
public Collection<? extends EStructuralFeature> getChildrenFeatures(Object object) {
if (this.childrenFeatures == null) {
super.getChildrenFeatures(object);
this.childrenFeatures.add(0, ViewPackage.Literals.NODE_TOOL__SELECTION_DESCRIPTION);
}
return this.childrenFeatures;
}

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
protected EStructuralFeature getChildFeature(Object object, Object child) {
// Check the type of the specified child object and return the proper feature to use for
// adding (see {@link AddCommand}) it as a child.

return super.getChildFeature(object, child);
}

/**
* This returns NodeTool.gif. <!-- begin-user-doc --> <!-- end-user-doc -->
*
Expand Down Expand Up @@ -91,6 +125,12 @@ public String getText(Object object) {
@Override
public void notifyChanged(Notification notification) {
this.updateChildren(notification);

switch (notification.getFeatureID(NodeTool.class)) {
case ViewPackage.NODE_TOOL__SELECTION_DESCRIPTION:
this.fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false));
return;
}
super.notifyChanged(notification);
}

Expand All @@ -103,6 +143,8 @@ public void notifyChanged(Notification notification) {
@Override
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
super.collectNewChildDescriptors(newChildDescriptors, object);

newChildDescriptors.add(this.createChildParameter(ViewPackage.Literals.NODE_TOOL__SELECTION_DESCRIPTION, ViewFactory.eINSTANCE.createSelectionDescription()));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/**
* Copyright (c) 2021, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*/
package org.eclipse.sirius.components.view.provider;

import java.util.Collection;
import java.util.List;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IChildCreationExtender;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ItemProviderAdapter;
import org.eclipse.emf.edit.provider.ViewerNotification;
import org.eclipse.sirius.components.view.SelectionDescription;
import org.eclipse.sirius.components.view.ViewPackage;

/**
* This is the item provider adapter for a {@link org.eclipse.sirius.components.view.SelectionDescription} object. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
public class SelectionDescriptionItemProvider extends ItemProviderAdapter
implements IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource {
/**
* This constructs an instance from a factory and a notifier. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
public SelectionDescriptionItemProvider(AdapterFactory adapterFactory) {
super(adapterFactory);
}

/**
* This returns the property descriptors for the adapted class. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
if (this.itemPropertyDescriptors == null) {
super.getPropertyDescriptors(object);

this.addSelectionCandidatesExpressionPropertyDescriptor(object);
this.addSelectionMessagePropertyDescriptor(object);
}
return this.itemPropertyDescriptors;
}

/**
* This adds a property descriptor for the Selection Candidates Expression feature. <!-- begin-user-doc --> <!--
* end-user-doc -->
*
* @generated
*/
protected void addSelectionCandidatesExpressionPropertyDescriptor(Object object) {
this.itemPropertyDescriptors.add(this.createItemPropertyDescriptor(((ComposeableAdapterFactory) this.adapterFactory).getRootAdapterFactory(), this.getResourceLocator(),
this.getString("_UI_SelectionDescription_selectionCandidatesExpression_feature"),
this.getString("_UI_PropertyDescriptor_description", "_UI_SelectionDescription_selectionCandidatesExpression_feature", "_UI_SelectionDescription_type"),
ViewPackage.Literals.SELECTION_DESCRIPTION__SELECTION_CANDIDATES_EXPRESSION, true, false, false, ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null));
}

/**
* This adds a property descriptor for the Selection Message feature. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
protected void addSelectionMessagePropertyDescriptor(Object object) {
this.itemPropertyDescriptors.add(this.createItemPropertyDescriptor(((ComposeableAdapterFactory) this.adapterFactory).getRootAdapterFactory(), this.getResourceLocator(),
this.getString("_UI_SelectionDescription_selectionMessage_feature"),
this.getString("_UI_PropertyDescriptor_description", "_UI_SelectionDescription_selectionMessage_feature", "_UI_SelectionDescription_type"),
ViewPackage.Literals.SELECTION_DESCRIPTION__SELECTION_MESSAGE, true, false, false, ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null));
}

/**
* This returns SelectionDescription.gif. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
public Object getImage(Object object) {
return this.overlayImage(object, this.getResourceLocator().getImage("full/obj16/SelectionDescription"));
}

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
protected boolean shouldComposeCreationImage() {
return true;
}

/**
* This returns the label text for the adapted class. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
public String getText(Object object) {
String label = ((SelectionDescription) object).getSelectionCandidatesExpression();
return label == null || label.length() == 0 ? this.getString("_UI_SelectionDescription_type") : this.getString("_UI_SelectionDescription_type") + " " + label;
}

/**
* This handles model notifications by calling {@link #updateChildren} to update any cached children and by creating
* a viewer notification, which it passes to {@link #fireNotifyChanged}. <!-- begin-user-doc --> <!-- end-user-doc
* -->
*
* @generated
*/
@Override
public void notifyChanged(Notification notification) {
this.updateChildren(notification);

switch (notification.getFeatureID(SelectionDescription.class)) {
case ViewPackage.SELECTION_DESCRIPTION__SELECTION_CANDIDATES_EXPRESSION:
case ViewPackage.SELECTION_DESCRIPTION__SELECTION_MESSAGE:
this.fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
}
super.notifyChanged(notification);
}

/**
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children that can be created
* under this object. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
super.collectNewChildDescriptors(newChildDescriptors, object);
}

/**
* Return the resource locator for this item provider's resources. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
public ResourceLocator getResourceLocator() {
return ((IChildCreationExtender) this.adapterFactory).getResourceLocator();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,29 @@ public Adapter createEdgePaletteAdapter() {
return this.edgePaletteItemProvider;
}

/**
* This keeps track of the one adapter used for all {@link org.eclipse.sirius.components.view.SelectionDescription}
* instances. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
protected SelectionDescriptionItemProvider selectionDescriptionItemProvider;

/**
* This creates an adapter for a {@link org.eclipse.sirius.components.view.SelectionDescription}. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
public Adapter createSelectionDescriptionAdapter() {
if (this.selectionDescriptionItemProvider == null) {
this.selectionDescriptionItemProvider = new SelectionDescriptionItemProvider(this);
}

return this.selectionDescriptionItemProvider;
}

/**
* This keeps track of the one adapter used for all {@link org.eclipse.sirius.components.view.BarChartDescription}
* instances. <!-- begin-user-doc --> <!-- end-user-doc -->
Expand Down Expand Up @@ -2048,6 +2071,8 @@ public void dispose() {
this.nodePaletteItemProvider.dispose();
if (this.edgePaletteItemProvider != null)
this.edgePaletteItemProvider.dispose();
if (this.selectionDescriptionItemProvider != null)
this.selectionDescriptionItemProvider.dispose();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
pluginName = View Edit Support
providerName = www.example.org

_UI_NodeTool_selectionDescription_feature = Selection Dialog
_UI_SelectionDescription_selectionCandidatesExpression_feature = Dialog Candidate Expression
_UI_SelectionDescription_selectionMessage_feature = Dialog message
_UI_SelectionDescription_type = Selection Dialog

_UI_CreateChild_text = {0}
_UI_CreateChild_text2 = {1} {0}
_UI_CreateChild_text3={1}
Expand Down
Loading

0 comments on commit 09a2b45

Please sign in to comment.