blob: 75b903be55b296e11c7f4a940df308b47a52ea06 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ant.internal.ui.preferences;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.ant.internal.ui.AntSourceViewerConfiguration;
import org.eclipse.ant.internal.ui.AntUIPlugin;
import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
import org.eclipse.ant.internal.ui.editor.text.AntDocumentSetupParticipant;
import org.eclipse.ant.internal.ui.editor.text.IAntEditorColorConstants;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.model.WorkbenchViewerSorter;
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
/*
* The page for setting the editor options.
*/
public class AntEditorPreferencePage extends AbstractAntEditorPreferencePage {
protected static class ControlData {
private String fKey;
private String[] fValues;
public ControlData(String key, String[] values) {
fKey= key;
fValues= values;
}
public String getKey() {
return fKey;
}
public String getValue(boolean selection) {
int index= selection ? 0 : 1;
return fValues[index];
}
public String getValue(int index) {
return fValues[index];
}
public int getSelection(String value) {
if (value != null) {
for (int i= 0; i < fValues.length; i++) {
if (value.equals(fValues[i])) {
return i;
}
}
}
return fValues.length -1; // assume the last option is the least severe
}
}
/**
* Item in the highlighting color list.
*
* @since 3.0
*/
private class HighlightingColorListItem {
/** Display name */
private String fDisplayName;
/** Color preference key */
private String fColorKey;
/** Bold preference key */
private String fBoldKey;
/** Italic preference key */
private String fItalicKey;
/** Item color */
private Color fItemColor;
/**
* Initialize the item with the given values.
*
* @param displayName the display name
* @param colorKey the color preference key
* @param boldKey the bold preference key
* @param italicKey the italic preference key
* @param itemColor the item color
*/
public HighlightingColorListItem(String displayName, String colorKey, String boldKey, String italicKey, Color itemColor) {
fDisplayName= displayName;
fColorKey= colorKey;
fBoldKey= boldKey;
fItalicKey= italicKey;
fItemColor= itemColor;
}
/**
* @return the bold preference key
*/
public String getBoldKey() {
return fBoldKey;
}
/**
* @return the bold preference key
*/
public String getItalicKey() {
return fItalicKey;
}
/**
* @return the color preference key
*/
public String getColorKey() {
return fColorKey;
}
/**
* @return the display name
*/
public String getDisplayName() {
return fDisplayName;
}
/**
* @return the item color
*/
public Color getItemColor() {
return fItemColor;
}
}
/**
* Color list label provider.
*
* @since 3.0
*/
private class ColorListLabelProvider extends LabelProvider implements IColorProvider {
/*
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*/
public String getText(Object element) {
return ((HighlightingColorListItem)element).getDisplayName();
}
/*
* @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
*/
public Color getForeground(Object element) {
return ((HighlightingColorListItem)element).getItemColor();
}
/*
* @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
*/
public Color getBackground(Object element) {
return null;
}
}
/**
* Color list content provider.
*
* @since 3.0
*/
private class ColorListContentProvider implements IStructuredContentProvider {
/*
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements(Object inputElement) {
return ((java.util.List)inputElement).toArray();
}
/*
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
}
/*
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
}
/** The keys of the overlay store. */
private String[][] fSyntaxColorListModel;
private final String[] fProblemPreferenceKeys= new String[] {
AntEditorPreferenceConstants.PROBLEM_CLASSPATH,
AntEditorPreferenceConstants.PROBLEM_PROPERTIES,
AntEditorPreferenceConstants.PROBLEM_IMPORTS,
AntEditorPreferenceConstants.PROBLEM_TASKS,
AntEditorPreferenceConstants.PROBLEM_SECURITY
};
private ColorEditor fSyntaxForegroundColorEditor;
private Button fBoldCheckBox;
private Button fItalicCheckBox;
private TableViewer fHighlightingColorListViewer;
private final java.util.List fHighlightingColorList= new ArrayList(5);
private SourceViewer fPreviewViewer;
private AntPreviewerUpdater fPreviewerUpdater;
private SelectionListener fSelectionListener;
protected Map fWorkingValues;
protected List fComboBoxes;
private List fProblemLabels;
private Button fIgnoreAllProblems;
private Text fBuildFilesToIgnoreProblems;
private Label fBuildFilesToIgnoreProblemsLabel;
private Label fSeverityLabel;
private Label fBuildFilesToIgnoreProblemsDescription;
public AntEditorPreferencePage() {
super();
setDescription(AntPreferencesMessages.AntEditorPreferencePage_description);
}
protected OverlayPreferenceStore createOverlayStore() {
fSyntaxColorListModel= new String[][] {
{AntPreferencesMessages.AntEditorPreferencePage_Ant_editor_text_1, IAntEditorColorConstants.TEXT_COLOR, null},
{AntPreferencesMessages.AntEditorPreferencePage_Ant_editor_processing_instuctions_2, IAntEditorColorConstants.PROCESSING_INSTRUCTIONS_COLOR, null},
{AntPreferencesMessages.AntEditorPreferencePage_Ant_editor_constant_strings_3, IAntEditorColorConstants.STRING_COLOR, null},
{AntPreferencesMessages.AntEditorPreferencePage_Ant_editor_tags_4, IAntEditorColorConstants.TAG_COLOR, null},
{AntPreferencesMessages.AntEditorPreferencePage_Ant_editor_comments_5, IAntEditorColorConstants.XML_COMMENT_COLOR, null},
{AntPreferencesMessages.AntEditorPreferencePage_26, IAntEditorColorConstants.XML_DTD_COLOR, null}
};
ArrayList overlayKeys= new ArrayList();
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.CODEASSIST_AUTOINSERT));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_ENABLED));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_COMMENTS));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_DTD));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_DEFINING));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_FOLDING_TARGETS));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_MARK_OCCURRENCES));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.EDITOR_STICKY_OCCURRENCES));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AntEditorPreferenceConstants.BUILDFILE_NAMES_TO_IGNORE));
for (int i= 0; i < fSyntaxColorListModel.length; i++) {
String colorKey= fSyntaxColorListModel[i][1];
addTextKeyToCover(overlayKeys, colorKey);
}
OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
overlayKeys.toArray(keys);
return new OverlayPreferenceStore(getPreferenceStore(), keys);
}
private void addTextKeyToCover(ArrayList overlayKeys, String mainKey) {
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, mainKey));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, mainKey + AntEditorPreferenceConstants.EDITOR_BOLD_SUFFIX));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, mainKey + AntEditorPreferenceConstants.EDITOR_ITALIC_SUFFIX));
}
private Control createAppearancePage(Composite parent) {
Font font= parent.getFont();
Composite appearanceComposite= new Composite(parent, SWT.NONE);
appearanceComposite.setFont(font);
GridLayout layout= new GridLayout();
layout.numColumns= 2;
appearanceComposite.setLayout(layout);
String labelText= AntPreferencesMessages.AntEditorPreferencePage_2;
addCheckBox(appearanceComposite, labelText, AntEditorPreferenceConstants.EDITOR_MARK_OCCURRENCES, 0);
labelText= AntPreferencesMessages.AntEditorPreferencePage_4;
addCheckBox(appearanceComposite, labelText, AntEditorPreferenceConstants.EDITOR_STICKY_OCCURRENCES, 0);
labelText= AntPreferencesMessages.AntEditorPreferencePage_40;
addCheckBox(appearanceComposite, labelText, AntEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS, 0);
labelText= AntPreferencesMessages.AntEditorPreferencePage_32;
addCheckBox(appearanceComposite, labelText, AntEditorPreferenceConstants.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE, 0);
return appearanceComposite;
}
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
protected Control createContents(Composite parent) {
PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IAntUIHelpContextIds.ANT_EDITOR_PREFERENCE_PAGE);
getOverlayStore().load();
getOverlayStore().start();
createHeader(parent);
TabFolder folder= new TabFolder(parent, SWT.NONE);
folder.setLayout(new TabFolderLayout());
folder.setLayoutData(new GridData(GridData.FILL_BOTH));
TabItem item= new TabItem(folder, SWT.NONE);
item.setText(AntPreferencesMessages.AntEditorPreferencePage_general);
item.setControl(createAppearancePage(folder));
item= new TabItem(folder, SWT.NONE);
item.setText(AntPreferencesMessages.AntEditorPreferencePage_1);
item.setControl(createSyntaxPage(folder));
item= new TabItem(folder, SWT.NONE);
item.setText(AntPreferencesMessages.AntEditorPreferencePage_10);
item.setControl(createProblemsTabContent(folder));
item= new TabItem(folder, SWT.NONE);
item.setText(AntPreferencesMessages.AntEditorPreferencePage_19);
item.setControl(createFoldingTabContent(folder));
initialize();
applyDialogFont(parent);
return folder;
}
private Control createFoldingTabContent(TabFolder folder) {
Composite composite= new Composite(folder, SWT.NULL);
GridLayout layout= new GridLayout();
layout.numColumns= 2;
composite.setLayout(layout);
addCheckBox(composite, AntPreferencesMessages.AntEditorPreferencePage_20, AntEditorPreferenceConstants.EDITOR_FOLDING_ENABLED, 0);
Label label= new Label(composite, SWT.LEFT);
label.setText(AntPreferencesMessages.AntEditorPreferencePage_21);
addCheckBox(composite, AntPreferencesMessages.AntEditorPreferencePage_22, AntEditorPreferenceConstants.EDITOR_FOLDING_DTD, 0);
addCheckBox(composite, AntPreferencesMessages.AntEditorPreferencePage_23, AntEditorPreferenceConstants.EDITOR_FOLDING_COMMENTS, 0);
addCheckBox(composite, AntPreferencesMessages.AntEditorPreferencePage_24, AntEditorPreferenceConstants.EDITOR_FOLDING_DEFINING, 0);
addCheckBox(composite, AntPreferencesMessages.AntEditorPreferencePage_25, AntEditorPreferenceConstants.EDITOR_FOLDING_TARGETS, 0);
return composite;
}
private void initialize() {
initializeFields();
for (int i= 0, n= fSyntaxColorListModel.length; i < n; i++) {
fHighlightingColorList.add(
new HighlightingColorListItem (fSyntaxColorListModel[i][0], fSyntaxColorListModel[i][1],
fSyntaxColorListModel[i][1] + AntEditorPreferenceConstants.EDITOR_BOLD_SUFFIX,
fSyntaxColorListModel[i][1] + AntEditorPreferenceConstants.EDITOR_ITALIC_SUFFIX, null));
}
fHighlightingColorListViewer.setInput(fHighlightingColorList);
fHighlightingColorListViewer.setSelection(new StructuredSelection(fHighlightingColorListViewer.getElementAt(0)));
}
/* (non-Javadoc)
* @see org.eclipse.ant.internal.ui.preferences.AbstractAntEditorPreferencePage#handleDefaults()
*/
protected void handleDefaults() {
handleSyntaxColorListSelection();
restoreWorkingValuesToDefaults();
updateControlsForProblemReporting(!AntUIPlugin.getDefault().getCombinedPreferenceStore().getBoolean(AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL));
}
private Control createSyntaxPage(Composite parent) {
Composite colorComposite= new Composite(parent, SWT.NONE);
colorComposite.setLayout(new GridLayout());
Label label= new Label(colorComposite, SWT.LEFT);
label.setText(AntPreferencesMessages.AntEditorPreferencePage_5);
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Composite editorComposite= new Composite(colorComposite, SWT.NONE);
GridLayout layout= new GridLayout();
layout.numColumns= 2;
layout.marginHeight= 0;
layout.marginWidth= 0;
editorComposite.setLayout(layout);
GridData gd= new GridData(GridData.FILL_BOTH);
editorComposite.setLayoutData(gd);
fHighlightingColorListViewer= new TableViewer(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
fHighlightingColorListViewer.setLabelProvider(new ColorListLabelProvider());
fHighlightingColorListViewer.setContentProvider(new ColorListContentProvider());
fHighlightingColorListViewer.setSorter(new WorkbenchViewerSorter());
gd= new GridData(GridData.FILL_BOTH);
gd.heightHint= convertHeightInCharsToPixels(5);
fHighlightingColorListViewer.getControl().setLayoutData(gd);
Composite stylesComposite= new Composite(editorComposite, SWT.NONE);
layout= new GridLayout();
layout.marginHeight= 0;
layout.marginWidth= 0;
layout.numColumns= 2;
stylesComposite.setLayout(layout);
stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
label= new Label(stylesComposite, SWT.LEFT);
label.setText(AntPreferencesMessages.AntEditorPreferencePage_6);
gd= new GridData();
gd.horizontalAlignment= GridData.BEGINNING;
label.setLayoutData(gd);
fSyntaxForegroundColorEditor= new ColorEditor(stylesComposite);
Button foregroundColorButton= fSyntaxForegroundColorEditor.getButton();
gd= new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment= GridData.BEGINNING;
foregroundColorButton.setLayoutData(gd);
fBoldCheckBox= new Button(stylesComposite, SWT.CHECK);
fBoldCheckBox.setText(AntPreferencesMessages.AntEditorPreferencePage_7);
gd= new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment= GridData.BEGINNING;
gd.horizontalSpan= 2;
fBoldCheckBox.setLayoutData(gd);
fItalicCheckBox= new Button(stylesComposite, SWT.CHECK);
fItalicCheckBox.setText(AntPreferencesMessages.AntEditorPreferencePage_8);
gd= new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalAlignment= GridData.BEGINNING;
gd.horizontalSpan= 2;
fItalicCheckBox.setLayoutData(gd);
label= new Label(colorComposite, SWT.LEFT);
label.setText(AntPreferencesMessages.AntEditorPreferencePage_9);
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Control previewer= createPreviewer(colorComposite);
gd= new GridData(GridData.FILL_BOTH);
gd.widthHint= convertWidthInCharsToPixels(20);
gd.heightHint= convertHeightInCharsToPixels(5);
previewer.setLayoutData(gd);
fHighlightingColorListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
handleSyntaxColorListSelection();
}
});
foregroundColorButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
// do nothing
}
public void widgetSelected(SelectionEvent e) {
HighlightingColorListItem item= getHighlightingColorListItem();
PreferenceConverter.setValue(getOverlayStore(), item.getColorKey(), fSyntaxForegroundColorEditor.getColorValue());
}
});
fBoldCheckBox.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
// do nothing
}
public void widgetSelected(SelectionEvent e) {
HighlightingColorListItem item= getHighlightingColorListItem();
getOverlayStore().setValue(item.getBoldKey(), fBoldCheckBox.getSelection());
}
});
fItalicCheckBox.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
// do nothing
}
public void widgetSelected(SelectionEvent e) {
HighlightingColorListItem item= getHighlightingColorListItem();
getOverlayStore().setValue(item.getItalicKey(), fItalicCheckBox.getSelection());
}
});
return colorComposite;
}
private Control createPreviewer(Composite parent) {
fPreviewViewer = new SourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
AntSourceViewerConfiguration configuration = new AntSourceViewerConfiguration();
fPreviewViewer.configure(configuration);
fPreviewViewer.setEditable(false);
Font font= JFaceResources.getFont(JFaceResources.TEXT_FONT);
fPreviewViewer.getTextWidget().setFont(font);
IPreferenceStore store= new ChainedPreferenceStore(new IPreferenceStore[] { getOverlayStore(), EditorsUI.getPreferenceStore() });
fPreviewerUpdater= new AntPreviewerUpdater(fPreviewViewer, configuration, store);
String content= loadPreviewContentFromFile("SyntaxPreviewCode.txt"); //$NON-NLS-1$
IDocument document = new Document(content);
new AntDocumentSetupParticipant().setup(document);
fPreviewViewer.setDocument(document);
return fPreviewViewer.getControl();
}
private void handleSyntaxColorListSelection() {
HighlightingColorListItem item= getHighlightingColorListItem();
RGB rgb= PreferenceConverter.getColor(getOverlayStore(), item.getColorKey());
fSyntaxForegroundColorEditor.setColorValue(rgb);
fBoldCheckBox.setSelection(getOverlayStore().getBoolean(item.getBoldKey()));
fItalicCheckBox.setSelection(getOverlayStore().getBoolean(item.getItalicKey()));
}
/**
* Returns the current highlighting color list item.
*
* @return the current highlighting color list item
* @since 3.0
*/
private HighlightingColorListItem getHighlightingColorListItem() {
IStructuredSelection selection= (IStructuredSelection) fHighlightingColorListViewer.getSelection();
return (HighlightingColorListItem) selection.getFirstElement();
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#dispose()
*/
public void dispose() {
super.dispose();
if (fPreviewerUpdater != null) {
fPreviewerUpdater.dispose();
}
}
private Composite createProblemsTabContent(TabFolder folder) {
fComboBoxes= new ArrayList();
fProblemLabels= new ArrayList();
initializeWorkingValues();
String[] errorWarningIgnoreLabels= new String[] {
AntPreferencesMessages.AntEditorPreferencePage_11, AntPreferencesMessages.AntEditorPreferencePage_12, AntPreferencesMessages.AntEditorPreferencePage_13};
String[] errorWarningIgnore= new String[] {
AntEditorPreferenceConstants.BUILDFILE_ERROR,
AntEditorPreferenceConstants.BUILDFILE_WARNING,
AntEditorPreferenceConstants.BUILDFILE_IGNORE };
int nColumns= 3;
GridLayout layout= new GridLayout();
layout.numColumns= nColumns;
Composite othersComposite= new Composite(folder, SWT.NULL);
othersComposite.setLayout(layout);
String labelText= AntPreferencesMessages.AntEditorPreferencePage_28;
fIgnoreAllProblems= addCheckBox(othersComposite, labelText, AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL, 0);
fIgnoreAllProblems.addSelectionListener(getSelectionListener());
fBuildFilesToIgnoreProblemsDescription = new Label(othersComposite, SWT.WRAP);
fBuildFilesToIgnoreProblemsDescription.setText(AntPreferencesMessages.AntEditorPreferencePage_29);
GridData gd= new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
gd.horizontalSpan= nColumns;
fBuildFilesToIgnoreProblemsDescription.setLayoutData(gd);
Control[] controls= addLabelledTextField(othersComposite, AntPreferencesMessages.AntEditorPreferencePage_30, AntEditorPreferenceConstants.BUILDFILE_NAMES_TO_IGNORE, 50, 0, null);
fBuildFilesToIgnoreProblems= getTextControl(controls);
fBuildFilesToIgnoreProblemsLabel= getLabelControl(controls);
fSeverityLabel= new Label(othersComposite, SWT.WRAP);
fSeverityLabel.setText(AntPreferencesMessages.AntEditorPreferencePage_14);
gd= new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
gd.horizontalSpan= nColumns;
fSeverityLabel.setLayoutData(gd);
String label= AntPreferencesMessages.AntEditorPreferencePage_18;
addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_TASKS, errorWarningIgnore, errorWarningIgnoreLabels, 0);
label= AntPreferencesMessages.AntEditorPreferencePage_15;
addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_CLASSPATH, errorWarningIgnore, errorWarningIgnoreLabels, 0);
label= AntPreferencesMessages.AntEditorPreferencePage_16;
addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_PROPERTIES, errorWarningIgnore, errorWarningIgnoreLabels, 0);
label= AntPreferencesMessages.AntEditorPreferencePage_17;
addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_IMPORTS, errorWarningIgnore, errorWarningIgnoreLabels, 0);
label= AntPreferencesMessages.AntEditorPreferencePage_27;
addComboBox(othersComposite, label, AntEditorPreferenceConstants.PROBLEM_SECURITY, errorWarningIgnore, errorWarningIgnoreLabels, 0);
updateControlsForProblemReporting(!AntUIPlugin.getDefault().getCombinedPreferenceStore().getBoolean(AntEditorPreferenceConstants.BUILDFILE_IGNORE_ALL));
return othersComposite;
}
private void initializeWorkingValues() {
fWorkingValues= new HashMap(fProblemPreferenceKeys.length);
for (int i = 0; i < fProblemPreferenceKeys.length; i++) {
String key = fProblemPreferenceKeys[i];
fWorkingValues.put(key, getPreferenceStore().getString(key));
}
}
private void restoreWorkingValuesToDefaults() {
fWorkingValues= new HashMap(fProblemPreferenceKeys.length);
for (int i = 0; i < fProblemPreferenceKeys.length; i++) {
String key = fProblemPreferenceKeys[i];
fWorkingValues.put(key, getPreferenceStore().getDefaultString(key));
}
updateControls();
}
protected Combo addComboBox(Composite parent, String label, String key, String[] values, String[] valueLabels, int indent) {
ControlData data= new ControlData(key, values);
GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.horizontalIndent= indent;
Label labelControl= new Label(parent, SWT.LEFT | SWT.WRAP);
labelControl.setText(label);
labelControl.setLayoutData(gd);
Combo comboBox= new Combo(parent, SWT.READ_ONLY);
comboBox.setItems(valueLabels);
comboBox.setData(data);
comboBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
comboBox.addSelectionListener(getSelectionListener());
Label placeHolder= new Label(parent, SWT.NONE);
placeHolder.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
String currValue= (String)fWorkingValues.get(key);
comboBox.select(data.getSelection(currValue));
fProblemLabels.add(labelControl);
fComboBoxes.add(comboBox);
return comboBox;
}
protected SelectionListener getSelectionListener() {
if (fSelectionListener == null) {
fSelectionListener= new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {}
public void widgetSelected(SelectionEvent e) {
controlChanged(e.widget);
}
};
}
return fSelectionListener;
}
protected void controlChanged(Widget widget) {
ControlData data= (ControlData) widget.getData();
String newValue= null;
if (widget instanceof Button) {
if (widget == fIgnoreAllProblems) {
updateControlsForProblemReporting(!((Button)widget).getSelection());
return;
}
newValue= data.getValue(((Button)widget).getSelection());
} else if (widget instanceof Combo) {
newValue= data.getValue(((Combo)widget).getSelectionIndex());
} else {
return;
}
fWorkingValues.put(data.getKey(), newValue);
}
private void updateControlsForProblemReporting(boolean reportProblems) {
for (int i= fComboBoxes.size() - 1; i >= 0; i--) {
((Control) fComboBoxes.get(i)).setEnabled(reportProblems);
((Control) fProblemLabels.get(i)).setEnabled(reportProblems);
}
fSeverityLabel.setEnabled(reportProblems);
fBuildFilesToIgnoreProblems.setEnabled(reportProblems);
fBuildFilesToIgnoreProblemsDescription.setEnabled(reportProblems);
fBuildFilesToIgnoreProblemsLabel.setEnabled(reportProblems);
}
protected void updateControls() {
// update the UI
for (int i= fComboBoxes.size() - 1; i >= 0; i--) {
Combo curr= (Combo) fComboBoxes.get(i);
ControlData data= (ControlData) curr.getData();
String currValue= (String) fWorkingValues.get(data.getKey());
curr.select(data.getSelection(currValue));
}
}
/* (non-Javadoc)
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
*/
public boolean performOk() {
Iterator iter= fWorkingValues.keySet().iterator();
IPreferenceStore store= getPreferenceStore();
while (iter.hasNext()) {
String key = (String) iter.next();
store.putValue(key, (String)fWorkingValues.get(key));
}
if (store.needsSaving()) {
//any AntModels listen for changes to the "PROBLEM" pref
//this is so that the models do not update for each and every pref modification
store.putValue(AntEditorPreferenceConstants.PROBLEM, "changed"); //$NON-NLS-1$
//ensure to clear as there may not be any models open currently
store.setToDefault(AntEditorPreferenceConstants.PROBLEM);
}
return super.performOk();
}
private void createHeader(Composite contents) {
final Link link= new Link(contents, SWT.NONE);
final String target= "org.eclipse.ui.preferencePages.GeneralTextEditor"; //$NON-NLS-1$
link.setText(AntPreferencesMessages.AntEditorPreferencePage_0);
link.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
PreferencesUtil.createPreferenceDialogOn(link.getShell(), target, null, null);
}
});
String linktooltip= AntPreferencesMessages.AntEditorPreferencePage_3;
link.setToolTipText(linktooltip);
}
}