Example usage for org.eclipse.jdt.core IPackageFragmentRoot getPath

List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getPath

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IPackageFragmentRoot getPath.

Prototype

IPath getPath();

Source Link

Document

Returns the path to the innermost resource enclosing this element.

Usage

From source file:com.google.gdt.eclipse.maven.sdk.GWTMavenRuntime.java

License:Open Source License

private IClasspathEntry findJavaXValidationClasspathEntry() throws JavaModelException {
    IType type = javaProject.findType("javax.validation.Constraint");

    if (type == null) {
        return null;
    }/*  w ww  . ja va  2 s .c o m*/

    IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) type
            .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
    if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_BINARY) {
        return JavaCore.newLibraryEntry(packageFragmentRoot.getPath(), null, null);
    }

    return null;
}

From source file:com.google.gwt.eclipse.core.wizards.NewModuleWizardPage.java

License:Open Source License

protected IPath getModulePath() {
    IPackageFragmentRoot root = getPackageFragmentRoot();
    IPath rootPath = root.getPath();

    String packageName = getModulePackageName();
    if (packageName != null && packageName.length() > 0) {
        rootPath = rootPath.append(packageName.replace('.', '/'));
    }//from ww w .ja va 2s .  c  om

    IPath moduleFilePath = rootPath.append(getModuleName());

    moduleFilePath = moduleFilePath.addFileExtension("gwt.xml");

    return moduleFilePath;
}

From source file:com.google.gwt.eclipse.core.wizards.NewModuleWizardPage.java

License:Open Source License

private IStatus packageChanged() {

    String packName = modulePackageField.getText();
    IStatus validatePackageStatus = Util.validatePackageName(packName);

    if (validatePackageStatus.getSeverity() == IStatus.ERROR) {
        return validatePackageStatus;
    }/*from   www  . j a  v a 2s  .  co m*/

    if (packName.length() == 0) {
        modulePackageField.setStatus(NewWizardMessages.NewTypeWizardPage_default);
    } else {
        modulePackageField.setStatus("");
    }

    IJavaProject project = getJavaProject();
    IPackageFragmentRoot root = getPackageFragmentRoot();

    if (project != null && root != null) {
        if (project.exists() && packName.length() > 0) {
            try {
                IPath rootPath = root.getPath();
                IPath outputPath = project.getOutputLocation();
                if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
                    // if the bin folder is inside of our root, don't allow to name a
                    // package like the bin folder
                    IPath packagePath = rootPath.append(packName.replace('.', '/'));
                    if (outputPath.isPrefixOf(packagePath)) {
                        return Util
                                .newErrorStatus(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation);
                    }
                }
            } catch (JavaModelException e) {
                // Not a critical exception at this juncture; we'll just log it
                // and move on.
                GWTPluginLog.logError(e);
            }
        }
    }

    return validatePackageStatus;
}

From source file:com.google.gwt.eclipse.devtoolsgen.actions.PopulateGwtDevTools.java

License:Open Source License

private static IFile findFileOnClasspath(IJavaProject javaProject, IPath classpathRelativePath)
        throws JavaModelException {
    for (IPackageFragmentRoot pckgFragmentRoot : javaProject.getPackageFragmentRoots()) {
        if (pckgFragmentRoot.isArchive()) {
            continue;
        }//  w ww .j  a  v  a  2  s.c o m
        IPath filepath = pckgFragmentRoot.getPath().append(classpathRelativePath);
        IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(filepath);
        if (res instanceof IFile) {
            return (IFile) res;
        }
    }
    return null;
}

From source file:com.gwtplatform.plugin.wizard.NewActionWizardPage.java

License:Apache License

