Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 219312 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/datatools/sqltools/sqleditor/preferences/SyntaxColoringPage.java (-11 / +77 lines)
Lines 41-58 Link Here
41
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.SWT;
42
import org.eclipse.swt.events.SelectionEvent;
42
import org.eclipse.swt.events.SelectionEvent;
43
import org.eclipse.swt.events.SelectionListener;
43
import org.eclipse.swt.events.SelectionListener;
44
import org.eclipse.swt.graphics.Color;
44
import org.eclipse.swt.graphics.RGB;
45
import org.eclipse.swt.graphics.RGB;
45
import org.eclipse.swt.layout.GridData;
46
import org.eclipse.swt.layout.GridData;
46
import org.eclipse.swt.layout.GridLayout;
47
import org.eclipse.swt.layout.GridLayout;
47
import org.eclipse.swt.widgets.Button;
48
import org.eclipse.swt.widgets.Button;
48
import org.eclipse.swt.widgets.Composite;
49
import org.eclipse.swt.widgets.Composite;
49
import org.eclipse.swt.widgets.Control;
50
import org.eclipse.swt.widgets.Control;
51
import org.eclipse.swt.widgets.Display;
50
import org.eclipse.swt.widgets.Event;
52
import org.eclipse.swt.widgets.Event;
51
import org.eclipse.swt.widgets.Label;
53
import org.eclipse.swt.widgets.Label;
52
import org.eclipse.swt.widgets.List;
54
import org.eclipse.swt.widgets.List;
53
import org.eclipse.ui.IWorkbench;
55
import org.eclipse.ui.IWorkbench;
54
import org.eclipse.ui.IWorkbenchPreferencePage;
56
import org.eclipse.ui.IWorkbenchPreferencePage;
55
import org.eclipse.ui.PlatformUI;
57
import org.eclipse.ui.PlatformUI;
58
import org.eclipse.ui.texteditor.AbstractTextEditor;
56
59
57
/**
60
/**
58
 * The preference page for configurating color and style of syntax.
61
 * The preference page for configurating color and style of syntax.
Lines 66-71 Link Here
66
	private Button _italicFont = null;
69
	private Button _italicFont = null;
67
	private Button _strikethroughFont = null;
70
	private Button _strikethroughFont = null;
68
	private Button _underlineFont = null;
71
	private Button _underlineFont = null;
72
	private Button _systemDefault = null;
69
	private ColorSelector _colorSelector;
73
	private ColorSelector _colorSelector;
70
	private SQLSourceViewer _sourceViewer;
74
	private SQLSourceViewer _sourceViewer;
71
75
Lines 82-95 Link Here
82
	}
86
	}
83
87
84
	private void initialPage() {
88
	private void initialPage() {
85
		_defaultSyntaxItems.put(SQLColorProvider.SQL_COMMENT, new SyntaxItem(false, false, false, false, new RGB(64, 128, 128)));
89
		_defaultSyntaxItems.put(SQLColorProvider.SQL_COMMENT, new SyntaxItem(false, false, false, false, false, new RGB(64, 128, 128)));
86
		_defaultSyntaxItems.put(SQLColorProvider.SQL_MULTILINE_COMMENT, new SyntaxItem(false, false, false, false, new RGB(64, 128, 128)));
90
		_defaultSyntaxItems.put(SQLColorProvider.SQL_MULTILINE_COMMENT, new SyntaxItem(false, false, false, false, false, new RGB(64, 128, 128)));
87
		_defaultSyntaxItems.put(SQLColorProvider.SQL_QUOTED_LITERAL, new SyntaxItem(false, false, false, false, new RGB(0, 0, 255)));
91
		_defaultSyntaxItems.put(SQLColorProvider.SQL_QUOTED_LITERAL, new SyntaxItem(false, false, false, false, false, new RGB(0, 0, 255)));
88
		_defaultSyntaxItems.put(SQLColorProvider.SQL_DELIMITED_IDENTIFIER, new SyntaxItem(false, false, false, false, new RGB(0, 128, 0)));
92
		_defaultSyntaxItems.put(SQLColorProvider.SQL_DELIMITED_IDENTIFIER, new SyntaxItem(false, false, false, false, false, new RGB(0, 128, 0)));
89
		_defaultSyntaxItems.put(SQLColorProvider.SQL_KEYWORD, new SyntaxItem(true, false, false, false, new RGB(127, 0, 85)));
93
		_defaultSyntaxItems.put(SQLColorProvider.SQL_KEYWORD, new SyntaxItem(true, false, false, false, false, new RGB(127, 0, 85)));
90
		_defaultSyntaxItems.put(SQLColorProvider.SQL_TYPE, new SyntaxItem(true, false, false, false, new RGB(64, 0, 200)));
94
		_defaultSyntaxItems.put(SQLColorProvider.SQL_TYPE, new SyntaxItem(true, false, false, false, false, new RGB(64, 0, 200)));
91
		_defaultSyntaxItems.put(SQLColorProvider.SQL_IDENTIFIER, new SyntaxItem(false, false, false, false, new RGB(0, 0, 128)));
95
		_defaultSyntaxItems.put(SQLColorProvider.SQL_IDENTIFIER, new SyntaxItem(false, false, false, false, false, new RGB(0, 0, 128)));
92
		_defaultSyntaxItems.put(SQLColorProvider.SQL_DEFAULT, new SyntaxItem(false, false, false, false, new RGB(0, 0, 0)));
96
		_defaultSyntaxItems.put(SQLColorProvider.SQL_DEFAULT, new SyntaxItem(false, false, false, false, true, getForeGroundColor()));
93
	}
97
	}
94
98
95
	/*
99
	/*
Lines 155-160 Link Here
155
159
156
			public void widgetSelected(SelectionEvent e) {
160
			public void widgetSelected(SelectionEvent e) {
157
				if (_syntaxList.getSelection()[0] != null) {
161
				if (_syntaxList.getSelection()[0] != null) {
162
					if (_syntaxList.getSelection()[0].equals(SQLColorProvider.SQL_DEFAULT)) {
163
						_systemDefault.setVisible(true);
164
					} else {
165
						_systemDefault.setVisible(false);
166
						_systemDefault.setSelection(false);
167
						_colorSelector.setEnabled(true);
168
					}
158
					refreshStyleComposite(((SyntaxItem) _syntaxList.getData(_syntaxList.getSelection()[0])));
169
					refreshStyleComposite(((SyntaxItem) _syntaxList.getData(_syntaxList.getSelection()[0])));
159
				}
170
				}
160
			}
171
			}
Lines 170-176 Link Here
170
		comp.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
181
		comp.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
171
182
172
		Composite compColorControl = new Composite(comp, SWT.NULL);
183
		Composite compColorControl = new Composite(comp, SWT.NULL);
173
		GridLayout colorLayout = new GridLayout(2, false);
184
		GridLayout colorLayout = new GridLayout(3, false);
174
		colorLayout.marginHeight = 0;
185
		colorLayout.marginHeight = 0;
175
		colorLayout.marginWidth = 0;
186
		colorLayout.marginWidth = 0;
176
		compColorControl.setLayout(colorLayout);
187
		compColorControl.setLayout(colorLayout);
Lines 185-190 Link Here
185
			}
196
			}
186
		});
197
		});
187
198
199
		_systemDefault = new Button(compColorControl, SWT.CHECK);
200
		_systemDefault.setText("Default foreground color");
201
		_systemDefault.addSelectionListener(new stylesListener());
202
		_systemDefault.setVisible(false);
203
188
		_boldFont = new Button(comp, SWT.CHECK);
204
		_boldFont = new Button(comp, SWT.CHECK);
189
		_boldFont.setText(PreferenceMessages.SyntaxColoringPage_bold);
205
		_boldFont.setText(PreferenceMessages.SyntaxColoringPage_bold);
190
		_boldFont.addSelectionListener(new stylesListener());
206
		_boldFont.addSelectionListener(new stylesListener());
Lines 226-231 Link Here
226
			extension3.setDocumentPartitioner(SQLPartitionScanner.SQL_PARTITIONING, partitioner);
242
			extension3.setDocumentPartitioner(SQLPartitionScanner.SQL_PARTITIONING, partitioner);
227
		}
243
		}
228
		_sourceViewer.setDocument(document);
244
		_sourceViewer.setDocument(document);
245
		_sourceViewer.getTextWidget().setBackground(new Color(Display.getCurrent(), getBackGroundColor()));
229
	}
246
	}
230
247
231
	/*
248
	/*
Lines 243-249 Link Here
243
260
244
			if (getPreferenceStore().getString(syntaxItemName) == null || getPreferenceStore().getString(syntaxItemName).equals("")) {
261
			if (getPreferenceStore().getString(syntaxItemName) == null || getPreferenceStore().getString(syntaxItemName).equals("")) {
245
				// use default values
262
				// use default values
246
				_syntaxList.setData(syntaxItemName, _defaultSyntaxItems.get(syntaxItemName));
263
				_syntaxList.setData(syntaxItemName, new SyntaxItem(_defaultSyntaxItems.get(syntaxItemName).toString()));
247
			} else {
264
			} else {
248
				// use values saved before
265
				// use values saved before
249
				_syntaxList.setData(syntaxItemName, new SyntaxItem(getPreferenceStore().getString(syntaxItemName)));
266
				_syntaxList.setData(syntaxItemName, new SyntaxItem(getPreferenceStore().getString(syntaxItemName)));
Lines 262-268 Link Here
262
	 */
