1 11 package org.eclipse.ant.internal.ui.preferences; 12 13 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 import java.util.List ; 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 35 public class AntPropertiesPage implements IAntBlockContainer { 36 37 private AntPropertiesBlock antPropertiesBlock= new AntPropertiesBlock(this); 38 private AntRuntimePreferencePage preferencePage; 39 40 43 public AntPropertiesPage(AntRuntimePreferencePage preferencePage) { 44 this.preferencePage= preferencePage; 45 } 46 47 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 79 protected void initialize() { 80 List 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 defaultProperties= AntCorePlugin.getPlugin().getPreferences().getDefaultProperties(); 89 antPropertiesBlock.setPropertiesInput((Property[]) defaultProperties.toArray(new Property[defaultProperties.size()])); 90 antPropertiesBlock.setPropertyFilesInput(new String [0]); 91 antPropertiesBlock.update(); 92 } 93 94 99 protected String [] getPropertyFiles() { 100 Object [] elements = antPropertiesBlock.getPropertyFiles(); 101 String [] files= new String [elements.length]; 102 for (int i = 0; i < elements.length; i++) { 103 files[i] = (String )elements[i]; 104 } 105 return files; 106 } 107 108 111 public void setMessage(String message) { 112 preferencePage.setMessage(message); 113 } 114 115 118 public void setErrorMessage(String message) { 119 preferencePage.setErrorMessage(message); 120 } 121 122 125 public Button createPushButton(Composite parent, String 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 136 public void update() { 137 } 138 139 protected List getProperties() { 140 Object [] allProperties= antPropertiesBlock.getProperties(); 141 List properties= new ArrayList (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 |