private IStatus actionHandlerChanged() {
    StatusInfo status = new StatusInfo();

    if (actionHandlerPackage.getText().isEmpty()) {
        status.setError("You must select the ActionHandler's package");
        return status;
    }//w w w.j  ava2  s. c  o  m

    IPackageFragmentRoot root = getPackageFragmentRoot();
    IJavaProject project = root.getJavaProject();
    IPackageFragment pack = root.getPackageFragment(actionHandlerPackage.getText());

    if (!pack.getElementName().isEmpty()) {
        IStatus val = JavaConventionsUtil.validatePackageName(pack.getElementName(), project);
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName,
                    val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(Messages.format(
                    NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName, val.getMessage()));
            // continue
        }
    } else {
        status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_DefaultPackageDiscouraged);
    }

    if (!pack.getElementName().contains(".server")) {
        status.setError("ActionHandler's package must be in the server package");
        return status;
    }

    if (project != null) {
        if (project.exists() && !pack.getElementName().isEmpty()) {
            try {
                IPath rootPath = root.getPath();
                IPath outputPath = project.getOutputLocation();
                if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
                    // if the bin folder is inside of our root, don't allow to name a
                    // package
                    // like the bin folder
                    IPath packagePath = rootPath.append(pack.getElementName().replace('.', '/'));
                    if (outputPath.isPrefixOf(packagePath)) {
                        status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation);
                        return status;
                    }
                }
            } catch (JavaModelException e) {
                JavaPlugin.log(e);
                // let pass
            }
        }
    } else {
        status.setError("");
    }
    return status;
}

From source file:com.hudson.hibernatesynchronizer.wizard.NewConfigurationWizardPage.java

License:GNU General Public License

/**
 * Tests if the current workbench selection is a suitable container to use.
 *///www. j  a  v a  2 s.  c om

private void initialize() {
    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() == 1) {
            Object obj = ssel.getFirstElement();
            if (obj instanceof IResource) {
                IContainer cont;
                if (obj instanceof IContainer)
                    cont = (IContainer) obj;
                else
                    cont = ((IResource) obj).getParent();
                containerText.setText(cont.getFullPath().toString());
                projectChanged(((IResource) obj).getProject());
            } else if (obj instanceof IPackageFragment) {
                IPackageFragment frag = (IPackageFragment) obj;
                containerText.setText(frag.getPath().toString());
                projectChanged(frag.getJavaProject().getProject());
            } else if (obj instanceof IPackageFragmentRoot) {
                IPackageFragmentRoot root = (IPackageFragmentRoot) obj;
                containerText.setText(root.getPath().toString());
                projectChanged(root.getJavaProject().getProject());
            } else if (obj instanceof IJavaProject) {
                IJavaProject proj = (IJavaProject) obj;
                containerText.setText("/" + proj.getProject().getName());
                projectChanged(proj.getProject());
            } else if (obj instanceof IProject) {
                IProject proj = (IProject) obj;
                containerText.setText("/" + proj.getName());
                projectChanged(proj);
            }
        }
    }
    fileText.setText("hibernate.cfg.xml");
}

From source file:com.hudson.hibernatesynchronizer.wizard.NewMappingWizardPage.java

License:GNU General Public License

