1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.eclipse.org/org/documents/epl-v10.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.ide.eclipse.ndk.internal.launch;
18
19import com.android.ide.eclipse.adt.internal.launch.MainLaunchConfigTab;
20import com.android.ide.eclipse.adt.internal.project.ProjectChooserHelper.IProjectChooserFilter;
21import com.android.ide.eclipse.adt.internal.sdk.ProjectState;
22import com.android.ide.eclipse.adt.internal.sdk.Sdk;
23
24import org.eclipse.cdt.core.model.CoreModel;
25import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
26import org.eclipse.core.resources.IProject;
27import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
28
29@SuppressWarnings("restriction")
30public class NdkMainLaunchConfigTab extends MainLaunchConfigTab {
31    private static class NdkProjectOnlyFilter implements IProjectChooserFilter {
32        @Override
33        public boolean accept(IProject project) {
34            ProjectState state = Sdk.getProjectState(project);
35            if (state == null) {
36                return false;
37            }
38
39            return !state.isLibrary()
40                    && (CoreModel.hasCCNature(project) || CoreModel.hasCNature(project));
41        }
42
43        @Override
44        public boolean useCache() {
45            return true;
46        }
47    }
48
49    @Override
50    protected IProjectChooserFilter getProjectFilter() {
51        return new NdkProjectOnlyFilter();
52    }
53
54    @Override
55    public void performApply(ILaunchConfigurationWorkingCopy configuration) {
56        super.performApply(configuration);
57
58        configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME,
59                mProjText.getText().trim());
60    }
61}
62