1 /*******************************************************************************
2 * Copyright (c) 2005, 2011 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.preferences.formatter;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.events.SelectionAdapter;
17 import org.eclipse.swt.events.SelectionEvent;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.widgets.Button;
20 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.jface.dialogs.IDialogSettings;
24 import org.eclipse.jdt.core.JavaCore;
25 import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
27 import org.eclipse.jdt.ui.JavaUI;
29 import org.eclipse.jdt.internal.ui.JavaPlugin;
32 public abstract class FormatterTabPage extends ModifyDialogTabPage {
34 private final static String SHOW_INVISIBLE_PREFERENCE_KEY= JavaUI.ID_PLUGIN + ".formatter_page.show_invisible_characters"; //$NON-NLS-1$
37 * Constant array for boolean false/true selection.
39 protected static String[] FALSE_TRUE= { DefaultCodeFormatterConstants.FALSE, DefaultCodeFormatterConstants.TRUE };
42 * Constant array for boolean true/false selection.
46 protected static String[] TRUE_FALSE= { DefaultCodeFormatterConstants.TRUE, DefaultCodeFormatterConstants.FALSE };
49 * Constant array for insert / not_insert.
51 protected static String[] DO_NOT_INSERT_INSERT= { JavaCore.DO_NOT_INSERT, JavaCore.INSERT };
54 private final IDialogSettings fDialogSettings;
55 Button fShowInvisibleButton;
57 public FormatterTabPage(IModifyDialogTabPage.IModificationListener modifyListener, Map<String, String> workingValues) {
58 super(modifyListener, workingValues);
60 fDialogSettings= JavaPlugin.getDefault().getDialogSettings();
64 protected Composite doCreatePreviewPane(Composite composite, int numColumns) {
66 createLabel(numColumns - 1, composite, FormatterMessages.ModifyDialogTabPage_preview_label_text);
68 fShowInvisibleButton= new Button(composite, SWT.CHECK);
69 fShowInvisibleButton.setText(FormatterMessages.FormatterTabPage_ShowInvisibleCharacters_label);
70 fShowInvisibleButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, false));
71 fShowInvisibleButton.addSelectionListener(new SelectionAdapter() {
73 public void widgetSelected(SelectionEvent e) {
74 fPreview.showInvisibleCharacters(fShowInvisibleButton.getSelection());
75 fDialogSettings.put(SHOW_INVISIBLE_PREFERENCE_KEY, fShowInvisibleButton.getSelection());
79 fShowInvisibleButton.setSelection(isShowInvisible());
81 fPreview= doCreateJavaPreview(composite);
82 fPreview.generated_2189189448780544534(this);
84 final GridData gd= createGridData(numColumns, GridData.FILL_BOTH, 0);
87 fPreview.getControl().setLayoutData(gd);
92 private boolean isShowInvisible() {
93 return fDialogSettings.getBoolean(SHOW_INVISIBLE_PREFERENCE_KEY);
97 protected void doUpdatePreview() {
98 boolean showInvisible= isShowInvisible();
99 fPreview.showInvisibleCharacters(showInvisible);
100 fShowInvisibleButton.setSelection(showInvisible);