KickJava   Java API By Example, From Geeks To Geeks.

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


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.Property;
19 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.graphics.Font;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.layout.GridLayout;
24 import org.eclipse.swt.widgets.Button;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.TabFolder;
27 import org.eclipse.swt.widgets.TabItem;
28 import org.eclipse.ui.PlatformUI;
29
30 /**
31  * Preference page for setting global Ant user properties.
32  * All properties specified here will be set as user properties on the
33  * project for any Ant build
34  */

35 public class AntPropertiesPage implements IAntBlockContainer {
36     
37     private AntPropertiesBlock antPropertiesBlock= new AntPropertiesBlock(this);
38     private AntRuntimePreferencePage preferencePage;
39     
40     /**
41      * Creates an instance.
42      */

43     public AntPropertiesPage(AntRuntimePreferencePage preferencePage) {
44         this.preferencePage= preferencePage;
45     }
46     
47     /**
48      * Creates the tab item that contains this sub-page.
49      */

50     protected TabItem createTabItem(TabFolder folder) {
51         TabItem item = new TabItem(folder, SWT.NONE);
52         item.setText(AntPreferencesMessages.AntPropertiesPage_title);
53         item.setImage(AntObjectLabelProvider.getPropertyImage());
54         item.setData(this);
55         item.setControl(createContents(folder));
56         return item;
57     }
58     
59     protected Composite createContents(Composite parent) {
60         Font font = parent.getFont();
61         
62         Composite top = new Composite(parent, SWT.NONE);
63         top.setFont(font);
64         PlatformUI.getWorkbench().getHelpSystem().setHelp(top, IAntUIHelpContextIds.ANT_PROPERTIES_PAGE);
65         GridLayout layout = new GridLayout();
66         layout.numColumns= 2;
67         top.setLayout(layout);
68         GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
69         top.setLayoutData(gridData);
70                 
71         antPropertiesBlock.createControl(top, AntPreferencesMessages.AntPropertiesPage__Global_properties__1, AntPreferencesMessages.AntPropertiesPage_Glo_bal_property_files__2);
72         
73         return top;
74     }
75     
76     /**
77      * Sets the contents of the tables on this page.
78      */

79     protected void initialize() {
80         List JavaDoc allProperties= AntCorePlugin.getPlugin().getPreferences().getDefaultProperties();
81         allProperties.addAll(Arrays.asList(AntCorePlugin.getPlugin().getPreferences().getCustomProperties()));
82         antPropertiesBlock.setPropertiesInput((Property[]) allProperties.toArray(new Property[allProperties.size()]));
83         antPropertiesBlock.setPropertyFilesInput(AntCorePlugin.getPlugin().getPreferences().getCustomPropertyFiles(false));
84         antPropertiesBlock.update();
85     }
86     
87     protected void performDefaults() {
88         List JavaDoc defaultProperties= AntCorePlugin.getPlugin().getPreferences().getDefaultProperties();
89         antPropertiesBlock.setPropertiesInput((Property[]) defaultProperties.toArray(new Property[defaultProperties.size()]));
90         antPropertiesBlock.setPropertyFilesInput(new String JavaDoc[0]);
91         antPropertiesBlock.update();
92     }
93     
94     /**
95      * Returns the specified property files
96      *
97      * @return String[]
98      */

99     protected String JavaDoc[] getPropertyFiles() {
100         Object JavaDoc[] elements = antPropertiesBlock.getPropertyFiles();
101         String JavaDoc[] files= new String JavaDoc[elements.length];
102         for (int i = 0; i < elements.length; i++) {
103             files[i] = (String JavaDoc)elements[i];
104         }
105         return files;
106     }
107     
108     /* (non-Javadoc)
109      * @see org.eclipse.ant.internal.ui.preferences.IAntBlockContainer#setMessage(java.lang.String)
110      */

111     public void setMessage(String JavaDoc message) {
112         preferencePage.setMessage(message);
113     }
114
115     /* (non-Javadoc)
116      * @see org.eclipse.ant.internal.ui.preferences.IAntBlockContainer#setErrorMessage(java.lang.String)
117      */

118     public void setErrorMessage(String JavaDoc message) {
119         preferencePage.setErrorMessage(message);
120     }
121
122     /* (non-Javadoc)
123      * @see org.eclipse.ant.internal.ui.preferences.IAntBlockContainer#createPushButton(org.eclipse.swt.widgets.Composite, java.lang.String)
124      */

125     public Button createPushButton(Composite parent, String JavaDoc buttonText) {
126         Button button = new Button(parent, SWT.PUSH);
127         button.setFont(parent.getFont());
128         button.setText(buttonText);
129         preferencePage.setButtonLayoutData(button);
130         return button;
131     }
132
133     /* (non-Javadoc)
134      * @see org.eclipse.ant.internal.ui.preferences.IAntBlockContainer#update()
135      */

136     public void update() {
137     }
138     
139     protected List JavaDoc getProperties() {
140         Object JavaDoc[] allProperties= antPropertiesBlock.getProperties();
141         List JavaDoc properties= new ArrayList JavaDoc(allProperties.length);
142         for (int i = 0; i < allProperties.length; i++) {
143             Property property = (Property)allProperties[i];
144             if (!property.isDefault()) {
145                 properties.add(property);
146             }
147         }
148         return properties;
149     }
150 }
151
Popular Tags