Skip to main content
summaryrefslogtreecommitdiffstats
blob: bdf59299909db11c6b2c0e01596d2a19cac35c91 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*******************************************************************************
 * Copyright (c) 2003, 2007 IBM Corporation and others.
 * 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:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.common.project.facet;

import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jst.common.project.facet.core.JavaFacetInstallConfig;
import org.eclipse.jst.common.project.facet.core.JavaFacetInstallConfig.ChangeEvent;
import org.eclipse.wst.common.componentcore.datamodel.FacetInstallDataModelProvider;
import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
import org.eclipse.wst.common.project.facet.core.util.IEventListener;

public class JavaFacetInstallDataModelProvider extends FacetInstallDataModelProvider implements IJavaFacetInstallDataModelProperties {

    private final JavaFacetInstallConfig installConfig;
    
	public JavaFacetInstallDataModelProvider() 
	{
		this( new JavaFacetInstallConfig() );
	}
	
	public JavaFacetInstallDataModelProvider( final JavaFacetInstallConfig installConfig )
	{
	    this.installConfig = installConfig;
	}

	public Set getPropertyNames() 
	{
		Set propertyNames = super.getPropertyNames();
		propertyNames.add(JAVA_FACET_INSTALL_CONFIG);
		propertyNames.add(SOURCE_FOLDER_NAME);
        propertyNames.add(DEFAULT_OUTPUT_FOLDER_NAME);
		return propertyNames;
	}

    @Override
    public void init()
    {
        super.init();
        
        final IDataModel dm = getDataModel();
        
        dm.setProperty( FACET_ID, IModuleConstants.JST_JAVA );
        dm.setProperty( JAVA_FACET_INSTALL_CONFIG, this.installConfig );
        
        String sourceFolderName = null;
        
        if( ! this.installConfig.getSourceFolders().isEmpty() )
        {
            sourceFolderName = this.installConfig.getSourceFolders().get( 0 ).toPortableString();
        }
        
        dm.setProperty( SOURCE_FOLDER_NAME, sourceFolderName );
        
        String defaultOutputFolderName = null;
        
        if( this.installConfig.getDefaultOutputFolder() != null )
        {
            defaultOutputFolderName = this.installConfig.getDefaultOutputFolder().toPortableString();
        }
        
        dm.setProperty( DEFAULT_OUTPUT_FOLDER_NAME, defaultOutputFolderName );
        
        final IEventListener<JavaFacetInstallConfig.ChangeEvent> listener
            = new IEventListener<JavaFacetInstallConfig.ChangeEvent>()
        {
            public void handleEvent( final ChangeEvent event )
            {
                if( event.getType() == JavaFacetInstallConfig.ChangeEvent.Type.SOURCE_FOLDERS_CHANGED )
                {
                    String val = null;
                    
                    if( installConfig.getSourceFolders().size() > 0 )
                    {
                        val = installConfig.getSourceFolders().get( 0 ).toPortableString();
                    }
                    
                    dm.setProperty( SOURCE_FOLDER_NAME, val );
                }
                else if( event.getType() == JavaFacetInstallConfig.ChangeEvent.Type.DEFAULT_OUTPUT_FOLDER_CHANGED )
                {
                    final String val = installConfig.getDefaultOutputFolder().toPortableString();
                    dm.setProperty( DEFAULT_OUTPUT_FOLDER_NAME, val );
                }
            }
        };
        
        this.installConfig.addListener( listener );
    }
	
	public boolean propertySet( final String propertyName, 
	                            final Object propertyValue )
    {
        if( propertyName.equals( SOURCE_FOLDER_NAME ) )
        {
            final List<IPath> sourceFolders;
            
            if( propertyValue == null )
            {
                sourceFolders = Collections.emptyList();
            }
            else
            {
                sourceFolders = Collections.<IPath>singletonList( new Path( (String) propertyValue ) );
            }
            
            this.installConfig.setSourceFolders( sourceFolders );
            
            return true;
        }
        else if( propertyName.equals( DEFAULT_OUTPUT_FOLDER_NAME ) )
        {
            this.installConfig.setDefaultOutputFolder( new Path( (String) propertyValue ) );
            return true;
        }
        else if( propertyName.equals( JAVA_FACET_INSTALL_CONFIG ) )
        {
            return false;
        }
        
        return super.propertySet( propertyName, propertyValue );
    }

}

Back to the top