KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > preferences > AntRuntimePreferencePage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.ant.internal.ui.preferences;
12
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Arrays JavaDoc;
16 import java.util.List JavaDoc;
17 import org.eclipse.ant.core.AntCorePlugin;
18 import org.eclipse.ant.core.AntCorePreferences;
19 import org.eclipse.ant.core.Property;
20 import org.eclipse.ant.core.Task;
21 import org.eclipse.ant.core.Type;
22 import org.eclipse.ant.internal.ui.AntUIPlugin;
23 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
24 import org.eclipse.jface.preference.PreferencePage;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.widgets.Button;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Control;
30 import org.eclipse.swt.widgets.TabFolder;
31 import org.eclipse.ui.IWorkbench;
32 import org.eclipse.ui.IWorkbenchPreferencePage;
33 import org.eclipse.ui.PlatformUI;
34
35 /**
36  * Ant preference page to set the classpath, tasks, types and properties.
37  */

38 public class AntRuntimePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
39     
40     private AntClasspathPage classpathPage;
41     private AntTasksPage tasksPage;
42     private AntTypesPage typesPage;
43     private AntPropertiesPage propertiesPage;
44     
45     /**
46      * Creates the preference page
47      */

48     public AntRuntimePreferencePage() {
49         setDescription(AntPreferencesMessages.AntPreferencePage_description);
50         setPreferenceStore(AntUIPlugin.getDefault().getPreferenceStore());
51     }
52     
53     /* (non-Javadoc)
54      * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
55      */

56     public void init(IWorkbench workbench) {
57     }
58     
59     /* (non-Javadoc)
60      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
61      */

62     protected Control createContents(Composite parent) {
63         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IAntUIHelpContextIds.ANT_RUNTIME_PREFERENCE_PAGE);
64         initializeDialogUnits(parent);
65
66         TabFolder folder = new TabFolder(parent, SWT.NONE);
67         folder.setLayout(new TabFolderLayout());
68         folder.setLayoutData(new GridData(GridData.FILL_BOTH));
69         folder.setFont(parent.getFont());
70
71         classpathPage = new AntClasspathPage(this);
72         classpathPage.createTabItem(folder);
73         
74         tasksPage = new AntTasksPage(this);
75         tasksPage.createTabItem(folder);
76         
77         typesPage = new AntTypesPage(this);
78         typesPage.createTabItem(folder);
79
80         propertiesPage= new AntPropertiesPage(this);
81         propertiesPage.createTabItem(folder);
82         
83         tasksPage.initialize();
84         typesPage.initialize();
85         classpathPage.initialize();
86         propertiesPage.initialize();
87
88         return folder;
89     }
90     
91     /* (non-Javadoc)
92      * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
93      */

94     protected void performDefaults() {
95         super.performDefaults();
96         
97         AntCorePreferences prefs = AntCorePlugin.getPlugin().getPreferences();
98         tasksPage.setInput(prefs.getDefaultTasks());
99         typesPage.setInput(prefs.getDefaultTypes());
100         classpathPage.performDefaults();
101         propertiesPage.performDefaults();
102     }
103     
104     /* (non-Javadoc)
105      * @see org.eclipse.jface.preference.IPreferencePage#performOk()
106      */

107     public boolean performOk() {
108         AntCorePreferences prefs = AntCorePlugin.getPlugin().getPreferences();
109         
110         prefs.setAntHomeClasspathEntries(classpathPage.getAntHomeEntries());
111         
112         
113         prefs.setAdditionalClasspathEntries(classpathPage.getAdditionalEntries());
114         
115         String JavaDoc antHome= classpathPage.getAntHome();
116         prefs.setAntHome(antHome);
117         
118         List JavaDoc contents = tasksPage.getContents(false);
119         if (contents != null) {
120             Task[] tasks = (Task[]) contents.toArray(new Task[contents.size()]);
121             prefs.setCustomTasks(tasks);
122         }
123         
124         contents = typesPage.getContents(false);
125         if (contents != null) {
126             Type[] types = (Type[]) contents.toArray(new Type[contents.size()]);
127             prefs.setCustomTypes(types);
128         }
129         
130         contents = propertiesPage.getProperties();
131         if (contents != null) {
132             Property[] properties = (Property[]) contents.toArray(new Property[contents.size()]);
133             prefs.setCustomProperties(properties);
134         }
135         
136         String JavaDoc[] files = propertiesPage.getPropertyFiles();
137         prefs.setCustomPropertyFiles(files);
138         
139         prefs.updatePluginPreferences();
140     
141         return super.performOk();
142     }
143     
144     /* (non-Javadoc)
145      * @see org.eclipse.jface.dialogs.DialogPage#setButtonLayoutData(org.eclipse.swt.widgets.Button)
146      */

147     protected GridData setButtonLayoutData(Button button) {
148         return super.setButtonLayoutData(button);
149     }
150     
151     protected List JavaDoc getLibraryEntries() {
152         List JavaDoc urls= new ArrayList JavaDoc();
153         urls.addAll(Arrays.asList(classpathPage.getAntHomeEntries()));
154         urls.addAll(Arrays.asList(classpathPage.getAdditionalEntries()));
155         urls.addAll(Arrays.asList(classpathPage.getContributedEntries()));
156         return urls;
157     }
158 }
159
Popular Tags