public Composite addConfiguration(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);/*ww w.j a va  2 s.  c  o m*/
    layout.numColumns = 3;
    layout.verticalSpacing = 9;

    Label label = new Label(container, SWT.NULL);
    label.setText("&Container:");

    containerText = new Text(container, SWT.BORDER | SWT.SINGLE);
    containerText.setEnabled(false);
    containerText.setBackground(new Color(null, 255, 255, 255));
    GridData gd = new GridData();
    gd.widthHint = 250;
    containerText.setLayoutData(gd);
    containerText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    Button containerButton = new Button(container, SWT.NATIVE);
    containerButton.setText("Browse");
    containerButton.addMouseListener(new ContainerMouseListener(this));

    label = new Label(container, SWT.NULL);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 3;
    label.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("&Driver:");
    driverText = new Text(container, SWT.BORDER | SWT.SINGLE);
    driverText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    driverText.setEnabled(false);
    driverText.setBackground(new Color(null, 255, 255, 255));
    gd = new GridData();
    gd.widthHint = 250;
    driverText.setLayoutData(gd);
    Button driverButton = new Button(container, SWT.NATIVE);
    driverButton.setText("Browse");
    driverButton.addMouseListener(new DriverMouseListener(this));

    label = new Label(container, SWT.NULL);
    label.setText("&Database URL:");
    databaseUrlText = new Text(container, SWT.BORDER | SWT.SINGLE);
    databaseUrlText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.widthHint = 250;
    databaseUrlText.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("&Username:");
    usernameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    usernameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.widthHint = 150;
    usernameText.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("&Password:");
    passwordText = new Text(container, SWT.BORDER | SWT.SINGLE);
    passwordText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    passwordText.setEchoChar('*');
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.widthHint = 150;
    passwordText.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("Table pattern:");
    tablePattern = new Text(container, SWT.BORDER | SWT.SINGLE);
    tablePattern.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    tablePattern.setEnabled(true);
    tablePattern.setBackground(new Color(null, 255, 255, 255));
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.widthHint = 250;
    tablePattern.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("Schema pattern:");
    schemaPattern = new Text(container, SWT.BORDER | SWT.SINGLE);
    schemaPattern.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    schemaPattern.setEnabled(true);
    schemaPattern.setBackground(new Color(null, 255, 255, 255));
    gd = new GridData();
    gd.horizontalSpan = 2;
    gd.widthHint = 250;
    schemaPattern.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("Tables");
    table = new Table(container, SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.CHECK);
    table.setVisible(true);
    table.setLinesVisible(false);
    table.setHeaderVisible(false);
    table.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            dialogChanged();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    GridData data = new GridData();
    data.heightHint = 150;
    data.widthHint = 250;
    table.setLayoutData(data);

    // create the columns
    TableColumn nameColumn = new TableColumn(table, SWT.LEFT);
    ColumnLayoutData nameColumnLayout = new ColumnWeightData(100, false);

    // set columns in Table layout
    TableLayout tableLayout = new TableLayout();
    tableLayout.addColumnData(nameColumnLayout);
    table.setLayout(tableLayout);

    Composite buttonContainer = new Composite(container, SWT.NULL);
    buttonContainer.setLayout(new GridLayout(1, true));
    gd = new GridData();
    gd.verticalAlignment = GridData.BEGINNING;
    gd.horizontalAlignment = GridData.BEGINNING;
    buttonContainer.setLayoutData(gd);
    tableRefreshButton = new Button(buttonContainer, SWT.PUSH);
    tableRefreshButton.setText("Refresh");
    tableRefreshButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    tableRefreshButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            try {
                dialog.run(false, true, new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        try {
                            monitor.beginTask("Refreshing tables...", 21);
                            refreshTables(monitor);
                        } catch (Exception e) {
                            throw new InvocationTargetException(e);
                        } finally {
                            monitor.done();
                        }
                    }
                });
            } catch (Exception exc) {
            }
        }
    });
    selectAllButton = new Button(buttonContainer, SWT.PUSH);
    selectAllButton.setText("Select All");
    selectAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    selectAllButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            try {
                for (int i = 0; i < table.getItemCount(); i++) {
                    table.getItem(i).setChecked(true);
                }
                dialogChanged();
            } catch (Exception exc) {
            }
        }
    });
    selectNoneButton = new Button(buttonContainer, SWT.PUSH);
    selectNoneButton.setText("Select None");
    selectNoneButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    selectNoneButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            try {
                for (int i = 0; i < table.getItemCount(); i++) {
                    table.getItem(i).setChecked(false);
                }
                dialogChanged();
            } catch (Exception exc) {
            }
        }
    });

    label = new Label(container, SWT.NULL);
    label.setText("&Package:");
    packageText = new Text(container, SWT.BORDER | SWT.SINGLE);
    packageText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });
    gd = new GridData();
    gd.widthHint = 250;
    packageText.setLayoutData(gd);

    packageButton = new Button(container, SWT.NATIVE);
    packageButton.setText("Browse");
    packageButton.addMouseListener(new MouseListener() {
        public void mouseDown(MouseEvent e) {
            if (null != project) {
                try {
                    IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope();
                    SelectionDialog sd = JavaUI.createPackageDialog(getShell(), project,
                            IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS);
                    sd.open();
                    Object[] objects = sd.getResult();
                    if (null != objects && objects.length > 0) {
                        IPackageFragment pf = (IPackageFragment) objects[0];
                        packageText.setText(pf.getElementName());
                    }
                } catch (JavaModelException jme) {
                    jme.printStackTrace();
                }
            }
        }

        public void mouseDoubleClick(MouseEvent e) {
        }

        public void mouseUp(MouseEvent e) {
        }

    });

    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() == 1) {
            Object obj = ssel.getFirstElement();
            if (obj instanceof IResource) {
                IContainer cont;
                if (obj instanceof IContainer)
                    cont = (IContainer) obj;
                else
                    cont = ((IResource) obj).getParent();
                containerText.setText(cont.getFullPath().toString());
                projectChanged(cont.getProject());
            } else if (obj instanceof IPackageFragment) {
                IPackageFragment frag = (IPackageFragment) obj;
                containerText.setText(frag.getPath().toString());
                projectChanged(frag.getJavaProject().getProject());
            } else if (obj instanceof IPackageFragmentRoot) {
                IPackageFragmentRoot root = (IPackageFragmentRoot) obj;
                containerText.setText(root.getPath().toString());
                projectChanged(root.getJavaProject().getProject());
            } else if (obj instanceof IJavaProject) {
                IJavaProject proj = (IJavaProject) obj;
                containerText.setText("/" + proj.getProject().getName());
                projectChanged(proj.getProject());
            } else if (obj instanceof IProject) {
                IProject proj = (IProject) obj;
                containerText.setText("/" + proj.getName());
                projectChanged(proj);
            }
        }
    }

    containerText.forceFocus();
    initialize();
    dialogChanged();
    return container;
}

