use of net.heartsome.cat.ts.importproject.widgiet.ProjectResource in project translationstudio8 by heartsome.
the class ImportProjectWizardPage2 method getProjectResourceInput.
/**
* 获取左边树(选择项目资源树)的输入内容
* @return
*/
private ProjectResource[] getProjectResourceInput() {
rootProjectArray = null;
List<ProjectResource> proResourceList = new ArrayList<ProjectResource>();
for (int i = 0; i < selectedProjects.length; i++) {
proResourceList.add(new ProjectResource(selectedProjects[i].getParent(), selectedProjects[i], structureProvider));
}
rootProjectArray = (ProjectResource[]) proResourceList.toArray(new ProjectResource[proResourceList.size()]);
selectElementTree.setRoot(rootProjectArray);
return rootProjectArray;
}
use of net.heartsome.cat.ts.importproject.widgiet.ProjectResource in project translationstudio8 by heartsome.
the class ImportProjectWizardPage2 method createCurProjectResource.
/**
* 获取指定节点被选择的子节点
* @param parentResource
* 树节点的父节点
* @param parentFolder
* 项目空间的父文件夹
* @return
*/
private void createCurProjectResource(ProjectResource parentResource, IFolder parentContainer) throws Exception {
if (parentResource == null || parentContainer == null) {
return;
}
for (Object obj : selectContentProvider.getChildren(parentResource)) {
if (obj instanceof ProjectResource) {
ProjectResource proResource = (ProjectResource) obj;
if (!selectElementTree.getChecked(proResource)) {
continue;
}
// 如果是文件夹,如果没有创建,直接创建
if (proResource.isFolder()) {
IFolder childFolder = parentContainer.getFolder(proResource.getLabel());
if (!childFolder.exists()) {
childFolder.create(true, true, null);
}
createCurProjectResource(proResource, childFolder);
} else {
// 如果是文件,则判断是否需要覆盖,若是,则直接覆盖
if (proResource.isNeedCover()) {
IFile iFile = parentContainer.getFile(proResource.getLabel());
InputStream inputStream = proResource.getInputStream();
if (inputStream != null) {
if (iFile.exists()) {
closeOpenedFile(iFile);
iFile.delete(true, null);
}
iFile.create(inputStream, true, null);
}
}
}
}
}
}
use of net.heartsome.cat.ts.importproject.widgiet.ProjectResource in project translationstudio8 by heartsome.
the class ImportProjectWizardPage2 method selectElementTreeBtnSelectFunction.
/**
* 点击选择所有以及所有不选择按钮时执行的方法
* @param event
*/
private void selectElementTreeBtnSelectFunction(final boolean checkState) {
checkedRepeatElementMap.clear();
selectElementTree.setCheckedAll(checkState);
Object[] checkedElementArray = selectElementTree.getCheckedElements();
for (Object checkedElement : checkedElementArray) {
if (checkedElement instanceof ProjectResource) {
ProjectResource proResourceElement = (ProjectResource) checkedElement;
String projectName = proResourceElement.getProjectName();
// 如果是重复的资源,那么添加到缓存中
if (proResourceElement.isProjectRepeat()) {
if (checkedRepeatElementMap.containsKey(projectName)) {
Set<ProjectResource> checkedElementSet = checkedRepeatElementMap.get(projectName);
checkedElementSet.add(proResourceElement);
checkedRepeatElementMap.put(projectName, checkedElementSet);
} else {
Set<ProjectResource> checkedElementSet = new HashSet<ProjectResource>();
checkedElementSet.add(proResourceElement);
checkedRepeatElementMap.put(projectName, checkedElementSet);
}
}
}
}
setNotCoverForNotcheckOfSelectTree();
repeatElementTree.refresh();
repeatElementTree.expandAll();
checkRepeatTreeBtnSelectFunction(true);
}
use of net.heartsome.cat.ts.importproject.widgiet.ProjectResource in project translationstudio8 by heartsome.
the class ImportProjectWizardPage2 method createProjects.
/**
* 创建项目
* @return
*/
public boolean createProjects(IProgressMonitor monitor) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
Display.getDefault().syncExec(new Runnable() {
public void run() {
for (ProjectResource projRoot : rootProjectArray) {
if (selectElementTree.getChecked(projRoot)) {
totalWorkSum++;
}
}
}
});
monitor.beginTask(Messages.getString("importProjectWizardPage.beginImportProj"), totalWorkSum);
Display.getDefault().syncExec(new Runnable() {
public void run() {
openedIfileMap = getAllOpenedIFile();
}
});
try {
// 一个项目一个项目的进行相关处理
for (final ProjectResource projRoot : rootProjectArray) {
// 如果当前项目未被选择。跳过继续执行
runContinue = false;
Display.getDefault().syncExec(new Runnable() {
public void run() {
if (!selectElementTree.getChecked(projRoot)) {
runContinue = true;
}
}
});
if (runContinue) {
continue;
}
monitor.setTaskName(MessageFormat.format(Messages.getString("importProjectWizardPage.beginImportProjName"), new Object[] { projRoot.getProjectName() }));
final IProject newProject = root.getProject(projRoot.getProjectName());
if (!projRoot.isProjectRepeat()) {
// 创建项目
newProject.create(null);
if (!newProject.isOpen()) {
newProject.open(null);
}
}
IFile configIFile = newProject.getFile(Constant.FILE_CONFIG);
ProjectConfigerUtil configUtil = null;
if (configIFile.exists()) {
configUtil = new ProjectConfigerUtil(newProject);
configUtil.setDbMementos();
configUtil.clearConfig();
}
final StringBuilder sb = new StringBuilder();
try {
Display.getDefault().syncExec(new Runnable() {
public void run() {
try {
createProjectImpl(projRoot, newProject);
} catch (Exception e) {
sb.append(Messages.getString("importProjectWizardPage.importFail"));
LOGGER.error("", e);
}
}
});
} finally {
if (null != configUtil) {
configUtil.restoreMementos();
}
if (!sb.toString().isEmpty()) {
monitor.done();
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openWarning(getShell(), Messages.getString("importProject.all.dialog.warning"), Messages.getString("importProjectWizardPage.importFail"));
}
});
return false;
}
}
createConfigFile(projRoot, newProject);
createRequireFolder(newProject);
resetConfigContent(newProject);
monitor.worked(1);
}
} catch (Exception e) {
e.printStackTrace();
monitor.done();
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openWarning(getShell(), Messages.getString("importProject.all.dialog.warning"), Messages.getString("importProjectWizardPage.importFail"));
}
});
LOGGER.error(Messages.getString("importProjectWizardPage.LOGG.importEroor"), e);
// disposeImg();
return false;
}
disposeImg();
monitor.done();
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("importProject.all.dialog.info"), Messages.getString("importProjectWizardPage.importSuccess"));
}
});
return true;
}
use of net.heartsome.cat.ts.importproject.widgiet.ProjectResource in project translationstudio8 by heartsome.
the class ImportProjectWizardPage2 method selectElementTreeCheckFunction.
/**
* 左边树点击事件触发的方法
* @param event
*/
private void selectElementTreeCheckFunction(CheckStateChangedEvent event) {
checkedRepeatElementMap.clear();
Object[] checkedElementArray = selectElementTree.getCheckedElements();
for (Object checkedElement : checkedElementArray) {
if (checkedElement instanceof ProjectResource) {
ProjectResource proResourceElement = (ProjectResource) checkedElement;
String projectName = proResourceElement.getProjectName();
// 如果是重复的资源,那么添加到缓存中
if (proResourceElement.isProjectRepeat()) {
if (checkedRepeatElementMap.containsKey(projectName)) {
Set<ProjectResource> checkedElementSet = checkedRepeatElementMap.get(projectName);
checkedElementSet.add(proResourceElement);
checkedRepeatElementMap.put(projectName, checkedElementSet);
} else {
Set<ProjectResource> checkedElementSet = new HashSet<ProjectResource>();
checkedElementSet.add(proResourceElement);
checkedRepeatElementMap.put(projectName, checkedElementSet);
}
}
}
}
boolean noData = repeatElementTree.getTree().getItemCount() <= 0;
repeatElementTree.refresh();
if (noData) {
checkRepeatTreeBtnSelectFunction(true);
repeatElementTree.expandAll();
}
}
Aggregations