Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve styling and simplify workflow example #148

Merged
merged 4 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2021 EclipseSource and others.
* Copyright (c) 2021-2022 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -23,6 +23,7 @@
import org.eclipse.glsp.example.workflow.wfgraph.WfgraphPackage;
import org.eclipse.glsp.graph.GNode;
import org.eclipse.glsp.graph.GPoint;
import org.eclipse.glsp.graph.builder.impl.GArguments;
import org.eclipse.glsp.server.model.GModelState;
import org.eclipse.glsp.server.utils.GModelUtil;

Expand All @@ -38,7 +39,8 @@ protected CategoryNodeBuilder builder(final Optional<GPoint> point, final GModel
String name = "Category " + nodeCounter;

return new CategoryNodeBuilder(name) //
.position(point.orElse(null));
.position(point.orElse(null))
.addArguments(GArguments.cornerRadius(5));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2019-2021 EclipseSource and others.
* Copyright (c) 2019-2022 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -16,8 +16,11 @@
package org.eclipse.glsp.example.workflow.labeledit;

import java.util.Set;
import java.util.stream.Stream;

import org.eclipse.glsp.example.workflow.utils.ModelTypes;
import org.eclipse.glsp.example.workflow.wfgraph.TaskNode;
import org.eclipse.glsp.graph.GLabel;
import org.eclipse.glsp.graph.GModelElement;
import org.eclipse.glsp.server.features.directediting.LabelEditValidator;
import org.eclipse.glsp.server.features.directediting.ValidationStatus;
Expand All @@ -37,9 +40,15 @@ public ValidationStatus validate(final String label, final GModelElement element
}

Set<TaskNode> taskNodes = modelState.getIndex().getAllByClass(TaskNode.class);
boolean hasDuplicate = taskNodes.stream()
Stream<GLabel> otherLabels = taskNodes.stream()
.filter(e -> !e.getId().equals(element.getId()))
.map(TaskNode::getName).anyMatch(name -> name.equals(label));
.flatMap(n -> n.getChildren().stream())
.filter(c -> ModelTypes.LABEL_HEADING.equals(c.getType()))
.filter(GLabel.class::isInstance)
.map(GLabel.class::cast);

boolean hasDuplicate = otherLabels.anyMatch(otherLabel -> label.equals(otherLabel.getText()));

if (hasDuplicate) {
return ValidationStatus.warning("Name should be unique");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2019-2021 EclipseSource and others.
* Copyright (c) 2019-2022 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -19,19 +19,17 @@
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.eclipse.glsp.example.workflow.utils.ModelTypes;
import org.eclipse.glsp.example.workflow.wfgraph.ActivityNode;
import org.eclipse.glsp.example.workflow.wfgraph.TaskNode;
import org.eclipse.glsp.graph.GCompartment;
import org.eclipse.glsp.graph.GEdge;
import org.eclipse.glsp.graph.GLabel;
import org.eclipse.glsp.graph.GModelElement;
import org.eclipse.glsp.server.features.validation.Marker;
import org.eclipse.glsp.server.features.validation.MarkerKind;
import org.eclipse.glsp.server.features.validation.ModelValidator;
import org.eclipse.glsp.server.model.GModelState;
import org.eclipse.glsp.server.utils.GModelUtil;

import com.google.inject.Inject;

Expand Down Expand Up @@ -84,11 +82,15 @@ private static Optional<Marker> validateTaskNode_isAutomated(final GModelState m
private static Optional<Marker> validateTaskNode_labelStartsUpperCase(final GModelState modelState,
final GModelElement element) {
TaskNode taskNode = (TaskNode) element;
List<GCompartment> gCompartment = GModelUtil.filterByType(taskNode.getChildren(), GCompartment.class)
.collect(Collectors.toList());
List<GLabel> gLabels = GModelUtil.filterByType(gCompartment.get(0).getChildren(), GLabel.class)
.collect(Collectors.toList());
if (gLabels.size() > 0 && !Character.isUpperCase(gLabels.get(0).getText().charAt(0))) {

boolean hasLowerCaseLabel = taskNode.getChildren().stream()
.filter(c -> ModelTypes.LABEL_HEADING.equals(c.getType()))
.filter(GLabel.class::isInstance)
.map(GLabel.class::cast)
.map(GLabel::getText)
.anyMatch(text -> text.length() > 0 && !Character.isUpperCase(text.charAt(0)));

if (hasLowerCaseLabel) {
return Optional.of(new Marker("Task node label in upper case",
"Task node names should start with upper case letters", element.getId(), MarkerKind.WARNING));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2019-2021 EclipseSource and others.
* Copyright (c) 2019-2022 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -31,9 +31,7 @@
import org.eclipse.glsp.graph.builder.AbstractGNodeBuilder;
import org.eclipse.glsp.graph.builder.impl.GCompartmentBuilder;
import org.eclipse.glsp.graph.builder.impl.GLabelBuilder;
import org.eclipse.glsp.graph.builder.impl.GLayoutOptions;
import org.eclipse.glsp.graph.util.GConstants;
import org.eclipse.glsp.graph.util.GConstants.HAlign;

public final class WorkflowBuilder {

Expand Down Expand Up @@ -126,20 +124,14 @@ public void setProperties(final TaskNode taskNode) {
taskNode.setName(name);
taskNode.setTaskType(taskType);
taskNode.setDuration(duration);
taskNode.setLayout(GConstants.Layout.VBOX);
taskNode.getChildren().add(createCompartment(taskNode));
planger marked this conversation as resolved.
Show resolved Hide resolved
taskNode.setLayout(GConstants.Layout.HBOX);
taskNode.getLayoutOptions().put("paddingRight", 10);
taskNode.getChildren().add(createCompartmentIcon(taskNode));
taskNode.getChildren().add(createCompartmentHeader(taskNode));
}

private GCompartment createCompartment(final TaskNode taskNode) {
Map<String, Object> layoutOptions = new HashMap<>();

return new GCompartmentBuilder(ModelTypes.COMP_HEADER) //
.id(taskNode.getId() + "_header") //
.layout(GConstants.Layout.HBOX) //
.layoutOptions(layoutOptions) //
.add(createCompartmentIcon(taskNode)) //
.add(createCompartmentHeader(taskNode)) //
.build();
private Icon createCompartmentIcon(final TaskNode taskNode) {
return new IconBuilder().id(taskNode.getId() + "_icon").build();
}

private GLabel createCompartmentHeader(final TaskNode taskNode) {
Expand All @@ -149,23 +141,6 @@ private GLabel createCompartmentHeader(final TaskNode taskNode) {
.build();
}

private Icon createCompartmentIcon(final TaskNode taskNode) {
return new IconBuilder() //
.id(taskNode.getId() + "_icon") //
.layout(GConstants.Layout.STACK) //
.layoutOptions(new GLayoutOptions() //
.hAlign(HAlign.CENTER) //
.resizeContainer(false)) //
.add(createCompartmentIconLabel(taskNode)).build();
}

private GLabel createCompartmentIconLabel(final TaskNode taskNode) {
return new GLabelBuilder(ModelTypes.LABEL_ICON) //
.id(taskNode.getId() + "_ticon") //
.text("" + taskNode.getTaskType().toUpperCase().charAt(0)) //
.build();
}

}

public static class IconBuilder extends AbstractGCompartmentBuilder<Icon, IconBuilder> {
Expand Down