Example usage for org.eclipse.jdt.internal.core JarPackageFragmentRoot getElementName

List of usage examples for org.eclipse.jdt.internal.core JarPackageFragmentRoot getElementName

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core JarPackageFragmentRoot getElementName.

Prototype

@Override
    public String getElementName() 

Source Link

Usage

From source file:org.eclipse.ajdt.internal.ui.lazystart.ImageDecorator.java

License:Open Source License

/**
 * @see ILabelDecorator#decorateImage/* ww w  .ja  v  a2  s  . c  om*/
 */
public Image decorateImage(Image image, Object element) {
    if (preventRecursion)
        return null;

    // only run the decorator if the bundle is already active
    if (!Utils.isBundleActive()) {
        return null;
    }

    Image img = null;
    if (element instanceof ICompilationUnit) {
        ICompilationUnit comp = (ICompilationUnit) element;
        IFile file = null;
        try {
            file = (IFile) comp.getCorrespondingResource();
        } catch (JavaModelException e) {
        }
        if (file != null) {
            if (comp instanceof AJCompilationUnit) {
                if (BuildConfig.isIncluded(file)) {
                    Rectangle rect = image.getBounds();
                    img = getImageLabel(
                            getJavaImageDescriptor(AspectJImages.ASPECTJ_FILE.getImageDescriptor(), rect, 0));
                } else {
                    Rectangle rect = image.getBounds();
                    img = getImageLabel(getJavaImageDescriptor(
                            AspectJImages.EXCLUDED_ASPECTJ_FILE.getImageDescriptor(), rect, 0));
                }
            }
        }
    } else if (element instanceof IFile) {
        IFile file = (IFile) element;
        if (file.getFileExtension() != null) {
            if (file.getFileExtension().equals(AJProperties.EXTENSION)) {
                img = getImageLabel(((AJDTIcon) AspectJImages.BC_FILE).getImageDescriptor());
            } else if (file.getFileExtension().equals("jar") || file.getFileExtension().equals("zip")) { //$NON-NLS-1$ //$NON-NLS-2$
                // TODO: decorate out-jars?
            } else if (file.getFileExtension().equals("xml")) {
                // maybe this is an aop.xml that is part of the build config
                if (new AopXmlPreferences(file.getProject()).isAopXml(file)) {
                    img = getImageLabel(((AJDTIcon) AspectJImages.AOP_XML).getImageDescriptor());
                }
            }
        }
    } else if (element instanceof JarPackageFragmentRoot) {
        JarPackageFragmentRoot root = (JarPackageFragmentRoot) element;
        try {
            IClasspathEntry entry = root.getRawClasspathEntry();
            if (entry != null) {
                IResource resource = root.getResource();
                String name = resource == null ? root.getElementName() : resource.getName();
                if (AspectJCorePreferences.isOnAspectpathWithRestrictions(entry, name)) {
                    img = getImageLabel(AspectJImages.JAR_ON_ASPECTPATH.getImageDescriptor());
                } else if (AspectJCorePreferences.isOnInpathWithRestrictions(entry, name)) {
                    img = getImageLabel(AspectJImages.JAR_ON_INPATH.getImageDescriptor());
                }
            }
        } catch (JavaModelException e1) {
        }
    } else if (element instanceof AJCodeElement) {
        img = getImageLabel(AspectJImages.AJ_CODE.getImageDescriptor());
    } else if (element instanceof IAspectJElement) {
        try {
            IAspectJElement ajElem = (IAspectJElement) element;
            if (ajElem.getJavaProject().getProject().exists()) {
                IProgramElement.Accessibility acceb = ajElem.getAJAccessibility();
                AJDTIcon icon = null;
                if (acceb == null) {
                    if (ajElem instanceof AdviceElement) {
                        boolean hasTest = AJProjectModelFactory.getInstance().getModelForJavaElement(ajElem)
                                .hasRuntimeTest(ajElem);
                        icon = (AJDTIcon) AspectJImages.instance().getAdviceIcon(ajElem.getAJExtraInformation(),
                                hasTest);
                    } else if (ajElem instanceof IntertypeElement) {
                        icon = (AJDTIcon) AspectJImages.instance().getStructureIcon(ajElem.getAJKind(),
                                ajElem.getAJAccessibility());
                    } else if (ajElem instanceof DeclareElement) {
                        icon = (AJDTIcon) AspectJImages.instance().getStructureIcon(ajElem.getAJKind(),
                                ajElem.getAJAccessibility());
                    } else {
                        icon = (AJDTIcon) AspectJImages.instance().getIcon(ajElem.getAJKind());
                    }
                } else {
                    icon = (AJDTIcon) AspectJImages.instance().getStructureIcon(ajElem.getAJKind(),
                            ajElem.getAJAccessibility());
                }
                if (icon != null) {
                    img = getImageLabel(getJavaImageDescriptor(icon.getImageDescriptor(), image.getBounds(),
                            computeJavaAdornmentFlags(ajElem)));
                }
            }
        } catch (JavaModelException e) {
        }
    }

    if (img != null) {
        preventRecursion = true;

        //the Java ProblemsDecorator is not registered in the official
        //decorator list of eclipse, so we need it to call ourself.
        //problem: if jdt includes more decorators, we won't know it.
        img = problemsDecorator.decorateImage(img, element);

        //apply standard decorators (eg cvs)
        img = decman.decorateImage(img, element);
        preventRecursion = false;
        return img;
    }
    return null;
}

