use of org.eclipse.core.resources.IWorkspaceRoot in project generator by mybatis.
the class EclipseShellCallback method getJavaProject.
private IJavaProject getJavaProject(String javaProjectName) throws ShellException {
IJavaProject javaProject = projects.get(javaProjectName);
if (javaProject == null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(javaProjectName);
if (project.exists()) {
boolean isJavaProject;
try {
isJavaProject = project.hasNature(JavaCore.NATURE_ID);
} catch (CoreException e) {
throw new ShellException(e.getStatus().getMessage(), e);
}
if (isJavaProject) {
javaProject = JavaCore.create(project);
} else {
StringBuffer sb = new StringBuffer();
sb.append("Project ");
sb.append(javaProjectName);
sb.append(" is not a Java project");
throw new ShellException(sb.toString());
}
} else {
StringBuffer sb = new StringBuffer();
sb.append("Project ");
sb.append(javaProjectName);
sb.append(" does not exist");
throw new ShellException(sb.toString());
}
projects.put(javaProjectName, javaProject);
}
return javaProject;
}
use of org.eclipse.core.resources.IWorkspaceRoot in project dbeaver by serge-rider.
the class TreeLoadVisualizer method completeLoading.
@Override
public void completeLoading(Object[] children) {
final Control viewerControl = viewer.getControl();
if (viewerControl.isDisposed()) {
return;
}
try {
viewerControl.setRedraw(false);
Widget widget = viewer.testFindItem(parent);
if (widget != null && !widget.isDisposed()) {
TreeItem item = (TreeItem) viewer.testFindItem(placeHolder);
if (children == null) {
// Some error occurred. In good case children must be at least an empty array
viewer.collapseToLevel(parent, -1);
} else if (children.length != 0) {
viewer.add(parent, children);
}
if (item != null && !item.isDisposed()) {
if (item.getParentItem() != null && !item.getParentItem().isDisposed() || this.parent instanceof IWorkspaceRoot) {
viewer.remove(placeHolder);
}
}
}
} finally {
placeHolder.dispose(parent);
if (!viewerControl.isDisposed()) {
viewerControl.setRedraw(true);
}
}
}
use of org.eclipse.core.resources.IWorkspaceRoot in project translationstudio8 by heartsome.
the class XLFValidator method validateXliffFile.
public static boolean validateXliffFile(File file) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile ifile = root.getFileForLocation(URIUtil.toPath(file.toURI()));
if (ifile == null) {
Shell shell = Display.getDefault().getActiveShell();
MessageDialog.openError(shell, Messages.getString("file.XLFValidator.msgTitle"), Messages.getString("file.XLFValidator.msg9"));
return false;
}
return validateXliffFile(ifile);
}
use of org.eclipse.core.resources.IWorkspaceRoot in project translationstudio8 by heartsome.
the class ApplicationWorkbenchWindowAdvisor method restorEditorHistory.
/**
* 重新恢复产品上次退时出所保存的编辑器,此修复针对 mac 下的 bug 2998 启动:某客户安装的软件只能使用一次. robert 2013-05-21
*/
private void restorEditorHistory() {
// 只针对 mac 下的用户
if (System.getProperty("os.name").indexOf("Mac") == -1) {
return;
}
final WorkbenchPage page = (WorkbenchPage) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("", 10);
String tempEditorHistoryLC = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(Constant.TEMP_EDITOR_HISTORY).toOSString();
File tempEditorHistoryFile = new File(tempEditorHistoryLC);
if (!tempEditorHistoryFile.exists()) {
return;
}
monitor.worked(1);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
VTDGen vg = new VTDGen();
try {
boolean parseResult = vg.parseFile(tempEditorHistoryLC, true);
if (!parseResult) {
return;
}
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
int storeFileSum = 0;
ap.selectXPath("count(/editors/editor)");
storeFileSum = (int) ap.evalXPathToNumber();
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
subMonitor.beginTask("", storeFileSum);
ap.selectXPath("/editors/editor");
String editorId = null;
String localFilePath = null;
boolean activate = false;
IEditorReference activateEditorRefe = null;
IEditorReference firstEditor = null;
IFile curIFile = null;
int index = -1;
while (ap.evalXPath() != -1) {
activate = false;
editorId = null;
localFilePath = null;
if ((index = vn.getAttrVal("id")) != -1) {
editorId = vn.toRawString(index);
}
if ((index = vn.getAttrVal("path")) != -1) {
localFilePath = vn.toRawString(index);
}
if (editorId == null || editorId.trim().length() <= 0 || localFilePath == null || localFilePath.trim().length() <= 0) {
continue;
}
if ((index = vn.getAttrVal("active")) != -1) {
if ("true".equals(vn.toRawString(index))) {
activate = true;
}
}
curIFile = root.getFileForLocation(new Path(localFilePath));
if (!curIFile.exists()) {
subMonitor.worked(1);
continue;
}
if (activate) {
activateEditorRefe = page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
} else {
if (firstEditor == null) {
firstEditor = page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
} else {
page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
}
PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
}
subMonitor.worked(1);
}
PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
if (activateEditorRefe != null) {
if (firstEditor != null) {
page.activate(firstEditor.getEditor(true));
}
page.activate(activateEditorRefe.getEditor(true));
}
subMonitor.done();
monitor.done();
} catch (Exception e) {
LOGGER.error("restore editor file error", e);
}
}
};
try {
new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, runnable);
} catch (Exception e) {
LOGGER.error("restore editor file error", e);
}
}
use of org.eclipse.core.resources.IWorkspaceRoot in project translationstudio8 by heartsome.
the class SplitXliffWizard method performFinish.
@Override
public boolean performFinish() {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IPath containerIPath = root.getLocation().append(splitXliffWizardPage.getTargetXlfPathStr());
IContainer splitXlfsContainer = root.getContainerForLocation(containerIPath);
if (!splitXlfsContainer.exists()) {
// 创建该路径
File file = new File(splitXlfsContainer.getLocation().toOSString());
file.mkdirs();
}
model.setSplitXlfsContainer(splitXlfsContainer);
final IRunnableWithProgress splitProgress = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
// uicallback
canFinish = splitXliff.splitTheXliff(monitor);
}
};
try {
getContainer().run(true, true, splitProgress);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
// 创建项目后刷新资源视图
try {
model.getSplitFile().getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
e.printStackTrace();
}
return canFinish;
}
Aggregations