From 7104c92f7f7ba9754cd120ea5c2ec9f9824a06a4 Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Mon, 30 Apr 2012 09:53:06 -0400 Subject: [PATCH] clean up --- .../BuiltinSpecsDetectorOptionPage.java | 103 +- .../GCCBuildCommandParserOptionPage.java | 32 - .../schema/LanguageSettingsProvider.exsd | 2 +- core/org.eclipse.cdt.ui/plugin.xml | 6 +- .../LanguageSettingsProviderAssociation.exsd | 69 +- ...ractLanguageSettingProviderOptionPage.java | 9 + .../providers/LanguageSettingEntryDialog.java | 136 +- .../providers/LanguageSettingsEntriesTab.java | 191 ++- ...ageSettingsProviderAssociationManager.java | 203 +-- .../LanguageSettingsProviderTab.java | 1124 +++++++++-------- ...anguageSettingsProvidersLabelProvider.java | 56 +- ...ava => LanguageSettingsProvidersPage.java} | 18 +- .../ui/newui/LanguageSettingsImages.java | 39 +- .../cdt/internal/ui/newui/Messages.java | 33 +- .../cdt/internal/ui/newui/Messages.properties | 33 +- .../cdt/ui/newui/AbstractLangsListTab.java | 8 +- .../eclipse/cdt/ui/newui/ErrorParsTab.java | 2 +- 17 files changed, 1069 insertions(+), 995 deletions(-) rename core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/{Page_LanguageSettingsProviders.java => LanguageSettingsProvidersPage.java} (69%) diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/language/settings/providers/BuiltinSpecsDetectorOptionPage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/language/settings/providers/BuiltinSpecsDetectorOptionPage.java index 2644cc4699f..b94db388875 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/language/settings/providers/BuiltinSpecsDetectorOptionPage.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/language/settings/providers/BuiltinSpecsDetectorOptionPage.java @@ -14,7 +14,6 @@ package org.eclipse.cdt.managedbuilder.internal.ui.language.settings.providers; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.internal.ui.language.settings.providers.AbstractLanguageSettingProviderOptionPage; -import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; import org.eclipse.cdt.managedbuilder.language.settings.providers.AbstractBuiltinSpecsDetector; import org.eclipse.cdt.utils.ui.controls.ControlFactory; import org.eclipse.core.runtime.Assert; @@ -37,25 +36,17 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; /** - * Options page for TODO - * + * Options page for {@link AbstractBuiltinSpecsDetector}. */ public final class BuiltinSpecsDetectorOptionPage extends AbstractLanguageSettingProviderOptionPage { private boolean fEditable; private Text inputCommand; - private StatusMessageLine fStatusLine; private Button allocateConsoleCheckBox; - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) - */ @Override public void createControl(Composite parent) { -// Composite optionsPageComposite = new Composite(composite, SWT.NULL); fEditable = parent.isEnabled(); Composite composite = new Composite(parent, SWT.NONE); @@ -126,93 +117,8 @@ public final class BuiltinSpecsDetectorOptionPage extends AbstractLanguageSettin } } }); - } -// { -// final Button button = new Button(composite, SWT.PUSH); -// button.setFont(parent.getFont()); -// String text = fProvider.isEmpty() ? "Run Now (TODO)" : "Clear"; -// button.setText(text); -//// button.addSelectionListener(this); -// GridData data = new GridData(); -// data.horizontalSpan = 2; -//// data.horizontalAlignment = GridData.BEGINNING; -//// data.widthHint = 60; -// button.setLayoutData(data); -// // TODO -// button.setEnabled(fEditable && !fProvider.isEmpty()); -// -// button.addSelectionListener(new SelectionAdapter() { -// -// @Override -// public void widgetSelected(SelectionEvent evt) { -// if (fProvider.isEmpty()) { -// // TODO -// } else { -// fProvider.clear(); -// } -// // TODO -// button.setEnabled(fEditable && !fProvider.isEmpty()); -// String text = fProvider.isEmpty() ? "Run Now (TODO)" : "Clear"; -// button.setText(text); -// button.pack(); -// } -// -// }); -// -// } - -// // Compiler specs command -// { -// Label label = ControlFactory.createLabel(composite, "Parsing rules:"); -// GridData gd = new GridData(); -// gd.horizontalSpan = 2; -// label.setLayoutData(gd); -//// Label newLabel = new Label(composite, SWT.NONE); -////// ((GridData) newLabel.getLayoutData()).horizontalSpan = 1; -//// newLabel.setText("Command to get compiler specs:"); -// } - - -// createPatternsTable(group, composite); - - - - - - - - -// Group group = new Group(parent, SWT.SHADOW_ETCHED_IN); -// group.setText(DialogsMessages.RegexErrorParserOptionPage_Title); -// -// GridLayout gridLayout = new GridLayout(2, true); -// gridLayout.makeColumnsEqualWidth = false; -// gridLayout.marginRight = -10; -// gridLayout.marginLeft = -4; -// group.setLayout(gridLayout); -// group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); -// -// Composite composite = new Composite(group, SWT.NONE); -// GridLayout layout = new GridLayout(); -// layout.numColumns = 2; -// layout.marginWidth = 1; -// layout.marginHeight = 1; -// layout.marginRight = 1; -// composite.setLayout(layout); -// composite.setLayoutData(new GridData(GridData.FILL_BOTH)); -// Dialog.applyDialogFont(composite); -// -// if (!fEditable) -// createLinkToPreferences(composite); -// -// createPatternsTable(group, composite); -// -// if (fEditable) { -// createButtons(composite); -// } - { allocateConsoleCheckBox = new Button(composite, SWT.CHECK); allocateConsoleCheckBox.setText("Allocate console in the Console View"); @@ -239,13 +145,6 @@ public final class BuiltinSpecsDetectorOptionPage extends AbstractLanguageSettin } -// // Status line -// if (fEditable) { -// fStatusLine = new StatusMessageLine(composite, SWT.LEFT, 2); -// IStatus status = new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID, "Note that currently not all options are persisted (FIXME)"); -// fStatusLine.setErrorStatus(status); -// } - setControl(composite); } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/language/settings/providers/GCCBuildCommandParserOptionPage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/language/settings/providers/GCCBuildCommandParserOptionPage.java index e41126cc3f2..ba4972332cd 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/language/settings/providers/GCCBuildCommandParserOptionPage.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/language/settings/providers/GCCBuildCommandParserOptionPage.java @@ -14,7 +14,6 @@ package org.eclipse.cdt.managedbuilder.internal.ui.language.settings.providers; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.internal.ui.language.settings.providers.AbstractLanguageSettingProviderOptionPage; -import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; import org.eclipse.cdt.managedbuilder.language.settings.providers.AbstractBuildCommandParser; import org.eclipse.cdt.utils.ui.controls.ControlFactory; import org.eclipse.core.runtime.Assert; @@ -43,9 +42,6 @@ public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSetti private Text inputCommand; - private StatusMessageLine fStatusLine; - private Button runOnceRadioButton; - private Button runEveryBuildRadioButton; private Button expandRelativePathCheckBox; private Button scopeProjectRadioButton; @@ -53,14 +49,8 @@ public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSetti private Button scopeFileRadioButton; - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) - */ @Override public void createControl(Composite parent) { -// Composite optionsPageComposite = new Composite(composite, SWT.NULL); fEditable = parent.isEnabled(); final Composite composite = new Composite(parent, SWT.NONE); @@ -116,21 +106,6 @@ public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSetti }); } -// { -// Button button = ControlFactory.createPushButton(composite, "Browse..."); -// button.setEnabled(fEditable); -// button.addSelectionListener(new SelectionAdapter() { -// -// @Override -// public void widgetSelected(SelectionEvent evt) { -//// handleAddr2LineButtonSelected(); -// //updateLaunchConfigurationDialog(); -// } -// -// }); -// -// } - { expandRelativePathCheckBox = new Button(composite, SWT.CHECK); expandRelativePathCheckBox.setText("Use heuristics to resolve paths"); @@ -265,13 +240,6 @@ public final class GCCBuildCommandParserOptionPage extends AbstractLanguageSetti } -// // Status line -// if (fEditable) { -// fStatusLine = new StatusMessageLine(composite, SWT.LEFT, 2); -// IStatus status = new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID, "Note that currently not all options are persisted (FIXME)"); -// fStatusLine.setErrorStatus(status); -// } - setControl(composite); } diff --git a/core/org.eclipse.cdt.core/schema/LanguageSettingsProvider.exsd b/core/org.eclipse.cdt.core/schema/LanguageSettingsProvider.exsd index 9cfae19859f..8c5e164a99d 100644 --- a/core/org.eclipse.cdt.core/schema/LanguageSettingsProvider.exsd +++ b/core/org.eclipse.cdt.core/schema/LanguageSettingsProvider.exsd @@ -226,7 +226,7 @@ The value "true" of this attribute is meaningful only for providers ca - CDT 9.0 + CDT 8.1 diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index c1f25a77721..96f00a9b5b3 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -3372,7 +3372,7 @@ @@ -4337,7 +4337,7 @@ name="Entries" weight="010" helpId="FIXME cdt_u_prop_pns_inc" - parent="org.eclipse.cdt.internal.ui.language.settings.providers.Page_LanguageSettingsProviders" + parent="org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProvidersPage" tooltip="%AllLanguageSettingEntries.tooltip"/> - + - + - [Enter description of this extension point.] + This extension point defines appearance and behavior of UI controls for Language Settings Providers defined with extension point <samp>org.eclipse.cdt.core.LanguageSettingsProvider</samp>. @@ -15,6 +15,9 @@ + + This extension point is used to define appearance and behavior of Language Settings Providers in user interface. + @@ -31,14 +34,14 @@ - + ID of the extension point, not used - + Name of the extension point, not used @@ -49,18 +52,23 @@ + + + The definition of UI elements associated with ID of language settings provider. + + - + ID of language settings provider for which appearance is being defined. - + The path to the provider icon in the defining plugin, for example icons/obj16/picture.gif. @@ -70,7 +78,7 @@ - + Options page for the provider to appear in preferences in Providers tab. @@ -80,14 +88,14 @@ - + Defines if user is allowed to edit provider's entries in UI. - + Defines if user is allowed to clear provider's entries in UI. For some providers like compiler specs detectors that may trigger automatic rerun. @@ -95,11 +103,16 @@ + + + The definition of UI elements associated with type of language settings provider. Providers subclassed from this type will inherit characteristics from closest super-type (unless exact ID association is defined). + + - + Class of language settings provider for which appearance is being defined. @@ -109,7 +122,7 @@ - + The path to the provider icon in the defining plugin, for example icons/obj16/picture.gif. @@ -119,24 +132,24 @@ - + Options page for the provider to appear in preferences in Providers tab. - - - - - - - - + Defines if user is allowed to edit provider's entries in UI. + + + + + + + Defines if user is allowed to clear provider's entries in UI. For some providers like compiler specs detectors that may trigger automatic rerun. @@ -148,7 +161,7 @@ - [Enter the first release in which this extension point appears.] + CDT 8.1 @@ -157,7 +170,7 @@ - [Enter extension point usage example here.] + For an example see definition for org.eclipse.cdt.ui.UserLanguageSettingsProvider. @@ -170,14 +183,18 @@ + - + - [Enter information about supplied implementation of this extension point.] + Copyright (c) 2010, 2012 Andrew Gvozdev 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 - diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/AbstractLanguageSettingProviderOptionPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/AbstractLanguageSettingProviderOptionPage.java index 21f0377857b..61f3f6ee184 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/AbstractLanguageSettingProviderOptionPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/AbstractLanguageSettingProviderOptionPage.java @@ -12,10 +12,19 @@ package org.eclipse.cdt.internal.ui.language.settings.providers; import org.eclipse.cdt.ui.dialogs.AbstractCOptionPage; +/** + * Abstract class to implement language settings providers Options page. + */ public abstract class AbstractLanguageSettingProviderOptionPage extends AbstractCOptionPage { protected LanguageSettingsProviderTab providerTab; protected String providerId; + /** + * Initialize the options page with the owning tab and provider ID. + * + * @param providerTab - provider tab which owns the options page. + * @param providerId - ID of the provider the options page is for. + */ protected void init(LanguageSettingsProviderTab providerTab, String providerId) { this.providerTab = providerTab; this.providerId = providerId; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java index 5142228afc8..977140eab08 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingEntryDialog.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2010, 2010 Andrew Gvozdev and others. + * Copyright (c) 2010, 2012 Andrew Gvozdev 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: - * Andrew Gvozdev (Quoin Inc.) - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.ui.language.settings.providers; @@ -52,6 +52,7 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { private boolean clearValue; private int kind; + private Composite compositeArea; private Label iconComboKind; private ImageCombo comboKind; private ImageCombo comboPathCategory; @@ -70,7 +71,6 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { private Button buttonOk; private Button buttonCancel; - private static final int COMBO_INDEX_INCLUDE_PATH = 0; private static final int COMBO_INDEX_MACRO = 1; private static final int COMBO_INDEX_INCLUDE_FILE = 2; @@ -79,12 +79,12 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { private static final int COMBO_INDEX_LIBRARY_FILE = 5; final private String [] comboKindItems = { - "Include Directory", - "Preprocessor Macro", - "Include File", - "Preprocessor Macros File", - "Library Path", - "Library", + Messages.LanguageSettingEntryDialog_IncludeDirectory, + Messages.LanguageSettingEntryDialog_PreporocessorMacro, + Messages.LanguageSettingEntryDialog_IncludeFile, + Messages.LanguageSettingEntryDialog_PreprocessorMacroFile, + Messages.LanguageSettingEntryDialog_LibraryPath, + Messages.LanguageSettingEntryDialog_Library, }; final private Image[] comboKindImages = { CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_INCLUDES_FOLDER), @@ -100,9 +100,9 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { private static final int COMBO_PATH_INDEX_FILESYSTEM = 2; final private String [] pathCategories = { - "Project-Relative", - "Workspace Path", - "Filesystem", + Messages.LanguageSettingEntryDialog_ProjectRelative, + Messages.LanguageSettingEntryDialog_WorkspacePath, + Messages.LanguageSettingEntryDialog_Filesystem, }; final private Image[] pathCategoryImages = { CDTSharedImages.getImage(CDTSharedImages.IMG_ETOOL_PROJECT), @@ -110,13 +110,11 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_FILESYSTEM), }; - - private ICLanguageSettingEntry[] entries; - private Composite comp1; + public LanguageSettingEntryDialog(Shell parent, ICConfigurationDescription cfgDescription, int kind) { - super(parent, ""); + super(parent, ""); //$NON-NLS-1$ this.cfgDescription = cfgDescription; this.project = cfgDescription.getProjectDescription().getProject(); this.entry = null; @@ -129,7 +127,7 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { * where provided entry is used as a template. */ public LanguageSettingEntryDialog(Shell parent, ICConfigurationDescription cfgDescription, ICLanguageSettingEntry entry, boolean clearValue) { - super(parent, ""); + super(parent, ""); //$NON-NLS-1$ this.cfgDescription = cfgDescription; this.project = cfgDescription.getProjectDescription().getProject(); this.entry = entry; @@ -199,26 +197,26 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { parent.setLayout(new GridLayout(4, false)); GridData gd; - // Composite comp1 - comp1 = new Composite (parent, SWT.NONE); + // Composite for the dialog area + compositeArea = new Composite (parent, SWT.NONE); gd = new GridData(GridData.FILL_HORIZONTAL); gd.verticalAlignment = SWT.TOP; gd.horizontalSpan = 7; - comp1.setLayoutData(gd); - comp1.setLayout(new GridLayout(7, false)); + compositeArea.setLayoutData(gd); + compositeArea.setLayout(new GridLayout(7, false)); // Icon for kind - iconComboKind = new Label (comp1, SWT.NONE); + iconComboKind = new Label (compositeArea, SWT.NONE); gd = new GridData(); gd.verticalAlignment = SWT.TOP; gd.horizontalAlignment = SWT.RIGHT; iconComboKind.setLayoutData(gd); - iconComboKind.setText("Select Kind:"); + iconComboKind.setText(Messages.LanguageSettingEntryDialog_SelectKind); int kindToComboIndex = kindToComboIndex(kind); iconComboKind.setImage(comboKindImages[kindToComboIndex]); // Combo for the setting entry kind - comboKind = new ImageCombo(comp1, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER); + comboKind = new ImageCombo(compositeArea, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER); for (int i = 0; i < comboKindItems.length; i++) { comboKind.add(comboKindItems[i], comboKindImages[i]); } @@ -238,24 +236,22 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { }); comboKind.setEnabled(clearValue); - - // // Icon for path category - final Label comboPathCategoryIcon = new Label (comp1, SWT.NONE); + final Label comboPathCategoryIcon = new Label (compositeArea, SWT.NONE); gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END); gd.verticalAlignment = SWT.TOP; gd.widthHint = 15; comboPathCategoryIcon.setLayoutData(gd); - comboPathCategoryIcon.setText(""); + comboPathCategoryIcon.setText(""); //$NON-NLS-1$ // Combo for path category - comboPathCategory = new ImageCombo(comp1, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER); + comboPathCategory = new ImageCombo(compositeArea, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER); for (int i = 0; i < pathCategories.length; i++) { comboPathCategory.add(pathCategories[i], pathCategoryImages[i]); } int pcindex = COMBO_PATH_INDEX_PROJECT; - if (entry!=null) { - if ( (entry.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH) == 0) { + if (entry != null) { + if ((entry.getFlags() & ICSettingEntry.VALUE_WORKSPACE_PATH) == 0) { pcindex = COMBO_PATH_INDEX_FILESYSTEM; } else { if (entry.getName().startsWith(SLASH)) { @@ -286,13 +282,13 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { }); // Dir/File/Name label - labelInput = new Label(comp1, SWT.NONE); - labelInput.setText("Dir:"); + labelInput = new Label(compositeArea, SWT.NONE); + labelInput.setText(Messages.LanguageSettingEntryDialog_Directory); gd = new GridData(); labelInput.setLayoutData(gd); // Dir/File/Name input - inputName = new Text(comp1, SWT.SINGLE | SWT.BORDER); + inputName = new Text(compositeArea, SWT.SINGLE | SWT.BORDER); if (entry!=null && !clearValue) { inputName.setText(entry.getName()); } @@ -310,14 +306,14 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { inputName.setSelection(0, inputName.getText().length()); // Value label - checkBoxValue = new Label(comp1, SWT.NONE); - checkBoxValue.setText("Value:"); + checkBoxValue = new Label(compositeArea, SWT.NONE); + checkBoxValue.setText(Messages.LanguageSettingEntryDialog_Value); gd = new GridData(); checkBoxValue.setLayoutData(gd); // Path button - buttonBrowse = new Button(comp1, SWT.PUSH); - buttonBrowse.setText("..."); + buttonBrowse = new Button(compositeArea, SWT.PUSH); + buttonBrowse.setText("..."); //$NON-NLS-1$ buttonBrowse.setImage(pathCategoryImages[0]); buttonBrowse.setLayoutData(new GridData()); buttonBrowse.addSelectionListener(new SelectionAdapter() { @@ -328,7 +324,7 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { }); // Variables button - buttonVars = new Button(comp1, SWT.PUSH); + buttonVars = new Button(compositeArea, SWT.PUSH); buttonVars.setText(AbstractCPropertyTab.VARIABLESBUTTON_NAME); buttonVars.setLayoutData(new GridData()); buttonVars.addSelectionListener(new SelectionAdapter() { @@ -340,15 +336,15 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { // Value input. Located after the other controls to get sufficient width int comboPathWidth = comboPathCategory.computeSize(SWT.DEFAULT, SWT.NONE).x; - inputValue = new Text(comp1, SWT.SINGLE | SWT.BORDER); - if (entry!=null && !clearValue) { + inputValue = new Text(compositeArea, SWT.SINGLE | SWT.BORDER); + if (entry != null && !clearValue) { inputValue.setText(entry.getValue()); } gd = new GridData(SWT.FILL, SWT.NONE, false, false); gd.widthHint = comboPathWidth; inputValue.setLayoutData(gd); - if (entry!=null && kind==ICSettingEntry.MACRO && !clearValue) { + if (entry != null && kind == ICSettingEntry.MACRO && !clearValue) { inputValue.setFocus(); inputValue.setSelection(0, inputValue.getText().length()); } @@ -363,18 +359,16 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { // Checkbox "Built-In" checkBoxBuiltIn = new Button(compCheckboxes, SWT.CHECK); - checkBoxBuiltIn.setText("Treat as Built-In (Ignore during build)"); + checkBoxBuiltIn.setText(Messages.LanguageSettingEntryDialog_BuiltInFlag); checkBoxBuiltIn.setSelection(entry!=null && (entry.getFlags()&ICSettingEntry.BUILTIN)!=0); gd = new GridData(GridData.FILL_HORIZONTAL); checkBoxBuiltIn.setLayoutData(gd); checkBoxBuiltIn.addSelectionListener(new SelectionListener() { - @Override public void widgetSelected(SelectionEvent e) { updateImages(); setButtons(); } - @Override public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); @@ -383,18 +377,16 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { // Checkbox "Framework" checkBoxFramework = new Button(compCheckboxes, SWT.CHECK); - checkBoxFramework.setText("Framework folder (Mac only)"); + checkBoxFramework.setText(Messages.LanguageSettingEntryDialog_FrameworkFolder); checkBoxFramework.setSelection(entry!=null && (entry.getFlags()&ICSettingEntry.FRAMEWORKS_MAC)!=0); gd = new GridData(GridData.FILL_HORIZONTAL); checkBoxFramework.setLayoutData(gd); checkBoxFramework.addSelectionListener(new SelectionListener() { - @Override public void widgetSelected(SelectionEvent e) { updateImages(); setButtons(); } - @Override public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); @@ -469,7 +461,7 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { private void setButtons() { int kindSelectionIndex = comboKind.getSelectionIndex(); - boolean isMacroSelected = kindSelectionIndex==COMBO_INDEX_MACRO; + boolean isMacroSelected = (kindSelectionIndex == COMBO_INDEX_MACRO); comboPathCategory.setVisible(!isMacroSelected); buttonBrowse.setVisible(!isMacroSelected); buttonVars.setVisible(!isMacroSelected); @@ -485,27 +477,27 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { switch (kindSelectionIndex) { case COMBO_INDEX_INCLUDE_PATH: case COMBO_INDEX_LIBRARY_PATH: - labelInput.setText("Path:"); + labelInput.setText(Messages.LanguageSettingEntryDialog_Path); break; case COMBO_INDEX_INCLUDE_FILE: case COMBO_INDEX_MACRO_FILE: case COMBO_INDEX_LIBRARY_FILE: - labelInput.setText("File:"); + labelInput.setText(Messages.LanguageSettingEntryDialog_File); break; case COMBO_INDEX_MACRO: default: - labelInput.setText("Name:"); + labelInput.setText(Messages.LanguageSettingEntryDialog_Name); } inputValue.setEnabled(isMacroSelected); int indexPathKind = comboPathCategory.getSelectionIndex(); - boolean isProjectSelected = indexPathKind==COMBO_PATH_INDEX_PROJECT; - boolean isWorkspaceSelected = indexPathKind==COMBO_PATH_INDEX_WORKSPACE; - boolean isFilesystemSelected = indexPathKind==COMBO_PATH_INDEX_FILESYSTEM; + boolean isProjectSelected = (indexPathKind == COMBO_PATH_INDEX_PROJECT); + boolean isWorkspaceSelected = (indexPathKind == COMBO_PATH_INDEX_WORKSPACE); + boolean isFilesystemSelected = (indexPathKind == COMBO_PATH_INDEX_FILESYSTEM); String path = inputName.getText(); - if (path.trim().length()==0) { + if (path.trim().length() == 0) { buttonOk.setEnabled(false); } else { buttonOk.setEnabled((isProjectSelected && !path.startsWith(SLASH)) || @@ -514,12 +506,12 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { buttonVars.setEnabled(isFilesystemSelected); - comp1.layout(true); + compositeArea.layout(true); } @Override public void buttonPressed(SelectionEvent e) { - String s=null; + String str = null; if (e.widget.equals(buttonOk)) { String name = inputName.getText(); text1 = name; @@ -586,39 +578,39 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { if (isDirectory) { switch (comboPathCategory.getSelectionIndex()) { case COMBO_PATH_INDEX_WORKSPACE: - s = AbstractCPropertyTab.getWorkspaceDirDialog(shell, inputName.getText()); + str = AbstractCPropertyTab.getWorkspaceDirDialog(shell, inputName.getText()); break; case COMBO_PATH_INDEX_PROJECT: - s = AbstractCPropertyTab.getProjectDirDialog(shell, inputName.getText(), project); + str = AbstractCPropertyTab.getProjectDirDialog(shell, inputName.getText(), project); break; case COMBO_PATH_INDEX_FILESYSTEM: - s = AbstractCPropertyTab.getFileSystemDirDialog(shell, inputName.getText()); + str = AbstractCPropertyTab.getFileSystemDirDialog(shell, inputName.getText()); break; } } else if (isFile) { switch (comboPathCategory.getSelectionIndex()) { case COMBO_PATH_INDEX_WORKSPACE: - s = AbstractCPropertyTab.getWorkspaceFileDialog(shell, inputName.getText()); + str = AbstractCPropertyTab.getWorkspaceFileDialog(shell, inputName.getText()); break; case COMBO_PATH_INDEX_PROJECT: - s = AbstractCPropertyTab.getProjectFileDialog(shell, inputName.getText(), project); + str = AbstractCPropertyTab.getProjectFileDialog(shell, inputName.getText(), project); break; case COMBO_PATH_INDEX_FILESYSTEM: - s = AbstractCPropertyTab.getFileSystemFileDialog(shell, inputName.getText()); + str = AbstractCPropertyTab.getFileSystemFileDialog(shell, inputName.getText()); break; } } - if (s != null) { - s = strip_wsp(s); - if (comboPathCategory.getSelectionIndex()==COMBO_PATH_INDEX_PROJECT && s.startsWith(SLASH+project.getName()+SLASH)) { - s=s.substring(project.getName().length()+2); + if (str != null) { + str = strip_wsp(str); + if (comboPathCategory.getSelectionIndex()==COMBO_PATH_INDEX_PROJECT && str.startsWith(SLASH+project.getName()+SLASH)) { + str=str.substring(project.getName().length()+2); } - inputName.setText(s); + inputName.setText(str); } } else if (e.widget.equals(buttonVars)) { - s = AbstractCPropertyTab.getVariableDialog(shell, cfgDescription); - if (s != null) inputName.insert(s); + str = AbstractCPropertyTab.getVariableDialog(shell, cfgDescription); + if (str != null) inputName.insert(str); } } @@ -629,7 +621,7 @@ public class LanguageSettingEntryDialog extends AbstractPropertyDialog { private void updateImages() { int indexEntryKind = comboKind.getSelectionIndex(); int indexPathKind = comboPathCategory.getSelectionIndex(); - shell.setText("Add " + comboKindItems[indexEntryKind]); + shell.setText(Messages.LanguageSettingEntryDialog_Add + comboKindItems[indexEntryKind]); int kind = comboIndexToKind(indexEntryKind); int flagBuiltin = checkBoxBuiltIn.getSelection() ? ICSettingEntry.BUILTIN : 0; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java index c50d4a2d8fc..c910e679c62 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsEntriesTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 Andrew Gvozdev and others. + * Copyright (c) 2010, 2012 Andrew Gvozdev 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,7 +8,6 @@ * Contributors: * Andrew Gvozdev - Initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.ui.language.settings.providers; import java.util.ArrayList; @@ -64,7 +63,6 @@ import org.eclipse.cdt.internal.ui.newui.LanguageSettingsImages; import org.eclipse.cdt.internal.ui.newui.Messages; import org.eclipse.cdt.internal.ui.newui.StatusMessageLine; - /** * This tab presents language settings entries categorized by language * settings providers. @@ -79,14 +77,14 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { private Tree treeLanguages; private Tree treeEntries; private TreeViewer treeEntriesViewer; - private static String currentLanguageIdGlobal = null; private String currentLanguageId = null; + private static String currentLanguageIdGlobal = null; private Button builtInCheckBox; private Button enableProvidersCheckBox; private StatusMessageLine fStatusLine; - private Page_LanguageSettingsProviders masterPropertyPage = null; + private LanguageSettingsProvidersPage masterPropertyPage = null; private static final int BUTTON_ADD = 0; private static final int BUTTON_EDIT = 1; @@ -95,7 +93,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { private static final int BUTTON_MOVE_UP = 4; private static final int BUTTON_MOVE_DOWN = 5; - private final static String[] BUTTON_LABELS = new String[6]; + private static final String[] BUTTON_LABELS = new String[6]; { BUTTON_LABELS[BUTTON_ADD] = ADD_STR; BUTTON_LABELS[BUTTON_EDIT] = EDIT_STR; @@ -108,25 +106,25 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { private Map> initialProvidersMap = new HashMap>(); + /** + * Label provider for language settings providers displayed by this tab. + */ private class EntriesTreeLabelProvider extends LanguageSettingsProvidersLabelProvider { @Override protected String[] getOverlayKeys(ILanguageSettingsProvider provider) { String[] overlayKeys = super.getOverlayKeys(provider); -// if (LanguageSettingsManager.isWorkspaceProvider(provider)) -// provider = LanguageSettingsManager.getRawWorkspaceProvider(provider.getId()); -// if (currentLanguageId != null) { IResource rc = getResource(); List entries = getSettingEntries(provider); if (entries == null && !(rc instanceof IProject)) { List entriesParent = getSettingEntriesUpResourceTree(provider); - if (entriesParent != null /*&& entriesParent.size() > 0*/) { + if (entriesParent != null) { overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_PARENT; } } else if (provider instanceof ILanguageSettingsBroadcastingProvider && (page.isForFile() || page.isForFolder())) { // Assuming that the default entries for a resource are always null. - // Using that for performance reasons. See note in PerformDefaults(). + // Using that for performance reasons. See note in performDefaults(). List entriesParent = provider.getSettingEntries(null, null, currentLanguageId); if (entries != null && !entries.equals(entriesParent)) { overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_SETTING; @@ -134,10 +132,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } } - // TODO ICConfigurationDescription cfgDescription = getConfigurationDescription(); List initialProviders = initialProvidersMap.get(cfgDescription.getId()); - if (initialProviders!=null && !initialProviders.contains(provider)) { + if (initialProviders != null && !initialProviders.contains(provider)) { overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_EDITED; } return overlayKeys; @@ -146,8 +143,8 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { @Override public Image getImage(Object element) { if (element instanceof ICLanguageSettingEntry) { - ICLanguageSettingEntry entry = (ICLanguageSettingEntry) element; - return LanguageSettingsImages.getImage(entry); + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + return LanguageSettingsImages.getImage((ICLanguageSettingEntry) element, cfgDescription); } return super.getImage(element); @@ -192,7 +189,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { // convert to modifiable list entriesList = new ArrayList(entriesList); - if (builtInCheckBox.getSelection()==false) { + if (builtInCheckBox.getSelection() == false) { for (Iterator iter = entriesList.iterator(); iter.hasNext();) { ICLanguageSettingEntry entry = iter.next(); if (entry.isBuiltIn()) { @@ -312,6 +309,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { return provider.getSettingEntries(cfgDescription, rc, currentLanguageId); } + /** + * Store original providers to be able to tell whether they were changed by user. + */ private void trackInitialSettings() { if (!page.isForPrefs()) { ICConfigurationDescription[] cfgDescriptions = page.getCfgsEditable(); @@ -325,6 +325,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } } + /** + * Create UI control for languages. + */ private void createTreeForLanguages(Composite parent) { treeLanguages = new Tree(parent, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL); treeLanguages.setLayoutData(new GridData(GridData.FILL_VERTICAL)); @@ -361,6 +364,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { }); } + /** + * Create tree for providers and their entries. + */ private void createTreeForEntries(Composite parent) { treeEntries = new Tree(parent, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); treeEntries.setLayoutData(new GridData(GridData.FILL_VERTICAL)); @@ -408,23 +414,29 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } + /** + * Create sash form. + */ private void createSashForm() { sashFormEntries = new SashForm(usercomp,SWT.HORIZONTAL); - + GridData gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2; gd.grabExcessVerticalSpace = true; sashFormEntries.setLayoutData(gd); - + GridLayout layout = new GridLayout(); sashFormEntries.setLayout(layout); - + createTreeForLanguages(sashFormEntries); createTreeForEntries(sashFormEntries); - + sashFormEntries.setWeights(DEFAULT_ENTRIES_SASH_WEIGHTS); } + /** + * Create check-box to control whether to show built-in entries or not. + */ private void createBuiltInsCheckBox() { builtInCheckBox = setupCheck(usercomp, Messages.AbstractLangsListTab_ShowBuiltin, 1, GridData.FILL_HORIZONTAL); builtInCheckBox.addSelectionListener(new SelectionAdapter() { @@ -437,6 +449,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { builtInCheckBox.setEnabled(true); } + /** + * Create check-box to allow disable/enable language settings providers functionality. + */ private void createEnableProvidersCheckBox() { enableProvidersCheckBox = setupCheck(usercomp, Messages.CDTMainWizardPage_TrySD90, 2, GridData.FILL_HORIZONTAL); enableProvidersCheckBox.addSelectionListener(new SelectionAdapter() { @@ -446,20 +461,12 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { if (masterPropertyPage != null) { masterPropertyPage.setLanguageSettingsProvidersEnabled(enabled); } - - if (!enabled) { - ICConfigurationDescription cfgDescription = getConfigurationDescription(); - if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { - ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(ScannerDiscoveryLegacySupport.getDefaultProvidersLegacy()); - updateData(getResDesc()); - } - } - + enableTabControls(enabled); updateStatusLine(); } }); - + if (masterPropertyPage != null) { // take the flag from master page if available (normally for resource properties) enableProvidersCheckBox.setSelection(masterPropertyPage.isLanguageSettingsProvidersEnabled()); @@ -481,8 +488,8 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { // Discourage settings entry table from trying to show all its items at once, see bug 264330 gd.heightHint =1; - if (page instanceof Page_LanguageSettingsProviders) { - masterPropertyPage = (Page_LanguageSettingsProviders) page; + if (page instanceof LanguageSettingsProvidersPage) { + masterPropertyPage = (LanguageSettingsProvidersPage) page; } trackInitialSettings(); @@ -497,6 +504,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { updateData(getResDesc()); } + /** + * Gray out or restore all controls except enabling check-box. + */ private void enableTabControls(boolean enable) { sashFormEntries.setEnabled(enable); treeLanguages.setEnabled(enable); @@ -508,18 +518,14 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { if (enable) { updateTreeForEntries(); } else { - disableButtons(); + buttonSetEnabled(BUTTON_ADD, false); + buttonSetEnabled(BUTTON_EDIT, false); + buttonSetEnabled(BUTTON_DELETE, false); + buttonSetEnabled(BUTTON_MOVE_UP, false); + buttonSetEnabled(BUTTON_MOVE_DOWN, false); } } - private void disableButtons() { - buttonSetEnabled(BUTTON_ADD, false); - buttonSetEnabled(BUTTON_EDIT, false); - buttonSetEnabled(BUTTON_DELETE, false); - buttonSetEnabled(BUTTON_MOVE_UP, false); - buttonSetEnabled(BUTTON_MOVE_DOWN, false); - } - /** * Updates state for all buttons. Called when table selection changes. */ @@ -579,14 +585,12 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { boolean isAllowedEditing = provider instanceof ILanguageSettingsEditableProvider && LanguageSettingsProviderAssociationManager.isAllowedToEditEntries(provider); if (!isAllowedEditing) { - String msg = "Setting entries for this provider are supplied by the system and are not editable."; - status = new Status(IStatus.INFO, CUIPlugin.PLUGIN_ID, msg); + status = new Status(IStatus.INFO, CUIPlugin.PLUGIN_ID, Messages.LanguageSettingsEntriesTab_Entries_Not_Editable); } } if (status == null || status == Status.OK_STATUS) { if (treeLanguages.getItemCount() <= 0) { - String msg = "Cannot determine toolchain languages."; - status = new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, msg); + status = new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, Messages.LanguageSettingsEntriesTab_Cannot_Determine_Languages); } } fStatusLine.setErrorStatus(status); @@ -640,6 +644,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { return -1; } + /** + * Find TreeItem associated with a provider. + */ private TreeItem findProviderItem(String id) { TreeItem[] providerItems = treeEntries.getItems(); for (TreeItem providerItem : providerItems) { @@ -654,26 +661,31 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { return null; } - private TreeItem findEntryItem(String id, ICLanguageSettingEntry entry) { + /** + * Find TreeItem associated with a provider's entry. + */ + private TreeItem findEntryItem(String providerId, ICLanguageSettingEntry entry) { TreeItem[] providerItems = treeEntries.getItems(); for (TreeItem providerItem : providerItems) { Object providerItemData = providerItem.getData(); if (providerItemData instanceof ILanguageSettingsProvider) { ILanguageSettingsProvider provider = (ILanguageSettingsProvider)providerItemData; - if (provider.getId().equals(id)) { + if (provider.getId().equals(providerId)) { TreeItem[] entryItems = providerItem.getItems(); for (TreeItem entryItem : entryItems) { Object entryItemData = entryItem.getData(); if (entryItemData==entry) return entryItem; } -// return providerItem; } } } return null; } + /** + * Select language settings entry item in the tree. + */ private void selectItem(String providerId, ICLanguageSettingEntry entry) { TreeItem providerItem = findProviderItem(providerId); if (providerItem != null) { @@ -689,6 +701,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } } + /** + * Add language settings entry. + */ private void addEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry) { if (provider != null && entry != null) { String providerId = provider.getId(); @@ -705,6 +720,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } } + /** + * Save entries into provider considering resource parent. + */ private void saveEntries(ILanguageSettingsProvider provider, List entries) { if (provider instanceof ILanguageSettingsEditableProvider) { ICConfigurationDescription cfgDescription = getConfigurationDescription(); @@ -740,6 +758,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { return entries; } + /** + * Call dialog to add settings entry. + */ private void performAdd(ILanguageSettingsProvider selectedProvider) { if (selectedProvider instanceof ILanguageSettingsEditableProvider) { ICConfigurationDescription cfgDescription = getConfigurationDescription(); @@ -748,7 +769,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { if (addDialog.open()) { ICLanguageSettingEntry settingEntry = addDialog.getEntries()[0]; if (settingEntry != null) { - selectedProvider = getEditedCopy((ILanguageSettingsEditableProvider)selectedProvider); + selectedProvider = getWorkingCopy((ILanguageSettingsEditableProvider)selectedProvider); addEntry(selectedProvider, settingEntry); } } @@ -756,10 +777,10 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } /** - * Return provider copy being edited in current session. If the supplied provider is already the edited copy - * return it. If not, create a copy to be edited. + * Return working copy of the provider to edit in current session. If the supplied provider is already + * the working copy return it. If not, create a copy to be edited. */ - private ILanguageSettingsEditableProvider getEditedCopy(ILanguageSettingsEditableProvider provider) { + private ILanguageSettingsEditableProvider getWorkingCopy(ILanguageSettingsEditableProvider provider) { ICConfigurationDescription cfgDescription = getConfigurationDescription(); List initialProviders = initialProvidersMap.get(cfgDescription.getId()); if (initialProviders.contains(provider)) { @@ -771,15 +792,18 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { providers.set(pos, provider); ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(providers); } catch (CloneNotSupportedException e) { - CUIPlugin.log("Internal Error: cannot clone provider "+provider.getId(), e); + CUIPlugin.log("Internal Error: cannot clone provider "+provider.getId(), e); //$NON-NLS-1$ } } else { - CUIPlugin.getDefault().logErrorMessage("Internal Error: cannot find provider "+provider.getId()); + CUIPlugin.log("Internal Error: cannot find provider "+provider.getId(), new Exception()); //$NON-NLS-1$ } } return provider; } + /** + * Call dialog to edit settings entry. + */ private void performEdit(ILanguageSettingsProvider selectedProvider, ICLanguageSettingEntry selectedEntry) { if (selectedProvider instanceof ILanguageSettingsEditableProvider && selectedEntry != null) { ICConfigurationDescription cfgDecsription = getConfigurationDescription(); @@ -787,7 +811,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { if (editDialog.open()) { ICLanguageSettingEntry newEntry = editDialog.getEntries()[0]; if (newEntry != null) { - selectedProvider = getEditedCopy((ILanguageSettingsEditableProvider)selectedProvider); + selectedProvider = getWorkingCopy((ILanguageSettingsEditableProvider)selectedProvider); replaceEntry(selectedProvider, selectedEntry, newEntry); } } @@ -795,6 +819,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } } + /** + * Delete provider's entry and update UI. + */ private void deleteEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry) { if (provider != null && entry != null) { String providerId = provider.getId(); @@ -815,6 +842,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } } + /** + * Replace provider's entry and update UI. + */ private void replaceEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry oldEntry, ICLanguageSettingEntry newEntry) { if (provider != null && oldEntry != null && newEntry != null) { String providerId = provider.getId(); @@ -830,6 +860,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } } + /** + * Clear all provider's entries for the given resource and update UI. + */ private void clearProvider(ILanguageSettingsProvider provider) { if (provider != null) { String providerId = provider.getId(); @@ -842,9 +875,12 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } } + /** + * Clear provider's entries for the given resource or remove one entry depending on selection. + */ private void performDelete(ILanguageSettingsProvider selectedProvider, ICLanguageSettingEntry selectedEntry) { if (selectedProvider instanceof ILanguageSettingsEditableProvider) { - selectedProvider = getEditedCopy((ILanguageSettingsEditableProvider)selectedProvider); + selectedProvider = getWorkingCopy((ILanguageSettingsEditableProvider)selectedProvider); if (selectedEntry != null) { deleteEntry(selectedProvider, selectedEntry); } else { @@ -853,6 +889,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } } + /** + * Move provider's entry up or down. + */ private void moveEntry(ILanguageSettingsProvider provider, ICLanguageSettingEntry entry, boolean up) { if (provider != null && entry != null) { String providerId = provider.getId(); @@ -869,16 +908,22 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } } + /** + * Move provider's entry up. + */ private void performMoveUp(ILanguageSettingsProvider selectedProvider, ICLanguageSettingEntry selectedEntry) { if (selectedEntry != null && (selectedProvider instanceof ILanguageSettingsEditableProvider)) { - selectedProvider = getEditedCopy((ILanguageSettingsEditableProvider)selectedProvider); + selectedProvider = getWorkingCopy((ILanguageSettingsEditableProvider)selectedProvider); moveEntry(selectedProvider, selectedEntry, true); } } + /** + * Move provider's entry down. + */ private void performMoveDown(ILanguageSettingsProvider selectedProvider, ICLanguageSettingEntry selectedEntry) { if (selectedEntry != null && (selectedProvider instanceof ILanguageSettingsEditableProvider)) { - selectedProvider = getEditedCopy((ILanguageSettingsEditableProvider)selectedProvider); + selectedProvider = getWorkingCopy((ILanguageSettingsEditableProvider)selectedProvider); moveEntry(selectedProvider, selectedEntry, false); } } @@ -952,6 +997,9 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } + /** + * Change selection of language. + */ private void selectLanguage(String langId) { currentLanguageId = langId; currentLanguageIdGlobal = currentLanguageId; @@ -965,7 +1013,7 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { } /** - * Called when configuration changed Refreshes languages list entries tree. + * Update the tab. Called when configuration changes. */ @Override public void updateData(ICResourceDescription rcDes) { @@ -1003,45 +1051,45 @@ public class LanguageSettingsEntriesTab extends AbstractCPropertyTab { // we use null for resetting file/folder resource which should be correct in most cases. // Count that as a feature. ICConfigurationDescription cfgDescription = getConfigurationDescription(); - if (!(cfgDescription instanceof ILanguageSettingsProvidersKeeper)) + if (!(cfgDescription instanceof ILanguageSettingsProvidersKeeper)) { return; + } boolean changed = false; IResource rc = getResource(); List oldProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); List newProviders = new ArrayList(oldProviders.size()); + // clear entries for a given resource for all languages where applicable providers: for (ILanguageSettingsProvider provider : oldProviders) { ILanguageSettingsEditableProvider providerCopy = null; if (provider instanceof ILanguageSettingsEditableProvider) { for (TreeItem langItems : treeLanguages.getItems()) { String langId = (String)langItems.getData(); - if (langId!=null) { - if (provider.getSettingEntries(cfgDescription, rc, langId)!=null) { + if (langId != null) { + if (provider.getSettingEntries(cfgDescription, rc, langId) != null) { if (providerCopy == null) { // copy providers to be able to "Cancel" in UI providerCopy = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider) provider, true); if (providerCopy == null) { continue providers; } - providerCopy.setSettingEntries(cfgDescription, rc, langId, null); - changed = true; } + providerCopy.setSettingEntries(cfgDescription, rc, langId, null); + changed = true; } } } } - if (providerCopy!=null) + if (providerCopy != null) { newProviders.add(providerCopy); - else + } else { newProviders.add(provider); + } } if (changed) { ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(newProviders); -// updateTreeEntries(); -// updateData(getResDesc()); - List tableItems = getProviders(currentLanguageId); - treeEntriesViewer.setInput(tableItems.toArray(new Object[tableItems.size()])); + updateTreeForEntries(); } } } @@ -1068,6 +1116,9 @@ providers: for (ILanguageSettingsProvider provider : oldProviders) { setLanguageSettingsProvidersFunctionalityEnablement(); } + /** + * TODO + */ private void setLanguageSettingsProvidersFunctionalityEnablement() { if (page.isForProject() && enableProvidersCheckBox != null) { boolean enabled = enableProvidersCheckBox.getSelection(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociationManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociationManager.java index beb4f420048..7cb5c087873 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociationManager.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderAssociationManager.java @@ -17,7 +17,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; @@ -30,8 +29,16 @@ import org.eclipse.cdt.ui.CDTSharedImages; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.dialogs.ICOptionPage; +/** + * This class manages extensions of extension point org.eclipse.cdt.core.LanguageSettingsProvider + * which defines appearance and behavior of UI controls for Language Settings Providers. + * + * @noextend This class is not intended to be subclassed by clients. + * @noinstantiate This class is not intended to be instantiated by clients. + */ public class LanguageSettingsProviderAssociationManager { - public static final String LANGUAGE_SETTINGS_PROVIDER_UI = "LanguageSettingsProviderAssociation"; //$NON-NLS-1$ + /** Name of the extension point for contributing language settings provider associations */ + private static final String PROVIDER_ASSOCIATION_EXTENSION_POINT_SIMPLE_ID = "LanguageSettingsProviderAssociation"; //$NON-NLS-1$ private static final String ELEM_ID_ASSOCIATION = "id-association"; //$NON-NLS-1$ private static final String ELEM_CLASS_ASSOCIATION = "class-association"; //$NON-NLS-1$ @@ -42,30 +49,27 @@ public class LanguageSettingsProviderAssociationManager { private static final String ATTR_UI_CLEAR_ENTRIES = "ui-clear-entries"; //$NON-NLS-1$ private static final String ATTR_UI_EDIT_ENTRIES = "ui-edit-entries"; //$NON-NLS-1$ - private static List loadedIcons = null; - private static Map fImagesUrlById = null; - private static Map fImagesUrlByClass = null; - private static List fRegirestedIds = null; - private static List fRegisteredClasses = null; + private static boolean isLoaded = false; + private static List loadedIcons = new ArrayList(); + private static Map fImagesUrlById = new HashMap(); + private static Map fImagesUrlByClass = new HashMap(); + private static List fRegirestedIds = new ArrayList(); + private static List fRegisteredClasses = new ArrayList(); - private static Map> fAssociationsById = null; - private static Map> fAssociationsByClass = null; + private static Map> fAssociationsById = new HashMap>(); + private static Map> fAssociationsByClass = new HashMap>(); + /** + * Load extensions into memory maps. + */ private static void loadExtensions() { - if (loadedIcons!=null) { + if (isLoaded) { return; } - if (loadedIcons==null) loadedIcons = new ArrayList(); - if (fImagesUrlById==null) fImagesUrlById = new HashMap(); - if (fImagesUrlByClass==null) fImagesUrlByClass = new HashMap(); - if (fRegirestedIds==null) fRegirestedIds = new ArrayList(); - if (fRegisteredClasses==null) fRegisteredClasses = new ArrayList(); - - if (fAssociationsById==null) fAssociationsById = new HashMap>(); - if (fAssociationsByClass==null) fAssociationsByClass = new HashMap>(); + isLoaded = true; IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, LANGUAGE_SETTINGS_PROVIDER_UI); + IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, PROVIDER_ASSOCIATION_EXTENSION_POINT_SIMPLE_ID); if (extension != null) { IExtension[] extensions = extension.getExtensions(); for (IExtension ext : extensions) { @@ -79,23 +83,23 @@ public class LanguageSettingsProviderAssociationManager { fRegirestedIds.add(id); Map properties = new HashMap(); - sensiblePut(properties, ATTR_PAGE, cfgEl.getAttribute(ATTR_PAGE)); - sensiblePut(properties, ATTR_UI_CLEAR_ENTRIES, cfgEl.getAttribute(ATTR_UI_CLEAR_ENTRIES)); - sensiblePut(properties, ATTR_UI_EDIT_ENTRIES, cfgEl.getAttribute(ATTR_UI_EDIT_ENTRIES)); + putNotEmpty(properties, ATTR_PAGE, cfgEl.getAttribute(ATTR_PAGE)); + putNotEmpty(properties, ATTR_UI_CLEAR_ENTRIES, cfgEl.getAttribute(ATTR_UI_CLEAR_ENTRIES)); + putNotEmpty(properties, ATTR_UI_EDIT_ENTRIES, cfgEl.getAttribute(ATTR_UI_EDIT_ENTRIES)); fAssociationsById.put(id, properties); } else if (cfgEl.getName().equals(ELEM_CLASS_ASSOCIATION)) { String className = cfgEl.getAttribute(ATTR_CLASS); URL url = getIconUrl(cfgEl); fImagesUrlByClass.put(className, url); String pageClass = cfgEl.getAttribute(ATTR_PAGE); - if (pageClass!=null && pageClass.length()>0) { + if (pageClass != null && pageClass.length() > 0) { fRegisteredClasses.add(className); } Map properties = new HashMap(); - sensiblePut(properties, ATTR_PAGE, cfgEl.getAttribute(ATTR_PAGE)); - sensiblePut(properties, ATTR_UI_CLEAR_ENTRIES, cfgEl.getAttribute(ATTR_UI_CLEAR_ENTRIES)); - sensiblePut(properties, ATTR_UI_EDIT_ENTRIES, cfgEl.getAttribute(ATTR_UI_EDIT_ENTRIES)); + putNotEmpty(properties, ATTR_PAGE, cfgEl.getAttribute(ATTR_PAGE)); + putNotEmpty(properties, ATTR_UI_CLEAR_ENTRIES, cfgEl.getAttribute(ATTR_UI_CLEAR_ENTRIES)); + putNotEmpty(properties, ATTR_UI_EDIT_ENTRIES, cfgEl.getAttribute(ATTR_UI_EDIT_ENTRIES)); fAssociationsByClass.put(className, properties); } } @@ -104,11 +108,17 @@ public class LanguageSettingsProviderAssociationManager { } - private static void sensiblePut(Map properties, String key, String value) { + /** + * Put value into properties ignoring nulls. + */ + private static void putNotEmpty(Map properties, String key, String value) { if (value != null) properties.put(key, value); } + /** + * Find icon URL in its bundle. + */ private static URL getIconUrl(IConfigurationElement config) { URL url = null; try { @@ -116,33 +126,42 @@ public class LanguageSettingsProviderAssociationManager { if (iconName != null) { URL pluginInstallUrl = Platform.getBundle(config.getDeclaringExtension().getContributor().getName()).getEntry("/"); //$NON-NLS-1$ url = new URL(pluginInstallUrl, iconName); - if (loadedIcons.contains(url)) + if (loadedIcons.contains(url)) { return url; + } } - } catch (MalformedURLException exception) {} + } catch (MalformedURLException e) { + CUIPlugin.log(e); + } loadedIcons.add(url); - if (url!=null) { + if (url != null) { CDTSharedImages.register(url); } return url; } - public static URL getImageUrl(String id) { - if (fImagesUrlById==null) { - loadExtensions(); - } - return fImagesUrlById.get(id); + /** + * Get image URL for language settings provider with the given ID. + * + * @param providerId - ID of language settings provider. + * @return image URL or {@code null}. + */ + public static URL getImageUrl(String providerId) { + loadExtensions(); + return fImagesUrlById.get(providerId); } + /** + * Create an Options page for language settings provider with given ID. + */ private static ICOptionPage createOptionsPageById(String providerId) { - if (fRegirestedIds==null) { - loadExtensions(); - } + loadExtensions(); + if (fRegirestedIds.contains(providerId)) { IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, LANGUAGE_SETTINGS_PROVIDER_UI); + IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, PROVIDER_ASSOCIATION_EXTENSION_POINT_SIMPLE_ID); if (extension != null) { IExtension[] extensions = extension.getExtensions(); for (IExtension ext : extensions) { @@ -154,7 +173,7 @@ public class LanguageSettingsProviderAssociationManager { String id = cfgEl.getAttribute(ATTR_ID); if (providerId.equals(id)) { String pageClass = cfgEl.getAttribute(ATTR_PAGE); - if (pageClass!=null && pageClass.trim().length()>0) { + if (pageClass != null && pageClass.trim().length() > 0) { ICOptionPage page = (ICOptionPage) cfgEl.createExecutableExtension(ATTR_PAGE); return page; } @@ -170,13 +189,15 @@ public class LanguageSettingsProviderAssociationManager { return null; } + /** + * Create an Options page for language settings provider class by its name. + */ private static ICOptionPage createOptionsPageByClass(String providerClassName) { - if (fRegisteredClasses==null) { - loadExtensions(); - } + loadExtensions(); + if (fRegisteredClasses.contains(providerClassName)) { IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, LANGUAGE_SETTINGS_PROVIDER_UI); + IExtensionPoint extension = registry.getExtensionPoint(CUIPlugin.PLUGIN_ID, PROVIDER_ASSOCIATION_EXTENSION_POINT_SIMPLE_ID); if (extension != null) { IExtension[] extensions = extension.getExtensions(); for (IExtension ext : extensions) { @@ -208,31 +229,35 @@ public class LanguageSettingsProviderAssociationManager { * Returns Language Settings Provider image registered for closest superclass * or interface. * - * @param clazz - class to find Language Settings Provider image. + * @param providerClass - class to find Language Settings Provider image. * @return image or {@code null} */ - public static URL getImage(Class clazz) { + public static URL getImage(Class providerClass) { URL url = null; - outer: for (Class cl=clazz;cl!=null;cl=cl.getSuperclass()) { - url = getImageURL(cl); - if (url!=null) + outer: for (Class c = providerClass; c != null; c = c.getSuperclass()) { + url = getImageURL(c); + if (url != null) { break; + } - // this does not check for superinterfaces, feel free to implement as needed - for (Class in : cl.getInterfaces()) { - url = getImageURL(in); - if (url!=null) + // this does not check for super-interfaces, feel free to implement as needed + for (Class i : c.getInterfaces()) { + url = getImageURL(i); + if (url != null) { break outer; + } } } return url; } + /** + * Return image URL registered for the given class. + */ private static URL getImageURL(Class clazz) { String className = clazz.getCanonicalName(); - Set> entrySet = fImagesUrlByClass.entrySet(); - for (Entry entry : entrySet) { + for (Entry entry : fImagesUrlByClass.entrySet()) { if (entry.getKey().equals(className)) { return entry.getValue(); } @@ -241,36 +266,42 @@ public class LanguageSettingsProviderAssociationManager { } /** - * Returns Language Settings Provider image registered for closest superclass. - * @param provider TODO - * @return image or {@code null} + * Returns language settings provider Options page registered for closest superclass. + * + * @param provider - instance of provider to create Options page for. + * @return image or {@code null}. */ public static ICOptionPage createOptionsPage(ILanguageSettingsProvider provider) { String id = provider.getId(); ICOptionPage optionsPage = createOptionsPageById(id); - if (optionsPage!=null) { + if (optionsPage != null) { return optionsPage; } Class clazz = provider.getClass(); - outer: for (Class cl=clazz;cl!=null;cl=cl.getSuperclass()) { - optionsPage = createOptionsPageByClass(cl); - if (optionsPage!=null) + outer: for (Class c = clazz ;c != null; c = c.getSuperclass()) { + optionsPage = createOptionsPageByClass(c); + if (optionsPage != null) { break; + } - // this does not check for superinterfaces, feel free to implement as needed - for (Class in : cl.getInterfaces()) { - optionsPage = createOptionsPageByClass(in); - if (optionsPage!=null) + // this does not check for super-interfaces, feel free to implement as needed + for (Class i : c.getInterfaces()) { + optionsPage = createOptionsPageByClass(i); + if (optionsPage != null) { break outer; + } } } return optionsPage; } - private static ICOptionPage createOptionsPageByClass(Class c) { + /** + * Create an Options page for language settings provider class. + */ + private static ICOptionPage createOptionsPageByClass(Class clazz) { ICOptionPage optionsPage = null; - String className = c.getCanonicalName(); + String className = clazz.getCanonicalName(); if (fRegisteredClasses.contains(className)) { optionsPage = createOptionsPageByClass(className); } @@ -278,9 +309,7 @@ public class LanguageSettingsProviderAssociationManager { } /** - * Returns TODO for id or closest superclass. - * @param provider TODO - * @return TODO + * Returns value of the attribute of the provider by id or closest superclass. */ private static boolean getBooleanAttribute(ILanguageSettingsProvider provider, String attr) { loadExtensions(); @@ -292,16 +321,16 @@ public class LanguageSettingsProviderAssociationManager { return Boolean.parseBoolean(properties.get(attr)); } - for (Class clazz=provider.getClass();clazz!=null;clazz=clazz.getSuperclass()) { - String className = clazz.getCanonicalName(); + for (Class c = provider.getClass();c != null; c = c.getSuperclass()) { + String className = c.getCanonicalName(); properties = fAssociationsByClass.get(className); if (properties != null) { return Boolean.parseBoolean(properties.get(attr)); } // this does not check for superinterfaces, feel free to implement as needed - for (Class iface : clazz.getInterfaces()) { - String interfaceName = iface.getCanonicalName(); + for (Class i : c.getInterfaces()) { + String interfaceName = i.getCanonicalName(); properties = fAssociationsByClass.get(interfaceName); if (properties != null) { return Boolean.parseBoolean(properties.get(attr)); @@ -312,21 +341,21 @@ public class LanguageSettingsProviderAssociationManager { } /** - * Returns TODO for id or closest superclass. - * @param provider TODO - * @return TODO - */ - public static boolean isAllowedToClear(ILanguageSettingsProvider provider) { - return getBooleanAttribute(provider, ATTR_UI_CLEAR_ENTRIES); - } - - /** - * Returns TODO for id or closest superclass. - * @param provider TODO - * @return TODO + * Check if the user is allowed to edit language settings provider entries in UI. + * @param provider - language settings provider. + * @return {@code true} if editing is allowed or {@code false} if not. */ public static boolean isAllowedToEditEntries(ILanguageSettingsProvider provider) { return getBooleanAttribute(provider, ATTR_UI_EDIT_ENTRIES); } + /** + * Check if the user is allowed to clear language settings provider entries in UI. + * @param provider - language settings provider. + * @return {@code true} if clearing is allowed or {@code false} if not. + */ + public static boolean isAllowedToClear(ILanguageSettingsProvider provider) { + return getBooleanAttribute(provider, ATTR_UI_CLEAR_ENTRIES); + } + } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java index cb728373f42..4644fd21c3d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProviderTab.java @@ -30,6 +30,7 @@ import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.IDecoration; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.events.SelectionAdapter; @@ -76,7 +77,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { private static final String TEST_PLUGIN_ID_PATTERN = "org.eclipse.cdt.*.tests.*"; //$NON-NLS-1$ private static final String CLEAR_STR = Messages.LanguageSettingsProviderTab_Clear; - private static final String RESET_STR = "Reset"; + private static final String RESET_STR = Messages.LanguageSettingsProviderTab_Reset; private static final int BUTTON_CLEAR = 0; private static final int BUTTON_RESET = 1; @@ -100,7 +101,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { private Link linkToWorkspacePreferences = null; private Button projectStorageCheckBox = null; - private Page_LanguageSettingsProviders masterPropertyPage = null; + private LanguageSettingsProvidersPage masterPropertyPage = null; /** * List of providers presented to the user. @@ -111,86 +112,9 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { private final Map optionsPageMap = new HashMap(); private Map> initialProvidersByCfg = new HashMap>(); - private boolean initialEnablement = false; - /** - * Returns current working copy of the provider. Creates one if it has not been created yet. - * Used by option pages when there is a need to modify the provider. - * Warning: Do not cache the result as the provider can be replaced at any time. - * @param providerId - * - * @return the provider + * Label provider for language settings providers displayed by this tab. */ - public ILanguageSettingsProvider getWorkingCopy(String providerId) { - ILanguageSettingsProvider provider = findProvider(providerId, presentedProviders); - if (isWorkingCopy(provider)) - return provider; - - ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); - Assert.isTrue(rawProvider instanceof ILanguageSettingsEditableProvider); - - ILanguageSettingsEditableProvider newProvider = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider)rawProvider, true); - if (newProvider != null) { - replaceSelectedProvider(newProvider); - // Warning: Do not initializeOptionsPage() here as the method can be called from an existing page - } - - return newProvider; - } - - private boolean isReconfiguredForProject(ILanguageSettingsProvider provider) { - String id = provider.getId(); - - ICConfigurationDescription cfgDescription = getConfigurationDescription(); - String[] defaultIds = ((ILanguageSettingsProvidersKeeper) cfgDescription).getDefaultLanguageSettingsProvidersIds(); - List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); - - // check for the provider mismatch in configuration list vs. default list from the tool-chain - if (defaultIds != null && (Arrays.asList(defaultIds).contains(id) != providers.contains(provider))) { - return true; - } - - // check if provider belongs to configuration (i.e. checked in the table) - if (!providers.contains(provider)) { - return false; - } - - // check if "shared" flag matches default shared preference from extension point definition - if (LanguageSettingsManager.isPreferShared(id) != LanguageSettingsManager.isWorkspaceProvider(provider)) { - return true; - } - - // check if configuration provider equals to the default one from extension point - if (!LanguageSettingsManager.isWorkspaceProvider(provider) && !LanguageSettingsManager.isEqualExtensionProvider(provider, false)) { - return true; - } - return false; - } - - private boolean isEditedForProject(ILanguageSettingsProvider provider) { - String id = provider.getId(); - ICConfigurationDescription cfgDescription = getConfigurationDescription(); - List initialProviders = initialProvidersByCfg.get(cfgDescription.getId()); - List providers = getCheckedProviders(); - - // check for the provider mismatch in configuration list vs. initial list - ILanguageSettingsProvider initialProvider = findProvider(id, initialProviders); - if ((initialProvider != null) != providers.contains(provider)) { - return true; - } - - // check if "shared" flag matches that of initial provider - if (providers.contains(provider) && LanguageSettingsManager.isWorkspaceProvider(initialProvider) != LanguageSettingsManager.isWorkspaceProvider(provider)) { - return true; - } - - // check if configuration provider equals to the initial one - if (!LanguageSettingsManager.isWorkspaceProvider(provider) && !provider.equals(initialProvider)) { - return true; - } - return false; - } - private class ProvidersTableLabelProvider extends LanguageSettingsProvidersLabelProvider { @Override protected String[] getOverlayKeys(ILanguageSettingsProvider provider) { @@ -228,23 +152,204 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { @Override public String getText(Object element) { - // AG TODO - address duplication with super.getText() if (element instanceof ILanguageSettingsProvider) { ILanguageSettingsProvider provider = (ILanguageSettingsProvider) element; String name = provider.getName(); - if (name != null) { - if (page.isForPrefs() || isPresentedAsShared(provider)) { - name = name + " [ Shared ]"; - } - return name; + if (name != null && (page.isForPrefs() || isPresentedAsShared(provider))) { + return name + Messages.LanguageSettingsProvidersLabelProvider_TextDecorator_Shared; } - String id = provider.getId(); - return "[ Not accessible id="+id+" ]"; } return super.getText(element); } + } + /** + * Returns the provider which is being presented to the user in UI. + * Used by option pages when there is a need. + * Warning: Do not cache the result as the provider can be replaced at any time. + * @param id - id of the provider. + * + * @return the provider. + */ + public ILanguageSettingsProvider getProvider(String id) { + return findProvider(id, presentedProviders); + } + /** + * Check if the provider is a working copy and can be modified. + */ + private boolean isWorkingCopy(ILanguageSettingsProvider provider) { + boolean isWorkingCopy = false; + if (page.isForPrefs()) { + isWorkingCopy = ! LanguageSettingsManager.isWorkspaceProvider(provider); + } else { + if (!LanguageSettingsManager.isWorkspaceProvider(provider)) { + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + List initialProviders = initialProvidersByCfg.get(cfgDescription.getId()); + isWorkingCopy = ! initialProviders.contains(provider); + } + + } + return isWorkingCopy; + } + + /** + * Returns current working copy of the provider. Creates one if it has not been created yet. + * A working copy will be discarded if user pushes [Cancel] or it will replace original + * provider on [Apply] or [OK]. + * + * This method is used also by option pages when there is a need to modify the provider. + * Warning: Do not cache the result as the provider can be replaced at any time. + * + * @param id - id of the provider. + * @return working copy of the provider. + */ + public ILanguageSettingsProvider getWorkingCopy(String id) { + ILanguageSettingsProvider provider = findProvider(id, presentedProviders); + if (isWorkingCopy(provider)) { + return provider; + } + + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + Assert.isTrue(rawProvider instanceof ILanguageSettingsEditableProvider); + + ILanguageSettingsEditableProvider newProvider = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider)rawProvider, true); + if (newProvider != null) { + replaceSelectedProvider(newProvider); + // Warning: Do not initializeOptionsPage() here as the method can be called from an existing page + } + + return newProvider; + } + + /** + * Refresh provider item in the table and update buttons. + * This method is intended for use by an Options Page of the provider. + * + * @param provider - provider item in the table to refresh. + */ + public void refreshItem(ILanguageSettingsProvider provider) { + tableProvidersViewer.refresh(provider); + updateButtons(); + } + + /** + * Check if provider should get "reconfigured" overlay in UI. + */ + private boolean isReconfiguredForProject(ILanguageSettingsProvider provider) { + String id = provider.getId(); + + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + String[] defaultIds = ((ILanguageSettingsProvidersKeeper) cfgDescription).getDefaultLanguageSettingsProvidersIds(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + + // check for the provider mismatch in configuration list vs. default list from the tool-chain + if (defaultIds != null && (Arrays.asList(defaultIds).contains(id) != providers.contains(provider))) { + return true; + } + + // check if provider belongs to configuration (i.e. checked in the table) + if (!providers.contains(provider)) { + return false; + } + + // check if "shared" flag matches default shared preference from extension point definition + if (LanguageSettingsManager.isPreferShared(id) != LanguageSettingsManager.isWorkspaceProvider(provider)) { + return true; + } + + // check if configuration provider equals to the default one from extension point + if (!LanguageSettingsManager.isWorkspaceProvider(provider) && !LanguageSettingsManager.isEqualExtensionProvider(provider, false)) { + return true; + } + + return false; + } + + /** + * Check if provider should get "edited" overlay in UI. + */ + private boolean isEditedForProject(ILanguageSettingsProvider provider) { + String id = provider.getId(); + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + List initialProviders = initialProvidersByCfg.get(cfgDescription.getId()); + List providers = getCheckedProviders(); + + // check for the provider mismatch in configuration list vs. initial list + ILanguageSettingsProvider initialProvider = findProvider(id, initialProviders); + if ((initialProvider != null) != providers.contains(provider)) { + return true; + } + + // check if "shared" flag matches that of initial provider + if (providers.contains(provider) && LanguageSettingsManager.isWorkspaceProvider(initialProvider) != LanguageSettingsManager.isWorkspaceProvider(provider)) { + return true; + } + + // check if configuration provider equals to the initial one + if (!LanguageSettingsManager.isWorkspaceProvider(provider) && !provider.equals(initialProvider)) { + return true; + } + + return false; + } + + /** + * Checks if the provider should be presented as shared. Unchecked providers are shown as non-shared + * if they are defined as non-shared in extension point even if in fact shared instance is used to display + * the options page. + */ + private boolean isPresentedAsShared(ILanguageSettingsProvider provider) { + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + return LanguageSettingsManager.isWorkspaceProvider(provider) && + ( providers.contains(provider) || LanguageSettingsManager.isPreferShared(provider.getId()) ); + } + + /** + * Find provider with a given ID in the list or {@code null}. + */ + private ILanguageSettingsProvider findProvider(String id, List providers) { + for (ILanguageSettingsProvider provider : providers) { + if (provider.getId().equals(id)) { + return provider; + } + } + return null; + } + + /** + * Shortcut for getting the currently selected provider. + * Do not use if you need to change provider's settings or entries, use {@link #getWorkingCopy(String)}. + */ + private ILanguageSettingsProvider getSelectedProvider() { + ILanguageSettingsProvider provider = null; + + int pos = tableProviders.getSelectionIndex(); + if (pos >= 0 && pos < tableProviders.getItemCount()) { + provider = (ILanguageSettingsProvider)tableProvidersViewer.getElementAt(pos); + } + return provider; + } + + /** + * Shortcut for getting the current configuration description. + */ + private ICConfigurationDescription getConfigurationDescription() { + if (page.isForPrefs()) { + return null; + } + + return getResDesc().getConfiguration(); + } + + /** + * Get the list of providers checked in the table in UI. + * @return + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + private List getCheckedProviders() { + return (List)Arrays.asList(tableProvidersViewer.getCheckedElements()); } /** @@ -255,30 +360,34 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } /** - * Shortcut for getting the current configuration description. + * Replace the selected provider in UI and in configuration. */ - private ICConfigurationDescription getConfigurationDescription() { - if (page.isForPrefs()) - return null; - - ICConfigurationDescription cfgDescription = getResDesc().getConfiguration(); - return cfgDescription; - } - - /** - * Shortcut for getting the currently selected provider. - * Do not use if you need to change provider's settings, use {@link #getWorkingCopy(String)}. - */ - private ILanguageSettingsProvider getSelectedProvider() { - ILanguageSettingsProvider provider = null; - + private void replaceSelectedProvider(ILanguageSettingsProvider newProvider) { int pos = tableProviders.getSelectionIndex(); - if (pos >= 0 && posWorkspace Settings, Discovery Tab."); - GridData gd = new GridData(); - gd.horizontalSpan = span; - linkToWorkspacePreferences.setLayoutData(gd); - - linkToWorkspacePreferences.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - // Use event.text to tell which link was used - PreferencesUtil.createPreferenceDialogOn(parent.getShell(), WORKSPACE_PREFERENCE_PAGE, null, null).open(); - } - }); - } - - // Called from globalProviderCheckBox listener + /** + * Change "globality" of a provider. + */ private ILanguageSettingsProvider toggleGlobalProvider(ILanguageSettingsProvider provider, boolean toGlobal) { ILanguageSettingsProvider newProvider = null; @@ -466,12 +477,12 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { newProvider = ((ILanguageSettingsEditableProvider) rawProvider).cloneShallow(); } } catch (CloneNotSupportedException e) { - CUIPlugin.log("Error cloning provider " + id, e); + CUIPlugin.log("Error cloning provider " + id, e); //$NON-NLS-1$ } } if (newProvider != null) { replaceSelectedProvider(newProvider); - initializeOptionsPage(newProvider); + createOptionsPage(newProvider); displaySelectedOptionPage(); updateButtons(); } else { @@ -482,59 +493,11 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } /** - * Refresh provider item in the table and update buttons. - * This method is intended for use by an Options Page of the provider. - * - * @param provider - provider item in the table to refresh. + * Create a check-box for "shared" or "global" property of a provider. */ - public void refreshItem(ILanguageSettingsProvider provider) { - tableProvidersViewer.refresh(provider); - updateButtons(); - } - - private void createOptionsPane(Composite parent) { - groupOptionsPage = new Group(parent, SWT.SHADOW_ETCHED_IN); - groupOptionsPage.setText("Language Settings Provider Options"); - groupOptionsPage.setLayout(new GridLayout(2, false)); - - if (!page.isForPrefs()) { - createSharedProviderCheckBox(groupOptionsPage); - createProjectStorageCheckBox(groupOptionsPage); - createLinkToPreferences(groupOptionsPage, 2); - } - - compositeOptionsPage = new Composite(groupOptionsPage, SWT.NONE); - compositeOptionsPage.setLayout(new TabFolderLayout()); - } - - private void createProjectStorageCheckBox(Composite parent) { - projectStorageCheckBox = new Button(parent, SWT.CHECK); - projectStorageCheckBox.setText("Store entries in project settings folder (easing project miration)"); - projectStorageCheckBox.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - boolean inProjectArea = projectStorageCheckBox.getSelection(); - ILanguageSettingsProvider newProvider = getWorkingCopy(getSelectedProvider().getId()); - // FIXME - Assert.isTrue(newProvider instanceof LanguageSettingsSerializableProvider); - - LanguageSettingsManager.setStoringEntriesInProjectArea((LanguageSettingsSerializableProvider) newProvider, inProjectArea); - replaceSelectedProvider(newProvider); - initializeOptionsPage(newProvider); - displaySelectedOptionPage(); - updateButtons(); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); - } - }); - } - private void createSharedProviderCheckBox(Composite parent) { sharedProviderCheckBox = new Button(parent, SWT.CHECK); - sharedProviderCheckBox.setText("Share setting entries between projects (global provider)"); + sharedProviderCheckBox.setText(Messages.LanguageSettingsProviderTab_ShareProviders); sharedProviderCheckBox.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -555,7 +518,93 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { }); } - private void enableControls(boolean enable) { + /** + * Create a check-box defining where to store entries of a provider. + */ + private void createProjectStorageCheckBox(Composite parent) { + projectStorageCheckBox = new Button(parent, SWT.CHECK); + projectStorageCheckBox.setText(Messages.LanguageSettingsProviderTab_StoreEntriesInsideProject); + projectStorageCheckBox.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean inProjectArea = projectStorageCheckBox.getSelection(); + ILanguageSettingsProvider newProvider = getWorkingCopy(getSelectedProvider().getId()); + Assert.isTrue(newProvider instanceof LanguageSettingsSerializableProvider); + + LanguageSettingsManager.setStoringEntriesInProjectArea((LanguageSettingsSerializableProvider) newProvider, inProjectArea); + replaceSelectedProvider(newProvider); + createOptionsPage(newProvider); + displaySelectedOptionPage(); + updateButtons(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + }); + } + + /** + * Create a link to Preferences page. + */ + private void createLinkToPreferences(final Composite parent, int span) { + linkToWorkspacePreferences = new Link(parent, SWT.NONE); +// NLS.bind(Messages.GeneralMessages_NonAccessibleID, provider.getId()); + String href = NLS.bind("{0}", Messages.LanguageSettingsProviderTab_WorkspaceSettings); //$NON-NLS-1$ + linkToWorkspacePreferences.setText(NLS.bind(Messages.LanguageSettingsProviderTab_OptionsCanBeChangedInPreferencesDiscoveryTab, href)); + GridData gd = new GridData(); + gd.horizontalSpan = span; + linkToWorkspacePreferences.setLayoutData(gd); + + linkToWorkspacePreferences.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event event) { + // Use event.text to tell which link was used + PreferencesUtil.createPreferenceDialogOn(parent.getShell(), WORKSPACE_PREFERENCE_PAGE, null, null).open(); + } + }); + } + + /** + * Create Options pane. + */ + private void createOptionsPane(Composite parent) { + groupOptionsPage = new Group(parent, SWT.SHADOW_ETCHED_IN); + groupOptionsPage.setText(Messages.LanguageSettingsProviderTab_LanguageSettingsProvidersOptions); + groupOptionsPage.setLayout(new GridLayout(2, false)); + + if (!page.isForPrefs()) { + createSharedProviderCheckBox(groupOptionsPage); + createProjectStorageCheckBox(groupOptionsPage); + createLinkToPreferences(groupOptionsPage, 2); + } + + compositeOptionsPage = new Composite(groupOptionsPage, SWT.NONE); + compositeOptionsPage.setLayout(new TabFolderLayout()); + } + + /** + * Create sash form. + */ + private void createSashForm() { + sashFormProviders = new SashForm(usercomp, SWT.VERTICAL); + GridLayout layout = new GridLayout(); + sashFormProviders.setLayout(layout); + GridData gd = new GridData(GridData.FILL_BOTH); + gd.horizontalSpan = 2; + sashFormProviders.setLayoutData(gd); + + createProvidersPane(sashFormProviders); + createOptionsPane(sashFormProviders); + + sashFormProviders.setWeights(DEFAULT_CONFIGURE_SASH_WEIGHTS); + } + + /** + * Gray out or restore all controls except enabling check-box. + */ + private void enableTabControls(boolean enable) { sashFormProviders.setEnabled(enable); tableProviders.setEnabled(enable); compositeOptionsPage.setEnabled(enable); @@ -568,45 +617,269 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { if (currentOptionsPage != null) { currentOptionsPage.setVisible(false); } - disableButtons(); + + buttonSetEnabled(BUTTON_CLEAR, false); + buttonSetEnabled(BUTTON_RESET, false); + buttonSetEnabled(BUTTON_MOVE_UP, false); + buttonSetEnabled(BUTTON_MOVE_DOWN, false); } } /** - * Populate provider tables and their option pages + * Create check-box to allow disable/enable language settings providers functionality. */ - private void updateProvidersTable() { - ILanguageSettingsProvider selectedProvider = getSelectedProvider(); - String selectedId = selectedProvider != null ? selectedProvider.getId() : null; + private void createEnableProvidersCheckBox() { + enableProvidersCheckBox = setupCheck(usercomp, Messages.CDTMainWizardPage_TrySD90, 2, GridData.FILL_HORIZONTAL); + enableProvidersCheckBox.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean enabled = enableProvidersCheckBox.getSelection(); + if (masterPropertyPage != null) { + masterPropertyPage.setLanguageSettingsProvidersEnabled(enabled); + } - // update viewer if the list of providers changed - int pos = tableProviders.getSelectionIndex(); - tableProvidersViewer.setInput(presentedProviders); - tableProviders.setSelection(pos); + enableTabControls(enabled); + } + }); - ICConfigurationDescription cfgDescription = getConfigurationDescription(); - if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { - List cfgProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); - tableProvidersViewer.setCheckedElements(cfgProviders.toArray(new ILanguageSettingsProvider[0])); + if (masterPropertyPage!=null) { + enableProvidersCheckBox.setSelection(masterPropertyPage.isLanguageSettingsProvidersEnabled()); + } else { + enableProvidersCheckBox.setSelection(ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(page.getProject())); + } + // display but disable the checkbox for file/folder resource + enableProvidersCheckBox.setEnabled(page.isForProject()); + enableTabControls(enableProvidersCheckBox.getSelection()); + } + + @Override + public void createControls(Composite parent) { + super.createControls(parent); + + usercomp.setLayout(new GridLayout()); + GridData gd = (GridData) usercomp.getLayoutData(); + // Discourage settings entry table from trying to show all its items at once, see bug 264330 + gd.heightHint = 1; + + if (page instanceof LanguageSettingsProvidersPage) { + masterPropertyPage = (LanguageSettingsProvidersPage) page; } - if (selectedId != null) { - for (int i = 0; i < presentedProviders.size(); i++) { - if (selectedId.equals(presentedProviders.get(i).getId())) { - tableProviders.setSelection(i); - break; + trackInitialSettings(); + + createSashForm(); + + fStatusLine = new StatusMessageLine(usercomp, SWT.LEFT, 2); + if (!page.isForPrefs()) { + createEnableProvidersCheckBox(); + } + + String[] buttonLabels; + if (page.isForPrefs()) { + buttonLabels = new String[2]; + buttonLabels[BUTTON_CLEAR] = CLEAR_STR; + buttonLabels[BUTTON_RESET] = RESET_STR; + } else { + buttonLabels = new String[5]; + buttonLabels[BUTTON_CLEAR] = CLEAR_STR; + buttonLabels[BUTTON_RESET] = RESET_STR; + buttonLabels[BUTTON_MOVE_UP] = MOVEUP_STR; + buttonLabels[BUTTON_MOVE_DOWN] = MOVEDOWN_STR; + } + initButtons(buttonLabels); + + updateData(getResDesc()); + } + + /** + * Clear entries of the selected provider. + */ + private void performClear(ILanguageSettingsProvider selectedProvider) { + if (isWorkingCopy(selectedProvider)) { + if (selectedProvider instanceof LanguageSettingsSerializableProvider) { + LanguageSettingsSerializableProvider editableProvider = (LanguageSettingsSerializableProvider) selectedProvider; + editableProvider.clear(); + tableProvidersViewer.update(selectedProvider, null); + } + } else { + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(selectedProvider); + if (rawProvider instanceof ILanguageSettingsEditableProvider) { + ILanguageSettingsEditableProvider newProvider = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider) rawProvider, false); + if (newProvider != null) { + replaceSelectedProvider(newProvider); + createOptionsPage(newProvider); + displaySelectedOptionPage(); } } } - - optionsPageMap.clear(); - for (ILanguageSettingsProvider provider : presentedProviders) { - initializeOptionsPage(provider); - } - - displaySelectedOptionPage(); + updateButtons(); } + /** + * Reset settings of the selected provider. + */ + private void performReset(ILanguageSettingsProvider selectedProvider) { + String id = selectedProvider.getId(); + + ILanguageSettingsProvider newProvider = null; + if (page.isForPrefs()) { + newProvider = LanguageSettingsManager.getExtensionProviderCopy(id, true); + if (newProvider == null) { + Status status = new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, IStatus.ERROR, Messages.GeneralMessages_InternalError_ReportLogToCdtTeam, + new Exception("Internal Error getting copy of provider id="+id)); //$NON-NLS-1$ + fStatusLine.setErrorStatus(status); + CUIPlugin.log(status); + } + } else { + ICConfigurationDescription cfgDescription = getConfigurationDescription(); + String[] defaultIds = ((ILanguageSettingsProvidersKeeper) cfgDescription).getDefaultLanguageSettingsProvidersIds(); + boolean isDefault = Arrays.asList(defaultIds).contains(id); + if (isDefault && !LanguageSettingsManager.isPreferShared(id)) { + newProvider = LanguageSettingsManager.getExtensionProviderCopy(id, true); + if (newProvider == null) { + Status status = new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, IStatus.ERROR, Messages.GeneralMessages_InternalError_ReportLogToCdtTeam, + new Exception("Internal Error getting copy of provider id="+id)); //$NON-NLS-1$ + fStatusLine.setErrorStatus(status); + CUIPlugin.log(status); + } + } else { + newProvider = LanguageSettingsManager.getWorkspaceProvider(id); + } + tableProvidersViewer.setChecked(selectedProvider, isDefault); + } + + if (newProvider != null) { + replaceSelectedProvider(newProvider); + createOptionsPage(newProvider); + displaySelectedOptionPage(); + updateButtons(); + } + } + + /** + * Move selected provider in the table. + */ + private void moveProvider(int oldPos, int newPos) { + Collections.swap(presentedProviders, oldPos, newPos); + tableProvidersViewer.refresh(); + tableProviders.showSelection(); + + saveCheckedProviders(); + updateButtons(); + } + + /** + * Move selected provider up. + */ + private void performMoveUp(ILanguageSettingsProvider selectedProvider) { + int pos = presentedProviders.indexOf(selectedProvider); + if (pos > 0) { + moveProvider(pos, pos-1); + } + } + + /** + * Move selected provider down. + */ + private void performMoveDown(ILanguageSettingsProvider selectedProvider) { + int pos = presentedProviders.indexOf(selectedProvider); + int last = presentedProviders.size() - 1; + if (pos >= 0 && pos < last) { + moveProvider(pos, pos+1); + } + } + + /** + * Handle pressed buttons. + */ + @Override + public void buttonPressed(int buttonIndex) { + ILanguageSettingsProvider selectedProvider = getSelectedProvider(); + + switch (buttonIndex) { + case BUTTON_CLEAR: + performClear(selectedProvider); + break; + case BUTTON_RESET: + performReset(selectedProvider); + break; + case BUTTON_MOVE_UP: + performMoveUp(selectedProvider); + break; + case BUTTON_MOVE_DOWN: + performMoveDown(selectedProvider); + break; + default: + } + } + + /** + * Updates state for all buttons. + */ + @Override + protected void updateButtons() { + ILanguageSettingsProvider provider = getSelectedProvider(); + boolean isProviderSelected = provider != null; + boolean canForWorkspace = isProviderSelected && page.isForPrefs(); + boolean canForProject = isProviderSelected && page.isForProject(); + + int pos = tableProviders.getSelectionIndex(); + int count = tableProviders.getItemCount(); + int last = count - 1; + boolean isRangeOk = (pos >= 0 && pos <= last); + + ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); + boolean isAllowedClearing = rawProvider instanceof ILanguageSettingsEditableProvider && rawProvider instanceof LanguageSettingsSerializableProvider + && LanguageSettingsProviderAssociationManager.isAllowedToClear(rawProvider); + + boolean canClear = isAllowedClearing && (canForWorkspace || (canForProject && !LanguageSettingsManager.isWorkspaceProvider(provider))); + if (rawProvider instanceof LanguageSettingsSerializableProvider) { + canClear = canClear && !((LanguageSettingsSerializableProvider)rawProvider).isEmpty(); + } + + boolean canResetForProject = canForProject && isReconfiguredForProject(provider); + boolean canResetForWorkspace = canForWorkspace && + (rawProvider instanceof ILanguageSettingsEditableProvider + && !LanguageSettingsManager.isEqualExtensionProvider(rawProvider, false)) + && ( LanguageSettingsManager.getExtensionProviderIds().contains(rawProvider.getId()) ); + boolean canReset = canResetForProject || canResetForWorkspace; + + boolean canMoveUp = canForProject && isRangeOk && pos != 0; + boolean canMoveDown = canForProject && isRangeOk && pos != last; + + buttonSetEnabled(BUTTON_CLEAR, canClear); + buttonSetEnabled(BUTTON_RESET, canReset); + buttonSetEnabled(BUTTON_MOVE_UP, canMoveUp); + buttonSetEnabled(BUTTON_MOVE_DOWN, canMoveDown); + } + + /** + * Sort providers displayed in UI. Sorting is by name except test providers are shown + * on bottom. + */ + private void sortByName(List providers) { + // ensure sorting by name all unchecked providers + Collections.sort(providers, new Comparator() { + @Override + public int compare(ILanguageSettingsProvider prov1, ILanguageSettingsProvider prov2) { + Boolean isTest1 = prov1.getId().matches(TEST_PLUGIN_ID_PATTERN); + Boolean isTest2 = prov2.getId().matches(TEST_PLUGIN_ID_PATTERN); + int result = isTest1.compareTo(isTest2); + if (result == 0) { + String name1 = prov1.getName(); + String name2 = prov2.getName(); + if (name1 != null && name2 != null) { + result = name1.compareTo(name2); + } + } + return result; + } + }); + } + + /** + * Initialize providers list. + */ private void initializeProviders() { // The providers list is formed to consist of configuration providers (checked elements on top of the table) // and after that other providers which could be possible added (unchecked) sorted by name. @@ -652,27 +925,10 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } } - private void sortByName(List providers) { - // ensure sorting by name all unchecked providers - Collections.sort(providers, new Comparator() { - @Override - public int compare(ILanguageSettingsProvider prov1, ILanguageSettingsProvider prov2) { - Boolean isTest1 = prov1.getId().matches(TEST_PLUGIN_ID_PATTERN); - Boolean isTest2 = prov2.getId().matches(TEST_PLUGIN_ID_PATTERN); - int result = isTest1.compareTo(isTest2); - if (result == 0) { - String name1 = prov1.getName(); - String name2 = prov2.getName(); - if (name1 != null && name2 != null) { - result = name1.compareTo(name2); - } - } - return result; - } - }); - } - - private ICOptionPage createOptionsPage(ILanguageSettingsProvider provider) { + /** + * Get option page from {@link LanguageSettingsProviderAssociationManager}. + */ + private ICOptionPage getOptionsPage(ILanguageSettingsProvider provider) { ICOptionPage optionsPage = null; if (provider != null) { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); @@ -688,8 +944,11 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { return optionsPage; } - private void initializeOptionsPage(ILanguageSettingsProvider provider) { - ICOptionPage optionsPage = createOptionsPage(provider); + /** + * Create Options page for a provider. + */ + private void createOptionsPage(ILanguageSettingsProvider provider) { + ICOptionPage optionsPage = getOptionsPage(provider); if (optionsPage != null) { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); @@ -707,6 +966,9 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } } + /** + * Display selected option page. + */ private void displaySelectedOptionPage() { if (currentOptionsPage != null) { currentOptionsPage.setVisible(false); @@ -749,214 +1011,42 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { } /** - * Checks if the provider should be presented as shared. Unchecked providers are shown as non-shared - * if they are defined as non-shared in extension point even if in fact shared instance is used to display - * the options page. + * Populate provider tables and their option pages */ - private boolean isPresentedAsShared(ILanguageSettingsProvider provider) { - ICConfigurationDescription cfgDescription = getConfigurationDescription(); - List providers = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); - return LanguageSettingsManager.isWorkspaceProvider(provider) && - ( providers.contains(provider) || LanguageSettingsManager.isPreferShared(provider.getId()) ); - } - - - private void disableButtons() { - buttonSetEnabled(BUTTON_CLEAR, false); - buttonSetEnabled(BUTTON_RESET, false); - buttonSetEnabled(BUTTON_MOVE_UP, false); - buttonSetEnabled(BUTTON_MOVE_DOWN, false); - } - - /** - * Updates state for all buttons. Called when table selection changes. - */ - @Override - protected void updateButtons() { - ILanguageSettingsProvider provider = getSelectedProvider(); - boolean isProviderSelected = provider != null; - boolean canForWorkspace = isProviderSelected && page.isForPrefs(); - boolean canForProject = isProviderSelected && page.isForProject(); - - int pos = tableProviders.getSelectionIndex(); - int count = tableProviders.getItemCount(); - int last = count - 1; - boolean isRangeOk = (pos >= 0 && pos <= last); - - ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); - boolean isAllowedClearing = rawProvider instanceof ILanguageSettingsEditableProvider && rawProvider instanceof LanguageSettingsSerializableProvider - && LanguageSettingsProviderAssociationManager.isAllowedToClear(rawProvider); - - boolean canClear = isAllowedClearing && (canForWorkspace || (canForProject && !LanguageSettingsManager.isWorkspaceProvider(provider))); - if (rawProvider instanceof LanguageSettingsSerializableProvider) { - canClear = canClear && !((LanguageSettingsSerializableProvider)rawProvider).isEmpty(); - } - - boolean canResetForProject = canForProject && isReconfiguredForProject(provider); - boolean canResetForWorkspace = canForWorkspace && - (rawProvider instanceof ILanguageSettingsEditableProvider - && !LanguageSettingsManager.isEqualExtensionProvider(rawProvider, false)) - && ( LanguageSettingsManager.getExtensionProviderIds().contains(rawProvider.getId()) ); - boolean canReset = canResetForProject || canResetForWorkspace; - - boolean canMoveUp = canForProject && isRangeOk && pos != 0; - boolean canMoveDown = canForProject && isRangeOk && pos != last; - - buttonSetEnabled(BUTTON_CLEAR, canClear); - buttonSetEnabled(BUTTON_RESET, canReset); - buttonSetEnabled(BUTTON_MOVE_UP, canMoveUp); - buttonSetEnabled(BUTTON_MOVE_DOWN, canMoveDown); - } - - /** - * Handle buttons - */ - @Override - public void buttonPressed(int buttonIndex) { + private void updateProvidersTable() { ILanguageSettingsProvider selectedProvider = getSelectedProvider(); + String selectedId = selectedProvider != null ? selectedProvider.getId() : null; - switch (buttonIndex) { - case BUTTON_CLEAR: - performClear(selectedProvider); - break; - case BUTTON_RESET: - performReset(selectedProvider); - break; - case BUTTON_MOVE_UP: - performMoveUp(selectedProvider); - break; - case BUTTON_MOVE_DOWN: - performMoveDown(selectedProvider); - break; - default: - } - } - - private void performClear(ILanguageSettingsProvider selectedProvider) { - if (isWorkingCopy(selectedProvider)) { - if (selectedProvider instanceof LanguageSettingsSerializableProvider) { - LanguageSettingsSerializableProvider editableProvider = (LanguageSettingsSerializableProvider) selectedProvider; - editableProvider.clear(); - tableProvidersViewer.update(selectedProvider, null); - } - } else { - ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(selectedProvider); - if (rawProvider instanceof ILanguageSettingsEditableProvider) { - ILanguageSettingsEditableProvider newProvider = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider) rawProvider, false); - if (newProvider != null) { - replaceSelectedProvider(newProvider); - initializeOptionsPage(newProvider); - displaySelectedOptionPage(); - } - } - } - updateButtons(); - } - - private void performReset(ILanguageSettingsProvider selectedProvider) { - String id = selectedProvider.getId(); - - ILanguageSettingsProvider newProvider = null; - if (page.isForPrefs()) { - newProvider = LanguageSettingsManager.getExtensionProviderCopy(id, true); - if (newProvider == null) { - Status status = new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, IStatus.ERROR, "Internal error happened, report application log to CDT team.", - new Exception("Internal Error getting copy of provider id="+id)); - fStatusLine.setErrorStatus(status); - CUIPlugin.log(status); - } - } else { - ICConfigurationDescription cfgDescription = getConfigurationDescription(); - String[] defaultIds = ((ILanguageSettingsProvidersKeeper) cfgDescription).getDefaultLanguageSettingsProvidersIds(); - boolean isDefault = Arrays.asList(defaultIds).contains(id); - if (isDefault && !LanguageSettingsManager.isPreferShared(id)) { - newProvider = LanguageSettingsManager.getExtensionProviderCopy(id, true); - if (newProvider == null) { - Status status = new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, IStatus.ERROR, "Internal error happened, report application log to CDT team.", - new Exception("Internal Error getting copy of provider id="+id)); - fStatusLine.setErrorStatus(status); - CUIPlugin.log(status); - } - } else { - newProvider = LanguageSettingsManager.getWorkspaceProvider(id); - } - tableProvidersViewer.setChecked(selectedProvider, isDefault); - } - - if (newProvider != null) { - replaceSelectedProvider(newProvider); - initializeOptionsPage(newProvider); - displaySelectedOptionPage(); - updateButtons(); - } - } - - private void replaceSelectedProvider(ILanguageSettingsProvider newProvider) { + // update viewer if the list of providers changed int pos = tableProviders.getSelectionIndex(); - boolean isChecked = tableProvidersViewer.getChecked(tableProvidersViewer.getElementAt(pos)); - - presentedProviders.set(pos, newProvider); - tableProvidersViewer.refresh(); - tableProvidersViewer.setChecked(newProvider, isChecked); + tableProvidersViewer.setInput(presentedProviders); tableProviders.setSelection(pos); - tableProvidersViewer.refresh(newProvider); - saveCheckedProviders(); - } - - private void saveCheckedProviders() { ICConfigurationDescription cfgDescription = getConfigurationDescription(); if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { - ((ILanguageSettingsProvidersKeeper) cfgDescription).setLanguageSettingProviders(getCheckedProviders()); + List cfgProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders(); + tableProvidersViewer.setCheckedElements(cfgProviders.toArray(new ILanguageSettingsProvider[0])); } - } - private boolean isWorkingCopy(ILanguageSettingsProvider provider) { - boolean isWorkingCopy = false; - if (page.isForPrefs()) { - isWorkingCopy = ! LanguageSettingsManager.isWorkspaceProvider(provider); - } else { - if (!LanguageSettingsManager.isWorkspaceProvider(provider)) { - ICConfigurationDescription cfgDescription = getConfigurationDescription(); - List initialProviders = initialProvidersByCfg.get(cfgDescription.getId()); - isWorkingCopy = ! initialProviders.contains(provider); + if (selectedId != null) { + for (int i = 0; i < presentedProviders.size(); i++) { + if (selectedId.equals(presentedProviders.get(i).getId())) { + tableProviders.setSelection(i); + break; + } } - } - return isWorkingCopy; - } - private void performMoveUp(ILanguageSettingsProvider selectedProvider) { - int pos = presentedProviders.indexOf(selectedProvider); - if (pos > 0) { - moveProvider(pos, pos-1); + optionsPageMap.clear(); + for (ILanguageSettingsProvider provider : presentedProviders) { + createOptionsPage(provider); } - } - private void performMoveDown(ILanguageSettingsProvider selectedProvider) { - int pos = presentedProviders.indexOf(selectedProvider); - int last = presentedProviders.size() - 1; - if (pos >= 0 && pos < last) { - moveProvider(pos, pos+1); - } - } - - private void moveProvider(int oldPos, int newPos) { - Collections.swap(presentedProviders, oldPos, newPos); - tableProvidersViewer.refresh(); - tableProviders.showSelection(); - - saveCheckedProviders(); - updateButtons(); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - private List getCheckedProviders() { - return (List)Arrays.asList(tableProvidersViewer.getCheckedElements()); + displaySelectedOptionPage(); } /** - * Called when configuration changed + * Update the tab. Called when configuration changes. */ @Override public void updateData(ICResourceDescription rcDes) { @@ -971,10 +1061,10 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { setAllVisible(true, null); } - if (enableProvidersCheckBox!=null && masterPropertyPage!=null) { + if (enableProvidersCheckBox != null && masterPropertyPage != null) { boolean enabled = masterPropertyPage.isLanguageSettingsProvidersEnabled(); enableProvidersCheckBox.setSelection(enabled); - enableControls(enabled); + enableTabControls(enabled); } } @@ -1068,7 +1158,7 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { try { LanguageSettingsManager.setWorkspaceProviders(presentedProviders); } catch (CoreException e) { - CUIPlugin.log("Error setting user defined providers", e); + CUIPlugin.log("Error setting user defined providers", e); //$NON-NLS-1$ } initializeProviders(); } @@ -1087,30 +1177,18 @@ public class LanguageSettingsProviderTab extends AbstractCPropertyTab { try { op.performApply(null); } catch (CoreException e) { - CUIPlugin.log("Error applying options page", e); + CUIPlugin.log("Error applying options page", e); //$NON-NLS-1$ } } } @Override public boolean canBeVisible() { - if (CDTPrefUtil.getBool(CDTPrefUtil.KEY_NO_SHOW_PROVIDERS)) + if (CDTPrefUtil.getBool(CDTPrefUtil.KEY_NO_SHOW_PROVIDERS)) { return false; + } return page.isForPrefs() || page.isForProject(); } - private ILanguageSettingsProvider findProvider(String id, List providers) { - for (ILanguageSettingsProvider provider : providers) { - if (provider.getId().equals(id)) { - return provider; - } - } - return null; - } - - public ILanguageSettingsProvider getProvider(String id) { - return findProvider(id, presentedProviders); - } - } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java index e7164dbbde4..e93bae0f8d3 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersLabelProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 Andrew Gvozdev and others. + * Copyright (c) 2010, 2012 Andrew Gvozdev 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,20 +8,19 @@ * Contributors: * Andrew Gvozdev - Initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.ui.language.settings.providers; import java.net.URL; -import org.eclipse.jface.viewers.IDecoration; import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.graphics.Image; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsSerializableProvider; import org.eclipse.cdt.ui.CDTSharedImages; +import org.eclipse.cdt.internal.ui.newui.Messages; /** * Label provider for language settings providers. @@ -40,17 +39,17 @@ public class LanguageSettingsProvidersLabelProvider extends LabelProvider { String id = provider.getId(); URL url = LanguageSettingsProviderAssociationManager.getImageUrl(id); // try class-association - if (url==null) { + if (url == null) { ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); - if (rawProvider!=null) { + if (rawProvider != null) { url = LanguageSettingsProviderAssociationManager.getImage(rawProvider.getClass()); } } - if (url!=null) { + if (url != null) { imageKey = url.toString(); } - if (imageKey==null) { + if (imageKey == null) { if (id.matches(TEST_PLUGIN_ID_PATTERN)) { imageKey = CDTSharedImages.IMG_OBJS_CDT_TESTING; } else { @@ -64,31 +63,7 @@ public class LanguageSettingsProvidersLabelProvider extends LabelProvider { * Returns keys for image overlays. Returning {@code null} is not allowed. */ protected String[] getOverlayKeys(ILanguageSettingsProvider provider) { - String[] overlayKeys = new String[5]; - - if (isDebugging()) { // TODO temporary for debugging - ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(provider); - if (rawProvider instanceof LanguageSettingsSerializableProvider) { - if (((LanguageSettingsSerializableProvider)rawProvider).isEmpty()) { - overlayKeys[IDecoration.BOTTOM_RIGHT] = CDTSharedImages.IMG_OVR_EMPTY; - } - } - - if (LanguageSettingsManager.isWorkspaceProvider(provider)) { - overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_GLOBAL; -// overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_REFERENCE; -// overlayKeys[IDecoration.TOP_RIGHT] = CDTSharedImages.IMG_OVR_PARENT; -// overlayKeys[IDecoration.BOTTOM_RIGHT] = CDTSharedImages.IMG_OVR_LINK; - } else { -// overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_CONFIGURATION; -// overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_INDEXED; -// overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_CONTEXT; - -// overlayKeys[IDecoration.TOP_LEFT] = CDTSharedImages.IMG_OVR_PROJECT; - } - - } - return overlayKeys; + return new String[5]; } @Override @@ -107,24 +82,15 @@ public class LanguageSettingsProvidersLabelProvider extends LabelProvider { if (element instanceof ILanguageSettingsProvider) { ILanguageSettingsProvider provider = (ILanguageSettingsProvider) element; String name = provider.getName(); - if (name!=null) { + if (name != null) { if (LanguageSettingsManager.isWorkspaceProvider(provider)) { - name = name + " [ Shared ]"; + name = name + Messages.LanguageSettingsProvidersLabelProvider_TextDecorator_Shared; } return name; } - String id = provider.getId(); - return "[ Not accessible id="+id+" ]"; + return NLS.bind(Messages.GeneralMessages_NonAccessibleID, provider.getId()); } return OOPS; } - /** - * Temporary method for debugging only - */ - @Deprecated - private boolean isDebugging() { - return false; -// return true; - } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/Page_LanguageSettingsProviders.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersPage.java similarity index 69% rename from core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/Page_LanguageSettingsProviders.java rename to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersPage.java index a9a8b6f7dc9..02883e43e5d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/Page_LanguageSettingsProviders.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/language/settings/providers/LanguageSettingsProvidersPage.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Intel Corporation and others. + * Copyright (c) 2010, 2012 Andrew Gvozdev 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: - * Intel Corporation - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.ui.language.settings.providers; @@ -15,10 +15,12 @@ import org.eclipse.cdt.ui.newui.AbstractPage; import org.eclipse.cdt.ui.newui.ICPropertyTab; /** + * Property page for language settings providers tabs. + * * @noextend This class is not intended to be subclassed by clients. * @noinstantiate This class is not intended to be instantiated by clients. */ -public class Page_LanguageSettingsProviders extends AbstractPage { +public class LanguageSettingsProvidersPage extends AbstractPage { private Boolean isLanguageSettingsProvidersEnabled = null; @Override @@ -26,6 +28,11 @@ public class Page_LanguageSettingsProviders extends AbstractPage { return false; } + /** + * Check if language settings providers functionality is enabled for a current project. + * + * @noreference This method is temporary and not intended to be referenced by clients. + */ public boolean isLanguageSettingsProvidersEnabled() { if (isLanguageSettingsProvidersEnabled == null) { isLanguageSettingsProvidersEnabled = ScannerDiscoveryLegacySupport.isLanguageSettingsProvidersFunctionalityEnabled(getProject()); @@ -33,6 +40,11 @@ public class Page_LanguageSettingsProviders extends AbstractPage { return isLanguageSettingsProvidersEnabled; } + /** + * Enable or disable language settings providers functionality for a current project. + * + * @noreference This method is temporary and not intended to be referenced by clients. + */ public void setLanguageSettingsProvidersEnabled(boolean enable) { isLanguageSettingsProvidersEnabled = enable; forEach(ICPropertyTab.UPDATE,getResDesc()); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java index 972f5f68797..7e26e3a295c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/LanguageSettingsImages.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.ui.newui; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; @@ -23,6 +24,7 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.cdt.core.settings.model.ACPathEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.ui.CDTSharedImages; @@ -32,15 +34,9 @@ import org.eclipse.cdt.ui.CUIPlugin; * Helper class to provide unified images for {@link ICLanguageSettingEntry}. */ public class LanguageSettingsImages { - // AG FIXME - replace usage with version taking cfgDescription - @Deprecated public static Image getImage(int kind, int flags, boolean isProjectRelative) { String imageKey = getImageKey(kind, flags, isProjectRelative); - if (imageKey!=null) { -// String overlayKey = getErrorOverlayKey(kind, flags, isProjectRelative); -// if (overlayKey!=null) { -// return getOverlaidImage(imageKey, overlayKey, IDecoration.BOTTOM_LEFT); -// } + if (imageKey != null) { return CDTSharedImages.getImage(imageKey); } return null; @@ -48,17 +44,26 @@ public class LanguageSettingsImages { /** * Returns image for the given entry from internally managed repository including - * necessary overlays. This method is shortcut for {@link #getImage(ICLanguageSettingEntry, String, ICConfigurationDescription)} - * when no project is available. + * necessary overlays for given configuration description. * * @param entry - language settings entry to get an image for. + * @param cfgDescription - configuration description of the entry. * @return the image for the entry with appropriate overlays. - * - * AG FIXME - replace usage with version taking cfgDescription */ - @Deprecated - public static Image getImage(ICLanguageSettingEntry entry) { - return getImage(entry, null, null); + public static Image getImage(ICLanguageSettingEntry entry, ICConfigurationDescription cfgDescription) { + String projectName = null; + + if (cfgDescription != null) { + ICProjectDescription prjDescription = cfgDescription.getProjectDescription(); + if (prjDescription != null) { + IProject project = prjDescription.getProject(); + if (project != null) { + projectName = project.getName(); + } + } + } + + return getImage(entry, projectName, cfgDescription); } /** @@ -66,11 +71,11 @@ public class LanguageSettingsImages { */ public static String getImageKey(int kind, int flag, boolean isProjectRelative) { String imageKey = null; - + boolean isWorkspacePath = (flag & ICSettingEntry.VALUE_WORKSPACE_PATH) != 0; boolean isBuiltin = (flag & ICSettingEntry.BUILTIN) != 0; boolean isFramework = (flag & ICSettingEntry.FRAMEWORKS_MAC) != 0; - + switch (kind) { case ICSettingEntry.INCLUDE_PATH: if (isWorkspacePath) { @@ -118,7 +123,7 @@ public class LanguageSettingsImages { * @param cfgDescription - configuration description of the entry. * @return the image for the entry with appropriate overlays. */ - public static Image getImage(ICLanguageSettingEntry entry, String projectName, ICConfigurationDescription cfgDescription) { + private static Image getImage(ICLanguageSettingEntry entry, String projectName, ICConfigurationDescription cfgDescription) { int kind = entry.getKind(); int flags = entry.getFlags(); boolean isWorkspacePath = (flags & ICSettingEntry.VALUE_WORKSPACE_PATH) != 0; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.java index 5fc35ae36db..1f5e16eddd7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.java @@ -139,7 +139,6 @@ public class Messages extends NLS { public static String EnvironmentTab_8; public static String EnvironmentTab_9; public static String ErrorParsTab_error_IllegalCharacter; - public static String ErrorParsTab_error_NonAccessibleID; public static String ErrorParsTab_error_NonEmptyName; public static String ErrorParsTab_error_NonUniqueID; public static String ErrorParsTab_error_OnApplyingSettings; @@ -175,6 +174,8 @@ public class Messages extends NLS { public static String FileListControl_editdialog_title; public static String FileListControl_movedown; public static String FileListControl_moveup; + public static String GeneralMessages_InternalError_ReportLogToCdtTeam; + public static String GeneralMessages_NonAccessibleID; public static String IncludeDialog_0; public static String IncludeDialog_1; public static String IncludeDialog_2; @@ -187,18 +188,42 @@ public class Messages extends NLS { public static String IncludeTab_2; public static String IncludeTab_export; public static String IncludeTab_import; + public static String LanguageSettingEntryDialog_Add; + public static String LanguageSettingEntryDialog_BuiltInFlag; + public static String LanguageSettingEntryDialog_Directory; + public static String LanguageSettingEntryDialog_File; + public static String LanguageSettingEntryDialog_Filesystem; + public static String LanguageSettingEntryDialog_FrameworkFolder; + public static String LanguageSettingEntryDialog_IncludeDirectory; + public static String LanguageSettingEntryDialog_IncludeFile; + public static String LanguageSettingEntryDialog_Library; + public static String LanguageSettingEntryDialog_LibraryPath; + public static String LanguageSettingEntryDialog_Name; + public static String LanguageSettingEntryDialog_Path; + public static String LanguageSettingEntryDialog_PreporocessorMacro; + public static String LanguageSettingEntryDialog_PreprocessorMacroFile; + public static String LanguageSettingEntryDialog_ProjectRelative; + public static String LanguageSettingEntryDialog_SelectKind; + public static String LanguageSettingEntryDialog_Value; + public static String LanguageSettingEntryDialog_WorkspacePath; + public static String LanguageSettingsEntriesTab_Cannot_Determine_Languages; + public static String LanguageSettingsEntriesTab_Entries_Not_Editable; public static String LanguageSettingsImages_FileDoesNotExist; public static String LanguageSettingsImages_FolderDoesNotExist; public static String LanguageSettingsImages_UsingRelativePathsNotRecommended; + public static String LanguageSettingsProvidersLabelProvider_TextDecorator_Shared; public static String LanguageSettingsProviderTab_AreYouSureToResetProviders; public static String LanguageSettingsProviderTab_Clear; - public static String LanguageSettingsProviderTab_Configure; - public static String LanguageSettingsProviderTab_ErrorPerformingDefaults; + public static String LanguageSettingsProviderTab_LanguageSettingsProvidersOptions; + public static String LanguageSettingsProviderTab_OptionsCanBeChangedInPreferencesDiscoveryTab; public static String LanguageSettingsProviderTab_ProviderOptions; + public static String LanguageSettingsProviderTab_Reset; public static String LanguageSettingsProviderTab_SettingEntries; public static String LanguageSettingsProviderTab_SettingEntriesTooltip; - public static String LanguageSettingsProviderTab_ShowEntries; + public static String LanguageSettingsProviderTab_ShareProviders; + public static String LanguageSettingsProviderTab_StoreEntriesInsideProject; public static String LanguageSettingsProviderTab_TitleResetProviders; + public static String LanguageSettingsProviderTab_WorkspaceSettings; public static String LanguagesTab_0; public static String LanguagesTab_1; public static String LibraryPathTab_1; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties index 84ed1fec698..284f752f134 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/newui/Messages.properties @@ -166,18 +166,42 @@ IncludeDialog_0=Directory: IncludeDialog_1=File: IncludeDialog_2=Add to all configurations IncludeDialog_3=Add to all languages +LanguageSettingEntryDialog_Add=Add +LanguageSettingEntryDialog_BuiltInFlag=Treat as Built-In (Ignore during build) +LanguageSettingEntryDialog_Directory=Dir: +LanguageSettingEntryDialog_File=File: +LanguageSettingEntryDialog_Filesystem=Filesystem +LanguageSettingEntryDialog_FrameworkFolder=Framework folder (Mac only) +LanguageSettingEntryDialog_IncludeDirectory=Include Directory +LanguageSettingEntryDialog_IncludeFile=Include File +LanguageSettingEntryDialog_Library=Library +LanguageSettingEntryDialog_LibraryPath=Library Path +LanguageSettingEntryDialog_Name=Name: +LanguageSettingEntryDialog_Path=Path: +LanguageSettingEntryDialog_PreporocessorMacro=Preprocessor Macro +LanguageSettingEntryDialog_PreprocessorMacroFile=Preprocessor Macros File +LanguageSettingEntryDialog_ProjectRelative=Project-Relative +LanguageSettingEntryDialog_SelectKind=Select Kind: +LanguageSettingEntryDialog_Value=Value: +LanguageSettingEntryDialog_WorkspacePath=Workspace Path +LanguageSettingsEntriesTab_Cannot_Determine_Languages=Cannot determine toolchain languages. +LanguageSettingsEntriesTab_Entries_Not_Editable=Setting entries for this provider are supplied by the system and are not editable. LanguageSettingsImages_FileDoesNotExist=The selected file does not exist or not accessible. LanguageSettingsImages_FolderDoesNotExist=The selected folder does not exist or not accessible. LanguageSettingsImages_UsingRelativePathsNotRecommended=Using relative paths is ambiguous and not recommended. It can cause unexpected effects. +LanguageSettingsProvidersLabelProvider_TextDecorator_Shared=\ \ \ [ Shared ] LanguageSettingsProviderTab_AreYouSureToResetProviders=Are you sure you want to reset all customized language settings providers?\nPlease note that providers may regain entries on their own schedule. LanguageSettingsProviderTab_Clear=Clear Entries -LanguageSettingsProviderTab_Configure=Configure -LanguageSettingsProviderTab_ErrorPerformingDefaults=Error restoring defaults for language settings providers +LanguageSettingsProviderTab_LanguageSettingsProvidersOptions=Language Settings Provider Options +LanguageSettingsProviderTab_OptionsCanBeChangedInPreferencesDiscoveryTab=Options of global providers below can be changed in {0}, Discovery Tab. +LanguageSettingsProviderTab_Reset=Reset LanguageSettingsProviderTab_ProviderOptions=Language Settings Provider Options LanguageSettingsProviderTab_SettingEntries=Setting Entries LanguageSettingsProviderTab_SettingEntriesTooltip=Setting Entries -LanguageSettingsProviderTab_ShowEntries=Show Entries +LanguageSettingsProviderTab_ShareProviders=Share setting entries between projects (global provider) +LanguageSettingsProviderTab_StoreEntriesInsideProject=Store entries in project settings folder (easing project miration) LanguageSettingsProviderTab_TitleResetProviders=Reset Language Settings Providers +LanguageSettingsProviderTab_WorkspaceSettings=Workspace Settings LanguagesTab_0=Content type LanguagesTab_1=Language LibraryPathTab_1=Add... @@ -216,7 +240,6 @@ ErrorParsTab_error_NonEmptyName=Specify non empty name ErrorParsTab_error_NonUniqueID=Error parser ID is not unique, specify different name ErrorParsTab_error_OnApplyingSettings=Error applying Error Parser Tab settings ErrorParsTab_error_OnRestoring=Error restoring default Error Parser Tab settings -ErrorParsTab_error_NonAccessibleID=[ Not accessible id={0} ] ErrorParsTab_error_IllegalCharacter=Special character ''{0}'' is not allowed ErrorParsTab_label_EnterName=Enter name of new error parser: ErrorParsTab_label_DefaultRegexErrorParserName=Regex Error Parser @@ -284,6 +307,8 @@ CDTMainWizardPage_1=Project category is selected. Expand the category and select CDTMainWizardPage_TrySD90=I want to try new upcoming version of Scanner Discovery in CDT 9.0 (sd90 v.0.9.0) CProjectWizard_0=Add C Project Nature CCProjectWizard_0=Add CC Project Nature +GeneralMessages_InternalError_ReportLogToCdtTeam=Internal error happened, report application log to CDT team. +GeneralMessages_NonAccessibleID=[ Not accessible id={0} ] WorkingSetConfigAction_21=Building project WorkingSetConfigAction_22=Build error IncludeTab_export=Export Settings... diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java index 63e0fe4ec34..637b944fa27 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractLangsListTab.java @@ -19,7 +19,6 @@ import java.util.Comparator; import java.util.LinkedList; import java.util.List; -import org.eclipse.core.resources.IProject; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.IFontProvider; import org.eclipse.jface.viewers.IStructuredContentProvider; @@ -242,7 +241,7 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab { int index = table.getSelectionIndex(); if (index<0 || table.getSelectionIndices().length!=1) return null; - + return (ICLanguageSettingEntry)(table.getItem(index).getData()); } @@ -730,8 +729,7 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab { public Image getColumnImage(Object element, int columnIndex) { if (columnIndex==0 && (element instanceof ICLanguageSettingEntry)) { ICConfigurationDescription cfg = getResDesc().getConfiguration(); - IProject project = cfg.getProjectDescription().getProject(); - return LanguageSettingsImages.getImage((ICLanguageSettingEntry) element, project.getName(), cfg); + return LanguageSettingsImages.getImage((ICLanguageSettingEntry) element, cfg); } return null; } @@ -760,7 +758,7 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab { } else if (columnIndex == 0) { return element.toString(); } - + return null; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ErrorParsTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ErrorParsTab.java index fe692d14e27..c8e9e891a81 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ErrorParsTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ErrorParsTab.java @@ -166,7 +166,7 @@ public class ErrorParsTab extends AbstractCPropertyTab { return name; } } - return NLS.bind(Messages.ErrorParsTab_error_NonAccessibleID, id); + return NLS.bind(Messages.GeneralMessages_NonAccessibleID, id); } return OOPS; }