From 6966477cbb063e0016aa4a304c658f068b4495b0 Mon Sep 17 00:00:00 2001 From: Simon Barner <barner@fortiss.org> Date: Wed, 21 Nov 2018 18:17:57 +0100 Subject: [PATCH] Update tabbed property sheet title when edited input is changed * PropertySectionBase: Register (non-recursive) EMF notification adapter * NamedCommentedPropertySection: special case due to input "retargeting" Issue-Ref: 3470 Issue-Url: https://af3-developer.fortiss.org/issues/3470 Signed-off-by: Simon Barner <barner@fortiss.org> --- .../tooling/kernel/ui/extension/base/.ratings | 2 +- .../extension/base/PropertySectionBase.java | 42 +++++++++++++++++++ .../kernel/ui/internal/properties/.ratings | 2 +- .../NamedCommentedPropertySection.java | 7 ++-- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/.ratings index 76a9001c4..832374ffe 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/.ratings @@ -10,7 +10,7 @@ ModelEditorBindingBase.java 4c5ac569c0b6e7678fc8191096b26dfd09fdcb98 GREEN ModelElementHandlerBase.java 384727748f125c9d43f19d9c0eba4ba1be5a7a26 GREEN MultiEObjectActionBase.java 9e237d8ea640c4194e4877af4a9cfce88698e543 GREEN NamedCommentedModelElementHandlerBase.java 681b98b50b362f01abb7a36f108f4f11b9e51829 GREEN -PropertySectionBase.java 8a0c90a7657fb93695d50f570ff8043cf7bb8602 YELLOW +PropertySectionBase.java c061c62531621d96b1e1d1c27ad99889c92bacb7 YELLOW TutorialStepUIAtomicBase.java cea2a158158b476de2108d2309afcf47f217b6d9 GREEN TutorialStepUIAtomicWithWhitelistBase.java a9788ae514f62d27169c737ef59fb583234b5d43 GREEN TutorialStepUICompositeBase.java 8225210eacb5b88de47d78280c5819f572f00ffa GREEN diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java index 8a0c90a76..c061c6253 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/extension/base/PropertySectionBase.java @@ -32,6 +32,9 @@ import org.conqat.ide.commons.ui.databinding.validate.TextToDoubleValidator; import org.conqat.ide.commons.ui.databinding.validate.TextToIntegerValidator; import org.eclipse.core.databinding.observable.value.IObservableValue; import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.emf.databinding.EMFDataBindingContext; import org.eclipse.emf.ecore.EObject; import org.eclipse.gef.EditPart; @@ -66,6 +69,26 @@ import com.ibm.icu.text.NumberFormat; */ public abstract class PropertySectionBase extends AbstractPropertySection { + /** Adapter to synchronize property sheet title. */ + private final class TitleSyncAdapter extends AdapterImpl { + /** {@inheritDoc} */ + @Override + public void notifyChanged(org.eclipse.emf.common.notify.Notification msg) { + if(msg.getEventType() != Notification.REMOVING_ADAPTER) { + // Updates the tabbed property sheets title + tabbedPropertySheetPage.labelProviderChanged(null); + } + } + + /** Removes itself. */ + public void remove() { + Notifier target = getTarget(); + if(target != null) { + target.eAdapters().remove(this); + } + } + } + /** Label width. */ public static final int PROPERTIES_LABEL_WIDTH = 150; @@ -75,10 +98,17 @@ public abstract class PropertySectionBase extends AbstractPropertySection { /** Stores the data binding context used. */ protected EMFDataBindingContext dbc = new EMFDataBindingContext(); + /** Underlying {@link TabbedPropertySheetPage}. */ + private TabbedPropertySheetPage tabbedPropertySheetPage; + + /** Adapter to synchronize property sheet title. */ + private TitleSyncAdapter titleSyncAdapter = new TitleSyncAdapter(); + /** {@inheritDoc} */ @Override public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) { super.createControls(parent, tabbedPropertySheetPage); + this.tabbedPropertySheetPage = tabbedPropertySheetPage; composite = getWidgetFactory().createFlatFormComposite(parent); composite.setLayout(new GridLayout(2, false)); @@ -112,11 +142,23 @@ public abstract class PropertySectionBase extends AbstractPropertySection { if(object instanceof EditPart) { object = ((EditPart)object).getModel(); } + if(object instanceof EObject) { + addTitleSyncAdapter((EObject)object); + } disableControlsForLibraryReferences(object); setSectionInput(object); } + /** + * Adds the {@link #titleSyncAdapter} to the given {@link EObject}, and undoes any + * possible previous registration. + */ + protected void addTitleSyncAdapter(EObject eObj) { + titleSyncAdapter.remove(); + eObj.eAdapters().add(titleSyncAdapter); + } + /** * Disables the graphical controls in the case we are in an {@link ILibraryElementReference}. */ diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/.ratings index 640663407..2db8f8fa8 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/.ratings @@ -1,3 +1,3 @@ IdLabeledPropertySection.java dcfb39d225391c87f47e29f6d1ba1cb22a3d3fe4 GREEN -NamedCommentedPropertySection.java d15d490708e5c7362ebc4f30a04bccb0f6b64f39 GREEN +NamedCommentedPropertySection.java d4fab618eca361f132b1baafecd66ad8f7919dfa YELLOW PropertiesAdapterFactory.java edcf34766a60f21c9ba22a1ba73aa487c3d9a946 GREEN diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/NamedCommentedPropertySection.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/NamedCommentedPropertySection.java index d15d49070..d4fab618e 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/NamedCommentedPropertySection.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/properties/NamedCommentedPropertySection.java @@ -67,14 +67,15 @@ public class NamedCommentedPropertySection extends PropertySectionBase { protected void setSectionInput(Object input) { namedCommented = (INamedCommentedElement)input; - // do section retargeting - IModelElementHandler<EObject> handler = - IModelElementHandlerService.getInstance().getModelElementHandler(namedCommented); + // "Re-target" section + IModelElementHandlerService hs = IModelElementHandlerService.getInstance(); + IModelElementHandler<EObject> handler = hs.getModelElementHandler(namedCommented); if(handler != null) { EObject retarget = handler.getPropertySectionRetargetElement(namedCommented); if(retarget instanceof INamedCommentedElement) { namedCommented = (INamedCommentedElement)retarget; } + addTitleSyncAdapter(namedCommented); } } -- GitLab