19 package org.turro.elephant.configuration;
22 import java.io.IOException;
23 import java.nio.charset.StandardCharsets;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import org.turro.command.Command;
27 import org.turro.command.Context;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.elephant.util.Messages;
30 import org.turro.file.Document;
31 import org.turro.file.Folder;
32 import org.turro.upload.Medias;
33 import org.turro.zip.Compress;
34 import org.turro.zkoss.text.CodemirrorEditor;
35 import org.zkoss.util.media.Media;
36 import org.zkoss.zk.ui.Component;
37 import org.zkoss.zk.ui.event.Event;
38 import org.zkoss.zk.ui.event.UploadEvent;
39 import org.zkoss.zk.ui.select.SelectorComposer;
40 import org.zkoss.zk.ui.select.annotation.Listen;
41 import org.zkoss.zk.ui.select.annotation.Wire;
42 import org.zkoss.zul.Label;
43 import org.zkoss.zul.Panel;
44 import org.zkoss.zul.Toolbarbutton;
53 private Label fileName;
56 private Toolbarbutton save;
59 private Toolbarbutton saveAs;
65 private Panel fileContent;
70 @Listen(
"onSelect = #filesTree")
72 save.setDisabled(
true);
73 saveAs.setDisabled(
true);
75 if(file !=
null && (file.isFile() || !file.exists())) {
76 fileName.setValue(file.getName());
82 fileName.setValue(
null);
86 filesTree.getSelectedItem().setOpen(
true);
90 @Listen(
"onClick = #save")
95 @Listen(
"onClick = #saveAs")
98 editor.
saveAs(
new Command() {
100 public Object execute(Context context) {
101 save.setDisabled(
false);
102 saveAs.setDisabled(
false);
105 filesTree.
selectFile((File) context.get(
"file"), selectedParent);
109 }
catch (IOException ex) {
114 @Listen(
"onClick = #newFile")
121 public Object execute(Context context) {
122 save.setDisabled(
false);
123 saveAs.setDisabled(
false);
125 filesTree.
selectFile((File) context.get(
"file"), folder);
130 }
catch (IOException ex) {
135 @Listen(
"onClick = #delFile")
142 filesTree.setSelectedItem(folder);
147 @Listen(
"onUpload = #fomantic")
151 for(Media media : event.getMedias()) {
153 Compress.unzip(fomantic.path().resolve(media.getName()), fomantic.path());
154 Document.from(fomantic.path().resolve(media.getName())).delete();
158 @Listen(
"onChange = *; onChanging = *")
160 save.setDisabled(
false);
163 saveAs.setDisabled(
false);
169 save.setDisabled(
true);
170 save.setAutodisable(
"+self,+saveAs");
171 saveAs.setDisabled(
true);
172 saveAs.setAutodisable(
"+self,+save");
175 private String guessEncoding(File file) {
176 if(file.getAbsolutePath().contains(
"/elephant/conf/mail/")) {
177 return StandardCharsets.UTF_8.name();
void onDelFile(Event event)
void onSaveAs(Event event)
void onFomantic(UploadEvent event)
void onSelectFile(Event event)
void onNewFile(Event event)
void onChange(Event event)
FilesItem getSelectedFolder()
void selectFile(File file, Treeitem parent)
FilesItem getSelectedFile()
FilesItem getSelectedFileParent()
static String getRealPath(String path)
static String logMsg(String msg)
static Messages confirmDeletion()
Messages add(String word)
void setDisabled(boolean value)
void saveAs(final Command command)
void newFile(final File folder, final Command command)
void setText(String value)
void setEncoding(String encoding)