Replace header composite with section in E4 Editor
-simplify container stack
-introduce section with text instead of two labels
-Icon can not be displayed anymore :-(
-reduce margins
Change-Id: I42936ac55fcd521036753fe79b593f98ad603b6d
Signed-off-by: Christof Joswig <christof.joswig@sap.com>
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF
index 02aec94..f64ea47 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF
@@ -37,7 +37,8 @@
org.eclipse.pde.core;resolution:=optional,
org.eclipse.e4.core.commands;bundle-version="0.10.0",
org.eclipse.e4.ui.dialogs;bundle-version="1.0.0",
- org.eclipse.e4.emf.xpath
+ org.eclipse.e4.emf.xpath,
+ org.eclipse.ui.forms;bundle-version="3.7.200"
Bundle-ActivationPolicy: lazy
Import-Package: javax.annotation;version="1.2.0",
javax.inject;version="1.0.0",
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/component/AbstractComponentEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/component/AbstractComponentEditor.java
index a50751d..330bf71 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/component/AbstractComponentEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/common/component/AbstractComponentEditor.java
@@ -144,10 +144,9 @@
/**
* Get the image described in element if this is a MUILabel
*
- * @param element
- * the element in tree to be displayed
- * @return image of element if iconUri is not empty (returns bad image if
- * bad URI), else returns null
+ * @param element the element in tree to be displayed
+ * @return image of element if iconUri is not empty (returns bad image if bad
+ * URI), else returns null
*/
public Image getImageFromIconURI(MUILabel element) {
@@ -171,9 +170,8 @@
return img;
}
- /** @return true if the image of this element should be displayed in grey*/
- private boolean shouldBeGrey(Object element)
- {
+ /** @return true if the image of this element should be displayed in grey */
+ private boolean shouldBeGrey(Object element) {
// It is grey if a MUIElement is not visible or not rendered
// It is not grey if this is not a MUIElement or if it is rendered and
// visible.
@@ -183,11 +181,9 @@
/**
*
- * @param key
- * the key of image (can be a constants from ResourceProvider or
- * a platform:/ uri location
- * @param grey
- * if true returns the grey version if original image exists
+ * @param key the key of image (can be a constants from ResourceProvider or a
+ * platform:/ uri location
+ * @param grey if true returns the grey version if original image exists
* @return the image with a give key or grey version.
*/
private Image getImage(String key, boolean grey) {
@@ -222,10 +218,8 @@
/**
* Get image from an element Implements algorithm described in bug #465271
*
- * @param element
- * the Application Element
- * @param key
- * the element image key if no icon URI
+ * @param element the Application Element
+ * @param key the element image key if no icon URI
* @return Image or null if nothing found
*/
public Image getImage(Object element, String key) {
@@ -348,11 +342,10 @@
/**
* Translates an input <code>String</code> using the current
- * {@link ResourceBundleTranslationProvider} and <code>locale</code> from
- * the {@link TranslationService}.
+ * {@link ResourceBundleTranslationProvider} and <code>locale</code> from the
+ * {@link TranslationService}.
*
- * @param string
- * the string to translate, may not be null.
+ * @param string the string to translate, may not be null.
* @return the translated string or the input string if it could not be
* translated.
*/
@@ -457,16 +450,13 @@
}
/**
- * Generates an ID when the another field changes. Must be called after
- * master is set with the objects value.
+ * Generates an ID when the another field changes. Must be called after master
+ * is set with the objects value.
*
- * @param attSource
- * The source attribute
- * @param attId
- * The id attribute to generate
- * @param control
- * optional control to disable generator after losing focus or
- * disposing
+ * @param attSource The source attribute
+ * @param attId The id attribute to generate
+ * @param control optional control to disable generator after losing focus or
+ * disposing
*/
protected void enableIdGenerator(EAttribute attSource, EAttribute attId, Control control) {
if (generator != null) {
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/AbstractPickList.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/AbstractPickList.java
index 893f6d2..cf6b2c0 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/AbstractPickList.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/AbstractPickList.java
@@ -75,6 +75,7 @@
public AbstractPickList(Composite parent, int style, List<PickListFeatures> listFeatures,
AbstractComponentEditor componentEditor) {
+
super(parent, style);
// TODO remove dependency AbstractComponentEditor. They
@@ -87,13 +88,25 @@
} else {
composite = new Group(this, SWT.NONE);
}
- composite.setLayout(new GridLayout(1, false));
- final Composite comp = new Composite(composite, SWT.NONE);
-
- GridLayout layout = new GridLayout(2, false);
+ GridLayout layout = new GridLayout(1, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
+ layout.marginRight = 0;
+ layout.marginLeft = 0;
+ layout.horizontalSpacing = 0;
+ layout.verticalSpacing = 0;
+ composite.setLayout(layout);
+
+ Composite comp = new Composite(composite, SWT.NONE);
+
+ layout = new GridLayout(2, false);
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.marginRight = 0;
+ layout.marginLeft = 0;
+ layout.horizontalSpacing = 0;
+ layout.verticalSpacing = 0;
comp.setLayout(layout);
comp.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
@@ -121,8 +134,14 @@
toolBar = new Composite(comp, SWT.NONE);
layout = new GridLayout(5, true);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
+ if (listFeatures != null && listFeatures.contains(PickListFeatures.NO_PICKER)) {
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ layout.marginRight = 0;
+ layout.marginLeft = 0;
+ }
+ layout.horizontalSpacing = 2;
+ layout.verticalSpacing = 0;
toolBar.setLayout(layout);
toolBar.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
toolBar.setFont(composite.getFont());
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
index b63eeda..7a3e428 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java
@@ -236,13 +236,13 @@
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Section;
public class ModelEditor implements IGotoObject {
private static final String ORG_ECLIPSE_E4_TOOLS_MODELEDITOR_FILTEREDTREE_ENABLED_XMITAB_DISABLED = "org.eclipse.e4.tools.modeleditor.filteredtree.enabled.xmitab.disabled";//$NON-NLS-1$
@@ -373,7 +373,7 @@
private XmiTab xmiTab;
- private Label sectionHeaderLabel;
+ private Section headerContainer;
public ModelEditor(Composite composite, IEclipseContext context, IModelResource modelProvider, IProject project,
final IResourcePool resourcePool) {
@@ -547,39 +547,24 @@
}
private Composite createFormTab(Composite composite) {
- final SashForm form = new SashForm(composite, SWT.HORIZONTAL);
- form.setBackground(form.getDisplay().getSystemColor(SWT.COLOR_WHITE));
+ SashForm form = new SashForm(composite, SWT.HORIZONTAL);
viewer = createTreeViewerArea(form);
- final Composite parent = new Composite(form, SWT.NONE);
- final FillLayout l = new FillLayout();
- parent.setLayout(l);
+ FormToolkit toolkit = new FormToolkit(form.getDisplay());
- final Composite editingArea = new Composite(parent, SWT.BORDER);
- final GridLayout gl = new GridLayout();
- editingArea.setLayout(gl);
+ headerContainer = toolkit.createSection(form, Section.TITLE_BAR);
+ headerContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
- final Composite headerContainer = new Composite(editingArea, SWT.NONE);
- headerContainer.setLayout(new GridLayout(3, false));
- headerContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ // Composite for storing the data
+ Composite contentContainer = toolkit.createComposite(headerContainer, SWT.NONE);
+ headerContainer.setClient(contentContainer);
- final Label iconLabel = new Label(headerContainer, SWT.NONE);
- iconLabel.setLayoutData(new GridData(20, 20));
-
- sectionHeaderLabel = new Label(headerContainer, SWT.NONE);
- sectionHeaderLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- final Label separatorLabel = new Label(headerContainer, SWT.SEPARATOR | SWT.HORIZONTAL);
- final GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
- gridData.horizontalSpan = 2;
- separatorLabel.setLayoutData(gridData);
-
- final StackLayout layout = new StackLayout();
- final Composite contentContainer = new Composite(editingArea, SWT.NONE);
- contentContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
-
+ StackLayout layout = new StackLayout();
contentContainer.setLayout(layout);
+ form.setWeights(new int[] { 2, 5 });
+
viewer.getTree().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(final KeyEvent e) {
@@ -608,11 +593,9 @@
final AbstractComponentEditor editor1 = getEditor(obj.eClass());
if (editor1 != null) {
currentEditor = editor1;
- sectionHeaderLabel.setText(editor1.getLabel(obj));
- iconLabel.setImage(editor1.getImage(obj));
+ headerContainer.setText(editor1.getLabel(obj));
obsManager.runAndCollect(() -> {
final Composite comp = editor1.getEditor(contentContainer, s.getFirstElement());
- comp.setBackgroundMode(SWT.INHERIT_DEFAULT);
layout.topControl = comp;
contentContainer.layout(true);
});
@@ -622,11 +605,9 @@
final AbstractComponentEditor editor2 = getEditor(entry.getId());
if (editor2 != null) {
currentEditor = editor2;
- sectionHeaderLabel.setText(editor2.getLabel(entry));
- iconLabel.setImage(editor2.getImage(entry));
+ headerContainer.setText(editor2.getLabel(entry));
obsManager.runAndCollect(() -> {
final Composite comp = editor2.getEditor(contentContainer, s.getFirstElement());
- comp.setBackgroundMode(SWT.INHERIT_DEFAULT);
layout.topControl = comp;
contentContainer.layout(true);
});
@@ -636,12 +617,9 @@
if (selectionService != null) {
selectionService.setSelection(s.getFirstElement());
}
-
}
});
- form.setWeights(new int[] { 3, 4 });
-
final MenuManager mgr = new MenuManager();
mgr.setRemoveAllWhenShown(true);
mgr.addMenuListener(manager -> {
@@ -1173,7 +1151,6 @@
registerEditor(VIRTUAL_SNIPPETS, VSnippetsEditor.class);
}
-
public void setSelection(Object element) {
viewer.setSelection(new StructuredSelection(element));
}
@@ -1392,8 +1369,7 @@
* Get editor from an eClass. May return the registered editor for this eclass,
* or the editor for a parent EClass or the default editor
*
- * @param eClass
- * the eClass to get editor for
+ * @param eClass the eClass to get editor for
* @return the {@link AbstractComponentEditor} found (never null).
*/
public AbstractComponentEditor getEditor(EClass eClass) {
@@ -1428,10 +1404,9 @@
/**
* get editor from a string key.
*
- * @param key
- * : the editor string key
- * @param createDefaultIfNull
- * if true, returns the default editor if no editor found
+ * @param key : the editor string key
+ * @param createDefaultIfNull if true, returns the default editor if no editor
+ * found
* @return the {@link AbstractComponentEditor} if exists. Never null if
* createDefaultIfNull is true
*/
@@ -1492,7 +1467,6 @@
return false;
}
-
@Persist
public void doSave(@Optional IProgressMonitor monitor) {
@@ -1528,7 +1502,7 @@
}
public void setHeaderTitle(String title) {
- sectionHeaderLabel.setText(title);
+ headerContainer.setText(title);
}
@PreDestroy
@@ -1542,7 +1516,9 @@
if (project == null) {
context.get(Display.class).removeFilter(SWT.MouseUp, keyListener);
}
- ContextInjectionFactory.uninject(xmiTab, xmiTab.getContext());
+ if (xmiTab != null) {
+ ContextInjectionFactory.uninject(xmiTab, xmiTab.getContext());
+ }
}
public IModelResource getModelProvider() {
@@ -1970,14 +1946,10 @@
* Create an internal Compound command containing a Remove and a Add so as to
* allow the Undo
*
- * @param data
- * the object to be dragged and dropped
- * @param destFeature
- * the target feature in the model where data must be dropped
- * @param parent
- * the destination parent
- * @param index
- * the index in the parent list
+ * @param data the object to be dragged and dropped
+ * @param destFeature the target feature in the model where data must be dropped
+ * @param parent the destination parent
+ * @param index the index in the parent list
* @see bug #429684
* @return the compound command
*/
@@ -2005,7 +1977,6 @@
}
-
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
boolean rv = true;
@@ -2028,11 +1999,13 @@
}
- /** This method checks if the target object is a valid target for the current instance.
- * It used both for paste and for drag and drop behavior
- * @param target the target object where instance should be pasted of dropped
+ /**
+ * This method checks if the target object is a valid target for the current
+ * instance. It used both for paste and for drag and drop behavior
+ *
+ * @param target the target object where instance should be pasted of dropped
* @param instance the instance of object to be pasted or dropped
- * @param isIndex if true, means that target is an object in a container
+ * @param isIndex if true, means that target is an object in a container
* @return
*/
private boolean isValidTarget(Object target, Object instance, boolean isIndex) {
@@ -2050,8 +2023,7 @@
final VirtualEntry<Object> vTarget = (VirtualEntry<Object>) target;
if (isIndex || !vTarget.getList().contains(instance)) {
if (vTarget.getProperty() instanceof IEMFProperty) {
- final EStructuralFeature feature = ((IEMFProperty) vTarget.getProperty())
- .getStructuralFeature();
+ final EStructuralFeature feature = ((IEMFProperty) vTarget.getProperty()).getStructuralFeature();
final EObject parent = (EObject) vTarget.getOriginalParent();
final EClassifier classifier = ModelUtils.getTypeArgument(parent.eClass(),
feature.getEGenericType());
@@ -2072,12 +2044,10 @@
return false;
}
-
/**
* compute a valid name for the undo/redo/paste of move commands
*
- * @param data
- * the object concerned by the command
+ * @param data the object concerned by the command
* @return a representative string for the object or 'Object' if nothing found
*/
private String getObjectNameForCommand(Object data) {