Bug 565437 - Table control link tips not like single-reference control
Reuse code used in the MultiReference control.
Try to manually read the class type from the edit bundle.
Otherwise derive the label from the eClass.
Change-Id: Iedb4e789f138ee042958866fe202315ce46ee1ab
Signed-off-by: Eugen Neufeld <eneufeld@eclipsesource.com>
diff --git a/bundles/org.eclipse.emf.ecp.view.table.ui.swt/OSGI-INF/l10n/bundle.properties b/bundles/org.eclipse.emf.ecp.view.table.ui.swt/OSGI-INF/l10n/bundle.properties
index 401a803..66b5466 100644
--- a/bundles/org.eclipse.emf.ecp.view.table.ui.swt/OSGI-INF/l10n/bundle.properties
+++ b/bundles/org.eclipse.emf.ecp.view.table.ui.swt/OSGI-INF/l10n/bundle.properties
@@ -5,4 +5,5 @@
TableControl_DeleteAreYouSure=Are you sure you want to delete the selected Elements?
TableControl_MoveUp=Move up the selected %1$s
TableControl_MoveDown=Move down the selected %1$s
-TableControl_Duplicate=Duplicate the selected %1$s
\ No newline at end of file
+TableControl_Duplicate=Duplicate the selected %1$s
+TableControl_defaultReferenceDisplayName=Element
\ No newline at end of file
diff --git a/bundles/org.eclipse.emf.ecp.view.table.ui.swt/src/org/eclipse/emf/ecp/view/internal/table/swt/MessageKeys.java b/bundles/org.eclipse.emf.ecp.view.table.ui.swt/src/org/eclipse/emf/ecp/view/internal/table/swt/MessageKeys.java
index dfe4692..775cee4 100644
--- a/bundles/org.eclipse.emf.ecp.view.table.ui.swt/src/org/eclipse/emf/ecp/view/internal/table/swt/MessageKeys.java
+++ b/bundles/org.eclipse.emf.ecp.view.table.ui.swt/src/org/eclipse/emf/ecp/view/internal/table/swt/MessageKeys.java
@@ -28,4 +28,10 @@
String TableControl_MoveUp = "TableControl_MoveUp"; //$NON-NLS-1$
String TableControl_MoveDown = "TableControl_MoveDown"; //$NON-NLS-1$
String TableControl_Duplicate = "TableControl_Duplicate"; //$NON-NLS-1$
+ /**
+ * Default display name for a reference, in case the model's edit support is not available.
+ *
+ * @since 1.25
+ */
+ public static String TableControlSWTRenderer_defaultReferenceDisplayName = "Element"; //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.emf.ecp.view.table.ui.swt/src/org/eclipse/emf/ecp/view/spi/table/swt/TableControlSWTRenderer.java b/bundles/org.eclipse.emf.ecp.view.table.ui.swt/src/org/eclipse/emf/ecp/view/spi/table/swt/TableControlSWTRenderer.java
index 8faba07..f3e966e 100644
--- a/bundles/org.eclipse.emf.ecp.view.table.ui.swt/src/org/eclipse/emf/ecp/view/spi/table/swt/TableControlSWTRenderer.java
+++ b/bundles/org.eclipse.emf.ecp.view.table.ui.swt/src/org/eclipse/emf/ecp/view/spi/table/swt/TableControlSWTRenderer.java
@@ -57,6 +57,7 @@
import org.eclipse.emf.databinding.EMFDataBindingContext;
import org.eclipse.emf.databinding.EMFProperties;
import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
@@ -128,6 +129,7 @@
import org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter;
import org.eclipse.emfforms.common.Optional;
import org.eclipse.emfforms.spi.common.BundleResolver;
+import org.eclipse.emfforms.spi.common.BundleResolver.NoBundleFoundException;
import org.eclipse.emfforms.spi.common.BundleResolverFactory;
import org.eclipse.emfforms.spi.common.report.AbstractReport;
import org.eclipse.emfforms.spi.common.report.ReportService;
@@ -227,6 +229,7 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Widget;
+import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
/**
@@ -286,6 +289,9 @@
/** DO NOT USE DIRECTLY! Use {@link #getEnumeratorComparator()} instead. */
private LocalizedEnumeratorComparator enumeratorComparator;
+ private EMFFormsLocalizationService l10n;
+ private String referenceDisplayName;
+
/**
* Legacy constructor for backwards compatibility.
*
@@ -3170,8 +3176,7 @@
}
private String formatTooltipText(EClass eClass, String messageKey) {
- // final EClass clazz = ((EReference) setting.getEStructuralFeature()).getEReferenceType();
- final String instanceName = eClass.getInstanceClass() == null ? "" : eClass.getInstanceClass().getSimpleName(); //$NON-NLS-1$
+ final String instanceName = getReferenceDisplayName(eClass);
return String.format(LocalizationServiceHelper.getString(
TableControlSWTRenderer.class, messageKey),
instanceName);
@@ -3208,4 +3213,35 @@
return columnFeatures[propertyIndex - regularColumnsStartIndex];
}
+ /**
+ * Obtains a user-presentable name for the reference that I edit, to be used for example
+ * in button tool-tips.
+ *
+ * @return the reference display name
+ * @since 1.25
+ */
+ protected String getReferenceDisplayName(EClassifier type) {
+ if (referenceDisplayName == null) {
+ if (l10n == null) {
+ // Maybe the view-model context has one
+ l10n = getViewModelContext().getService(EMFFormsLocalizationService.class);
+ }
+
+ if (type != null && l10n != null) {
+ try {
+ final Bundle editBundle = bundleResolver.getEditBundle(type);
+ referenceDisplayName = l10n.getString(editBundle, String.format("_UI_%s_type", type.getName())); //$NON-NLS-1$
+ } catch (final NoBundleFoundException ex) {
+ referenceDisplayName = type.getName();
+ }
+ }
+
+ if (referenceDisplayName == null) {
+ referenceDisplayName = LocalizationServiceHelper.getString(TableControlSWTRenderer.class,
+ MessageKeys.TableControlSWTRenderer_defaultReferenceDisplayName);
+ }
+ }
+
+ return referenceDisplayName;
+ }
}