diff options
| author | Mélanie Bats | 2015-01-26 09:20:52 +0000 |
|---|---|---|
| committer | Laurent Redor | 2015-05-18 15:36:27 +0000 |
| commit | f8061e370b1f84329fcdecac18639fad1363dada (patch) | |
| tree | 9d185d2e2e06595a3f12b4ed0e36c6b72960e416 | |
| parent | 1fbed5da54c01c9279bf2e4ff358aa0574613f9f (diff) | |
| download | org.eclipse.sirius-f8061e370b1f84329fcdecac18639fad1363dada.tar.gz org.eclipse.sirius-f8061e370b1f84329fcdecac18639fad1363dada.tar.xz org.eclipse.sirius-f8061e370b1f84329fcdecac18639fad1363dada.zip | |
[424422] Update appearance views to support diagram reset, underline and
strike through
Update the appearance views to add the underline and strike through
buttons and support the diagram reset.
Bug : 424422
Change-Id: I6c4c7d8f3f1e3daead44ca3e87a9be0991ad3c42
Signed-off-by: Mélanie Bats <melanie.bats@obeo.fr>
3 files changed, 314 insertions, 3 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/properties/DiagramColorAndFontPropertySection.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/properties/DiagramColorAndFontPropertySection.java index 196351061c..188b6efa9e 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/properties/DiagramColorAndFontPropertySection.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/properties/DiagramColorAndFontPropertySection.java @@ -22,21 +22,32 @@ import org.eclipse.gmf.runtime.diagram.ui.internal.properties.Properties; import org.eclipse.gmf.runtime.diagram.ui.properties.sections.appearance.DiagramColorsAndFontsPropertySection; import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities; import org.eclipse.gmf.runtime.emf.core.util.PackageUtil; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter; import org.eclipse.sirius.diagram.business.api.query.EObjectQuery; import org.eclipse.sirius.diagram.ui.internal.refresh.diagram.ViewPropertiesSynchronizer; +import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; +import org.eclipse.sirius.diagram.ui.tools.api.image.DiagramImagesPath; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.style.ResetStylePropertiesToDefaultValuesAction; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.style.SetStyleToWorkspaceImageAction; import org.eclipse.sirius.diagram.ui.tools.internal.dialogs.ColorPalettePopup; import org.eclipse.sirius.viewpoint.description.DescriptionFactory; import org.eclipse.sirius.viewpoint.description.UserFixedColor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleAdapter; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; /** * Class necessary to remove default color option. @@ -47,6 +58,25 @@ import org.eclipse.swt.widgets.Button; @SuppressWarnings("restriction") public class DiagramColorAndFontPropertySection extends DiagramColorsAndFontsPropertySection { + /** button to set back the view to default color. */ + protected Button resetStylePropertiesToDefaultValuesButton; + + /** + * button to allow user to select an image in the workspace and set the + * selected image as view background image. + */ + protected Button setStyleToWorkspaceImageButton; + + /** + * button to set the font underlined. + */ + private Button fontUnderlineButton; + + /** + * button to set the font struck through. + */ + private Button fontStrikeThroughButton; + /** * {@inheritDoc} * @@ -135,4 +165,147 @@ public class DiagramColorAndFontPropertySection extends DiagramColorsAndFontsPro } + /** + * {@inheritDoc} + * + * @see org.eclipse.gmf.runtime.diagram.ui.properties.sections.appearance.ShapeColorsAndFontsPropertySection#createFontsGroup(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Composite createFontsGroup(final Composite parent) { + final Composite toolBar = super.createFontsGroup(parent); + + final Image imageUndo = DiagramUIPlugin.getPlugin().getBundledImage(DiagramImagesPath.UNDO_ICON); + final Image imageImage = DiagramUIPlugin.getPlugin().getBundledImage(DiagramImagesPath.IMAGE_ICON); + final Image imageUnderline = DiagramUIPlugin.getPlugin().getBundledImage(DiagramImagesPath.UNDERLINE_ICON); + final Image imageStrikeThrough = DiagramUIPlugin.getPlugin().getBundledImage(DiagramImagesPath.STRIKE_THROUGH_ICON); + + boolean isReadOnly = isReadOnly(); + + fontUnderlineButton = new Button(toolBar, SWT.TOGGLE); + fontUnderlineButton.setImage(imageUnderline); + fontUnderlineButton.setEnabled(!isReadOnly); + fontUnderlineButton.getAccessible().addAccessibleListener(new AccessibleAdapter() { + @Override + public void getName(final AccessibleEvent e) { + e.result = "Underline"; + } + }); + + fontStrikeThroughButton = new Button(toolBar, SWT.TOGGLE); + fontStrikeThroughButton.setImage(imageStrikeThrough); + fontStrikeThroughButton.setEnabled(!isReadOnly); + fontStrikeThroughButton.getAccessible().addAccessibleListener(new AccessibleAdapter() { + @Override + public void getName(final AccessibleEvent e) { + e.result = "StrikeThrough"; + } + }); + + new Label(toolBar, SWT.LEFT); + new Label(toolBar, SWT.LEFT); + new Label(toolBar, SWT.LEFT); + + setStyleToWorkspaceImageButton = new Button(toolBar, SWT.PUSH); + setStyleToWorkspaceImageButton.setToolTipText(SetStyleToWorkspaceImageAction.SET_STYLE_TO_WORKSPACE_IMAGE_ACTION_NAME); + setStyleToWorkspaceImageButton.setImage(imageImage); + setStyleToWorkspaceImageButton.setEnabled(false); + + resetStylePropertiesToDefaultValuesButton = new Button(toolBar, SWT.PUSH); + resetStylePropertiesToDefaultValuesButton.setToolTipText(ResetStylePropertiesToDefaultValuesAction.ACTION_NAME); + resetStylePropertiesToDefaultValuesButton.setImage(imageUndo); + resetStylePropertiesToDefaultValuesButton.addSelectionListener(new ResetStylePropertiesToDefaultValuesSelectionAdapter(this)); + resetStylePropertiesToDefaultValuesButton.setEnabled(!isReadOnly); + + fontUnderlineButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent event) { + updateFontUnderline(); + } + }); + + fontStrikeThroughButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent event) { + updateFontStrikeThrough(); + } + }); + return toolBar; + } + + private void updateFontUnderline() { + // Update model in response to user + final List<ICommand> commands = new ArrayList<ICommand>(); + final Iterator<?> it = getInputIterator(); + + while (it.hasNext()) { + final IGraphicalEditPart ep = (IGraphicalEditPart) it.next(); + commands.add(createCommand(FONT_COMMAND_NAME, ((View) ep.getModel()).eResource(), new Runnable() { + + @Override + public void run() { + ep.setStructuralFeatureValue(NotationPackage.eINSTANCE.getFontStyle_Underline(), Boolean.valueOf(fontUnderlineButton.getSelection())); + } + })); + } + + executeAsCompositeCommand(FONT_COMMAND_NAME, commands); + } + + private void updateFontStrikeThrough() { + // Update model in response to user + final List<ICommand> commands = new ArrayList<ICommand>(); + final Iterator<?> it = getInputIterator(); + + while (it.hasNext()) { + final IGraphicalEditPart ep = (IGraphicalEditPart) it.next(); + commands.add(createCommand(FONT_COMMAND_NAME, ((View) ep.getModel()).eResource(), new Runnable() { + + @Override + public void run() { + ep.setStructuralFeatureValue(NotationPackage.eINSTANCE.getFontStyle_StrikeThrough(), Boolean.valueOf(fontStrikeThroughButton.getSelection())); + } + })); + } + + executeAsCompositeCommand(FONT_COMMAND_NAME, commands); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.gmf.runtime.diagram.ui.properties.sections.appearance.ShapeColorsAndFontsPropertySection#refresh() + */ + @Override + public void refresh() { + if (!isDisposed()) { + super.refresh(); + executeAsReadAction(new Runnable() { + + @Override + public void run() { + final IGraphicalEditPart ep = getSingleInput(); + if (ep != null) { + final View view = (View) ep.getModel(); + boolean isCustomizedView = ResetStylePropertiesToDefaultValuesSelectionAdapter.isCustomizedView(view); + final boolean isReadOnly = isReadOnly(); + if (resetStylePropertiesToDefaultValuesButton != null) { + resetStylePropertiesToDefaultValuesButton.setEnabled(!isReadOnly && isCustomizedView); + } + if (fontUnderlineButton != null) { + boolean underlined = (Boolean) ep.getStructuralFeatureValue(NotationPackage.eINSTANCE.getFontStyle_Underline()); + fontUnderlineButton.setSelection(underlined); + fontUnderlineButton.setEnabled(!isReadOnly); + } + if (fontStrikeThroughButton != null) { + boolean striked = (Boolean) ep.getStructuralFeatureValue(NotationPackage.eINSTANCE.getFontStyle_StrikeThrough()); + fontStrikeThroughButton.setSelection(striked); + fontStrikeThroughButton.setEnabled(!isReadOnly); + } + } + } + }); + } + } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/properties/DiagramConnectionAppearancePropertySection.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/properties/DiagramConnectionAppearancePropertySection.java index c238f78064..53ce0d0589 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/properties/DiagramConnectionAppearancePropertySection.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/properties/DiagramConnectionAppearancePropertySection.java @@ -25,6 +25,7 @@ import org.eclipse.gmf.runtime.diagram.ui.internal.properties.Properties; import org.eclipse.gmf.runtime.diagram.ui.properties.sections.appearance.ConnectionAppearancePropertySection; import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities; import org.eclipse.gmf.runtime.emf.core.util.PackageUtil; +import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.Routing; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.jface.dialogs.IDialogConstants; @@ -38,12 +39,17 @@ import org.eclipse.sirius.diagram.EdgeStyle; import org.eclipse.sirius.diagram.business.api.query.EObjectQuery; import org.eclipse.sirius.diagram.ui.internal.refresh.diagram.ViewPropertiesSynchronizer; import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; +import org.eclipse.sirius.diagram.ui.tools.api.image.DiagramImagesPath; import org.eclipse.sirius.diagram.ui.tools.internal.actions.style.ResetStylePropertiesToDefaultValuesAction; +import org.eclipse.sirius.diagram.ui.tools.internal.actions.style.SetStyleToWorkspaceImageAction; import org.eclipse.sirius.diagram.ui.tools.internal.dialogs.ColorPalettePopup; import org.eclipse.sirius.viewpoint.DSemanticDecorator; import org.eclipse.sirius.viewpoint.description.DescriptionFactory; import org.eclipse.sirius.viewpoint.description.UserFixedColor; import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleAdapter; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; @@ -52,6 +58,7 @@ import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; import org.eclipse.ui.IWorkbenchPart; /** @@ -66,9 +73,25 @@ public class DiagramConnectionAppearancePropertySection extends ConnectionAppear /** button to set back the view to default color. */ protected Button resetStylePropertiesToDefaultValuesButton; + /** + * button to allow user to select an image in the workspace and set the + * selected image as view background image. + */ + protected Button setStyleToWorkspaceImageButton; + private Composite routingGroups; /** + * button to set the font underlined. + */ + private Button fontUnderlineButton; + + /** + * button to set the font struck trough. + */ + private Button fontStrikeThroughButton; + + /** * {@inheritDoc} * * @see org.eclipse.gmf.runtime.diagram.ui.properties.sections.appearance.ColorsAndFontsPropertySection#changeColor(org.eclipse.swt.events.SelectionEvent, @@ -164,18 +187,105 @@ public class DiagramConnectionAppearancePropertySection extends ConnectionAppear protected Composite createFontsGroup(final Composite parent) { final Composite toolBar = super.createFontsGroup(parent); - final String path = "icons/undo_edit.gif"; - final Image image = DiagramUIPlugin.getPlugin().getBundledImage(path); + final Image imageUndo = DiagramUIPlugin.getPlugin().getBundledImage(DiagramImagesPath.UNDO_ICON); + final Image imageImage = DiagramUIPlugin.getPlugin().getBundledImage(DiagramImagesPath.IMAGE_ICON); + final Image imageUnderline = DiagramUIPlugin.getPlugin().getBundledImage(DiagramImagesPath.UNDERLINE_ICON); + final Image imageStrikeThrough = DiagramUIPlugin.getPlugin().getBundledImage(DiagramImagesPath.STRIKE_THROUGH_ICON); + + boolean isReadOnly = isReadOnly(); + + fontUnderlineButton = new Button(toolBar, SWT.TOGGLE); + fontUnderlineButton.setImage(imageUnderline); + fontUnderlineButton.setEnabled(!isReadOnly); + fontUnderlineButton.getAccessible().addAccessibleListener(new AccessibleAdapter() { + @Override + public void getName(final AccessibleEvent e) { + e.result = "Underline"; + } + }); + + fontStrikeThroughButton = new Button(toolBar, SWT.TOGGLE); + fontStrikeThroughButton.setImage(imageStrikeThrough); + fontStrikeThroughButton.setEnabled(!isReadOnly); + fontStrikeThroughButton.getAccessible().addAccessibleListener(new AccessibleAdapter() { + @Override + public void getName(final AccessibleEvent e) { + e.result = "StrikeThrough"; + } + }); + + new Label(toolBar, SWT.LEFT); + new Label(toolBar, SWT.LEFT); + new Label(toolBar, SWT.LEFT); + + setStyleToWorkspaceImageButton = new Button(toolBar, SWT.PUSH); + setStyleToWorkspaceImageButton.setToolTipText(SetStyleToWorkspaceImageAction.SET_STYLE_TO_WORKSPACE_IMAGE_ACTION_NAME); + setStyleToWorkspaceImageButton.setImage(imageImage); + setStyleToWorkspaceImageButton.setEnabled(false); resetStylePropertiesToDefaultValuesButton = new Button(toolBar, SWT.PUSH); resetStylePropertiesToDefaultValuesButton.setToolTipText(ResetStylePropertiesToDefaultValuesAction.ACTION_NAME); - resetStylePropertiesToDefaultValuesButton.setImage(image); + resetStylePropertiesToDefaultValuesButton.setImage(imageUndo); resetStylePropertiesToDefaultValuesButton.addSelectionListener(new ResetStylePropertiesToDefaultValuesSelectionAdapter(this)); resetStylePropertiesToDefaultValuesButton.setEnabled(!isReadOnly()); + fontUnderlineButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent event) { + updateFontUnderline(); + } + }); + + fontStrikeThroughButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(final SelectionEvent event) { + updateFontStrikeThrough(); + } + }); return toolBar; } + private void updateFontUnderline() { + // Update model in response to user + final List<ICommand> commands = new ArrayList<ICommand>(); + final Iterator<?> it = getInputIterator(); + + while (it.hasNext()) { + final IGraphicalEditPart ep = (IGraphicalEditPart) it.next(); + commands.add(createCommand(FONT_COMMAND_NAME, ((View) ep.getModel()).eResource(), new Runnable() { + + @Override + public void run() { + ep.setStructuralFeatureValue(NotationPackage.eINSTANCE.getFontStyle_Underline(), Boolean.valueOf(fontUnderlineButton.getSelection())); + } + })); + } + + executeAsCompositeCommand(FONT_COMMAND_NAME, commands); + + } + + private void updateFontStrikeThrough() { + // Update model in response to user + final List<ICommand> commands = new ArrayList<ICommand>(); + final Iterator<?> it = getInputIterator(); + + while (it.hasNext()) { + final IGraphicalEditPart ep = (IGraphicalEditPart) it.next(); + commands.add(createCommand(FONT_COMMAND_NAME, ((View) ep.getModel()).eResource(), new Runnable() { + + @Override + public void run() { + ep.setStructuralFeatureValue(NotationPackage.eINSTANCE.getFontStyle_StrikeThrough(), Boolean.valueOf(fontStrikeThroughButton.getSelection())); + } + })); + } + + executeAsCompositeCommand(FONT_COMMAND_NAME, commands); + } + /** * Overridden to access to the routing group. * @@ -281,6 +391,16 @@ public class DiagramConnectionAppearancePropertySection extends ConnectionAppear boolean isCustomizedView = ResetStylePropertiesToDefaultValuesSelectionAdapter.isCustomizedView(view); resetStylePropertiesToDefaultValuesButton.setEnabled(!isReadOnly && isCustomizedView); enableRoutingGroup(hasBracketStyle); + if (fontUnderlineButton != null) { + boolean underlined = (Boolean) ep.getStructuralFeatureValue(NotationPackage.eINSTANCE.getFontStyle_Underline()); + fontUnderlineButton.setSelection(underlined); + fontUnderlineButton.setEnabled(!isReadOnly); + } + if (fontStrikeThroughButton != null) { + boolean striked = (Boolean) ep.getStructuralFeatureValue(NotationPackage.eINSTANCE.getFontStyle_StrikeThrough()); + fontStrikeThroughButton.setSelection(striked); + fontStrikeThroughButton.setEnabled(!isReadOnly); + } } } }); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/properties/ResetStylePropertiesToDefaultValuesSelectionAdapter.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/properties/ResetStylePropertiesToDefaultValuesSelectionAdapter.java index e7d4951738..54e91658d9 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/properties/ResetStylePropertiesToDefaultValuesSelectionAdapter.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/properties/ResetStylePropertiesToDefaultValuesSelectionAdapter.java @@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.diagram.ui.properties.sections.appearance.ColorsA import org.eclipse.gmf.runtime.notation.View; import org.eclipse.sirius.diagram.DDiagram; import org.eclipse.sirius.diagram.DDiagramElement; +import org.eclipse.sirius.diagram.DSemanticDiagram; import org.eclipse.sirius.diagram.business.api.query.DDiagramElementQuery; import org.eclipse.sirius.diagram.ui.business.api.query.ViewQuery; import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramContainerEditPart; @@ -75,6 +76,23 @@ public class ResetStylePropertiesToDefaultValuesSelectionAdapter extends Selecti customizedViews.put(notationView, dDiagramElement); oldStyles.put(graphicalEditPart, dDiagramElement.getStyle()); } + } else if (semanticElement instanceof DSemanticDiagram) { + // If a diagram is selected, reset all the children + for (Object graphicalEditParChild : graphicalEditPart.getChildren()) { + if (!(graphicalEditParChild instanceof IGraphicalEditPart)) { + continue; + } + IGraphicalEditPart subGraphicalEditPart = (IGraphicalEditPart) graphicalEditParChild; + View subNotationView = subGraphicalEditPart.getNotationView(); + EObject subSemanticElement = subGraphicalEditPart.resolveSemanticElement(); + if (subSemanticElement instanceof DDiagramElement + && (new DDiagramElementQuery((DDiagramElement) subSemanticElement).isCustomized() || new ViewQuery(subNotationView).isCustomized())) { + customizedViews.put(subNotationView, (DDiagramElement) subSemanticElement); + oldStyles.put(subGraphicalEditPart, ((DDiagramElement) subSemanticElement).getStyle()); + } else if (dDiagramElement == null && new ViewQuery(subNotationView).isCustomized()) { + customizedViews.put(subNotationView, dDiagramElement); + } + } } else if (dDiagramElement == null && new ViewQuery(notationView).isCustomized()) { customizedViews.put(notationView, dDiagramElement); } |
