io.pelle.mango.demo.client.DemoClient Maven / Gradle / Ivy
The newest version!
package io.pelle.mango.demo.client;
import io.pelle.mango.client.base.modules.dictionary.editor.IDictionaryEditor;
import io.pelle.mango.client.base.modules.dictionary.hooks.BaseEditorHook;
import io.pelle.mango.client.base.modules.dictionary.hooks.BaseTableHook;
import io.pelle.mango.client.base.property.IProperty;
import io.pelle.mango.client.base.property.IPropertyCategory;
import io.pelle.mango.client.core.property.PropertyBuilder;
import io.pelle.mango.client.core.property.PropertyProvider;
import io.pelle.mango.client.gwt.MangoBootstrapLayoutFactory;
import io.pelle.mango.client.web.MangoClientWeb;
import io.pelle.mango.client.web.module.ModuleHandler;
import io.pelle.mango.client.web.modules.dictionary.search.DictionarySearchModule;
import io.pelle.mango.client.web.modules.hierarchical.HierarchicalTreeModule;
import io.pelle.mango.client.web.modules.navigation.ModuleNavigationModule;
import io.pelle.mango.demo.client.showcase.CountryVO;
import io.pelle.mango.demo.client.test.Entity1VO;
import java.math.BigDecimal;
import java.util.Date;
import org.gwtbootstrap3.client.ui.Button;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Style.Overflow;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.regexp.shared.RegExp;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DockLayoutPanel.Direction;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
public class DemoClient implements EntryPoint {
private static final IProperty STRING_PROPERTY1 = PropertyBuilder.getInstance().createStringProperty("stringProperty1").database().name("A string property");
public static final IProperty ENTITY1_CREATE_FEATURE_WAIT_TIME = PropertyBuilder.getInstance().createIntegerProperty("entity1CreateWaitTime").database().name("entity1 create wait time").defaultValue(250);
public static final IProperty ACTIVATE_ENTITY1_CREATE_FEATURE = PropertyBuilder.getInstance().createBooleanProperty("activateEntity1CreateWaitTime").database().name("activate entity1 create wait").defaultValue(false);
private static final IProperty STRING_PROPERTY4 = PropertyBuilder.getInstance().createStringProperty("stringProperty4").database().name("An example string property");
private static final IProperty STRING_PROPERTY5 = PropertyBuilder.getInstance().createStringProperty("stringProperty5").database().name("An example string property");
private static final IProperty STRING_PROPERTY6 = PropertyBuilder.getInstance().createStringProperty("stringProperty6").database().name("An example string property");
/** {@inheritDoc} */
@Override
public void onModuleLoad() {
MangoClientWeb.getInstance().setLayoutFactory(new MangoBootstrapLayoutFactory());
init();
ModuleHandler.getInstance().startUIModule(DictionarySearchModule.SEARCH_QUERY_UI_MODULE_LOCATOR, Direction.WEST.toString());
ModuleHandler.getInstance().startUIModule(ModuleNavigationModule.NAVIGATION_UI_MODULE_LOCATOR, Direction.WEST.toString());
ModuleHandler.getInstance().startUIModule(HierarchicalTreeModule.getUIModuleLocator(TestClientHierarchicalConfiguration.ID), Direction.WEST.toString());
String greetingText = "";
greetingText += "Mango Showcase
";
greetingText += "This example Mango application showcases some key features that make up the generic CRUD UI part of Mango.
";
greetingText += "Click on question marks after the country search/editor title to see how the model corresponds to the UI.";
greetingText += "Country Search
";
greetingText += "";
greetingText += "Country Editor
";
greetingText += "To open an empty editor click on the create button (+) in the Country Search toolbar";
greetingText += "";
final PopupPanel greeting = new PopupPanel();
VerticalPanel vPanel = new VerticalPanel();
vPanel.setSpacing(25);
HTML content = new HTML(SafeHtmlUtils.fromTrustedString(greetingText));
content.getElement().getStyle().setOverflowY(Overflow.SCROLL);
content.setWidth("600px");
content.setHeight("500px");
vPanel.add(content);
Button closeButton = new Button("Got it!");
closeButton.getElement().getStyle().setBackgroundColor("#FF6666");
closeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
greeting.hide();
}
});
vPanel.add(closeButton);
greeting.setWidget(vPanel);
greeting.setGlassEnabled(true);
greeting.center();
greeting.setAutoHideEnabled(true);
greeting.show();
}
private void initProperties() {
IPropertyCategory category1 = PropertyProvider.getInstance().createCategory("category1");
category1.addProperty(STRING_PROPERTY1);
category1.addProperty(ACTIVATE_ENTITY1_CREATE_FEATURE);
category1.addProperty(ENTITY1_CREATE_FEATURE_WAIT_TIME);
IPropertyCategory category2 = PropertyProvider.getInstance().createCategory("category2");
category2.addProperty(STRING_PROPERTY4);
category2.addProperty(STRING_PROPERTY5);
category2.addProperty(STRING_PROPERTY6);
// PropertyProvider.getInstance().getRootCategory().addProperty(STRING_PROPERTY1);
}
public void init() {
MangoDemoClientConfiguration.registerAll();
initProperties();
String string1 = "";
string1 += "Model defining this control
";
string1 += "";
string1 += "stringdatatype StringDatatype1 {\n";
string1 += " maxLength 42\n";
string1 += "}\n\n";
string1 += "entity Entity1 {\n";
string1 += " string StringDatatype1 stringDatatype1\n";
string1 += "}\n\n";
string1 += "dictionary DemoDictionary1 {\n";
string1 += " [...]\n";
string1 += " textcontrol TextControl1 {\n";
string1 += " entityattribute Entity1.stringDatatype1\n";
string1 += " }\n";
string1 += " [...]\n";
string1 += "}";
string1 += "
";
MangoDemoDictionaryModel.DEMO_DICTIONARY1.DEMO_EDITOR1.TEXT_CONTROL1.setHelpText(replaceKeywords(string1));
String string2 = "";
string2 += "Model defining this control
";
string2 += "";
string2 += "entitydatatype Entity2Datatype { entity Entity2 }\n\n";
string2 += "entity Entity1 { entity Entity2Datatype entity2Datatype }\n\n";
string2 += "stringdatatype StringDatatype2 { }\n\n";
string2 += "entity Entity2 {\n";
string2 += " string StringDatatype2 stringDatatype2\n";
string2 += "}\n\n";
string2 += "dictionary DemoDictionary1 {\n";
string2 += " [...]\n";
string2 += " referencecontrol ReferenceControl1 {\n";
string2 += " entityattribute Entity1.entity2Datatype\n";
string2 += " dictionary DemoDictionary2\n";
string2 += " }\n";
string2 += " [...]\n";
string2 += "}\n\n";
string2 += "dictionary DemoDictionary2 {\n";
string2 += " [...]\n";
string2 += " labelcontrols {\n";
string2 += " referencecontrol ReferenceControl1 {\n";
string2 += " entityattribute Entity1.entity2Datatype\n";
string2 += " dictionary DemoDictionary2\n";
string2 += " }\n";
string2 += " }\n";
string2 += " [...]\n";
string2 += "}";
string2 += "
";
MangoDemoDictionaryModel.DEMO_DICTIONARY1.DEMO_EDITOR1.REFERENCE_CONTROL1.setHelpText(replaceKeywords(string2));
MangoDemoDictionaryModel.DEMO_DICTIONARY1.DEMO_EDITOR1.addEditorHook(new BaseEditorHook() {
@Override
public void onSave(AsyncCallback asyncCallback, IDictionaryEditor dictionaryEditor) {
dictionaryEditor.getVO().setDateDatype1(new Date());
asyncCallback.onSuccess(true);
}
});
createNavigationHelpText();
createCountrySearchHelpText();
createCountryEditorHelpText();
MangoDemoDictionaryModel.COUNTRY.COUNTRY_EDITOR.enableLogDisplay();
MangoDemoDictionaryModel.COUNTRY.COUNTRY_EDITOR.addEditorHook(new BaseEditorHook() {
@Override
public void onSave(AsyncCallback asyncCallback, IDictionaryEditor dictionaryEditor) {
dictionaryEditor.getVO().setCountryExchangeRate(new BigDecimal(1.56));
asyncCallback.onSuccess(true);
}
});
MangoDemoDictionaryModel.COUNTRY.COUNTRY_SEARCH.COUNTRY_RESULT.setTableHook(new BaseTableHook() {
@Override
public String getStyleName(CountryVO tableRow) {
if (tableRow.getCountryIsoCode2() != null && tableRow.getCountryIsoCode2().toLowerCase().equals("de")) {
return "countryResultRow";
} else {
return super.getStyleName(tableRow);
}
}
});
}
private void createNavigationHelpText() {
String helpText = "";
helpText += "Model defining navigation tree for the showcase
";
helpText += "The title text is taken from the navigation nodes name. Each navigation node can link to a dictionarySearch to open the corresponding search or an dictionaryEditor for the same functionality on an editor.
";
helpText += "";
helpText += "navigationnode Showcase {\n";
helpText += " navigationnode Country {\n";
helpText += " dictionarySearch Country.CountrySearch\n";
helpText += " }\n";
helpText += " navigationnode Currency {\n";
helpText += " dictionarySearch Currency.CurrencySearch\n";
helpText += " }\n";
helpText += " navigationnode Customer {\n";
helpText += " dictionarySearch Customer.CustomerSearch\n";
helpText += " }\n";
helpText += "}\n";
helpText += "
";
MangoDemoNavigationModel.ROOT.setHelpText(replaceKeywords(helpText));
}
private void createCountryEditorHelpText() {
String helpText = "";
helpText += "Model defining the country editor
";
helpText += "Again all controls are reused from the central defintion in dictionarycontrols. Note the label for the IsoCode3 control model which is overriden in the editor model.
";
helpText += "";
helpText += "stringdatatype CountryName {\n label \"Name\"\n maxLength 64\n}\n";
helpText += "stringdatatype IsoCode2 {\n label \"ISO-Code (2)\"\n maxLength 2\n minLength 2\n}\n";
helpText += "stringdatatype IsoCode3 {\n label \"ISO-Code (3)\"\n maxLength 3\n minLength 3\n}\n";
helpText += "entitydatatype CountryCurrency {\n label \"Currency\"\n entity Currency }\n";
helpText += "\n";
helpText += "entity Country {\n";
helpText += " naturalkey { countryIsoCode2 }\n";
helpText += " string IsoCode2 countryIsoCode2\n";
helpText += " string IsoCode3 countryIsoCode3\n";
helpText += " string CountryName countryName\n";
helpText += " entity CountryCurrency countryCurrency\n";
helpText += "}";
helpText += "\n";
helpText += "dictionary Country {\n";
helpText += " entity Country\n";
helpText += " dictionarycontrols {\n";
helpText += " textcontrol CountryIsoCode2 {\n";
helpText += " entityattribute countryIsoCode2\n";
helpText += " }\n";
helpText += " textcontrol CountryIsoCode3 {\n";
helpText += " entityattribute countryIsoCode3\n";
helpText += " }\n";
helpText += " textcontrol CountryName {\n";
helpText += " entityattribute countryName\n";
helpText += " width 32\n";
helpText += " }\n";
helpText += " referencecontrol CountryCurrency {\n";
helpText += " entityattribute countryCurrency\n";
helpText += " dictionary Currency\n";
helpText += " }\n";
helpText += " bigdecimalcontrol CountryExchangeRate {\n";
helpText += " entityattribute countryExchangeRate\n";
helpText += " readonly true\n";
helpText += " }\n";
helpText += " }\n";
helpText += " }\n";
helpText += " [...]\n";
helpText += " dictionaryeditor CountryEditor {\n";
helpText += " layout { columns 2 }\n";
helpText += " textcontrol ref CountryIsoCode2\n";
helpText += " textcontrol ref CountryIsoCode3 {\n label \"Alpha 3\"\n }\n";
helpText += " textcontrol ref CountryName\n";
helpText += " referencecontrol ref CountryCurrency\n";
helpText += " bigdecimalcontrol ref CountryExchangeRate\n";
helpText += " }\n";
helpText += "}\n";
helpText += "
";
MangoDemoDictionaryModel.COUNTRY.COUNTRY_EDITOR.setHelpText(replaceKeywords(helpText));
}
private void createCountrySearchHelpText() {
String helpText = "";
helpText += "Model defining the country search
";
helpText += "All controls used in the model are defined once in the dictionarycontrols section of the dictionary and then referenced from the filter/result model. "
+ "Each control referes to an entityAttribute from the entity that is set in the root dictionary model. The control labels are inherited from the datatypes "
+ "that are used for each entityAttribute. All model attributes like label/maxlength/... can be overridden at any point in the inheritance hierarchy (see "
+ "the label for the IsoCode3 control model for example.
";
helpText += "";
helpText += "stringdatatype CountryName {\n label \"Name\"\n}\n";
helpText += "stringdatatype IsoCode2 {\n label \"ISO-Code (2)\"\n maxLength 2\n minLength 2\n}\n";
helpText += "stringdatatype IsoCode3 {\n label \"ISO-Code (3)\"\n maxLength 3\n minLength 3\n}\n";
helpText += "entitydatatype CountryCurrency {\n label \"Currency\"\n entity Currency }\n";
helpText += "\n";
helpText += "entity Country {\n";
helpText += " naturalkey { countryIsoCode2 }\n";
helpText += " string IsoCode2 countryIsoCode2\n";
helpText += " string IsoCode3 countryIsoCode3\n";
helpText += " string CountryName countryName\n";
helpText += " entity CountryCurrency countryCurrency\n";
helpText += "}";
helpText += "\n";
helpText += "dictionary Country {\n";
helpText += " entity Country\n";
helpText += " dictionarycontrols {\n";
helpText += " textcontrol CountryIsoCode2 {\n";
helpText += " entityattribute countryIsoCode2\n";
helpText += " }\n";
helpText += " textcontrol CountryIsoCode3 {\n";
helpText += " entityattribute countryIsoCode3\n";
helpText += " }\n";
helpText += " textcontrol CountryName {\n";
helpText += " entityattribute countryName\n";
helpText += " }\n";
helpText += " referencecontrol CountryCurrency {\n";
helpText += " entityattribute countryCurrency\n";
helpText += " dictionary Currency\n";
helpText += " }\n";
helpText += " }\n";
helpText += " dictionarysearch CountrySearch {\n";
helpText += " label \"Countries\"\n";
helpText += " dictionaryfilter CountryFilter {\n";
helpText += " layout { columns 2 }\n";
helpText += " textcontrol ref CountryIsoCode2\n";
helpText += " textcontrol ref CountryIsoCode3 {\n label \"ISO-3166 (Alpha 3)\"\n }\n";
helpText += " textcontrol ref CountryName\n";
helpText += " referencecontrol ref CountryCurrency\n";
helpText += " }\n";
helpText += " dictionaryresult CountryResult {\n";
helpText += " textcontrol ref CountryIsoCode2\n";
helpText += " textcontrol ref CountryIsoCode3\n";
helpText += " textcontrol ref CountryName\n";
helpText += " referencecontrol ref CountryCurrency\n";
helpText += " }\n";
helpText += " }\n";
helpText += " [...]\n";
helpText += "}\n";
helpText += "
";
MangoDemoDictionaryModel.COUNTRY.COUNTRY_SEARCH.setHelpText(replaceKeywords(helpText));
}
private String replaceKeywords(String string) {
String result = string;
result = keyword(result, "textcontrol");
result = keyword(result, "maxLength");
result = keyword(result, "entityattribute");
result = keyword(result, "navigationnode");
result = keyword(result, "dictionarySearch");
result = keyword(result, "dictionaryEditor");
result = keyword(result, "entity");
result = keyword(result, "stringdatatype");
result = keyword(result, "string");
result = keyword(result, "entity");
result = keyword(result, "referencecontrol");
result = keyword(result, "dictionary");
result = keyword(result, "entitydatatype");
result = keyword(result, "labelcontrols");
result = keyword(result, "layout");
result = keyword(result, "minLength");
result = keyword(result, "dictionarycontrols");
result = keyword(result, "dictionarysearch");
result = keyword(result, "label");
result = keyword(result, "dictionaryfilter");
result = keyword(result, "dictionaryresult");
result = keyword(result, "ref");
result = coloredItalicString(result, "\\[\\.\\.\\.\\]", "#999");
return result.toString();
}
private String coloredStrongString(String text, String colorString, String color) {
return replace(text, colorString, "", "");
}
private String coloredItalicString(String text, String colorString, String color) {
return replace(text, colorString, "", "");
}
public String keyword(String text, String keyword) {
return coloredStrongString(text, keyword, "#950055");
}
public String replace(String text, String strongText, String before, String after) {
RegExp pattern = RegExp.compile("(" + strongText + ")(\\s+)", "g");
return pattern.replace(text, before + "$1" + after + "$2");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy