mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 20:05:35 +02:00
Using of pooled list refined
This commit is contained in:
parent
d0407361a8
commit
e95e3a02b7
4 changed files with 178 additions and 118 deletions
|
@ -1,12 +1,12 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) and others.
|
* Copyright (c) 2009, 2011 Andrew Gvozdev and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
|
* Andrew Gvozdev - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.core.language.settings.providers;
|
package org.eclipse.cdt.core.language.settings.providers;
|
||||||
|
@ -18,7 +18,6 @@ import java.util.List;
|
||||||
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
|
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
|
||||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||||
import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages;
|
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,6 +130,7 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas
|
||||||
* @param languageId - language id. If {@code null}, then entries defined for
|
* @param languageId - language id. If {@code null}, then entries defined for
|
||||||
* the language scope are returned. See {@link #getLanguageScope()}
|
* the language scope are returned. See {@link #getLanguageScope()}
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||||
if (languageScope==null) {
|
if (languageScope==null) {
|
||||||
if (entries==null)
|
if (entries==null)
|
||||||
|
|
|
@ -70,9 +70,9 @@ public class LanguageSettingsProvidersSerializer {
|
||||||
private static final String ELEM_CONFIGURATION = "configuration"; //$NON-NLS-1$
|
private static final String ELEM_CONFIGURATION = "configuration"; //$NON-NLS-1$
|
||||||
private static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$
|
private static final String ELEM_PROVIDER = "provider"; //$NON-NLS-1$
|
||||||
private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; //$NON-NLS-1$
|
private static final String ELEM_PROVIDER_REFERENCE = "provider-reference"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static ILock serializingLock = Job.getJobManager().newLock();
|
private static ILock serializingLock = Job.getJobManager().newLock();
|
||||||
|
|
||||||
/** Cache of globally available providers to be consumed by calling clients */
|
/** Cache of globally available providers to be consumed by calling clients */
|
||||||
private static Map<String, ILanguageSettingsProvider> rawGlobalWorkspaceProviders = new HashMap<String, ILanguageSettingsProvider>();
|
private static Map<String, ILanguageSettingsProvider> rawGlobalWorkspaceProviders = new HashMap<String, ILanguageSettingsProvider>();
|
||||||
private static Map<String, ILanguageSettingsProvider> globalWorkspaceProviders = new HashMap<String, ILanguageSettingsProvider>();
|
private static Map<String, ILanguageSettingsProvider> globalWorkspaceProviders = new HashMap<String, ILanguageSettingsProvider>();
|
||||||
|
@ -82,7 +82,7 @@ public class LanguageSettingsProvidersSerializer {
|
||||||
private static class ListenerAssociation {
|
private static class ListenerAssociation {
|
||||||
private ICListenerRegisterer listener;
|
private ICListenerRegisterer listener;
|
||||||
private ICConfigurationDescription cfgDescription;
|
private ICConfigurationDescription cfgDescription;
|
||||||
|
|
||||||
public ListenerAssociation(ICListenerRegisterer li, ICConfigurationDescription cfgd) {
|
public ListenerAssociation(ICListenerRegisterer li, ICConfigurationDescription cfgd) {
|
||||||
listener = li;
|
listener = li;
|
||||||
cfgDescription = cfgd;
|
cfgDescription = cfgd;
|
||||||
|
@ -149,7 +149,7 @@ public class LanguageSettingsProvidersSerializer {
|
||||||
private int getProjectCount() {
|
private int getProjectCount() {
|
||||||
return projectCount;
|
return projectCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized int incrementProjectCount() {
|
private synchronized int incrementProjectCount() {
|
||||||
projectCount++;
|
projectCount++;
|
||||||
return projectCount;
|
return projectCount;
|
||||||
|
@ -159,7 +159,7 @@ public class LanguageSettingsProvidersSerializer {
|
||||||
projectCount--;
|
projectCount--;
|
||||||
return projectCount;
|
return projectCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerListener(ICConfigurationDescription cfgDescription) {
|
public void registerListener(ICConfigurationDescription cfgDescription) {
|
||||||
// keep in mind that rawProvider can change
|
// keep in mind that rawProvider can change
|
||||||
|
@ -186,7 +186,7 @@ public class LanguageSettingsProvidersSerializer {
|
||||||
private static class LanguageSettingsChangeEvent implements ILanguageSettingsChangeEvent {
|
private static class LanguageSettingsChangeEvent implements ILanguageSettingsChangeEvent {
|
||||||
private String projectName = null;
|
private String projectName = null;
|
||||||
private Map<String /*cfg*/, LanguageSettingsDelta> deltaMap = new HashMap<String, LanguageSettingsDelta>();
|
private Map<String /*cfg*/, LanguageSettingsDelta> deltaMap = new HashMap<String, LanguageSettingsDelta>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The act of creating event resets internal delta count in configuration state.
|
* The act of creating event resets internal delta count in configuration state.
|
||||||
* That implies that when the event is retrieved it must be fired or delta will go missing.
|
* That implies that when the event is retrieved it must be fired or delta will go missing.
|
||||||
|
@ -315,7 +315,7 @@ public class LanguageSettingsProvidersSerializer {
|
||||||
|
|
||||||
List<ICListenerRegisterer> oldListeners = selectListeners(rawGlobalWorkspaceProviders.values());
|
List<ICListenerRegisterer> oldListeners = selectListeners(rawGlobalWorkspaceProviders.values());
|
||||||
List<ICListenerRegisterer> newListeners = selectListeners(rawProviders);
|
List<ICListenerRegisterer> newListeners = selectListeners(rawProviders);
|
||||||
|
|
||||||
for (ICListenerRegisterer oldListener : oldListeners) {
|
for (ICListenerRegisterer oldListener : oldListeners) {
|
||||||
if (!isObjectInTheList(newListeners, oldListener)) {
|
if (!isObjectInTheList(newListeners, oldListener)) {
|
||||||
LanguageSettingsWorkspaceProvider wspProvider = (LanguageSettingsWorkspaceProvider) globalWorkspaceProviders.get(((ILanguageSettingsProvider)oldListener).getId());
|
LanguageSettingsWorkspaceProvider wspProvider = (LanguageSettingsWorkspaceProvider) globalWorkspaceProviders.get(((ILanguageSettingsProvider)oldListener).getId());
|
||||||
|
@ -324,7 +324,7 @@ public class LanguageSettingsProvidersSerializer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ICListenerRegisterer newListener : newListeners) {
|
for (ICListenerRegisterer newListener : newListeners) {
|
||||||
if (!isObjectInTheList(oldListeners, newListener)) {
|
if (!isObjectInTheList(oldListeners, newListener)) {
|
||||||
LanguageSettingsWorkspaceProvider wspProvider = (LanguageSettingsWorkspaceProvider) globalWorkspaceProviders.get(((ILanguageSettingsProvider)newListener).getId());
|
LanguageSettingsWorkspaceProvider wspProvider = (LanguageSettingsWorkspaceProvider) globalWorkspaceProviders.get(((ILanguageSettingsProvider)newListener).getId());
|
||||||
|
@ -333,13 +333,13 @@ public class LanguageSettingsProvidersSerializer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rawGlobalWorkspaceProviders = rawWorkspaceProviders;
|
rawGlobalWorkspaceProviders = rawWorkspaceProviders;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<LanguageSettingsChangeEvent> createLanguageLettingsChangeEvents(List<LanguageSettingsSerializable> serializableProviders) {
|
private static List<LanguageSettingsChangeEvent> createLanguageLettingsChangeEvents(List<LanguageSettingsSerializable> serializableProviders) {
|
||||||
List<LanguageSettingsChangeEvent> events = new ArrayList<LanguageSettingsProvidersSerializer.LanguageSettingsChangeEvent>();
|
List<LanguageSettingsChangeEvent> events = new ArrayList<LanguageSettingsProvidersSerializer.LanguageSettingsChangeEvent>();
|
||||||
|
|
||||||
List<String> serializableIds = new ArrayList<String>();
|
List<String> serializableIds = new ArrayList<String>();
|
||||||
for (LanguageSettingsSerializable provider : serializableProviders) {
|
for (LanguageSettingsSerializable provider : serializableProviders) {
|
||||||
serializableIds.add(provider.getId());
|
serializableIds.add(provider.getId());
|
||||||
|
@ -366,15 +366,15 @@ projects:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void serializeLanguageSettingsWorkspace() throws CoreException {
|
public static void serializeLanguageSettingsWorkspace() throws CoreException {
|
||||||
LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace()");
|
LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace()");
|
||||||
|
|
||||||
URI uriStoreWsp = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
|
URI uriStoreWsp = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
|
||||||
List<LanguageSettingsSerializable> serializableWorkspaceProviders = new ArrayList<LanguageSettingsSerializable>();
|
List<LanguageSettingsSerializable> serializableWorkspaceProviders = new ArrayList<LanguageSettingsSerializable>();
|
||||||
for (ILanguageSettingsProvider provider : rawGlobalWorkspaceProviders.values()) {
|
for (ILanguageSettingsProvider provider : rawGlobalWorkspaceProviders.values()) {
|
||||||
|
@ -402,11 +402,11 @@ projects:
|
||||||
Document doc = XmlUtil.newDocument();
|
Document doc = XmlUtil.newDocument();
|
||||||
Element rootElement = XmlUtil.appendElement(doc, ELEM_PLUGIN);
|
Element rootElement = XmlUtil.appendElement(doc, ELEM_PLUGIN);
|
||||||
Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, new String[] {ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID});
|
Element elementExtension = XmlUtil.appendElement(rootElement, ELEM_EXTENSION, new String[] {ATTR_POINT, LanguageSettingsExtensionManager.PROVIDER_EXTENSION_FULL_ID});
|
||||||
|
|
||||||
for (LanguageSettingsSerializable provider : serializableWorkspaceProviders) {
|
for (LanguageSettingsSerializable provider : serializableWorkspaceProviders) {
|
||||||
provider.serialize(elementExtension);
|
provider.serialize(elementExtension);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
serializingLock.acquire();
|
serializingLock.acquire();
|
||||||
XmlUtil.serializeXml(doc, uriStoreWsp);
|
XmlUtil.serializeXml(doc, uriStoreWsp);
|
||||||
|
@ -537,7 +537,7 @@ projects:
|
||||||
public static void serializeLanguageSettings(ICProjectDescription prjDescription) throws CoreException {
|
public static void serializeLanguageSettings(ICProjectDescription prjDescription) throws CoreException {
|
||||||
IProject project = prjDescription.getProject();
|
IProject project = prjDescription.getProject();
|
||||||
LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettings() for " + project);
|
LanguageSettingsLogger.logWarning("LanguageSettingsProvidersSerializer.serializeLanguageSettings() for " + project);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Document to store in project area
|
// Document to store in project area
|
||||||
Document docStorePrj = XmlUtil.newDocument();
|
Document docStorePrj = XmlUtil.newDocument();
|
||||||
|
@ -548,7 +548,7 @@ projects:
|
||||||
|
|
||||||
// The project store should not be absent. Absent store means legacy project, not 0 providers.
|
// The project store should not be absent. Absent store means legacy project, not 0 providers.
|
||||||
IFile fileStorePrj = getStoreInProjectArea(project);
|
IFile fileStorePrj = getStoreInProjectArea(project);
|
||||||
|
|
||||||
URI uriStoreWsp = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
|
URI uriStoreWsp = getStoreInWorkspaceArea(project.getName()+'.'+STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
|
||||||
LanguageSettingsChangeEvent event = null;
|
LanguageSettingsChangeEvent event = null;
|
||||||
|
|
||||||
|
@ -567,7 +567,7 @@ projects:
|
||||||
} else {
|
} else {
|
||||||
new java.io.File(uriStoreWsp).delete();
|
new java.io.File(uriStoreWsp).delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
// manufacture the event only if serialization was successful
|
// manufacture the event only if serialization was successful
|
||||||
event = new LanguageSettingsChangeEvent(prjDescription);
|
event = new LanguageSettingsChangeEvent(prjDescription);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -884,7 +884,7 @@ projects:
|
||||||
}
|
}
|
||||||
return listeners;
|
return listeners;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<ICListenerRegisterer> selectListeners(Collection<ILanguageSettingsProvider> values) {
|
private static List<ICListenerRegisterer> selectListeners(Collection<ILanguageSettingsProvider> values) {
|
||||||
List<ICListenerRegisterer> listeners = new ArrayList<ICListenerRegisterer>();
|
List<ICListenerRegisterer> listeners = new ArrayList<ICListenerRegisterer>();
|
||||||
for (ILanguageSettingsProvider provider : values) {
|
for (ILanguageSettingsProvider provider : values) {
|
||||||
|
@ -913,7 +913,7 @@ projects:
|
||||||
}
|
}
|
||||||
return associations;
|
return associations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregister listeners which are not used anymore and register new listeners.
|
* Unregister listeners which are not used anymore and register new listeners.
|
||||||
* The method is used when project description is applied to workspace.
|
* The method is used when project description is applied to workspace.
|
||||||
|
@ -928,10 +928,10 @@ projects:
|
||||||
|
|
||||||
assertConsistency(oldPrjDescription); // TODO - remove me
|
assertConsistency(oldPrjDescription); // TODO - remove me
|
||||||
assertConsistency(newPrjDescription); // TODO - remove me
|
assertConsistency(newPrjDescription); // TODO - remove me
|
||||||
|
|
||||||
List<ICListenerRegisterer> oldListeners = getListeners(oldPrjDescription);
|
List<ICListenerRegisterer> oldListeners = getListeners(oldPrjDescription);
|
||||||
List<ListenerAssociation> newAssociations = getListenersAssociations(newPrjDescription);
|
List<ListenerAssociation> newAssociations = getListenersAssociations(newPrjDescription);
|
||||||
|
|
||||||
for (ICListenerRegisterer oldListener : oldListeners) {
|
for (ICListenerRegisterer oldListener : oldListeners) {
|
||||||
if (!isListenerInTheListOfAssociations(newAssociations, oldListener)) {
|
if (!isListenerInTheListOfAssociations(newAssociations, oldListener)) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
@ -948,7 +948,7 @@ projects:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ListenerAssociation newListenerAssociation : newAssociations) {
|
for (ListenerAssociation newListenerAssociation : newAssociations) {
|
||||||
ICListenerRegisterer newListener = newListenerAssociation.listener;
|
ICListenerRegisterer newListener = newListenerAssociation.listener;
|
||||||
if (!isObjectInTheList(oldListeners, newListener)) {
|
if (!isObjectInTheList(oldListeners, newListener)) {
|
||||||
|
@ -966,12 +966,12 @@ projects:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deep clone of a list of language settings providers.
|
* Deep clone of a list of language settings providers.
|
||||||
*
|
*
|
||||||
* @param baseProviders - list of providers to clone.
|
* @param baseProviders - list of providers to clone.
|
||||||
* @return newly cloned list.
|
* @return newly cloned list.
|
||||||
*/
|
*/
|
||||||
|
@ -991,19 +991,19 @@ projects:
|
||||||
}
|
}
|
||||||
return new ArrayList<ILanguageSettingsProvider>(newProviders);
|
return new ArrayList<ILanguageSettingsProvider>(newProviders);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a listener that will be notified of changes in language settings.
|
* Adds a listener that will be notified of changes in language settings.
|
||||||
*
|
*
|
||||||
* @param listener the ILanguageMappingChangeListener to add
|
* @param listener the ILanguageMappingChangeListener to add
|
||||||
*/
|
*/
|
||||||
public static void registerLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) {
|
public static void registerLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) {
|
||||||
fLanguageSettingsChangeListeners.add(listener);
|
fLanguageSettingsChangeListeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a language settings change listener.
|
* Removes a language settings change listener.
|
||||||
*
|
*
|
||||||
* @param listener the ILanguageMappingChangeListener to remove.
|
* @param listener the ILanguageMappingChangeListener to remove.
|
||||||
*/
|
*/
|
||||||
public static void unregisterLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) {
|
public static void unregisterLanguageSettingsChangeListener(ILanguageSettingsChangeListener listener) {
|
||||||
|
@ -1012,7 +1012,7 @@ projects:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies all language settings change listeners of a change.
|
* Notifies all language settings change listeners of a change.
|
||||||
*
|
*
|
||||||
* @param event the ILanguageSettingsChangeEvent event to be broadcast.
|
* @param event the ILanguageSettingsChangeEvent event to be broadcast.
|
||||||
*/
|
*/
|
||||||
public static void notifyLanguageSettingsChangeListeners(ILanguageSettingsChangeEvent event) {
|
public static void notifyLanguageSettingsChangeListeners(ILanguageSettingsChangeEvent event) {
|
||||||
|
@ -1025,17 +1025,17 @@ projects:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<ICLanguageSettingEntry> safeGetSettingEntries(ILanguageSettingsProvider provider,
|
private static List<ICLanguageSettingEntry> getSettingEntriesPooled(ILanguageSettingsProvider provider,
|
||||||
ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return provider.getSettingEntries(cfgDescription, rc, languageId);
|
return LanguageSettingsStorage.getPooledList(provider.getSettingEntries(cfgDescription, rc, languageId));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
String cfgId = cfgDescription!=null ? cfgDescription.getId() : null;
|
String cfgId = cfgDescription!=null ? cfgDescription.getId() : null;
|
||||||
String msg = "Exception in provider "+provider.getId()+": getSettingEntries("+cfgId+", "+rc+", "+languageId+")";
|
String msg = "Exception in provider "+provider.getId()+": getSettingEntries("+cfgId+", "+rc+", "+languageId+")";
|
||||||
CCorePlugin.log(msg, e);
|
CCorePlugin.log(msg, e);
|
||||||
// return empty array to prevent climbing up the resource tree
|
// return empty list to prevent getting potentially non-empty list from up the resource tree
|
||||||
return new ArrayList<ICLanguageSettingEntry>(0);
|
return LanguageSettingsStorage.getPooledEmptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1044,21 +1044,21 @@ projects:
|
||||||
* for the given configuration description, resource and language.
|
* for the given configuration description, resource and language.
|
||||||
* This method reaches to the parent folder of the resource recursively
|
* This method reaches to the parent folder of the resource recursively
|
||||||
* in case the resource does not define the entries for the given provider.
|
* in case the resource does not define the entries for the given provider.
|
||||||
*
|
*
|
||||||
* @param provider - language settings provider.
|
* @param provider - language settings provider.
|
||||||
* @param cfgDescription - configuration description.
|
* @param cfgDescription - configuration description.
|
||||||
* @param rc - resource such as file or folder.
|
* @param rc - resource such as file or folder.
|
||||||
* @param languageId - language id.
|
* @param languageId - language id.
|
||||||
*
|
*
|
||||||
* @return the list of setting entries. Never returns {@code null}
|
* @return the list of setting entries which is unmodifiable. Never returns {@code null}
|
||||||
* although individual providers mandated to return {@code null} if no settings defined.
|
* although individual providers mandated to return {@code null} if no settings defined.
|
||||||
*/
|
*/
|
||||||
public static List<ICLanguageSettingEntry> getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
public static List<ICLanguageSettingEntry> getSettingEntriesUpResourceTree(ILanguageSettingsProvider provider, ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||||
Assert.isTrue( !(rc instanceof IWorkspaceRoot) );
|
Assert.isTrue( !(rc instanceof IWorkspaceRoot) );
|
||||||
if (provider!=null) {
|
if (provider!=null) {
|
||||||
List<ICLanguageSettingEntry> entries = safeGetSettingEntries(provider, cfgDescription, rc, languageId);
|
List<ICLanguageSettingEntry> entries = getSettingEntriesPooled(provider, cfgDescription, rc, languageId);
|
||||||
if (entries!=null) {
|
if (entries!=null) {
|
||||||
return new ArrayList<ICLanguageSettingEntry>(entries);
|
return entries;
|
||||||
}
|
}
|
||||||
if (rc!=null) {
|
if (rc!=null) {
|
||||||
IResource parentFolder = (rc instanceof IProject) ? null : rc.getParent();
|
IResource parentFolder = (rc instanceof IProject) ? null : rc.getParent();
|
||||||
|
@ -1066,21 +1066,21 @@ projects:
|
||||||
return getSettingEntriesUpResourceTree(provider, cfgDescription, parentFolder, languageId);
|
return getSettingEntriesUpResourceTree(provider, cfgDescription, parentFolder, languageId);
|
||||||
}
|
}
|
||||||
// if out of parent resources - get default entries for the applicable language scope
|
// if out of parent resources - get default entries for the applicable language scope
|
||||||
entries = safeGetSettingEntries(provider, null, null, languageId);
|
entries = getSettingEntriesPooled(provider, null, null, languageId);
|
||||||
if (entries!=null) {
|
if (entries!=null) {
|
||||||
return new ArrayList<ICLanguageSettingEntry>(entries);
|
return entries;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ArrayList<ICLanguageSettingEntry>(0);
|
return LanguageSettingsStorage.getPooledEmptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds for the provider a nice looking resource tree to present hierarchical view to the user.
|
* Builds for the provider a nice looking resource tree to present hierarchical view to the user.
|
||||||
* Note that it is not advisable to "compact" the tree because of potential loss of information
|
* Note that it is not advisable to "compact" the tree because of potential loss of information
|
||||||
* which is especially important during partial or incremental builds.
|
* which is especially important during partial or incremental builds.
|
||||||
*
|
*
|
||||||
* @param provider - language settings provider to build the tree for.
|
* @param provider - language settings provider to build the tree for.
|
||||||
* @param cfgDescription - configuration description.
|
* @param cfgDescription - configuration description.
|
||||||
* @param languageId - language ID.
|
* @param languageId - language ID.
|
||||||
|
@ -1095,17 +1095,17 @@ projects:
|
||||||
}
|
}
|
||||||
if (members==null)
|
if (members==null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (IResource rc : members) {
|
for (IResource rc : members) {
|
||||||
if (rc instanceof IContainer) {
|
if (rc instanceof IContainer) {
|
||||||
buildResourceTree(provider, cfgDescription, languageId, (IContainer) rc);
|
buildResourceTree(provider, cfgDescription, languageId, (IContainer) rc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int rcNumber = members.length;
|
int rcNumber = members.length;
|
||||||
|
|
||||||
Map<List<ICLanguageSettingEntry>, Integer> listMap = new HashMap<List<ICLanguageSettingEntry>, Integer>();
|
Map<List<ICLanguageSettingEntry>, Integer> listMap = new HashMap<List<ICLanguageSettingEntry>, Integer>();
|
||||||
|
|
||||||
// on the first pass find majority entries
|
// on the first pass find majority entries
|
||||||
List<ICLanguageSettingEntry> majorityEntries = null;
|
List<ICLanguageSettingEntry> majorityEntries = null;
|
||||||
List<ICLanguageSettingEntry> candidate = null;
|
List<ICLanguageSettingEntry> candidate = null;
|
||||||
|
@ -1123,26 +1123,26 @@ projects:
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
if (count>candidateCount) {
|
if (count>candidateCount) {
|
||||||
candidateCount = count;
|
candidateCount = count;
|
||||||
candidate = entries;
|
candidate = entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
listMap.put(entries, count);
|
listMap.put(entries, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (candidateCount > rcNumber/2) {
|
if (candidateCount > rcNumber/2) {
|
||||||
majorityEntries = candidate;
|
majorityEntries = candidate;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (majorityEntries!=null) {
|
if (majorityEntries!=null) {
|
||||||
provider.setSettingEntries(cfgDescription, folder, languageId, majorityEntries);
|
provider.setSettingEntries(cfgDescription, folder, languageId, majorityEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
// second pass - assign the entries to the folders
|
// second pass - assign the entries to the folders
|
||||||
for (IResource rc : members) {
|
for (IResource rc : members) {
|
||||||
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, rc, languageId);
|
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(null, rc, languageId);
|
||||||
|
@ -1178,7 +1178,7 @@ projects:
|
||||||
* for the given configuration description, resource and language. This is a
|
* for the given configuration description, resource and language. This is a
|
||||||
* combined list for all providers taking into account settings of parent folder
|
* combined list for all providers taking into account settings of parent folder
|
||||||
* if settings for the given resource are not defined.
|
* if settings for the given resource are not defined.
|
||||||
*
|
*
|
||||||
* @param cfgDescription - configuration description.
|
* @param cfgDescription - configuration description.
|
||||||
* @param rc - resource such as file or folder.
|
* @param rc - resource such as file or folder.
|
||||||
* @param languageId - language id.
|
* @param languageId - language id.
|
||||||
|
@ -1190,15 +1190,15 @@ projects:
|
||||||
* @param isLocal - {@code true} if "local" entries should be provided and
|
* @param isLocal - {@code true} if "local" entries should be provided and
|
||||||
* {@code false} for "system" entries. This makes sense for include paths where
|
* {@code false} for "system" entries. This makes sense for include paths where
|
||||||
* [#include "..."] is "local" and [#include <...>] is system.
|
* [#include "..."] is "local" and [#include <...>] is system.
|
||||||
*
|
*
|
||||||
* @return the list of setting entries found.
|
* @return the list of setting entries found.
|
||||||
*/
|
*/
|
||||||
private static List<ICLanguageSettingEntry> getSettingEntriesByKind(ICConfigurationDescription cfgDescription,
|
private static List<ICLanguageSettingEntry> getSettingEntriesByKind(ICConfigurationDescription cfgDescription,
|
||||||
IResource rc, String languageId, int kind, boolean checkLocality, boolean isLocal) {
|
IResource rc, String languageId, int kind, boolean checkLocality, boolean isLocal) {
|
||||||
|
|
||||||
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||||
List<String> alreadyAdded = new ArrayList<String>();
|
List<String> alreadyAdded = new ArrayList<String>();
|
||||||
|
|
||||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||||
for (ILanguageSettingsProvider provider: providers) {
|
for (ILanguageSettingsProvider provider: providers) {
|
||||||
List<ICLanguageSettingEntry> providerEntries = getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId);
|
List<ICLanguageSettingEntry> providerEntries = getSettingEntriesUpResourceTree(provider, cfgDescription, rc, languageId);
|
||||||
|
@ -1221,7 +1221,7 @@ projects:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1231,7 +1231,7 @@ projects:
|
||||||
* combined list for all providers taking into account settings of parent folder
|
* combined list for all providers taking into account settings of parent folder
|
||||||
* if settings for the given resource are not defined. For include paths both
|
* if settings for the given resource are not defined. For include paths both
|
||||||
* local (#include "...") and system (#include <...>) entries are returned.
|
* local (#include "...") and system (#include <...>) entries are returned.
|
||||||
*
|
*
|
||||||
* @param cfgDescription - configuration description.
|
* @param cfgDescription - configuration description.
|
||||||
* @param rc - resource such as file or folder.
|
* @param rc - resource such as file or folder.
|
||||||
* @param languageId - language id.
|
* @param languageId - language id.
|
||||||
|
@ -1239,7 +1239,7 @@ projects:
|
||||||
* {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag
|
* {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag
|
||||||
* and it is possible to specify composite kind.
|
* and it is possible to specify composite kind.
|
||||||
* Use {@link ICSettingEntry#ALL} to get all kinds.
|
* Use {@link ICSettingEntry#ALL} to get all kinds.
|
||||||
*
|
*
|
||||||
* @return the list of setting entries.
|
* @return the list of setting entries.
|
||||||
*/
|
*/
|
||||||
public static List<ICLanguageSettingEntry> getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) {
|
public static List<ICLanguageSettingEntry> getSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) {
|
||||||
|
@ -1247,11 +1247,11 @@ projects:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of "system" (such as [#include <...>]) setting entries of a certain kind
|
* Returns the list of "system" (such as [#include <...>]) setting entries of a certain kind
|
||||||
* for the given configuration description, resource and language. This is a
|
* for the given configuration description, resource and language. This is a
|
||||||
* combined list for all providers taking into account settings of parent folder
|
* combined list for all providers taking into account settings of parent folder
|
||||||
* if settings for the given resource are not defined.
|
* if settings for the given resource are not defined.
|
||||||
*
|
*
|
||||||
* @param cfgDescription - configuration description.
|
* @param cfgDescription - configuration description.
|
||||||
* @param rc - resource such as file or folder.
|
* @param rc - resource such as file or folder.
|
||||||
* @param languageId - language id.
|
* @param languageId - language id.
|
||||||
|
@ -1259,7 +1259,7 @@ projects:
|
||||||
* {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag
|
* {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag
|
||||||
* and it is possible to specify composite kind.
|
* and it is possible to specify composite kind.
|
||||||
* Use {@link ICSettingEntry#ALL} to get all kinds.
|
* Use {@link ICSettingEntry#ALL} to get all kinds.
|
||||||
*
|
*
|
||||||
* @return the list of setting entries.
|
* @return the list of setting entries.
|
||||||
*/
|
*/
|
||||||
public static List<ICLanguageSettingEntry> getSystemSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) {
|
public static List<ICLanguageSettingEntry> getSystemSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) {
|
||||||
|
@ -1267,11 +1267,11 @@ projects:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of "local" (such as [#include "..."]) setting entries of a certain kind
|
* Returns the list of "local" (such as [#include "..."]) setting entries of a certain kind
|
||||||
* for the given configuration description, resource and language. This is a
|
* for the given configuration description, resource and language. This is a
|
||||||
* combined list for all providers taking into account settings of parent folder
|
* combined list for all providers taking into account settings of parent folder
|
||||||
* if settings for the given resource are not defined.
|
* if settings for the given resource are not defined.
|
||||||
*
|
*
|
||||||
* @param cfgDescription - configuration description.
|
* @param cfgDescription - configuration description.
|
||||||
* @param rc - resource such as file or folder.
|
* @param rc - resource such as file or folder.
|
||||||
* @param languageId - language id.
|
* @param languageId - language id.
|
||||||
|
@ -1279,7 +1279,7 @@ projects:
|
||||||
* {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag
|
* {@link ICSettingEntry#INCLUDE_PATH} etc. This is a binary flag
|
||||||
* and it is possible to specify composite kind.
|
* and it is possible to specify composite kind.
|
||||||
* Use {@link ICSettingEntry#ALL} to get all kinds.
|
* Use {@link ICSettingEntry#ALL} to get all kinds.
|
||||||
*
|
*
|
||||||
* @return the list of setting entries.
|
* @return the list of setting entries.
|
||||||
*/
|
*/
|
||||||
public static List<ICLanguageSettingEntry> getLocalSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) {
|
public static List<ICLanguageSettingEntry> getLocalSettingEntriesByKind(ICConfigurationDescription cfgDescription, IResource rc, String languageId, int kind) {
|
||||||
|
|
|
@ -55,8 +55,8 @@ public class LanguageSettingsStorage {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <br> Note that this list is <b>unmodifiable</b>. To modify the list copy it, change and use
|
* TODO
|
||||||
* {@link #setSettingEntries(ICConfigurationDescription, IResource, String, List)}.
|
* <br> Note that this list is <b>unmodifiable</b>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||||
|
@ -98,7 +98,7 @@ public class LanguageSettingsStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void setSettingEntries(String rcProjectPath, String languageId, List<ICLanguageSettingEntry> entries) {
|
public void setSettingEntries(String rcProjectPath, String languageId, List<ICLanguageSettingEntry> entries) {
|
||||||
synchronized (fStorage) {
|
synchronized (fStorage) {
|
||||||
|
@ -108,7 +108,7 @@ public class LanguageSettingsStorage {
|
||||||
langMap = new HashMap<String, List<ICLanguageSettingEntry>>();
|
langMap = new HashMap<String, List<ICLanguageSettingEntry>>();
|
||||||
fStorage.put(languageId, langMap);
|
fStorage.put(languageId, langMap);
|
||||||
}
|
}
|
||||||
List<ICLanguageSettingEntry> sortedEntries = listPool.add(Collections.unmodifiableList(sortEntries(entries)));
|
List<ICLanguageSettingEntry> sortedEntries = getPooledList(sortEntries(entries), false);
|
||||||
langMap.put(rcProjectPath, sortedEntries);
|
langMap.put(rcProjectPath, sortedEntries);
|
||||||
} else {
|
} else {
|
||||||
// do not keep nulls in the tables
|
// do not keep nulls in the tables
|
||||||
|
@ -129,7 +129,7 @@ public class LanguageSettingsStorage {
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return fStorage.isEmpty();
|
return fStorage.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all the entries for all configurations, all resources and all languages.
|
* Clear all the entries for all configurations, all resources and all languages.
|
||||||
*/
|
*/
|
||||||
|
@ -239,20 +239,20 @@ public class LanguageSettingsStorage {
|
||||||
private ICLanguageSettingEntry loadSettingEntry(Node parentElement) {
|
private ICLanguageSettingEntry loadSettingEntry(Node parentElement) {
|
||||||
String settingKind = XmlUtil.determineAttributeValue(parentElement, ATTR_KIND);
|
String settingKind = XmlUtil.determineAttributeValue(parentElement, ATTR_KIND);
|
||||||
String settingName = XmlUtil.determineAttributeValue(parentElement, ATTR_NAME);
|
String settingName = XmlUtil.determineAttributeValue(parentElement, ATTR_NAME);
|
||||||
|
|
||||||
NodeList flagNodes = parentElement.getChildNodes();
|
NodeList flagNodes = parentElement.getChildNodes();
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
for (int i=0;i<flagNodes.getLength();i++) {
|
for (int i=0;i<flagNodes.getLength();i++) {
|
||||||
Node flagNode = flagNodes.item(i);
|
Node flagNode = flagNodes.item(i);
|
||||||
if(flagNode.getNodeType() != Node.ELEMENT_NODE || !ELEM_FLAG.equals(flagNode.getNodeName()))
|
if(flagNode.getNodeType() != Node.ELEMENT_NODE || !ELEM_FLAG.equals(flagNode.getNodeName()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
String settingFlags = XmlUtil.determineAttributeValue(flagNode, ATTR_VALUE);
|
String settingFlags = XmlUtil.determineAttributeValue(flagNode, ATTR_VALUE);
|
||||||
int bitFlag = LanguageSettingEntriesSerializer.composeFlags(settingFlags);
|
int bitFlag = LanguageSettingEntriesSerializer.composeFlags(settingFlags);
|
||||||
flags |= bitFlag;
|
flags |= bitFlag;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String settingValue = null;
|
String settingValue = null;
|
||||||
int kind = LanguageSettingEntriesSerializer.stringToKind(settingKind);
|
int kind = LanguageSettingEntriesSerializer.stringToKind(settingKind);
|
||||||
if (kind == ICSettingEntry.MACRO)
|
if (kind == ICSettingEntry.MACRO)
|
||||||
|
@ -319,6 +319,53 @@ public class LanguageSettingsStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the equal list of entries from the pool to conserve the memory.
|
||||||
|
*
|
||||||
|
* @param entries - list of entries to pool.
|
||||||
|
* @param copy - specify {@code true} to copy the list in order to prevent
|
||||||
|
* back-door modification on the original list changes.
|
||||||
|
* @return returns the list of entries from the pool.
|
||||||
|
*/
|
||||||
|
private static List<ICLanguageSettingEntry> getPooledList(List<ICLanguageSettingEntry> entries, boolean copy) {
|
||||||
|
if (entries == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
List<ICLanguageSettingEntry> pooledList = listPool.get(entries);
|
||||||
|
if (pooledList != null) {
|
||||||
|
return pooledList;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entries.size() == 0) {
|
||||||
|
return getPooledEmptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (copy) {
|
||||||
|
entries = new ArrayList<ICLanguageSettingEntry>(entries);
|
||||||
|
}
|
||||||
|
pooledList = Collections.unmodifiableList(entries);
|
||||||
|
return listPool.add(pooledList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the equal list of entries from the pool to conserve the memory.
|
||||||
|
*
|
||||||
|
* @param entries - list of entries to pool.
|
||||||
|
* @return returns the list of entries from the pool.
|
||||||
|
*/
|
||||||
|
public static List<ICLanguageSettingEntry> getPooledList(List<ICLanguageSettingEntry> entries) {
|
||||||
|
return getPooledList(entries, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the empty immutable list which is pooled. Use this call rather than creating
|
||||||
|
* new empty array to ensure that operator '==' can be used instead of deep equals().
|
||||||
|
*/
|
||||||
|
public static List<ICLanguageSettingEntry> getPooledEmptyList() {
|
||||||
|
List<ICLanguageSettingEntry> pooledEmptyList = Collections.emptyList();
|
||||||
|
return listPool.add(pooledEmptyList);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clone storage for the entries. Copies references for lists of entries as a whole.
|
* Clone storage for the entries. Copies references for lists of entries as a whole.
|
||||||
* Note that is OK as the lists kept in storage are unmodifiable.
|
* Note that is OK as the lists kept in storage are unmodifiable.
|
||||||
|
|
|
@ -79,11 +79,11 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
private Tree treeEntries;
|
private Tree treeEntries;
|
||||||
private TreeViewer treeEntriesViewer;
|
private TreeViewer treeEntriesViewer;
|
||||||
private static String currentLanguageId = null;
|
private static String currentLanguageId = null;
|
||||||
|
|
||||||
private Button builtInCheckBox;
|
private Button builtInCheckBox;
|
||||||
private Button enableProvidersCheckBox;
|
private Button enableProvidersCheckBox;
|
||||||
private StatusMessageLine fStatusLine;
|
private StatusMessageLine fStatusLine;
|
||||||
|
|
||||||
private Page_LanguageSettingsProviders masterPropertyPage = null;
|
private Page_LanguageSettingsProviders masterPropertyPage = null;
|
||||||
|
|
||||||
private static final int BUTTON_ADD = 0;
|
private static final int BUTTON_ADD = 0;
|
||||||
|
@ -105,15 +105,15 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
|
|
||||||
private Map<String, List<ILanguageSettingsProvider>> initialProvidersMap = new HashMap<String, List<ILanguageSettingsProvider>>();
|
private Map<String, List<ILanguageSettingsProvider>> initialProvidersMap = new HashMap<String, List<ILanguageSettingsProvider>>();
|
||||||
private boolean initialEnablement =false;
|
private boolean initialEnablement =false;
|
||||||
|
|
||||||
private class EntriesTreeLabelProvider extends LanguageSettingsProvidersLabelProvider {
|
private class EntriesTreeLabelProvider extends LanguageSettingsProvidersLabelProvider {
|
||||||
@Override
|
@Override
|
||||||
protected String[] getOverlayKeys(ILanguageSettingsProvider provider) {
|
protected String[] getOverlayKeys(ILanguageSettingsProvider provider) {
|
||||||
String[] overlayKeys = super.getOverlayKeys(provider);
|
String[] overlayKeys = super.getOverlayKeys(provider);
|
||||||
|
|
||||||
// if (LanguageSettingsManager.isWorkspaceProvider(provider))
|
// if (LanguageSettingsManager.isWorkspaceProvider(provider))
|
||||||
// provider = LanguageSettingsManager.getRawWorkspaceProvider(provider.getId());
|
// provider = LanguageSettingsManager.getRawWorkspaceProvider(provider.getId());
|
||||||
//
|
//
|
||||||
if (currentLanguageId != null) {
|
if (currentLanguageId != null) {
|
||||||
IResource rc = getResource();
|
IResource rc = getResource();
|
||||||
List<ICLanguageSettingEntry> entries = getSettingEntries(provider);
|
List<ICLanguageSettingEntry> entries = getSettingEntries(provider);
|
||||||
|
@ -131,7 +131,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
||||||
List<ILanguageSettingsProvider> initialProviders = initialProvidersMap.get(cfgDescription.getId());
|
List<ILanguageSettingsProvider> initialProviders = initialProvidersMap.get(cfgDescription.getId());
|
||||||
|
@ -140,7 +140,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
}
|
}
|
||||||
return overlayKeys;
|
return overlayKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Image getImage(Object element) {
|
public Image getImage(Object element) {
|
||||||
if (element instanceof ICLanguageSettingEntry) {
|
if (element instanceof ICLanguageSettingEntry) {
|
||||||
|
@ -165,21 +165,30 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
return super.getText(element);
|
return super.getText(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Content provider for setting entries tree.
|
* Content provider for setting entries tree.
|
||||||
*/
|
*/
|
||||||
private class EntriesTreeContentProvider implements ITreeContentProvider {
|
private class EntriesTreeContentProvider implements ITreeContentProvider {
|
||||||
|
@Override
|
||||||
public Object[] getElements(Object inputElement) {
|
public Object[] getElements(Object inputElement) {
|
||||||
return getChildren(inputElement);
|
return getChildren(inputElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object[] getChildren(Object parentElement) {
|
public Object[] getChildren(Object parentElement) {
|
||||||
if (parentElement instanceof Object[])
|
if (parentElement instanceof Object[])
|
||||||
return (Object[]) parentElement;
|
return (Object[]) parentElement;
|
||||||
|
|
||||||
if (parentElement instanceof ILanguageSettingsProvider) {
|
if (parentElement instanceof ILanguageSettingsProvider) {
|
||||||
ILanguageSettingsProvider lsProvider = (ILanguageSettingsProvider)parentElement;
|
ILanguageSettingsProvider lsProvider = (ILanguageSettingsProvider)parentElement;
|
||||||
List<ICLanguageSettingEntry> entriesList = getSettingEntriesUpResourceTree(lsProvider);
|
List<ICLanguageSettingEntry> entriesList = getSettingEntriesUpResourceTree(lsProvider);
|
||||||
|
if (entriesList == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert to modifiable list
|
||||||
|
entriesList = new ArrayList<ICLanguageSettingEntry>(entriesList);
|
||||||
|
|
||||||
if (builtInCheckBox.getSelection()==false) {
|
if (builtInCheckBox.getSelection()==false) {
|
||||||
for (Iterator<ICLanguageSettingEntry> iter = entriesList.iterator(); iter.hasNext();) {
|
for (Iterator<ICLanguageSettingEntry> iter = entriesList.iterator(); iter.hasNext();) {
|
||||||
|
@ -189,26 +198,28 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return entriesList.toArray();
|
||||||
if (entriesList!=null) {
|
|
||||||
return entriesList.toArray();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object getParent(Object element) {
|
public Object getParent(Object element) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasChildren(Object element) {
|
public boolean hasChildren(Object element) {
|
||||||
Object[] children = getChildren(element);
|
Object[] children = getChildren(element);
|
||||||
return children!=null && children.length>0;
|
return children!=null && children.length>0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,6 +334,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
columnLanguages.setToolTipText(Messages.AbstractLangsListTab_Languages);
|
columnLanguages.setToolTipText(Messages.AbstractLangsListTab_Languages);
|
||||||
|
|
||||||
treeLanguages.addPaintListener(new PaintListener() {
|
treeLanguages.addPaintListener(new PaintListener() {
|
||||||
|
@Override
|
||||||
public void paintControl(PaintEvent e) {
|
public void paintControl(PaintEvent e) {
|
||||||
int x = treeLanguages.getBounds().width - 5;
|
int x = treeLanguages.getBounds().width - 5;
|
||||||
if (columnLanguages.getWidth() != x)
|
if (columnLanguages.getWidth() != x)
|
||||||
|
@ -340,6 +352,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
|
|
||||||
final TreeColumn treeCol = new TreeColumn(treeEntries, SWT.NONE);
|
final TreeColumn treeCol = new TreeColumn(treeEntries, SWT.NONE);
|
||||||
treeEntries.addPaintListener(new PaintListener() {
|
treeEntries.addPaintListener(new PaintListener() {
|
||||||
|
@Override
|
||||||
public void paintControl(PaintEvent e) {
|
public void paintControl(PaintEvent e) {
|
||||||
int x = treeEntries.getClientArea().width;
|
int x = treeEntries.getClientArea().width;
|
||||||
if (treeCol.getWidth() != x)
|
if (treeCol.getWidth() != x)
|
||||||
|
@ -355,7 +368,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
treeEntriesViewer = new TreeViewer(treeEntries);
|
treeEntriesViewer = new TreeViewer(treeEntries);
|
||||||
treeEntriesViewer.setContentProvider(new EntriesTreeContentProvider());
|
treeEntriesViewer.setContentProvider(new EntriesTreeContentProvider());
|
||||||
treeEntriesViewer.setLabelProvider(new EntriesTreeLabelProvider());
|
treeEntriesViewer.setLabelProvider(new EntriesTreeLabelProvider());
|
||||||
|
|
||||||
treeEntriesViewer.setUseHashlookup(true);
|
treeEntriesViewer.setUseHashlookup(true);
|
||||||
|
|
||||||
treeEntries.addSelectionListener(new SelectionAdapter() {
|
treeEntries.addSelectionListener(new SelectionAdapter() {
|
||||||
|
@ -387,7 +400,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
initialEnablement = ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(page.getProject());
|
initialEnablement = ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(page.getProject());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createControls(Composite parent) {
|
public void createControls(Composite parent) {
|
||||||
super.createControls(parent);
|
super.createControls(parent);
|
||||||
|
@ -395,7 +408,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
GridData gd = (GridData) usercomp.getLayoutData();
|
GridData gd = (GridData) usercomp.getLayoutData();
|
||||||
// Discourage settings entry table from trying to show all its items at once, see bug 264330
|
// Discourage settings entry table from trying to show all its items at once, see bug 264330
|
||||||
gd.heightHint =1;
|
gd.heightHint =1;
|
||||||
|
|
||||||
if (page instanceof Page_LanguageSettingsProviders) {
|
if (page instanceof Page_LanguageSettingsProviders) {
|
||||||
masterPropertyPage = (Page_LanguageSettingsProviders) page;
|
masterPropertyPage = (Page_LanguageSettingsProviders) page;
|
||||||
}
|
}
|
||||||
|
@ -404,7 +417,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
|
|
||||||
// SashForms for each mode
|
// SashForms for each mode
|
||||||
createShowEntriesSashForm();
|
createShowEntriesSashForm();
|
||||||
|
|
||||||
// Status line
|
// Status line
|
||||||
fStatusLine = new StatusMessageLine(usercomp, SWT.LEFT, 2);
|
fStatusLine = new StatusMessageLine(usercomp, SWT.LEFT, 2);
|
||||||
|
|
||||||
|
@ -451,7 +464,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
gd.horizontalSpan = 2;
|
gd.horizontalSpan = 2;
|
||||||
gd.grabExcessVerticalSpace = true;
|
gd.grabExcessVerticalSpace = true;
|
||||||
sashFormEntries.setLayoutData(gd);
|
sashFormEntries.setLayoutData(gd);
|
||||||
|
|
||||||
GridLayout layout = new GridLayout();
|
GridLayout layout = new GridLayout();
|
||||||
sashFormEntries.setLayout(layout);
|
sashFormEntries.setLayout(layout);
|
||||||
|
|
||||||
|
@ -466,7 +479,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
treeLanguages.setEnabled(enable);
|
treeLanguages.setEnabled(enable);
|
||||||
treeEntries.setEnabled(enable);
|
treeEntries.setEnabled(enable);
|
||||||
builtInCheckBox.setEnabled(enable);
|
builtInCheckBox.setEnabled(enable);
|
||||||
|
|
||||||
buttoncomp.setEnabled(enable);
|
buttoncomp.setEnabled(enable);
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
|
@ -475,7 +488,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
disableButtons();
|
disableButtons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disableButtons() {
|
private void disableButtons() {
|
||||||
buttonSetEnabled(BUTTON_ADD, false);
|
buttonSetEnabled(BUTTON_ADD, false);
|
||||||
buttonSetEnabled(BUTTON_EDIT, false);
|
buttonSetEnabled(BUTTON_EDIT, false);
|
||||||
|
@ -499,24 +512,24 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
|
|
||||||
boolean isProviderEditable = provider instanceof ILanguageSettingsEditableProvider;
|
boolean isProviderEditable = provider instanceof ILanguageSettingsEditableProvider;
|
||||||
// boolean isUserProvider = provider instanceof UserLanguageSettingsProvider;
|
// boolean isUserProvider = provider instanceof UserLanguageSettingsProvider;
|
||||||
|
|
||||||
boolean canAdd = isProviderEditable;
|
boolean canAdd = isProviderEditable;
|
||||||
boolean canEdit = isProviderEditable && isEntrySelected;
|
boolean canEdit = isProviderEditable && isEntrySelected;
|
||||||
boolean canDelete = isProviderEditable && isEntrySelected;
|
boolean canDelete = isProviderEditable && isEntrySelected;
|
||||||
boolean canClear = isProviderEditable && isProviderSelected && entries!=null && entries.size()>0;
|
boolean canClear = isProviderEditable && isProviderSelected && entries!=null && entries.size()>0;
|
||||||
|
|
||||||
boolean canMoveUp = false;
|
boolean canMoveUp = false;
|
||||||
boolean canMoveDown = false;
|
boolean canMoveDown = false;
|
||||||
if (isProviderEditable && isEntrySelected && entries!=null) {
|
if (isProviderEditable && isEntrySelected && entries!=null) {
|
||||||
int last = entries.size()-1;
|
int last = entries.size()-1;
|
||||||
int pos = getExactIndex(entries, entry);
|
int pos = getExactIndex(entries, entry);
|
||||||
|
|
||||||
if (pos>=0 && pos<=last) {
|
if (pos>=0 && pos<=last) {
|
||||||
canMoveUp = pos!=0;
|
canMoveUp = pos!=0;
|
||||||
canMoveDown = pos!=last;
|
canMoveDown = pos!=last;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buttonSetText(BUTTON_DELETE, isProviderSelected ? CLEAR_STR : DEL_STR);
|
buttonSetText(BUTTON_DELETE, isProviderSelected ? CLEAR_STR : DEL_STR);
|
||||||
|
|
||||||
buttonSetEnabled(BUTTON_ADD, canAdd);
|
buttonSetEnabled(BUTTON_ADD, canAdd);
|
||||||
|
@ -525,7 +538,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
|
|
||||||
buttonSetEnabled(BUTTON_MOVE_UP, canMoveUp);
|
buttonSetEnabled(BUTTON_MOVE_UP, canMoveUp);
|
||||||
buttonSetEnabled(BUTTON_MOVE_DOWN, canMoveDown);
|
buttonSetEnabled(BUTTON_MOVE_DOWN, canMoveDown);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -655,13 +668,13 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
private void addEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry) {
|
private void addEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry) {
|
||||||
if (provider!=null && entry != null) {
|
if (provider!=null && entry != null) {
|
||||||
String providerId = provider.getId();
|
String providerId = provider.getId();
|
||||||
|
|
||||||
List<ICLanguageSettingEntry> entries = getWritableEntries(provider);
|
List<ICLanguageSettingEntry> entries = getWritableEntries(provider);
|
||||||
ICLanguageSettingEntry selectedEntry = getSelectedEntry();
|
ICLanguageSettingEntry selectedEntry = getSelectedEntry();
|
||||||
int pos = getExactIndex(entries, selectedEntry);
|
int pos = getExactIndex(entries, selectedEntry);
|
||||||
entries.add(pos+1, entry);
|
entries.add(pos+1, entry);
|
||||||
saveEntries(provider, entries);
|
saveEntries(provider, entries);
|
||||||
|
|
||||||
updateTreeEntries();
|
updateTreeEntries();
|
||||||
selectItem(providerId, entry);
|
selectItem(providerId, entry);
|
||||||
updateButtons();
|
updateButtons();
|
||||||
|
@ -692,7 +705,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
ICConfigurationDescription cfgDescription = getConfigurationDescription();
|
||||||
IResource rc = getResource();
|
IResource rc = getResource();
|
||||||
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(cfgDescription, rc, currentLanguageId);
|
List<ICLanguageSettingEntry> entries = provider.getSettingEntries(cfgDescription, rc, currentLanguageId);
|
||||||
if (entries==null) {
|
if (entries == null) {
|
||||||
entries = getSettingEntriesUpResourceTree(provider);
|
entries = getSettingEntriesUpResourceTree(provider);
|
||||||
}
|
}
|
||||||
entries = new ArrayList<ICLanguageSettingEntry>(entries);
|
entries = new ArrayList<ICLanguageSettingEntry>(entries);
|
||||||
|
@ -718,7 +731,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param selectedProvider
|
* @param selectedProvider
|
||||||
* @return
|
* @return
|
||||||
|
@ -768,16 +781,16 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
private void deleteEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry) {
|
private void deleteEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry) {
|
||||||
if (provider!=null && entry != null) {
|
if (provider!=null && entry != null) {
|
||||||
String providerId = provider.getId();
|
String providerId = provider.getId();
|
||||||
|
|
||||||
List<ICLanguageSettingEntry> entries = getWritableEntries(provider);
|
List<ICLanguageSettingEntry> entries = getWritableEntries(provider);
|
||||||
int pos = getExactIndex(getSettingEntriesUpResourceTree(provider), entry);
|
int pos = getExactIndex(entries, entry);
|
||||||
entries.remove(entry);
|
entries.remove(entry);
|
||||||
saveEntries(provider, entries);
|
saveEntries(provider, entries);
|
||||||
|
|
||||||
if (pos>=entries.size())
|
if (pos>=entries.size())
|
||||||
pos = entries.size()-1;
|
pos = entries.size()-1;
|
||||||
ICLanguageSettingEntry nextEntry = pos>=0 ? entries.get(pos) : null;
|
ICLanguageSettingEntry nextEntry = pos>=0 ? entries.get(pos) : null;
|
||||||
|
|
||||||
updateTreeEntries();
|
updateTreeEntries();
|
||||||
selectItem(providerId, nextEntry);
|
selectItem(providerId, nextEntry);
|
||||||
updateButtons();
|
updateButtons();
|
||||||
|
@ -789,7 +802,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
String providerId = provider.getId();
|
String providerId = provider.getId();
|
||||||
List<ICLanguageSettingEntry> empty = new ArrayList<ICLanguageSettingEntry>();
|
List<ICLanguageSettingEntry> empty = new ArrayList<ICLanguageSettingEntry>();
|
||||||
saveEntries(provider, empty);
|
saveEntries(provider, empty);
|
||||||
|
|
||||||
updateTreeEntries();
|
updateTreeEntries();
|
||||||
selectItem(providerId, null);
|
selectItem(providerId, null);
|
||||||
updateButtons();
|
updateButtons();
|
||||||
|
@ -810,13 +823,13 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
private void moveEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry, boolean up) {
|
private void moveEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry, boolean up) {
|
||||||
if (provider!=null && entry != null) {
|
if (provider!=null && entry != null) {
|
||||||
String providerId = provider.getId();
|
String providerId = provider.getId();
|
||||||
|
|
||||||
List<ICLanguageSettingEntry> entries = getWritableEntries(provider);
|
List<ICLanguageSettingEntry> entries = getWritableEntries(provider);
|
||||||
int pos = getExactIndex(entries, entry);
|
int pos = getExactIndex(entries, entry);
|
||||||
int newPos = up ? pos-1 : pos+1;
|
int newPos = up ? pos-1 : pos+1;
|
||||||
Collections.swap(entries, pos, newPos);
|
Collections.swap(entries, pos, newPos);
|
||||||
saveEntries(provider, entries);
|
saveEntries(provider, entries);
|
||||||
|
|
||||||
updateTreeEntries();
|
updateTreeEntries();
|
||||||
selectItem(providerId, entry);
|
selectItem(providerId, entry);
|
||||||
updateButtons();
|
updateButtons();
|
||||||
|
@ -923,7 +936,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
} else {
|
} else {
|
||||||
setAllVisible(true, null);
|
setAllVisible(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTreeLanguages(rcDes);
|
updateTreeLanguages(rcDes);
|
||||||
updateTreeEntries();
|
updateTreeEntries();
|
||||||
if (masterPropertyPage!=null) {
|
if (masterPropertyPage!=null) {
|
||||||
|
@ -950,7 +963,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab {
|
||||||
IResource rc = getResource();
|
IResource rc = getResource();
|
||||||
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
|
||||||
List<ILanguageSettingsProvider> writableProviders = new ArrayList<ILanguageSettingsProvider>(providers.size());
|
List<ILanguageSettingsProvider> writableProviders = new ArrayList<ILanguageSettingsProvider>(providers.size());
|
||||||
|
|
||||||
providers: for (ILanguageSettingsProvider provider : providers) {
|
providers: for (ILanguageSettingsProvider provider : providers) {
|
||||||
ILanguageSettingsEditableProvider writableProvider = null;
|
ILanguageSettingsEditableProvider writableProvider = null;
|
||||||
if (provider instanceof ILanguageSettingsEditableProvider) {
|
if (provider instanceof ILanguageSettingsEditableProvider) {
|
||||||
|
@ -997,7 +1010,7 @@ providers: for (ILanguageSettingsProvider provider : providers) {
|
||||||
List<ILanguageSettingsProvider> providers = srcCfgDescription.getLanguageSettingProviders();
|
List<ILanguageSettingsProvider> providers = srcCfgDescription.getLanguageSettingProviders();
|
||||||
destCfgDescription.setLanguageSettingProviders(providers);
|
destCfgDescription.setLanguageSettingProviders(providers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!page.isForPrefs()) {
|
if (!page.isForPrefs()) {
|
||||||
ICConfigurationDescription sd = srcRcDescription.getConfiguration();
|
ICConfigurationDescription sd = srcRcDescription.getConfiguration();
|
||||||
ICConfigurationDescription dd = destRcDescription.getConfiguration();
|
ICConfigurationDescription dd = destRcDescription.getConfiguration();
|
||||||
|
@ -1038,7 +1051,7 @@ providers: for (ILanguageSettingsProvider provider : providers) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue