Skip to main content
summaryrefslogtreecommitdiffstats
blob: 80b94a2aaa1b42310381c6c5737530e044fa37ad (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/******************************************************************************
 * 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.j2ee.ui.project.facet;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager;

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

public final class RuntimeMismatchMarkerResolutions

    implements IMarkerResolutionGenerator
    
{
    public IMarkerResolution[] getResolutions( final IMarker marker )
    {
        return new IMarkerResolution[] 
        { 
            new Resolution( marker, marker.getAttribute( "runtime1", null ) ), 
            new Resolution( marker, marker.getAttribute( "runtime2", null ) ) 
        };
    }
    
    private static final class Resolution
    
        implements IMarkerResolution
        
    {
        private final IMarker marker;
        private final String runtimeName;
        
        public Resolution( final IMarker marker,
                           final String runtimeName )
        {
            this.marker = marker;
            this.runtimeName = runtimeName;
        }
        
        public String getLabel()
        {
            return NLS.bind( Resources.useSameRuntime, this.runtimeName );
        }

        public void run( final IMarker marker )
        {
            final IRuntime runtime 
                = RuntimeManager.getRuntime( this.runtimeName );
            
            try
            {
                setRuntime( this.marker.getResource().getProject(), runtime );
                
                final String pjname 
                    = this.marker.getAttribute( "moduleProject", null );
                
                final IWorkspace ws = ResourcesPlugin.getWorkspace();
                final IProject pj = ws.getRoot().getProject( pjname );
                
                setRuntime( pj, runtime );
            }
            catch( CoreException e )
            {
                ErrorDialog.openError( null, Resources.errorDialogTitle,
                                       Resources.errorDialogMessage,
                                       e.getStatus() );
            }
        }
        
        private void setRuntime( final IProject proj,
                                 final IRuntime runtime )
        
            throws CoreException
            
        {
            final IFacetedProject fproj = ProjectFacetsManager.create( proj );
            
            if( ! fproj.getRuntime().equals( runtime ) )
            {
                fproj.setRuntime( runtime, null );
            }
        }
    }
    
    private static final class Resources
    
        extends NLS
        
    {
        public static String useSameRuntime;
        public static String errorDialogTitle;
        public static String errorDialogMessage;
        
        static
        {
            initializeMessages( RuntimeMismatchMarkerResolutions.class.getName(), 
                                Resources.class );
        }
    }
    
}

Back to the top