2 * Copyright (c) 2003-2004 Christopher Lenz and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * Christopher Lenz - initial API and implementation
11 * $Id: CssEditorContentAssistConfigurationBlock.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $
14 package net.sourceforge.phpeclipse.css.ui.internal.preferences;
16 import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages;
17 import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences;
19 import org.eclipse.jface.preference.ColorSelector;
20 import org.eclipse.jface.preference.IPreferenceStore;
21 import org.eclipse.jface.preference.PreferenceConverter;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.events.SelectionAdapter;
24 import org.eclipse.swt.events.SelectionEvent;
25 import org.eclipse.swt.events.SelectionListener;
26 import org.eclipse.swt.graphics.RGB;
27 import org.eclipse.swt.layout.GridData;
28 import org.eclipse.swt.layout.GridLayout;
29 import org.eclipse.swt.widgets.Button;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Label;
33 import org.eclipse.swt.widgets.List;
36 * Configuration block for setting the preferences related to content assist.
38 final class CssEditorContentAssistConfigurationBlock
39 extends AbstractConfigurationBlock {
41 // Instance Variables ------------------------------------------------------
43 private List fColorList;
44 private final String[][] fColorListModel = new String[][] {
45 { getString("backgroundForCompletionProposals"), //$NON-NLS-1$
46 CssUIPreferences.CONTENTASSIST_PROPOSALS_BACKGROUND },
47 { getString("foregroundForCompletionProposals"), //$NON-NLS-1$
48 CssUIPreferences.CONTENTASSIST_PROPOSALS_FOREGROUND },
50 private ColorSelector fColorSelector;
51 private Control fAutoActivationDelayField;
52 private Control fAutoActivationTriggersField;
54 // Constructors ------------------------------------------------------------
56 public CssEditorContentAssistConfigurationBlock(IPreferenceStore store) {
60 // Public Methods ----------------------------------------------------------
62 public Control createControl(Composite parent) {
64 Composite composite = new Composite(parent, SWT.NONE);
65 GridLayout layout = new GridLayout();
66 layout.numColumns = 2;
67 composite.setLayout(layout);
69 //addCompletionRadioButtons(contentAssistComposite);
71 addBooleanField(composite,
72 getString("insertSingleProposalsAutomatically"), //$NON-NLS-1$
73 CssUIPreferences.CONTENTASSIST_AUTOINSERT, 0);
74 addBooleanField(composite,
75 getString("presentProposalsInAlphabeticalOrder"), //$NON-NLS-1$
76 CssUIPreferences.CONTENTASSIST_ORDER_PROPOSALS, 0);
77 addBooleanField(composite,
78 getString("enableAutoActivation"), //$NON-NLS-1$
79 CssUIPreferences.CONTENTASSIST_AUTOACTIVATION,
80 0).addSelectionListener(new SelectionAdapter() {
81 public void widgetSelected(SelectionEvent e) {
82 updateAutoactivationControls();
85 fAutoActivationDelayField = addIntegerField(composite,
86 getString("autoActivationDelay"), //$NON-NLS-1$
87 CssUIPreferences.CONTENTASSIST_AUTOACTIVATION_DELAY, 4, 0);
88 fAutoActivationTriggersField = addTextField(composite,
89 getString("autoActivationTriggers"), //$NON-NLS-1$
90 CssUIPreferences.CONTENTASSIST_AUTOACTIVATION_TRIGGERS, 4, 0);
92 Label label = new Label(composite, SWT.LEFT);
93 label.setText(getString("colorOptions")); //$NON-NLS-1$
94 GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
95 gridData.horizontalSpan = 2;
96 label.setLayoutData(gridData);
98 Composite editorComposite = new Composite(composite, SWT.NONE);
99 layout = new GridLayout();
100 layout.numColumns = 2;
101 layout.marginHeight = 0;
102 layout.marginWidth = 0;
103 editorComposite.setLayout(layout);
104 gridData = new GridData(
105 GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
106 gridData.horizontalSpan = 2;
107 editorComposite.setLayoutData(gridData);
109 fColorList = new List(editorComposite,
110 SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
111 gridData = new GridData(
112 GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL);
113 gridData.heightHint = convertHeightInCharsToPixels(composite, 8);
114 fColorList.setLayoutData(gridData);
115 fColorList.addSelectionListener(new SelectionListener() {
116 public void widgetDefaultSelected(SelectionEvent e) {
119 public void widgetSelected(SelectionEvent e) {
120 handleColorListSelection();
124 Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
125 layout = new GridLayout();
126 layout.marginHeight = 0;
127 layout.marginWidth = 0;
128 layout.numColumns = 2;
129 stylesComposite.setLayout(layout);
130 stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
131 label = new Label(stylesComposite, SWT.LEFT);
132 label.setText(getString("color")); //$NON-NLS-1$
133 gridData = new GridData();
134 gridData.horizontalAlignment = GridData.BEGINNING;
135 label.setLayoutData(gridData);
137 fColorSelector = new ColorSelector(stylesComposite);
138 Button colorButton = fColorSelector.getButton();
139 gridData = new GridData(GridData.FILL_HORIZONTAL);
140 gridData.horizontalAlignment = GridData.BEGINNING;
141 colorButton.setLayoutData(gridData);
142 colorButton.addSelectionListener(new SelectionListener() {
143 public void widgetDefaultSelected(SelectionEvent e) {
146 public void widgetSelected(SelectionEvent e) {
147 int i = fColorList.getSelectionIndex();
148 String key = fColorListModel[i][1];
149 PreferenceConverter.setValue(getPreferenceStore(), key,
150 fColorSelector.getColorValue());
159 // Event Handlers ----------------------------------------------------------
161 void handleColorListSelection() {
162 int i = fColorList.getSelectionIndex();
163 String key = fColorListModel[i][1];
164 RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key);
165 fColorSelector.setColorValue(rgb);
168 // Private Methods ---------------------------------------------------------
170 private static String getString(String key) {
171 return CssUIMessages.getString(
172 "CssEditorPreferencePage.contentAssist." + key); //$NON-NLS-1$
175 private void initialize() {
176 for (int i = 0; i < fColorListModel.length; i++) {
177 fColorList.add(fColorListModel[i][0]);
179 fColorList.getDisplay().asyncExec(new Runnable() {
181 if ((fColorList != null)
182 && !fColorList.isDisposed()) {
183 fColorList.select(0);
184 handleColorListSelection();
191 private void updateAutoactivationControls() {
192 boolean enabled = getPreferenceStore().getBoolean(
193 CssUIPreferences.CONTENTASSIST_AUTOACTIVATION);
194 fAutoActivationDelayField.setEnabled(enabled);
195 getLabel(fAutoActivationDelayField).setEnabled(enabled);
196 fAutoActivationTriggersField.setEnabled(enabled);
197 getLabel(fAutoActivationTriggersField).setEnabled(enabled);