XiaXiang
8 years ago
14 changed files with 589 additions and 207 deletions
@ -0,0 +1,42 @@
|
||||
package com.fr.design.mainframe.alphafine.cell; |
||||
|
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.design.mainframe.alphafine.cell.cellModel.*; |
||||
import com.fr.json.JSONObject; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/5/17. |
||||
*/ |
||||
public class CellModelHelper { |
||||
public static AlphaCellModel jsonToModel(JSONObject object) { |
||||
int cellType = object.optInt("cellType"); |
||||
switch (CellType.parse(cellType)) { |
||||
case ACTION: |
||||
return ActionModel.jsonToModel(object); |
||||
case DOCUMENT: |
||||
return DocumentModel.jsonToModel(object); |
||||
case FILE: |
||||
return FileModel.jsonToModel(object); |
||||
case PLUGIN: |
||||
case REUSE: |
||||
return PluginModel.jsonToModel(object); |
||||
|
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static String getResultValueFromModel(AlphaCellModel cellModel) { |
||||
switch (cellModel.getType()) { |
||||
case ACTION: |
||||
return cellModel.getName(); |
||||
case DOCUMENT: |
||||
return ((DocumentModel)cellModel).getDocumentUrl(); |
||||
case FILE: |
||||
return ((FileModel)cellModel).getFilePath(); |
||||
case REUSE: |
||||
case PLUGIN: |
||||
return ((PluginModel)cellModel).getPluginUrl(); |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.cellModel; |
||||
|
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/5/16. |
||||
*/ |
||||
public interface ModelHandel { |
||||
|
||||
JSONObject ModelToJson() throws JSONException; |
||||
|
||||
} |
@ -0,0 +1,294 @@
|
||||
package com.fr.design.mainframe.alphafine.recentSearch; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.base.Utils; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||
import com.fr.design.mainframe.alphafine.cell.CellModelHelper; |
||||
import com.fr.design.mainframe.alphafine.cell.cellModel.AlphaCellModel; |
||||
import com.fr.file.XMLFileManager; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.IOUtils; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.stable.ProductConstants; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.project.ProjectConstants; |
||||
import com.fr.stable.xml.XMLPrintWriter; |
||||
import com.fr.stable.xml.XMLReadable; |
||||
import com.fr.stable.xml.XMLTools; |
||||
import com.fr.stable.xml.XMLableReader; |
||||
|
||||
import java.io.*; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/5/15. |
||||
*/ |
||||
public class RecentSearchManager extends XMLFileManager { |
||||
|
||||
private static final String XML_TAG = "AlphafineRecent"; |
||||
private static RecentSearchManager recentSearchManager = null; |
||||
private static File recentFile = null; |
||||
private List<String> fileList; |
||||
private List<String> actionList; |
||||
private List<String> documentList; |
||||
|
||||
//private List<recentKVModel> recentKVModelList = new ArrayList<>();
|
||||
private List<String> pluginList; |
||||
private List<AlphaCellModel> recentModelList = new ArrayList<>(); |
||||
private Map<String, List<AlphaCellModel>> recentKVModelMap = new HashMap<>(); |
||||
|
||||
public synchronized static RecentSearchManager getInstance() { |
||||
if (recentSearchManager == null) { |
||||
recentSearchManager = new RecentSearchManager(); |
||||
try { |
||||
XMLTools.readFileXML(recentSearchManager, recentSearchManager.getRecentEnvFile()); |
||||
} catch (Exception e) { |
||||
FRContext.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
return recentSearchManager; |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void readXML(XMLableReader reader) { |
||||
if (reader.isAttr()) { |
||||
reader.readXMLObject(new XMLReadable() { |
||||
public void readXML(XMLableReader reader) { |
||||
if (reader.isChildNode()) { |
||||
String nodeName = reader.getTagName(); |
||||
if (nodeName.equals("RecentModel")) { |
||||
String key = reader.getAttrAsString("searchKey", StringUtils.EMPTY); |
||||
final ArrayList<AlphaCellModel> list = new ArrayList<AlphaCellModel>(); |
||||
reader.readXMLObject(new XMLReadable() { |
||||
@Override |
||||
public void readXML(XMLableReader reader) { |
||||
if (reader.isChildNode()) { |
||||
String nodeName = reader.getTagName(); |
||||
if (nodeName.equals("modelList")) { |
||||
String name = reader.getAttrAsString("cellModel", StringUtils.EMPTY); |
||||
try { |
||||
list.add(CellModelHelper.jsonToModel(new JSONObject(name))); |
||||
} catch (JSONException e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
); |
||||
recentKVModelMap.put(key, list); |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void writeXML(XMLPrintWriter writer) { |
||||
writer.startTAG(XML_TAG); |
||||
if (!recentKVModelMap.isEmpty()) { |
||||
for (String key : recentKVModelMap.keySet()) { |
||||
writer.startTAG("RecentModel"); |
||||
writer.attr("searchKey", key); |
||||
writer.startTAG("modelList"); |
||||
for (AlphaCellModel model : recentKVModelMap.get(key)) { |
||||
try { |
||||
String name = model.ModelToJson().toString(); |
||||
writer.attr("cellModel", name); |
||||
} catch (JSONException e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
writer.end(); |
||||
writer.end(); |
||||
} |
||||
} |
||||
writer.end(); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public String fileName() { |
||||
return "alphafine_recent.xml"; |
||||
} |
||||
|
||||
public List<String> getFileList() { |
||||
return fileList; |
||||
} |
||||
|
||||
public void setFileList(List<String> fileList) { |
||||
this.fileList = fileList; |
||||
} |
||||
|
||||
public List<String> getActionList() { |
||||
return actionList; |
||||
} |
||||
|
||||
public void setActionList(List<String> actionList) { |
||||
this.actionList = actionList; |
||||
} |
||||
|
||||
public List<String> getDocumentList() { |
||||
return documentList; |
||||
} |
||||
|
||||
public void setDocumentList(List<String> documentList) { |
||||
this.documentList = documentList; |
||||
} |
||||
|
||||
public List<String> getPluginList() { |
||||
return pluginList; |
||||
} |
||||
|
||||
public void setPluginList(List<String> pluginList) { |
||||
this.pluginList = pluginList; |
||||
} |
||||
|
||||
private File getRecentFile() { |
||||
if (recentFile == null) { |
||||
recentFile = new File(ProductConstants.getEnvHome() + File.separator + fileName()); |
||||
} |
||||
return recentFile; |
||||
} |
||||
|
||||
private File getRecentEnvFile() { |
||||
File envFile = getRecentFile(); |
||||
if (!envFile.exists()) { |
||||
createRecentFile(envFile); |
||||
} |
||||
|
||||
return envFile; |
||||
} |
||||
|
||||
private void createRecentFile(File envFile) { |
||||
try { |
||||
FileWriter fileWriter = new FileWriter(envFile); |
||||
StringReader stringReader = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><AlphafineRecent></AlphafineRecent>"); |
||||
Utils.copyCharTo(stringReader, fileWriter); |
||||
stringReader.close(); |
||||
fileWriter.close(); |
||||
} catch (IOException e) { |
||||
FRContext.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 保存XML到设计器安装目录 |
||||
*/ |
||||
public void saveXMLFile() { |
||||
File xmlFile = this.getRecentEnvFile(); |
||||
if (xmlFile == null) { |
||||
return; |
||||
} |
||||
if (!xmlFile.getParentFile().exists()) {//建立目录.
|
||||
StableUtils.mkdirs(xmlFile.getParentFile()); |
||||
} |
||||
|
||||
String tempName = xmlFile.getName() + ProjectConstants.TEMP_SUFFIX; |
||||
File tempFile = new File(xmlFile.getParentFile(), tempName); |
||||
|
||||
writeTempFile(tempFile); |
||||
IOUtils.renameTo(tempFile, xmlFile); |
||||
} |
||||
|
||||
private void writeTempFile(File tempFile) { |
||||
try { |
||||
OutputStream fout = new FileOutputStream(tempFile); |
||||
XMLTools.writeOutputStreamXML(this, fout); |
||||
fout.flush(); |
||||
fout.close(); |
||||
} catch (Exception e) { |
||||
FRContext.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
|
||||
public List<AlphaCellModel> getRecentModelList() { |
||||
return recentModelList; |
||||
} |
||||
|
||||
public void setRecentModelList(List<AlphaCellModel> recentModelList) { |
||||
this.recentModelList = recentModelList; |
||||
} |
||||
|
||||
public List<AlphaCellModel> getRecentModelList(String searchText) { |
||||
for (String key : recentKVModelMap.keySet()) { |
||||
if (recentKVModelMap.keySet().contains(searchText)) { |
||||
List<AlphaCellModel> list = recentKVModelMap.get(searchText); |
||||
return list; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public void addRecentModel(String searchKey, AlphaCellModel cellModel) { |
||||
|
||||
//final AlphaCellModel alphaCellModel = getCellModel(cellModel);
|
||||
if (recentKVModelMap.keySet().contains(searchKey)) { |
||||
List<AlphaCellModel> cellModels = recentKVModelMap.get(searchKey); |
||||
if (cellModels.contains(cellModel)) { |
||||
cellModels.remove(cellModel); |
||||
cellModels.add(cellModel); |
||||
} else { |
||||
cellModels.add(cellModel); |
||||
} |
||||
} else { |
||||
List<AlphaCellModel> list = new ArrayList<>(); |
||||
list.add(cellModel); |
||||
recentKVModelMap.put(searchKey, list); |
||||
} |
||||
// if (alphaCellModel != null) {
|
||||
// moveOnTop(alphaCellModel);
|
||||
// } else {
|
||||
// this.recentModelList.add(cellModel);
|
||||
// }
|
||||
// trimToSize();
|
||||
} |
||||
|
||||
private void moveOnTop(AlphaCellModel alphaCellModel) { |
||||
recentModelList.remove(alphaCellModel); |
||||
recentModelList.add(alphaCellModel); |
||||
} |
||||
|
||||
private synchronized void trimToSize() { |
||||
if (recentModelList.size() > AlphaFineConstants.MAX_FILE_SIZE) { |
||||
recentModelList.remove(0); |
||||
} |
||||
} |
||||
|
||||
private synchronized AlphaCellModel getCellModel(AlphaCellModel model) { |
||||
for (int i = recentModelList.size() - 1; i >= 0; i--) { |
||||
final AlphaCellModel entry = recentModelList.get(i); |
||||
String name = entry.getName(); |
||||
if (name.equals(model.getName())) { |
||||
return entry; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public Map<String, List<AlphaCellModel>> getRecentKVModelMap() { |
||||
return recentKVModelMap; |
||||
} |
||||
|
||||
public void setRecentKVModelMap(Map<String, List<AlphaCellModel>> recentKVModelMap) { |
||||
this.recentKVModelMap = recentKVModelMap; |
||||
} |
||||
|
||||
// public List<recentKVModel> getRecentKVModelList() {
|
||||
// return recentKVModelList;
|
||||
// }
|
||||
//
|
||||
// public void setRecentKVModelList(List<recentKVModel> recentKVModelList) {
|
||||
// this.recentKVModelList = recentKVModelList;
|
||||
// }
|
||||
} |
@ -1,194 +0,0 @@
|
||||
package com.fr.design.mainframe.alphafine.xmlManager; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.base.Utils; |
||||
import com.fr.file.XMLFileManager; |
||||
import com.fr.general.IOUtils; |
||||
import com.fr.stable.ProductConstants; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.project.ProjectConstants; |
||||
import com.fr.stable.xml.XMLPrintWriter; |
||||
import com.fr.stable.xml.XMLReadable; |
||||
import com.fr.stable.xml.XMLTools; |
||||
import com.fr.stable.xml.XMLableReader; |
||||
|
||||
import java.io.*; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* Created by XiaXiang on 2017/5/15. |
||||
*/ |
||||
public class RecentSearchManager extends XMLFileManager { |
||||
|
||||
private static final String XML_TAG = "AlphafineRecent"; |
||||
|
||||
private List<String> fileList; |
||||
|
||||
private List<String> actionList; |
||||
|
||||
private List<String> documentList; |
||||
|
||||
private List<String> pluginList; |
||||
|
||||
private Map<String, Integer> modelMap = new HashMap<>(); |
||||
|
||||
private static RecentSearchManager recentSearchManager = null; |
||||
|
||||
public synchronized static RecentSearchManager getInstance() { |
||||
if (recentSearchManager == null) { |
||||
recentSearchManager = new RecentSearchManager(); |
||||
} |
||||
try { |
||||
XMLTools.readFileXML(recentSearchManager, recentSearchManager.getRecentEnvFile()); |
||||
} catch (Exception e) { |
||||
FRContext.getLogger().error(e.getMessage(), e); |
||||
} |
||||
return recentSearchManager; |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void readXML(XMLableReader reader) { |
||||
if (reader.isAttr()) { |
||||
reader.readXMLObject(new XMLReadable() { |
||||
public void readXML(XMLableReader reader) { |
||||
if (reader.isChildNode()) { |
||||
String nodeName = reader.getTagName(); |
||||
if (nodeName.equals("RecentModel")) { |
||||
modelMap.put(reader.getAttrAsString("name", StringUtils.EMPTY), reader.getAttrAsInt("celltype", 0)); |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void writeXML(XMLPrintWriter writer) { |
||||
writer.startTAG(XML_TAG); |
||||
if (!modelMap.isEmpty()) { |
||||
for (String name : modelMap.keySet()) { |
||||
writer.startTAG("RecentModel"); |
||||
writer.attr("name", name); |
||||
writer.attr("celltype", modelMap.get(name)); |
||||
writer.end(); |
||||
} |
||||
} |
||||
writer.end(); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public String fileName() { |
||||
return "alphafine_recent.xml"; |
||||
} |
||||
|
||||
public List<String> getFileList() { |
||||
return fileList; |
||||
} |
||||
|
||||
public void setFileList(List<String> fileList) { |
||||
this.fileList = fileList; |
||||
} |
||||
|
||||
public List<String> getActionList() { |
||||
return actionList; |
||||
} |
||||
|
||||
public void setActionList(List<String> actionList) { |
||||
this.actionList = actionList; |
||||
} |
||||
|
||||
public List<String> getDocumentList() { |
||||
return documentList; |
||||
} |
||||
|
||||
public void setDocumentList(List<String> documentList) { |
||||
this.documentList = documentList; |
||||
} |
||||
|
||||
public List<String> getPluginList() { |
||||
return pluginList; |
||||
} |
||||
|
||||
public void setPluginList(List<String> pluginList) { |
||||
this.pluginList = pluginList; |
||||
} |
||||
|
||||
public Map<String, Integer> getModelMap() { |
||||
return modelMap; |
||||
} |
||||
|
||||
public void setModelMap(Map<String, Integer> modelMap) { |
||||
this.modelMap = modelMap; |
||||
} |
||||
|
||||
private static File recentFile = null; |
||||
|
||||
private File getRecentFile() { |
||||
if (recentFile == null) { |
||||
recentFile = new File(ProductConstants.getEnvHome() + File.separator + fileName()); |
||||
} |
||||
return recentFile; |
||||
} |
||||
|
||||
private File getRecentEnvFile() { |
||||
File envFile = getRecentFile(); |
||||
if (!envFile.exists()) { |
||||
createRecentFile(envFile); |
||||
} |
||||
|
||||
return envFile; |
||||
} |
||||
|
||||
private void createRecentFile(File envFile) { |
||||
try { |
||||
FileWriter fileWriter = new FileWriter(envFile); |
||||
StringReader stringReader = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><AlphafineRecent></AlphafineRecent>"); |
||||
Utils.copyCharTo(stringReader, fileWriter); |
||||
stringReader.close(); |
||||
fileWriter.close(); |
||||
} catch (IOException e) { |
||||
FRContext.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 保存设计器的配置文件, 该文件不在env的resource目录下 |
||||
* 而是在Consts.getEnvHome() + File.separator + Consts.APP_NAME |
||||
* |
||||
* |
||||
* @date 2014-9-29-上午11:04:23 |
||||
* |
||||
*/ |
||||
public void saveXMLFile() { |
||||
File xmlFile = this.getRecentEnvFile(); |
||||
if (xmlFile == null) { |
||||
return; |
||||
} |
||||
if (!xmlFile.getParentFile().exists()) {//建立目录.
|
||||
StableUtils.mkdirs(xmlFile.getParentFile()); |
||||
} |
||||
|
||||
String tempName = xmlFile.getName() + ProjectConstants.TEMP_SUFFIX; |
||||
File tempFile = new File(xmlFile.getParentFile(), tempName); |
||||
|
||||
writeTempFile(tempFile); |
||||
IOUtils.renameTo(tempFile, xmlFile); |
||||
} |
||||
|
||||
private void writeTempFile(File tempFile){ |
||||
try{ |
||||
OutputStream fout = new FileOutputStream(tempFile); |
||||
XMLTools.writeOutputStreamXML(this, fout); |
||||
fout.flush(); |
||||
fout.close(); |
||||
}catch (Exception e) { |
||||
FRContext.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue