Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 101913ec98bc41aa3ac0de5b5c88fc908d329ec1 (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
138
139
140
141
142
143
144
145
146
147
148
149
150
/*******************************************************************************
 * Copyright (c) 2007 Wind River Systems, Inc. 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:
 *    Markus Schorn - initial API and implementation
 *******************************************************************************/ 
package org.eclipse.cdt.internal.ui.preferences;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;

import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionPreferences;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionWorkspacePreferences;
import org.eclipse.cdt.ui.dialogs.AbstractCOptionPage;
import org.eclipse.cdt.ui.dialogs.DialogsMessages;
import org.eclipse.cdt.ui.dialogs.ICOptionContainer;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;

import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;

/**
 * This OptionPage is used in the IndexerPreference page to allow for adjusting
 * various parsing related caches.
 */
public class IndexerStrategyBlock extends AbstractCOptionPage {

    private Button fAutoUpdateButton;
	private Button fImmediateUpdateButton;
	private Button fUseActiveBuildButton;
	private Button fUseFixedBuildConfig;

	public IndexerStrategyBlock(ICOptionContainer container){
    	setContainer(container);
    }

    @Override
	public void createControl(Composite parent) {
    	GridData gd;
    	GridLayout gl;
        Composite composite = ControlFactory.createComposite(parent, 1);
		gl=  (GridLayout)composite.getLayout();
		gl.marginWidth= 0;
		gl.verticalSpacing= gl.marginHeight*2;
		
		gd= (GridData) composite.getLayoutData();
		gd.grabExcessHorizontalSpace= false;
		gd.horizontalAlignment= GridData.FILL;

		setControl(composite);
      
		SelectionListener updateEnablement= new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				updateEnablement();
			}
		};

		Group group= ControlFactory.createGroup(composite, DialogsMessages.IndexerStrategyBlock_strategyGroup, 1);
		gd= (GridData) group.getLayoutData();
		gd.grabExcessHorizontalSpace= true;
		gd.horizontalAlignment= GridData.FILL;	
		fAutoUpdateButton= ControlFactory.createCheckBox(group, DialogsMessages.IndexerStrategyBlock_autoUpdate);
		fImmediateUpdateButton= ControlFactory.createCheckBox(group, DialogsMessages.IndexerStrategyBlock_immediateUpdate);
		fAutoUpdateButton.addSelectionListener(updateEnablement);
		
		if (IndexerPreferencePage.showBuildConfiguration()) {
			group= ControlFactory.createGroup(composite, DialogsMessages.IndexerStrategyBlock_buildConfigGroup, 1);
			gd= (GridData) group.getLayoutData();
			gd.grabExcessHorizontalSpace= true;
			gd.horizontalAlignment= GridData.FILL;
			fUseActiveBuildButton= ControlFactory.createRadioButton(group, DialogsMessages.IndexerStrategyBlock_activeBuildConfig, null, null);
			fUseFixedBuildConfig= ControlFactory.createRadioButton(group, DialogsMessages.IndexerStrategyBlock_specificBuildConfig, null, null);
		}		
		initializeValues();
    }

    protected void updateEnablement() {
    	fImmediateUpdateButton.setEnabled(fAutoUpdateButton.getSelection());
	}

	private void initializeValues() {
    	int updatePolicy= IndexerPreferences.getUpdatePolicy(null);
    	initUpdatePolicy(updatePolicy);

    	if (fUseActiveBuildButton != null) {
    		ICProjectDescriptionManager prjDescMgr= CCorePlugin.getDefault().getProjectDescriptionManager();
    		ICProjectDescriptionWorkspacePreferences prefs= prjDescMgr.getProjectDescriptionWorkspacePreferences(false);
    		boolean useActive= prefs.getConfigurationRelations() == ICProjectDescriptionPreferences.CONFIGS_LINK_SETTINGS_AND_ACTIVE;
    		fUseActiveBuildButton.setSelection(useActive);
    		fUseFixedBuildConfig.setSelection(!useActive);
    	}    	
    	updateEnablement();
	}

	private void initUpdatePolicy(int updatePolicy) {
		fAutoUpdateButton.setSelection(updatePolicy != IndexerPreferences.UPDATE_POLICY_MANUAL);
    	fImmediateUpdateButton.setSelection(updatePolicy == IndexerPreferences.UPDATE_POLICY_IMMEDIATE);
	}

	@Override
	public void performApply(IProgressMonitor monitor) throws CoreException {
		int updatePolicy;
		if (!fAutoUpdateButton.getSelection()) {
			updatePolicy= IndexerPreferences.UPDATE_POLICY_MANUAL;
		}
		else if (fImmediateUpdateButton.getSelection()) {
			updatePolicy= IndexerPreferences.UPDATE_POLICY_IMMEDIATE;
		}
		else {
			updatePolicy= IndexerPreferences.UPDATE_POLICY_LAZY;
		}			
		IndexerPreferences.setUpdatePolicy(null, updatePolicy);

    	if (fUseActiveBuildButton != null) {
    		boolean useActive= fUseActiveBuildButton.getSelection();
    		int relation=  useActive
    		? ICProjectDescriptionPreferences.CONFIGS_LINK_SETTINGS_AND_ACTIVE
    				: ICProjectDescriptionPreferences.CONFIGS_INDEPENDENT;
    		ICProjectDescriptionManager prjDescMgr= CCorePlugin.getDefault().getProjectDescriptionManager();
    		ICProjectDescriptionWorkspacePreferences prefs= prjDescMgr.getProjectDescriptionWorkspacePreferences(true);
    		prefs.setConfigurationRelations(relation);
    		prjDescMgr.setProjectDescriptionWorkspacePreferences(prefs, false, new NullProgressMonitor());
    	}
	}

    @Override
	public void performDefaults() {
    	initUpdatePolicy(IndexerPreferences.getDefaultUpdatePolicy());
    	if (fUseActiveBuildButton != null) {
    		fUseActiveBuildButton.setSelection(false);
    		fUseFixedBuildConfig.setSelection(true);
    	}
    	updateEnablement();
    }
}

Back to the top