From ba95fc98b231aaaa06a6f983003091c172836b2b Mon Sep 17 00:00:00 2001 From: Axel RICHARD Date: Mon, 11 Sep 2023 10:41:30 +0200 Subject: [PATCH] [2371] Improve color management in View Bug: https://github.com/eclipse-sirius/sirius-web/issues/2371 Signed-off-by: Axel RICHARD --- CHANGELOG.adoc | 3 +- .../project/edit/formdescriptioneditor.cy.js | 3 + .../cypress/e2e/project/edit/studio.cy.js | 117 +++++- .../src/color/getCSSColor.ts | 99 +++++ .../sirius-components-core/src/index.ts | 1 + .../src/renderer/Label.tsx | 16 +- .../src/renderer/edge/MarkerDefinitions.tsx | 67 +++- .../src/renderer/edge/MultiLabelEdge.tsx | 4 +- .../src/renderer/node/ImageNode.tsx | 7 +- .../src/renderer/node/ListNode.tsx | 5 +- .../src/renderer/node/RectangularNode.tsx | 4 +- .../representation/DiagramRepresentation.tsx | 4 + .../DiagramRepresentationMachine.ts | 4 + .../src/sprotty/DiagramServer.tsx | 9 +- .../src/sprotty/convertDiagram.tsx | 58 +-- .../src/sprotty/views/RectangleView.tsx | 2 +- .../src/ButtonWidget.tsx | 12 +- .../src/CheckboxWidget.tsx | 5 +- .../src/FlexboxContainerWidget.tsx | 4 +- .../src/Group.tsx | 4 +- .../src/LabelWidget.tsx | 3 +- .../src/LinkWidget.tsx | 3 +- .../src/ListWidget.tsx | 3 +- .../src/MultiSelectWidget.tsx | 5 +- .../src/RadioWidget.tsx | 3 +- .../src/SelectWidget.tsx | 5 +- .../src/TextAreaWidget.tsx | 5 +- .../src/TextfieldWidget.tsx | 5 +- .../src/ToolbarActionWidget.tsx | 18 +- .../handlers/ClickListItemEventHandler.java | 2 +- .../handlers/DeleteListItemEventHandler.java | 2 +- .../handlers/EditCheckboxEventHandler.java | 2 +- .../handlers/EditMultiSelectEventHandler.java | 2 +- .../forms/handlers/EditRadioEventHandler.java | 2 +- .../handlers/EditRichTextEventHandler.java | 2 +- .../handlers/EditSelectEventHandler.java | 2 +- .../handlers/EditTextfieldEventHandler.java | 2 +- .../handlers/PushButtonEventHandler.java | 2 +- .../EditCheckboxEventHandlerTests.java | 2 +- .../EditMultiSelectEventHandlerTests.java | 2 +- .../handlers/EditRadioEventHandlerTests.java | 2 +- .../handlers/EditSelectEventHandlerTests.java | 2 +- .../EditTextfieldEventHandlerTests.java | 2 +- .../handlers/ListItemEventHandlersTests.java | 4 +- .../handlers/PushButtonEventHandlerTests.java | 2 +- .../src/groups/Group.tsx | 4 +- .../ButtonPropertySection.tsx | 12 +- .../CheckboxPropertySection.tsx | 6 +- .../FlexboxContainerPropertySection.tsx | 3 +- .../LabelWidgetPropertySection.tsx | 5 +- .../propertysections/LinkPropertySection.tsx | 5 +- .../propertysections/ListPropertySection.tsx | 4 +- .../MultiSelectPropertySection.tsx | 6 +- .../propertysections/RadioPropertySection.tsx | 5 +- .../SelectPropertySection.tsx | 6 +- .../TextfieldPropertySection.tsx | 7 +- .../src/toolbaraction/ToolbarAction.tsx | 12 +- .../src/ReferencePreview.tsx | 4 +- .../ValuedReferenceAutocomplete.tsx | 6 +- ...ereotypeDescriptionRegistryConfigurer.java | 36 +- .../StudioProjectTemplatesInitializer.java | 5 + .../services/EditingContextActionHandler.java | 36 +- .../EditingDomainFactoryService.java | 6 + .../DefaultColorPalettesProvider.java | 189 ++++++++++ .../diagram/adapters/DiagramColorAdapter.java | 78 ++++ .../configuration/ViewEMFConfiguration.java | 3 + .../diagram/DiagramDescriptionValidator.java | 41 ++ .../emf/diagram/FormDescriptionValidator.java | 350 ++++++++++++++++++ .../emf/validation/ViewValidatorTests.java | 26 +- .../view/form/adapters/FormColorAdapter.java | 217 +++++++++++ .../util/services/ColorPaletteService.java | 47 +++ 71 files changed, 1415 insertions(+), 216 deletions(-) create mode 100644 packages/core/frontend/sirius-components-core/src/color/getCSSColor.ts create mode 100644 packages/view/backend/sirius-components-view-builder/src/main/java/org/eclipse/sirius/components/view/builder/providers/DefaultColorPalettesProvider.java create mode 100644 packages/view/backend/sirius-components-view-diagram/src/main/java/org/eclipse/sirius/components/view/diagram/adapters/DiagramColorAdapter.java create mode 100644 packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/diagram/FormDescriptionValidator.java create mode 100644 packages/view/backend/sirius-components-view-form/src/main/java/org/eclipse/sirius/components/view/form/adapters/FormColorAdapter.java create mode 100644 packages/view/backend/sirius-components-view/src/main/java/org/eclipse/sirius/components/view/util/services/ColorPaletteService.java diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index bc7e4c5875d..7c4760c4e70 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -115,10 +115,11 @@ To illustrate this new feature, we contribute a new tool on the _Papaya Diagram_ - https://github.com/eclipse-sirius/sirius-web/issues/2261[#2261] [diagram] Change the handle used by edges depending on the position of the source and target - https://github.com/eclipse-sirius/sirius-web/issues/2265[#2265] [diagram] Update the viewport to show the current state of the selection - https://github.com/eclipse-sirius/sirius-web/issues/2368[#2368] [form] Remove useless reference to the GraphQL version of Google Guava - - https://github.com/eclipse-sirius/sirius-web/issues/2343[#2343] [emf] Add icon for type selection in new object modal. - https://github.com/eclipse-sirius/sirius-web/issues/2365[#2365] [diagram] Support key down and F2 to enable direct edit on edges on react-flow diagrams. - https://github.com/eclipse-sirius/sirius-web/issues/2358[#2358] [form] Adds diagnostic messages to the reference widget. +- https://github.com/eclipse-sirius/sirius-web/issues/2371[#2371] [view] Add new default color palettes along with the creation of a view (theme colors, mui colors...). +- https://github.com/eclipse-sirius/sirius-web/issues/2371[#2371] [view] Add new validation rules about colors for View diagrams & forms. == v2023.8.0 diff --git a/integration-tests/cypress/e2e/project/edit/formdescriptioneditor.cy.js b/integration-tests/cypress/e2e/project/edit/formdescriptioneditor.cy.js index 7d0ca907a96..df84c77f5cf 100644 --- a/integration-tests/cypress/e2e/project/edit/formdescriptioneditor.cy.js +++ b/integration-tests/cypress/e2e/project/edit/formdescriptioneditor.cy.js @@ -132,6 +132,7 @@ describe('/projects/:projectId/edit - FormDescriptionEditor', () => { it('display the page of the element selected', () => { // Creates a second page + cy.getByTestId('New Form Description').click(); cy.getByTestId('New Form Description-more').should('be.enabled').click(); cy.getByTestId('treeitem-contextmenu').findByTestId('new-object').click(); cy.getByTestId('childCreationDescription').children('[role="button"]').invoke('text').should('have.length.gt', 1); @@ -139,6 +140,7 @@ describe('/projects/:projectId/edit - FormDescriptionEditor', () => { cy.getByTestId('create-object').click(); // Adds a widget to the first page cy.getByTestId('PageDescription').eq(0).dblclick(); + cy.getByTestId('GroupDescription').eq(0).click(); cy.getByTestId('GroupDescription-more').eq(0).should('be.enabled').click(); cy.getByTestId('treeitem-contextmenu').findByTestId('new-object').click(); cy.getByTestId('childCreationDescription').children('[role="button"]').invoke('text').should('have.length.gt', 1); @@ -150,6 +152,7 @@ describe('/projects/:projectId/edit - FormDescriptionEditor', () => { cy.getByTestId('create-object').click(); // Adds a widget to the second page cy.getByTestId('PageDescription').eq(1).dblclick(); + cy.getByTestId('GroupDescription').eq(1).click(); cy.getByTestId('GroupDescription-more').eq(1).should('be.enabled').click(); cy.getByTestId('treeitem-contextmenu').findByTestId('new-object').click(); cy.getByTestId('childCreationDescription').children('[role="button"]').invoke('text').should('have.length.gt', 1); diff --git a/integration-tests/cypress/e2e/project/edit/studio.cy.js b/integration-tests/cypress/e2e/project/edit/studio.cy.js index e15b10eb77d..858fd0f70e5 100644 --- a/integration-tests/cypress/e2e/project/edit/studio.cy.js +++ b/integration-tests/cypress/e2e/project/edit/studio.cy.js @@ -112,7 +112,7 @@ describe('/projects/:projectId/edit - Studio', () => { cy.get('[data-value="Target Edge End Reconnection Tool"]').should('not.exist'); }); - it.only('Check the precondition on tools', () => { + it('Check the precondition on tools', () => { cy.getByTestId('ViewNewModel').dblclick(); cy.getByTestId('View').dblclick(); cy.get('[data-testid$=" Diagram Description"]').dblclick(); @@ -127,13 +127,18 @@ describe('/projects/:projectId/edit - Studio', () => { cy.getByTestId('Name').clear(); cy.getByTestId('Name').type('TestTool'); - cy.get('[title="Back to the homepage"]').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/projects'); - cy.getByTestId('create').click(); - - cy.url().should('eq', Cypress.config().baseUrl + '/new/project'); - cy.getByTestId('name').type('Instance'); - cy.getByTestId('create-project').click(); + cy.get('[title="Back to the homepage"]') + .click() + .then(() => { + cy.url().should('eq', Cypress.config().baseUrl + '/projects'); + }); + cy.getByTestId('create') + .click() + .then(() => { + cy.url().should('eq', Cypress.config().baseUrl + '/new/project'); + cy.getByTestId('name').type('Instance'); + cy.getByTestId('create-project').click(); + }); cy.getByTestId('empty').click(); cy.getByTestId('Others...-more').click(); @@ -152,7 +157,7 @@ describe('/projects/:projectId/edit - Studio', () => { cy.getByTestId('create-representation').click(); cy.getByTestId('Diagram').should('exist'); cy.getByTestId('Diagram') - .click() + .click('left') .then(() => { cy.getByTestId('New Entity1 - Tool').should('exist'); cy.getByTestId('New Entity2 - Tool').should('exist'); @@ -160,11 +165,103 @@ describe('/projects/:projectId/edit - Studio', () => { cy.getByTestId('New Entity1 - Tool').click(); }); cy.getByTestId('Diagram') - .click() + .click('center') .then(() => { cy.getByTestId('New Entity1 - Tool').should('exist'); cy.getByTestId('New Entity2 - Tool').should('exist'); cy.getByTestId('TestTool - Tool').should('exist'); }); }); + + it('Check node style description has default colors', () => { + cy.getByTestId('ViewNewModel').dblclick(); + cy.getByTestId('View').dblclick(); + cy.get('[data-testid$=" Diagram Description"]').dblclick(); + cy.get('[data-testid$=" Diagram Description-more"]').click(); + cy.getByTestId('new-object').click(); + cy.getByTestId('childCreationDescription').click(); + cy.getByTestId('childCreationDescription').get('[data-value="Node Description"]').should('exist').click(); + cy.getByTestId('create-object').click(); + cy.getByTestId('Node').dblclick(); + cy.getByTestId('1').click(); + cy.getByTestId('Label Color').findByTestId('reference-value-black').should('exist'); + cy.getByTestId('Color').findByTestId('reference-value-white').should('exist'); + cy.getByTestId('Border Color').findByTestId('reference-value-black').should('exist'); + }); + + it('Check edge style description has default colors', () => { + cy.getByTestId('ViewNewModel').dblclick(); + cy.getByTestId('View').dblclick(); + cy.get('[data-testid$=" Diagram Description"]').dblclick(); + cy.get('[data-testid$=" Diagram Description-more"]').click(); + cy.getByTestId('new-object').click(); + cy.getByTestId('childCreationDescription').click(); + cy.getByTestId('childCreationDescription').get('[data-value="Edge Description"]').should('exist').click(); + cy.getByTestId('create-object').click(); + cy.getByTestId('Edge').dblclick(); + cy.getByTestId('EdgeStyle').click(); + + cy.getByTestId('Color').findByTestId('reference-value-black').should('exist'); + }); + + it('Check textfield widget style description has default colors', () => { + cy.getByTestId('ViewNewModel').dblclick(); + cy.getByTestId('View-more').click(); + cy.getByTestId('new-object').click(); + cy.getByTestId('childCreationDescription').click(); + cy.getByTestId('childCreationDescription').get('[data-value="Form Description"]').should('exist').click(); + cy.getByTestId('create-object').click(); + cy.getByTestId('New Form Description').dblclick(); + cy.getByTestId('PageDescription').dblclick(); + cy.getByTestId('GroupDescription').dblclick(); + cy.getByTestId('GroupDescription-more').click(); + cy.getByTestId('new-object').click(); + cy.getByTestId('childCreationDescription').click(); + cy.getByTestId('childCreationDescription') + .get('[data-value="Widgets Textfield Description"]') + .should('exist') + .click(); + cy.getByTestId('create-object').click(); + cy.getByTestId('TextfieldDescription-more').click(); + cy.getByTestId('new-object').click(); + cy.getByTestId('childCreationDescription').click(); + cy.getByTestId('childCreationDescription') + .get('[data-value="Style Textfield Description Style"]') + .should('exist') + .click(); + cy.getByTestId('create-object').click(); + cy.getByTestId('TextfieldDescriptionStyle').click(); + + cy.getByTestId('Background Color').findByTestId('reference-value-transparent').should('exist'); + cy.getByTestId('Foreground Color').findByTestId('reference-value-theme.palette.text.primary').should('exist'); + }); + + it('Check default color palettes', () => { + cy.getByTestId('ViewNewModel').dblclick(); + cy.getByTestId('View').dblclick(); + cy.getByTestId('Theme Colors Palette').dblclick(); + cy.getByTestId('theme.palette.primary.main').should('exist'); + cy.getByTestId('Special Colors Palette').dblclick(); + cy.getByTestId('black').should('exist'); + cy.getByTestId('Amber Colors Palette').dblclick(); + cy.getByTestId('amber 50').should('exist'); + cy.getByTestId('Blue Colors Palette').should('exist'); + cy.getByTestId('BlueGrey Colors Palette').should('exist'); + cy.getByTestId('Brown Colors Palette').should('exist'); + cy.getByTestId('Cyan Colors Palette').should('exist'); + cy.getByTestId('DeepOrange Colors Palette').should('exist'); + cy.getByTestId('DeepPurple Colors Palette').should('exist'); + cy.getByTestId('Green Colors Palette').should('exist'); + cy.getByTestId('Grey Colors Palette').should('exist'); + cy.getByTestId('Indigo Colors Palette').should('exist'); + cy.getByTestId('LightBlue Colors Palette').should('exist'); + cy.getByTestId('LightGreen Colors Palette').should('exist'); + cy.getByTestId('Lime Colors Palette').should('exist'); + cy.getByTestId('Orange Colors Palette').should('exist'); + cy.getByTestId('Pink Colors Palette').should('exist'); + cy.getByTestId('Purple Colors Palette').should('exist'); + cy.getByTestId('Red Colors Palette').should('exist'); + cy.getByTestId('Teal Colors Palette').should('exist'); + cy.getByTestId('Yellow Colors Palette').should('exist'); + }); }); diff --git a/packages/core/frontend/sirius-components-core/src/color/getCSSColor.ts b/packages/core/frontend/sirius-components-core/src/color/getCSSColor.ts new file mode 100644 index 00000000000..c5424238666 --- /dev/null +++ b/packages/core/frontend/sirius-components-core/src/color/getCSSColor.ts @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2023 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +import { + amber, + blue, + blueGrey, + brown, + common, + cyan, + deepOrange, + deepPurple, + green, + grey, + indigo, + lightBlue, + lightGreen, + lime, + orange, + pink, + purple, + red, + teal, + yellow, +} from '@material-ui/core/colors'; +import { Theme } from '@material-ui/core/styles'; + +const muiColors = { + amber: amber, + blue: blue, + blueGrey: blueGrey, + brown: brown, + common: common, + cyan: cyan, + deepOrange: deepOrange, + deepPurple: deepPurple, + green: green, + grey: grey, + indigo: indigo, + lightBlue: lightBlue, + lightGreen: lightGreen, + lime: lime, + orange: orange, + pink: pink, + purple: purple, + red: red, + teal: teal, + yellow: yellow, +}; + +export const getCSSColor = (value: string, theme: Theme): string | null => { + let cssColor: string | null = null; + if (value) { + if (value === 'theme.palette.primary.main') { + cssColor = theme.palette.primary.main; + } else if (value === 'theme.palette.primary.light') { + cssColor = theme.palette.primary.light; + } else if (value === 'theme.palette.primary.dark') { + cssColor = theme.palette.primary.dark; + } else if (value === 'theme.palette.secondary.main') { + cssColor = theme.palette.secondary.main; + } else if (value === 'theme.palette.secondary.light') { + cssColor = theme.palette.secondary.light; + } else if (value === 'theme.palette.secondary.dark') { + cssColor = theme.palette.secondary.dark; + } else if (value === 'theme.palette.text.primary') { + cssColor = theme.palette.text.primary; + } else if (value === 'theme.palette.text.disabled') { + cssColor = theme.palette.text.disabled; + } else if (value === 'theme.palette.text.hint') { + cssColor = theme.palette.text.hint; + } else if (value === 'theme.palette.error.main') { + cssColor = theme.palette.error.main; + } else if (value === 'theme.palette.error.light') { + cssColor = theme.palette.error.light; + } else if (value === 'theme.palette.error.dark') { + cssColor = theme.palette.error.dark; + } else { + const colorName: string = value.substring(0, value.indexOf('[')); + const colorValue: string = value.substring(value.indexOf('[') + 1, value.length - 1); + if (colorName && colorValue) { + cssColor = muiColors[colorName][colorValue]; + } + if (!cssColor) { + cssColor = value; + } + } + } + return cssColor; +}; diff --git a/packages/core/frontend/sirius-components-core/src/index.ts b/packages/core/frontend/sirius-components-core/src/index.ts index df1015211eb..90817ef8813 100644 --- a/packages/core/frontend/sirius-components-core/src/index.ts +++ b/packages/core/frontend/sirius-components-core/src/index.ts @@ -10,6 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +export * from './color/getCSSColor'; export * from './contexts/ServerContext'; export * from './contexts/ServerContext.types'; export * from './contexts/ToastContext'; diff --git a/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/Label.tsx b/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/Label.tsx index 61ac68f1a68..52cfca8112b 100644 --- a/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/Label.tsx +++ b/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/Label.tsx @@ -11,14 +11,21 @@ * Obeo - initial API and implementation *******************************************************************************/ -import { ServerContext, ServerContextValue } from '@eclipse-sirius/sirius-components-core'; +import { ServerContext, ServerContextValue, getCSSColor } from '@eclipse-sirius/sirius-components-core'; +import { Theme, useTheme } from '@material-ui/core/styles'; import { memo, useContext } from 'react'; import { LabelProps } from './Label.types'; import { DiagramDirectEditInput } from './direct-edit/DiagramDirectEditInput'; import { useDiagramDirectEdit } from './direct-edit/useDiagramDirectEdit'; -const labelStyle = (style: React.CSSProperties, faded: Boolean, transform: string): React.CSSProperties => { +const labelStyle = ( + theme: Theme, + style: React.CSSProperties, + faded: Boolean, + transform: string +): React.CSSProperties => { return { + ...style, transform, opacity: faded ? '0.4' : '', pointerEvents: 'all', @@ -26,11 +33,12 @@ const labelStyle = (style: React.CSSProperties, faded: Boolean, transform: strin flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-start', - ...style, + color: getCSSColor(String(style.color), theme) || undefined, }; }; export const Label = memo(({ diagramElementId, label, faded, transform }: LabelProps) => { + const theme: Theme = useTheme(); const { httpOrigin } = useContext(ServerContext); const { currentlyEditedLabelId, editingKey, setCurrentlyEditedLabelId, resetDirectEdit } = useDiagramDirectEdit(); @@ -56,7 +64,7 @@ export const Label = memo(({ diagramElementId, label, faded, transform }: LabelP data-id={label.id} data-testid={`Label - ${label.text}`} onDoubleClick={handleDoubleClick} - style={labelStyle(label.style, faded, transform)} + style={labelStyle(theme, label.style, faded, transform)} className="nopan"> {label.iconURL ? : ''} {label.text} diff --git a/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/edge/MarkerDefinitions.tsx b/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/edge/MarkerDefinitions.tsx index 674e24c3816..4746f3a1df7 100644 --- a/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/edge/MarkerDefinitions.tsx +++ b/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/edge/MarkerDefinitions.tsx @@ -11,6 +11,7 @@ * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { useTheme } from '@material-ui/core/styles'; import { useCallback } from 'react'; import { Edge, EdgeMarkerType, ReactFlowState, useStore } from 'reactflow'; @@ -118,7 +119,7 @@ const buildMarkerAttributes = ( }; }; -const buildArrow = (id: string, path: string, edgeColor: string, fill: boolean) => { +const buildArrow = (id: string, path: string, edgeColor: string | undefined, fill: boolean) => { return ( @@ -126,7 +127,7 @@ const buildArrow = (id: string, path: string, edgeColor: string, fill: boolean) ); }; -const buildDiamond = (id: string, path: string, edgeColor: string, fill: boolean) => { +const buildDiamond = (id: string, path: string, edgeColor: string | undefined, fill: boolean) => { return ( @@ -134,7 +135,7 @@ const buildDiamond = (id: string, path: string, edgeColor: string, fill: boolean ); }; -const buildCircle = (id: string, edgeColor: string, fill: boolean) => { +const buildCircle = (id: string, edgeColor: string | undefined, fill: boolean) => { return ( @@ -154,67 +155,89 @@ export const MarkerDefinitions = () => { const OutputArrow = ({ id, edgeColor }: MarkerProps) => { const theme = useTheme(); - const strokeColor: string = id.endsWith('--selected') ? theme.palette.primary.main : edgeColor; + const strokeColor: string | undefined = id.endsWith('--selected') + ? theme.palette.primary.main + : getCSSColor(edgeColor, theme) || undefined; return buildArrow(id, OutputArrowPath, strokeColor, false); }; const InputArrow = ({ id, edgeColor }: MarkerProps) => { const theme = useTheme(); - const strokeColor: string = id.endsWith('--selected') ? theme.palette.primary.main : edgeColor; + const strokeColor: string | undefined = id.endsWith('--selected') + ? theme.palette.primary.main + : getCSSColor(edgeColor, theme) || undefined; return buildArrow(id, InputArrowPath, strokeColor, false); }; const OutputClosedArrow = ({ id, edgeColor }: MarkerProps) => { const theme = useTheme(); - const strokeColor: string = id.endsWith('--selected') ? theme.palette.primary.main : edgeColor; + const strokeColor: string | undefined = id.endsWith('--selected') + ? theme.palette.primary.main + : getCSSColor(edgeColor, theme) || undefined; return buildArrow(id, OutputClosedArrowPath, strokeColor, false); }; const InputClosedArrow = ({ id, edgeColor }: MarkerProps) => { const theme = useTheme(); - const strokeColor: string = id.endsWith('--selected') ? theme.palette.primary.main : edgeColor; + const strokeColor: string | undefined = id.endsWith('--selected') + ? theme.palette.primary.main + : getCSSColor(edgeColor, theme) || undefined; return buildArrow(id, InputClosedArrowPath, strokeColor, false); }; const OutputFillClosedArrow = ({ id, edgeColor }: MarkerProps) => { const theme = useTheme(); - const strokeColor: string = id.endsWith('--selected') ? theme.palette.primary.main : edgeColor; + const strokeColor: string | undefined = id.endsWith('--selected') + ? theme.palette.primary.main + : getCSSColor(edgeColor, theme) || undefined; return buildArrow(id, OutputClosedArrowPath, strokeColor, true); }; const InputFillClosedArrow = ({ id, edgeColor }: MarkerProps) => { const theme = useTheme(); - const strokeColor: string = id.endsWith('--selected') ? theme.palette.primary.main : edgeColor; + const strokeColor: string | undefined = id.endsWith('--selected') + ? theme.palette.primary.main + : getCSSColor(edgeColor, theme) || undefined; return buildArrow(id, InputClosedArrowPath, strokeColor, true); }; const Diamond = ({ id, edgeColor }: MarkerProps) => { const theme = useTheme(); - const strokeColor: string = id.endsWith('--selected') ? theme.palette.primary.main : edgeColor; + const strokeColor: string | undefined = id.endsWith('--selected') + ? theme.palette.primary.main + : getCSSColor(edgeColor, theme) || undefined; return buildDiamond(id, DiamondPath, strokeColor, false); }; const FillDiamond = ({ id, edgeColor }: MarkerProps) => { const theme = useTheme(); - const strokeColor: string = id.endsWith('--selected') ? theme.palette.primary.main : edgeColor; + const strokeColor: string | undefined = id.endsWith('--selected') + ? theme.palette.primary.main + : getCSSColor(edgeColor, theme) || undefined; return buildDiamond(id, DiamondPath, strokeColor, true); }; const Circle = ({ id, edgeColor }: MarkerProps) => { const theme = useTheme(); - const strokeColor: string = id.endsWith('--selected') ? theme.palette.primary.main : edgeColor; + const strokeColor: string | undefined = id.endsWith('--selected') + ? theme.palette.primary.main + : getCSSColor(edgeColor, theme) || undefined; return buildCircle(id, strokeColor, false); }; const FillCircle = ({ id, edgeColor }: MarkerProps) => { const theme = useTheme(); - const strokeColor: string = id.endsWith('--selected') ? theme.palette.primary.main : edgeColor; + const strokeColor: string | undefined = id.endsWith('--selected') + ? theme.palette.primary.main + : getCSSColor(edgeColor, theme) || undefined; return buildCircle(id, strokeColor, true); }; const CrossedCircle = ({ id, edgeColor }: MarkerProps) => { const theme = useTheme(); - const strokeColor: string = id.endsWith('--selected') ? theme.palette.primary.main : edgeColor; + const strokeColor: string | undefined = id.endsWith('--selected') + ? theme.palette.primary.main + : getCSSColor(edgeColor, theme) || undefined; return ( @@ -226,7 +249,9 @@ const CrossedCircle = ({ id, edgeColor }: MarkerProps) => { const InputArrowWithDiamond = ({ id, edgeColor }: MarkerProps) => { const theme = useTheme(); - const strokeColor: string = id.endsWith('--selected') ? theme.palette.primary.main : edgeColor; + const strokeColor: string | undefined = id.endsWith('--selected') + ? theme.palette.primary.main + : getCSSColor(edgeColor, theme) || undefined; return ( @@ -237,7 +262,9 @@ const InputArrowWithDiamond = ({ id, edgeColor }: MarkerProps) => { const InputArrowWithFillDiamond = ({ id, edgeColor }: MarkerProps) => { const theme = useTheme(); - const strokeColor: string = id.endsWith('--selected') ? theme.palette.primary.main : edgeColor; + const strokeColor: string | undefined = id.endsWith('--selected') + ? theme.palette.primary.main + : getCSSColor(edgeColor, theme) || undefined; return ( @@ -248,7 +275,9 @@ const InputArrowWithFillDiamond = ({ id, edgeColor }: MarkerProps) => { const ClosedArrowWithVerticalBar = ({ id, edgeColor }: MarkerProps) => { const theme = useTheme(); - const strokeColor: string = id.endsWith('--selected') ? theme.palette.primary.main : edgeColor; + const strokeColor: string | undefined = id.endsWith('--selected') + ? theme.palette.primary.main + : getCSSColor(edgeColor, theme) || undefined; return ( @@ -259,7 +288,9 @@ const ClosedArrowWithVerticalBar = ({ id, edgeColor }: MarkerProps) => { const ClosedArrowWithDots = ({ id, edgeColor }: MarkerProps) => { const theme = useTheme(); - const strokeColor: string = id.endsWith('--selected') ? theme.palette.primary.main : edgeColor; + const strokeColor: string | undefined = id.endsWith('--selected') + ? theme.palette.primary.main + : getCSSColor(edgeColor, theme) || undefined; return ( diff --git a/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/edge/MultiLabelEdge.tsx b/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/edge/MultiLabelEdge.tsx index cfaf5bb4d1d..ed066d31ade 100644 --- a/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/edge/MultiLabelEdge.tsx +++ b/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/edge/MultiLabelEdge.tsx @@ -10,6 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { Theme, useTheme } from '@material-ui/core/styles'; import { memo, useCallback } from 'react'; import { BaseEdge, EdgeLabelRenderer, EdgeProps, Node, ReactFlowState, getSmoothStepPath, useStore } from 'reactflow'; @@ -26,8 +27,9 @@ const multiLabelEdgeStyle = ( faded: boolean | undefined ): React.CSSProperties => { const multiLabelEdgeStyle: React.CSSProperties = { - opacity: faded ? '0.4' : '', ...style, + opacity: faded ? '0.4' : '', + stroke: getCSSColor(String(style?.stroke), theme) || undefined, }; if (selected) { diff --git a/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/node/ImageNode.tsx b/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/node/ImageNode.tsx index a74ddf42c1f..c75a5ecfcd7 100644 --- a/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/node/ImageNode.tsx +++ b/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/node/ImageNode.tsx @@ -25,7 +25,12 @@ const imageNodeStyle = ( selected: boolean, faded: boolean ): React.CSSProperties => { - const imageNodeStyle: React.CSSProperties = { width: '100%', height: '100%', opacity: faded ? '0.4' : '', ...style }; + const imageNodeStyle: React.CSSProperties = { + ...style, + width: '100%', + height: '100%', + opacity: faded ? '0.4' : '', + }; if (selected) { imageNodeStyle.outline = `${theme.palette.primary.main} solid 1px`; } diff --git a/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/node/ListNode.tsx b/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/node/ListNode.tsx index 57719a5ec3a..479e4d5635e 100644 --- a/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/node/ListNode.tsx +++ b/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/node/ListNode.tsx @@ -11,6 +11,7 @@ * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { Theme, useTheme } from '@material-ui/core/styles'; import { memo } from 'react'; import { Handle, NodeProps, NodeResizer, Position } from 'reactflow'; @@ -26,13 +27,15 @@ const listNodeStyle = ( faded: boolean ): React.CSSProperties => { const listNodeStyle: React.CSSProperties = { + ...style, display: 'flex', flexDirection: 'column', alignItems: 'stretch', width: '100%', height: '100%', opacity: faded ? '0.4' : '', - ...style, + backgroundColor: getCSSColor(String(style.backgroundColor), theme) || undefined, + borderColor: getCSSColor(String(style.borderColor), theme) || undefined, }; if (selected) { listNodeStyle.outline = `${theme.palette.primary.main} solid 1px`; diff --git a/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/node/RectangularNode.tsx b/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/node/RectangularNode.tsx index 4d8d5cdd380..2512fc0312f 100644 --- a/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/node/RectangularNode.tsx +++ b/packages/diagrams/frontend/sirius-components-diagrams-reactflow/src/renderer/node/RectangularNode.tsx @@ -11,6 +11,7 @@ * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { Theme, useTheme } from '@material-ui/core/styles'; import React, { memo } from 'react'; import { Handle, NodeProps, NodeResizer, Position } from 'reactflow'; @@ -26,12 +27,13 @@ const rectangularNodeStyle = ( faded: boolean ): React.CSSProperties => { const rectangularNodeStyle: React.CSSProperties = { + ...style, display: 'flex', padding: '8px', width: '100%', height: '100%', opacity: faded ? '0.4' : '', - ...style, + backgroundColor: getCSSColor(String(style.backgroundColor), theme) || undefined, }; if (selected) { diff --git a/packages/diagrams/frontend/sirius-components-diagrams/src/representation/DiagramRepresentation.tsx b/packages/diagrams/frontend/sirius-components-diagrams/src/representation/DiagramRepresentation.tsx index 0387d126b32..5bfc1154d6e 100644 --- a/packages/diagrams/frontend/sirius-components-diagrams/src/representation/DiagramRepresentation.tsx +++ b/packages/diagrams/frontend/sirius-components-diagrams/src/representation/DiagramRepresentation.tsx @@ -22,6 +22,7 @@ import { } from '@eclipse-sirius/sirius-components-core'; import { SelectionDialog } from '@eclipse-sirius/sirius-components-selection'; import Typography from '@material-ui/core/Typography'; +import { Theme, useTheme } from '@material-ui/core/styles'; import makeStyles from '@material-ui/core/styles/makeStyles'; import { useMachine } from '@xstate/react'; import { useCallback, useContext, useEffect, useRef } from 'react'; @@ -346,6 +347,7 @@ export const DiagramRepresentation = ({ selection, setSelection, }: RepresentationComponentProps) => { + const theme: Theme = useTheme(); const diagramDomElement = useRef(null); const { httpOrigin } = useContext(ServerContext); const classes = useDiagramRepresentationStyle(); @@ -791,6 +793,7 @@ export const DiagramRepresentation = ({ updateRoutingPointsListener, httpOrigin, editingContextId, + theme, }; dispatch(initializeRepresentationEvent); } @@ -813,6 +816,7 @@ export const DiagramRepresentation = ({ dispatch, readOnly, updateRoutingPointsListener, + theme, ]); useEffect(() => { diff --git a/packages/diagrams/frontend/sirius-components-diagrams/src/representation/DiagramRepresentationMachine.ts b/packages/diagrams/frontend/sirius-components-diagrams/src/representation/DiagramRepresentationMachine.ts index 16e721ad4e0..d08393b029a 100644 --- a/packages/diagrams/frontend/sirius-components-diagrams/src/representation/DiagramRepresentationMachine.ts +++ b/packages/diagrams/frontend/sirius-components-diagrams/src/representation/DiagramRepresentationMachine.ts @@ -11,6 +11,7 @@ * Obeo - initial API and implementation *******************************************************************************/ import { Selection } from '@eclipse-sirius/sirius-components-core'; +import { Theme } from '@material-ui/core/styles'; import { MutableRefObject } from 'react'; import { MousePositionTracker, SModelElement, TYPES } from 'sprotty'; import { Point } from 'sprotty-protocol'; @@ -152,6 +153,7 @@ export type InitializeRepresentationEvent = { updateRoutingPointsListener: (routingPoints: Point[], edgeId: string) => void; httpOrigin: string; editingContextId: string; + theme: Theme; }; export type DiagramRepresentationEvent = @@ -426,6 +428,7 @@ export const diagramRepresentationMachine = Machine< updateRoutingPointsListener, httpOrigin, editingContextId, + theme, } = event as InitializeRepresentationEvent; const container = createDependencyInjectionContainer( @@ -452,6 +455,7 @@ export const diagramRepresentationMachine = Machine< diagramServer.setContextualPaletteListener(setContextualPalette); diagramServer.setContextualMenuListener(setContextualMenu); diagramServer.setHttpOrigin(httpOrigin); + diagramServer.setTheme(theme); diagramServer.setActiveToolListener(setActiveTool); diagramServer.setOnSelectElementListener(onSelectElement); diagramServer.setUpdateRoutingPointsListener(updateRoutingPointsListener); diff --git a/packages/diagrams/frontend/sirius-components-diagrams/src/sprotty/DiagramServer.tsx b/packages/diagrams/frontend/sirius-components-diagrams/src/sprotty/DiagramServer.tsx index 63f2fd5629c..f05eedc71fc 100644 --- a/packages/diagrams/frontend/sirius-components-diagrams/src/sprotty/DiagramServer.tsx +++ b/packages/diagrams/frontend/sirius-components-diagrams/src/sprotty/DiagramServer.tsx @@ -10,6 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +import { Theme } from '@material-ui/core/styles'; import { ActionHandlerRegistry, ApplyLabelEditAction, @@ -152,8 +153,8 @@ export class DiagramServer extends ModelSource { // Used to store the edge source element. diagramSource: SourceElement | null; currentRoot: Root = INITIAL_ROOT; - httpOrigin: string; + theme: Theme; firstOpen: boolean = true; getCursorOn: (element: any, diagramServer: DiagramServer) => CursorValue; @@ -381,7 +382,7 @@ export class DiagramServer extends ModelSource { handleSiriusUpdateModelAction(action: SiriusUpdateModelAction) { const { diagram, diagramDescription, readOnly } = action; if (diagram) { - const convertedDiagram = convertDiagram(diagram, diagramDescription, this.httpOrigin, readOnly); + const convertedDiagram = convertDiagram(diagram, diagramDescription, this.httpOrigin, readOnly, this.theme); const sprottyModel = this.modelFactory.createRoot(convertedDiagram); this.actionDispatcher.request(GetSelectionAction.create()).then((selectionResult) => { (sprottyModel as any).cursor = 'pointer'; @@ -700,6 +701,10 @@ export class DiagramServer extends ModelSource { this.httpOrigin = httpOrigin; } + setTheme(theme: Theme) { + this.theme = theme; + } + setActiveToolListener(setActiveTool) { this.setActiveTool = setActiveTool; } diff --git a/packages/diagrams/frontend/sirius-components-diagrams/src/sprotty/convertDiagram.tsx b/packages/diagrams/frontend/sirius-components-diagrams/src/sprotty/convertDiagram.tsx index 3edba93ef2b..2e8cf81c3c4 100644 --- a/packages/diagrams/frontend/sirius-components-diagrams/src/sprotty/convertDiagram.tsx +++ b/packages/diagrams/frontend/sirius-components-diagrams/src/sprotty/convertDiagram.tsx @@ -10,6 +10,8 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; +import { Theme } from '@material-ui/core/styles'; import { boundsFeature, connectableFeature, @@ -87,7 +89,8 @@ export const convertDiagram = ( gqlDiagram: GQLDiagram, diagramDescription: DiagramDescription, httpOrigin: string, - readOnly: boolean + readOnly: boolean, + theme: Theme ): Diagram => { const { id, @@ -110,10 +113,10 @@ export const convertDiagram = ( const { autoLayout } = diagramDescription; nodes .filter((node) => node.state !== GQLViewModifier.Hidden) - .map((node) => convertNode(diagram, node, httpOrigin, readOnly, autoLayout)); + .map((node) => convertNode(diagram, node, httpOrigin, readOnly, autoLayout, theme)); edges .filter((edge) => edge.state !== GQLViewModifier.Hidden) - .map((edge) => convertEdge(diagram, edge, httpOrigin, readOnly)); + .map((edge) => convertEdge(diagram, edge, httpOrigin, readOnly, theme)); return diagram; }; @@ -123,7 +126,8 @@ const convertNode = ( gqlNode: GQLNode, httpOrigin: string, readOnly: boolean, - autoLayout: boolean + autoLayout: boolean, + theme: Theme ): Node => { const { id, @@ -147,19 +151,19 @@ const convertNode = ( node.state = ViewModifier[GQLViewModifier[state]]; - const convertedLabel = convertLabel(node, label, httpOrigin, readOnly); + const convertedLabel = convertLabel(node, label, httpOrigin, readOnly, theme); (borderNodes ?? []) .filter((borderNode) => borderNode.state !== GQLViewModifier.Hidden) - .map((borderNode) => convertBorderNode(node, borderNode, httpOrigin, readOnly, autoLayout)); + .map((borderNode) => convertBorderNode(node, borderNode, httpOrigin, readOnly, autoLayout, theme)); (childNodes ?? []) .filter((childNode) => childNode.state !== GQLViewModifier.Hidden) - .map((childNode) => convertNode(node, childNode, httpOrigin, readOnly, autoLayout)); + .map((childNode) => convertNode(node, childNode, httpOrigin, readOnly, autoLayout, theme)); node.id = id; node.type = type; node.kind = `siriusComponents://graphical?representationType=Diagram&type=Node`; node.descriptionId = descriptionId; - node.style = convertNodeStyle(style, httpOrigin); + node.style = convertNodeStyle(style, theme, httpOrigin); node.editableLabel = !readOnly ? convertedLabel : null; node.targetObjectId = targetObjectId; node.targetObjectKind = targetObjectKind; @@ -176,7 +180,8 @@ const convertBorderNode = ( gqlNode: GQLNode, httpOrigin: string, readOnly: boolean, - autoLayout: boolean + autoLayout: boolean, + theme: Theme ): BorderNode => { const { id, @@ -196,13 +201,13 @@ const convertBorderNode = ( const node: BorderNode = new BorderNode(); parentElement.add(node); - const convertedLabel = convertLabel(node, label, httpOrigin, readOnly); + const convertedLabel = convertLabel(node, label, httpOrigin, readOnly, theme); node.id = id; node.type = type.replace('node:', 'port:'); node.kind = `siriusComponents://graphical?representationType=Diagram&type=Node`; node.descriptionId = descriptionId; - node.style = convertNodeStyle(style, httpOrigin); + node.style = convertNodeStyle(style, theme, httpOrigin); node.editableLabel = !readOnly ? convertedLabel : null; node.targetObjectId = targetObjectId; node.targetObjectKind = targetObjectKind; @@ -264,7 +269,8 @@ const convertLabel = ( parentElement: SParentElement, gqlLabel: GQLLabel, httpOrigin: string, - readOnly: boolean + readOnly: boolean, + theme: Theme ): Label => { const { id, text, type, style, alignment, position, size } = gqlLabel; @@ -285,7 +291,7 @@ const convertLabel = ( const labelStyle: LabelStyle = new LabelStyle(); labelStyle.bold = bold; - labelStyle.color = color; + labelStyle.color = getCSSColor(color, theme); labelStyle.fontSize = fontSize; labelStyle.iconURL = iconURL; labelStyle.italic = italic; @@ -302,7 +308,7 @@ const convertLabel = ( return label; }; -const convertNodeStyle = (style: GQLINodeStyle, httpOrigin: string): INodeStyle | null => { +const convertNodeStyle = (style: GQLINodeStyle, theme: Theme, httpOrigin: string): INodeStyle | null => { let convertedStyle: INodeStyle | null = null; if (isImageNodeStyle(style)) { @@ -310,7 +316,7 @@ const convertNodeStyle = (style: GQLINodeStyle, httpOrigin: string): INodeStyle const imageNodeStyle = new ImageNodeStyle(); imageNodeStyle.imageURL = httpOrigin + imageURL; - imageNodeStyle.borderColor = borderColor; + imageNodeStyle.borderColor = getCSSColor(borderColor, theme); imageNodeStyle.borderSize = borderSize; imageNodeStyle.borderRadius = borderRadius; imageNodeStyle.borderStyle = LineStyle[GQLLineStyle[borderStyle]]; @@ -321,18 +327,18 @@ const convertNodeStyle = (style: GQLINodeStyle, httpOrigin: string): INodeStyle const svgNodeStyle = new ParametricSVGNodeStyle(); svgNodeStyle.svgURL = httpOrigin + svgURL; - svgNodeStyle.borderColor = borderColor; + svgNodeStyle.borderColor = getCSSColor(borderColor, theme); svgNodeStyle.borderSize = borderSize; svgNodeStyle.borderStyle = LineStyle[GQLLineStyle[borderStyle]]; - svgNodeStyle.backgroundColor = backgroundColor; + svgNodeStyle.backgroundColor = getCSSColor(backgroundColor, theme); convertedStyle = svgNodeStyle; } else if (isRectangularNodeStyle(style)) { const { color, borderColor, borderRadius, borderSize, borderStyle, withHeader } = style; const rectangularNodeStyle = new RectangularNodeStyle(); - rectangularNodeStyle.color = color; - rectangularNodeStyle.borderColor = borderColor; + rectangularNodeStyle.color = getCSSColor(color, theme); + rectangularNodeStyle.borderColor = getCSSColor(borderColor, theme); rectangularNodeStyle.borderRadius = borderRadius; rectangularNodeStyle.borderSize = borderSize; rectangularNodeStyle.borderStyle = LineStyle[GQLLineStyle[borderStyle]]; @@ -343,14 +349,14 @@ const convertNodeStyle = (style: GQLINodeStyle, httpOrigin: string): INodeStyle const { backgroundColor } = style; const iconLabelNodeStyle = new IconLabelNodeStyle(); - iconLabelNodeStyle.backgroundColor = backgroundColor; + iconLabelNodeStyle.backgroundColor = getCSSColor(backgroundColor, theme); convertedStyle = iconLabelNodeStyle; } return convertedStyle; }; -const convertEdge = (diagram: Diagram, gqlEdge: GQLEdge, httpOrigin: string, readOnly: boolean): Edge => { +const convertEdge = (diagram: Diagram, gqlEdge: GQLEdge, httpOrigin: string, readOnly: boolean, theme: Theme): Edge => { const { id, type, @@ -371,7 +377,7 @@ const convertEdge = (diagram: Diagram, gqlEdge: GQLEdge, httpOrigin: string, rea } = gqlEdge; const edgeStyle = new EdgeStyle(); - edgeStyle.color = style.color; + edgeStyle.color = getCSSColor(style.color, theme); edgeStyle.size = style.size; edgeStyle.lineStyle = LineStyle[GQLLineStyle[style.lineStyle]]; edgeStyle.sourceArrow = ArrowStyle[GQLArrowStyle[style.sourceArrow]]; @@ -384,11 +390,13 @@ const convertEdge = (diagram: Diagram, gqlEdge: GQLEdge, httpOrigin: string, rea edge.state = ViewModifier[GQLViewModifier[state]]; if (beginLabel) { - convertLabel(edge, beginLabel, httpOrigin, readOnly); + convertLabel(edge, beginLabel, httpOrigin, readOnly, theme); } - const convertedCenterLabel: Label | null = centerLabel ? convertLabel(edge, centerLabel, httpOrigin, readOnly) : null; + const convertedCenterLabel: Label | null = centerLabel + ? convertLabel(edge, centerLabel, httpOrigin, readOnly, theme) + : null; if (endLabel) { - convertLabel(edge, endLabel, httpOrigin, readOnly); + convertLabel(edge, endLabel, httpOrigin, readOnly, theme); } edge.id = id; diff --git a/packages/diagrams/frontend/sirius-components-diagrams/src/sprotty/views/RectangleView.tsx b/packages/diagrams/frontend/sirius-components-diagrams/src/sprotty/views/RectangleView.tsx index c6b63a54e3b..46bde1d1e2c 100644 --- a/packages/diagrams/frontend/sirius-components-diagrams/src/sprotty/views/RectangleView.tsx +++ b/packages/diagrams/frontend/sirius-components-diagrams/src/sprotty/views/RectangleView.tsx @@ -15,8 +15,8 @@ import { VNode } from 'snabbdom'; import { RectangularNodeView, RenderingContext, SLabel, svg } from 'sprotty'; import { Node, RectangularNodeStyle } from '../Diagram.types'; -import { debugInfos } from './debugInfos'; import { createResizeHandles } from './ViewUtils'; +import { debugInfos } from './debugInfos'; const preventRemovalOfUnusedImportByPrettier = svg !== null; /** diff --git a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/ButtonWidget.tsx b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/ButtonWidget.tsx index 047d6b25b8e..57a9ce571ba 100644 --- a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/ButtonWidget.tsx +++ b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/ButtonWidget.tsx @@ -10,7 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ -import { ServerContext, ServerContextValue } from '@eclipse-sirius/sirius-components-core'; +import { ServerContext, ServerContextValue, getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { ButtonStyleProps, getTextDecorationLineValue } from '@eclipse-sirius/sirius-components-forms'; import Button from '@material-ui/core/Button'; import Typography from '@material-ui/core/Typography'; @@ -22,15 +22,17 @@ import { ButtonWidgetProps } from './WidgetEntry.types'; const useStyles = makeStyles((theme) => ({ style: { - backgroundColor: ({ backgroundColor }) => (backgroundColor ? backgroundColor : theme.palette.primary.light), - color: ({ foregroundColor }) => (foregroundColor ? foregroundColor : 'white'), + backgroundColor: ({ backgroundColor }) => + backgroundColor ? getCSSColor(backgroundColor, theme) : theme.palette.primary.light, + color: ({ foregroundColor }) => (foregroundColor ? getCSSColor(foregroundColor, theme) : 'white'), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), textDecorationLine: ({ underline, strikeThrough }) => getTextDecorationLineValue(underline, strikeThrough), '&:hover': { - backgroundColor: ({ backgroundColor }) => (backgroundColor ? backgroundColor : theme.palette.primary.main), - color: ({ foregroundColor }) => (foregroundColor ? foregroundColor : 'white'), + backgroundColor: ({ backgroundColor }) => + backgroundColor ? getCSSColor(backgroundColor, theme) : theme.palette.primary.main, + color: ({ foregroundColor }) => (foregroundColor ? getCSSColor(foregroundColor, theme) : 'white'), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/CheckboxWidget.tsx b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/CheckboxWidget.tsx index f5b41099dee..506374eec3a 100644 --- a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/CheckboxWidget.tsx +++ b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/CheckboxWidget.tsx @@ -10,6 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { CheckboxStyleProps } from '@eclipse-sirius/sirius-components-forms'; import Checkbox from '@material-ui/core/Checkbox'; import FormControlLabel from '@material-ui/core/FormControlLabel'; @@ -21,9 +22,9 @@ import { CheckboxWidgetProps } from './WidgetEntry.types'; const useStyles = makeStyles((theme) => ({ style: { - color: ({ color }) => (color ? color : theme.palette.primary.light), + color: ({ color }) => (color ? getCSSColor(color, theme) : theme.palette.primary.light), '&.Mui-checked': { - color: ({ color }) => (color ? color : theme.palette.primary.light), + color: ({ color }) => (color ? getCSSColor(color, theme) : theme.palette.primary.light), }, }, selected: { diff --git a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/FlexboxContainerWidget.tsx b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/FlexboxContainerWidget.tsx index 11d7b4e1320..9b71e5c54fc 100644 --- a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/FlexboxContainerWidget.tsx +++ b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/FlexboxContainerWidget.tsx @@ -11,7 +11,7 @@ * Obeo - initial API and implementation *******************************************************************************/ import { useMutation } from '@apollo/client'; -import { Toast } from '@eclipse-sirius/sirius-components-core'; +import { Toast, getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { GQLWidget, PropertySectionContext, @@ -49,7 +49,7 @@ const useStyles = makeStyles((theme) => margin: ({ borderStyle }) => (borderStyle ? theme.spacing(0.5) : 0), padding: ({ borderStyle }) => (borderStyle ? theme.spacing(0.5) : 0), borderWidth: ({ borderStyle }) => borderStyle?.size || 1, - borderColor: ({ borderStyle }) => borderStyle?.color || 'gray', + borderColor: ({ borderStyle }) => getCSSColor(borderStyle?.color, theme) || 'gray', borderStyle: ({ borderStyle }) => borderStyle?.lineStyle || 'solid', borderRadius: ({ borderStyle }) => borderStyle?.radius || 0, }, diff --git a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/Group.tsx b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/Group.tsx index 4d2bd7ff28c..c1b16e3469f 100644 --- a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/Group.tsx +++ b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/Group.tsx @@ -11,7 +11,7 @@ * Obeo - initial API and implementation *******************************************************************************/ import { useMutation } from '@apollo/client'; -import { Selection, Toast } from '@eclipse-sirius/sirius-components-core'; +import { Selection, Toast, getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { GQLWidget, PropertySectionContext, @@ -64,7 +64,7 @@ const useGroupEntryStyles = makeStyles((theme) => ({ flexDirection: 'column', flexGrow: 1, borderWidth: ({ borderStyle }) => (borderStyle ? borderStyle.size : 1), - borderColor: ({ borderStyle }) => (borderStyle ? borderStyle?.color || 'transparent' : 'gray'), + borderColor: ({ borderStyle }) => (borderStyle ? getCSSColor(borderStyle?.color, theme) || 'transparent' : 'gray'), borderStyle: ({ borderStyle }) => borderStyle?.lineStyle || 'solid', borderRadius: ({ borderStyle }) => (borderStyle ? borderStyle.radius : 10), paddingTop: '1px', diff --git a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/LabelWidget.tsx b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/LabelWidget.tsx index dc69125cad3..d678f8bccfe 100644 --- a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/LabelWidget.tsx +++ b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/LabelWidget.tsx @@ -10,6 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { getTextDecorationLineValue, LabelStyleProps } from '@eclipse-sirius/sirius-components-forms'; import { makeStyles, Theme } from '@material-ui/core/styles'; import Typography from '@material-ui/core/Typography'; @@ -19,7 +20,7 @@ import { LabelWidgetProps } from './WidgetEntry.types'; const useStyles = makeStyles((theme) => ({ style: { - color: ({ color }) => (color ? color : null), + color: ({ color }) => (color ? getCSSColor(color, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/LinkWidget.tsx b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/LinkWidget.tsx index fd142e0ccd2..5df4062a860 100644 --- a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/LinkWidget.tsx +++ b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/LinkWidget.tsx @@ -10,6 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { getTextDecorationLineValue, LinkStyleProps } from '@eclipse-sirius/sirius-components-forms'; import Link from '@material-ui/core/Link'; import { makeStyles, Theme } from '@material-ui/core/styles'; @@ -19,7 +20,7 @@ import { LinkWidgetProps } from './WidgetEntry.types'; const useStyles = makeStyles((theme) => ({ style: { - color: ({ color }) => (color ? color : null), + color: ({ color }) => (color ? getCSSColor(color, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/ListWidget.tsx b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/ListWidget.tsx index dfebad14f04..c6e0e37154d 100644 --- a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/ListWidget.tsx +++ b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/ListWidget.tsx @@ -11,6 +11,7 @@ * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { getTextDecorationLineValue, ListStyleProps } from '@eclipse-sirius/sirius-components-forms'; import IconButton from '@material-ui/core/IconButton'; import { makeStyles, Theme } from '@material-ui/core/styles'; @@ -27,7 +28,7 @@ import { ListWidgetProps } from './WidgetEntry.types'; const useStyles = makeStyles((theme) => ({ style: { - color: ({ color }) => (color ? color : null), + color: ({ color }) => (color ? getCSSColor(color, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/MultiSelectWidget.tsx b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/MultiSelectWidget.tsx index 5364a46d08d..2c9c204196e 100644 --- a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/MultiSelectWidget.tsx +++ b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/MultiSelectWidget.tsx @@ -10,6 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { getTextDecorationLineValue, MultiSelectStyleProps } from '@eclipse-sirius/sirius-components-forms'; import Checkbox from '@material-ui/core/Checkbox'; import ListItemText from '@material-ui/core/ListItemText'; @@ -23,8 +24,8 @@ import { MultiSelectWidgetProps } from './WidgetEntry.types'; const useStyles = makeStyles((theme) => ({ style: { - backgroundColor: ({ backgroundColor }) => (backgroundColor ? backgroundColor : null), - color: ({ foregroundColor }) => (foregroundColor ? foregroundColor : null), + backgroundColor: ({ backgroundColor }) => (backgroundColor ? getCSSColor(backgroundColor, theme) : null), + color: ({ foregroundColor }) => (foregroundColor ? getCSSColor(foregroundColor, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/RadioWidget.tsx b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/RadioWidget.tsx index 70933edb98e..115c7ddd0e1 100644 --- a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/RadioWidget.tsx +++ b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/RadioWidget.tsx @@ -10,6 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { getTextDecorationLineValue, RadioStyleProps } from '@eclipse-sirius/sirius-components-forms'; import FormControlLabel from '@material-ui/core/FormControlLabel'; import Radio from '@material-ui/core/Radio'; @@ -22,7 +23,7 @@ import { RadioWidgetProps } from './WidgetEntry.types'; const useStyles = makeStyles((theme) => ({ style: { - color: ({ color }) => (color ? color : null), + color: ({ color }) => (color ? getCSSColor(color, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/SelectWidget.tsx b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/SelectWidget.tsx index 7ac4638cf2d..c061b8d3811 100644 --- a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/SelectWidget.tsx +++ b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/SelectWidget.tsx @@ -10,6 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { getTextDecorationLineValue, SelectStyleProps } from '@eclipse-sirius/sirius-components-forms'; import MenuItem from '@material-ui/core/MenuItem'; import Select from '@material-ui/core/Select'; @@ -21,8 +22,8 @@ import { SelectWidgetProps } from './WidgetEntry.types'; const useStyles = makeStyles((theme) => ({ style: { - backgroundColor: ({ backgroundColor }) => (backgroundColor ? backgroundColor : null), - color: ({ foregroundColor }) => (foregroundColor ? foregroundColor : null), + backgroundColor: ({ backgroundColor }) => (backgroundColor ? getCSSColor(backgroundColor, theme) : null), + color: ({ foregroundColor }) => (foregroundColor ? getCSSColor(foregroundColor, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/TextAreaWidget.tsx b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/TextAreaWidget.tsx index de443ac11b0..6891c4f9aac 100644 --- a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/TextAreaWidget.tsx +++ b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/TextAreaWidget.tsx @@ -10,6 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { getTextDecorationLineValue, TextfieldStyleProps } from '@eclipse-sirius/sirius-components-forms'; import { makeStyles, Theme } from '@material-ui/core/styles'; import TextField from '@material-ui/core/TextField'; @@ -20,8 +21,8 @@ import { TextareaWidgetProps } from './WidgetEntry.types'; const useStyles = makeStyles((theme) => ({ style: { - backgroundColor: ({ backgroundColor }) => (backgroundColor ? backgroundColor : null), - color: ({ foregroundColor }) => (foregroundColor ? foregroundColor : null), + backgroundColor: ({ backgroundColor }) => (backgroundColor ? getCSSColor(backgroundColor, theme) : null), + color: ({ foregroundColor }) => (foregroundColor ? getCSSColor(foregroundColor, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/TextfieldWidget.tsx b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/TextfieldWidget.tsx index 29a92407e2c..d8e9770563d 100644 --- a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/TextfieldWidget.tsx +++ b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/TextfieldWidget.tsx @@ -10,6 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { getTextDecorationLineValue, TextfieldStyleProps } from '@eclipse-sirius/sirius-components-forms'; import { makeStyles, Theme } from '@material-ui/core/styles'; import TextField from '@material-ui/core/TextField'; @@ -20,8 +21,8 @@ import { TextfieldWidgetProps } from './WidgetEntry.types'; const useStyles = makeStyles((theme) => ({ style: { - backgroundColor: ({ backgroundColor }) => (backgroundColor ? backgroundColor : null), - color: ({ foregroundColor }) => (foregroundColor ? foregroundColor : null), + backgroundColor: ({ backgroundColor }) => (backgroundColor ? getCSSColor(backgroundColor, theme) : null), + color: ({ foregroundColor }) => (foregroundColor ? getCSSColor(foregroundColor, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/ToolbarActionWidget.tsx b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/ToolbarActionWidget.tsx index a66b2862402..d54f02e2261 100644 --- a/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/ToolbarActionWidget.tsx +++ b/packages/formdescriptioneditors/frontend/sirius-components-formdescriptioneditors/src/ToolbarActionWidget.tsx @@ -11,7 +11,13 @@ * Obeo - initial API and implementation *******************************************************************************/ import { useMutation } from '@apollo/client'; -import { Selection, ServerContext, ServerContextValue, Toast } from '@eclipse-sirius/sirius-components-core'; +import { + Selection, + ServerContext, + ServerContextValue, + Toast, + getCSSColor, +} from '@eclipse-sirius/sirius-components-core'; import { ButtonStyleProps, GQLButton, @@ -38,15 +44,17 @@ const useStyles = makeStyles((theme) => ({ style: { minWidth: '32px', lineHeight: 1.25, - backgroundColor: ({ backgroundColor }) => (backgroundColor ? backgroundColor : theme.palette.primary.light), - color: ({ foregroundColor }) => (foregroundColor ? foregroundColor : 'white'), + backgroundColor: ({ backgroundColor }) => + backgroundColor ? getCSSColor(backgroundColor, theme) : theme.palette.primary.light, + color: ({ foregroundColor }) => (foregroundColor ? getCSSColor(foregroundColor, theme) : 'white'), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), textDecorationLine: ({ underline, strikeThrough }) => getTextDecorationLineValue(underline, strikeThrough), '&:hover': { - backgroundColor: ({ backgroundColor }) => (backgroundColor ? backgroundColor : theme.palette.primary.main), - color: ({ foregroundColor }) => (foregroundColor ? foregroundColor : 'white'), + backgroundColor: ({ backgroundColor }) => + backgroundColor ? getCSSColor(backgroundColor, theme) : theme.palette.primary.main, + color: ({ foregroundColor }) => (foregroundColor ? getCSSColor(foregroundColor, theme) : 'white'), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/ClickListItemEventHandler.java b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/ClickListItemEventHandler.java index 8ee169866af..e8885f2b0de 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/ClickListItemEventHandler.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/ClickListItemEventHandler.java @@ -86,7 +86,7 @@ public void handle(One payloadSink, Many changeDesc IStatus status; if (optionalList.map(List::isReadOnly).filter(Boolean::booleanValue).isPresent()) { - status = new Failure("Read-only widget can not be edited"); + status = new Failure("Read-only widget cannot be edited"); } else { var optionalListItem = optionalList .stream() diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/DeleteListItemEventHandler.java b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/DeleteListItemEventHandler.java index 3f8ddc2fcea..2b70750e94a 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/DeleteListItemEventHandler.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/DeleteListItemEventHandler.java @@ -87,7 +87,7 @@ public void handle(One payloadSink, Many changeDesc IStatus status; if (optionalList.map(List::isReadOnly).filter(Boolean::booleanValue).isPresent()) { - status = new Failure("Read-only widget can not be edited"); + status = new Failure("Read-only widget cannot be edited"); } else { var optionalListItem = optionalList .stream() diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditCheckboxEventHandler.java b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditCheckboxEventHandler.java index e2051764a94..f01c41e0b7d 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditCheckboxEventHandler.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditCheckboxEventHandler.java @@ -83,7 +83,7 @@ public void handle(One payloadSink, Many changeDesc IStatus status; if (optionalCheckbox.map(Checkbox::isReadOnly).filter(Boolean::booleanValue).isPresent()) { - status = new Failure("Read-only widget can not be edited"); + status = new Failure("Read-only widget cannot be edited"); } else { status = optionalCheckbox.map(Checkbox::getNewValueHandler) .map(handler -> handler.apply(input.newValue())) diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditMultiSelectEventHandler.java b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditMultiSelectEventHandler.java index 902f31346a2..3088252237b 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditMultiSelectEventHandler.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditMultiSelectEventHandler.java @@ -84,7 +84,7 @@ public void handle(One payloadSink, Many changeDesc IStatus status; if (optionalMultiSelect.map(MultiSelect::isReadOnly).filter(Boolean::booleanValue).isPresent()) { - status = new Failure("Read-only widget can not be edited"); + status = new Failure("Read-only widget cannot be edited"); } else { status = optionalMultiSelect.map(MultiSelect::getNewValuesHandler) .map(handler -> handler.apply(input.newValues())) diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditRadioEventHandler.java b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditRadioEventHandler.java index 183e61f8c17..ed399c87ae7 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditRadioEventHandler.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditRadioEventHandler.java @@ -83,7 +83,7 @@ public void handle(One payloadSink, Many changeDesc IStatus status; if (optionalRadio.map(Radio::isReadOnly).filter(Boolean::booleanValue).isPresent()) { - status = new Failure("Read-only widget can not be edited"); + status = new Failure("Read-only widget cannot be edited"); } else { status = optionalRadio.map(Radio::getNewValueHandler) .map(handler -> handler.apply(input.newValue())) diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditRichTextEventHandler.java b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditRichTextEventHandler.java index b6d7ca2fe91..b49a436e3e4 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditRichTextEventHandler.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditRichTextEventHandler.java @@ -83,7 +83,7 @@ public void handle(One payloadSink, Many changeDesc IStatus status; if (optionalRichText.map(RichText::isReadOnly).filter(Boolean::booleanValue).isPresent()) { - status = new Failure("Read-only widget can not be edited"); + status = new Failure("Read-only widget cannot be edited"); } else { status = optionalRichText .map(RichText::getNewValueHandler) diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditSelectEventHandler.java b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditSelectEventHandler.java index 07bf7833b14..efc21ec798a 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditSelectEventHandler.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditSelectEventHandler.java @@ -84,7 +84,7 @@ public void handle(One payloadSink, Many changeDesc IStatus status; if (optionalSelect.map(Select::isReadOnly).filter(Boolean::booleanValue).isPresent()) { - status = new Failure("Read-only widget can not be edited"); + status = new Failure("Read-only widget cannot be edited"); } else { status = optionalSelect.map(Select::getNewValueHandler) .map(handler -> handler.apply(input.newValue())) diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditTextfieldEventHandler.java b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditTextfieldEventHandler.java index d22a28f1025..1b6d71f45be 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditTextfieldEventHandler.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditTextfieldEventHandler.java @@ -84,7 +84,7 @@ public void handle(One payloadSink, Many changeDesc IStatus status; if (optionalText.map(AbstractWidget::isReadOnly).filter(Boolean::booleanValue).isPresent()) { - status = new Failure("Read-only widget can not be edited"); + status = new Failure("Read-only widget cannot be edited"); } else { status = optionalText .map(widget -> { diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/PushButtonEventHandler.java b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/PushButtonEventHandler.java index 4c315b1e695..776c01a9784 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/PushButtonEventHandler.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/main/java/org/eclipse/sirius/components/collaborative/forms/handlers/PushButtonEventHandler.java @@ -84,7 +84,7 @@ public void handle(One payloadSink, Many changeDesc IStatus status; if (optionalButton.map(AbstractWidget::isReadOnly).filter(Boolean::booleanValue).isPresent()) { - status = new Failure("Read-only widget can not be edited"); + status = new Failure("Read-only widget cannot be edited"); } else { var handler = optionalButton.filter(Button.class::isInstance) diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditCheckboxEventHandlerTests.java b/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditCheckboxEventHandlerTests.java index bc27669830a..95d995b57f3 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditCheckboxEventHandlerTests.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditCheckboxEventHandlerTests.java @@ -162,7 +162,7 @@ public Optional findWidget(Form form, String widgetId) { IPayload payload = payloadSink.asMono().block(); assertThat(payload).isInstanceOf(ErrorPayload.class); - assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget can not be edited"); + assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget cannot be edited"); assertThat(hasBeenExecuted.get()).isFalse(); } } diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditMultiSelectEventHandlerTests.java b/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditMultiSelectEventHandlerTests.java index c555c1598bd..59f0bfe3808 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditMultiSelectEventHandlerTests.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditMultiSelectEventHandlerTests.java @@ -186,7 +186,7 @@ public Optional findWidget(Form form, String widgetId) { IPayload payload = payloadSink.asMono().block(); assertThat(payload).isInstanceOf(ErrorPayload.class); - assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget can not be edited"); + assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget cannot be edited"); assertThat(hasBeenExecuted.get()).isFalse(); } } diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditRadioEventHandlerTests.java b/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditRadioEventHandlerTests.java index ae97c9a3cea..e6776c3017f 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditRadioEventHandlerTests.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditRadioEventHandlerTests.java @@ -181,7 +181,7 @@ public Optional findWidget(Form form, String widgetId) { IPayload payload = payloadSink.asMono().block(); assertThat(payload).isInstanceOf(ErrorPayload.class); - assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget can not be edited"); + assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget cannot be edited"); assertThat(hasBeenExecuted.get()).isFalse(); } } diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditSelectEventHandlerTests.java b/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditSelectEventHandlerTests.java index 035d963dc5c..ec92730fb46 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditSelectEventHandlerTests.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditSelectEventHandlerTests.java @@ -187,7 +187,7 @@ public Optional findWidget(Form form, String widgetId) { IPayload payload = payloadSink.asMono().block(); assertThat(payload).isInstanceOf(ErrorPayload.class); - assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget can not be edited"); + assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget cannot be edited"); assertThat(hasBeenExecuted.get()).isFalse(); } } diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditTextfieldEventHandlerTests.java b/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditTextfieldEventHandlerTests.java index 65df26b7d37..667137fb8da 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditTextfieldEventHandlerTests.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/EditTextfieldEventHandlerTests.java @@ -168,7 +168,7 @@ public Optional findWidget(Form form, String widgetId) { IPayload payload = payloadSink.asMono().block(); assertThat(payload).isInstanceOf(ErrorPayload.class); - assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget can not be edited"); + assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget cannot be edited"); assertThat(hasBeenExecuted.get()).isFalse(); } } diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/ListItemEventHandlersTests.java b/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/ListItemEventHandlersTests.java index f8223d14dcc..9c2bace28fb 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/ListItemEventHandlersTests.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/ListItemEventHandlersTests.java @@ -211,7 +211,7 @@ public Optional findWidget(Form form, String widgetId) { IPayload payload = payloadSink.asMono().block(); assertThat(payload).isInstanceOf(ErrorPayload.class); - assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget can not be edited"); + assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget cannot be edited"); assertThat(hasBeenExecuted.get()).isFalse(); } @@ -312,7 +312,7 @@ public Optional findWidget(Form form, String widgetId) { IPayload payload = payloadSink.asMono().block(); assertThat(payload).isInstanceOf(ErrorPayload.class); - assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget can not be edited"); + assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget cannot be edited"); assertThat(hasBeenExecuted.get()).isFalse(); } diff --git a/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/PushButtonEventHandlerTests.java b/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/PushButtonEventHandlerTests.java index de5540838be..4aa9b34cb12 100644 --- a/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/PushButtonEventHandlerTests.java +++ b/packages/forms/backend/sirius-components-collaborative-forms/src/test/java/org/eclipse/sirius/components/collaborative/forms/handlers/PushButtonEventHandlerTests.java @@ -166,7 +166,7 @@ public Optional findWidget(Form form, String widgetId) { IPayload payload = payloadSink.asMono().block(); assertThat(payload).isInstanceOf(ErrorPayload.class); - assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget can not be edited"); + assertThat(((ErrorPayload) payload).message()).isEqualTo("Read-only widget cannot be edited"); assertThat(hasBeenExecuted.get()).isFalse(); } } diff --git a/packages/forms/frontend/sirius-components-forms/src/groups/Group.tsx b/packages/forms/frontend/sirius-components-forms/src/groups/Group.tsx index eca9dd397a8..07c1eb0103c 100644 --- a/packages/forms/frontend/sirius-components-forms/src/groups/Group.tsx +++ b/packages/forms/frontend/sirius-components-forms/src/groups/Group.tsx @@ -10,7 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ -import { ServerContext, ServerContextValue } from '@eclipse-sirius/sirius-components-core'; +import { ServerContext, ServerContextValue, getCSSColor } from '@eclipse-sirius/sirius-components-core'; import Typography from '@material-ui/core/Typography'; import { Theme, makeStyles } from '@material-ui/core/styles'; import ToggleButton from '@material-ui/lab/ToggleButton'; @@ -27,7 +27,7 @@ const useGroupStyles = makeStyles((theme) => ({ margin: ({ borderStyle }) => (borderStyle ? theme.spacing(0.5) : 0), padding: ({ borderStyle }) => (borderStyle ? theme.spacing(0.5) : 0), borderWidth: ({ borderStyle }) => borderStyle?.size || 0, - borderColor: ({ borderStyle }) => borderStyle?.color || 'transparent', + borderColor: ({ borderStyle }) => getCSSColor(borderStyle?.color, theme) || 'transparent', borderStyle: ({ borderStyle }) => borderStyle?.lineStyle || 'solid', borderRadius: ({ borderStyle }) => borderStyle?.radius || 0, }, diff --git a/packages/forms/frontend/sirius-components-forms/src/propertysections/ButtonPropertySection.tsx b/packages/forms/frontend/sirius-components-forms/src/propertysections/ButtonPropertySection.tsx index 42f46cab744..73627db3d03 100644 --- a/packages/forms/frontend/sirius-components-forms/src/propertysections/ButtonPropertySection.tsx +++ b/packages/forms/frontend/sirius-components-forms/src/propertysections/ButtonPropertySection.tsx @@ -11,7 +11,7 @@ * Obeo - initial API and implementation *******************************************************************************/ import { useMutation } from '@apollo/client'; -import { ServerContext, ServerContextValue, useMultiToast } from '@eclipse-sirius/sirius-components-core'; +import { ServerContext, ServerContextValue, getCSSColor, useMultiToast } from '@eclipse-sirius/sirius-components-core'; import Button from '@material-ui/core/Button'; import { Theme, makeStyles } from '@material-ui/core/styles'; import gql from 'graphql-tag'; @@ -35,15 +35,17 @@ import { getTextDecorationLineValue } from './getTextDecorationLineValue'; const useStyle = makeStyles((theme) => ({ style: { - backgroundColor: ({ backgroundColor }) => (backgroundColor ? backgroundColor : theme.palette.primary.light), - color: ({ foregroundColor }) => (foregroundColor ? foregroundColor : 'white'), + backgroundColor: ({ backgroundColor }) => + backgroundColor ? getCSSColor(backgroundColor, theme) : theme.palette.primary.light, + color: ({ foregroundColor }) => (foregroundColor ? getCSSColor(foregroundColor, theme) : 'white'), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), textDecorationLine: ({ underline, strikeThrough }) => getTextDecorationLineValue(underline, strikeThrough), '&:hover': { - backgroundColor: ({ backgroundColor }) => (backgroundColor ? backgroundColor : theme.palette.primary.main), - color: ({ foregroundColor }) => (foregroundColor ? foregroundColor : 'white'), + backgroundColor: ({ backgroundColor }) => + backgroundColor ? getCSSColor(backgroundColor, theme) : theme.palette.primary.main, + color: ({ foregroundColor }) => (foregroundColor ? getCSSColor(foregroundColor, theme) : 'white'), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/forms/frontend/sirius-components-forms/src/propertysections/CheckboxPropertySection.tsx b/packages/forms/frontend/sirius-components-forms/src/propertysections/CheckboxPropertySection.tsx index f7a3fd7486f..0110c8b4b1f 100644 --- a/packages/forms/frontend/sirius-components-forms/src/propertysections/CheckboxPropertySection.tsx +++ b/packages/forms/frontend/sirius-components-forms/src/propertysections/CheckboxPropertySection.tsx @@ -11,12 +11,12 @@ * Obeo - initial API and implementation *******************************************************************************/ import { gql, useMutation } from '@apollo/client'; -import { useMultiToast } from '@eclipse-sirius/sirius-components-core'; +import { getCSSColor, useMultiToast } from '@eclipse-sirius/sirius-components-core'; import Checkbox from '@material-ui/core/Checkbox'; import FormControl from '@material-ui/core/FormControl'; import FormControlLabel from '@material-ui/core/FormControlLabel'; import FormHelperText from '@material-ui/core/FormHelperText'; -import { makeStyles, Theme } from '@material-ui/core/styles'; +import { Theme, makeStyles } from '@material-ui/core/styles'; import { useEffect } from 'react'; import { CheckboxPropertySectionProps, @@ -39,7 +39,7 @@ const useStyle = makeStyles((theme) => ({ alignItems: 'flex-start', }, style: { - color: ({ color }) => (color ? color : theme.palette.primary.light), + color: ({ color }) => (color ? getCSSColor(color, theme) : theme.palette.primary.light), }, disabled: {}, })); diff --git a/packages/forms/frontend/sirius-components-forms/src/propertysections/FlexboxContainerPropertySection.tsx b/packages/forms/frontend/sirius-components-forms/src/propertysections/FlexboxContainerPropertySection.tsx index 9adac3a1298..bca836332da 100644 --- a/packages/forms/frontend/sirius-components-forms/src/propertysections/FlexboxContainerPropertySection.tsx +++ b/packages/forms/frontend/sirius-components-forms/src/propertysections/FlexboxContainerPropertySection.tsx @@ -10,6 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { makeStyles, Theme } from '@material-ui/core/styles'; import { FlexboxContainerPropertySectionProps, @@ -24,7 +25,7 @@ const useFlexboxContainerPropertySectionStyles = makeStyles (borderStyle ? theme.spacing(0.5) : 0), padding: ({ borderStyle }) => (borderStyle ? theme.spacing(0.5) : 0), borderWidth: ({ borderStyle }) => borderStyle?.size || 0, - borderColor: ({ borderStyle }) => borderStyle?.color || 'transparent', + borderColor: ({ borderStyle }) => getCSSColor(borderStyle?.color, theme) || 'transparent', borderStyle: ({ borderStyle }) => borderStyle?.lineStyle || 'solid', borderRadius: ({ borderStyle }) => borderStyle?.radius || 0, }, diff --git a/packages/forms/frontend/sirius-components-forms/src/propertysections/LabelWidgetPropertySection.tsx b/packages/forms/frontend/sirius-components-forms/src/propertysections/LabelWidgetPropertySection.tsx index adfb397fd5e..0c795db4209 100644 --- a/packages/forms/frontend/sirius-components-forms/src/propertysections/LabelWidgetPropertySection.tsx +++ b/packages/forms/frontend/sirius-components-forms/src/propertysections/LabelWidgetPropertySection.tsx @@ -10,15 +10,16 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { makeStyles, Theme } from '@material-ui/core/styles'; import Typography from '@material-ui/core/Typography'; import { getTextDecorationLineValue } from './getTextDecorationLineValue'; import { LabelStyleProps, LabelWidgetPropertySectionProps } from './LabelWidgetPropertySection.types'; import { PropertySectionLabel } from './PropertySectionLabel'; -const useStyle = makeStyles(() => ({ +const useStyle = makeStyles((theme) => ({ style: { - color: ({ color }) => (color ? color : null), + color: ({ color }) => (color ? getCSSColor(color, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/forms/frontend/sirius-components-forms/src/propertysections/LinkPropertySection.tsx b/packages/forms/frontend/sirius-components-forms/src/propertysections/LinkPropertySection.tsx index 2460cd3c972..af365031879 100644 --- a/packages/forms/frontend/sirius-components-forms/src/propertysections/LinkPropertySection.tsx +++ b/packages/forms/frontend/sirius-components-forms/src/propertysections/LinkPropertySection.tsx @@ -10,15 +10,16 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import Link from '@material-ui/core/Link'; import { makeStyles, Theme } from '@material-ui/core/styles'; import { getTextDecorationLineValue } from './getTextDecorationLineValue'; import { HelpTooltip } from './HelpTooltip'; import { LinkPropertySectionProps, LinkStyleProps } from './LinkPropertySection.types'; -const useStyle = makeStyles(() => ({ +const useStyle = makeStyles((theme) => ({ style: { - color: ({ color }) => (color ? color : null), + color: ({ color }) => (color ? getCSSColor(color, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/forms/frontend/sirius-components-forms/src/propertysections/ListPropertySection.tsx b/packages/forms/frontend/sirius-components-forms/src/propertysections/ListPropertySection.tsx index d9388bb6dc1..0cf1d52c0dc 100644 --- a/packages/forms/frontend/sirius-components-forms/src/propertysections/ListPropertySection.tsx +++ b/packages/forms/frontend/sirius-components-forms/src/propertysections/ListPropertySection.tsx @@ -11,7 +11,7 @@ * Obeo - initial API and implementation *******************************************************************************/ import { gql, useMutation } from '@apollo/client'; -import { ServerContext, ServerContextValue, useMultiToast } from '@eclipse-sirius/sirius-components-core'; +import { ServerContext, ServerContextValue, getCSSColor, useMultiToast } from '@eclipse-sirius/sirius-components-core'; import FormControl from '@material-ui/core/FormControl'; import FormHelperText from '@material-ui/core/FormHelperText'; import IconButton from '@material-ui/core/IconButton'; @@ -96,7 +96,7 @@ const useListPropertySectionStyles = makeStyles((theme) = }, }, style: { - color: ({ color }) => (color ? color : null), + color: ({ color }) => (color ? getCSSColor(color, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/forms/frontend/sirius-components-forms/src/propertysections/MultiSelectPropertySection.tsx b/packages/forms/frontend/sirius-components-forms/src/propertysections/MultiSelectPropertySection.tsx index b17f46db49e..98ece818208 100644 --- a/packages/forms/frontend/sirius-components-forms/src/propertysections/MultiSelectPropertySection.tsx +++ b/packages/forms/frontend/sirius-components-forms/src/propertysections/MultiSelectPropertySection.tsx @@ -11,7 +11,7 @@ * Obeo - initial API and implementation *******************************************************************************/ import { gql, useMutation } from '@apollo/client'; -import { ServerContext, ServerContextValue, useMultiToast } from '@eclipse-sirius/sirius-components-core'; +import { ServerContext, ServerContextValue, getCSSColor, useMultiToast } from '@eclipse-sirius/sirius-components-core'; import Checkbox from '@material-ui/core/Checkbox'; import FormControl from '@material-ui/core/FormControl'; import FormHelperText from '@material-ui/core/FormHelperText'; @@ -36,8 +36,8 @@ import { getTextDecorationLineValue } from './getTextDecorationLineValue'; const useStyle = makeStyles((theme) => ({ style: { - backgroundColor: ({ backgroundColor }) => (backgroundColor ? backgroundColor : null), - color: ({ foregroundColor }) => (foregroundColor ? foregroundColor : null), + backgroundColor: ({ backgroundColor }) => (backgroundColor ? getCSSColor(backgroundColor, theme) : null), + color: ({ foregroundColor }) => (foregroundColor ? getCSSColor(foregroundColor, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/forms/frontend/sirius-components-forms/src/propertysections/RadioPropertySection.tsx b/packages/forms/frontend/sirius-components-forms/src/propertysections/RadioPropertySection.tsx index ff4081f64e6..aba5c1cd00a 100644 --- a/packages/forms/frontend/sirius-components-forms/src/propertysections/RadioPropertySection.tsx +++ b/packages/forms/frontend/sirius-components-forms/src/propertysections/RadioPropertySection.tsx @@ -22,6 +22,7 @@ import { Theme, makeStyles } from '@material-ui/core/styles'; import { useEffect } from 'react'; import { getTextDecorationLineValue } from './getTextDecorationLineValue'; +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { PropertySectionLabel } from './PropertySectionLabel'; import { GQLEditRadioInput, @@ -72,12 +73,12 @@ export const updateWidgetFocusMutation = gql` } `; -const useRadioPropertySectionStyles = makeStyles(() => ({ +const useRadioPropertySectionStyles = makeStyles((theme) => ({ radioGroupRoot: { flexDirection: 'row', }, style: { - color: ({ color }) => (color ? color : null), + color: ({ color }) => (color ? getCSSColor(color, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/forms/frontend/sirius-components-forms/src/propertysections/SelectPropertySection.tsx b/packages/forms/frontend/sirius-components-forms/src/propertysections/SelectPropertySection.tsx index e3bc2740c27..085b8cbc9d7 100644 --- a/packages/forms/frontend/sirius-components-forms/src/propertysections/SelectPropertySection.tsx +++ b/packages/forms/frontend/sirius-components-forms/src/propertysections/SelectPropertySection.tsx @@ -11,7 +11,7 @@ * Obeo - initial API and implementation *******************************************************************************/ import { gql, useMutation } from '@apollo/client'; -import { ServerContext, ServerContextValue, useMultiToast } from '@eclipse-sirius/sirius-components-core'; +import { ServerContext, ServerContextValue, getCSSColor, useMultiToast } from '@eclipse-sirius/sirius-components-core'; import FormControl from '@material-ui/core/FormControl'; import FormHelperText from '@material-ui/core/FormHelperText'; import ListItemIcon from '@material-ui/core/ListItemIcon'; @@ -33,8 +33,8 @@ import { getTextDecorationLineValue } from './getTextDecorationLineValue'; const useStyle = makeStyles((theme) => ({ style: { - backgroundColor: ({ backgroundColor }) => (backgroundColor ? backgroundColor : null), - color: ({ foregroundColor }) => (foregroundColor ? foregroundColor : null), + backgroundColor: ({ backgroundColor }) => (backgroundColor ? getCSSColor(backgroundColor, theme) : null), + color: ({ foregroundColor }) => (foregroundColor ? getCSSColor(foregroundColor, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/forms/frontend/sirius-components-forms/src/propertysections/TextfieldPropertySection.tsx b/packages/forms/frontend/sirius-components-forms/src/propertysections/TextfieldPropertySection.tsx index fa6360fe815..ead017f2a56 100644 --- a/packages/forms/frontend/sirius-components-forms/src/propertysections/TextfieldPropertySection.tsx +++ b/packages/forms/frontend/sirius-components-forms/src/propertysections/TextfieldPropertySection.tsx @@ -20,6 +20,7 @@ import { GQLTextarea, GQLWidget } from '../form/FormEventFragments.types'; import { GQLSuccessPayload } from './ListPropertySection.types'; import { getTextDecorationLineValue } from './getTextDecorationLineValue'; +import { getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { PropertySectionLabel } from './PropertySectionLabel'; import { ProposalsList } from './ProposalsList'; import { @@ -51,10 +52,10 @@ import { textfieldPropertySectionMachine, } from './TextfieldPropertySectionMachine'; -const useStyle = makeStyles(() => ({ +const useStyle = makeStyles((theme) => ({ style: { - backgroundColor: ({ backgroundColor }) => (backgroundColor ? backgroundColor : null), - color: ({ foregroundColor }) => (foregroundColor ? foregroundColor : null), + backgroundColor: ({ backgroundColor }) => (backgroundColor ? getCSSColor(backgroundColor, theme) : null), + color: ({ foregroundColor }) => (foregroundColor ? getCSSColor(foregroundColor, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/forms/frontend/sirius-components-forms/src/toolbaraction/ToolbarAction.tsx b/packages/forms/frontend/sirius-components-forms/src/toolbaraction/ToolbarAction.tsx index 66442bd6ea4..3fa1c683b82 100644 --- a/packages/forms/frontend/sirius-components-forms/src/toolbaraction/ToolbarAction.tsx +++ b/packages/forms/frontend/sirius-components-forms/src/toolbaraction/ToolbarAction.tsx @@ -11,7 +11,7 @@ * Obeo - initial API and implementation *******************************************************************************/ import { useMutation } from '@apollo/client'; -import { ServerContext, ServerContextValue, useMultiToast } from '@eclipse-sirius/sirius-components-core'; +import { ServerContext, ServerContextValue, getCSSColor, useMultiToast } from '@eclipse-sirius/sirius-components-core'; import Button from '@material-ui/core/Button'; import { Theme, makeStyles } from '@material-ui/core/styles'; import gql from 'graphql-tag'; @@ -38,15 +38,17 @@ const useStyle = makeStyles((theme) => ({ style: { minWidth: '32px', lineHeight: 1.25, - backgroundColor: ({ backgroundColor }) => (backgroundColor ? backgroundColor : theme.palette.primary.light), - color: ({ foregroundColor }) => (foregroundColor ? foregroundColor : 'white'), + backgroundColor: ({ backgroundColor }) => + backgroundColor ? getCSSColor(backgroundColor, theme) : theme.palette.primary.light, + color: ({ foregroundColor }) => (foregroundColor ? getCSSColor(foregroundColor, theme) : 'white'), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), textDecorationLine: ({ underline, strikeThrough }) => getTextDecorationLineValue(underline, strikeThrough), '&:hover': { - backgroundColor: ({ backgroundColor }) => (backgroundColor ? backgroundColor : theme.palette.primary.main), - color: ({ foregroundColor }) => (foregroundColor ? foregroundColor : 'white'), + backgroundColor: ({ backgroundColor }) => + backgroundColor ? getCSSColor(backgroundColor, theme) : theme.palette.primary.main, + color: ({ foregroundColor }) => (foregroundColor ? getCSSColor(foregroundColor, theme) : 'white'), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/forms/frontend/sirius-components-widget-reference/src/ReferencePreview.tsx b/packages/forms/frontend/sirius-components-widget-reference/src/ReferencePreview.tsx index ab58caa5c2c..c3c8f611dfd 100644 --- a/packages/forms/frontend/sirius-components-widget-reference/src/ReferencePreview.tsx +++ b/packages/forms/frontend/sirius-components-widget-reference/src/ReferencePreview.tsx @@ -10,7 +10,7 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ -import { ServerContext, ServerContextValue } from '@eclipse-sirius/sirius-components-core'; +import { ServerContext, ServerContextValue, getCSSColor } from '@eclipse-sirius/sirius-components-core'; import { WidgetProps } from '@eclipse-sirius/sirius-components-formdescriptioneditors'; import { getTextDecorationLineValue } from '@eclipse-sirius/sirius-components-forms'; import { GQLReferenceWidget } from '@eclipse-sirius/sirius-components-widget-reference'; @@ -28,7 +28,7 @@ import { GQLReferenceWidgetStyle } from './ReferenceWidgetFragment.types'; const useStyles = makeStyles((theme) => ({ style: { - color: ({ color }) => (color ? color : null), + color: ({ color }) => (color ? getCSSColor(color, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/forms/frontend/sirius-components-widget-reference/src/components/ValuedReferenceAutocomplete.tsx b/packages/forms/frontend/sirius-components-widget-reference/src/components/ValuedReferenceAutocomplete.tsx index 1013c928685..83460745c5e 100644 --- a/packages/forms/frontend/sirius-components-widget-reference/src/components/ValuedReferenceAutocomplete.tsx +++ b/packages/forms/frontend/sirius-components-widget-reference/src/components/ValuedReferenceAutocomplete.tsx @@ -10,13 +10,13 @@ * Contributors: * Obeo - initial API and implementation *******************************************************************************/ -import { ServerContext, ServerContextValue, theme } from '@eclipse-sirius/sirius-components-core'; +import { ServerContext, ServerContextValue, getCSSColor, theme } from '@eclipse-sirius/sirius-components-core'; import { getTextDecorationLineValue } from '@eclipse-sirius/sirius-components-forms'; import Chip from '@material-ui/core/Chip'; import IconButton from '@material-ui/core/IconButton'; import InputAdornment from '@material-ui/core/InputAdornment'; -import { makeStyles, Theme } from '@material-ui/core/styles'; import TextField from '@material-ui/core/TextField'; +import { Theme, makeStyles } from '@material-ui/core/styles'; import AddIcon from '@material-ui/icons/Add'; import DeleteIcon from '@material-ui/icons/Delete'; import MoreHorizIcon from '@material-ui/icons/MoreHoriz'; @@ -30,7 +30,7 @@ const useStyles = makeStyles((theme) => ({ paddingLeft: theme.spacing(0.5), }, referenceValueStyle: { - color: ({ color }) => (color ? color : null), + color: ({ color }) => (color ? getCSSColor(color, theme) : null), fontSize: ({ fontSize }) => (fontSize ? fontSize : null), fontStyle: ({ italic }) => (italic ? 'italic' : null), fontWeight: ({ bold }) => (bold ? 'bold' : null), diff --git a/packages/sirius-web/backend/sirius-web-sample-application/src/main/java/org/eclipse/sirius/web/sample/configuration/StereotypeDescriptionRegistryConfigurer.java b/packages/sirius-web/backend/sirius-web-sample-application/src/main/java/org/eclipse/sirius/web/sample/configuration/StereotypeDescriptionRegistryConfigurer.java index daad0684940..4bd80f90959 100644 --- a/packages/sirius-web/backend/sirius-web-sample-application/src/main/java/org/eclipse/sirius/web/sample/configuration/StereotypeDescriptionRegistryConfigurer.java +++ b/packages/sirius-web/backend/sirius-web-sample-application/src/main/java/org/eclipse/sirius/web/sample/configuration/StereotypeDescriptionRegistryConfigurer.java @@ -22,10 +22,9 @@ import org.eclipse.sirius.components.core.configuration.StereotypeDescription; import org.eclipse.sirius.components.domain.Domain; import org.eclipse.sirius.components.domain.DomainFactory; -import org.eclipse.sirius.components.view.ColorPalette; -import org.eclipse.sirius.components.view.FixedColor; import org.eclipse.sirius.components.view.View; import org.eclipse.sirius.components.view.ViewFactory; +import org.eclipse.sirius.components.view.builder.providers.DefaultColorPalettesProvider; import org.eclipse.sirius.components.view.diagram.DiagramDescription; import org.eclipse.sirius.components.view.diagram.DiagramFactory; import org.eclipse.sirius.web.sample.papaya.domain.PapayaDomainProvider; @@ -82,12 +81,16 @@ public class StereotypeDescriptionRegistryConfigurer implements IStereotypeDescr private final SampleDomainNameProvider domainNameProvider; + private final DefaultColorPalettesProvider defaultColorPalettesProvider; + private final boolean studiosEnabled; public StereotypeDescriptionRegistryConfigurer(MeterRegistry meterRegistry, @Value("${org.eclipse.sirius.web.features.studioDefinition:false}") boolean studiosEnabled) { this.stereotypeBuilder = new StereotypeBuilder(TIMER_NAME, meterRegistry); this.studiosEnabled = studiosEnabled; this.domainNameProvider = new SampleDomainNameProvider(); + this.defaultColorPalettesProvider = new DefaultColorPalettesProvider(); + } @Override @@ -120,33 +123,8 @@ private String getEmptyViewContent() { DiagramDescription diagramDescription = DiagramFactory.eINSTANCE.createDiagramDescription(); diagramDescription.setName("New Diagram Description"); newView.getDescriptions().add(diagramDescription); - ColorPalette colorPalette = ViewFactory.eINSTANCE.createColorPalette(); - colorPalette.setName("Color Palette"); - FixedColor themePrimaryMain = ViewFactory.eINSTANCE.createFixedColor(); - themePrimaryMain.setName("theme_primary_main"); - themePrimaryMain.setValue("#BE1A78"); - colorPalette.getColors().add(themePrimaryMain); - FixedColor themePrimaryDark = ViewFactory.eINSTANCE.createFixedColor(); - themePrimaryDark.setName("theme_primary_dark"); - themePrimaryDark.setValue("#851254"); - colorPalette.getColors().add(themePrimaryDark); - FixedColor themePrimaryLight = ViewFactory.eINSTANCE.createFixedColor(); - themePrimaryLight.setName("theme_primary_light"); - themePrimaryLight.setValue("#CB4793"); - colorPalette.getColors().add(themePrimaryLight); - FixedColor themeSecondaryMain = ViewFactory.eINSTANCE.createFixedColor(); - themeSecondaryMain.setName("theme_secondary_main"); - themeSecondaryMain.setValue("#261E58"); - colorPalette.getColors().add(themeSecondaryMain); - FixedColor themeSecondaryDark = ViewFactory.eINSTANCE.createFixedColor(); - themeSecondaryDark.setName("theme_secondary_dark"); - themeSecondaryDark.setValue("#1A153D"); - colorPalette.getColors().add(themeSecondaryDark); - FixedColor themeSecondaryLight = ViewFactory.eINSTANCE.createFixedColor(); - themeSecondaryLight.setName("theme_secondary_light"); - themeSecondaryLight.setValue("#514B79"); - colorPalette.getColors().add(themeSecondaryLight); - newView.getColorPalettes().add(colorPalette); + newView.getColorPalettes().addAll(this.defaultColorPalettesProvider.getDefaultColorPalettes()); + return this.stereotypeBuilder.getStereotypeBody(List.of(newView)); } diff --git a/packages/sirius-web/backend/sirius-web-sample-application/src/main/java/org/eclipse/sirius/web/sample/configuration/StudioProjectTemplatesInitializer.java b/packages/sirius-web/backend/sirius-web-sample-application/src/main/java/org/eclipse/sirius/web/sample/configuration/StudioProjectTemplatesInitializer.java index b8e2d4a3057..67be5eb4916 100644 --- a/packages/sirius-web/backend/sirius-web-sample-application/src/main/java/org/eclipse/sirius/web/sample/configuration/StudioProjectTemplatesInitializer.java +++ b/packages/sirius-web/backend/sirius-web-sample-application/src/main/java/org/eclipse/sirius/web/sample/configuration/StudioProjectTemplatesInitializer.java @@ -46,6 +46,7 @@ import org.eclipse.sirius.components.view.UserColor; import org.eclipse.sirius.components.view.View; import org.eclipse.sirius.components.view.ViewFactory; +import org.eclipse.sirius.components.view.builder.providers.DefaultColorPalettesProvider; import org.eclipse.sirius.components.view.diagram.DiagramFactory; import org.eclipse.sirius.components.view.diagram.EdgeDescription; import org.eclipse.sirius.components.view.diagram.EdgeStyle; @@ -95,6 +96,8 @@ public class StudioProjectTemplatesInitializer implements IProjectTemplateInitia private final StereotypeBuilder stereotypeBuilder; + private final DefaultColorPalettesProvider defaultColorPalettesProvider; + public StudioProjectTemplatesInitializer(IProjectRepository projectRepository, IDocumentRepository documentRepository, IRepresentationDescriptionSearchService representationDescriptionSearchService, IDiagramCreationService diagramCreationService, IRepresentationPersistenceService representationPersistenceService, MeterRegistry meterRegistry) { @@ -104,6 +107,7 @@ public StudioProjectTemplatesInitializer(IProjectRepository projectRepository, I this.diagramCreationService = Objects.requireNonNull(diagramCreationService); this.representationPersistenceService = Objects.requireNonNull(representationPersistenceService); this.stereotypeBuilder = new StereotypeBuilder("studio-template-initializer", meterRegistry); + this.defaultColorPalettesProvider = new DefaultColorPalettesProvider(); } @Override @@ -265,6 +269,7 @@ private String getViewContent(String domainName) { view.getDescriptions().add(viewDiagramDescription); view.getColorPalettes().add(this.createColorPalette()); + view.getColorPalettes().addAll(this.defaultColorPalettesProvider.getDefaultColorPalettes()); NodeDescription entity1Node = DiagramFactory.eINSTANCE.createNodeDescription(); entity1Node.setName("Entity1 Node"); diff --git a/packages/sirius-web/backend/sirius-web-sample-application/src/main/java/org/eclipse/sirius/web/sample/services/EditingContextActionHandler.java b/packages/sirius-web/backend/sirius-web-sample-application/src/main/java/org/eclipse/sirius/web/sample/services/EditingContextActionHandler.java index 601de43dfc2..8e2fadd1001 100644 --- a/packages/sirius-web/backend/sirius-web-sample-application/src/main/java/org/eclipse/sirius/web/sample/services/EditingContextActionHandler.java +++ b/packages/sirius-web/backend/sirius-web-sample-application/src/main/java/org/eclipse/sirius/web/sample/services/EditingContextActionHandler.java @@ -51,10 +51,9 @@ import org.eclipse.sirius.components.representations.Failure; import org.eclipse.sirius.components.representations.IStatus; import org.eclipse.sirius.components.representations.Success; -import org.eclipse.sirius.components.view.ColorPalette; -import org.eclipse.sirius.components.view.FixedColor; import org.eclipse.sirius.components.view.View; import org.eclipse.sirius.components.view.ViewFactory; +import org.eclipse.sirius.components.view.builder.providers.DefaultColorPalettesProvider; import org.eclipse.sirius.components.view.diagram.DiagramDescription; import org.eclipse.sirius.components.view.diagram.DiagramFactory; import org.eclipse.sirius.emfjson.resource.JsonResource; @@ -84,8 +83,12 @@ public class EditingContextActionHandler implements IEditingContextActionHandler private final SampleDomainNameProvider domainNameProvider; + private final DefaultColorPalettesProvider defaultColorPalettesProvider; + public EditingContextActionHandler() { this.domainNameProvider = new SampleDomainNameProvider(); + this.defaultColorPalettesProvider = new DefaultColorPalettesProvider(); + } @Override @@ -158,33 +161,8 @@ private void createEmptyViewResource(ResourceSet resourceSet) { DiagramDescription diagramDescription = DiagramFactory.eINSTANCE.createDiagramDescription(); diagramDescription.setName("New Diagram Description"); newView.getDescriptions().add(diagramDescription); - ColorPalette colorPalette = ViewFactory.eINSTANCE.createColorPalette(); - colorPalette.setName("Color Palette"); - FixedColor themePrimaryMain = ViewFactory.eINSTANCE.createFixedColor(); - themePrimaryMain.setName("theme_primary_main"); - themePrimaryMain.setValue("#BE1A78"); - colorPalette.getColors().add(themePrimaryMain); - FixedColor themePrimaryDark = ViewFactory.eINSTANCE.createFixedColor(); - themePrimaryDark.setName("theme_primary_dark"); - themePrimaryDark.setValue("#851254"); - colorPalette.getColors().add(themePrimaryDark); - FixedColor themePrimaryLight = ViewFactory.eINSTANCE.createFixedColor(); - themePrimaryLight.setName("theme_primary_light"); - themePrimaryLight.setValue("#CB4793"); - colorPalette.getColors().add(themePrimaryLight); - FixedColor themeSecondaryMain = ViewFactory.eINSTANCE.createFixedColor(); - themeSecondaryMain.setName("theme_secondary_main"); - themeSecondaryMain.setValue("#261E58"); - colorPalette.getColors().add(themeSecondaryMain); - FixedColor themeSecondaryDark = ViewFactory.eINSTANCE.createFixedColor(); - themeSecondaryDark.setName("theme_secondary_dark"); - themeSecondaryDark.setValue("#1A153D"); - colorPalette.getColors().add(themeSecondaryDark); - FixedColor themeSecondaryLight = ViewFactory.eINSTANCE.createFixedColor(); - themeSecondaryLight.setName("theme_secondary_light"); - themeSecondaryLight.setValue("#514B79"); - colorPalette.getColors().add(themeSecondaryLight); - newView.getColorPalettes().add(colorPalette); + newView.getColorPalettes().addAll(this.defaultColorPalettesProvider.getDefaultColorPalettes()); + JsonResource resource = new JSONResourceFactory().createResourceFromPath(UUID.randomUUID().toString()); resource.getContents().add(newView); resource.eAdapters().add(new ResourceMetadataAdapter("View")); diff --git a/packages/sirius-web/backend/sirius-web-services/src/main/java/org/eclipse/sirius/web/services/editingcontext/EditingDomainFactoryService.java b/packages/sirius-web/backend/sirius-web-services/src/main/java/org/eclipse/sirius/web/services/editingcontext/EditingDomainFactoryService.java index a4e852b4c8b..ebbff871a9a 100644 --- a/packages/sirius-web/backend/sirius-web-services/src/main/java/org/eclipse/sirius/web/services/editingcontext/EditingDomainFactoryService.java +++ b/packages/sirius-web/backend/sirius-web-services/src/main/java/org/eclipse/sirius/web/services/editingcontext/EditingDomainFactoryService.java @@ -28,6 +28,8 @@ import org.eclipse.sirius.components.domain.DomainPackage; import org.eclipse.sirius.components.emf.services.IEditingContextEPackageService; import org.eclipse.sirius.components.view.ViewPackage; +import org.eclipse.sirius.components.view.diagram.adapters.DiagramColorAdapter; +import org.eclipse.sirius.components.view.form.adapters.FormColorAdapter; import org.eclipse.sirius.web.services.api.projects.Nature; import org.eclipse.sirius.web.services.editingcontext.api.IEditingDomainFactoryService; import org.eclipse.sirius.web.services.projects.api.IEditingContextMetadataProvider; @@ -76,6 +78,10 @@ public AdapterFactoryEditingDomain createEditingDomain(String editingContextId) .forEach(ePackage -> ePackageRegistry.put(ePackage.getNsURI(), ePackage)); resourceSet.setPackageRegistry(ePackageRegistry); + if (isStudioProjectNature) { + resourceSet.eAdapters().add(new DiagramColorAdapter()); + resourceSet.eAdapters().add(new FormColorAdapter()); + } this.optionalResourceFactoryRegistry.ifPresent(resourceSet::setResourceFactoryRegistry); return editingDomain; diff --git a/packages/view/backend/sirius-components-view-builder/src/main/java/org/eclipse/sirius/components/view/builder/providers/DefaultColorPalettesProvider.java b/packages/view/backend/sirius-components-view-builder/src/main/java/org/eclipse/sirius/components/view/builder/providers/DefaultColorPalettesProvider.java new file mode 100644 index 00000000000..81e5bfc3db7 --- /dev/null +++ b/packages/view/backend/sirius-components-view-builder/src/main/java/org/eclipse/sirius/components/view/builder/providers/DefaultColorPalettesProvider.java @@ -0,0 +1,189 @@ +/******************************************************************************* + * Copyright (c) 2023 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.components.view.builder.providers; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.sirius.components.view.ColorPalette; +import org.eclipse.sirius.components.view.FixedColor; +import org.eclipse.sirius.components.view.ViewFactory; + +/** + * Provide default color palettes for views + * . + * @author arichard + */ +public class DefaultColorPalettesProvider { + + private List muiHues = List.of( + "amber", + "blue", + "blueGrey", + "brown", + "cyan", + "deepOrange", + "deepPurple", + "green", + "grey", + "indigo", + "lightBlue", + "lightGreen", + "lime", + "orange", + "pink", + "purple", + "red", + "teal", + "yellow" + ); + + private List muiShades = List.of( + "50", + "100", + "200", + "300", + "400", + "500", + "600", + "700", + "800", + "900", + "A100", + "A200", + "A400", + "A700" + ); + + public List getDefaultColorPalettes() { + List colorPalettes = new ArrayList<>(); + colorPalettes.add(this.createThemeColorsPalette()); + colorPalettes.add(this.createSpecialColorsPalette()); + this.muiHues.forEach(hue -> { + colorPalettes.add(this.createMUIColorsPalette(hue, this.muiShades)); + }); + return colorPalettes; + } + + private ColorPalette createSpecialColorsPalette() { + ColorPalette colorPalette = ViewFactory.eINSTANCE.createColorPalette(); + colorPalette.setName("Special Colors Palette"); + FixedColor black = ViewFactory.eINSTANCE.createFixedColor(); + black.setName("black"); + black.setValue("#000000"); + colorPalette.getColors().add(black); + FixedColor white = ViewFactory.eINSTANCE.createFixedColor(); + white.setName("white"); + white.setValue("#ffffff"); + colorPalette.getColors().add(white); + FixedColor transparent = ViewFactory.eINSTANCE.createFixedColor(); + transparent.setName("transparent"); + transparent.setValue("transparent"); + colorPalette.getColors().add(transparent); + FixedColor inherit = ViewFactory.eINSTANCE.createFixedColor(); + inherit.setName("inherit"); + inherit.setValue("inherit"); + colorPalette.getColors().add(inherit); + return colorPalette; + } + + private ColorPalette createThemeColorsPalette() { + ColorPalette colorPalette = ViewFactory.eINSTANCE.createColorPalette(); + colorPalette.setName("Theme Colors Palette"); + colorPalette.getColors().addAll(this.themePrimaryColors()); + colorPalette.getColors().addAll(this.themeSecondaryColors()); + colorPalette.getColors().addAll(this.themeTextColors()); + colorPalette.getColors().addAll(this.themeErrorColors()); + return colorPalette; + } + + private List themePrimaryColors() { + List colors = new ArrayList<>(); + FixedColor primaryMain = ViewFactory.eINSTANCE.createFixedColor(); + primaryMain.setName("theme.palette.primary.main"); + primaryMain.setValue("theme.palette.primary.main"); + colors.add(primaryMain); + FixedColor primaryLight = ViewFactory.eINSTANCE.createFixedColor(); + primaryLight.setName("theme.palette.primary.light"); + primaryLight.setValue("theme.palette.primary.light"); + colors.add(primaryLight); + FixedColor primaryDark = ViewFactory.eINSTANCE.createFixedColor(); + primaryDark.setName("theme.palette.primary.dark"); + primaryDark.setValue("theme.palette.primary.dark"); + colors.add(primaryDark); + return colors; + } + + private List themeSecondaryColors() { + List colors = new ArrayList<>(); + FixedColor secondaryMain = ViewFactory.eINSTANCE.createFixedColor(); + secondaryMain.setName("theme.palette.secondary.main"); + secondaryMain.setValue("theme.palette.secondary.main"); + colors.add(secondaryMain); + FixedColor secondaryLight = ViewFactory.eINSTANCE.createFixedColor(); + secondaryLight.setName("theme.palette.secondary.light"); + secondaryLight.setValue("theme.palette.secondary.light"); + colors.add(secondaryLight); + FixedColor secondaryDark = ViewFactory.eINSTANCE.createFixedColor(); + secondaryDark.setName("theme.palette.secondary.dark"); + secondaryDark.setValue("theme.palette.secondary.dark"); + colors.add(secondaryDark); + return colors; + } + + private List themeTextColors() { + List colors = new ArrayList<>(); + FixedColor textPrimary = ViewFactory.eINSTANCE.createFixedColor(); + textPrimary.setName("theme.palette.text.primary"); + textPrimary.setValue("theme.palette.text.primary"); + colors.add(textPrimary); + FixedColor textDisabled = ViewFactory.eINSTANCE.createFixedColor(); + textDisabled.setName("theme.palette.text.disabled"); + textDisabled.setValue("theme.palette.text.disabled"); + colors.add(textDisabled); + FixedColor textHint = ViewFactory.eINSTANCE.createFixedColor(); + textHint.setName("theme.palette.text.hint"); + textHint.setValue("theme.palette.text.hint"); + colors.add(textHint); + return colors; + } + + private List themeErrorColors() { + List colors = new ArrayList<>(); + FixedColor errorMain = ViewFactory.eINSTANCE.createFixedColor(); + errorMain.setName("theme.palette.error.main"); + errorMain.setValue("theme.palette.error.main"); + colors.add(errorMain); + FixedColor errorLight = ViewFactory.eINSTANCE.createFixedColor(); + errorLight.setName("theme.palette.error.light"); + errorLight.setValue("theme.palette.error.light"); + colors.add(errorLight); + FixedColor errorDark = ViewFactory.eINSTANCE.createFixedColor(); + errorDark.setName("theme.palette.error.dark"); + errorDark.setValue("theme.palette.error.dark"); + colors.add(errorDark); + return colors; + } + + private ColorPalette createMUIColorsPalette(String hue, List shades) { + ColorPalette colorPalette = ViewFactory.eINSTANCE.createColorPalette(); + colorPalette.setName(hue.substring(0, 1).toUpperCase() + hue.substring(1) + " Colors Palette"); + for (String shade : shades) { + FixedColor color = ViewFactory.eINSTANCE.createFixedColor(); + color.setName(hue + " " + shade); + color.setValue(hue + "[" + shade + "]"); + colorPalette.getColors().add(color); + } + return colorPalette; + } +} diff --git a/packages/view/backend/sirius-components-view-diagram/src/main/java/org/eclipse/sirius/components/view/diagram/adapters/DiagramColorAdapter.java b/packages/view/backend/sirius-components-view-diagram/src/main/java/org/eclipse/sirius/components/view/diagram/adapters/DiagramColorAdapter.java new file mode 100644 index 00000000000..72ee62815e7 --- /dev/null +++ b/packages/view/backend/sirius-components-view-diagram/src/main/java/org/eclipse/sirius/components/view/diagram/adapters/DiagramColorAdapter.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2023 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.components.view.diagram.adapters; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.util.EContentAdapter; +import org.eclipse.sirius.components.view.diagram.ConditionalNodeStyle; +import org.eclipse.sirius.components.view.diagram.DiagramDescription; +import org.eclipse.sirius.components.view.diagram.DiagramPackage; +import org.eclipse.sirius.components.view.diagram.EdgeDescription; +import org.eclipse.sirius.components.view.diagram.EdgeStyle; +import org.eclipse.sirius.components.view.diagram.NodeDescription; +import org.eclipse.sirius.components.view.diagram.NodeStyleDescription; +import org.eclipse.sirius.components.view.util.services.ColorPaletteService; + +/** + * Adapter allowing to set default colors after the creation of node/edge style elements. + * + * @author arichard + */ +public class DiagramColorAdapter extends EContentAdapter { + + private ColorPaletteService colorPaletteService; + + public DiagramColorAdapter() { + this.colorPaletteService = new ColorPaletteService(); + } + + @Override + public void notifyChanged(Notification notification) { + super.notifyChanged(notification); + if (Notification.ADD == notification.getEventType() && notification.getNotifier() instanceof DiagramDescription && notification.getNewValue() instanceof NodeDescription nodeDescription + && DiagramPackage.DIAGRAM_DESCRIPTION__NODE_DESCRIPTIONS == notification.getFeatureID(DiagramDescription.class)) { + NodeStyleDescription style = nodeDescription.getStyle(); + if (style != null && style.getColor() == null) { + style.setColor(this.colorPaletteService.getColorFromPalette(nodeDescription, "white")); + } + if (style != null && style.getBorderColor() == null) { + style.setBorderColor(this.colorPaletteService.getColorFromPalette(nodeDescription, "black")); + } + if (style != null && style.getLabelColor() == null) { + style.setLabelColor(this.colorPaletteService.getColorFromPalette(nodeDescription, "black")); + } + } else if (Notification.SET == notification.getEventType() && notification.getNotifier() instanceof ConditionalNodeStyle condition && notification.getNewValue() instanceof NodeStyleDescription style + && DiagramPackage.CONDITIONAL_NODE_STYLE__STYLE == notification.getFeatureID(ConditionalNodeStyle.class)) { + if (style.getColor() == null) { + style.setColor(this.colorPaletteService.getColorFromPalette(condition, "white")); + } + if (style.getBorderColor() == null) { + style.setBorderColor(this.colorPaletteService.getColorFromPalette(condition, "black")); + } + if (style.getLabelColor() == null) { + style.setLabelColor(this.colorPaletteService.getColorFromPalette(condition, "black")); + } + } else if (Notification.ADD == notification.getEventType() && notification.getNotifier() instanceof DiagramDescription && notification.getNewValue() instanceof EdgeDescription edgeDescription + && DiagramPackage.DIAGRAM_DESCRIPTION__EDGE_DESCRIPTIONS == notification.getFeatureID(DiagramDescription.class)) { + EdgeStyle style = edgeDescription.getStyle(); + if (style.getColor() == null) { + style.setColor(this.colorPaletteService.getColorFromPalette(edgeDescription, "black")); + } + } else if (Notification.ADD == notification.getEventType() && notification.getNotifier() instanceof EdgeDescription condition && notification.getNewValue() instanceof EdgeStyle style + && DiagramPackage.EDGE_DESCRIPTION__CONDITIONAL_STYLES == notification.getFeatureID(EdgeDescription.class)) { + if (style.getColor() == null) { + style.setColor(this.colorPaletteService.getColorFromPalette(condition, "black")); + } + } + } +} diff --git a/packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/configuration/ViewEMFConfiguration.java b/packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/configuration/ViewEMFConfiguration.java index 9788096b1c4..a0ac2730890 100644 --- a/packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/configuration/ViewEMFConfiguration.java +++ b/packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/configuration/ViewEMFConfiguration.java @@ -17,6 +17,8 @@ import org.eclipse.emf.ecore.EValidator.Registry; import org.eclipse.sirius.components.view.diagram.DiagramPackage; import org.eclipse.sirius.components.view.emf.diagram.DiagramDescriptionValidator; +import org.eclipse.sirius.components.view.emf.diagram.FormDescriptionValidator; +import org.eclipse.sirius.components.view.form.FormPackage; import org.springframework.context.annotation.Configuration; import jakarta.annotation.PostConstruct; @@ -38,5 +40,6 @@ public ViewEMFConfiguration(Registry eValidatorRegistry) { @PostConstruct public void registerViewValidator() { this.eValidatorRegistry.put(DiagramPackage.eINSTANCE, new DiagramDescriptionValidator()); + this.eValidatorRegistry.put(FormPackage.eINSTANCE, new FormDescriptionValidator()); } } diff --git a/packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/diagram/DiagramDescriptionValidator.java b/packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/diagram/DiagramDescriptionValidator.java index 55b3fc9f864..96c11fcef93 100644 --- a/packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/diagram/DiagramDescriptionValidator.java +++ b/packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/diagram/DiagramDescriptionValidator.java @@ -76,6 +76,9 @@ public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnost } if (eObject instanceof NodeStyleDescription nodeStyle) { isValid = this.hasProperColor(nodeStyle, diagnostics) && isValid; + isValid = this.hasProperLabelColor(nodeStyle, diagnostics) && isValid; + isValid = this.hasProperBorderColor(nodeStyle, diagnostics) && isValid; + } if (eObject instanceof ImageNodeStyleDescription imageNodeStyle) { isValid = this.hasProperShape(imageNodeStyle, diagnostics) && isValid; @@ -154,6 +157,44 @@ private boolean hasProperColor(NodeStyleDescription nodeStyle, DiagnosticChain d return isValid; } + private boolean hasProperLabelColor(NodeStyleDescription nodeStyle, DiagnosticChain diagnostics) { + boolean isValid = Objects.nonNull(nodeStyle.getLabelColor()); + + if (!isValid && diagnostics != null) { + BasicDiagnostic basicDiagnostic = new BasicDiagnostic(Diagnostic.ERROR, + SIRIUS_COMPONENTS_EMF_PACKAGE, + 0, + "The label color should not be empty", + new Object [] { + nodeStyle, + DiagramPackage.Literals.NODE_STYLE_DESCRIPTION__LABEL_COLOR, + }); + + diagnostics.add(basicDiagnostic); + } + + return isValid; + } + + private boolean hasProperBorderColor(NodeStyleDescription nodeStyle, DiagnosticChain diagnostics) { + boolean isValid = Objects.nonNull(nodeStyle.getBorderColor()); + + if (!isValid && diagnostics != null) { + BasicDiagnostic basicDiagnostic = new BasicDiagnostic(Diagnostic.ERROR, + SIRIUS_COMPONENTS_EMF_PACKAGE, + 0, + "The border color should not be empty", + new Object [] { + nodeStyle, + DiagramPackage.Literals.BORDER_STYLE__BORDER_COLOR, + }); + + diagnostics.add(basicDiagnostic); + } + + return isValid; + } + private boolean hasProperShape(ImageNodeStyleDescription imageNodeStyle, DiagnosticChain diagnostics) { boolean isValid = Objects.nonNull(imageNodeStyle.getShape()); diff --git a/packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/diagram/FormDescriptionValidator.java b/packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/diagram/FormDescriptionValidator.java new file mode 100644 index 00000000000..7dd32813d16 --- /dev/null +++ b/packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/diagram/FormDescriptionValidator.java @@ -0,0 +1,350 @@ +/******************************************************************************* + * Copyright (c) 2023 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.components.view.emf.diagram; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Optional; + +import org.eclipse.emf.common.util.BasicDiagnostic; +import org.eclipse.emf.common.util.Diagnostic; +import org.eclipse.emf.common.util.DiagnosticChain; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.EValidator; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.sirius.components.compatibility.emf.DomainClassPredicate; +import org.eclipse.sirius.components.domain.Domain; +import org.eclipse.sirius.components.domain.DomainPackage; +import org.eclipse.sirius.components.domain.Entity; +import org.eclipse.sirius.components.view.Conditional; +import org.eclipse.sirius.components.view.CreateInstance; +import org.eclipse.sirius.components.view.ViewPackage; +import org.eclipse.sirius.components.view.form.ContainerBorderStyle; +import org.eclipse.sirius.components.view.form.FormDescription; +import org.eclipse.sirius.components.view.form.FormPackage; +import org.eclipse.sirius.components.view.form.PageDescription; +import org.eclipse.sirius.components.view.form.WidgetDescriptionStyle; + +/** + * The validator for {@link FormDescription}. + * + * @author arichard + */ +public class FormDescriptionValidator implements EValidator { + + public static final String FORM_DESCRIPTION_INVALID_DOMAIN_TYPE_ERROR_MESSAGE = "The form description \"%1$s\" does not have a valid domain class"; + + public static final String FORM_PAGE_DESCRIPTION_INVALID_DOMAIN_TYPE_ERROR_MESSAGE = "The element description \"%1$s\" does not have a valid domain class"; + + public static final String CREATE_INSTANCE_INVALID_DOMAIN_TYPE_ERROR_MESSAGE = "The create instance operation \"%1$s\" does not have a valid domain class"; + + public static final String SIRIUS_COMPONENTS_EMF_PACKAGE = "org.eclipse.sirius.components.emf"; + + @Override + public boolean validate(EObject eObject, DiagnosticChain diagnostics, Map context) { + return true; + } + + @Override + public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map context) { + boolean isValid = true; + if (eObject instanceof FormDescription formDescription) { + isValid = this.hasProperDomainType(formDescription, diagnostics) && isValid; + } + if (eObject instanceof PageDescription pageDescription) { + isValid = this.hasProperDomainType(pageDescription, diagnostics) && isValid; + } + if (eObject instanceof WidgetDescriptionStyle widgetDescriptionStyle) { + isValid = this.hasProperBackgroundColor(widgetDescriptionStyle, diagnostics) && isValid; + isValid = this.hasProperForegroundColor(widgetDescriptionStyle, diagnostics) && isValid; + isValid = this.hasProperColor(widgetDescriptionStyle, diagnostics) && isValid; + } + if (eObject instanceof ContainerBorderStyle containerBorderStyle) { + isValid = this.hasProperBorderColor(containerBorderStyle, diagnostics) && isValid; + } + if (eObject instanceof Conditional conditional) { + isValid = this.conditionIsPresent(conditional, diagnostics) && isValid; + } + if (eObject instanceof CreateInstance createInstance) { + isValid = this.hasProperDomainType(createInstance, diagnostics) && isValid; + } + return isValid; + } + + @Override + public boolean validate(EDataType eDataType, Object value, DiagnosticChain diagnostics, Map context) { + return true; + } + + private boolean conditionIsPresent(Conditional conditional, DiagnosticChain diagnostics) { + boolean isValid = !conditional.getCondition().isBlank(); + + if (!isValid && diagnostics != null) { + BasicDiagnostic basicDiagnostic = new BasicDiagnostic(Diagnostic.ERROR, + SIRIUS_COMPONENTS_EMF_PACKAGE, + 0, + "The condition should not be empty", + new Object [] { + conditional, + ViewPackage.Literals.CONDITIONAL__CONDITION, + }); + + diagnostics.add(basicDiagnostic); + } + + return isValid; + } + + private boolean hasProperBackgroundColor(WidgetDescriptionStyle widgetDescriptionStyle, DiagnosticChain diagnostics) { + EStructuralFeature backgroundColor = widgetDescriptionStyle.eClass().getEStructuralFeature("backgroundColor"); + boolean isValid = Objects.isNull(backgroundColor) || Objects.nonNull(widgetDescriptionStyle.eGet(backgroundColor)); + + if (!isValid && diagnostics != null) { + BasicDiagnostic basicDiagnostic = new BasicDiagnostic(Diagnostic.ERROR, + SIRIUS_COMPONENTS_EMF_PACKAGE, + 0, + "The background color should not be empty", + new Object [] { + widgetDescriptionStyle, + backgroundColor, + }); + + diagnostics.add(basicDiagnostic); + } + + return isValid; + } + + private boolean hasProperForegroundColor(WidgetDescriptionStyle widgetDescriptionStyle, DiagnosticChain diagnostics) { + EStructuralFeature foregroundColor = widgetDescriptionStyle.eClass().getEStructuralFeature("foregroundColor"); + boolean isValid = Objects.isNull(foregroundColor) || Objects.nonNull(widgetDescriptionStyle.eGet(foregroundColor)); + + if (!isValid && diagnostics != null) { + BasicDiagnostic basicDiagnostic = new BasicDiagnostic(Diagnostic.ERROR, + SIRIUS_COMPONENTS_EMF_PACKAGE, + 0, + "The foreground color should not be empty", + new Object [] { + widgetDescriptionStyle, + foregroundColor, + }); + + diagnostics.add(basicDiagnostic); + } + + return isValid; + } + + private boolean hasProperColor(WidgetDescriptionStyle widgetDescriptionStyle, DiagnosticChain diagnostics) { + EStructuralFeature color = widgetDescriptionStyle.eClass().getEStructuralFeature("color"); + boolean isValid = Objects.isNull(color) || Objects.nonNull(widgetDescriptionStyle.eGet(color)); + + if (!isValid && diagnostics != null) { + BasicDiagnostic basicDiagnostic = new BasicDiagnostic(Diagnostic.ERROR, + SIRIUS_COMPONENTS_EMF_PACKAGE, + 0, + "The color should not be empty", + new Object [] { + widgetDescriptionStyle, + color, + }); + + diagnostics.add(basicDiagnostic); + } + + return isValid; + } + + private boolean hasProperBorderColor(ContainerBorderStyle containerBorderStyle, DiagnosticChain diagnostics) { + boolean isValid = Objects.nonNull(containerBorderStyle.getBorderColor()); + + if (!isValid && diagnostics != null) { + BasicDiagnostic basicDiagnostic = new BasicDiagnostic(Diagnostic.ERROR, + SIRIUS_COMPONENTS_EMF_PACKAGE, + 0, + "The border color should not be empty", + new Object [] { + containerBorderStyle, + FormPackage.Literals.CONTAINER_BORDER_STYLE__BORDER_COLOR, + }); + + diagnostics.add(basicDiagnostic); + } + + return isValid; + } + + private boolean hasProperDomainType(FormDescription formDescription, DiagnosticChain diagnostics) { + boolean isValid = false; + ResourceSet resourceSet = formDescription.eResource().getResourceSet(); + List entities = this.getDomainEntitiesFromResourceSet(resourceSet); + List ePackages = this.getEPackagesFromRegistry(resourceSet.getPackageRegistry()); + + String domainType = Optional.ofNullable(formDescription.getDomainType()).orElse(""); + isValid = entities.stream().anyMatch(entity -> this.describesEntity(domainType, entity)); + + if (!isValid && !domainType.isBlank()) { + isValid = ePackages.stream() + .map(EPackage::getEClassifiers) + .flatMap(Collection::stream) + .filter(EClass.class::isInstance) + .map(EClass.class::cast) + .anyMatch(classifier -> new DomainClassPredicate(domainType).test(classifier)); + } + + if (!isValid && diagnostics != null) { + BasicDiagnostic basicDiagnostic = new BasicDiagnostic(Diagnostic.ERROR, + SIRIUS_COMPONENTS_EMF_PACKAGE, + 0, + String.format(FORM_DESCRIPTION_INVALID_DOMAIN_TYPE_ERROR_MESSAGE, domainType), + new Object [] { + formDescription, + ViewPackage.Literals.REPRESENTATION_DESCRIPTION__DOMAIN_TYPE, + }); + + diagnostics.add(basicDiagnostic); + } + + return isValid; + } + + private boolean hasProperDomainType(PageDescription pageDescription, DiagnosticChain diagnostics) { + boolean isValid = false; + ResourceSet resourceSet = pageDescription.eResource().getResourceSet(); + List entities = this.getDomainEntitiesFromResourceSet(resourceSet); + List ePackages = this.getEPackagesFromRegistry(resourceSet.getPackageRegistry()); + + String domainType = Optional.ofNullable(pageDescription.getDomainType()).orElse(""); + isValid = entities.stream().anyMatch(entity -> this.describesEntity(domainType, entity)); + + if (!isValid && !domainType.isBlank()) { + isValid = ePackages.stream() + .map(EPackage::getEClassifiers) + .flatMap(Collection::stream) + .filter(EClass.class::isInstance) + .map(EClass.class::cast) + .anyMatch(classifier -> new DomainClassPredicate(domainType).test(classifier)); + } + + if (!isValid && diagnostics != null) { + BasicDiagnostic basicDiagnostic = new BasicDiagnostic(Diagnostic.ERROR, + SIRIUS_COMPONENTS_EMF_PACKAGE, + 0, + String.format(FORM_PAGE_DESCRIPTION_INVALID_DOMAIN_TYPE_ERROR_MESSAGE, domainType), + new Object [] { + pageDescription, + FormPackage.Literals.PAGE_DESCRIPTION__DOMAIN_TYPE, + }); + + diagnostics.add(basicDiagnostic); + } + + return isValid; + } + + private boolean hasProperDomainType(CreateInstance createInstance, DiagnosticChain diagnostics) { + boolean isValid = false; + ResourceSet resourceSet = createInstance.eResource().getResourceSet(); + List entities = this.getDomainEntitiesFromResourceSet(resourceSet); + List ePackages = this.getEPackagesFromRegistry(resourceSet.getPackageRegistry()); + + String domainType = Optional.ofNullable(createInstance.getTypeName()).orElse(""); + isValid = entities.stream().anyMatch(entity -> this.describesEntity(domainType, entity)); + + if (!isValid && !domainType.isBlank()) { + isValid = ePackages.stream() + .map(EPackage::getEClassifiers) + .flatMap(Collection::stream) + .filter(EClass.class::isInstance) + .map(EClass.class::cast) + .anyMatch(classifier -> new DomainClassPredicate(domainType).test(classifier)); + } + + if (!isValid && diagnostics != null) { + BasicDiagnostic basicDiagnostic = new BasicDiagnostic(Diagnostic.ERROR, + SIRIUS_COMPONENTS_EMF_PACKAGE, + 0, + String.format(CREATE_INSTANCE_INVALID_DOMAIN_TYPE_ERROR_MESSAGE, domainType), + new Object [] { + createInstance, + ViewPackage.Literals.CREATE_INSTANCE__TYPE_NAME, + }); + + diagnostics.add(basicDiagnostic); + } + + return isValid; + } + + private boolean describesEntity(String domainType, Entity entity) { + boolean result = false; + if (Objects.equals(domainType, entity.getName())) { + result = true; + } else if (entity.eContainer() instanceof Domain) { + String domainName = ((Domain) entity.eContainer()).getName(); + result = Objects.equals(domainType, domainName + "::" + entity.getName()); + } + return result; + } + + private List getDomainEntitiesFromResourceSet(ResourceSet resourceSet) { + return resourceSet.getResources().stream() + .map(Resource::getContents) + .flatMap(Collection::stream) + .filter(e -> DomainPackage.Literals.DOMAIN.equals(e.eClass())) + .map(Domain.class::cast) + .map(Domain::getTypes) + .flatMap(Collection::stream) + .toList(); + } + + private List getEPackagesFromRegistry(EPackage.Registry ePackageRegistry) { + List allEPackage = new ArrayList<>(); + + List ePackages = ePackageRegistry.entrySet().stream() + .map(Entry::getValue) + .filter(EPackage.class::isInstance) + .map(EPackage.class::cast) + .toList(); + allEPackage.addAll(ePackages); + + ePackages.stream() + .map(this::getSubPackages) + .forEach(allEPackage::addAll); + + return allEPackage; + } + + private List getSubPackages(EPackage ePackage) { + List allEPackage = new ArrayList<>(); + + EList eSubpackages = ePackage.getESubpackages(); + allEPackage.addAll(eSubpackages); + + eSubpackages.stream() + .map(this::getSubPackages) + .forEach(allEPackage::addAll); + + return allEPackage; + } +} diff --git a/packages/view/backend/sirius-components-view-emf/src/test/java/org/eclipse/sirius/components/view/emf/validation/ViewValidatorTests.java b/packages/view/backend/sirius-components-view-emf/src/test/java/org/eclipse/sirius/components/view/emf/validation/ViewValidatorTests.java index bf9b677795e..3269967be0f 100644 --- a/packages/view/backend/sirius-components-view-emf/src/test/java/org/eclipse/sirius/components/view/emf/validation/ViewValidatorTests.java +++ b/packages/view/backend/sirius-components-view-emf/src/test/java/org/eclipse/sirius/components/view/emf/validation/ViewValidatorTests.java @@ -75,7 +75,6 @@ public void testConditionalConditionIsAbsent() { conditionalNodeStyle.setStyle(DiagramFactory.eINSTANCE.createRectangularNodeStyleDescription()); BasicDiagnostic expected = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null); - // @formatter:off expected.add(new BasicDiagnostic(Diagnostic.ERROR, SIRIUS_COMPONENTS_EMF_PACKAGE, 0, @@ -84,7 +83,6 @@ public void testConditionalConditionIsAbsent() { conditionalNodeStyle, ViewPackage.Literals.CONDITIONAL__CONDITION, })); - // @formatter:on BasicDiagnostic diagnosticChain = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null); boolean validationResult = new DiagramDescriptionValidator().validate(conditionalNodeStyle.eClass(), conditionalNodeStyle, diagnosticChain, defaultContext); @@ -98,7 +96,6 @@ public void testConditionalStyleIsAbsent() { ConditionalNodeStyle conditionalNodeStyle = DiagramFactory.eINSTANCE.createConditionalNodeStyle(); BasicDiagnostic expected = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null); - // @formatter:off expected.add(new BasicDiagnostic(Diagnostic.ERROR, SIRIUS_COMPONENTS_EMF_PACKAGE, 0, @@ -107,7 +104,6 @@ public void testConditionalStyleIsAbsent() { conditionalNodeStyle, DiagramPackage.Literals.CONDITIONAL_NODE_STYLE__STYLE, })); - // @formatter:on BasicDiagnostic diagnosticChain = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null); boolean validationResult = new DiagramDescriptionValidator().validate(conditionalNodeStyle.eClass(), conditionalNodeStyle, diagnosticChain, defaultContext); @@ -121,7 +117,6 @@ public void testNodeStyleColorIsAbsent() { RectangularNodeStyleDescription conditionalNodeStyle = DiagramFactory.eINSTANCE.createRectangularNodeStyleDescription(); BasicDiagnostic expected = new BasicDiagnostic(Diagnostic.ERROR, null, 0, null, null); - // @formatter:off expected.add(new BasicDiagnostic(Diagnostic.ERROR, SIRIUS_COMPONENTS_EMF_PACKAGE, 0, @@ -130,8 +125,22 @@ public void testNodeStyleColorIsAbsent() { conditionalNodeStyle, DiagramPackage.Literals.STYLE__COLOR, })); - // @formatter:on - + expected.add(new BasicDiagnostic(Diagnostic.ERROR, + SIRIUS_COMPONENTS_EMF_PACKAGE, + 0, + "The label color should not be empty", + new Object [] { + conditionalNodeStyle, + DiagramPackage.Literals.NODE_STYLE_DESCRIPTION__LABEL_COLOR, + })); + expected.add(new BasicDiagnostic(Diagnostic.ERROR, + SIRIUS_COMPONENTS_EMF_PACKAGE, + 0, + "The border color should not be empty", + new Object [] { + conditionalNodeStyle, + DiagramPackage.Literals.BORDER_STYLE__BORDER_COLOR, + })); BasicDiagnostic diagnosticChain = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null); boolean validationResult = new DiagramDescriptionValidator().validate(conditionalNodeStyle.eClass(), conditionalNodeStyle, diagnosticChain, defaultContext); assertThat(validationResult).isFalse(); @@ -149,7 +158,6 @@ public void testNodeDescriptionInvalidDomain() { resourceSet.getResources().add(xmiResource); BasicDiagnostic expected = new BasicDiagnostic(Diagnostic.ERROR, null, 0, null, null); - // @formatter:off expected.add(new BasicDiagnostic(Diagnostic.ERROR, SIRIUS_COMPONENTS_EMF_PACKAGE, 0, @@ -159,8 +167,6 @@ public void testNodeDescriptionInvalidDomain() { DiagramPackage.Literals.DIAGRAM_ELEMENT_DESCRIPTION__DOMAIN_TYPE, })); - // @formatter:on - BasicDiagnostic diagnosticChain = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null); boolean validationResult = new DiagramDescriptionValidator().validate(nodeDescription.eClass(), nodeDescription, diagnosticChain, defaultContext); assertThat(validationResult).isFalse(); diff --git a/packages/view/backend/sirius-components-view-form/src/main/java/org/eclipse/sirius/components/view/form/adapters/FormColorAdapter.java b/packages/view/backend/sirius-components-view-form/src/main/java/org/eclipse/sirius/components/view/form/adapters/FormColorAdapter.java new file mode 100644 index 00000000000..e7f3f6b2fff --- /dev/null +++ b/packages/view/backend/sirius-components-view-form/src/main/java/org/eclipse/sirius/components/view/form/adapters/FormColorAdapter.java @@ -0,0 +1,217 @@ +/******************************************************************************* + * Copyright (c) 2023 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.components.view.form.adapters; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.util.EContentAdapter; +import org.eclipse.sirius.components.view.form.ButtonDescription; +import org.eclipse.sirius.components.view.form.ButtonDescriptionStyle; +import org.eclipse.sirius.components.view.form.CheckboxDescription; +import org.eclipse.sirius.components.view.form.CheckboxDescriptionStyle; +import org.eclipse.sirius.components.view.form.FormElementFor; +import org.eclipse.sirius.components.view.form.FormElementIf; +import org.eclipse.sirius.components.view.form.FormPackage; +import org.eclipse.sirius.components.view.form.GroupDescription; +import org.eclipse.sirius.components.view.form.LabelDescription; +import org.eclipse.sirius.components.view.form.LabelDescriptionStyle; +import org.eclipse.sirius.components.view.form.LinkDescription; +import org.eclipse.sirius.components.view.form.LinkDescriptionStyle; +import org.eclipse.sirius.components.view.form.ListDescription; +import org.eclipse.sirius.components.view.form.ListDescriptionStyle; +import org.eclipse.sirius.components.view.form.MultiSelectDescription; +import org.eclipse.sirius.components.view.form.MultiSelectDescriptionStyle; +import org.eclipse.sirius.components.view.form.RadioDescription; +import org.eclipse.sirius.components.view.form.RadioDescriptionStyle; +import org.eclipse.sirius.components.view.form.SelectDescription; +import org.eclipse.sirius.components.view.form.SelectDescriptionStyle; +import org.eclipse.sirius.components.view.form.TextAreaDescription; +import org.eclipse.sirius.components.view.form.TextareaDescriptionStyle; +import org.eclipse.sirius.components.view.form.TextfieldDescription; +import org.eclipse.sirius.components.view.form.TextfieldDescriptionStyle; +import org.eclipse.sirius.components.view.form.WidgetDescription; +import org.eclipse.sirius.components.view.form.WidgetDescriptionStyle; +import org.eclipse.sirius.components.view.form.util.FormSwitch; +import org.eclipse.sirius.components.view.util.services.ColorPaletteService; + +/** + * Adapter allowing to set default colors after the creation of widget style elements. + * + * @author arichard + */ +public class FormColorAdapter extends EContentAdapter { + + + private FormStyleSwitch formStyleSwitch; + + public FormColorAdapter() { + this.formStyleSwitch = new FormStyleSwitch(); + } + + @Override + public void notifyChanged(Notification notification) { + super.notifyChanged(notification); + if (Notification.ADD == notification.getEventType() && notification.getNotifier() instanceof GroupDescription && notification.getNewValue() instanceof WidgetDescription widget + && FormPackage.GROUP_DESCRIPTION__CHILDREN == notification.getFeatureID(GroupDescription.class)) { + WidgetDescriptionStyle style = this.getStyle(widget); + if (style != null) { + this.formStyleSwitch.doSwitch(style); + } + } else if (Notification.ADD == notification.getEventType() && notification.getNotifier() instanceof FormElementFor && notification.getNewValue() instanceof WidgetDescription widget + && FormPackage.FORM_ELEMENT_FOR__CHILDREN == notification.getFeatureID(FormElementFor.class)) { + WidgetDescriptionStyle style = this.getStyle(widget); + if (style != null) { + this.formStyleSwitch.doSwitch(style); + } + } else if (Notification.ADD == notification.getEventType() && notification.getNotifier() instanceof FormElementIf && notification.getNewValue() instanceof WidgetDescription widget + && FormPackage.FORM_ELEMENT_IF__CHILDREN == notification.getFeatureID(FormElementIf.class)) { + WidgetDescriptionStyle style = this.getStyle(widget); + if (style != null) { + this.formStyleSwitch.doSwitch(style); + } + } else if (Notification.SET == notification.getEventType() && notification.getNotifier() instanceof WidgetDescription && notification.getNewValue() instanceof WidgetDescriptionStyle style) { + this.formStyleSwitch.doSwitch(style); + } else if (Notification.ADD == notification.getEventType() && notification.getNotifier() instanceof WidgetDescription && notification.getNewValue() instanceof WidgetDescriptionStyle style) { + this.formStyleSwitch.doSwitch(style); + } + } + + private WidgetDescriptionStyle getStyle(WidgetDescription widget) { + WidgetDescriptionStyle style = null; + if (widget instanceof ButtonDescription styledWidget) { + style = styledWidget.getStyle(); + } else if (widget instanceof CheckboxDescription styledWidget) { + style = styledWidget.getStyle(); + } else if (widget instanceof LabelDescription styledWidget) { + style = styledWidget.getStyle(); + } else if (widget instanceof LinkDescription styledWidget) { + style = styledWidget.getStyle(); + } else if (widget instanceof ListDescription styledWidget) { + style = styledWidget.getStyle(); + } else if (widget instanceof MultiSelectDescription styledWidget) { + style = styledWidget.getStyle(); + } else if (widget instanceof RadioDescription styledWidget) { + style = styledWidget.getStyle(); + } else if (widget instanceof SelectDescription styledWidget) { + style = styledWidget.getStyle(); + } else if (widget instanceof TextAreaDescription styledWidget) { + style = styledWidget.getStyle(); + } else if (widget instanceof TextfieldDescription styledWidget) { + style = styledWidget.getStyle(); + } + return style; + } + + private class FormStyleSwitch extends FormSwitch { + + private ColorPaletteService colorPaletteService; + + public FormStyleSwitch() { + this.colorPaletteService = new ColorPaletteService(); + } + + @Override + public Void caseButtonDescriptionStyle(ButtonDescriptionStyle object) { + if (object.getBackgroundColor() == null) { + object.setBackgroundColor(this.colorPaletteService.getColorFromPalette(object, "theme.palette.primary.light")); + } + if (object.getForegroundColor() == null) { + object.setForegroundColor(this.colorPaletteService.getColorFromPalette(object, "white")); + } + return null; + } + + @Override + public Void caseCheckboxDescriptionStyle(CheckboxDescriptionStyle object) { + if (object.getColor() == null) { + object.setColor(this.colorPaletteService.getColorFromPalette(object, "theme.palette.primary.main")); + } + return null; + } + + @Override + public Void caseLabelDescriptionStyle(LabelDescriptionStyle object) { + if (object.getColor() == null) { + object.setColor(this.colorPaletteService.getColorFromPalette(object, "theme.palette.text.primary")); + } + return null; + } + + @Override + public Void caseLinkDescriptionStyle(LinkDescriptionStyle object) { + if (object.getColor() == null) { + object.setColor(this.colorPaletteService.getColorFromPalette(object, "theme.palette.text.primary")); + } + return null; + } + + @Override + public Void caseListDescriptionStyle(ListDescriptionStyle object) { + if (object.getColor() == null) { + object.setColor(this.colorPaletteService.getColorFromPalette(object, "theme.palette.text.primary")); + } + return null; + } + + @Override + public Void caseMultiSelectDescriptionStyle(MultiSelectDescriptionStyle object) { + if (object.getBackgroundColor() == null) { + object.setBackgroundColor(this.colorPaletteService.getColorFromPalette(object, "transparent")); + } + if (object.getForegroundColor() == null) { + object.setForegroundColor(this.colorPaletteService.getColorFromPalette(object, "theme.palette.text.primary")); + } + return null; + } + + @Override + public Void caseRadioDescriptionStyle(RadioDescriptionStyle object) { + if (object.getColor() == null) { + object.setColor(this.colorPaletteService.getColorFromPalette(object, "theme.palette.primary.main")); + } + return null; + } + + @Override + public Void caseSelectDescriptionStyle(SelectDescriptionStyle object) { + if (object.getBackgroundColor() == null) { + object.setBackgroundColor(this.colorPaletteService.getColorFromPalette(object, "transparent")); + } + if (object.getForegroundColor() == null) { + object.setForegroundColor(this.colorPaletteService.getColorFromPalette(object, "theme.palette.text.primary")); + } + return null; + } + + @Override + public Void caseTextareaDescriptionStyle(TextareaDescriptionStyle object) { + if (object.getBackgroundColor() == null) { + object.setBackgroundColor(this.colorPaletteService.getColorFromPalette(object, "transparent")); + } + if (object.getForegroundColor() == null) { + object.setForegroundColor(this.colorPaletteService.getColorFromPalette(object, "theme.palette.text.primary")); + } + return null; + } + + @Override + public Void caseTextfieldDescriptionStyle(TextfieldDescriptionStyle object) { + if (object.getBackgroundColor() == null) { + object.setBackgroundColor(this.colorPaletteService.getColorFromPalette(object, "transparent")); + } + if (object.getForegroundColor() == null) { + object.setForegroundColor(this.colorPaletteService.getColorFromPalette(object, "theme.palette.text.primary")); + } + return null; + } + } +} diff --git a/packages/view/backend/sirius-components-view/src/main/java/org/eclipse/sirius/components/view/util/services/ColorPaletteService.java b/packages/view/backend/sirius-components-view/src/main/java/org/eclipse/sirius/components/view/util/services/ColorPaletteService.java new file mode 100644 index 00000000000..774e6629d2c --- /dev/null +++ b/packages/view/backend/sirius-components-view/src/main/java/org/eclipse/sirius/components/view/util/services/ColorPaletteService.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2023 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.components.view.util.services; + +import java.util.Collection; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.sirius.components.view.ColorPalette; +import org.eclipse.sirius.components.view.UserColor; +import org.eclipse.sirius.components.view.View; + +/** + * Service class to access {@link ColorPalette}'s colors. + * + * @author arichard + */ +public class ColorPaletteService { + + public UserColor getColorFromPalette(View view, String colorName) { + return view.getColorPalettes() + .stream() + .map(ColorPalette::getColors) + .flatMap(Collection::stream) + .filter(userColor -> userColor.getName().equals(colorName)) + .findFirst() + .orElse(null); + } + + public UserColor getColorFromPalette(Object object, String colorName) { + if (object instanceof View view) { + return this.getColorFromPalette(view, colorName); + } else if (object instanceof EObject eObject) { + return this.getColorFromPalette(eObject.eContainer(), colorName); + } + return null; + } +}