diff options
| author | Pierre-Charles David | 2016-05-20 09:19:01 +0000 |
|---|---|---|
| committer | Pierre-Charles David | 2016-05-20 13:22:14 +0000 |
| commit | fdd417cb869f7a4bcdc2890556c22dc39bcaa71b (patch) | |
| tree | a495ad2d3d93a3c38fe68651385fc21efb56904c | |
| parent | 2556ba95b19d9d86cc41abdb7cb656b3bae1ebb1 (diff) | |
| download | org.eclipse.sirius-fdd417cb869f7a4bcdc2890556c22dc39bcaa71b.tar.gz org.eclipse.sirius-fdd417cb869f7a4bcdc2890556c22dc39bcaa71b.tar.xz org.eclipse.sirius-fdd417cb869f7a4bcdc2890556c22dc39bcaa71b.zip | |
[482528] Fix inconsistencies in FontFormat property sections
Use custom property sections (with checkboxes) for:
- WidgetStyle.labelFontFormat, which is common to all widgets and
corresponds to the format of the widget's "header" label;
- LabelWidgetStyle.fontFormat, HyperlinkWidgetStyle.fontFormat and
TextWidgetStyle.fontFormat, which correspond to the format of the
actual text for the corresponding widgets, TextWidgetStyle being
shared by both Text and TextArea widgets (TextArea inherits from
Text).
Bug: 482528
Change-Id: Ic0de9a86375e922ebc340eb315aa2a0ae0c9a77e
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
4 files changed, 494 insertions, 4 deletions
diff --git a/incubation/org.eclipse.sirius.editor.properties/plugin.xml b/incubation/org.eclipse.sirius.editor.properties/plugin.xml index 94498b4096..124c8fa19c 100644 --- a/incubation/org.eclipse.sirius.editor.properties/plugin.xml +++ b/incubation/org.eclipse.sirius.editor.properties/plugin.xml @@ -86,7 +86,7 @@ <input type="org.eclipse.sirius.properties.GroupStyle"/> </propertySection> <propertySection - class="org.eclipse.sirius.properties.editor.properties.sections.properties.hyperlinkwidgetstyle.HyperlinkWidgetStyleFontFormatPropertySection" + class="org.eclipse.sirius.properties.editor.properties.sections.properties.hyperlinkwidgetstyle.HyperlinkWidgetStyleFontFormatPropertySectionSpec" id="properties.section.hyperlinkWidgetStyle.FontFormat" filter="org.eclipse.sirius.properties.editor.properties.filters.properties.hyperlinkwidgetstyle.HyperlinkWidgetStyleFontFormatFilter" afterSection="properties.section.hyperlinkWidgetStyle.BackgroundColor" @@ -156,7 +156,7 @@ <input type="org.eclipse.sirius.properties.LabelWidgetStyle"/> </propertySection> <propertySection - class="org.eclipse.sirius.properties.editor.properties.sections.properties.labelwidgetstyle.LabelWidgetStyleFontFormatPropertySectionSpec" + class="org.eclipse.sirius.properties.editor.properties.sections.properties.textwidgetstyle.TextWidgetStyleFontFormatPropertySectionSpec" id="properties.section.textWidgetStyle.FontFormat" filter="org.eclipse.sirius.properties.editor.properties.filters.properties.textwidgetstyle.TextWidgetStyleFontFormatFilter" afterSection="properties.section.textWidgetStyle.ForegroundColor" diff --git a/incubation/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/properties/editor/properties/sections/properties/hyperlinkwidgetstyle/HyperlinkWidgetStyleFontFormatPropertySectionSpec.java b/incubation/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/properties/editor/properties/sections/properties/hyperlinkwidgetstyle/HyperlinkWidgetStyleFontFormatPropertySectionSpec.java new file mode 100644 index 0000000000..4cd84cc5de --- /dev/null +++ b/incubation/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/properties/editor/properties/sections/properties/hyperlinkwidgetstyle/HyperlinkWidgetStyleFontFormatPropertySectionSpec.java @@ -0,0 +1,244 @@ +/******************************************************************************* + * Copyright (c) 2016 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.properties.editor.properties.sections.properties.hyperlinkwidgetstyle; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EEnum; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.emf.edit.domain.IEditingDomainProvider; +import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; +import org.eclipse.sirius.editor.properties.sections.common.AbstractCheckBoxGroupPropertySection; +import org.eclipse.sirius.properties.HyperlinkWidgetStyle; +import org.eclipse.sirius.properties.LabelWidgetStyle; +import org.eclipse.sirius.properties.PropertiesPackage; +import org.eclipse.sirius.viewpoint.FontFormat; +import org.eclipse.sirius.viewpoint.ViewpointPackage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; + +/** + * Use proper checkboxes for hyperlinks' font format property. + * + * @author pcdavid + */ +public class HyperlinkWidgetStyleFontFormatPropertySectionSpec extends AbstractCheckBoxGroupPropertySection { + + private static final String BOLD = "Bold"; + + private static final String ITALIC = "Italic"; + + private static final String UNDERLINE = "Underline"; + + private static final String STRIKE_THROUGH = "Strike through"; + + private static final String TOOL_TIP = "The font formatting style to use for the label"; + + public HyperlinkWidgetStyleFontFormatPropertySectionSpec() { + buttonGroup = false; + } + + @Override + protected boolean isEqual(List<?> newList) { + List<String> value = HyperlinkWidgetStyleFontFormatPropertySectionSpec.convertPropertiesToUI(((HyperlinkWidgetStyle) eObject).getFontFormat()); + return value.equals(newList); + } + + @Override + protected List<?> getChoiceOfValues() { + List<String> values = new ArrayList<String>(); + values.add(BOLD); + values.add(ITALIC); + values.add(UNDERLINE); + values.add(STRIKE_THROUGH); + return values; + } + + protected List<FontFormat> getSelectedValue() { + List<?> possibleValues = getChoiceOfValues(); + List<Object> selectedValues = new ArrayList<Object>(); + List<FontFormat> fontFormat = new ArrayList<FontFormat>(); + + for (int i = 0; i < button.length; i++) { + if (button[i].getSelection()) + selectedValues.add(possibleValues.get(i)); + } + + if (selectedValues.size() > 0) { + for (Object selectedValue : selectedValues) { + if (selectedValue.equals(ITALIC)) { + fontFormat.add(FontFormat.ITALIC_LITERAL); + } + if (selectedValue.equals(BOLD)) { + fontFormat.add(FontFormat.BOLD_LITERAL); + } + if (selectedValue.equals(UNDERLINE)) { + fontFormat.add(FontFormat.UNDERLINE_LITERAL); + } + if (selectedValue.equals(STRIKE_THROUGH)) { + fontFormat.add(FontFormat.STRIKE_THROUGH_LITERAL); + } + } + } + + return fontFormat; + } + + @Override + protected EStructuralFeature getFeature() { + return PropertiesPackage.eINSTANCE.getHyperlinkWidgetStyle_FontFormat(); + } + + @Override + protected String getDefaultLabelText() { + return "Font Format"; + } + + @Override + protected String getFeatureAsText() { + String featureText; + final EStructuralFeature eFeature = getFeature(); + final IItemPropertyDescriptor propertyDescriptor = getPropertyDescriptor(eFeature); + if (propertyDescriptor != null) { + featureText = propertyDescriptor.getLabelProvider(eObject).getText(eObject.eGet(eFeature)); + return featureText; + } + return getDefaultFeatureAsText(); + } + + @Override + protected String getDefaultFeatureAsText() { + String returnStr = ""; + if (eObject instanceof LabelWidgetStyle) { + for (String str : convertPropertiesToUI(((HyperlinkWidgetStyle) eObject).getFontFormat())) { + if (returnStr.length() > 0) { + returnStr = returnStr + (", ") + str; + } else { + returnStr = str; + } + } + } + return returnStr; + } + + @Override + protected String getLabelText() { + return super.getLabelText() + ":"; + } + + protected EEnum getFeatures() { + return ViewpointPackage.eINSTANCE.getFontFormat(); + + } + + @Override + public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) { + super.createControls(parent, tabbedPropertySheetPage); + FormData data; + + // Create a new composite to add button in fake group + Composite fakeGroup = getWidgetFactory().createComposite(composite); + RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL); + rowLayout.marginLeft = 0; + rowLayout.spacing = 5; + fakeGroup.setLayout(rowLayout); + data = new FormData(); + data.left = new FormAttachment(0, LABEL_WIDTH); + data.right = new FormAttachment(100, 0); + data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE); + fakeGroup.setLayoutData(data); + + for (int i = 0; i < button.length; i++) { + button[i].setParent(fakeGroup); + button[i].setLayoutData(null); + } + + data = new FormData(); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(fakeGroup, -ITabbedPropertyConstants.HSPACE - 20); + data.top = new FormAttachment(fakeGroup, 0, SWT.CENTER); + nameLabel.setLayoutData(data); + nameLabel.setToolTipText(TOOL_TIP); + + data = new FormData(); + CLabel help = getWidgetFactory().createCLabel(composite, ""); + data.top = new FormAttachment(nameLabel, 0, SWT.TOP); + data.left = new FormAttachment(nameLabel); + help.setLayoutData(data); + help.setImage(getHelpIcon()); + help.setToolTipText(TOOL_TIP); + + } + + @Override + public void handleSelectionChanged() { + boolean equals = isEqual(getSelectedValues()); + + if (!equals) { + EditingDomain editingDomain = ((IEditingDomainProvider) getPart()).getEditingDomain(); + Object value = getSelectedValue(); + + if (eObjectList.size() == 1) { + // apply the property change to single selected object + editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, eObject, getFeature(), value)); + } else { + CompoundCommand compoundCommand = new CompoundCommand(); + /* apply the property change to all selected elements */ + for (Iterator<EObject> i = eObjectList.iterator(); i.hasNext();) { + EObject nextObject = i.next(); + compoundCommand.append(SetCommand.create(editingDomain, nextObject, getFeature(), value)); + } + editingDomain.getCommandStack().execute(compoundCommand); + } + } + } + + protected EAttribute getAttribute() { + EAttribute attribute = null; + for (EAttribute eAttribute : PropertiesPackage.eINSTANCE.getHyperlinkWidgetStyle().getEAllAttributes()) { + if (eAttribute.getEType().equals(getFeatures())) { + attribute = eAttribute; + break; + } + } + return attribute; + } + + public static List<String> convertPropertiesToUI(List<FontFormat> font) { + List<String> formats = new ArrayList<String>(); + for (FontFormat format : font) { + if (format.getValue() == 1) { + formats.add(ITALIC); + } else if (format.getValue() == 2) { + formats.add(BOLD); + } else if (format.getValue() == 3) { + formats.add(UNDERLINE); + } else if (format.getValue() == 4) { + formats.add(STRIKE_THROUGH); + } + } + + return formats; + } +} diff --git a/incubation/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/properties/editor/properties/sections/properties/labelwidgetstyle/LabelWidgetStyleFontFormatPropertySectionSpec.java b/incubation/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/properties/editor/properties/sections/properties/labelwidgetstyle/LabelWidgetStyleFontFormatPropertySectionSpec.java index e2aa68cd0b..42f69b391f 100644 --- a/incubation/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/properties/editor/properties/sections/properties/labelwidgetstyle/LabelWidgetStyleFontFormatPropertySectionSpec.java +++ b/incubation/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/properties/editor/properties/sections/properties/labelwidgetstyle/LabelWidgetStyleFontFormatPropertySectionSpec.java @@ -26,6 +26,7 @@ import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; import org.eclipse.sirius.editor.properties.sections.common.AbstractCheckBoxGroupPropertySection; import org.eclipse.sirius.properties.LabelWidgetStyle; import org.eclipse.sirius.properties.PropertiesPackage; +import org.eclipse.sirius.properties.TextWidgetStyle; import org.eclipse.sirius.viewpoint.FontFormat; import org.eclipse.sirius.viewpoint.ViewpointPackage; import org.eclipse.swt.SWT; @@ -38,7 +39,7 @@ import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; /** - * Custom property section for label format to use more appropriate widgets. + * Use proper checkboxes for labels' font format property. * * @author pcdavid */ @@ -130,7 +131,7 @@ public class LabelWidgetStyleFontFormatPropertySectionSpec extends AbstractCheck protected String getDefaultFeatureAsText() { String returnStr = ""; if (eObject instanceof LabelWidgetStyle) { - for (String str : convertPropertiesToUI(((LabelWidgetStyle) eObject).getFontFormat())) { + for (String str : convertPropertiesToUI(((TextWidgetStyle) eObject).getFontFormat())) { if (returnStr.length() > 0) { returnStr = returnStr + (", ") + str; } else { diff --git a/incubation/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/properties/editor/properties/sections/properties/textwidgetstyle/TextWidgetStyleFontFormatPropertySectionSpec.java b/incubation/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/properties/editor/properties/sections/properties/textwidgetstyle/TextWidgetStyleFontFormatPropertySectionSpec.java new file mode 100644 index 0000000000..3b7bffb1d9 --- /dev/null +++ b/incubation/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/properties/editor/properties/sections/properties/textwidgetstyle/TextWidgetStyleFontFormatPropertySectionSpec.java @@ -0,0 +1,245 @@ +/******************************************************************************* + * Copyright (c) 2016 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.properties.editor.properties.sections.properties.textwidgetstyle; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EEnum; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.emf.edit.domain.IEditingDomainProvider; +import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; +import org.eclipse.sirius.editor.properties.sections.common.AbstractCheckBoxGroupPropertySection; +import org.eclipse.sirius.properties.LabelWidgetStyle; +import org.eclipse.sirius.properties.PropertiesPackage; +import org.eclipse.sirius.properties.TextWidgetStyle; +import org.eclipse.sirius.viewpoint.FontFormat; +import org.eclipse.sirius.viewpoint.ViewpointPackage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; + +/** + * Custom property section for label format to use more appropriate widgets. + * + * @author pcdavid + */ +public class TextWidgetStyleFontFormatPropertySectionSpec extends AbstractCheckBoxGroupPropertySection { + + private static final String BOLD = "Bold"; + + private static final String ITALIC = "Italic"; + + private static final String UNDERLINE = "Underline"; + + private static final String STRIKE_THROUGH = "Strike through"; + + private static final String TOOL_TIP = "The font formatting style to use for the label"; + + public TextWidgetStyleFontFormatPropertySectionSpec() { + buttonGroup = false; + } + + @Override + protected boolean isEqual(List<?> newList) { + List<String> value = TextWidgetStyleFontFormatPropertySectionSpec.convertPropertiesToUI(((TextWidgetStyle) eObject).getFontFormat()); + return value.equals(newList); + } + + @Override + protected List<?> getChoiceOfValues() { + List<String> values = new ArrayList<String>(); + values.add(BOLD); + values.add(ITALIC); + values.add(UNDERLINE); + values.add(STRIKE_THROUGH); + return values; + } + + protected List<FontFormat> getSelectedValue() { + List<?> possibleValues = getChoiceOfValues(); + List<Object> selectedValues = new ArrayList<Object>(); + List<FontFormat> fontFormat = new ArrayList<FontFormat>(); + + for (int i = 0; i < button.length; i++) { + if (button[i].getSelection()) + selectedValues.add(possibleValues.get(i)); + } + + if (selectedValues.size() > 0) { + for (Object selectedValue : selectedValues) { + if (selectedValue.equals(ITALIC)) { + fontFormat.add(FontFormat.ITALIC_LITERAL); + } + if (selectedValue.equals(BOLD)) { + fontFormat.add(FontFormat.BOLD_LITERAL); + } + if (selectedValue.equals(UNDERLINE)) { + fontFormat.add(FontFormat.UNDERLINE_LITERAL); + } + if (selectedValue.equals(STRIKE_THROUGH)) { + fontFormat.add(FontFormat.STRIKE_THROUGH_LITERAL); + } + } + } + + return fontFormat; + } + + @Override + protected EStructuralFeature getFeature() { + return PropertiesPackage.eINSTANCE.getTextWidgetStyle_FontFormat(); + } + + @Override + protected String getDefaultLabelText() { + return "Font Format"; + } + + @Override + protected String getFeatureAsText() { + String featureText; + final EStructuralFeature eFeature = getFeature(); + final IItemPropertyDescriptor propertyDescriptor = getPropertyDescriptor(eFeature); + if (propertyDescriptor != null) { + featureText = propertyDescriptor.getLabelProvider(eObject).getText(eObject.eGet(eFeature)); + return featureText; + } + return getDefaultFeatureAsText(); + } + + @Override + protected String getDefaultFeatureAsText() { + String returnStr = ""; + if (eObject instanceof LabelWidgetStyle) { + for (String str : convertPropertiesToUI(((TextWidgetStyle) eObject).getFontFormat())) { + if (returnStr.length() > 0) { + returnStr = returnStr + (", ") + str; + } else { + returnStr = str; + } + } + } + return returnStr; + } + + @Override + protected String getLabelText() { + return super.getLabelText() + ":"; + } + + protected EEnum getFeatures() { + return ViewpointPackage.eINSTANCE.getFontFormat(); + + } + + @Override + public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) { + super.createControls(parent, tabbedPropertySheetPage); + FormData data; + + // Create a new composite to add button in fake group + Composite fakeGroup = getWidgetFactory().createComposite(composite); + RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL); + rowLayout.marginLeft = 0; + rowLayout.spacing = 5; + fakeGroup.setLayout(rowLayout); + data = new FormData(); + data.left = new FormAttachment(0, LABEL_WIDTH); + data.right = new FormAttachment(100, 0); + data.top = new FormAttachment(0, ITabbedPropertyConstants.VSPACE); + fakeGroup.setLayoutData(data); + + for (int i = 0; i < button.length; i++) { + button[i].setParent(fakeGroup); + button[i].setLayoutData(null); + } + + data = new FormData(); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(fakeGroup, -ITabbedPropertyConstants.HSPACE - 20); + data.top = new FormAttachment(fakeGroup, 0, SWT.CENTER); + nameLabel.setLayoutData(data); + nameLabel.setToolTipText(TOOL_TIP); + + data = new FormData(); + CLabel help = getWidgetFactory().createCLabel(composite, ""); + data.top = new FormAttachment(nameLabel, 0, SWT.TOP); + data.left = new FormAttachment(nameLabel); + help.setLayoutData(data); + help.setImage(getHelpIcon()); + help.setToolTipText(TOOL_TIP); + + } + + @Override + public void handleSelectionChanged() { + boolean equals = isEqual(getSelectedValues()); + + if (!equals) { + EditingDomain editingDomain = ((IEditingDomainProvider) getPart()).getEditingDomain(); + Object value = getSelectedValue(); + + if (eObjectList.size() == 1) { + // apply the property change to single selected object + editingDomain.getCommandStack().execute(SetCommand.create(editingDomain, eObject, getFeature(), value)); + } else { + CompoundCommand compoundCommand = new CompoundCommand(); + /* apply the property change to all selected elements */ + for (Iterator<EObject> i = eObjectList.iterator(); i.hasNext();) { + EObject nextObject = i.next(); + compoundCommand.append(SetCommand.create(editingDomain, nextObject, getFeature(), value)); + } + editingDomain.getCommandStack().execute(compoundCommand); + } + } + } + + protected EAttribute getAttribute() { + EAttribute attribute = null; + for (EAttribute eAttribute : PropertiesPackage.eINSTANCE.getTextWidgetStyle().getEAllAttributes()) { + if (eAttribute.getEType().equals(getFeatures())) { + attribute = eAttribute; + break; + } + } + return attribute; + } + + public static List<String> convertPropertiesToUI(List<FontFormat> font) { + List<String> formats = new ArrayList<String>(); + for (FontFormat format : font) { + if (format.getValue() == 1) { + formats.add(ITALIC); + } else if (format.getValue() == 2) { + formats.add(BOLD); + } else if (format.getValue() == 3) { + formats.add(UNDERLINE); + } else if (format.getValue() == 4) { + formats.add(STRIKE_THROUGH); + } + } + + return formats; + } + +} |
