Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2236] Add support for For/If in FormDescriptionEditor
Bug: #2236 Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
- Loading branch information
Showing
34 changed files
with
1,679 additions
and
144 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
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
122 changes: 122 additions & 0 deletions
122
...n/java/org/eclipse/sirius/components/formdescriptioneditors/FormDescriptionEditorFor.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,122 @@ | ||
/******************************************************************************* | ||
* 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.formdescriptioneditors; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.function.Supplier; | ||
|
||
import org.eclipse.sirius.components.annotations.Immutable; | ||
import org.eclipse.sirius.components.forms.AbstractWidget; | ||
import org.eclipse.sirius.components.forms.validation.Diagnostic; | ||
|
||
/** | ||
* A widget to represent a "For" element when rendering a Form in the context of a FormDescriptionEditor. | ||
* | ||
* @author pcdavid | ||
*/ | ||
@Immutable | ||
public final class FormDescriptionEditorFor extends AbstractWidget { | ||
private List<AbstractWidget> children; | ||
|
||
private FormDescriptionEditorFor() { | ||
// Prevent instantiation | ||
} | ||
|
||
public List<AbstractWidget> getChildren() { | ||
return this.children; | ||
} | ||
|
||
public boolean hasHelpText() { | ||
return false; | ||
} | ||
|
||
public static Builder newFormDescriptionEditorFor(String id) { | ||
return new Builder(id); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String pattern = "{0} '{'id: {1}, label: {2}'}'"; | ||
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.getId(), this.label); | ||
} | ||
|
||
/** | ||
* The builder used to create the For widget. | ||
* | ||
* @author pcdavid | ||
*/ | ||
@SuppressWarnings("checkstyle:HiddenField") | ||
public static final class Builder { | ||
private String id; | ||
|
||
private String label; | ||
|
||
private String iconURL; | ||
|
||
private List<Diagnostic> diagnostics; | ||
|
||
private Supplier<String> helpTextProvider; | ||
|
||
private boolean readOnly; | ||
|
||
private List<AbstractWidget> children; | ||
|
||
private Builder(String id) { | ||
this.id = Objects.requireNonNull(id); | ||
} | ||
|
||
public Builder label(String label) { | ||
this.label = Objects.requireNonNull(label); | ||
return this; | ||
} | ||
|
||
public Builder iconURL(String iconURL) { | ||
this.iconURL = Objects.requireNonNull(iconURL); | ||
return this; | ||
} | ||
|
||
public Builder diagnostics(List<Diagnostic> diagnostics) { | ||
this.diagnostics = Objects.requireNonNull(diagnostics); | ||
return this; | ||
} | ||
|
||
public Builder helpTextProvider(Supplier<String> helpTextProvider) { | ||
this.helpTextProvider = Objects.requireNonNull(helpTextProvider); | ||
return this; | ||
} | ||
|
||
public Builder readOnly(boolean readOnly) { | ||
this.readOnly = readOnly; | ||
return this; | ||
} | ||
|
||
public Builder children(List<AbstractWidget> children) { | ||
this.children = Objects.requireNonNull(children); | ||
return this; | ||
} | ||
|
||
public FormDescriptionEditorFor build() { | ||
FormDescriptionEditorFor formDescriptionEditorFor = new FormDescriptionEditorFor(); | ||
formDescriptionEditorFor.id = Objects.requireNonNull(this.id); | ||
formDescriptionEditorFor.label = Objects.requireNonNull(this.label); | ||
formDescriptionEditorFor.iconURL = this.iconURL; | ||
formDescriptionEditorFor.diagnostics = Objects.requireNonNull(this.diagnostics); | ||
formDescriptionEditorFor.helpTextProvider = this.helpTextProvider; // Optional on purpose | ||
formDescriptionEditorFor.readOnly = this.readOnly; | ||
formDescriptionEditorFor.children = Objects.requireNonNull(this.children); | ||
return formDescriptionEditorFor; | ||
} | ||
} | ||
} |
Oops, something went wrong.