Skip to content

Commit

Permalink
- began fixing #8 Support for variable names
Browse files Browse the repository at this point in the history
- removed unused method from AbstractPropertyRenderer
- began fixing #35 partly
- added fix for build issue
- added missing translation
- fixed possible issue in ImageRenderer
- added missing method to CompilationMetaInformation
- close #46
- close #48
- close #47
- close #50
  • Loading branch information
appreciated committed Oct 21, 2020
1 parent b04a6a2 commit cd188da
Show file tree
Hide file tree
Showing 37 changed files with 222 additions and 168 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@
</goals>
</execution>
</executions>
<configuration>
<wait>1000</wait>
<maxAttempts>180</maxAttempts>
</configuration>
</plugin>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.github.appreciated.designer.application.view.file.designer.sidebar.renderer.property.interfaces.HasStyleRenderer;
import com.github.appreciated.designer.application.view.file.designer.sidebar.renderer.type.AbstractPropertyRenderer;
import com.github.appreciated.designer.component.ComponentPropertyParser;
import com.github.appreciated.designer.component.designer.StyleEditorDetails;
import com.github.appreciated.designer.component.designer.StyleEditor;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasComponents;
import com.vaadin.flow.component.HasStyle;
Expand Down Expand Up @@ -62,7 +62,7 @@ private void onFocus(Component propertyParent) {
if (renderer.canRender(propertyParent)) {
Stream<RenderPair> component = renderer.render((HasStyle) propertyParent);
RenderPair pair = component.findFirst().get();
StyleEditorDetails details = (StyleEditorDetails) pair.getPropertyComponent();
StyleEditor details = (StyleEditor) pair.getPropertyComponent();
renderers.getPropertyRenderers().stream()
.filter(interfaceRenderer -> interfaceRenderer.canRender(propertyParent))
.forEach(interfaceRenderer -> details.removeRenderedStyles(interfaceRenderer.rendersCssStyle()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public StructureView(final ProjectFileModel projectFileModel) {
info = projectFileModel.getInformation();

grid.addHierarchyColumn(component -> {
if (info.hasComponentMetainfo(component) && info.getComponentMetainfo(component).isProjectComponent()) {
return info.getComponentMetainfo(component).getClassName();
if (info.hasCompilationMetaInformation(component) && info.getCompilationMetaInformation(component).isProjectComponent()) {
return info.getCompilationMetaInformation(component).getClassName();
} else {
return component.getClass().getSimpleName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public abstract class AbstractPropertyRenderer<T> {

public abstract boolean canRender(Component propertyParent);

public abstract void applyValue(T propertyParent);

public void setValueButNull(HasValue field, Object value) {
if (value != null) {
field.setValue(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.appreciated.designer.application.view.file.designer.sidebar.renderer.AbstractPropertyRenderer;
import com.github.appreciated.designer.application.view.file.designer.sidebar.renderer.RenderPair;
import com.github.appreciated.designer.model.CompilationMetaInformation;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.binder.Binder;
Expand All @@ -25,11 +26,16 @@ public Stream<RenderPair> render(Component component) {
componentBinder.forField(id)
.bind(component1 -> component1.getId().orElse(null), Component::setId);
componentBinder.setBean(component);
return Stream.of(new RenderPair("id", id));
}

@Override
public void applyValue(Component propertyParent) {

TextField variableName = new TextField();
variableName.setValueChangeMode(ValueChangeMode.EAGER);
boolean hasInfo = getProjectFileModel().getInformation().hasCompilationMetaInformation(component);
CompilationMetaInformation info = getProjectFileModel().getInformation().getCompilationMetaInformation(component);
if (hasInfo && info.hasVariableName()) {
variableName.setValue(info.getVariableName());
}
variableName.addValueChangeListener(event -> info.setVariableName(event.getValue()));
return Stream.of(new RenderPair("id", id), new RenderPair("variableName", variableName));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public Stream<RenderPair> render(Image component) {
is.setSrc(component.getSrc());
src.setValue(component.getSrc());
setSrc(component, src);
} else if (getProjectFileModel().getInformation().getComponentMetainfo(component).hasPropertyReplacement("src")) {
is.setSrc((String) getProjectFileModel().getInformation().getComponentMetainfo(component).getPropertyReplacement("src"));
} else if (getProjectFileModel().getInformation().getCompilationMetaInformation(component).hasPropertyReplacement("src")) {
is.setSrc((String) getProjectFileModel().getInformation().getCompilationMetaInformation(component).getPropertyReplacement("src"));
}
sourceBinder.setBean(is);
src.addBlurListener(textFieldBlurEvent -> sourceBinder.validate());
Expand All @@ -62,13 +62,13 @@ public Stream<RenderPair> render(Image component) {
}

public void setSrc(Image component, TextField src) {
if (component != null || (src.getValue() != null && !src.getValue().equals(""))) {
if (src.getValue() != null && !src.getValue().equals("")) {
if (component != null) {
if (src.getValue() != null && (src.getValue() != null && !src.getValue().equals(""))) {
component.setSrc(new FileStreamResource(new File(getProjectFileModel().getInformation().getProject().getFrontendFolder() + File.separator + src.getValue().replace("/", File.separator))));
getProjectFileModel().getInformation().getOrCreateCompilationMetainformation(component).setPropertyReplacement("src", src.getValue());
getProjectFileModel().getInformation().getOrCreateCompilationMetaInformation(component).setPropertyReplacement("src", src.getValue());
} else {
component.getElement().setAttribute("src", "");
getProjectFileModel().getInformation().getOrCreateCompilationMetainformation(component).setPropertyReplacement("src", null);
getProjectFileModel().getInformation().getOrCreateCompilationMetaInformation(component).removePropertyReplacement("src");
}
}
}
Expand All @@ -83,10 +83,6 @@ public Stream<String> rendersProperty() {
return Stream.of("src");
}

@Override
public void applyValue(Image propertyParent) {

}

class ImageSource {
String src;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,4 @@ public Stream<String> rendersCssStyle() {
return super.rendersCssStyle();
}

@Override
public void applyValue(FlexComponent propertyParent) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import com.github.appreciated.designer.application.view.file.designer.sidebar.renderer.AbstractPropertyRenderer;
import com.github.appreciated.designer.application.view.file.designer.sidebar.renderer.RenderPair;
import com.github.appreciated.designer.component.designer.StringItemsEditor;
import com.github.appreciated.designer.model.CompilationMetaInformation;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.data.binder.HasItems;
import com.vaadin.flow.data.provider.Query;
import org.vaadin.gatanaso.MultiselectComboBox;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class HasItemsRenderer extends AbstractPropertyRenderer<HasItems> {
Expand All @@ -20,35 +17,23 @@ public boolean canRender(Component propertyParent) {
return propertyParent instanceof HasItems;
}

@Override
public void applyValue(HasItems propertyParent) {

}

@Override
public Stream<RenderPair> render(HasItems propertyParent) {
MultiselectComboBox<String> multiselectComboBox = new MultiselectComboBox<>();
multiselectComboBox.setWidth("100%");
multiselectComboBox.setPlaceholder("Add some items");
// custom values handler to process the added value(s)
multiselectComboBox.addCustomValuesSetListener(e -> {
LinkedHashSet<String> value = new LinkedHashSet<>(multiselectComboBox.getValue());
value.add(e.getDetail());
List<String> updatedItems = multiselectComboBox.getDataProvider().fetch(new Query<>()).collect(Collectors.toList());
updatedItems.add(e.getDetail());
multiselectComboBox.setItems(updatedItems);
multiselectComboBox.setValue(value);
});
if (getProjectFileModel().getInformation().hasComponentMetainfo((Component) propertyParent) && getProjectFileModel().getInformation().getComponentMetainfo((Component) propertyParent).hasPropertyReplacement("items")) {
multiselectComboBox.setItems((Set<String>) getProjectFileModel().getInformation().getComponentMetainfo((Component) propertyParent).getPropertyReplacement("items"));
multiselectComboBox.setValue((Set<String>) getProjectFileModel().getInformation().getComponentMetainfo((Component) propertyParent).getPropertyReplacement("items"));
}

multiselectComboBox.addValueChangeListener(event -> {
getProjectFileModel().getInformation().getOrCreateCompilationMetainformation((Component) propertyParent).setPropertyReplacement("items", event.getValue());
propertyParent.setItems(event.getValue());
});
return Stream.of(new RenderPair("items", multiselectComboBox));

boolean hasMetaInformation = getProjectFileModel().getInformation().hasCompilationMetaInformation((Component) propertyParent);
CompilationMetaInformation metaInformation = getProjectFileModel().getInformation().getCompilationMetaInformation((Component) propertyParent);

return Stream.of(
new RenderPair("items",
new StringItemsEditor("items",
(hasMetaInformation ? ((List<String>) metaInformation.getPropertyReplacement("items")).stream() : Stream.empty()),
collection -> {
propertyParent.setItems(collection);
getProjectFileModel().getInformation().getOrCreateCompilationMetaInformation((Component) propertyParent).setPropertyReplacement("items", collection);
}
)
)
);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public Stream<RenderPair> render(HasSize component) {
new IconButton(VaadinIcon.ARROWS_LONG_H.create(),
buttonClickEvent -> widthComponent.setValue("100%"))
);
String widht = widthComponent.getWidth();
String styleWidth = widthComponent.getStyle().get("width");
widthComponent.setValueChangeMode(ValueChangeMode.EAGER);
componentBinder.forField(widthComponent)
.withValidator(new RegexpValidator("Not a valid css length", CssRegex.getLengthRegex()))
Expand All @@ -67,8 +65,4 @@ public Stream<String> rendersCssStyle() {
return Stream.of("height", "width");
}

@Override
public void applyValue(HasSize propertyParent) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.github.appreciated.designer.application.view.file.designer.sidebar.renderer.AbstractPropertyRenderer;
import com.github.appreciated.designer.application.view.file.designer.sidebar.renderer.RenderPair;
import com.github.appreciated.designer.component.designer.StyleEditorDetails;
import com.github.appreciated.designer.component.designer.StyleEditor;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasStyle;

Expand All @@ -18,12 +18,8 @@ public boolean canRender(Component propertyParent) {
@Override
public Stream<RenderPair> render(HasStyle component) {
return Stream.of(
new RenderPair("styles", new StyleEditorDetails(component.getStyle()))
new RenderPair("styles", new StyleEditor(component.getStyle()))
);
}

@Override
public void applyValue(HasStyle propertyParent) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ public Stream<RenderPair> render(HasText component) {
buttons.setSpacing(false);
textField.setSuffixComponent(buttons);
textField.setValueChangeMode(ValueChangeMode.EAGER);
if (getProjectFileModel().getInformation().hasComponentMetainfo((Component) component) &&
getProjectFileModel().getInformation().getComponentMetainfo((Component) component).hasPropertyReplacement("text")) {
textField.setValue((String) getProjectFileModel().getInformation().getComponentMetainfo((Component) component).getPropertyReplacement("text"));
if (getProjectFileModel().getInformation().hasCompilationMetaInformation((Component) component) &&
getProjectFileModel().getInformation().getCompilationMetaInformation((Component) component).hasPropertyReplacement("text")) {
textField.setValue((String) getProjectFileModel().getInformation().getCompilationMetaInformation((Component) component).getPropertyReplacement("text"));
textField.setReadOnly(true);
} else {
textField.setValue(component.getText());
}
textField.addValueChangeListener(event -> {
if (getProjectFileModel().getInformation().hasComponentMetainfo((Component) component)) {
String key = (String) getProjectFileModel().getInformation().getComponentMetainfo((Component) component).getPropertyReplacement("text");
if (getProjectFileModel().getInformation().hasCompilationMetaInformation((Component) component) &&
getProjectFileModel().getInformation().getCompilationMetaInformation((Component) component).hasPropertyReplacement("text")) {
String key = (String) getProjectFileModel().getInformation().getCompilationMetaInformation((Component) component).getPropertyReplacement("text");
component.setText(getProjectFileModel().getInformation().getProject().getTranslationForKey(key));
} else {
component.setText(event.getValue());
Expand All @@ -61,8 +62,4 @@ public Stream<RenderPair> render(HasText component) {
return Stream.of(new RenderPair("text", textField));
}

@Override
public void applyValue(HasText propertyParent) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,4 @@ public Stream<RenderPair> render(HasTheme component) {
});
return Stream.of(new RenderPair("themes", combobox));
}

@Override
public void applyValue(HasTheme propertyParent) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,4 @@ public Stream<String> rendersCssStyle() {
return super.rendersCssStyle();
}

@Override
public void applyValue(ThemableLayout propertyParent) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.vaadin.flow.data.value.ValueChangeMode;

import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;

public class DoublePropertyRenderer extends AbstractPropertyRenderer<Double> {
@Override
Expand All @@ -17,6 +18,14 @@ public Component render(String propertyName, PropertyDescriptor propertyDescript
numberField.setValueChangeMode(ValueChangeMode.EAGER);
numberField.setHasControls(true);
numberField.setStep(0.01);
try {
Double value = (Double) propertyDescriptor.getReadMethod().invoke(propertyParent);
if (value != null) {
numberField.setValue(value);
}
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
numberField.addValueChangeListener(checkboxBooleanComponentValueChangeEvent -> applyValue(propertyParent, propertyDescriptor, numberField.getValue()));
return numberField;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.vaadin.flow.data.value.ValueChangeMode;

import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;

public class StringPropertyRenderer extends AbstractPropertyRenderer<String> {
@Override
Expand All @@ -15,6 +16,14 @@ public boolean canRender(Component propertyParent, String propertyName, Property
public Component render(String propertyName, PropertyDescriptor propertyDescriptor, Component propertyParent) {
TextField textField = new TextField();
textField.setValueChangeMode(ValueChangeMode.EAGER);
try {
String value = (String) propertyDescriptor.getReadMethod().invoke(propertyParent);
if (value != null) {
textField.setValue(value);
}
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
textField.addValueChangeListener(checkboxBooleanComponentValueChangeEvent -> applyValue(propertyParent, propertyDescriptor, textField.getValue()));
return textField;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.appreciated.designer.component;

import com.github.appreciated.designer.application.model.file.ProjectFileModel;
import com.github.appreciated.designer.model.CompilationMetainformation;
import com.github.appreciated.designer.model.CompilationMetaInformation;
import com.github.appreciated.designer.model.project.Project;
import com.github.appreciated.designer.template.java.parser.ComponentTreeParser;
import com.github.javaparser.ParseException;
Expand Down Expand Up @@ -54,7 +54,7 @@ public DesignerComponentWrapper generateComponent(ProjectFileModel projectModel)
Project project = projectModel.getInformation().getProject();
CompilationUnit compilationUnit = getCompilationUnitFromDesignerFile(projectModel, file);
Component generatedComponent = new ComponentTreeParser(compilationUnit, project).getComponent();
CompilationMetainformation info = projectModel.getInformation().getOrCreateCompilationMetainformation(generatedComponent);
CompilationMetaInformation info = projectModel.getInformation().getOrCreateCompilationMetaInformation(generatedComponent);
info.setProjectComponent(true);
info.setPackage(compilationUnit.getPackageDeclaration().get().getName().asString());
info.setClassName(compilationUnit.getPrimaryTypeName().get());
Expand Down
Loading

0 comments on commit cd188da

Please sign in to comment.