Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
miche.atucha committed Apr 14, 2017
2 parents a8e64be + 6a5b8b6 commit ba4ca00
Show file tree
Hide file tree
Showing 25 changed files with 662 additions and 226 deletions.
51 changes: 51 additions & 0 deletions bridje-jfx/src/main/java/org/bridje/jfx/srcgen/model/IconDef.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2017 Bridje Framework.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.bridje.jfx.srcgen.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;

@XmlAccessorType(XmlAccessType.FIELD)
public class IconDef
{
@XmlAttribute
private String name;

@XmlAttribute
private String file;

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}

public String getFile()
{
return file;
}

public void setFile(String file)
{
this.file = file;
}
}
17 changes: 17 additions & 0 deletions bridje-jfx/src/main/java/org/bridje/jfx/srcgen/model/ModelInf.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public class ModelInf
})
private List<ObjectInf> objects;

@XmlElementWrapper(name = "icons")
@XmlElements(
{
@XmlElement(name = "icon", type = IconDef.class)
})
private List<IconDef> icons;

@XmlElementWrapper(name = "properties")
@XmlElements(
{
Expand Down Expand Up @@ -93,4 +100,14 @@ public void setProperties(List<PropertyInf> properties)
{
this.properties = properties;
}

public List<IconDef> getIcons()
{
return icons;
}

public void setIcons(List<IconDef> icons)
{
this.icons = icons;
}
}
23 changes: 11 additions & 12 deletions bridje-jfx/src/main/java/org/bridje/jfx/utils/JfxUtils.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@

package org.bridje.jfx.utils;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.MenuItem;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

/*
* Copyright 2017 Bridje Framework.
*
Expand All @@ -25,9 +14,19 @@
* limitations under the License.
*/

package org.bridje.jfx.utils;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.MenuItem;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

public class JfxUtils
{
public static Node loadImage(Class<?> cls, String resource, double height, double width)
public static ImageView loadImage(Class<?> cls, String resource, double height, double width)
{
Image img = new Image(cls.getResourceAsStream(resource));
ImageView iv = new ImageView(img);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@ import ${inc.fullName};
</#list>
import javafx.beans.property.*;
import javafx.collections.ObservableList;
import javafx.scene.image.ImageView;
import org.bridje.jfx.utils.JfxUtils;

public class ${model.name}
{
<#list model.icons as icon>
public static ImageView ${icon.name}(int size)
{
return JfxUtils.loadImage(${model.name}.class, "${icon.file}", size, size);
}

</#list>

<#list model.properties as property>
private final ${property.propertyDec} ${property.name}Property = new ${property.propertyDimDec}();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Menu;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
Expand Down Expand Up @@ -86,6 +87,7 @@ public ControlEditor()
getRowConstraints().add(rowConst);

nameListener = (observable, oldValue, newValue) -> updateName(oldValue, newValue);
fieldsEditor.setNameListener((observable, oldValue, newValue) -> taRender.searchAndReplace("control." + oldValue, "control." + newValue));

uiSuiteProperty.addListener((observable, oldValue, newValue) ->
{
Expand Down Expand Up @@ -131,7 +133,11 @@ public ControlEditor()
}
});

taRender.getContextMenu().getItems().add(0, JfxUtils.createMenuItem("Create Child", null, this::createChildFildFromCurrentSelection));
Menu createMenu = new Menu("Create");
taRender.getContextMenu().getItems().add(0, createMenu);
createMenu.getItems().add(JfxUtils.createMenuItem("Child Field", null, this::createChildFieldFromCurrentSelection));
createMenu.getItems().add(JfxUtils.createMenuItem("Expresion Field", null, this::createExprFieldFromCurrentSelection));
createMenu.getItems().add(JfxUtils.createMenuItem("Boolean Field", null, this::createBooleanFieldFromCurrentSelection));
}

public StringConverter<ControlDefModel> createStringConverter(Callback<String, ControlDefModel> callback)
Expand Down Expand Up @@ -217,7 +223,7 @@ public void addField(ActionEvent event)
getControl().getFields().add(field);
}

public void createChildFildFromCurrentSelection(ActionEvent event)
public void createChildFieldFromCurrentSelection(ActionEvent event)
{
String selection = taRender.findSelection();
if(selection != null && !selection.isEmpty())
Expand All @@ -231,9 +237,44 @@ public void createChildFildFromCurrentSelection(ActionEvent event)
field.setName("newChildField" + getControl().getFields().size());
field.setType(ctrl.getName());
field.setField("child");
field.nameProperty().addListener(fieldsEditor.getNameListener());
getControl().getFields().add(field);

taRender.replaceSelection("<#if control.newChild??>\n\t<@renderControl control." + field.getName() + " />\n</#if>");
taRender.replaceSelection("<#if control." + field.getName() + "??>\n\t<@renderControl control." + field.getName() + " />\n</#if>");
}
}

