forked from eclipse-sirius/sirius-web
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1265] Handle Flexbox Container on FormDescriptionEditors
Bug: eclipse-sirius#1265 Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
- Loading branch information
1 parent
a982c6c
commit fe2f1b7
Showing
41 changed files
with
1,764 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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 SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon'; | ||
import React from 'react'; | ||
|
||
export const FlexboxContainer = (props: SvgIconProps) => { | ||
return ( | ||
<SvgIcon | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
aria-labelledby="title" | ||
aria-describedby="desc" | ||
role="img" | ||
{...props} | ||
> | ||
<path d="M14.67,5v14H9.33V5H14.67z M15.67,19H21V5h-5.33V19z M8.33,19V5H3v14H8.33z"></path> | ||
</SvgIcon> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...mponents/collaborative/formdescriptioneditors/handlers/DeleteWidgetEventHandlerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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.collaborative.formdescriptioneditors.handlers; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.collaborative.api.ChangeDescription; | ||
import org.eclipse.sirius.components.collaborative.api.ChangeKind; | ||
import org.eclipse.sirius.components.collaborative.formdescriptioneditors.FormDescriptionEditorContext; | ||
import org.eclipse.sirius.components.collaborative.formdescriptioneditors.TestFormDescriptionEditorBuilder; | ||
import org.eclipse.sirius.components.collaborative.formdescriptioneditors.api.IFormDescriptionEditorContext; | ||
import org.eclipse.sirius.components.collaborative.formdescriptioneditors.dto.DeleteWidgetInput; | ||
import org.eclipse.sirius.components.collaborative.formdescriptioneditors.dto.DeleteWidgetSuccessPayload; | ||
import org.eclipse.sirius.components.collaborative.formdescriptioneditors.messages.ICollaborativeFormDescriptionEditorMessageService; | ||
import org.eclipse.sirius.components.core.api.IEditService; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.core.api.IObjectService; | ||
import org.eclipse.sirius.components.core.api.IPayload; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry; | ||
import reactor.core.publisher.Sinks; | ||
import reactor.core.publisher.Sinks.Many; | ||
import reactor.core.publisher.Sinks.One; | ||
|
||
/** | ||
* Tests of the delete widget event handler. | ||
* | ||
* @author arichard | ||
*/ | ||
public class DeleteWidgetEventHandlerTests { | ||
@Test | ||
public void testDeleteWidget() { | ||
var handler = new DeleteWidgetEventHandler(new IObjectService.NoOp(), new IEditService.NoOp(), new ICollaborativeFormDescriptionEditorMessageService.NoOp(), new SimpleMeterRegistry()) { | ||
@Override | ||
protected boolean deleteWidget(IEditingContext editingContext, IFormDescriptionEditorContext formDescriptionEditorContext, String widgetId) { | ||
return true; | ||
} | ||
}; | ||
var input = new DeleteWidgetInput(UUID.randomUUID(), "editingContextId", "representationId", "widgetId"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ | ||
|
||
assertThat(handler.canHandle(input)).isTrue(); | ||
|
||
One<IPayload> payloadSink = Sinks.one(); | ||
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer(); | ||
IFormDescriptionEditorContext formDescriptionEditorContext = new FormDescriptionEditorContext(new TestFormDescriptionEditorBuilder().getFormDescriptionEditor(UUID.randomUUID().toString())); | ||
|
||
handler.handle(payloadSink, changeDescriptionSink, new IEditingContext.NoOp(), formDescriptionEditorContext, input); | ||
|
||
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst(); | ||
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE); | ||
|
||
IPayload payload = payloadSink.asMono().block(); | ||
assertThat(payload).isInstanceOf(DeleteWidgetSuccessPayload.class); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...components/collaborative/formdescriptioneditors/handlers/MoveWidgetEventHandlerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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.collaborative.formdescriptioneditors.handlers; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.collaborative.api.ChangeDescription; | ||
import org.eclipse.sirius.components.collaborative.api.ChangeKind; | ||
import org.eclipse.sirius.components.collaborative.formdescriptioneditors.FormDescriptionEditorContext; | ||
import org.eclipse.sirius.components.collaborative.formdescriptioneditors.TestFormDescriptionEditorBuilder; | ||
import org.eclipse.sirius.components.collaborative.formdescriptioneditors.api.IFormDescriptionEditorContext; | ||
import org.eclipse.sirius.components.collaborative.formdescriptioneditors.dto.MoveWidgetInput; | ||
import org.eclipse.sirius.components.collaborative.formdescriptioneditors.dto.MoveWidgetSuccessPayload; | ||
import org.eclipse.sirius.components.collaborative.formdescriptioneditors.messages.ICollaborativeFormDescriptionEditorMessageService; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.core.api.IObjectService; | ||
import org.eclipse.sirius.components.core.api.IPayload; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry; | ||
import reactor.core.publisher.Sinks; | ||
import reactor.core.publisher.Sinks.Many; | ||
import reactor.core.publisher.Sinks.One; | ||
|
||
/** | ||
* Tests of the move widget event handler. | ||
* | ||
* @author arichard | ||
*/ | ||
public class MoveWidgetEventHandlerTests { | ||
@Test | ||
public void testMoveWidget() { | ||
var handler = new MoveWidgetEventHandler(new IObjectService.NoOp(), new ICollaborativeFormDescriptionEditorMessageService.NoOp(), new SimpleMeterRegistry()) { | ||
@Override | ||
protected boolean moveWidget(IEditingContext editingContext, IFormDescriptionEditorContext formDescriptionEditorContext, String containerId, String kind, int index) { | ||
return true; | ||
} | ||
}; | ||
var input = new MoveWidgetInput(UUID.randomUUID(), "editingContextId", "representationId", "containerId", "kind", 0); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ | ||
|
||
assertThat(handler.canHandle(input)).isTrue(); | ||
|
||
One<IPayload> payloadSink = Sinks.one(); | ||
Many<ChangeDescription> changeDescriptionSink = Sinks.many().unicast().onBackpressureBuffer(); | ||
IFormDescriptionEditorContext formDescriptionEditorContext = new FormDescriptionEditorContext(new TestFormDescriptionEditorBuilder().getFormDescriptionEditor(UUID.randomUUID().toString())); | ||
|
||
handler.handle(payloadSink, changeDescriptionSink, new IEditingContext.NoOp(), formDescriptionEditorContext, input); | ||
|
||
ChangeDescription changeDescription = changeDescriptionSink.asFlux().blockFirst(); | ||
assertThat(changeDescription.getKind()).isEqualTo(ChangeKind.SEMANTIC_CHANGE); | ||
|
||
IPayload payload = payloadSink.asMono().block(); | ||
assertThat(payload).isInstanceOf(MoveWidgetSuccessPayload.class); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...eclipse/sirius/components/formdescriptioneditors/AbstractFormDescriptionEditorWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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.formdescriptioneditors; | ||
|
||
/** | ||
* Abstract class to be extended by all the widgets of the form-description-editor representation. | ||
* | ||
* @author arichard | ||
*/ | ||
public class AbstractFormDescriptionEditorWidget implements IFormDescriptionEditorWidget { | ||
|
||
protected String id; | ||
|
||
protected String kind; | ||
|
||
protected String label; | ||
|
||
@Override | ||
public String getId() { | ||
return this.id; | ||
} | ||
|
||
@Override | ||
public String getKind() { | ||
return this.kind; | ||
} | ||
|
||
@Override | ||
public String getLabel() { | ||
return this.label; | ||
} | ||
|
||
} |
134 changes: 134 additions & 0 deletions
134
...lipse/sirius/components/formdescriptioneditors/FormDescriptionEditorFlexboxContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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.formdescriptioneditors; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.sirius.components.annotations.Immutable; | ||
|
||
/** | ||
* Any widget contained in the form description editor flexbox container. | ||
* | ||
* @author arichard | ||
*/ | ||
@Immutable | ||
public final class FormDescriptionEditorFlexboxContainer extends AbstractFormDescriptionEditorWidget { | ||
|
||
private String flexDirection; | ||
|
||
private String flexWrap; | ||
|
||
private int flexGrow; | ||
|
||
private List<AbstractFormDescriptionEditorWidget> children; | ||
|
||
private FormDescriptionEditorFlexboxContainer() { | ||
// Prevent instantiation | ||
} | ||
|
||
public String getFlexDirection() { | ||
return this.flexDirection; | ||
} | ||
|
||
public String getFlexWrap() { | ||
return this.flexWrap; | ||
} | ||
|
||
public int getFlexGrow() { | ||
return this.flexGrow; | ||
} | ||
|
||
public List<AbstractFormDescriptionEditorWidget> getChildren() { | ||
return this.children; | ||
} | ||
|
||
public static Builder newFormDescriptionEditorFlexboxContainer(String id) { | ||
return new Builder(id); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String pattern = "{0} '{'id: {1}, kind: {2}, label: {3}, flexDirection: {4}, flexWrap: {5}, flexGrow: {6}'}'"; //$NON-NLS-1$ | ||
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.kind, this.label, this.flexDirection, this.flexWrap, this.flexGrow); | ||
} | ||
|
||
/** | ||
* The builder used to create the form description editor flexbox container. | ||
* | ||
* @author arichard | ||
*/ | ||
@SuppressWarnings("checkstyle:HiddenField") | ||
public static final class Builder { | ||
private String id; | ||
|
||
private String kind; | ||
|
||
private String label; | ||
|
||
private String flexDirection; | ||
|
||
private String flexWrap; | ||
|
||
private int flexGrow; | ||
|
||
private List<AbstractFormDescriptionEditorWidget> children; | ||
|
||
private Builder(String id) { | ||
this.id = Objects.requireNonNull(id); | ||
} | ||
|
||
public Builder kind(String kind) { | ||
this.kind = Objects.requireNonNull(kind); | ||
return this; | ||
} | ||
|
||
public Builder label(String label) { | ||
this.label = Objects.requireNonNull(label); | ||
return this; | ||
} | ||
|
||
public Builder flexDirection(String flexDirection) { | ||
this.flexDirection = Objects.requireNonNull(flexDirection); | ||
return this; | ||
} | ||
|
||
public Builder flexWrap(String flexWrap) { | ||
this.flexWrap = Objects.requireNonNull(flexWrap); | ||
return this; | ||
} | ||
|
||
public Builder flexGrow(int flexGrow) { | ||
this.flexGrow = Objects.requireNonNull(flexGrow); | ||
return this; | ||
} | ||
|
||
public Builder children(List<AbstractFormDescriptionEditorWidget> children) { | ||
this.children = Objects.requireNonNull(children); | ||
return this; | ||
} | ||
|
||
public FormDescriptionEditorFlexboxContainer build() { | ||
FormDescriptionEditorFlexboxContainer fdeFlexboxContainer = new FormDescriptionEditorFlexboxContainer(); | ||
fdeFlexboxContainer.id = Objects.requireNonNull(this.id); | ||
fdeFlexboxContainer.kind = Objects.requireNonNull(this.kind); | ||
fdeFlexboxContainer.label = Objects.requireNonNull(this.label); | ||
fdeFlexboxContainer.flexDirection = Objects.requireNonNull(this.flexDirection); | ||
fdeFlexboxContainer.flexWrap = Objects.requireNonNull(this.flexWrap); | ||
fdeFlexboxContainer.flexGrow = Objects.requireNonNull(this.flexGrow); | ||
fdeFlexboxContainer.children = Objects.requireNonNull(this.children); | ||
return fdeFlexboxContainer; | ||
} | ||
} | ||
} |
Oops, something went wrong.