Search in sources :

Example 11 with IWorkspaceRoot

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;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) ShellException(org.mybatis.generator.exception.ShellException) IProject(org.eclipse.core.resources.IProject)

Example 12 with IWorkspaceRoot

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);
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) TreeItem(org.eclipse.swt.widgets.TreeItem) Widget(org.eclipse.swt.widgets.Widget)

Example 13 with IWorkspaceRoot

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);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot)

Example 14 with IWorkspaceRoot

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);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) VTDGen(com.ximpleware.VTDGen) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) WorkbenchPage(org.eclipse.ui.internal.WorkbenchPage) IEditorReference(org.eclipse.ui.IEditorReference) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) AutoPilot(com.ximpleware.AutoPilot) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IFile(org.eclipse.core.resources.IFile) File(java.io.File) VTDNav(com.ximpleware.VTDNav)

Example 15 with IWorkspaceRoot

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;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)92 IPath (org.eclipse.core.runtime.IPath)41 IProject (org.eclipse.core.resources.IProject)31 IFile (org.eclipse.core.resources.IFile)30 IResource (org.eclipse.core.resources.IResource)29 CoreException (org.eclipse.core.runtime.CoreException)25 File (java.io.File)19 IWorkspace (org.eclipse.core.resources.IWorkspace)15 Path (org.eclipse.core.runtime.Path)14 IFolder (org.eclipse.core.resources.IFolder)12 IJavaProject (org.eclipse.jdt.core.IJavaProject)11 ArrayList (java.util.ArrayList)10 IContainer (org.eclipse.core.resources.IContainer)10 IOException (java.io.IOException)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 URI (java.net.URI)5 IProjectDescription (org.eclipse.core.resources.IProjectDescription)5 IStatus (org.eclipse.core.runtime.IStatus)5 Project (aQute.bnd.build.Project)4 Workspace (aQute.bnd.build.Workspace)4