| /******************************************************************************* |
| * Copyright (c) 2000, 2004 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Common Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/cpl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.ant.internal.ui.preferences; |
| |
| import java.util.ArrayList; |
| |
| import org.eclipse.jface.preference.PreferenceConverter; |
| 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.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.Composite; |
| import org.eclipse.swt.widgets.Control; |
| import org.eclipse.swt.widgets.Label; |
| import org.eclipse.swt.widgets.List; |
| import org.eclipse.swt.widgets.Text; |
| |
| /* |
| * The page for setting the Ant editor code assist options. |
| */ |
| public class AntCodeAssistPreferencePage extends AbstractAntEditorPreferencePage { |
| |
| private final String[][] fContentAssistColorListModel= new String[][] { |
| {AntPreferencesMessages.getString("AntCodeAssistPreferencePage.backgroundForCompletionProposals"), AntEditorPreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND }, //$NON-NLS-1$ |
| {AntPreferencesMessages.getString("AntCodeAssistPreferencePage.foregroundForCompletionProposals"), AntEditorPreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND }, //$NON-NLS-1$ |
| }; |
| |
| private List fContentAssistColorList; |
| private ColorEditor fContentAssistColorEditor; |
| |
| private Control fAutoInsertDelayText; |
| private Control fAutoInsertTriggerText; |
| private Label fAutoInsertDelayLabel; |
| private Label fAutoInsertTriggerLabel; |
| |
| protected OverlayPreferenceStore createOverlayStore() { |
| |
| ArrayList overlayKeys= new ArrayList(); |
| 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)); |
| |
| OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; |
| overlayKeys.toArray(keys); |
| return new OverlayPreferenceStore(getPreferenceStore(), keys); |
| } |
| |
| private Label getLabelControl(Control[] labelledTextField){ |
| return (Label)labelledTextField[0]; |
| } |
| |
| private Text getTextControl(Control[] labelledTextField){ |
| return (Text)labelledTextField[1]; |
| } |
| |
| private Control createContentAssistPage(Composite parent) { |
| Font font= parent.getFont(); |
| Composite contentAssistComposite= new Composite(parent, SWT.NULL); |
| GridLayout layout= new GridLayout(); |
| layout.numColumns= 2; |
| contentAssistComposite.setLayout(layout); |
| contentAssistComposite.setFont(font); |
| |
| String text= AntPreferencesMessages.getString("AntCodeAssistPreferencePage.Insert"); //$NON-NLS-1$ |
| addCheckBox(contentAssistComposite, text, AntEditorPreferenceConstants.CODEASSIST_AUTOINSERT, 0); |
| |
| text= AntPreferencesMessages.getString("AntCodeAssistPreferencePage.&Enable_auto_activation_2"); //$NON-NLS-1$ |
| final Button autoactivation= addCheckBox(contentAssistComposite, text, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION, 0); |
| autoactivation.addSelectionListener(new SelectionAdapter(){ |
| public void widgetSelected(SelectionEvent e) { |
| updateAutoactivationControls(); |
| } |
| }); |
| |
| Control[] labelledTextField; |
| text= AntPreferencesMessages.getString("AntCodeAssistPreferencePage.Auto_activation_&delay__3"); //$NON-NLS-1$ |
| String[] errorMessages= new String[]{AntPreferencesMessages.getString("AntCodeAssistPreferencePage.empty_input_auto_activation"), AntPreferencesMessages.getString("AntCodeAssistPreferencePage.invalid_input_auto_activation")}; //$NON-NLS-1$//$NON-NLS-2$ |
| labelledTextField= addLabelledTextField(contentAssistComposite, text, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY, 4, 0, errorMessages); |
| fAutoInsertDelayLabel= getLabelControl(labelledTextField); |
| fAutoInsertDelayText= getTextControl(labelledTextField); |
| |
| text= AntPreferencesMessages.getString("AntCodeAssistPreferencePage.Auto_activation_tri&ggers__4"); //$NON-NLS-1$ |
| labelledTextField= addLabelledTextField(contentAssistComposite, text, AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS, 4, 0, null); |
| fAutoInsertTriggerLabel= getLabelControl(labelledTextField); |
| fAutoInsertTriggerText= getTextControl(labelledTextField); |
| |
| Label label= new Label(contentAssistComposite, SWT.LEFT); |
| label.setText(AntPreferencesMessages.getString("AntCodeAssistPreferencePage.Code_assist_colo&r_options__5")); //$NON-NLS-1$ |
| label.setFont(font); |
| GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); |
| gd.horizontalSpan= 2; |
| label.setLayoutData(gd); |
| |
| Composite editorComposite= new Composite(contentAssistComposite, SWT.NONE); |
| layout= new GridLayout(); |
| layout.numColumns= 2; |
| layout.marginHeight= 0; |
| layout.marginWidth= 0; |
| editorComposite.setLayout(layout); |
| editorComposite.setFont(font); |
| gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL); |
| gd.horizontalSpan= 2; |
| editorComposite.setLayoutData(gd); |
| |
| fContentAssistColorList= new List(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); |
| gd= new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL); |
| gd.heightHint= convertHeightInCharsToPixels(3); |
| fContentAssistColorList.setLayoutData(gd); |
| fContentAssistColorList.setFont(font); |
| |
| 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)); |
| stylesComposite.setFont(font); |
| |
| label= new Label(stylesComposite, SWT.LEFT); |
| label.setText(AntPreferencesMessages.getString("AntEditorPreferencePage.Col&or__6")); //$NON-NLS-1$ |
| label.setFont(font); |
| gd= new GridData(); |
| gd.horizontalAlignment= GridData.BEGINNING; |
| label.setLayoutData(gd); |
| |
| fContentAssistColorEditor= new ColorEditor(stylesComposite); |
| Button colorButton= fContentAssistColorEditor.getButton(); |
| gd= new GridData(GridData.FILL_HORIZONTAL); |
| gd.horizontalAlignment= GridData.BEGINNING; |
| colorButton.setLayoutData(gd); |
| |
| fContentAssistColorList.addSelectionListener(new SelectionListener() { |
| public void widgetDefaultSelected(SelectionEvent e) { |
| // do nothing |
| } |
| public void widgetSelected(SelectionEvent e) { |
| handleContentAssistColorListSelection(); |
| } |
| }); |
| |
| colorButton.addSelectionListener(new SelectionListener() { |
| public void widgetDefaultSelected(SelectionEvent e) { |
| // do nothing |
| } |
| public void widgetSelected(SelectionEvent e) { |
| int i= fContentAssistColorList.getSelectionIndex(); |
| String key= fContentAssistColorListModel[i][1]; |
| |
| PreferenceConverter.setValue(getOverlayStore(), key, fContentAssistColorEditor.getColorValue()); |
| } |
| }); |
| |
| return contentAssistComposite; |
| } |
| |
| private void handleContentAssistColorListSelection() { |
| int i= fContentAssistColorList.getSelectionIndex(); |
| String key= fContentAssistColorListModel[i][1]; |
| RGB rgb= PreferenceConverter.getColor(getOverlayStore(), key); |
| fContentAssistColorEditor.setColorValue(rgb); |
| } |
| |
| private void updateAutoactivationControls() { |
| boolean autoactivation= getOverlayStore().getBoolean(AntEditorPreferenceConstants.CODEASSIST_AUTOACTIVATION); |
| fAutoInsertDelayText.setEnabled(autoactivation); |
| fAutoInsertDelayLabel.setEnabled(autoactivation); |
| |
| fAutoInsertTriggerText.setEnabled(autoactivation); |
| fAutoInsertTriggerLabel.setEnabled(autoactivation); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) |
| */ |
| protected Control createContents(Composite parent) { |
| getOverlayStore().load(); |
| getOverlayStore().start(); |
| |
| Composite control= new Composite(parent, SWT.NONE); |
| GridLayout layout= new GridLayout(); |
| layout.numColumns= 2; |
| layout.marginHeight= 0; |
| layout.marginWidth= 0; |
| control.setLayout(layout); |
| createContentAssistPage(control); |
| |
| initialize(); |
| |
| applyDialogFont(control); |
| //TODO set help context |
| //WorkbenchHelp.setHelp(control, IAntUIHelpContextIds.ANT_CONTENTASSIST_PREFERENCE_PAGE); |
| return control; |
| } |
| |
| private void initialize() { |
| |
| initializeFields(); |
| |
| for (int i= 0; i < fContentAssistColorListModel.length; i++) { |
| fContentAssistColorList.add(fContentAssistColorListModel[i][0]); |
| } |
| fContentAssistColorList.getDisplay().asyncExec(new Runnable() { |
| public void run() { |
| if (fContentAssistColorList != null && !fContentAssistColorList.isDisposed()) { |
| fContentAssistColorList.select(0); |
| handleContentAssistColorListSelection(); |
| } |
| } |
| }); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.ant.internal.ui.preferences.AbstractAntEditorPreferencePage#handleDefaults() |
| */ |
| protected void handleDefaults() { |
| handleContentAssistColorListSelection(); |
| } |
| } |