279
	 */
263
	private void getInitialValue() {
280
	private void getInitialValue() {
264
		if (_syntaxList.getSelection()[0] != null) {
281
		if (_syntaxList.getSelection()[0] != null) {
265
			_syntaxList.setData(_syntaxList.getSelection()[0], _defaultSyntaxItems.get(_syntaxList.getSelection()[0]));
282
			_syntaxList.setData(_syntaxList.getSelection()[0], new SyntaxItem(_defaultSyntaxItems.get(_syntaxList.getSelection()[0]).toString()));
266
			refreshStyleComposite((SyntaxItem) _defaultSyntaxItems.get(_syntaxList.getSelection()[0]));
283
			refreshStyleComposite((SyntaxItem) _defaultSyntaxItems.get(_syntaxList.getSelection()[0]));
267
		}
284
		}
268
	}
285
	}
Lines 323-328 Link Here
323
		_italicFont.setSelection(syntax.isItalic());
340
		_italicFont.setSelection(syntax.isItalic());
324
		_strikethroughFont.setSelection(syntax.isStrikethrough());
341
		_strikethroughFont.setSelection(syntax.isStrikethrough());
325
		_underlineFont.setSelection(syntax.isUnderline());
342
		_underlineFont.setSelection(syntax.isUnderline());
