diff options
| author | Pierre-Charles David | 2016-05-17 13:46:39 +0000 |
|---|---|---|
| committer | Pierre-Charles David | 2016-05-17 15:27:40 +0000 |
| commit | 1e316ed241f522ceba48967ab46601b5bb777104 (patch) | |
| tree | 8ccbb3686f6c073218e67b658c0ed5487ba71be6 | |
| parent | 5586c61206d83a0cb7c87149200c71f4df4d3f36 (diff) | |
| download | org.eclipse.sirius-1e316ed241f522ceba48967ab46601b5bb777104.tar.gz org.eclipse.sirius-1e316ed241f522ceba48967ab46601b5bb777104.tar.xz org.eclipse.sirius-1e316ed241f522ceba48967ab46601b5bb777104.zip | |
[482528] Use proper checkboxes to configure font formats
Bug: 482528
Change-Id: I08898f30c9e91d6fff59bde65eea9e3c320ff0ea
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
3 files changed, 493 insertions, 3 deletions
diff --git a/incubation/org.eclipse.sirius.editor.properties/plugin.xml b/incubation/org.eclipse.sirius.editor.properties/plugin.xml index 5fdead39da..0106c25e7d 100644 --- a/incubation/org.eclipse.sirius.editor.properties/plugin.xml +++ b/incubation/org.eclipse.sirius.editor.properties/plugin.xml @@ -117,7 +117,7 @@ <input type="org.eclipse.sirius.properties.HyperlinkWidgetStyle"/> </propertySection> <propertySection - class="org.eclipse.sirius.properties.editor.properties.sections.properties.labelwidgetstyle.LabelWidgetStyleFontFormatPropertySection" + class="org.eclipse.sirius.properties.editor.properties.sections.properties.labelwidgetstyle.LabelWidgetStyleFontFormatPropertySectionSpec" id="properties.section.labelWidgetStyle.FontFormat" filter="org.eclipse.sirius.properties.editor.properties.filters.properties.labelwidgetstyle.LabelWidgetStyleFontFormatFilter" afterSection="properties.section.labelWidgetStyle.ForegroundColor" @@ -156,7 +156,7 @@ <input type="org.eclipse.sirius.properties.LabelWidgetStyle"/> </propertySection> <propertySection - class="org.eclipse.sirius.properties.editor.properties.sections.properties.textwidgetstyle.TextWidgetStyleFontFormatPropertySection" + class="org.eclipse.sirius.properties.editor.properties.sections.properties.labelwidgetstyle.LabelWidgetStyleFontFormatPropertySectionSpec" id="properties.section.textWidgetStyle.FontFormat" filter="org.eclipse.sirius.properties.editor.properties.filters.properties.textwidgetstyle.TextWidgetStyleFontFormatFilter" afterSection="properties.section.textWidgetStyle.ForegroundColor" @@ -195,7 +195,7 @@ <input type="org.eclipse.sirius.properties.TextWidgetStyle"/> </propertySection> <propertySection - class="org.eclipse.sirius.properties.editor.properties.sections.properties.widgetstyle.WidgetStyleLabelFontFormatPropertySection" + class="org.eclipse.sirius.properties.editor.properties.sections.properties.widgetstyle.WidgetStyleLabelFontFormatPropertySectionSpec" id="properties.section.widgetStyle.LabelFontFormat" filter="org.eclipse.sirius.properties.editor.properties.filters.properties.widgetstyle.WidgetStyleLabelFontFormatFilter" afterSection="properties.section.widgetStyle.LabelForegroundColor" 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 new file mode 100644 index 0000000000..e2aa68cd0b --- /dev/null +++ b/incubation/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/properties/editor/properties/sections/properties/labelwidgetstyle/LabelWidgetStyleFontFormatPropertySectionSpec.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.labelwidgetstyle; + +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.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 LabelWidgetStyleFontFormatPropertySectionSpec 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 LabelWidgetStyleFontFormatPropertySectionSpec() { + buttonGroup = false; + } + + @Override + protected boolean isEqual(List<?> newList) { + List<String> value = LabelWidgetStyleFontFormatPropertySectionSpec.convertPropertiesToUI(((LabelWidgetStyle) 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.getLabelWidgetStyle_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(((LabelWidgetStyle) 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.getLabelWidgetStyle().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/widgetstyle/WidgetStyleLabelFontFormatPropertySectionSpec.java b/incubation/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/properties/editor/properties/sections/properties/widgetstyle/WidgetStyleLabelFontFormatPropertySectionSpec.java new file mode 100644 index 0000000000..d72a7bcbb5 --- /dev/null +++ b/incubation/org.eclipse.sirius.editor.properties/src/org/eclipse/sirius/properties/editor/properties/sections/properties/widgetstyle/WidgetStyleLabelFontFormatPropertySectionSpec.java @@ -0,0 +1,246 @@ +/******************************************************************************* + * 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.widgetstyle; + +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.WidgetStyle; +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 WidgetStyleLabelFontFormatPropertySectionSpec 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 WidgetStyleLabelFontFormatPropertySectionSpec() { + buttonGroup = false; + } + + @Override + protected boolean isEqual(List<?> newList) { + List<String> value = convertPropertiesToUI(((WidgetStyle) eObject).getLabelFontFormat()); + 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.getWidgetStyle_LabelFontFormat(); + } + + @Override + protected String getDefaultLabelText() { + return "Label 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(((WidgetStyle) eObject).getLabelFontFormat())) { + 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.getWidgetStyle().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; + } + + +} |
