Skip to content

Commit

Permalink
news2: Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed Oct 24, 2021
1 parent f7f78e1 commit eab7edf
Showing 1 changed file with 46 additions and 49 deletions.
95 changes: 46 additions & 49 deletions src/main/java/org/luwrain/app/news2/PropertiesLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,26 @@
import java.util.*;

import org.luwrain.core.*;
import org.luwrain.core.events.*;
import org.luwrain.controls.*;
import org.luwrain.controls.reader.*;
import org.luwrain.pim.news.*;
import org.luwrain.pim.*;
import org.luwrain.app.base.*;

final class PropertiesLayout extends LayoutBase
{
static private final String
ORDER_INDEX = "order-index";
static private final String
NAME = "name",
ORDER_INDEX = "order-index";

private final App app;
final FormArea formArea;
final FormArea formArea;

PropertiesLayout(App app, NewsGroup group)
{
super(app);
NullCheck.notNull(group, "group");
this.app = app;
this.formArea = new FormArea(getControlContext()) ;
final List<String> urls = group.getUrls();
PropertiesLayout(App app, NewsGroup group)
{
super(app);
NullCheck.notNull(group, "group");
this.app = app;
this.formArea = new FormArea(getControlContext()) ;
final List<String> urls = group.getUrls();
final String[] urlLines;
if (urls != null && !urls.isEmpty())
{
Expand All @@ -36,49 +34,48 @@ final class PropertiesLayout extends LayoutBase
urlLines = res.toArray(new String[res.size()]);
} else
urlLines = new String[0];
formArea.addEdit("name", app.getStrings().groupPropertiesName(), group.getName());
formArea.addEdit("order-index", app.getStrings().groupPropertiesOrderIndex(), "" + group.getOrderIndex());
formArea.addEdit(NAME, app.getStrings().groupPropertiesName(), group.getName());
formArea.addEdit(ORDER_INDEX, app.getStrings().groupPropertiesOrderIndex(), "" + group.getOrderIndex());
formArea.activateMultilineEdit(app.getStrings().groupPropertiesUrls(), urlLines, true);
setAreaLayout(formArea, actions());
}

private boolean save(NewsGroup group)
{
NullCheck.notNull(group, "group");

final String name = formArea.getEnteredText("name");
if (name.trim().isEmpty())
{
app.message(app.getStrings().groupPropertiesNameMayNotBeEmpty(), Luwrain.MessageType.ERROR);
return false;
}
group.setName(name);
if (formArea.getEnteredText("order-index").trim().isEmpty())
{
app.message(app.getStrings().groupPropertiesInvalidOrderIndex(), Luwrain.MessageType.ERROR);
return false;
}
final int orderIndex;
try {
orderIndex = Integer.parseInt(formArea.getEnteredText(ORDER_INDEX));
}
catch(NumberFormatException e)
{
app.message(app.getStrings().groupPropertiesInvalidOrderIndex(), Luwrain.MessageType.ERROR);
return false;
}
if (orderIndex < 0)
{
app.message(app.getStrings().groupPropertiesInvalidOrderIndex(), Luwrain.MessageType.ERROR);
return false;
}
group.setOrderIndex(orderIndex);
final List<String> urls = new ArrayList<>();
for(String s: formArea.getMultilineEditLines())
if (!s.trim().isEmpty())
urls.add(s.trim());
group.setUrls(urls);
group.save();
final String name = formArea.getEnteredText(NAME);
if (name.trim().isEmpty())
{
app.message(app.getStrings().groupPropertiesNameMayNotBeEmpty(), Luwrain.MessageType.ERROR);
return false;
}
group.setName(name);
if (formArea.getEnteredText("order-index").trim().isEmpty())
{
app.message(app.getStrings().groupPropertiesInvalidOrderIndex(), Luwrain.MessageType.ERROR);
return false;
}
final int orderIndex;
try {
orderIndex = Integer.parseInt(formArea.getEnteredText(ORDER_INDEX));
}
catch(NumberFormatException e)
{
app.message(app.getStrings().groupPropertiesInvalidOrderIndex(), Luwrain.MessageType.ERROR);
return false;
}
if (orderIndex < 0)
{
app.message(app.getStrings().groupPropertiesInvalidOrderIndex(), Luwrain.MessageType.ERROR);
return false;
}
group.setOrderIndex(orderIndex);
final List<String> urls = new ArrayList<>();
for(String s: formArea.getMultilineEditLines())
if (!s.trim().isEmpty())
urls.add(s.trim());
group.setUrls(urls);
group.save();
return true;
}
}

0 comments on commit eab7edf

Please sign in to comment.