343
		_systemDefault.setSelection(syntax.isSystemDefault());
344
		_systemDefault.notifyListeners(SWT.Selection, new Event());
326
	}
345
	}
327
346
328
	/**
347
	/**
Lines 337-342 Link Here
337
	}
356
	}
338
357
339
	/**
358
	/**
359
	 * Get foreground color
360
	 * @return foreground color
361
	 */
362
	private RGB getForeGroundColor()
363
	{
364
		String rgb[] = new String[]{"0","0","0"};
365
		try {
366
			if (!org.eclipse.ui.internal.editors.text.EditorsPlugin.getDefault().getPreferenceStore().getString(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT).equalsIgnoreCase("true")) {
367
				String foreGroundColor = org.eclipse.ui.internal.editors.text.EditorsPlugin.getDefault().getPreferenceStore().getString(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND);
368
				if (foreGroundColor != null && !foreGroundColor.equals("")) {
369
					rgb = foreGroundColor.split(",");
370
				}
371
			}
372
		} catch (Throwable ex) {
373
			// do nothing, keep using default value
374
		}
375
		return new RGB(Integer.parseInt(rgb[0]),Integer.parseInt(rgb[1]),Integer.parseInt(rgb[2]));
376
	}
377
	
378
	/**
379
	 * Get background color
380
	 * @return background color
381
	 */
