use of net.heartsome.cat.ts.websearch.bean.SearchEntry in project translationstudio8 by heartsome.
the class WebSearchPreferencePage method downSelectItem.
public void downSelectItem() {
int selectIndex = getSelectIndex();
if (-1 == selectIndex || cache.size() - 1 == selectIndex) {
return;
}
SearchEntry currentSelect = cache.get(selectIndex);
SearchEntry lastData = cache.get(selectIndex + 1);
cache.set(selectIndex + 1, currentSelect);
cache.set(selectIndex, lastData);
checkboxTableViewer.refresh();
setDirty(true);
updateState();
}
use of net.heartsome.cat.ts.websearch.bean.SearchEntry in project translationstudio8 by heartsome.
the class WebSearchPreferencePage method deleteSelectItem.
public void deleteSelectItem() {
int selectIndex = getSelectIndex();
if (-1 == selectIndex) {
return;
}
SearchEntry searchEntry = cache.get(selectIndex);
boolean config = MessageDialog.openConfirm(getShell(), Messages.getString("Websearch.WebSearcPreferencePage.tipTitle"), MessageFormat.format(Messages.getString("Websearch.WebSearcPreferencePage.deleteConfig"), searchEntry.getSearchName()));
if (config) {
cache.remove(selectIndex);
checkboxTableViewer.refresh();
setDirty(true);
updateState();
}
}
use of net.heartsome.cat.ts.websearch.bean.SearchEntry in project translationstudio8 by heartsome.
the class WebSearchPreferencStore method storeConfig.
/**
* 保存设置值
* @param searchEntry
* ;
*/
public void storeConfig(List<SearchEntry> searchEntry) {
FileOutputStream out = null;
boolean hasError = false;
try {
out = new FileOutputStream(customConfigPath);
writeContent(out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
writeContent(out, "<WebSearchInfo xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instancexmlns:xsd=http://www.w3.org/2001/XMLSchema\">\r\n");
writeContent(out, " <Providers>\r\n");
if (null != searchEntry) {
for (SearchEntry s : searchEntry) {
writeContent(out, convert2Xml(s));
}
}
writeContent(out, " </Providers>\r\n </WebSearchInfo>");
out.flush();
support.firePropertyChange("URL", null, getUseredConfig(searchEntry));
} catch (FileNotFoundException e) {
hasError = true;
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
hasError = true;
e.printStackTrace();
} catch (IOException e) {
hasError = true;
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
if (hasError) {
XMLModifier modifier;
try {
modifier = new XMLModifier(customVu.getVTDNav());
modifier.output(customConfigPath);
} catch (ModifyException e) {
e.printStackTrace();
logger.error("", e);
} catch (TranscodeException e) {
e.printStackTrace();
logger.error("", e);
} catch (IOException e) {
e.printStackTrace();
logger.error("", e);
}
} else {
try {
customVu.parseFile(customConfigPath, false);
} catch (ParseException e) {
e.printStackTrace();
logger.error("", e);
} catch (IOException e) {
e.printStackTrace();
logger.error("", e);
}
}
}
}
use of net.heartsome.cat.ts.websearch.bean.SearchEntry in project translationstudio8 by heartsome.
the class WebSearchPreferencStore method getConfig.
/**
* @param vu
* @param isDefault
* getCustomContent===false:返回所有内容 getCustomContent===true :返回非默认的内容
* @return ;
*/
private List<SearchEntry> getConfig(VTDUtils vu, boolean getCustomContent) {
VTDNav vn = vu.getVTDNav();
AutoPilot mainAp = new AutoPilot(vn);
AutoPilot uesedAp = new AutoPilot(vn);
AutoPilot nameAp = new AutoPilot(vn);
AutoPilot urlAp = new AutoPilot(vn);
List<SearchEntry> cache = new ArrayList<SearchEntry>();
try {
mainAp.selectXPath("/WebSearchInfo/Providers/ProviderInfo");
uesedAp.selectXPath("./Used");
nameAp.selectXPath("./Name");
urlAp.selectXPath("./Url");
SearchEntry temp = null;
while (mainAp.evalXPath() != -1) {
int attrVal = vn.getAttrVal("isDefault");
if (getCustomContent) {
if (-1 != attrVal) {
continue;
}
}
temp = new SearchEntry();
if (-1 != attrVal) {
temp.setDefault(true);
}
int idIndex = vn.getAttrVal("id");
if (-1 != idIndex) {
temp.setId(vn.toString(idIndex));
}
vn.push();
uesedAp.resetXPath();
if (uesedAp.evalXPath() != -1) {
int textIndex = vn.getText();
if (-1 != textIndex && null != temp) {
temp.setChecked("true".equalsIgnoreCase(vn.toString(textIndex)) ? true : false);
}
} else {
temp = null;
}
vn.pop();
vn.push();
nameAp.resetXPath();
if (nameAp.evalXPath() != -1) {
int textIndex = vn.getText();
if (-1 != textIndex && null != temp) {
temp.setSearchName(TextUtil.resetSpecialString(vn.toString(textIndex)));
}
} else {
temp = null;
}
vn.pop();
vn.push();
urlAp.resetXPath();
if (urlAp.evalXPath() != -1) {
int textIndex = vn.getText();
if (-1 != textIndex && null != temp) {
temp.setSearchUrl((TextUtil.resetSpecialString(vn.toString(textIndex))));
}
} else {
temp = null;
}
vn.pop();
if (null != temp) {
cache.add(temp);
}
}
} catch (XPathEvalException e) {
e.printStackTrace();
logger.error("", e);
} catch (NavException e) {
e.printStackTrace();
logger.error("", e);
} catch (XPathParseException e) {
e.printStackTrace();
logger.error("", e);
}
return cache;
}
use of net.heartsome.cat.ts.websearch.bean.SearchEntry in project translationstudio8 by heartsome.
the class WebSearchPreferencStore method getDefaluSearchConfig.
/**
* 获取默认的配置信息,包括自定义配置文件和默认配置文件两个文件中的信息
* @return ;
*/
public List<SearchEntry> getDefaluSearchConfig() {
List<SearchEntry> config = getConfig(customVu, true);
for (SearchEntry temp : config) {
temp.setChecked(false);
}
List<SearchEntry> defaultconfig = getConfig(defaultVu, false);
defaultconfig.addAll(config);
return defaultconfig;
}
Aggregations