~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/formatter/ControlStatementsTabPage.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2000, 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.cdt.internal.ui.preferences.formatter;
 
12
 
 
13
import java.util.Map;
 
14
import java.util.Observable;
 
15
import java.util.Observer;
 
16
 
 
17
import org.eclipse.swt.SWT;
 
18
import org.eclipse.swt.layout.GridData;
 
19
import org.eclipse.swt.widgets.Composite;
 
20
import org.eclipse.swt.widgets.Group;
 
21
import org.eclipse.swt.widgets.Label;
 
22
 
 
23
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
 
24
 
 
25
public class ControlStatementsTabPage extends FormatterTabPage {
 
26
        
 
27
        private final String PREVIEW=
 
28
        createPreviewHeader(FormatterMessages.ControlStatementsTabPage_preview_header) + 
 
29
        "class Example {" +     //$NON-NLS-1$   
 
30
        "  void bar() {" +      //$NON-NLS-1$
 
31
        "    do {} while (true);" +     //$NON-NLS-1$
 
32
        "    try {} catch (...) { }" +  //$NON-NLS-1$
 
33
        "  }" + //$NON-NLS-1$
 
34
        "  void foo2() {" +     //$NON-NLS-1$
 
35
        "    if (true) { " + //$NON-NLS-1$
 
36
        "      return;" + //$NON-NLS-1$
 
37
        "    }" + //$NON-NLS-1$
 
38
        "    if (true) {" + //$NON-NLS-1$
 
39
        "      return;" + //$NON-NLS-1$
 
40
        "    } else if (false) {" +     //$NON-NLS-1$
 
41
        "      return; " + //$NON-NLS-1$
 
42
        "    } else {" + //$NON-NLS-1$
 
43
        "      return;" + //$NON-NLS-1$
 
44
        "    }" + //$NON-NLS-1$
 
45
        "  }" + //$NON-NLS-1$
 
46
        "  void foo(int state) {" + //$NON-NLS-1$
 
47
        "    if (true) return;" + //$NON-NLS-1$
 
48
        "    if (true) " + //$NON-NLS-1$
 
49
        "      return;" + //$NON-NLS-1$
 
50
        "    else if (false)" + //$NON-NLS-1$
 
51
        "      return;" + //$NON-NLS-1$
 
52
        "    else return;" + //$NON-NLS-1$
 
53
        "  }" + //$NON-NLS-1$
 
54
        "};"; //$NON-NLS-1$
 
55
        
 
56
        
 
57
        private TranslationUnitPreview fPreview;
 
58
        
 
59
        protected CheckboxPreference fThenStatementPref, fSimpleIfPref;
 
60
 
 
61
        
 
62
        public ControlStatementsTabPage(ModifyDialog modifyDialog, Map<String, String> workingValues) {
 
63
                super(modifyDialog, workingValues);
 
64
        }
 
65
 
 
66
        @Override
 
67
        protected void doCreatePreferences(Composite composite, int numColumns) {
 
68
                
 
69
                final Group generalGroup= createGroup(numColumns, composite, FormatterMessages.ControlStatementsTabPage_general_group_title); 
 
70
                createOption(generalGroup, numColumns, FormatterMessages.ControlStatementsTabPage_general_group_insert_new_line_before_else_statements, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_ELSE_IN_IF_STATEMENT, DO_NOT_INSERT_INSERT); 
 
71
                createOption(generalGroup, numColumns, FormatterMessages.ControlStatementsTabPage_general_group_insert_new_line_before_catch_statements, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CATCH_IN_TRY_STATEMENT, DO_NOT_INSERT_INSERT); 
 
72
                createOption(generalGroup, numColumns, FormatterMessages.ControlStatementsTabPage_general_group_insert_new_line_before_while_in_do_statements, DefaultCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_WHILE_IN_DO_STATEMENT, DO_NOT_INSERT_INSERT); 
 
73
                                
 
74
                final Group ifElseGroup= createGroup(numColumns, composite, FormatterMessages.ControlStatementsTabPage_if_else_group_title); 
 
75
                fThenStatementPref= createOption(ifElseGroup, numColumns, FormatterMessages.ControlStatementsTabPage_if_else_group_keep_then_on_same_line, DefaultCodeFormatterConstants.FORMATTER_KEEP_THEN_STATEMENT_ON_SAME_LINE, FALSE_TRUE); 
 
76
                
 
77
                Label l= new Label(ifElseGroup, SWT.NONE);
 
78
                GridData gd= new GridData();
 
79
                gd.widthHint= fPixelConverter.convertWidthInCharsToPixels(4);
 
80
                l.setLayoutData(gd);
 
81
                
 
82
                fSimpleIfPref= createOption(ifElseGroup, numColumns - 1, FormatterMessages.ControlStatementsTabPage_if_else_group_keep_simple_if_on_one_line, DefaultCodeFormatterConstants.FORMATTER_KEEP_SIMPLE_IF_ON_ONE_LINE, FALSE_TRUE); 
 
83
                
 
84
                fThenStatementPref.addObserver( new Observer() {
 
85
                        public void update(Observable o, Object arg) {
 
86
                                fSimpleIfPref.setEnabled(!fThenStatementPref.getChecked());
 
87
                        }
 
88
                        
 
89
                });
 
90
                
 
91
                fSimpleIfPref.setEnabled(!fThenStatementPref.getChecked());
 
92
                
 
93
                createOption(ifElseGroup, numColumns, FormatterMessages.ControlStatementsTabPage_if_else_group_keep_else_on_same_line, DefaultCodeFormatterConstants.FORMATTER_KEEP_ELSE_STATEMENT_ON_SAME_LINE, FALSE_TRUE); 
 
94
                createCheckboxPref(ifElseGroup, numColumns, FormatterMessages.ControlStatementsTabPage_if_else_group_keep_else_if_on_one_line, DefaultCodeFormatterConstants.FORMATTER_COMPACT_ELSE_IF, FALSE_TRUE); 
 
95
//              createCheckboxPref(ifElseGroup, numColumns, FormatterMessages.ControlStatementsTabPage_if_else_group_keep_guardian_clause_on_one_line, DefaultCodeFormatterConstants.FORMATTER_KEEP_GUARDIAN_CLAUSE_ON_ONE_LINE, FALSE_TRUE); 
 
96
        }
 
97
        
 
98
        @Override
 
99
        protected void initializePage() {
 
100
            fPreview.setPreviewText(PREVIEW);
 
101
        }
 
102
 
 
103
    /*
 
104
     * @see org.eclipse.cdt.internal.ui.preferences.formatter.ModifyDialogTabPage#doCreateCPreview(org.eclipse.swt.widgets.Composite)
 
105
     */
 
106
    @Override
 
107
        protected CPreview doCreateCPreview(Composite parent) {
 
108
        fPreview= new TranslationUnitPreview(fWorkingValues, parent);
 
109
        return fPreview;
 
110
    }
 
111
 
 
112
    /*
 
113
     * @see org.eclipse.cdt.internal.ui.preferences.formatter.ModifyDialogTabPage#doUpdatePreview()
 
114
     */
 
115
    @Override
 
116
        protected void doUpdatePreview() {
 
117
        super.doUpdatePreview();
 
118
        fPreview.update();
 
119
    }
 
120
 
 
121
    private CheckboxPreference createOption(Composite composite, int span, String name, String key, String [] values) {
 
122
                return createCheckboxPref(composite, span, name, key, values);
 
123
        }
 
124
}