382
	private RGB getBackGroundColor()
383
	{
384
		String rgb[] = new String[] { "255", "255", "255" };
385
		try {
386
			if (!org.eclipse.ui.internal.editors.text.EditorsPlugin.getDefault().getPreferenceStore().getString(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT).equalsIgnoreCase("true")) {
387
				String backGroundColor = org.eclipse.ui.internal.editors.text.EditorsPlugin.getDefault().getPreferenceStore().getString(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
388
				if (backGroundColor != null && !backGroundColor.equals("")) {
389
					rgb = backGroundColor.split(",");
390
				}
391
			}
392
		} catch (Throwable ex) {
393
			// do nothing, keep using default value
394
		}
395
		return new RGB(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2]));
396
	}
397
398
	/**
340
	 * Handle selection event of all check boxes
399
	 * Handle selection event of all check boxes
341
	 */
400
	 */
342
	class stylesListener implements SelectionListener {
401
	class stylesListener implements SelectionListener {
Lines 348-353 Link Here
348
			((SyntaxItem) _syntaxList.getData(_syntaxList.getSelection()[0])).setItalicKey(_italicFont.getSelection());
407
			((SyntaxItem) _syntaxList.getData(_syntaxList.getSelection()[0])).setItalicKey(_italicFont.getSelection());
349
			((SyntaxItem) _syntaxList.getData(_syntaxList.getSelection()[0])).setStrikethroughKey(_strikethroughFont.getSelection());
408
			((SyntaxItem) _syntaxList.getData(_syntaxList.getSelection()[0])).setStrikethroughKey(_strikethroughFont.getSelection());
350
			((SyntaxItem) _syntaxList.getData(_syntaxList.getSelection()[0])).setUnderlineKey(_underlineFont.getSelection());
409
			((SyntaxItem) _syntaxList.getData(_syntaxList.getSelection()[0])).setUnderlineKey(_underlineFont.getSelection());
410
			((SyntaxItem) _syntaxList.getData(_syntaxList.getSelection()[0])).setSystemDefault(_systemDefault.getSelection());
411
			if (_systemDefault.isVisible() && _systemDefault.getSelection()) {
412
				((SyntaxItem) _syntaxList.getData(_syntaxList.getSelection()[0])).setColor(((SyntaxItem)_defaultSyntaxItems.get(SQLColorProvider.SQL_DEFAULT)).getColor());
413
			} else {
414
				((SyntaxItem) _syntaxList.getData(_syntaxList.getSelection()[0])).setColor(_colorSelector.getColorValue());
415
			}
416
			_colorSelector.setEnabled(!_systemDefault.getSelection());
351
			updatePreviewer();
417
			updatePreviewer();
352
		}
418
		}
353
	}
419
	}
(-)src/org/eclipse/datatools/sqltools/sqleditor/preferences/SyntaxItem.java (-4 / +15 lines)
Lines 21-32 Link Here
21
 * @author renj
21
 * @author renj
22
 */
22
 */
