|
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(PreferenceMessages.SyntaxColoringPage_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 |
} |