BrightSide Workbench Full Report + Source Code
CloneDocumentAction.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.financials.document.action;
19 
20 import java.util.Date;
21 import org.turro.action.AbstractAction;
22 import org.turro.command.Command;
23 import org.turro.command.Context;
24 import org.turro.financials.contract.ContractCombobox;
25 import org.turro.financials.entity.Contract;
26 import org.turro.financials.entity.Document;
27 import org.turro.financials.menu.FinancialsMenu;
28 import org.turro.i18n.I_;
29 import org.turro.zkoss.dialog.InputDialog;
30 import org.turro.zkoss.dialog.InputField;
31 import org.turro.zkoss.input.DateboxShort;
32 import org.turro.zul.frame.Framework;
33 import org.zkoss.zk.ui.HtmlBasedComponent;
34 
39 public class CloneDocumentAction extends AbstractAction {
40 
41  @Override
42  public Object execute(Context context) {
43  final Document nd = new Document(),
44  doc = (Document) context.get("entity");
46  Framework.getCurrent().getPage(),
47  I_.get("Change"),
48  new InputField[]{
49  new InputField("Contract", null, null, 0) {
50  @Override
51  protected HtmlBasedComponent createEditor() {
53  ccb.setOnlyActive(true);
54  ccb.setDocumentDefinition(doc.getDocumentDefinition());
55  ccb.setObjectValue(doc.getContract());
56  return ccb;
57  }
58  },
59  new InputField("Date", null, null, 0) {
60  @Override
61  protected HtmlBasedComponent createEditor() {
62  return new DateboxShort((Date) Framework.getAttribute(this, "date"));
63  }
64  },
65  new InputField("Draft", (Boolean) Framework.getAttribute(this, "draft", false), null, 0)
66  }, new Command() {
67  @Override
68  public Object execute(Context context) {
69  InputField[] fields = (InputField[]) context.get("fields");
70  Contract contract = null;
71  Date date = null;
72  Boolean draft = false;
73  if (fields.length > 0) {
74  for (InputField f : fields) {
75  if ("Contract".equals(f.getLabel())) {
76  contract = (Contract) f.getValue();
77  } else if ("Date".equals(f.getLabel())) {
78  date = (Date) f.getValue();
79  Framework.setAttribute(this, "date", date);
80  } else if ("Draft".equals(f.getLabel())) {
81  draft = (Boolean) f.getValue();
82  Framework.setAttribute(this, "draft", draft);
83  }
84  }
85  if (contract != null) {
86  nd.setContract(contract);
87  nd.copyFrom(doc, nd.getContract().getId() != doc.getContract().getId());
88  if (date != null) {
89  nd.setDocumentDate(date);
90  nd.setReceiptDate(date);
91  }
92  if (draft != null) {
93  nd.setDraft(draft);
94  }
96  nd.setDocumentNumber("");
97  }
99  }
100  }
101  return null;
102  }
103  });
104  return null;
105  }
106 
107  @Override
108  public String getLabel() {
109  return I_.get("Clone document");
110  }
111 
112  @Override
113  public String getImage() {
114  return "/_zul/images/document_clone.png";
115  }
116 
117 }
void setDocumentDefinition(DocumentDefinition documentDefinition)
void setDocumentNumber(String documentNumber)
Definition: Document.java:192
void setDocumentDate(Date documentDate)
Definition: Document.java:163
void copyFrom(Document doc, boolean shallowCopy)
Definition: Document.java:581
void setContract(Contract contract)
Definition: Document.java:123
void setReceiptDate(Date receiptDate)
Definition: Document.java:256
DocumentDefinition getDocumentDefinition()
Definition: Document.java:167
static String get(String msg)
Definition: I_.java:41
static void getInput(Page page, String title, String label, Object value, String format, int scale, final Command onOk)
static Object getAttribute(Object object, String key)
Definition: Framework.java:207
static Framework getCurrent()
Definition: Framework.java:203
static void setAttribute(Object object, String key, Object value)
Definition: Framework.java:216