From source file:org.eclipse.jst.jee.ui.internal.navigator.dnd.AddProjectToEARDropAssistant.java

License:Open Source License

@Override
public IStatus validateDrop(Object target, int operation, TransferData transferType) {
    libDir = ""; //$NON-NLS-1$
    if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)
            || PluginTransfer.getInstance().isSupportedType(transferType)) {
        ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
        if (selection != null && !selection.isEmpty() && (selection instanceof IStructuredSelection)) {
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            earProject = getProject(target);
            if (earProject == null) {
                return Status.CANCEL_STATUS;
            }/* ww w . jav a2 s. c  o m*/
            earComponent = ComponentCore.createComponent(earProject);
            int earVersion = getEarVersion(earProject);
            if (target instanceof BundledNode && ((BundledNode) target).getBundledLibsDirectoryNode() == null) {
                libDir = EarUtilities.getEARLibDir(earComponent);
            }

            IStatus status = null;
            for (Iterator iterator = structuredSelection.iterator(); iterator.hasNext();) {
                Object next = iterator.next();

                //check if library is physically present in the Ear path
                if (IVirtualReference.class.isInstance(next)) {
                    IVirtualComponent referencedComponent = ((IVirtualReference) next).getReferencedComponent();
                    if (referencedComponent.isBinary() && isPhysicallyAdded(referencedComponent)) {
                        return Status.CANCEL_STATUS;
                    }
                }

                if (next instanceof IVirtualReference) {
                    return Status.OK_STATUS;
                }

                /*
                 * Check if we try to add a JarPackageFragment that is
                 * already referenced
                 */
                if (next instanceof JarPackageFragmentRoot) {
                    JarPackageFragmentRoot jar = (JarPackageFragmentRoot) next;
                    for (IVirtualReference reference : earComponent.getReferences()) {
                        if (reference.getArchiveName().equals(jar.getElementName())) {
                            return Status.CANCEL_STATUS;
                        }
                    }
                    return Status.OK_STATUS;
                }

                /*
                 * Check if we try to add a module that is already
                 * referenced by the ear but at the same time allow to
                 * change its location from the root to the lib directory
                 * and the opposite.
                 */
                IProject projectToAdd = getProject(next);
                hasConflictingProjectInMetaInf(ComponentCore.createComponent(projectToAdd));
                try {
                    for (IProject referencedProject : earProject.getReferencedProjects()) {
                        if (referencedProject == projectToAdd) {
                            return Status.CANCEL_STATUS;
                        }
                    }
                } catch (CoreException e) {
                    String msg = e.getMessage() != null ? e.getMessage() : e.toString();
                    status = J2EENavigatorPlugin.createErrorStatus(0, msg, e);
                }

                if ((status = validateProjectMayBeAdded(earProject, projectToAdd, earVersion)).isOK())
                    return status;
            }
        }

    }
    return Status.CANCEL_STATUS;
}