23
public class SyntaxItem {
23
public class SyntaxItem {
24
	private Pattern pattern = Pattern.compile("(\\d)\\,(\\d)\\,(\\d)\\,(\\d)\\,(\\d{1,3})\\,(\\d{1,3})\\,(\\d{1,3})");
24
	private Pattern pattern = Pattern.compile("(\\d)\\,(\\d)\\,(\\d)\\,(\\d)\\,(\\d)\\,(\\d{1,3})\\,(\\d{1,3})\\,(\\d{1,3})");
25
25
26
	private Boolean _boldKey = Boolean.FALSE;
26
	private Boolean _boldKey = Boolean.FALSE;
27
	private Boolean _italicKey = Boolean.FALSE;
27
	private Boolean _italicKey = Boolean.FALSE;
28
	private Boolean _strikethroughKey = Boolean.FALSE;
28
	private Boolean _strikethroughKey = Boolean.FALSE;
29
	private Boolean _underlineKey = Boolean.FALSE;
29
	private Boolean _underlineKey = Boolean.FALSE;
30
	private Boolean _systemDefault = Boolean.FALSE;
30
	private RGB _color = new RGB(0, 0, 0);
31
	private RGB _color = new RGB(0, 0, 0);
31
32
32
	public SyntaxItem(String preferenceCodes) {
33
	public SyntaxItem(String preferenceCodes) {
Lines 37-52 Link Here
37
				_italicKey = Boolean.valueOf(m.group(2).equals("1") ? true : false);
38
				_italicKey = Boolean.valueOf(m.group(2).equals("1") ? true : false);
38
				_strikethroughKey = Boolean.valueOf(m.group(3).equals("1") ? true : false);
39
				_strikethroughKey = Boolean.valueOf(m.group(3).equals("1") ? true : false);
39
				_underlineKey = Boolean.valueOf(m.group(4).equals("1") ? true : false);
40
				_underlineKey = Boolean.valueOf(m.group(4).equals("1") ? true : false);
40
				_color = new RGB(Integer.parseInt(m.group(5)), Integer.parseInt(m.group(6)), Integer.parseInt(m.group(7)));
41
				_systemDefault = Boolean.valueOf(m.group(5).equals("1") ? true : false);
42
				_color = new RGB(Integer.parseInt(m.group(6)), Integer.parseInt(m.group(7)), Integer.parseInt(m.group(8)));
41
			}
43
			}
42
		}
44
		}
43
	}
45
	}
44
46
45
	public SyntaxItem(boolean bk, boolean ik, boolean sk, boolean uk, RGB rgb) {
47
	public SyntaxItem(boolean bk, boolean ik, boolean sk, boolean uk, boolean sys, RGB rgb) {
46
		_boldKey = Boolean.valueOf(bk);
48
		_boldKey = Boolean.valueOf(bk);
47
		_italicKey = Boolean.valueOf(ik);
49
		_italicKey = Boolean.valueOf(ik);
48
		_strikethroughKey = Boolean.valueOf(sk);
50
		_strikethroughKey = Boolean.valueOf(sk);
49
		_underlineKey = Boolean.valueOf(uk);
51
		_underlineKey = Boolean.valueOf(uk);
52
		_systemDefault = Boolean.valueOf(sys);
50
		_color = rgb;
53
		_color = rgb;
51
	}
54
	}
52
55
Lines 66-71 Link Here
66
		_underlineKey = Boolean.valueOf(uk);
69
		_underlineKey = Boolean.valueOf(uk);
67
	}
70
	}
68
71
72
	public void setSystemDefault(boolean sys) {
73
		_systemDefault = Boolean.valueOf(sys);
74
	}
75
69
	public void setColor(RGB rgb) {
76
	public void setColor(RGB rgb) {
70
		_color = rgb;
77
		_color = rgb;
71
	}
78
	}
Lines 86-98 Link Here
86
		return _underlineKey.booleanValue();
93
		return _underlineKey.booleanValue();
87
	}
94
	}
88
95
96
	public boolean isSystemDefault() {
97
		return _systemDefault.booleanValue();
98
	}
99
89
	public RGB getColor() {
100
	public RGB getColor() {
90
		return _color;
101
		return _color;
91
	}
102
	}
92
103
93
	public String toString() {
104
	public String toString() {
94
		String preferenceCodes = (_boldKey.booleanValue() ? "1" : "0") + "," + (_italicKey.booleanValue() ? "1" : "0") + "," + (_strikethroughKey.booleanValue() ? "1" : "0") + ","
105
		String preferenceCodes = (_boldKey.booleanValue() ? "1" : "0") + "," + (_italicKey.booleanValue() ? "1" : "0") + "," + (_strikethroughKey.booleanValue() ? "1" : "0") + ","
95
				+ (_underlineKey.booleanValue() ? "1" : "0") + "," + _color.red + "," + _color.green + "," + _color.blue;
106
				+ (_underlineKey.booleanValue() ? "1" : "0") + "," + (_systemDefault.booleanValue() ? "1" : "0") + "," + _color.red + "," + _color.green + "," + _color.blue;
96
		return preferenceCodes;
107
		return preferenceCodes;
97
	}
108
	}
98
}
109
}

Return to bug 219312