]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/preferences/formatter/FormatterTabPage.java
274fb8e675c2e9a0ee3a8e191d32a283824b507c
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / preferences / formatter / FormatterTabPage.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.preferences.formatter;
12
13 import java.util.Map;
14
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;
21
22 import org.eclipse.jface.dialogs.IDialogSettings;
23
24 import org.eclipse.jdt.core.JavaCore;
25 import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
26
27 import org.eclipse.jdt.ui.JavaUI;
28
29 import org.eclipse.jdt.internal.ui.JavaPlugin;
30
31
32 public abstract class FormatterTabPage extends ModifyDialogTabPage {
33
34         private final static String SHOW_INVISIBLE_PREFERENCE_KEY= JavaUI.ID_PLUGIN + ".formatter_page.show_invisible_characters"; //$NON-NLS-1$
35
36         /**
37          * Constant array for boolean false/true selection.
38          */
39         protected static String[] FALSE_TRUE= { DefaultCodeFormatterConstants.FALSE, DefaultCodeFormatterConstants.TRUE };
40
41         /**
42          * Constant array for boolean true/false selection.
43          * 
44          * @since 3.5
45          */
46         protected static String[] TRUE_FALSE= { DefaultCodeFormatterConstants.TRUE, DefaultCodeFormatterConstants.FALSE };
47
48         /**
49          * Constant array for insert / not_insert.
50          */
51         protected static String[] DO_NOT_INSERT_INSERT= { JavaCore.DO_NOT_INSERT, JavaCore.INSERT };
52
53         JavaPreview fPreview;
54         private final IDialogSettings fDialogSettings;
55         Button fShowInvisibleButton;
56
57         public FormatterTabPage(IModifyDialogTabPage.IModificationListener modifyListener, Map<String, String> workingValues) {
58                 super(modifyListener, workingValues);
59
60                 fDialogSettings= JavaPlugin.getDefault().getDialogSettings();
61         }
62
63         @Override
64         protected Composite doCreatePreviewPane(Composite composite, int numColumns) {
65
66                 createLabel(numColumns - 1, composite, FormatterMessages.ModifyDialogTabPage_preview_label_text);
67
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() {
72                         @Override
73                         public void widgetSelected(SelectionEvent e) {
74                                 fPreview.showInvisibleCharacters(fShowInvisibleButton.getSelection());
75                                 fDialogSettings.put(SHOW_INVISIBLE_PREFERENCE_KEY, fShowInvisibleButton.getSelection());
76                                 doUpdatePreview();
77                         }
78                 });
79                 fShowInvisibleButton.setSelection(isShowInvisible());
80
81                 fPreview= doCreateJavaPreview(composite);
82                 fPreview.generated_2189189448780544534(this);
83
84                 final GridData gd= createGridData(numColumns, GridData.FILL_BOTH, 0);
85                 gd.widthHint= 0;
86                 gd.heightHint=0;
87                 fPreview.getControl().setLayoutData(gd);
88
89                 return composite;
90         }
91
92         private boolean isShowInvisible() {
93                 return fDialogSettings.getBoolean(SHOW_INVISIBLE_PREFERENCE_KEY);
94         }
95
96         @Override
97         protected void doUpdatePreview() {
98                 boolean showInvisible= isShowInvisible();
99                 fPreview.showInvisibleCharacters(showInvisible);
100                 fShowInvisibleButton.setSelection(showInvisible);
101         }
102
103 }