Skip to main content
summaryrefslogtreecommitdiffstats
blob: f3849aa785f03cf84e9733cc097583c381cc8870 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/******************************************************************************
 * Copyright (c) 2005 BEA Systems, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Konstantin Komissarchik - initial API and implementation
 ******************************************************************************/

package org.eclipse.jst.common.jdt.internal.classpath;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.ClasspathContainerInitializer;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;

/**
 * @author <a href="mailto:kosta@bea.com">Konstantin Komissarchik</a>
 */

public abstract class FlexibleProjectContainerInitializer 

    extends ClasspathContainerInitializer

{
    private static final ClasspathDecorationsManager decorations
        = FlexibleProjectContainer.getDecorationsManager();
    
    public boolean canUpdateClasspathContainer( final IPath containerPath, 
                                                final IJavaProject project) 
    {
        return true; 
    }

    public void requestClasspathContainerUpdate( final IPath containerPath, 
                                                 final IJavaProject project, 
                                                 final IClasspathContainer sg ) 
    
        throws CoreException
        
    {
        final String cid = containerPath.toString();
        final IClasspathEntry[] entries = sg.getClasspathEntries();
        
        decorations.clearAllDecorations( cid );
        
        for( int i = 0; i < entries.length; i++ )
        {
            final IClasspathEntry entry = entries[ i ];
            
            final IPath srcpath = entry.getSourceAttachmentPath();
            final IPath srcrootpath = entry.getSourceAttachmentRootPath();
            final IClasspathAttribute[] attrs = entry.getExtraAttributes();
            
            if( srcpath != null || attrs.length > 0 )
            {
                final String eid = entry.getPath().toString();
                final ClasspathDecorations dec = new ClasspathDecorations();
                
                dec.setSourceAttachmentPath( srcpath );
                dec.setSourceAttachmentRootPath( srcrootpath );
                dec.setExtraAttributes( attrs );
                
                decorations.setDecorations( cid, eid, dec );
            }
        }
        
        decorations.save();
        
        final IClasspathContainer container
            = JavaCore.getClasspathContainer( containerPath, project );
        
        ( (FlexibleProjectContainer) container ).refresh();
    }

}

Back to the top