Skip to content

Commit

Permalink
Using model.Folder
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed May 1, 2024
1 parent e06189c commit 32e0b64
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 85 deletions.
15 changes: 13 additions & 2 deletions src/main/java/org/luwrain/app/mail/App.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2023 Michael Pozhidaev <[email protected]>
Copyright 2012-2024 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand Down Expand Up @@ -29,6 +29,7 @@ public final class App extends AppBase<Strings> implements MonoApp

private Hooks hooks = null;
private MailStoring storing = null;
private Data data = null;
private Conv conv = null;
private MainLayout mainLayout = null;
private StartingLayout startingLayout = null;
Expand All @@ -41,15 +42,24 @@ public App()
@Override protected AreaLayout onAppInit()
{
this.hooks = new Hooks(getLuwrain());
Log.debug(LOG_COMPONENT, "before data");
this.data = new Data();
Log.debug(LOG_COMPONENT, "after data");
this.storing = org.luwrain.pim.Connections.getMailStoring(getLuwrain(), true);
/*
if (storing == null)
return null;
*/
this.conv = new Conv(this);
this.mainLayout = new MainLayout(this);
Log.debug("proba", "before main layout ");
this.mainLayout = new MainLayout(this, data);
Log.debug("proba", "after main layout");
this.startingLayout = new StartingLayout(this);
setAppName(getStrings().appName());
/*
if (storing.getAccounts().load().length == 0)
return startingLayout.getAreaLayout();
*/
return mainLayout.getAreaLayout();
}

Expand Down Expand Up @@ -82,6 +92,7 @@ Layouts layouts()
MailStoring getStoring() { return this.storing; }
Hooks getHooks() { return this.hooks; }
Conv getConv() { return conv; }
public Data getData() { return data; }

interface Layouts
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/luwrain/app/mail/Conv.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
Copyright 2012-2024 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand Down
72 changes: 72 additions & 0 deletions src/main/java/org/luwrain/app/mail/Data.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright 2012-2024 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
LUWRAIN is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
LUWRAIN is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
*/

package org.luwrain.app.mail;

import java.util.*;

import org.luwrain.core.*;
import org.luwrain.pim.mail2.persistence.dao.*;
import org.luwrain.pim.mail2.persistence.model.*;
import org.luwrain.pim.mail2.persistence.*;

import static org.luwrain.pim.mail2.FolderProperties.*;

