upload tizen1.0 source
[sdk/ide/product.git] / org.eclipse.cdt.ui / src / org / eclipse / cdt / internal / ui / preferences / GlobalBuildLogPreferencePage.java
1 /*******************************************************************************
2  * Copyright (c) 2010 Broadcom 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  * Alex Collins (Broadcom Corp.) - Initial implementation
10  *******************************************************************************/
11 package org.eclipse.cdt.internal.ui.preferences;
12
13 import org.eclipse.core.runtime.IPath;
14 import org.eclipse.core.runtime.Path;
15 import org.eclipse.jface.preference.BooleanFieldEditor;
16 import org.eclipse.jface.preference.FieldEditorPreferencePage;
17 import org.eclipse.jface.preference.IPreferenceStore;
18 import org.eclipse.jface.preference.StringButtonFieldEditor;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.FileDialog;
22 import org.eclipse.ui.IWorkbench;
23 import org.eclipse.ui.IWorkbenchPreferencePage;
24
25 import org.eclipse.cdt.internal.ui.buildconsole.BuildConsoleManager;
26 import org.eclipse.cdt.internal.ui.buildconsole.GlobalBuildConsoleManager;
27
28 /**
29  * Preference page for build logging options, such as whether the
30  * global build console should be logged and, if so, where.
31  */
32 public class GlobalBuildLogPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
33         public GlobalBuildLogPreferencePage() {
34                 super(GRID);
35                 setPreferenceStore(GlobalBuildConsoleManager.getBuildLogPreferenceStore());
36         }
37
38         /**
39          * A file path field with choose button that does not require the chosen file to exist.
40          */
41         static private class FilePathEditor extends StringButtonFieldEditor {
42                 public FilePathEditor(String name, String label, Composite parent) {
43                         super(name, label, parent);
44                 }
45
46                 @Override
47                 protected String changePressed() {
48                         FileDialog dialog = new FileDialog(getShell(), SWT.NONE);
49                         dialog.setText(getLabelText());
50                         String fileName = super.oldValue;
51                         IPath logFolder = new Path(fileName).removeLastSegments(1);
52                         dialog.setFilterPath(logFolder.toOSString());
53                         return dialog.open();
54                 }
55         }
56
57         @Override
58         protected void createFieldEditors() {
59                 Composite parent = getFieldEditorParent();
60                 BooleanFieldEditor keepLog = new BooleanFieldEditor(BuildConsoleManager.KEY_KEEP_LOG,
61                                 PreferencesMessages.GlobalBuildLogPreferencePage_EnableLogging, parent);
62                 addField(keepLog);
63                 FilePathEditor logLocation = new FilePathEditor(BuildConsoleManager.KEY_LOG_LOCATION,
64                                 PreferencesMessages.GlobalBuildLogPreferencePage_LogLocation, parent);
65                 addField(logLocation);
66         }
67
68         public void init(IWorkbench workbench) {
69                 initDefaults(GlobalBuildConsoleManager.getBuildLogPreferenceStore());
70         }
71
72         public static void initDefaults(IPreferenceStore prefs) {
73                 prefs.setDefault(BuildConsoleManager.KEY_KEEP_LOG, BuildConsoleManager.CONSOLE_KEEP_LOG_DEFAULT);
74                 prefs.setDefault(BuildConsoleManager.KEY_LOG_LOCATION,
75                                 GlobalBuildConsoleManager.getDefaultConsoleLogLocation());
76         }
77 }