From source file:com.ibm.research.tours.content.url.delegates.ClassFileURLTourElementDelegate.java

License:Open Source License

private void init() {
    IPackageFragmentRoot root = null;
    root = JavaModelUtil.getPackageFragmentRoot(fFile);

    String[] entries = JavaCore.getClasspathVariableNames();
    ArrayList elements = new ArrayList(entries.length);

    for (int i = 0; i < entries.length; i++) {
        String name = entries[i];
        IPath entryPath = JavaCore.getClasspathVariable(name);
        IPath fullPath = root.getPath();

        if (entryPath != null) {
            if (entryPath.isPrefixOf(fullPath)) {
                int matchingSegments = fullPath.matchingFirstSegments(entryPath);
                int numSegments = fullPath.segmentCount();
                String[] segments = fullPath.segments();
                String path = name + Path.SEPARATOR;

                for (int j = matchingSegments; j < numSegments; j++) {
                    path = path + segments[j];

                    if (j != numSegments - 1)
                        path = path + Path.SEPARATOR;
                }/*  w ww .  j a  va2  s. c o  m*/
                break;
            }
        }
    }

}

From source file:com.ifedorenko.m2e.sourcelookup.internal.JavaProjectSources.java

License:Open Source License

private void addJavaProject(IJavaProject project) throws CoreException {
    if (project != null) {
        final Map<File, IPackageFragmentRoot> classpath = new LinkedHashMap<File, IPackageFragmentRoot>();
        for (IPackageFragmentRoot fragment : project.getPackageFragmentRoots()) {
            if (fragment.getKind() == IPackageFragmentRoot.K_BINARY
                    && fragment.getSourceAttachmentPath() != null) {
                File classpathLocation;
                if (fragment.isExternal()) {
                    classpathLocation = fragment.getPath().toFile();
                } else {
                    classpathLocation = toFile(fragment.getPath());
                }/*from  ww w.ja va 2  s. co  m*/
                if (classpathLocation != null) {
                    classpath.put(classpathLocation, fragment);
                }
            }
        }

        final JavaProjectInfo projectInfo = new JavaProjectInfo(project, classpath);

        final Set<File> projectLocations = new HashSet<File>();

        final String jarLocation = project.getProject().getPersistentProperty(BinaryProjectPlugin.QNAME_JAR);
        if (jarLocation != null) {
            // maven binary project
            projectLocations.add(new File(jarLocation));
        } else {
            // regular project
            projectLocations.add(toFile(project.getOutputLocation()));
            for (IClasspathEntry cpe : project.getRawClasspath()) {
                if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    projectLocations.add(toFile(cpe.getOutputLocation()));
                }
            }
        }

        synchronized (lock) {
            projects.put(project, projectLocations);
            for (File projectLocation : projectLocations) {
                locations.put(projectLocation, projectInfo);
            }
        }
    }
}

From source file:com.iw.plugins.spindle.core.util.CoreUtils.java

License:Mozilla Public License

/**
 * Returns true if the element is on the build path of the given project
 *//*www.j a  v  a 2  s .  com*/
public static boolean isOnBuildPath(IJavaProject jproject, IJavaElement element) throws JavaModelException {
    IPath rootPath;
    if (element.getElementType() == IJavaElement.JAVA_PROJECT) {
        rootPath = ((IJavaProject) element).getProject().getFullPath();
    } else {
        IPackageFragmentRoot root = getPackageFragmentRoot(element);
        if (root == null) {
            return false;
        }
        rootPath = root.getPath();
    }
    return jproject.findPackageFragmentRoot(rootPath) != null;
}