public void createExprFieldFromCurrentSelection(ActionEvent event)
{
String selection = taRender.findSelection();
if(selection != null && !selection.isEmpty())
{
FieldDefModel field = new FieldDefModel();
field.setName("newExprAttr" + getControl().getFields().size());
field.setType("String");
field.setField("outAttr");
field.setDefaultValue("\"" + selection + "\"");
field.nameProperty().addListener(fieldsEditor.getNameListener());
getControl().getFields().add(field);

taRender.replaceSelection("${control." + field.getName() + "}");
}
}

public void createBooleanFieldFromCurrentSelection(ActionEvent event)
{
String selection = taRender.findSelection();
if(selection != null && !selection.isEmpty())
{
FieldDefModel field = new FieldDefModel();
field.setName("newBoolAttr" + getControl().getFields().size());
field.setType("Boolean");
field.setField("outAttr");
field.setDefaultValue("false");
field.nameProperty().addListener(fieldsEditor.getNameListener());
getControl().getFields().add(field);

taRender.replaceSelection("<#if control." + field.getName() + "?? && control." + field.getName() + ">" + selection + "</#if>");
}
}

Expand All @@ -244,6 +285,7 @@ private void updateName(String oldValue, String newValue)

private void updateChildTypes(ControlDefModel control, String oldValue, String newValue)
{
if(control.getFields() == null) return;
control.getFields()
.stream()
.filter(f -> "child".equalsIgnoreCase(f.getField()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@
import org.bridje.srcgen.editor.EditorTreeItem;
import org.bridje.web.srcgen.models.ControlDefModel;
import org.bridje.web.srcgen.models.UISuiteModel;
import org.bridje.web.srcgen.models.UISuitesModel;

public final class ControlTreeItem extends EditorTreeItem
{
private final ControlDefModel control;

private final UISuiteModel suite;

private final static ControlEditor editor = new ControlEditor();

public ControlTreeItem(ControlDefModel control, UISuiteModel suite)
public ControlTreeItem(ControlDefModel control)
{
super(control, loadImage("control.png", 16));
super(control, UISuitesModel.control(16));
this.control = control;
this.suite = suite;
setContextMenu(createContextMenu());
setToolBar(createToolBar());
this.control.nameProperty().addListener((observable, oldValue, newValue) ->
Expand All @@ -50,26 +48,27 @@ public ControlTreeItem(ControlDefModel control, UISuiteModel suite)
private ContextMenu createContextMenu()
{
ContextMenu ctx = new ContextMenu();
ctx.getItems().add(JfxUtils.createMenuItem("Save", loadImage("save.png", 24), this::saveModel));
ctx.getItems().add(JfxUtils.createMenuItem("Delete", loadImage("delete.png", 24), this::deleteControl));
ctx.getItems().add(JfxUtils.createMenuItem("Save", UISuitesModel.save(24), this::saveModel));
ctx.getItems().add(JfxUtils.createMenuItem("Delete", UISuitesModel.delete(24), this::deleteControl));
return ctx;
}

private ToolBar createToolBar()
{
ToolBar tb = new ToolBar();
tb.getItems().add(JfxUtils.createToolButton(loadImage("save.png", 32), this::saveModel));
tb.getItems().add(JfxUtils.createToolButton(loadImage("delete.png", 32), this::deleteControl));
tb.getItems().add(JfxUtils.createToolButton(UISuitesModel.save(32), this::saveModel));
tb.getItems().add(JfxUtils.createToolButton(UISuitesModel.delete(32), this::deleteControl));
return tb;
}

public void saveModel(ActionEvent event)
{
ModelUtils.saveUISuite(suite);
ModelUtils.saveUISuite(control.getParent());
}

public void deleteControl(ActionEvent event)
{
UISuiteModel suite = control.getParent();
if(suite.getControls().contains(control))
{
suite.getControls().remove(control);
Expand All @@ -80,14 +79,10 @@ public void deleteControl(ActionEvent event)
}
}

private static Node loadImage(String image, int size)
{
return JfxUtils.loadImage(ControlTreeItem.class, image, size, size);
}

@Override
public Node edit()
{
UISuiteModel suite = control.getParent();
if(editor.getUISuite() == null || !editor.getUISuite().equals(suite)) editor.setUISuite(suite);
editor.setControl(control);
return editor;
Expand Down
Loading

0 comments on commit ba4ca00

Please sign in to comment.