public final class Data
{
public final FolderDAO folderDAO = MailPersistence.getFolderDAO();
public final MessageDAO messageDAO = MailPersistence.getMessageDAO();
public final AccountDAO accountDAO = MailPersistence.getAccountDAO();

Data()
{
if (folderDAO.getRoot() == null)
createInitialFolders();
}

private void createInitialFolders()
{
final var t = "true";
final var root = new Folder();
root.setName("Почтовые группы");
folderDAO.add(root);
folderDAO.setRoot(root);
var f = new Folder();
f.setName("Входящие");
f.getProperties().setProperty(DEFAULT_INCOMING, t);
f.setParentFolderId(root.getId());
folderDAO.add(f);
f = new Folder();
f.setName("Рассылки");
f.getProperties().setProperty(DEFAULT_MAILING_LISTS, t);
f.setParentFolderId(root.getId());
folderDAO.add(f);
f = new Folder();
f.setName("Исходящие");
f.getProperties().setProperty(DEFAULT_OUTGOING, t);
f.setParentFolderId(root.getId());
folderDAO.add(f);
f = new Folder();
f.setName("Отправленные");
f.getProperties().setProperty(DEFAULT_SENT, t);
f.setParentFolderId(root.getId());
folderDAO.add(f);
f = new Folder();
f.setName("Черновики");
f.setParentFolderId(root.getId());
folderDAO.add(f);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/luwrain/app/mail/Extension.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2023 Michael Pozhidaev <[email protected]>
Copyright 2012-2024 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand Down
48 changes: 0 additions & 48 deletions src/main/java/org/luwrain/app/mail/FoldersModel.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/org/luwrain/app/mail/Hooks.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
Copyright 2012-2024 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand Down
39 changes: 30 additions & 9 deletions src/main/java/org/luwrain/app/mail/MainLayout.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2023 Michael Pozhidaev <[email protected]>
Copyright 2012-2024 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand Down Expand Up @@ -30,39 +30,45 @@
import org.luwrain.pim.mail.script.*;
import org.luwrain.app.base.*;

import org.luwrain.pim.mail2.persistence.model.*;
import org.luwrain.app.mail.layouts.*;


import static org.luwrain.script.ScriptUtils.*;
import static org.luwrain.core.DefaultEventResponse.*;

import static org.luwrain.app.mail.App.*;
import static org.luwrain.app.mail.Utils.*;
import static org.luwrain.core.DefaultEventResponse.*;

final class MainLayout extends LayoutBase implements TreeListArea.LeafClickHandler<MailFolder>, ClickHandler<SummaryItem>
final class MainLayout extends LayoutBase implements TreeListArea.LeafClickHandler<Folder>, ClickHandler<SummaryItem>
{
static private final InputEvent
HOT_KEY_REPLY = new InputEvent('r', EnumSet.of(InputEvent.Modifiers.ALT));

final App app;
final TreeListArea<MailFolder> foldersArea;
final TreeListArea<Folder> foldersArea;
final ListArea<SummaryItem> summaryArea;
final ReaderArea messageArea;

private final Data data;
private final List<SummaryItem> summaryItems = new ArrayList<>();
private boolean showDeleted = false;
private MailFolder folder = null;
private Folder folder = null;
private MailMessage message = null;

MainLayout(App app)
MainLayout(App app, Data data)
{
super(app);
this.app = app;
this.data = data;

final TreeListArea.Params<MailFolder> treeParams = new TreeListArea.Params<>();
final TreeListArea.Params<Folder> treeParams = new TreeListArea.Params<>();
treeParams.context = getControlContext();
treeParams.name = app.getStrings().foldersAreaName();
treeParams.model = new FoldersModel(app);
treeParams.model = new FoldersModel();
treeParams.leafClickHandler = this;
this.foldersArea = new TreeListArea<MailFolder>(treeParams) {
this.foldersArea = new TreeListArea<>(treeParams) {
@Override public boolean onSystemEvent(SystemEvent event)
{
if (event.getType() == SystemEvent.Type.REGULAR)
Expand Down Expand Up @@ -167,7 +173,7 @@ void updateSummary()
summaryArea.refresh();
}

@Override public boolean onLeafClick(TreeListArea<MailFolder> area, MailFolder folder)
@Override public boolean onLeafClick(TreeListArea<Folder> area, Folder folder)
{
this.folder = folder;
updateSummary();
Expand All @@ -178,6 +184,7 @@ void updateSummary()

private boolean actNewFolder()
{
/*
final MailFolder opened = foldersArea.opened();
if (opened == null)
return false;
Expand All @@ -190,11 +197,13 @@ private boolean actNewFolder()
app.getStoring().getFolders().save(opened, newFolder, Math.max(selectedIndex, 0));
foldersArea.requery();
foldersArea.refresh();
*/
return true;
}

private boolean actRemoveFolder()
{
/*
final MailFolder opened = foldersArea.opened();
if (opened == null)
return false;
Expand All @@ -206,6 +215,7 @@ private boolean actRemoveFolder()
app.getStoring().getFolders().remove(opened, selectedIndex);
foldersArea.requery();
foldersArea.refresh();
*/
return true;
}

Expand Down Expand Up @@ -359,4 +369,15 @@ boolean saveAttachment(String fileName)
*/
return true;
}

final class FoldersModel implements TreeListArea.Model<Folder>
{
@Override public boolean getItems(Folder folder, TreeListArea.Collector<Folder> collector)
{
collector.collect(data.folderDAO.getChildFolders(folder));
return true;
}
@Override public Folder getRoot() { return data.folderDAO.getRoot(); }
@Override public boolean isLeaf(Folder folder) { return data.folderDAO.getChildFolders(folder).size() != 0; }
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/luwrain/app/mail/StartingLayout.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
Copyright 2012-2024 Michael Pozhidaev <[email protected]>
Copyright 2015-2016 Roman Volovodov <[email protected]>
This file is part of LUWRAIN.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/luwrain/app/mail/Strings.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2023 Michael Pozhidaev <[email protected]>
Copyright 2012-2024 Michael Pozhidaev <[email protected]>
i This file is part of LUWRAIN.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/luwrain/app/mail/SummaryItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
Copyright 2012-2024 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/luwrain/app/mail/Utils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
Copyright 2012-2024 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand Down
Loading

0 comments on commit 32e0b64

Please sign in to comment.