diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java index 8cbc114cc04..a14c49a1cb9 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2FileBasePluginTest.java @@ -72,7 +72,6 @@ public class AST2FileBasePluginTest extends TestCase { className = aClassName; numProjects++; } - CCorePlugin.getPDOMManager().setIndexerId(cPrj, IPDOMManager.ID_NO_INDEXER); } catch ( CoreException e ) { /*boo*/ } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java index 851cbbb91e6..844ecc385e4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java @@ -31,6 +31,7 @@ import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.TestScannerProvider; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.internal.core.CCoreInternals; +import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.ResourcesPlugin; @@ -79,11 +80,11 @@ public class IndexIncludeTest extends IndexTestBase { public void testFastIndexer() throws Exception { CCoreInternals.getPDOMManager().setIndexerId(fProject, IPDOMManager.ID_FAST_INDEXER); - CCoreInternals.getPDOMManager().setIndexAllFiles(fProject, false); + IndexerPreferences.set(fProject.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, "false"); waitForIndexer(); checkHeader(false); - CCoreInternals.getPDOMManager().setIndexAllFiles(fProject, true); + IndexerPreferences.set(fProject.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, "true"); waitForIndexer(); checkHeader(true); @@ -96,11 +97,11 @@ public class IndexIncludeTest extends IndexTestBase { public void testFullIndexer() throws Exception { CCoreInternals.getPDOMManager().setIndexerId(fProject, IPDOMManager.ID_FULL_INDEXER); - CCoreInternals.getPDOMManager().setIndexAllFiles(fProject, false); + IndexerPreferences.set(fProject.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, "false"); waitForIndexer(); checkHeader(false); - CCoreInternals.getPDOMManager().setIndexAllFiles(fProject, true); + IndexerPreferences.set(fProject.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, "true"); waitForIndexer(); checkHeader(true); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/TrilogyPerformanceTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/TrilogyPerformanceTest.java index 312c8254d34..ea3dc3f82ed 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/TrilogyPerformanceTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/TrilogyPerformanceTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Symbian Software Systems and others. + * Copyright (c) 2006, 2007 Symbian Software Systems 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 @@ -7,6 +7,7 @@ * * Contributors: * Andrew Ferguson (Symbian) - Initial implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.index.tests; @@ -19,7 +20,7 @@ import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.TestScannerProvider; -import org.eclipse.cdt.internal.core.CCoreInternals; +import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; import org.eclipse.cdt.utils.spawner.EnvironmentReader; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; @@ -55,7 +56,7 @@ public class TrilogyPerformanceTest extends IndexTestBase { assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); TestScannerProvider.sIncludes = new String[]{EnvironmentReader.getEnvVar("INETSDK")+"\\Include"}; try { - CCoreInternals.getPDOMManager().setIndexAllFiles(cproject, true); + IndexerPreferences.set(cproject.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, "true"); long start = System.currentTimeMillis(); CCorePlugin.getPDOMManager().reindex(cproject); assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); diff --git a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java index 2cdf1677f82..850d392a445 100644 --- a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java +++ b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 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 @@ -72,11 +72,7 @@ abstract public class BaseTestFramework extends TestCase { fileManager = new FileManager(); } } - - public void disableIndexing() throws CoreException { - CCorePlugin.getPDOMManager().setIndexerId(cproject, IPDOMManager.ID_NO_INDEXER); - } - + public BaseTestFramework() { super(); diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CProjectHelper.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CProjectHelper.java index 6707fe94410..81cb7ad8612 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CProjectHelper.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/CProjectHelper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 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 @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Andrew Ferguson (Symbian) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.testplugin; import java.io.File; @@ -32,6 +33,7 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.internal.core.CCoreInternals; +import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; @@ -94,7 +96,7 @@ public class CProjectHelper { } newProject[0] = CCorePlugin.getDefault().getCoreModel().create(project); if (indexerID != null) { - CCoreInternals.getPDOMManager().setIndexAllFiles(newProject[0], true); + IndexerPreferences.set(newProject[0].getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, "true"); CCoreInternals.getPDOMManager().setIndexerId(newProject[0], indexerID); } } diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index 2e9bd56e217..f4e309fb444 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -61,7 +61,7 @@ Export-Package: org.eclipse.cdt.core, org.eclipse.cdt.internal.core.pdom.dom;x-friends:="org.eclipse.cdt.ui", org.eclipse.cdt.internal.core.pdom.dom.c;x-internal:=true, org.eclipse.cdt.internal.core.pdom.dom.cpp;x-internal:=true, - org.eclipse.cdt.internal.core.pdom.indexer;x-internal:=true, + org.eclipse.cdt.internal.core.pdom.indexer;x-friends:="org.eclipse.cdt.ui", org.eclipse.cdt.internal.core.pdom.indexer.fast;x-internal:=true, org.eclipse.cdt.internal.core.pdom.indexer.full;x-internal:=true, org.eclipse.cdt.internal.core.pdom.indexer.nulli;x-internal:=true, diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java index efe2493015b..72ca99abffe 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 QNX Software Systems and others. + * Copyright (c) 2000, 2007 QNX Software Systems 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 @@ -51,6 +51,7 @@ import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.internal.core.CCoreInternals; +import org.eclipse.cdt.internal.core.LocalProjectScope; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -770,6 +771,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe case IResourceChangeEvent.POST_CHANGE : try { if (delta != null) { + checkForProjectRename(delta); ICElementDelta[] translatedDeltas = fDeltaProcessor.processResourceDelta(delta); if (translatedDeltas.length > 0) { for (int i = 0; i < translatedDeltas.length; i++) { @@ -1160,6 +1162,21 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe } } + private void checkForProjectRename(IResourceDelta delta) { + IResourceDelta[] rem= delta.getAffectedChildren(IResourceDelta.REMOVED); + for (int i = 0; i < rem.length; i++) { + delta = rem[i]; + IResource res= delta.getResource(); + if (res.getType() == IResource.PROJECT) { + IPath movedTo= null; + if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) { + movedTo= delta.getMovedToPath(); + } + LocalProjectScope.deletePreferences(res.getFullPath(), movedTo); + } + } + } + private void deleting(IProject project, IResourceDelta delta) { // stop the binary runner for this project removeBinaryRunner(project); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexer.java index f203ddcabe2..929a91a4b37 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 QNX Software Systems and others. + * Copyright (c) 2006, 2007 QNX Software Systems 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 @@ -8,10 +8,13 @@ * Contributors: * QNX - Initial API and implementation * Andrew Ferguson (Symbian) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom; +import java.util.Properties; + import org.eclipse.cdt.core.model.ICElementDelta; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.core.runtime.CoreException; @@ -37,21 +40,21 @@ public interface IPDOMIndexer { public String getID(); /** - * Returns whether to index source files that are not actually part of the build. + * Returns the value of a property. * @since 4.0 */ - public boolean getIndexAllFiles(); + public String getProperty(String key); /** * Clients are not allowed to call this method, it is called by the framework. * @since 4.0 */ - public void setIndexAllFiles(boolean value); + public void setProperties(Properties props); /** * Clients are not allowed to call this method, it is called by the framework. * Used to check whether we need to reindex a project. * @since 4.0 */ - public boolean isIndexAllFiles(boolean value); + public boolean hasProperties(Properties props); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Messages.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Messages.java index e292f9ed04d..68975c42b18 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Messages.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Messages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 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 @@ -19,7 +19,6 @@ public class Messages extends NLS { public static String PDOMManager_JoinIndexerTask; public static String PDOMManager_notifyJob_label; public static String PDOMManager_notifyTask_message; - public static String PDOMManager_savePrefsJob; public static String PDOMManager_StartJob_name; public static String WritablePDOM_error_unknownLinkage; static { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index 78718b7efe2..0c78de10176 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -189,7 +189,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { protected void clear() throws CoreException { Database db = getDB(); // Clear out the database - db.clear(0); + db.clear(1); // Zero out the File Index and Linkages db.putInt(FILE_INDEX, 0); @@ -535,7 +535,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { } public IIndexFragmentBinding adaptBinding(IIndexFragmentBinding binding) throws CoreException { - if (binding instanceof IBinding) { + if (binding != null) { return adaptBinding((IBinding) binding); } return null; 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 0d88a35db76..70f8b9097a1 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 QNX Software Systems and others. + * Copyright (c) 2005, 2007 QNX Software Systems 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 @@ -18,10 +18,9 @@ import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Map; +import java.util.Properties; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.ICDescriptor; -import org.eclipse.cdt.core.ICExtensionReference; import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.dom.IPDOMIndexer; import org.eclipse.cdt.core.dom.IPDOMIndexerTask; @@ -33,6 +32,7 @@ import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElementDelta; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.IElementChangedListener; +import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.index.IWritableIndex; import org.eclipse.cdt.internal.core.index.IWritableIndexManager; import org.eclipse.cdt.internal.core.index.IndexChangeEvent; @@ -40,11 +40,10 @@ import org.eclipse.cdt.internal.core.index.IndexFactory; import org.eclipse.cdt.internal.core.index.IndexerStateEvent; import org.eclipse.cdt.internal.core.pdom.PDOM.IListener; import org.eclipse.cdt.internal.core.pdom.dom.PDOMProjectIndexLocationConverter; +import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; import org.eclipse.cdt.internal.core.pdom.indexer.nulli.PDOMNullIndexer; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.ProjectScope; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; @@ -58,14 +57,8 @@ import org.eclipse.core.runtime.SafeRunner; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; -import org.eclipse.core.runtime.preferences.IPreferencesService; -import org.eclipse.core.runtime.preferences.IScopeContext; -import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; -import org.osgi.service.prefs.BackingStoreException; -import org.osgi.service.prefs.Preferences; /** * The PDOM Provider. This is likely temporary since I hope @@ -84,12 +77,21 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen return rule == this; } } + + private final class PCL implements IPreferenceChangeListener { + private IProject fProject; + public PCL(IProject prj) { + fProject= prj; + } + public void preferenceChange(PreferenceChangeEvent event) { + onPreferenceChange(fProject, event); + } + } + private static final QualifiedName indexerProperty= new QualifiedName(CCorePlugin.PLUGIN_ID, "pdomIndexer"); //$NON-NLS-1$ private static final QualifiedName dbNameProperty= new QualifiedName(CCorePlugin.PLUGIN_ID, "pdomName"); //$NON-NLS-1$ - public static final String INDEXER_ID_KEY = "indexerId"; //$NON-NLS-1$ - public static final String INDEX_ALL_FILES = "indexAllFiles"; //$NON-NLS-1$ private static final ISchedulingRule NOTIFICATION_SCHEDULING_RULE = new PerInstanceSchedulingRule(); private static final ISchedulingRule INDEXER_SCHEDULING_RULE = new PerInstanceSchedulingRule(); @@ -122,11 +124,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen * not allowed to hold a lock on fPDOMs. */ private Object fIndexerMutex= new Object(); - private IPreferenceChangeListener fPreferenceChangeListener= new IPreferenceChangeListener(){ - public void preferenceChange(PreferenceChangeEvent event) { - onPreferenceChange(event); - } - }; + private HashMap fPrefListeners= new HashMap(); /** * Startup the PDOM. This mainly sets us up to handle model @@ -209,135 +207,38 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen return project.getElementName() + "." + System.currentTimeMillis() + ".pdom"; //$NON-NLS-1$//$NON-NLS-2$ } - public String getDefaultIndexerId() { - IPreferencesService prefService = Platform.getPreferencesService(); - return prefService.getString(CCorePlugin.PLUGIN_ID, INDEXER_ID_KEY, - CCorePlugin.DEFAULT_INDEXER, null); - } - - public void setDefaultIndexerId(String indexerId) { - IEclipsePreferences prefs = new InstanceScope().getNode(CCorePlugin.PLUGIN_ID); - if (prefs != null) { - prefs.put(INDEXER_ID_KEY, indexerId); - try { - prefs.flush(); - } catch (BackingStoreException e) { - } - } - } - + public String getDefaultIndexerId() { + return getIndexerId(null); + } + + public void setDefaultIndexerId(String indexerId) { + setIndexerId(null, indexerId); + } + public String getIndexerId(ICProject project) { - IEclipsePreferences prefs = new ProjectScope(project.getProject()).getNode(CCorePlugin.PLUGIN_ID); - if (prefs == null) - return getDefaultIndexerId(); - - String indexerId = prefs.get(INDEXER_ID_KEY, null); - if (indexerId == null) { - // See if it is in the ICDescriptor - try { - ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(project.getProject(), false); - if (desc != null) { - ICExtensionReference[] ref = desc.get(CCorePlugin.INDEXER_UNIQ_ID); - if (ref != null && ref.length > 0) { - indexerId = ref[0].getID(); - } - if (indexerId != null) { - // Make sure it is a valid indexer - IExtension indexerExt = Platform.getExtensionRegistry() - .getExtension(CCorePlugin.INDEXER_UNIQ_ID, indexerId); - if (indexerExt == null) { - // It is not, forget about it. - indexerId = null; - } - } - } - } catch (CoreException e) { - } - - // if Indexer still null schedule a job to get it - if (indexerId == null || indexerId.equals("org.eclipse.cdt.core.ctagsindexer")) //$NON-NLS-1$ - // make it the default, ctags is gone - indexerId = getDefaultIndexerId(); - - // Start a job to set the id. - setIndexerId(project, indexerId); - } - - return indexerId; + IProject prj= project != null ? project.getProject() : null; + return IndexerPreferences.get(prj, IndexerPreferences.KEY_INDEXER_ID, ID_NO_INDEXER); } public void setIndexerId(final ICProject project, String indexerId) { - IEclipsePreferences prefs = new ProjectScope(project.getProject()).getNode(CCorePlugin.PLUGIN_ID); - if (prefs == null) - return; // TODO why would this be null? - - prefs.put(INDEXER_ID_KEY, indexerId); - Job job= new Job(Messages.PDOMManager_savePrefsJob) { - protected IStatus run(IProgressMonitor monitor) { - IEclipsePreferences prefs = new ProjectScope(project.getProject()).getNode(CCorePlugin.PLUGIN_ID); - if (prefs != null) { - try { - prefs.flush(); - } catch (BackingStoreException e) { - } - } - return Status.OK_STATUS; - } - }; - job.setSystem(true); - job.setRule(project.getProject()); - job.schedule(2000); - } - - public void setIndexAllFiles(final ICProject project, boolean val) { - IEclipsePreferences prefs = new ProjectScope(project.getProject()).getNode(CCorePlugin.PLUGIN_ID); - if (prefs == null) - return; // TODO why would this be null? - - prefs.putBoolean(INDEX_ALL_FILES, val); - Job job= new Job(Messages.PDOMManager_savePrefsJob) { - protected IStatus run(IProgressMonitor monitor) { - IEclipsePreferences prefs = new ProjectScope(project.getProject()).getNode(CCorePlugin.PLUGIN_ID); - if (prefs != null) { - try { - prefs.flush(); - } catch (BackingStoreException e) { - } - } - return Status.OK_STATUS; - } - }; - job.setSystem(true); - job.setRule(project.getProject()); - job.schedule(2000); - } - - public boolean getIndexAllFiles(ICProject project) { - IScopeContext[] scope= new IScopeContext[] {new ProjectScope(project.getProject()), new InstanceScope()}; - return Platform.getPreferencesService().getBoolean(CCorePlugin.PLUGIN_ID, INDEX_ALL_FILES, false, scope); + IProject prj= project.getProject(); + IndexerPreferences.set(prj, IndexerPreferences.KEY_INDEXER_ID, indexerId); + CCoreInternals.savePreferences(prj); } public IPDOMIndexer getIndexer(ICProject project) { return getIndexer(project, true); } - public void onPreferenceChange(PreferenceChangeEvent event) { - Object key= event.getKey(); - if (key.equals(INDEXER_ID_KEY) || key.equals(INDEX_ALL_FILES)) { - Preferences node = event.getNode(); - if (CCorePlugin.PLUGIN_ID.equals(node.name())) { - node= node.parent(); - IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject(node.name()); - if (project.exists() && project.isOpen()) { - ICProject cproject= CoreModel.getDefault().create(project); - if (cproject != null) { - try { - changeIndexer(cproject); - } - catch (Exception e) { - CCorePlugin.log(e); - } - } + protected void onPreferenceChange(IProject project, PreferenceChangeEvent event) { + if (project.exists() && project.isOpen()) { + ICProject cproject= CoreModel.getDefault().create(project); + if (cproject != null) { + try { + changeIndexer(cproject); + } + catch (Exception e) { + CCorePlugin.log(e); } } } @@ -346,17 +247,19 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen private void changeIndexer(ICProject cproject) throws CoreException { assert !Thread.holdsLock(fProjectToPDOM); IPDOMIndexer oldIndexer= null; - String newid= getIndexerId(cproject); - boolean allFiles= getIndexAllFiles(cproject); + IProject prj= cproject.getProject(); + + String newid= IndexerPreferences.get(prj, IndexerPreferences.KEY_INDEXER_ID, ID_NO_INDEXER); + Properties props= IndexerPreferences.getProperties(prj); synchronized (fIndexerMutex) { oldIndexer= getIndexer(cproject, false); if (oldIndexer != null) { - if (oldIndexer.getID().equals(newid) && oldIndexer.isIndexAllFiles(allFiles)) { + if (oldIndexer.getID().equals(newid) && oldIndexer.hasProperties(props)) { return; } } - createIndexer(cproject, newid, allFiles, true); + createIndexer(cproject, newid, props, true); } if (oldIndexer != null) { @@ -367,14 +270,14 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen public IPDOMIndexer getIndexer(ICProject project, boolean create) { assert !Thread.holdsLock(fProjectToPDOM); synchronized (fIndexerMutex) { - IProject rproject = project.getProject(); - if (!rproject.isOpen()) { + IProject prj = project.getProject(); + if (!prj.isOpen()) { return null; } IPDOMIndexer indexer; try { - indexer = (IPDOMIndexer)rproject.getSessionProperty(indexerProperty); + indexer = (IPDOMIndexer)prj.getSessionProperty(indexerProperty); } catch (CoreException e) { CCorePlugin.log(e); return null; @@ -386,7 +289,8 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen if (create) { try { - return createIndexer(project, getIndexerId(project), getIndexAllFiles(project), false); + Properties props= IndexerPreferences.getProperties(prj); + return createIndexer(project, getIndexerId(project), props, false); } catch (CoreException e) { CCorePlugin.log(e); } @@ -395,7 +299,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen } } - private IPDOMIndexer createIndexer(ICProject project, String indexerId, boolean allHeaders, boolean forceReindex) throws CoreException { + private IPDOMIndexer createIndexer(ICProject project, String indexerId, Properties props, boolean forceReindex) throws CoreException { assert Thread.holdsLock(fIndexerMutex); PDOM pdom= (PDOM) getPDOM(project); @@ -411,7 +315,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen if ("run".equals(element.getName())) { //$NON-NLS-1$ try { indexer = (IPDOMIndexer)element.createExecutableExtension("class"); //$NON-NLS-1$ - indexer.setIndexAllFiles(allHeaders); + indexer.setProperties(props); } catch (CoreException e) { CCorePlugin.log(e); } @@ -496,17 +400,21 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen } private void registerPreferenceListener(ICProject project) { - IEclipsePreferences prefs = new ProjectScope(project.getProject()).getNode(CCorePlugin.PLUGIN_ID); - if (prefs != null) { - prefs.addPreferenceChangeListener(fPreferenceChangeListener); - } + IProject prj= project.getProject(); + PCL pcl= (PCL) fPrefListeners.get(prj); + if (pcl == null) { + pcl= new PCL(prj); + fPrefListeners.put(prj, pcl); + } + IndexerPreferences.addChangeListener(prj, pcl); } private void unregisterPreferenceListener(ICProject project) { - IEclipsePreferences prefs = new ProjectScope(project.getProject()).getNode(CCorePlugin.PLUGIN_ID); - if (prefs != null) { - prefs.removePreferenceChangeListener(fPreferenceChangeListener); - } + IProject prj= project.getProject(); + PCL pcl= (PCL) fPrefListeners.remove(prj); + if (pcl != null) { + IndexerPreferences.removeChangeListener(prj, pcl); + } } public void changeProject(ICProject project, ICElementDelta delta) throws CoreException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/AbstractPDOMIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/AbstractPDOMIndexer.java new file mode 100644 index 00000000000..20539f515a7 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/AbstractPDOMIndexer.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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.core.pdom.indexer; + +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; + +import org.eclipse.cdt.core.dom.IPDOMIndexer; +import org.eclipse.cdt.core.model.ICProject; + +public abstract class AbstractPDOMIndexer implements IPDOMIndexer { + + protected ICProject project; + protected Properties fProperties= new Properties(); + + public AbstractPDOMIndexer() { + fProperties.put(IndexerPreferences.KEY_INDEX_ALL_FILES, String.valueOf(false)); + } + + public ICProject getProject() { + return project; + } + + public void setProject(ICProject project) { + this.project = project; + } + + public String getProperty(String key) { + return fProperties.getProperty(key); + } + + public boolean hasProperties(Properties props) { + for (Iterator i= fProperties.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry) i.next(); + String key = (String) entry.getKey(); + String myval = (String) entry.getValue(); + + if (myval != null) { // relevant property + String v2= (String) props.get(key); + if (v2 != null && !myval.equals(v2)) { + return false; + } + } + } + return true; + } + + public void setProperties(Properties props) { + // only set relevant properties as initialized in the constructor + for (Iterator i= props.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry) i.next(); + String key = (String) entry.getKey(); + String val = (String) entry.getValue(); + + if (val != null && fProperties.get(key) != null) { + fProperties.put(key, val); + } + } + } +} 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 new file mode 100644 index 00000000000..e45334cc8ab --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerPreferences.java @@ -0,0 +1,289 @@ +/******************************************************************************* + * 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.core.pdom.indexer; + +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.IPDOMManager; +import org.eclipse.cdt.internal.core.CCoreInternals; +import org.eclipse.cdt.internal.core.LocalProjectScope; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.core.runtime.preferences.DefaultScope; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IPreferencesService; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; + +/** + * Access to indexer properties. + * @since 4.0 + */ +public class IndexerPreferences { + public static final String KEY_INDEXER_ID= "indexerId"; //$NON-NLS-1$ + public static final String KEY_INDEX_ALL_FILES= "indexAllFiles"; //$NON-NLS-1$ + + private static final String QUALIFIER = CCorePlugin.PLUGIN_ID; + private static final String INDEXER_NODE = "indexer"; //$NON-NLS-1$ + private static final String KEY_INDEXER_PREFS_SCOPE = "preferenceScope"; //$NON-NLS-1$ + + public static final int SCOPE_INSTANCE = 0; + public static final int SCOPE_PROJECT_PRIVATE = 1; + public static final int SCOPE_PROJECT_SHARED = 2; + + /** + * Returns the scope that is selected for the project. + * @param project + * @return one of {@link #SCOPE_INSTANCE}, {@link #SCOPE_PROJECT_SHARED} or + * {@link #SCOPE_PROJECT_PRIVATE}. + */ + public static int getScope(IProject project) { + int scope= SCOPE_INSTANCE; + if (project != null) { + Preferences ppp= getLocalPreferences(project); + scope= ppp.getInt(KEY_INDEXER_PREFS_SCOPE, -1); + if (scope == -1) { + scope= determineScopeOnFirstUse(project); + } + if (scope != SCOPE_INSTANCE) { + if (get(project, scope, KEY_INDEXER_ID, null) == null) { + scope= SCOPE_INSTANCE; + ppp.putInt(KEY_INDEXER_PREFS_SCOPE, scope); + CCoreInternals.savePreferences(project); + } + } + } + return scope; + } + + /** + * Sets the scope that shall be used for the project. + * Must be one of {@link #SCOPE_INSTANCE}, {@link #SCOPE_PROJECT_SHARED} or + * {@link #SCOPE_PROJECT_PRIVATE}. + */ + public static int setScope(IProject project, int scope) { + if (project == null) + throw new IllegalArgumentException(); + boolean makeCopy= false; + switch (scope) { + case SCOPE_INSTANCE: + break; + case SCOPE_PROJECT_PRIVATE: + case SCOPE_PROJECT_SHARED: + makeCopy= true; + break; + default: + throw new IllegalArgumentException(); + } + + if (makeCopy) { + Preferences[] prefs= getPreferences(project, scope); + if (prefs[0].get(KEY_INDEXER_ID, null) == null) { + Properties props= getProperties(project, SCOPE_INSTANCE); + setProperties(prefs[0], props); + } + } + + Preferences ppp= getLocalPreferences(project); + ppp.putInt(KEY_INDEXER_PREFS_SCOPE, scope); + return scope; + } + + /** + * Returns the properties for the indexer of a project. + */ + public static Properties getProperties(IProject project) { + return getProperties(project, getScope(project)); + } + + /** + * Returns the properties for the indexer of a project for a + * specific scope. + */ + public static Properties getProperties(IProject project, int scope) { + Preferences[] prefs= getPreferences(project, scope); + Properties props= new Properties(); + for (int i=prefs.length-1; i>=0; i--) { + addProperties(prefs[i], props); + } + return props; + } + + /** + * Adds or changes indexer properties for a project. + */ + public static void setProperties(IProject project, int scope, Properties props) { + Preferences[] prefs= getPreferences(project, scope); + setProperties(prefs[0], props); + } + + private static void setProperties(Preferences prefs, Properties props) { + for (Iterator i = props.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry) i.next(); + String key = (String) entry.getKey(); + String val = (String) entry.getValue(); + prefs.put(key, val); + } + } + + /** + * Returns an indexer property for the given project. + * @since 4.0 + */ + public static String get(IProject project, String key, String defval) { + IPreferencesService prefService = Platform.getPreferencesService(); + Preferences[] prefs= IndexerPreferences.getPreferences(project); + return prefService.get(key, defval, prefs); + } + + /** + * Returns an indexer property in a scope for the given project. + * @since 4.0 + */ + private static String get(IProject project, int scope, String key, String defval) { + IPreferencesService prefService = Platform.getPreferencesService(); + Preferences[] prefs= IndexerPreferences.getPreferences(project, scope); + return prefService.get(key, defval, prefs); + } + + /** + * Adds or changes an indexer property for the given project. + */ + public static void set(final IProject project, String key, String value) { + if (getScope(project) == SCOPE_INSTANCE) { + setScope(project, SCOPE_PROJECT_PRIVATE); + } + final Preferences[] prefs= IndexerPreferences.getPreferences(project.getProject()); + prefs[0].put(key, value); + } + + /** + * Sets up the initial indexing preferences for the project. + */ + private static int determineScopeOnFirstUse(IProject project) { + int scope= SCOPE_INSTANCE; + Preferences prjPrefs= getProjectPreferences(project); + if (prjPrefs.get(KEY_INDEXER_ID, null) != null) { + scope= SCOPE_PROJECT_SHARED; + } + else { + Preferences oldStyle= prjPrefs.parent(); + String id= oldStyle.get(KEY_INDEXER_ID, null); + if (id != null) { + prjPrefs.put(KEY_INDEXER_ID, id); + String value= oldStyle.get(KEY_INDEX_ALL_FILES, null); + if (value != null) { + prjPrefs.put(KEY_INDEX_ALL_FILES, value); + } + scope= SCOPE_PROJECT_SHARED; + } + } + getLocalPreferences(project).putInt(KEY_INDEXER_PREFS_SCOPE, scope); + CCoreInternals.savePreferences(project); + return scope; + } + + private static Preferences[] getPreferences(IProject project) { + return getPreferences(project, getScope(project)); + } + + private static Preferences[] getPreferences(IProject project, int scope) { + if (project != null) { + switch (scope) { + case SCOPE_PROJECT_PRIVATE: + return new Preferences[] {getLocalPreferences(project)}; + case SCOPE_PROJECT_SHARED: + return new Preferences[] {getProjectPreferences(project)}; + } + } + return getInstancePreferencesArray(); + } + + private static Preferences[] getInstancePreferencesArray() { + return new Preferences[] { + getInstancePreferences(), + new ConfigurationScope().getNode(QUALIFIER).node(INDEXER_NODE), + new DefaultScope().getNode(QUALIFIER).node(INDEXER_NODE) + }; + } + + private static Preferences getInstancePreferences() { + return new InstanceScope().getNode(QUALIFIER).node(INDEXER_NODE); + } + + private static Preferences getProjectPreferences(IProject project) { + return new ProjectScope(project).getNode(QUALIFIER).node(INDEXER_NODE); + } + + private static Preferences getLocalPreferences(IProject project) { + return new LocalProjectScope(project).getNode(QUALIFIER).node(INDEXER_NODE); + } + + private static void addProperties(Preferences preferences, Properties props) { + try { + String[] keys = preferences.keys(); + for (int i=0; i < keys.length; i++) { + String key= keys[i]; + String val= preferences.get(key, null); + if (val != null) { + props.put(key, val); + } + } + } catch (BackingStoreException e) { + } + } + + public static void initializeDefaultPreferences(IEclipsePreferences defaultPreferences) { + Preferences prefs= defaultPreferences.node(INDEXER_NODE); + prefs.put(KEY_INDEXER_ID, IPDOMManager.ID_FAST_INDEXER); + prefs.putBoolean(KEY_INDEX_ALL_FILES, false); + } + + public static void addChangeListener(IProject prj, IPreferenceChangeListener pcl) { + Preferences node= getProjectPreferences(prj); + addListener(node, pcl); + node= getLocalPreferences(prj); + addListener(node, pcl); + node= getInstancePreferences(); + addListener(node, pcl); + } + + private static void addListener(Preferences node, IPreferenceChangeListener pcl) { + if (node instanceof IEclipsePreferences) { + IEclipsePreferences enode= (IEclipsePreferences) node; + enode.addPreferenceChangeListener(pcl); + } + } + + public static void removeChangeListener(IProject prj, IPreferenceChangeListener pcl) { + Preferences node= getProjectPreferences(prj); + removeListener(node, pcl); + node= getLocalPreferences(prj); + removeListener(node, pcl); + node= getInstancePreferences(); + removeListener(node, pcl); + } + + private static void removeListener(Preferences node, IPreferenceChangeListener pcl) { + if (node instanceof IEclipsePreferences) { + IEclipsePreferences enode= (IEclipsePreferences) node; + enode.removePreferenceChangeListener(pcl); + } + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java index 4deb4288058..c56edbcc7fb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java @@ -95,6 +95,7 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask { private static final Object NO_CONTEXT = new Object(); protected static final int MAX_ERRORS = 500; + private static final String TRUE = String.valueOf(true); protected volatile int fTotalSourcesEstimate= 0; protected volatile int fCompletedSources= 0; @@ -283,7 +284,7 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask { } protected boolean getIndexAllFiles() { - return getIndexer().getIndexAllFiles(); + return TRUE.equals(getIndexer().getProperty(IndexerPreferences.KEY_INDEX_ALL_FILES)); } protected ITranslationUnit findContext(IIndex index, IIndexFileLocation location) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java index f7ef70dec9c..8c22987625b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 QNX Software Systems and others. + * Copyright (c) 2006, 2007 QNX Software Systems 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 @@ -13,37 +13,25 @@ package org.eclipse.cdt.internal.core.pdom.indexer.fast; -import org.eclipse.cdt.core.dom.IPDOMIndexer; import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.CCoreInternals; +import org.eclipse.cdt.internal.core.pdom.indexer.AbstractPDOMIndexer; import org.eclipse.core.runtime.CoreException; /** * @author Doug Schaefer * */ -public class PDOMFastIndexer implements IPDOMIndexer { +public class PDOMFastIndexer extends AbstractPDOMIndexer { // Must match extension id public static final String ID = IPDOMManager.ID_FAST_INDEXER; - protected ICProject project; - - private boolean fIndexAllFiles; public PDOMFastIndexer() { } - public ICProject getProject() { - return project; - } - - public void setProject(ICProject project) { - this.project = project; - } - public void handleDelta(ICElementDelta delta) throws CoreException { PDOMFastHandleDelta fhd= new PDOMFastHandleDelta(this, delta); if (fhd.estimateRemainingSources() > 0) { @@ -58,16 +46,4 @@ public class PDOMFastIndexer implements IPDOMIndexer { public String getID() { return ID; } - - public void setIndexAllFiles(boolean val) { - fIndexAllFiles= val; - } - - public boolean getIndexAllFiles() { - return fIndexAllFiles; - } - - public boolean isIndexAllFiles(boolean val) { - return fIndexAllFiles==val; - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java index e2bae1b8580..6f9fd5fd0e0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 QNX Software Systems and others. + * Copyright (c) 2006, 2007 QNX Software Systems 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 @@ -7,15 +7,15 @@ * * Contributors: * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.indexer.full; -import org.eclipse.cdt.core.dom.IPDOMIndexer; import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.CCoreInternals; +import org.eclipse.cdt.internal.core.pdom.indexer.AbstractPDOMIndexer; import org.eclipse.core.runtime.CoreException; /** @@ -25,21 +25,9 @@ import org.eclipse.core.runtime.CoreException; * @author Doug Schaefer * */ -public class PDOMFullIndexer implements IPDOMIndexer { +public class PDOMFullIndexer extends AbstractPDOMIndexer { public static final String ID = IPDOMManager.ID_FULL_INDEXER; - private boolean fIndexAllFiles= true; - private ICProject project; - - - public ICProject getProject() { - return project; - } - - public void setProject(ICProject project) { - this.project = project; - } - public void handleDelta(ICElementDelta delta) throws CoreException { PDOMFullHandleDelta task = new PDOMFullHandleDelta(this, delta); if (task.estimateRemainingSources() > 0) { @@ -54,16 +42,4 @@ public class PDOMFullIndexer implements IPDOMIndexer { public String getID() { return ID; } - - public void setIndexAllFiles(boolean val) { - fIndexAllFiles= val; - } - - public boolean getIndexAllFiles() { - return fIndexAllFiles; - } - - public boolean isIndexAllFiles(boolean val) { - return fIndexAllFiles==val; - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/nulli/PDOMNullIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/nulli/PDOMNullIndexer.java index 9b178c641eb..88dd18fa035 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/nulli/PDOMNullIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/nulli/PDOMNullIndexer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 QNX Software Systems and others. + * Copyright (c) 2006, 2007 QNX Software Systems 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 @@ -17,10 +17,10 @@ import org.eclipse.cdt.core.dom.IPDOMIndexer; import org.eclipse.cdt.core.dom.IPDOMIndexerTask; import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.index.IWritableIndex; import org.eclipse.cdt.internal.core.index.IWritableIndexManager; +import org.eclipse.cdt.internal.core.pdom.indexer.AbstractPDOMIndexer; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -29,18 +29,12 @@ import org.eclipse.core.runtime.IProgressMonitor; * * The Null Indexer which does nothing. */ -public class PDOMNullIndexer implements IPDOMIndexer { +public class PDOMNullIndexer extends AbstractPDOMIndexer { public static final String ID = IPDOMManager.ID_NO_INDEXER; - - private ICProject project; - - public ICProject getProject() { - return project; - } - - public void setProject(ICProject project) { - this.project = project; + + public PDOMNullIndexer() { + fProperties.clear(); // don't accept any properties } public void handleDelta(ICElementDelta delta) { @@ -93,15 +87,4 @@ public class PDOMNullIndexer implements IPDOMIndexer { public String getID() { return ID; } - - public boolean getIndexAllFiles() { - return false; - } - - public void setIndexAllFiles(boolean value) { - } - - public boolean isIndexAllFiles(boolean val) { - return true; - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/messages.properties b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/messages.properties index 0fdc52cf4d7..b8427fb62b7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/messages.properties +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/messages.properties @@ -1,7 +1,16 @@ +############################################################################### +# Copyright (c) 2006, 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 (Wind River Systems) +############################################################################### WritablePDOM_error_unknownLinkage=AST specifies unknown linkage ''{0}'' PDOMManager_notifyJob_label=Notify Index Change Listeners PDOMManager_JoinIndexerTask=Join Indexer -PDOMManager_savePrefsJob=Save Project Preferences PDOMManager_StartJob_name=Initialize Indexing PDOMManager_notifyTask_message=Notify Listeners PDOMManager_indexMonitorDetail={0}/{1} sources, {2} headers diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java index bd81cc91892..2cd85a77571 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java @@ -34,7 +34,6 @@ import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.parser.IScannerInfoProvider; import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.core.resources.IPathEntryVariableManager; -import org.eclipse.cdt.core.resources.ScannerProvider; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.WriteAccessException; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCoreInternals.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCoreInternals.java index 8fdb807f357..3743067e4cc 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCoreInternals.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCoreInternals.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 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 @@ -13,10 +13,46 @@ package org.eclipse.cdt.internal.core; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.internal.core.pdom.PDOMManager; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.osgi.service.prefs.BackingStoreException; public class CCoreInternals { public static PDOMManager getPDOMManager() { return (PDOMManager) CCorePlugin.getPDOMManager(); } + + /** + * Saves the local project preferences, shared project preferences and the + * scope preferences for the core plugin. + * @param project the project for which to save preferences, may be null + * @since 4.0 + */ + public static void savePreferences(final IProject project) { + Job job= new Job(CCorePlugin.getResourceString("CCoreInternals.savePreferencesJob")) { //$NON-NLS-1$ + protected IStatus run(IProgressMonitor monitor) { + try { + if (project != null) { + new LocalProjectScope(project).getNode(CCorePlugin.PLUGIN_ID).flush(); + new ProjectScope(project).getNode(CCorePlugin.PLUGIN_ID).flush(); + } + new InstanceScope().getNode(CCorePlugin.PLUGIN_ID).flush(); + } catch (BackingStoreException e) { + CCorePlugin.log(e); + } + return Status.OK_STATUS; + } + }; + job.setSystem(true); + if (project != null) { + job.setRule(project); + } + job.schedule(2000); + } } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePluginResources.properties b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePluginResources.properties index 3a067836af0..b25b4f80c91 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePluginResources.properties +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePluginResources.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2006 QNX Software Systems and others. +# Copyright (c) 2000, 2007 QNX Software Systems 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 @@ -7,6 +7,7 @@ # # Contributors: # QNX Software Systems - Initial API and implementation +# Markus Schorn (Wind River Systems) ############################################################################### CBuilder.build_error= Build Error CoreModel.BinaryRunner.Binary_Search_Thread=Searching for Binaries @@ -75,6 +76,5 @@ indexer.notFound = Indexer not found pdom.requestTooLarge=Request too large pdom.indexer.name=C/C++ Indexer pdom.indexer.task=Indexing -pdom.indexer.filling=Counting files -pdom.indexer.message=file {0} of {1}: {2} PDOMIndexerJob.updateMonitorJob=Update Monitor +CCoreInternals.savePreferencesJob=Save preferences diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePreferenceInitializer.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePreferenceInitializer.java index 1493ea1f45d..e1f7f85259a 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePreferenceInitializer.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePreferenceInitializer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 QNX Software Systems and others. + * Copyright (c) 2000, 2007 QNX Software Systems 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 @@ -8,6 +8,7 @@ * Contributors: * QNX Software Systems - Initial API and implementation * Sergey Prigogin, Google + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core; @@ -17,10 +18,9 @@ import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePreferenceConstants; -import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants; import org.eclipse.cdt.internal.core.model.CModelManager; -import org.eclipse.cdt.internal.core.pdom.PDOMManager; +import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; import org.eclipse.core.runtime.preferences.DefaultScope; import org.eclipse.core.runtime.preferences.IEclipsePreferences; @@ -54,8 +54,6 @@ public class CCorePreferenceInitializer extends AbstractPreferenceInitializer { } // indexer defaults - defaultPreferences.putBoolean(PDOMManager.INDEX_ALL_FILES, false); - defaultPreferences.put(PDOMManager.INDEXER_ID_KEY, IPDOMManager.ID_FAST_INDEXER); + IndexerPreferences.initializeDefaultPreferences(defaultPreferences); } - } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/LocalProjectScope.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/LocalProjectScope.java new file mode 100644 index 00000000000..ce4c1bdf8b4 --- /dev/null +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/LocalProjectScope.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * 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.core; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; + +public class LocalProjectScope implements IScopeContext { + private static final String QUALIFIER_EXT = ".prj-"; //$NON-NLS-1$ + + /** + * String constant (value of "project-local") used for the + * scope name for this preference scope. + */ + public static final String SCOPE = "project-local"; //$NON-NLS-1$ + + private String fContext; + + /** + * Create and return a new local project scope for the given project. The given + * project must not be null. + * + * @param context the project + * @exception IllegalArgumentException if the project is null + */ + public LocalProjectScope(IProject context) { + if (context == null) + throw new IllegalArgumentException(); + fContext= context.getName(); + } + + /** + * Create and return a new local project scope for the given project. The given + * project must not be null. + * + * @param context the project + * @exception IllegalArgumentException if the project is null + */ + public LocalProjectScope(String projectName) { + if (projectName == null) + throw new IllegalArgumentException(); + fContext= projectName; + } + + public IPath getLocation() { + return null; + } + + public String getName() { + return SCOPE; + } + + public IEclipsePreferences getNode(String qualifier) { + return new InstanceScope().getNode(qualifier + QUALIFIER_EXT + fContext); + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (!(obj instanceof LocalProjectScope)) + return false; + LocalProjectScope other = (LocalProjectScope) obj; + return fContext.equals(other.fContext); + } + + public int hashCode() { + return fContext.hashCode(); + } + + + private static Preferences getPPP(String name) { + return new LocalProjectScope(name).getNode(CCorePlugin.PLUGIN_ID); + } + + public static void deletePreferences(IPath prjToDelete, IPath movedTo) { + try { + Preferences prefs= getPPP(prjToDelete.lastSegment()); + if (movedTo != null) { + Preferences target= getPPP(movedTo.lastSegment()); + copyPrefs(prefs, target); + } + Preferences parent= prefs.parent(); + prefs.removeNode(); + parent.flush(); + } catch (BackingStoreException e) { + } + } + + private static void copyPrefs(Preferences prefs, Preferences target) throws BackingStoreException { + String[] keys= prefs.keys(); + for (int i = 0; i < keys.length; i++) { + String key = keys[i]; + String val= prefs.get(key, null); + if (val != null) { + target.put(key, val); + } + } + String[] children= prefs.childrenNames(); + for (int i = 0; i < children.length; i++) { + String child = children[i]; + copyPrefs(prefs.node(child), target.node(child)); + } + } +} diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/CharOperation.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/CharOperation.java index 1d441d2266a..a6019774829 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/CharOperation.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/CharOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core; @@ -1712,7 +1713,8 @@ public final class CharOperation { // offsets inside pattern int pSegmentStart, pLength = pattern.length; - if (freeLeadingDoubleStar = pattern[0] != pathSeparator){ + freeLeadingDoubleStar= (pattern[0] != pathSeparator); + if (freeLeadingDoubleStar){ pSegmentStart = 0; } else { pSegmentStart = 1; diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/includebrowser/BasicIncludeBrowserTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/includebrowser/BasicIncludeBrowserTest.java index 5c6efeba2fa..5190eb45842 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/includebrowser/BasicIncludeBrowserTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/includebrowser/BasicIncludeBrowserTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 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 @@ -24,6 +24,7 @@ import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.TestScannerProvider; import org.eclipse.cdt.internal.core.CCoreInternals; +import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; public class BasicIncludeBrowserTest extends IncludeBrowserBaseTest { @@ -74,7 +75,7 @@ public class BasicIncludeBrowserTest extends IncludeBrowserBaseTest { public void _testInclusionAccrossProjects() throws Exception { ICProject op= CProjectHelper.createCCProject("__ibTest_other__", "bin", IPDOMManager.ID_FAST_INDEXER); try { - CCoreInternals.getPDOMManager().setIndexAllFiles(op, true); + IndexerPreferences.set(op.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, "true"); CCoreInternals.getPDOMManager().reindex(op); fIndex= CCorePlugin.getIndexManager().getIndex(new ICProject[] {getProject(), op}); diff --git a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF index ea8151a5ee5..8b9ea357709 100644 --- a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF @@ -47,7 +47,6 @@ Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true, org.eclipse.cdt.ui.actions, org.eclipse.cdt.ui.browser.typeinfo, org.eclipse.cdt.ui.dialogs, - org.eclipse.cdt.ui.index, org.eclipse.cdt.ui.text, org.eclipse.cdt.ui.text.c.hover, org.eclipse.cdt.ui.text.contentassist, diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 65b49c10339..b75cc7d29c8 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -1495,15 +1495,14 @@ - - + name="%CDTLanguagesProperty.name"> + + + + + diff --git a/core/org.eclipse.cdt.ui/schema/cPropertyTab.exsd b/core/org.eclipse.cdt.ui/schema/cPropertyTab.exsd index 6845e596727..1b5f49f2fcc 100644 --- a/core/org.eclipse.cdt.ui/schema/cPropertyTab.exsd +++ b/core/org.eclipse.cdt.ui/schema/cPropertyTab.exsd @@ -23,9 +23,7 @@ in multi-tab and single-tab mode. It's up to page to select displaying mode. In multi-tab page, tabs are displayed in order defined by -their weights. - - +their weights. @@ -99,8 +97,6 @@ Ignored for single-tab pages. Usually pages are to be derived from org.eclipse.cdt.ui.newui.AbstractPage, but it is not obligatory. - - @@ -119,7 +115,6 @@ but it is not obligatory. Abstract value to be used for sorting tabs inside of tab folder. Ignored for single-tab page. - @@ -140,7 +135,7 @@ Ignored for single-tab page. - <extension + <extension point="org.eclipse.cdt.ui.cPropertyTab"> <tab class="org.eclipse.cdt.managedbuilder.ui.newui.DiscoveryTab" @@ -148,7 +143,7 @@ Ignored for single-tab page. name="Discovery options" weight="100" parent="org.eclipse.cdt.ui.newui.Page_PathAndSymb"/> - </entension> + </extension> @@ -195,8 +190,7 @@ CBuildLocationOutputTab CPropertyVarsTab DiscoveryTab ToolChainEditTab -ToolSettingsTab - +ToolSettingsTab diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties index cda6d0ed827..bc1a8742152 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties @@ -8,6 +8,7 @@ # Contributors: # IBM Corporation - initial API and implementation # QNX Software System +# Markus Schorn (Wind River Systems) ############################################################################### # ------- CView ----------------- @@ -47,7 +48,7 @@ BinaryParserBlock.desc=Set required binary parser for this project BaseIndexerBlock.label=C/C++ Indexer BaseIndexerBlock.desc=C/C++ Indexer setting for this project. -BaseIndexerBlock.comboLabel=Available indexers +BaseIndexerBlock.comboLabel=Select Indexer ReferenceBlock.label= Projects ReferenceBlock.desc= Referenced C/C++ Projects @@ -328,5 +329,3 @@ IndexView.setFastIndexer.name = Use Fast Indexer IndexView.CountSymbols.name = Count Symbols IndexView.CountSymbols.title = Symbol Count IndexView.CountSymbols.message = The selected PDOMs contain {0} files, {1} macros; {2} symbols\r\n{3} references, {4} declarations, {5} definitions. - -IndexerPreferencePage.applyToAllProjects = Apply indexer to all projects now 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 c3a8b5d25d9..fbea59323c3 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 QNX Software Systems and others. + * Copyright (c) 2005, 2007 QNX Software Systems 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 @@ -7,106 +7,65 @@ * * Contributors: * QNX Software Systems - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.ui.preferences; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.IPDOMManager; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.cdt.ui.dialogs.ICOptionContainer; -import org.eclipse.cdt.ui.dialogs.IndexerBlock; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Preferences; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.cdt.ui.dialogs.ICOptionContainer; +import org.eclipse.cdt.ui.dialogs.IndexerBlock; + public class IndexerPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, ICOptionContainer { private IndexerBlock fOptionBlock; - private Button applyIndexerToAllButton; public IndexerPreferencePage(){ - setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore()); - setDescription(PreferencesMessages.IndexerPrefs_description); fOptionBlock = new IndexerBlock(); } protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(1, true); - composite.setLayout(layout); + composite.setLayout(new FillLayout()); fOptionBlock.createControl(composite); - applyIndexerToAllButton = new Button(composite, SWT.CHECK); - applyIndexerToAllButton.setText(CUIPlugin.getResourceString("IndexerPreferencePage.applyToAllProjects")); //$NON-NLS-1$ - return composite; } public void init(IWorkbench workbench) { - // TODO Auto-generated method stub - } public void updateContainer() { - // TODO Auto-generated method stub - } public IProject getProject() { - // TODO Auto-generated method stub return null; } public Preferences getPreferences() { - return null; + throw new UnsupportedOperationException(); } - private static class ApplyIndexer extends Job { - private final String indexerId; - public ApplyIndexer(String indexerId) { - super("ApplyIndexer"); //$NON-NLS-1$ - setSystem(true); - this.indexerId = indexerId; - } - protected IStatus run(IProgressMonitor monitor) { - try { - IPDOMManager manager = CCorePlugin.getPDOMManager(); - ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects(); - for (int i = 0; i < projects.length; ++i) { - manager.setIndexerId(projects[i], indexerId); - } - return Status.OK_STATUS; - } catch (CoreException e) { - return e.getStatus(); - } - } - } public boolean performOk() { try { - fOptionBlock.performApply(null); - if (applyIndexerToAllButton.getSelection()) { - String indexerName = fOptionBlock.getSelectedIndexerID(); - String indexerId = fOptionBlock.getIndexerPageId(indexerName); - new ApplyIndexer(indexerId).schedule(); - } + fOptionBlock.performApply(new NullProgressMonitor()); } catch (CoreException e) {} - CUIPlugin.getDefault().savePluginPreferences(); return true; } + + public void performDefaults() { + fOptionBlock.performDefaults(); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java index dcd3e12d4ec..b3722a7e2e2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.java @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Anton Leherbauer (Wind River Systems) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.ui.preferences; @@ -164,7 +165,6 @@ public final class PreferencesMessages extends NLS { public static String PathEntryVariablesBlock_addVariableButton; public static String PathEntryVariablesBlock_editVariableButton; public static String PathEntryVariablesBlock_removeVariableButton; - public static String IndexerPrefs_description; public static String ProposalFilterPreferencesUtil_defaultFilterName; public static String CEditorPreferencePage_typing_tabTitle; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties index 98c4c0fdf14..3664e099450 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties @@ -8,6 +8,7 @@ # Contributors: # IBM Corporation - initial API and implementation # Anton Leherbauer (Wind River Systems) +# Markus Schorn (Wind River Systems) ############################################################################### CEditorPreferencePage_link=C/C++ Editor Preferences. Note that some preferences may be set on the Text Editors preference page. @@ -224,8 +225,6 @@ PathEntryVariablesBlock_editVariableButton = Edi&t... PathEntryVariablesBlock_removeVariableButton = &Remove -#Indexer -IndexerPrefs_description=Sets default Indexer Options for new Projects # Language settings ProjectLanguagesPropertyPage_contentTypeColumn = Content Type diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/AbstractIndexerPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/AbstractIndexerPage.java new file mode 100644 index 00000000000..4f751bf80c8 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/AbstractIndexerPage.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2005, 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 - Initial API and implementation + * Markus Schorn (Wind River Systems) + *******************************************************************************/ +package org.eclipse.cdt.ui.dialogs; + +import java.util.Properties; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IProgressMonitor; + + +/** + * @author Bogdan Gheorghe + */ +public abstract class AbstractIndexerPage extends AbstractCOptionPage { + protected static final String INDEX_ALL_FILES = DialogsMessages.AbstractIndexerPage_indexAllFiles; + protected static final String TRUE = String.valueOf(true); + + protected AbstractIndexerPage() { + super(); + } + + final public IProject getCurrentProject() { + ICOptionContainer container = getContainer(); + if (container != null) { + return container.getProject(); + } + return null; + } + + /** + * Use the properties to initialize the controls of the page. Fill in defaults + * for properties that are missing. + * @since 4.0 + */ + abstract public void setProperties(Properties properties); + + /** + * Return the properties according to the selections on the page. + * @since 4.0 + */ + abstract public Properties getProperties(); + + /** + * {@link #getProperties()} will be called instead. + */ + final public void performApply(IProgressMonitor monitor) { + throw new UnsupportedOperationException(); + } + + /** + * {@link #setProperties(Properties)} will be called instead. + */ + final public void performDefaults() { + throw new UnsupportedOperationException(); + } + + /** + * The framework disables and enables controls created by this page. + * After controls are enabled {@link #updateEnablement()} is called to + * allow for disabeling controls. + * @since 4.0 + */ + public void updateEnablement() { + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DOMSourceIndexerBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DOMSourceIndexerBlock.java index b4cb8d8b227..024e8427ad1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DOMSourceIndexerBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DOMSourceIndexerBlock.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 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 @@ -7,170 +7,40 @@ * * Contributors: * IBM Corp. - Rational Software - initial implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.ui.dialogs; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; +import java.util.Properties; + +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.ICExtensionReference; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.cdt.ui.index.AbstractIndexerPage; import org.eclipse.cdt.utils.ui.controls.ControlFactory; -import org.eclipse.cdt.internal.ui.CUIMessages; +import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; public class DOMSourceIndexerBlock extends AbstractIndexerPage { + private Button fAllFiles; - public final static String PREF_INDEX_MARKERS = CUIPlugin.PLUGIN_ID + ".indexmarkers"; //$NON-NLS-1$ - - private static final String ENABLE_PREPROCESSOR_PROBLEMS = CUIMessages.getString( "IndexerOptions.enablePreprocessor" ); //$NON-NLS-1$ - private static final String ENABLE_SEMANTIC_PROBLEMS = CUIMessages.getString( "IndexerOptions.enableSemantic" ); //$NON-NLS-1$ - private static final String ENABLE_SYNTACTIC_PROBLEMS = CUIMessages.getString( "IndexerOptions.enableSyntactic" ); //$NON-NLS-1$ - - private static final String INDEXER_PROBLEMS = CUIMessages.getString("IndexerOptions.problemReporting" ); //$NON-NLS-1$ - /* (non-Javadoc) - * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor) - */ - public void performApply(IProgressMonitor monitor) throws CoreException { - - if (monitor == null) { - monitor = new NullProgressMonitor(); - } - - monitor.beginTask(CUIMessages.getString("IndexerOptiosn.task.savingAttributes "), 1); //$NON-NLS-1$ - ICOptionContainer container = getContainer(); - IProject proj = null; -// String indexMarkers = getIndexerProblemsValuesString(); - - if (container != null){ - proj = container.getProject(); - } - else{ - proj = currentProject.getProject(); - } - - if (proj != null) { - ICExtensionReference[] cext = CCorePlugin.getDefault().getBinaryParserExtensions(proj); - if (cext.length > 0) { - for (int i = 0; i < cext.length; i++) { -// String id = cext[i].getID(); -// String orig = cext[i].getExtensionData("indexmarkers"); //$NON-NLS-1$ -// String indexProblems = getIndexerProblemsValuesString(); -// if (orig == null || !orig.equals(indexProblems)) { -// cext[i].setExtensionData("indexmarkers", indexProblems); //$NON-NLS-1$ -// } - - } - } - } else { - if (prefStore != null) { -// prefStore.setValue(PREF_INDEX_MARKERS, indexMarkers); - } - } - - //Project has just been created and its values have been store - don't need to request - //an indexAll as one will come through the DeltaProcessor - if (currentProject == null) - return; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults() - */ - public void performDefaults() { - // TODO Auto-generated method stub - } - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) - */ public void createControl(Composite parent) { - Composite page = ControlFactory.createComposite(parent, 1); - - Group problemsGroup = ControlFactory.createGroup(page,INDEXER_PROBLEMS,1); - - GridData gd2 = (GridData) problemsGroup.getLayoutData(); - gd2.grabExcessHorizontalSpace = true; - gd2.horizontalAlignment = GridData.FILL; - - - ControlFactory.createCheckBox( problemsGroup, ENABLE_PREPROCESSOR_PROBLEMS ); - ControlFactory.createCheckBox( problemsGroup, ENABLE_SEMANTIC_PROBLEMS ); - ControlFactory.createCheckBox( problemsGroup, ENABLE_SYNTACTIC_PROBLEMS ); - + fAllFiles= ControlFactory.createCheckBox(page, INDEX_ALL_FILES); setControl(page); } - -// public String getIndexerProblemsValuesString(){ -// int result = 0; -// result |= preprocessorProblemsEnabled.getSelection() ? DOMSourceIndexer.PREPROCESSOR_PROBLEMS_BIT : 0; -// if( syntacticProblemsEnabled != null ) -// result |= syntacticProblemsEnabled.getSelection() ? DOMSourceIndexer.SYNTACTIC_PROBLEMS_BIT : 0; -// result |= semanticProblemsEnabled.getSelection() ? DOMSourceIndexer.SEMANTIC_PROBLEMS_BIT : 0; -// Integer tempInt = new Integer(result); -// -// return tempInt.toString(); -// } - - /* (non-Javadoc) - * @see org.eclipse.cdt.ui.index2.AbstractIndexerPage#initialize(org.eclipse.core.resources.IProject) - */ - public void initialize(ICProject project) { - - try { - loadPersistedValues(project.getProject()); - this.currentProject = project; - } catch (CoreException e) {} - - //Set the IProblem checkboxes -// setIndexerProblemValues(oldIndexerProblemsValue); + + public Properties getProperties() { + Properties props= new Properties(); + props.put(IndexerPreferences.KEY_INDEX_ALL_FILES, String.valueOf(fAllFiles.getSelection())); + return props; } - public void loadPersistedValues(IProject project) throws CoreException { - - ICExtensionReference[] cext = CCorePlugin.getDefault().getBinaryParserExtensions(project); - if (cext.length > 0) { - for (int i = 0; i < cext.length; i++) { -// String id = cext[i].getID(); - - String orig = cext[i].getExtensionData("indexmarkers"); //$NON-NLS-1$ - if (orig != null){ -// Integer tempInt = new Integer(orig); -// oldIndexerProblemsValue = tempInt.intValue(); - } - } - } - + public void setProperties(Properties properties) { + boolean indexAllFiles= TRUE.equals(properties.get(IndexerPreferences.KEY_INDEX_ALL_FILES)); + fAllFiles.setSelection(indexAllFiles); } - -// public void setIndexerProblemValues( int value ){ -// preprocessorProblemsEnabled.setSelection( (value & DOMSourceIndexer.PREPROCESSOR_PROBLEMS_BIT) != 0 ); -// if( syntacticProblemsEnabled != null ) -// syntacticProblemsEnabled.setSelection( (value & DOMSourceIndexer.SYNTACTIC_PROBLEMS_BIT) != 0 ); -// semanticProblemsEnabled.setSelection( (value & DOMSourceIndexer.SEMANTIC_PROBLEMS_BIT) != 0 ); -// } - - public void loadPreferences() { - String indexerId=prefStore.getString(PREF_INDEX_MARKERS); - if (!indexerId.equals("")) { //$NON-NLS-1$ -// oldIndexerProblemsValue = (new Integer(indexerId)).intValue(); -// setIndexerProblemValues(oldIndexerProblemsValue); - } - } - - public void removePreferences() { - prefStore.setToDefault(PREF_INDEX_MARKERS); - } - } 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 new file mode 100644 index 00000000000..45b989dff06 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * 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 DialogsMessages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.cdt.ui.dialogs.DialogsMessages"; //$NON-NLS-1$ + public static String AbstractIndexerPage_indexAllFiles; + public static String PreferenceScopeBlock_enableProjectSettings; + public static String PreferenceScopeBlock_preferenceLink; + public static String PreferenceScopeBlock_storeWithProject; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, DialogsMessages.class); + } + + private DialogsMessages() { + } +} 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 new file mode 100644 index 00000000000..944293edbe9 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/DialogsMessages.properties @@ -0,0 +1,14 @@ +############################################################################### +# 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 (Wind River Systems) +############################################################################### +PreferenceScopeBlock_enableProjectSettings=Enable project specific settings +PreferenceScopeBlock_storeWithProject=Store settings with project +PreferenceScopeBlock_preferenceLink=Configure Workspace Settings... +AbstractIndexerPage_indexAllFiles=Index all files (files neither built nor included, also) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/FastIndexerBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/FastIndexerBlock.java new file mode 100644 index 00000000000..605d7495b56 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/FastIndexerBlock.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * 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 java.util.Properties; + +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; + +import org.eclipse.cdt.utils.ui.controls.ControlFactory; + +import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; + +public class FastIndexerBlock extends AbstractIndexerPage { + private Button fAllFiles; + + public void createControl(Composite parent) { + Composite page = ControlFactory.createComposite(parent, 1); + fAllFiles= ControlFactory.createCheckBox(page, INDEX_ALL_FILES); + setControl(page); + } + + public Properties getProperties() { + Properties props= new Properties(); + props.put(IndexerPreferences.KEY_INDEX_ALL_FILES, String.valueOf(fAllFiles.getSelection())); + return props; + } + + public void setProperties(Properties properties) { + boolean indexAllFiles= TRUE.equals(properties.get(IndexerPreferences.KEY_INDEX_ALL_FILES)); + fAllFiles.setSelection(indexAllFiles); + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/ICOptionContainerExtension.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/ICOptionContainerExtension.java new file mode 100644 index 00000000000..146070e809e --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/ICOptionContainerExtension.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * 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.resources.IProject; + +/** + * Extension for the ICOptionContainer to be used with new project wizards. + * This allows children to access the the project handle. + * @since 4.0 + */ +public interface ICOptionContainerExtension extends ICOptionContainer { + /** + * Returns the project to be created. + * @since 4.0 + */ + IProject getProjectHandle(); +} 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 008e47facc5..f187b57a5b8 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 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 @@ -7,435 +7,390 @@ * * Contributors: * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.ui.dialogs; -import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; -import java.util.List; +import java.util.Map; +import java.util.Properties; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.dialogs.ControlEnableState; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Font; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.IPDOMManager; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ICProject; +import com.ibm.icu.text.Collator; + import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.cdt.ui.index.AbstractIndexerPage; import org.eclipse.cdt.utils.ui.controls.ControlFactory; import org.eclipse.cdt.utils.ui.controls.TabFolderLayout; -import org.eclipse.cdt.internal.ui.CUIMessages; +import org.eclipse.cdt.internal.core.CCoreInternals; +import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; /** * @author Bogdan Gheorghe */ /** - * This IndexerBlock2 is used in the MakeProjectWizardOptionPage and + * This IndexerBlock is used in the MakeProjectWizardOptionPage and * the NewManagedProjectOptionPage to display the indexer options during the creation of * a new project. */ - public class IndexerBlock extends AbstractCOptionPage { + private static final String NODE_INDEXERUI = "indexerUI"; //$NON-NLS-1$ + private static final String ATTRIB_CLASS = "class"; //$NON-NLS-1$ + private static final String ATTRIB_NAME = "name"; //$NON-NLS-1$ + private static final String ATTRIB_INDEXERID = "indexerID"; //$NON-NLS-1$ + + private static final String PREF_PAGE_ID = "org.eclipse.cdt.ui.preferences.IndexerPreferencePage"; //$NON-NLS-1$ private static final String INDEXER_LABEL = CUIPlugin.getResourceString("BaseIndexerBlock.label" ); //$NON-NLS-1$ private static final String INDEXER_DESCRIPTION = CUIPlugin.getResourceString("BaseIndexerBlock.desc"); //$NON-NLS-1$ private static final String INDEXER_COMBO_LABEL = CUIPlugin.getResourceString("BaseIndexerBlock.comboLabel"); //$NON-NLS-1$ - private Combo indexersComboBox; - private HashMap indexerPageMap; - private List indexerPageList; - private String selectedIndexerId = null; - private Composite parentComposite; - private ICOptionPage currentPage; + private PreferenceScopeBlock fPrefScopeBlock; + private Combo fIndexersComboBox; + private HashMap fIndexerConfigMap; + private Composite fIndexerPageComposite; + private AbstractIndexerPage fCurrentPage; + private Properties fCurrentProperties; + private ControlEnableState fEnableState; + private Composite fPreferenceContent; - String initialSelected; - public IndexerBlock(){ super(INDEXER_LABEL); setDescription(INDEXER_DESCRIPTION); - initializeIndexerPageMap(); - } - - /** + initializeIndexerConfigMap(); + } + + /** * Create a profile page only on request */ - protected static class IndexerPageConfiguration { + private static class IndexerConfig { + private AbstractIndexerPage fPage; + private IConfigurationElement fElement; - ICOptionPage page; - IConfigurationElement element; - - public IndexerPageConfiguration(IConfigurationElement _element) { - element = _element; + public IndexerConfig(IConfigurationElement element) { + fElement= element; } - public ICOptionPage getPage() throws CoreException { - if (page == null) { - page = (ICOptionPage) element.createExecutableExtension("class"); //$NON-NLS-1$ + public AbstractIndexerPage getPage() throws CoreException { + if (fPage == null) { + try { + fPage= (AbstractIndexerPage) fElement.createExecutableExtension(ATTRIB_CLASS); + } + catch (Exception e) { + CUIPlugin.getDefault().log(e); + } + if (fPage == null) { + fPage= new NullIndexerBlock(); + } } - return page; + return fPage; } + public String getName() { - return element.getAttribute("name"); //$NON-NLS-1$ + return fElement.getAttribute(ATTRIB_NAME); } + public String getIndexerID(){ - return element.getAttribute("indexerID"); //$NON-NLS-1$ + return fElement.getAttribute(ATTRIB_INDEXERID); } } public void createControl(Composite parent) { - Composite composite = ControlFactory.createComposite(parent, 1); - Font font = parent.getFont(); GridLayout layout= ((GridLayout)composite.getLayout()); layout.marginHeight= 0; layout.marginWidth= 0; layout.verticalSpacing= 0; layout.horizontalSpacing= GridData.FILL_HORIZONTAL; composite.setLayoutData(null); - composite.setFont(font); setControl(composite); - Composite scComp = ControlFactory.createComposite(composite, 1); - ((GridLayout)scComp.getLayout()).marginHeight = 0; - ((GridLayout)scComp.getLayout()).marginTop = 5; - scComp.setFont(font); - - // Create a group for discovered indexer's UI - if (createIndexerControls(scComp)) { - // create a composite for discovery profile options - Composite indexPageComposite = ControlFactory.createComposite(composite, 1); - indexPageComposite.setFont(font); - indexPageComposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); - indexPageComposite.setLayout(new TabFolderLayout()); - // Must set the composite parent to super class. - parentComposite = indexPageComposite; - - setPage(); - - } + if (getProject() != null || getContainer() instanceof ICOptionContainerExtension) { + fPrefScopeBlock= new PreferenceScopeBlock(PREF_PAGE_ID) { + protected void onPreferenceScopeChange() { + IndexerBlock.this.onPreferenceScopeChange(); + } + }; + fPrefScopeBlock.createControl(composite); + } + + fPreferenceContent= ControlFactory.createComposite(composite, 1); + layout= ((GridLayout)fPreferenceContent.getLayout()); + layout.marginHeight= 0; + layout.marginWidth= 0; + + Composite isc = ControlFactory.createComposite(fPreferenceContent, 1); + GridLayout gridLayout = ((GridLayout)isc.getLayout()); + gridLayout.makeColumnsEqualWidth= false; + gridLayout.marginHeight = 0; + gridLayout.marginTop = 5; + + // add combo to select indexer + Group group= ControlFactory.createGroup(isc,INDEXER_COMBO_LABEL, 1); + fIndexersComboBox = ControlFactory.createSelectCombo(group,"", ""); //$NON-NLS-1$ //$NON-NLS-2$ + fIndexersComboBox.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + onIndexerChange(); + } + }); + + // add composite for pages + fIndexerPageComposite= ControlFactory.createComposite(fPreferenceContent, 1); + fIndexerPageComposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1)); + fIndexerPageComposite.setLayout(new TabFolderLayout()); + + initializeScope(); + initializeIndexerCombo(); + onPreferenceScopeChange(); parent.layout(true); } - /** - * - */ - private void setPage() { - - String profileId = getCurrentIndexPageId(); - - //If no indexer has been selected, return - if (profileId == null) - return; - - ICOptionPage page = getIndexerPage(profileId); - if (page != null) { - if (page.getControl() == null) { - page.setContainer(getContainer()); - page.createControl(parentComposite); - parentComposite.layout(true); - } - - if (currentPage != null){ - currentPage.setVisible(false); - } - - page.setVisible(true); - } - - setCurrentPage(page); - - if (page instanceof AbstractIndexerPage){ - ((AbstractIndexerPage) page).loadPreferences(); + + private void enablePreferenceContent(boolean enable) { + if (fEnableState != null) { + fEnableState.restore(); + } + if (enable) { + fEnableState= null; + } + else { + fEnableState= ControlEnableState.disable(fPreferenceContent); } } - /** - * @param page - */ - private void setCurrentPage(ICOptionPage page) { - currentPage = page; + private void initializeScope() { + IProject proj= getProject(); + if (fPrefScopeBlock == null) { + return; + } + + int scope= proj == null ? IndexerPreferences.SCOPE_INSTANCE : IndexerPreferences.getScope(proj); + switch(scope) { + case IndexerPreferences.SCOPE_PROJECT_PRIVATE: + fPrefScopeBlock.setProjectLocalScope(); + break; + case IndexerPreferences.SCOPE_PROJECT_SHARED: + fPrefScopeBlock.setProjectScope(); + break; + default: + fPrefScopeBlock.setInstanceScope(); + break; + } } - protected String getCurrentIndexPageId() { - String selectedIndexPageName = getSelectedIndexerID(); - - if (selectedIndexPageName == null) - return null; - - - String selectedIndexPageId = getIndexerPageId(selectedIndexPageName); - - return selectedIndexPageId; - } - - private boolean createIndexerControls(Composite parent) { - Group group= ControlFactory.createGroup(parent,INDEXER_COMBO_LABEL,2); - - // Add discovered indexers combo box - indexersComboBox = ControlFactory.createSelectCombo(group,"", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - //Add combo box listener - indexersComboBox.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - setPage(); - } - }); - //Make sure that the combo box takes up two cells - GridData gridData = (GridData) indexersComboBox.getLayoutData(); - gridData.verticalSpan=2; - - // fill the combobox and set the initial value - for (Iterator items = getIndexerPageIdList().iterator(); items.hasNext();) { - String profileId = (String)items.next(); - String pageName = getIndexerPageName(profileId); - if (pageName != null) { - indexersComboBox.add(pageName); - } + private void initializeIndexerCombo() { + String[] names= new String[fIndexerConfigMap.size()]; + int j= 0; + for (Iterator i = fIndexerConfigMap.values().iterator(); i.hasNext();) { + IndexerConfig config = (IndexerConfig) i.next(); + names[j++]= config.getName(); } + Arrays.sort(names, Collator.getInstance()); + fIndexersComboBox.setItems(names); + } - //See what the preferred indexer is - String indexerId = CCorePlugin.getPDOMManager().getDefaultIndexerId(); - String preferredIndexer = getIndexerPageName(indexerId); - String[] indexerList = indexersComboBox.getItems(); + protected void onPreferenceScopeChange() { + int scope= computeScope(); + if (fCurrentProperties == null || scope != IndexerPreferences.SCOPE_PROJECT_PRIVATE) { + Properties props= IndexerPreferences.getProperties(getProject(), scope); + + String indexerId= props.getProperty(IndexerPreferences.KEY_INDEXER_ID); + if (getIndexerName(indexerId) == null) { + if (fCurrentProperties != null) { + props= fCurrentProperties; + } + else { + props= IndexerPreferences.getProperties(getProject(), IndexerPreferences.SCOPE_INSTANCE); + } + } + fCurrentProperties= props; + } + String indexerId= fCurrentProperties.getProperty(IndexerPreferences.KEY_INDEXER_ID); + String indexerName = getIndexerName(indexerId); + String[] indexerList = fIndexersComboBox.getItems(); int selectedIndex = 0; for (int i=0; i