From 5edeb05a5b0fd3f3d31b26f73262cd9ad3cc9e1f Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Tue, 1 May 2012 19:10:32 -0400 Subject: [PATCH] bug 328007: [sd90] Disablement of property pages depending on preference --- build/org.eclipse.cdt.make.ui/plugin.xml | 4 +- .../plugin.xml | 4 +- .../ui/properties/DiscoveryTab.java | 53 +++++++++++++++- .../ScannerDiscoveryLegacySupport.java | 4 +- core/org.eclipse.cdt.ui/plugin.xml | 9 ++- .../eclipse/cdt/ui/newui/PropertyTester.java | 60 +++++++++++++------ 6 files changed, 106 insertions(+), 28 deletions(-) diff --git a/build/org.eclipse.cdt.make.ui/plugin.xml b/build/org.eclipse.cdt.make.ui/plugin.xml index b93d372f944..25d04fc5613 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.xml +++ b/build/org.eclipse.cdt.make.ui/plugin.xml @@ -502,11 +502,11 @@ ` - + - + diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml index f5c72d2b4ae..aa14d2bdc2a 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml @@ -534,7 +534,7 @@ - + @@ -564,7 +564,7 @@ - + diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/DiscoveryTab.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/DiscoveryTab.java index 1cb3196cbea..18d6660c721 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/DiscoveryTab.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/DiscoveryTab.java @@ -24,10 +24,13 @@ import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set import org.eclipse.cdt.build.internal.core.scannerconfig.CfgDiscoveredPathManager; import org.eclipse.cdt.build.internal.core.scannerconfig.CfgScannerConfigUtil; import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager; +import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; import org.eclipse.cdt.core.model.util.CDTListComparator; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICResourceDescription; import org.eclipse.cdt.core.settings.model.util.CDataUtil; +import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProvidersPage; +import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2; import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2Set; @@ -46,7 +49,9 @@ import org.eclipse.cdt.managedbuilder.core.IInputType; import org.eclipse.cdt.managedbuilder.core.IResourceInfo; import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.IToolChain; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.internal.ui.Messages; +import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.newui.CDTPrefUtil; import org.eclipse.cdt.utils.ui.controls.ControlFactory; import org.eclipse.cdt.utils.ui.controls.TabFolderLayout; @@ -103,6 +108,7 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf private Button reportProblemsCheckBox; private Combo profileComboBox; private Composite profileOptionsComposite; + private Button clearButton; private ICfgScannerConfigBuilderInfo2Set cbi; private Map baseInfoMap; @@ -116,6 +122,8 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf private DiscoveryPageWrapper wrapper = null; + private StatusMessageLine fStatusLine; + /* * (non-Javadoc) * @@ -184,6 +192,9 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf profileOptionsComposite.setLayoutData(gd); profileOptionsComposite.setLayout(new TabFolderLayout()); + fStatusLine = new StatusMessageLine(usercomp, SWT.LEFT, 2); + setEnablement(); + sashForm.setWeights(DEFAULT_SASH_WEIGHTS); } @@ -204,6 +215,7 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf buildInfo.setSelectedProfileId(id); handleDiscoveryProfileChanged(); } + showStatusLine(); } }); reportProblemsCheckBox = setupCheck(autoDiscoveryGroup, @@ -236,7 +248,7 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf Label clearLabel = ControlFactory.createLabel(autoDiscoveryGroup, Messages.DiscoveryTab_ClearDisoveredEntries); // "Clear" button - Button clearButton = ControlFactory.createPushButton(autoDiscoveryGroup, Messages.DiscoveryTab_Clear); + clearButton = ControlFactory.createPushButton(autoDiscoveryGroup, Messages.DiscoveryTab_Clear); GridData gd = (GridData) clearButton.getLayoutData(); gd.grabExcessHorizontalSpace = true; //Bug 331783 - NLS: "Clear" button label in Makefile Project preferences truncated @@ -334,6 +346,37 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf } else { setVisibility(Messages.DiscoveryTab_6); } + + setEnablement(); + } + + private void setEnablement() { + ICConfigurationDescription cfgDescription = page.getResDesc().getConfiguration(); + boolean isEnabled = !LanguageSettingsProvidersPage.isLanguageSettingsProvidersEnabled(getProject()) || ScannerDiscoveryLegacySupport.isMbsLanguageSettingsProviderOn(cfgDescription); + + scopeComboBox.setEnabled(isEnabled); + resTable.setEnabled(isEnabled); + boolean isSCDEnabled = autoDiscoveryCheckBox.getSelection(); + reportProblemsCheckBox.setEnabled(isEnabled && isSCDEnabled); + autoDiscoveryCheckBox.setEnabled(isEnabled); + autoDiscoveryGroup.setEnabled(isEnabled); + clearButton.setEnabled(isEnabled); + + showStatusLine(); + } + + private void showStatusLine() { + ICConfigurationDescription cfgDescription = page.getResDesc().getConfiguration(); + boolean isEnabled = !LanguageSettingsProvidersPage.isLanguageSettingsProvidersEnabled(getProject()) || ScannerDiscoveryLegacySupport.isMbsLanguageSettingsProviderOn(cfgDescription); + IStatus status = null; + if (isEnabled) { + if (autoDiscoveryCheckBox.getSelection()) { + status = new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID, "This discovery method is deprecated, use 'Preprocessor Include Paths' instead."); + } + } else { + status = new Status(IStatus.INFO, CUIPlugin.PLUGIN_ID, "Managed Build language settings provider is not enabled (see 'Preprocessor Include Paths' page)."); + } + fStatusLine.setErrorStatus(status); } private void setVisibility(String errMsg) { @@ -372,7 +415,13 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf buildInfo = (IScannerConfigBuilderInfo2) ti.getData("info"); //$NON-NLS-1$ String selectedProfileId = buildInfo.getSelectedProfileId(); iContext = (CfgInfoContext) ti.getData("cont"); //$NON-NLS-1$ - autoDiscoveryCheckBox.setSelection(buildInfo.isAutoDiscoveryEnabled() + boolean autodiscoveryEnabled2 = buildInfo.isAutoDiscoveryEnabled(); + if (autodiscoveryEnabled2) { + IConfiguration cfg = iContext.getConfiguration(); + ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(cfg); + autodiscoveryEnabled2 = ScannerDiscoveryLegacySupport.isLegacyScannerDiscoveryOn(cfgDescription); + } + autoDiscoveryCheckBox.setSelection(autodiscoveryEnabled2 && !selectedProfileId.equals(ScannerConfigProfileManager.NULL_PROFILE_ID)); reportProblemsCheckBox.setSelection(buildInfo.isProblemReportingEnabled()); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java index 212d31465a5..c8617a3fa56 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/language/settings/providers/ScannerDiscoveryLegacySupport.java @@ -91,8 +91,10 @@ public class ScannerDiscoveryLegacySupport { /** * Check if legacy Scanner Discovery in MBS should be active. + * @noreference This is internal helper method to support compatibility with previous versions + * which is not intended to be referenced by clients. */ - private static boolean isMbsLanguageSettingsProviderOn(ICConfigurationDescription cfgDescription) { + public static boolean isMbsLanguageSettingsProviderOn(ICConfigurationDescription cfgDescription) { if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { List lsProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); for (ILanguageSettingsProvider lsp : lsProviders) { diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 9d7e8e2cb4e..6bb38870bdc 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -3376,7 +3376,10 @@ category="org.eclipse.cdt.ui.newui.Page_head_general"> - + + + + @@ -3940,10 +3943,10 @@ + * 2. Checks value of a preference. Usage: + * + * * @noextend This class is not intended to be subclassed by clients. */ public class PropertyTester extends org.eclipse.core.expressions.PropertyTester { - private static final String KEY_SRC = "isSource"; //$NON-NLS-1$ - private static final String KEY_PAGE = "pageEnabled"; //$NON-NLS-1$ - private static final String VAL_EXP = "export"; //$NON-NLS-1$ - private static final String VAL_TOOL = "toolEdit"; //$NON-NLS-1$ + private static final String KEY_SRC = "isSource"; //$NON-NLS-1$ + private static final String KEY_PREF = "checkPreference"; //$NON-NLS-1$ @Override - public boolean test(Object receiver, String property, Object[] args, - Object expectedValue) { + public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (KEY_SRC.equals(property)) { if (receiver instanceof ITranslationUnit) { - return ((ITranslationUnit)receiver).isSourceUnit(); - } - else if (receiver instanceof IFile) { - IFile file = (IFile)receiver; + return ((ITranslationUnit) receiver).isSourceUnit(); + } else if (receiver instanceof IFile) { + IFile file = (IFile) receiver; return CoreModel.isValidSourceUnitName(file.getProject(), file.getName()); } - } else if (KEY_PAGE.equals(property) - && expectedValue instanceof String) { - String s = (String) expectedValue; - if (VAL_EXP.equalsIgnoreCase(s)) - return CDTPrefUtil.getBool(CDTPrefUtil.KEY_EXPORT); - if (VAL_TOOL.equalsIgnoreCase(s)) - return !CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOTOOLM); + } else if (KEY_PREF.equals(property) && expectedValue instanceof String) { + boolean result = false; + final Pattern pat = Pattern.compile("(.*):(.*)=(.*)"); //$NON-NLS-1$ + Matcher matcher = pat.matcher((String) expectedValue); + if (matcher.matches()) { + String pluginId = matcher.group(1); + String preference = matcher.group(2); + String wantedValue = matcher.group(3); + + IEclipsePreferences node = InstanceScope.INSTANCE.getNode(pluginId); + if (wantedValue != null) { + String actualValue = node.get(preference, ""); //$NON-NLS-1$ + result = wantedValue.equals(actualValue) || (wantedValue.equals("false") && actualValue.isEmpty()); //$NON-NLS-1$ + } else { + try { + result = Arrays.asList(node.keys()).contains(preference); + } catch (BackingStoreException e) { + CUIPlugin.log(e); + } + } + } + return result; } return false; }