diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/IndexUpdatePolicy.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/IndexUpdatePolicy.java index c874c7de3e2..b69a87f807c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/IndexUpdatePolicy.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/IndexUpdatePolicy.java @@ -18,12 +18,13 @@ import org.eclipse.cdt.core.dom.IPDOMIndexerTask; import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; +import org.eclipse.cdt.internal.core.pdom.indexer.PDOMUpdateTask; public class IndexUpdatePolicy { - - public static final int POST_CHANGE = 0; - public static final int POST_BUILD = 1; - public static final int MANUAL= 2; + public static final int POST_CHANGE= IndexerPreferences.UPDATE_POLICY_IMMEDIATE; + public static final int POST_BUILD= IndexerPreferences.UPDATE_POLICY_LAZY; + public static final int MANUAL= IndexerPreferences.UPDATE_POLICY_MANUAL; private final ICProject fCProject; private int fKind; @@ -35,20 +36,55 @@ public class IndexUpdatePolicy { public IndexUpdatePolicy(ICProject project, int kind) { fCProject= project; - fKind= kind; + fKind= getLegalPolicy(kind); + } + + private int getLegalPolicy(int kind) { + switch(kind) { + case POST_BUILD: + case POST_CHANGE: + case MANUAL: + return kind; + } + return POST_CHANGE; } public ICProject getProject() { return fCProject; } - public int getKind() { - return fKind; + public void clearTUs() { + fAdded.clear(); + fChanged.clear(); + fRemoved.clear(); } - - public IPDOMIndexerTask addDelta(ITranslationUnit[] added, ITranslationUnit[] changed, - ITranslationUnit[] removed) { - if (fIndexer != null && fIndexer.getID().equals(IPDOMManager.ID_NO_INDEXER)) { + + public boolean hasTUs() { + return !(fAdded.isEmpty() && fChanged.isEmpty() && fRemoved.isEmpty()); + } + + private ITranslationUnit[] getAdded() { + return (ITranslationUnit[]) fAdded.toArray(new ITranslationUnit[fAdded.size()]); + } + + private ITranslationUnit[] getChanged() { + return (ITranslationUnit[]) fChanged.toArray(new ITranslationUnit[fChanged.size()]); + } + + private ITranslationUnit[] getRemoved() { + return (ITranslationUnit[]) fRemoved.toArray(new ITranslationUnit[fRemoved.size()]); + } + + public void setIndexer(IPDOMIndexer indexer) { + fIndexer= indexer; + } + + public IPDOMIndexer getIndexer() { + return fIndexer; + } + + public IPDOMIndexerTask handleDelta(ITranslationUnit[] added, ITranslationUnit[] changed, ITranslationUnit[] removed) { + if (isNullIndexer()) { return null; } @@ -84,45 +120,39 @@ public class IndexUpdatePolicy { } return null; } - - public void clearTUs() { - fAdded.clear(); - fChanged.clear(); - fRemoved.clear(); - } - - public boolean hasTUs() { - return !(fAdded.isEmpty() && fChanged.isEmpty() && fRemoved.isEmpty()); - } - + public IPDOMIndexerTask createTask() { + IPDOMIndexerTask task= null; if (fIndexer != null && hasTUs()) { - if (getKind() != IndexUpdatePolicy.MANUAL && - !fIndexer.getID().equals(IPDOMManager.ID_NO_INDEXER)) { - return fIndexer.createTask(getAdded(), getChanged(), getRemoved()); + if (fKind != IndexUpdatePolicy.MANUAL && !isNullIndexer()) { + task= fIndexer.createTask(getAdded(), getChanged(), getRemoved()); } clearTUs(); } - return null; + return task; } - private ITranslationUnit[] getAdded() { - return (ITranslationUnit[]) fAdded.toArray(new ITranslationUnit[fAdded.size()]); + private boolean isNullIndexer() { + return fIndexer != null && fIndexer.getID().equals(IPDOMManager.ID_NO_INDEXER); } - private ITranslationUnit[] getChanged() { - return (ITranslationUnit[]) fChanged.toArray(new ITranslationUnit[fChanged.size()]); - } - - private ITranslationUnit[] getRemoved() { - return (ITranslationUnit[]) fRemoved.toArray(new ITranslationUnit[fRemoved.size()]); - } - - public void setIndexer(IPDOMIndexer indexer) { - fIndexer= indexer; - } - - public IPDOMIndexer getIndexer() { - return fIndexer; + public IPDOMIndexerTask changePolicy(int updatePolicy) { + int oldPolicy= fKind; + fKind= getLegalPolicy(updatePolicy); + + IPDOMIndexerTask task= null; + if (fKind == MANUAL || isNullIndexer()) { + clearTUs(); + } + else if (fIndexer != null) { + if (oldPolicy == MANUAL) { + task= new PDOMUpdateTask(fIndexer, true); + clearTUs(); + } + else if (fKind == POST_CHANGE) { + task= createTask(); + } + } + return task; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java index cf59b037f71..cb5d769785b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java @@ -66,6 +66,7 @@ import org.eclipse.cdt.internal.core.pdom.indexer.nulli.PDOMNullIndexer; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -169,7 +170,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { initializeDatabaseCache(); final CoreModel model = CoreModel.getDefault(); - ResourcesPlugin.getWorkspace().addResourceChangeListener(fCModelListener); + ResourcesPlugin.getWorkspace().addResourceChangeListener(fCModelListener, IResourceChangeEvent.POST_BUILD); model.addElementChangedListener(fCModelListener); LanguageManager.getInstance().registerLanguageChangeListener(fLanguageChangeListener); @@ -349,13 +350,31 @@ public class PDOMManager implements IWritableIndexManager, IListener { } protected void onPreferenceChange(ICProject cproject, PreferenceChangeEvent event) { - IProject project= cproject.getProject(); - if (project.exists() && project.isOpen()) { - try { - changeIndexer(cproject); + if (IndexerPreferences.KEY_UPDATE_POLICY.equals(event.getKey())) { + changeUpdatePolicy(cproject); + } + else { + IProject project= cproject.getProject(); + if (project.exists() && project.isOpen()) { + try { + changeIndexer(cproject); + } + catch (Exception e) { + CCorePlugin.log(e); + } } - catch (Exception e) { - CCorePlugin.log(e); + } + } + + private void changeUpdatePolicy(ICProject cproject) { + assert !Thread.holdsLock(fProjectToPDOM); + synchronized (fUpdatePolicies) { + IndexUpdatePolicy policy= getPolicy(cproject); + if (policy != null) { + IPDOMIndexerTask task= policy.changePolicy(IndexerPreferences.getUpdatePolicy(cproject.getProject())); + if (task != null) { + enqueue(task); + } } } } @@ -622,7 +641,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { if (added.length > 0 || changed.length > 0 || removed.length > 0) { synchronized (fUpdatePolicies) { IndexUpdatePolicy policy= createPolicy(project); - IPDOMIndexerTask task= policy.addDelta(added, changed, removed); + IPDOMIndexerTask task= policy.handleDelta(added, changed, removed); if (task != null) { enqueue(task); } @@ -710,6 +729,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { IndexUpdatePolicy policy= getPolicy(project); if (policy != null) { if (policy.getIndexer() == indexer) { + policy.clearTUs(); policy.setIndexer(null); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerPreferences.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerPreferences.java index 8394ac311a7..24efd1e4a82 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerPreferences.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerPreferences.java @@ -41,15 +41,19 @@ public class IndexerPreferences { public static final int SCOPE_PROJECT_PRIVATE = 1; public static final int SCOPE_PROJECT_SHARED = 2; + public static final int UPDATE_POLICY_IMMEDIATE= 0; + public static final int UPDATE_POLICY_LAZY= 1; + public static final int UPDATE_POLICY_MANUAL= 2; + public static final String KEY_INDEXER_ID= "indexerId"; //$NON-NLS-1$ public static final String KEY_INDEX_ALL_FILES= "indexAllFiles"; //$NON-NLS-1$ public static final String KEY_FILES_TO_PARSE_UP_FRONT= "filesToParseUpFront"; //$NON-NLS-1$ public static final String KEY_SKIP_ALL_REFERENCES= "skipReferences"; //$NON-NLS-1$ public static final String KEY_SKIP_TYPE_REFERENCES= "skipTypeReferences"; //$NON-NLS-1$ + public static final String KEY_UPDATE_POLICY= "updatePolicy"; //$NON-NLS-1$ private static final String KEY_INDEXER_PREFS_SCOPE = "preferenceScope"; //$NON-NLS-1$ private static final String KEY_INDEX_IMPORT_LOCATION = "indexImportLocation"; //$NON-NLS-1$ - private static final String KEY_UPDATE_POLICY= "updatePolicy"; //$NON-NLS-1$ private static final String DEFAULT_INDEX_IMPORT_LOCATION = ".settings/cdt-index.zip"; //$NON-NLS-1$ private static final String DEFAULT_FILES_TO_PARSE_UP_FRONT= "stdarg.h, stddef.h, sys/types.h"; //$NON-NLS-1$ @@ -120,6 +124,24 @@ public class IndexerPreferences { return scope; } + /** + * Sets the scope that shall be used for the project. + * Must be one of {@link #UPDATE_POLICY_IMMEDIATE}, {@link #UPDATE_POLICY_LAZY} or + * {@link #UPDATE_POLICY_MANUAL}. + */ + public static void setUpdatePolicy(IProject project, int policy) { + switch (policy) { + case UPDATE_POLICY_IMMEDIATE: + case UPDATE_POLICY_LAZY: + case UPDATE_POLICY_MANUAL: + break; + default: + throw new IllegalArgumentException(); + } + // no support for project specific policies. + getInstancePreferences().put(KEY_UPDATE_POLICY, String.valueOf(policy)); + } + /** * Returns the properties for the indexer of a project. */ @@ -146,7 +168,14 @@ public class IndexerPreferences { addProperties(prefs, props); return props; } - + + public static int getDefaultUpdatePolicy() { + Preferences[] prefs = new Preferences[] { + getDefaultPreferences() + }; + return getUpdatePolicy(prefs); + } + /** * Adds or changes indexer properties for a project. */ @@ -350,22 +379,12 @@ public class IndexerPreferences { } public static int getUpdatePolicy(IProject project) { - Preferences[] prefs; - if (project != null) { - prefs= new Preferences[] { - getProjectPreferences(project), - getInstancePreferences(), - getConfigurationPreferences(), - getDefaultPreferences() - }; - } - else { - prefs= new Preferences[] { - getInstancePreferences(), - getConfigurationPreferences(), - getDefaultPreferences() - }; - } + // no support for project specific policies + Preferences[] prefs= getPreferences(null); + return getUpdatePolicy(prefs); + } + + private static int getUpdatePolicy(Preferences[] prefs) { String val= Platform.getPreferencesService().get(KEY_UPDATE_POLICY, null, prefs); if (val != null) { try { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/IndexerPreferencePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/IndexerPreferencePage.java index 5558408a098..0a59ac86289 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/IndexerPreferencePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/IndexerPreferencePage.java @@ -27,25 +27,30 @@ import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.cdt.ui.dialogs.CacheSizeBlock; import org.eclipse.cdt.ui.dialogs.ICOptionContainer; import org.eclipse.cdt.ui.dialogs.IndexerBlock; +import org.eclipse.cdt.ui.dialogs.IndexerStrategyBlock; public class IndexerPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, ICOptionContainer { private IndexerBlock fOptionBlock; private CacheSizeBlock fCacheBlock; + private IndexerStrategyBlock fStrategyBlock; public IndexerPreferencePage(){ fOptionBlock = new IndexerBlock(); + fStrategyBlock= new IndexerStrategyBlock(this); fCacheBlock= new CacheSizeBlock(this); } protected Control createContents(Composite parent) { + GridLayout gl; Composite composite = new Composite(parent, SWT.NONE); - composite.setLayout(new GridLayout()); - GridData gd= new GridData(); - composite.setLayoutData(gd); + composite.setLayout(gl= new GridLayout()); + composite.setLayoutData(new GridData()); + gl.verticalSpacing= 0; fOptionBlock.createControl(composite); + fStrategyBlock.createControl(composite); fCacheBlock.createControl(composite); return composite; @@ -59,6 +64,10 @@ public class IndexerPreferencePage extends PreferencePage implements setErrorMessage(fOptionBlock.getErrorMessage()); setValid(false); } + else if (!fStrategyBlock.isValid()) { + setErrorMessage(fStrategyBlock.getErrorMessage()); + setValid(false); + } else if (!fCacheBlock.isValid()) { setErrorMessage(fCacheBlock.getErrorMessage()); setValid(false); @@ -80,6 +89,7 @@ public class IndexerPreferencePage extends PreferencePage implements public boolean performOk() { try { fOptionBlock.performApply(new NullProgressMonitor()); + fStrategyBlock.performApply(new NullProgressMonitor()); fCacheBlock.performApply(new NullProgressMonitor()); } catch (CoreException e) {} return true; @@ -87,6 +97,8 @@ public class IndexerPreferencePage extends PreferencePage implements public void performDefaults() { fOptionBlock.performDefaults(); + fStrategyBlock.performDefaults(); fCacheBlock.performDefaults(); + updateContainer(); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/CacheSizeBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/CacheSizeBlock.java index c0ceee2e39a..79b74569fad 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/CacheSizeBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/CacheSizeBlock.java @@ -67,24 +67,24 @@ public class CacheSizeBlock extends AbstractCOptionPage { setControl(composite); - Group group= ControlFactory.createGroup(composite, Messages.CacheSizeBlock_cacheLimitGroup, 1); + Group group= ControlFactory.createGroup(composite, DialogsMessages.CacheSizeBlock_cacheLimitGroup, 1); gd= (GridData) group.getLayoutData(); gd.grabExcessHorizontalSpace= true; gd.horizontalAlignment= GridData.FILL; Composite cacheComp= ControlFactory.createComposite(group, 3); - Label dbCacheLabel= ControlFactory.createLabel(cacheComp, Messages.CacheSizeBlock_indexDatabaseCache); - fDBLimitPct= new IntegerFieldEditor(CCorePreferenceConstants.INDEX_DB_CACHE_SIZE_PCT, Messages.CacheSizeBlock_limitRelativeToMaxHeapSize, cacheComp, 3); + Label dbCacheLabel= ControlFactory.createLabel(cacheComp, DialogsMessages.CacheSizeBlock_indexDatabaseCache); + fDBLimitPct= new IntegerFieldEditor(CCorePreferenceConstants.INDEX_DB_CACHE_SIZE_PCT, DialogsMessages.CacheSizeBlock_limitRelativeToMaxHeapSize, cacheComp, 3); fDBLimitPct.setValidRange(1, 40); ControlFactory.createLabel(cacheComp, "%"); //$NON-NLS-1$ - fDBAbsoluteLimit= new IntegerFieldEditor(CCorePreferenceConstants.MAX_INDEX_DB_CACHE_SIZE_MB, Messages.CacheSizeBlock_absoluteLimit, cacheComp, 4); + fDBAbsoluteLimit= new IntegerFieldEditor(CCorePreferenceConstants.MAX_INDEX_DB_CACHE_SIZE_MB, DialogsMessages.CacheSizeBlock_absoluteLimit, cacheComp, 4); fDBAbsoluteLimit.setValidRange(1, 10000); ControlFactory.createLabel(cacheComp, "mb"); //$NON-NLS-1$ - Label codeReaderLabel= ControlFactory.createLabel(cacheComp, Messages.CacheSizeBlock_headerFileCache); - fCodeReaderLimit= new IntegerFieldEditor(CodeReaderCache.CODE_READER_BUFFER, Messages.CacheSizeBlock_absoluteLimit, cacheComp, 4); + Label codeReaderLabel= ControlFactory.createLabel(cacheComp, DialogsMessages.CacheSizeBlock_headerFileCache); + fCodeReaderLimit= new IntegerFieldEditor(CodeReaderCache.CODE_READER_BUFFER, DialogsMessages.CacheSizeBlock_absoluteLimit, cacheComp, 4); fCodeReaderLimit.setValidRange(1, 10000); ControlFactory.createLabel(cacheComp, "mb"); //$NON-NLS-1$ @@ -92,6 +92,7 @@ public class CacheSizeBlock extends AbstractCOptionPage { gl.numColumns= 3; gl.makeColumnsEqualWidth= false; gl.marginLeft= 0; + gl.verticalSpacing= 2; gd= (GridData) dbCacheLabel.getLayoutData(); gd.horizontalSpan= 3; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.java index 11f8671989a..da737be9a1a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.java @@ -19,9 +19,21 @@ public class DialogsMessages extends NLS { public static String AbstractIndexerPage_indexUpFront; public static String AbstractIndexerPage_skipAllReferences; public static String AbstractIndexerPage_skipTypeReferences; + public static String IndexerStrategyBlock_activeBuildConfig; + public static String IndexerStrategyBlock_autoUpdate; + public static String IndexerStrategyBlock_buildConfigGroup; + public static String IndexerStrategyBlock_immediateUpdate; + public static String IndexerStrategyBlock_specificBuildConfig; + public static String IndexerStrategyBlock_strategyGroup; public static String PreferenceScopeBlock_enableProjectSettings; public static String PreferenceScopeBlock_preferenceLink; public static String PreferenceScopeBlock_storeWithProject; + public static String CacheSizeBlock_absoluteLimit; + public static String CacheSizeBlock_cacheLimitGroup; + public static String CacheSizeBlock_headerFileCache; + public static String CacheSizeBlock_indexDatabaseCache; + public static String CacheSizeBlock_limitRelativeToMaxHeapSize; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, DialogsMessages.class); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.properties index 85b88284abe..dd8e0bb380b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.properties @@ -15,3 +15,14 @@ AbstractIndexerPage_indexAllFiles=Index all files (files neither built nor inclu AbstractIndexerPage_skipAllReferences=Skip all references (Call Hierarchy and Search will not work) AbstractIndexerPage_skipTypeReferences=Skip type references (Search for type references will not work) AbstractIndexerPage_indexUpFront=Files to index up-front: +CacheSizeBlock_cacheLimitGroup=Cache limits +CacheSizeBlock_indexDatabaseCache=Index database cache: +CacheSizeBlock_limitRelativeToMaxHeapSize=Limit relative to the maximum heap size: +CacheSizeBlock_absoluteLimit=Absolute Limit: +CacheSizeBlock_headerFileCache=Header file cache (used by full indexer and refactoring): +IndexerStrategyBlock_strategyGroup=Indexing strategy +IndexerStrategyBlock_autoUpdate=Automatically update the index +IndexerStrategyBlock_immediateUpdate=Update index immediately after every file-change +IndexerStrategyBlock_buildConfigGroup=Build configuration for the indexer +IndexerStrategyBlock_activeBuildConfig=Use active build configuration +IndexerStrategyBlock_specificBuildConfig=Use the build configuration specified in the project's indexer settings diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java index cbe730c9772..e3794e98958 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java @@ -120,7 +120,8 @@ public class IndexerBlock extends AbstractCOptionPage { GridLayout layout= ((GridLayout)composite.getLayout()); layout.marginWidth= 0; - composite.setLayoutData(null); + GridData gd= (GridData) composite.getLayoutData(); + gd.grabExcessHorizontalSpace= true; setControl(composite); if (getProject() != null || getContainer() instanceof ICOptionContainerExtension) { @@ -136,8 +137,8 @@ public class IndexerBlock extends AbstractCOptionPage { layout= (GridLayout)fPreferenceContent.getLayout(); layout.marginHeight= 0; layout.marginWidth= 0; - GridData gd= (GridData) fPreferenceContent.getLayoutData(); - gd.horizontalIndent= 0; + gd= (GridData) fPreferenceContent.getLayoutData(); + gd.horizontalIndent= 0; Composite isc = ControlFactory.createComposite(fPreferenceContent, 1); GridLayout gridLayout = ((GridLayout)isc.getLayout()); @@ -147,6 +148,8 @@ public class IndexerBlock extends AbstractCOptionPage { // add combo to select indexer Group group= ControlFactory.createGroup(isc,INDEXER_COMBO_LABEL, 1); + gd= (GridData) group.getLayoutData(); + gd.grabExcessHorizontalSpace= true; fIndexersComboBox = ControlFactory.createSelectCombo(group,"", ""); //$NON-NLS-1$ //$NON-NLS-2$ fIndexersComboBox.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { @@ -155,7 +158,7 @@ public class IndexerBlock extends AbstractCOptionPage { }); // add composite for pages - fIndexerPageComposite= ControlFactory.createComposite(fPreferenceContent, 1); + fIndexerPageComposite= ControlFactory.createComposite(group, 1); fIndexerPageComposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1)); fIndexerPageComposite.setLayout(new TabFolderLayout()); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java index 55dd1469bd9..4959ba2f7df 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerOptionPropertyPage.java @@ -19,7 +19,7 @@ import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Preferences; import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.PlatformUI; @@ -41,7 +41,7 @@ public class IndexerOptionPropertyPage extends PropertyPage implements ICOptionC protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); - composite.setLayout(new FillLayout()); + composite.setLayout(new GridLayout()); optionPage.createControl(composite); PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, ICHelpContextIds.PROJECT_INDEXER_PROPERTIES); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerStrategyBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerStrategyBlock.java new file mode 100644 index 00000000000..b6ea5a5d88e --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/IndexerStrategyBlock.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * 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.ui.dialogs; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +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.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); + } + + 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() { + 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); + +// 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); + +// fUseActiveBuildButton.setSelection(false); +// fUseFixedBuildConfig.setSelection(false); + + updateEnablement(); + } + + private void initUpdatePolicy(int updatePolicy) { + fAutoUpdateButton.setSelection(updatePolicy != IndexerPreferences.UPDATE_POLICY_MANUAL); + fImmediateUpdateButton.setSelection(updatePolicy == IndexerPreferences.UPDATE_POLICY_IMMEDIATE); + } + + 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); + } + + public void performDefaults() { + initUpdatePolicy(IndexerPreferences.getDefaultUpdatePolicy()); + updateEnablement(); + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/Messages.java deleted file mode 100644 index 9df9ff3a5fa..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/Messages.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * 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.ui.dialogs; - -import org.eclipse.osgi.util.NLS; - -public class Messages extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.cdt.ui.dialogs.messages"; //$NON-NLS-1$ - public static String CacheSizeBlock_absoluteLimit; - public static String CacheSizeBlock_cacheLimitGroup; - public static String CacheSizeBlock_headerFileCache; - public static String CacheSizeBlock_indexDatabaseCache; - public static String CacheSizeBlock_limitRelativeToMaxHeapSize; - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - } -} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/NullIndexerBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/NullIndexerBlock.java index 5ad6e760ddb..cb5e3649011 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/NullIndexerBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/NullIndexerBlock.java @@ -13,7 +13,7 @@ package org.eclipse.cdt.ui.dialogs; import java.util.Properties; -import org.eclipse.swt.SWT; +import org.eclipse.jface.dialogs.ControlEnableState; import org.eclipse.swt.widgets.Composite; @@ -23,8 +23,8 @@ import org.eclipse.swt.widgets.Composite; public class NullIndexerBlock extends AbstractIndexerPage { public void createControl(Composite parent) { - Composite comp = new Composite(parent, SWT.NULL); - setControl(comp); + super.createControl(parent); + ControlEnableState.disable(getControl()); } public Properties getProperties() { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/messages.properties deleted file mode 100644 index f332adbf629..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/messages.properties +++ /dev/null @@ -1,5 +0,0 @@ -CacheSizeBlock_cacheLimitGroup=Cache limits -CacheSizeBlock_indexDatabaseCache=Index database cache: -CacheSizeBlock_limitRelativeToMaxHeapSize=Limit relative to the maximum heap size: -CacheSizeBlock_absoluteLimit=Absolute Limit: -CacheSizeBlock_headerFileCache=Header file cache (used by full indexer and refactoring):