1 11 package org.eclipse.update.internal.ui.properties; 12 13 import org.eclipse.core.runtime.*; 14 import org.eclipse.jface.dialogs.Dialog; 15 import org.eclipse.jface.resource.ImageDescriptor; 16 import org.eclipse.swt.*; 17 import org.eclipse.swt.layout.*; 18 import org.eclipse.swt.widgets.*; 19 import org.eclipse.ui.*; 20 import org.eclipse.ui.dialogs.*; 21 import org.eclipse.update.core.*; 22 import org.eclipse.update.core.model.*; 23 import org.eclipse.update.internal.ui.model.*; 24 import org.eclipse.update.internal.ui.UpdateUI; 25 import org.eclipse.update.internal.ui.UpdateUIImages; 26 import org.eclipse.update.internal.ui.UpdateUIMessages; 27 28 public class FeatureGeneralPropertyPage 29 extends PropertyPage 30 implements IWorkbenchPropertyPage { 31 32 public FeatureGeneralPropertyPage() { 33 noDefaultAndApplyButton(); 34 } 35 36 protected Control createContents(Composite parent) { 37 try { 38 IFeatureAdapter adapter = (IFeatureAdapter) getElement(); 39 IFeature feature = adapter.getFeature(null); 40 41 Composite composite = new Composite(parent, SWT.NONE); 42 GridLayout layout = new GridLayout(); 43 layout.marginWidth = 0; 44 layout.marginHeight = 0; 45 layout.verticalSpacing = 15; 46 composite.setLayout(layout); 47 48 addGeneralSection(feature, composite); 49 addSupportedPlatformsSection(feature, composite); 50 addDescription(feature, composite); 51 52 Dialog.applyDialogFont(parent); 53 54 return composite; 55 56 } catch (CoreException e) { 57 } 58 59 return null; 60 } 61 62 private void addGeneralSection(IFeature feature, Composite parent) { 63 Composite composite = new Composite(parent, SWT.NONE); 64 GridLayout layout = new GridLayout(); 65 layout.numColumns = 2; 66 layout.marginWidth = 0; 67 layout.marginHeight = 0; 68 composite.setLayout(layout); 69 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 70 Composite fieldComposite = new Composite(composite, SWT.NONE); 71 layout = new GridLayout(); 72 layout.numColumns = 2; 73 fieldComposite.setLayout(layout); 74 75 Label imageLabel = new Label(composite, SWT.RIGHT); 76 imageLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 77 if (feature.getImage()!=null) { 78 ImageDescriptor desc = ImageDescriptor.createFromURL(feature.getImage()); 79 imageLabel.setImage(UpdateUI.getDefault().getLabelProvider().get(desc)); 80 } 81 else { 82 imageLabel.setImage(UpdateUI.getDefault().getLabelProvider().get(UpdateUIImages.DESC_PROVIDER)); 83 } 84 addField(fieldComposite, UpdateUIMessages.FeatureGeneralPropertyPage_name, feature.getLabel()); 85 86 addField( 87 fieldComposite, 88 UpdateUIMessages.FeatureGeneralPropertyPage_id, 89 feature.getVersionedIdentifier().getIdentifier()); 90 addField( 91 fieldComposite, 92 UpdateUIMessages.FeatureGeneralPropertyPage_version, 93 feature.getVersionedIdentifier().getVersion().toString()); 94 addField(fieldComposite, UpdateUIMessages.FeatureGeneralPropertyPage_provider, feature.getProvider()); 95 long size = feature.getInstallSize(); 96 if (size != ContentEntryModel.UNKNOWN_SIZE) { 97 addField(fieldComposite, UpdateUIMessages.FeatureGeneralPropertyPage_size, new Long (size).toString() + " " + UpdateUIMessages.FeatureGeneralPropertyPage_Kilobytes); } 99 } 100 101 private void addSupportedPlatformsSection(IFeature feature, Composite parent) { 102 Group group = new Group(parent, SWT.NONE); 103 group.setText(UpdateUIMessages.FeatureGeneralPropertyPage_platforms); 104 105 GridLayout layout = new GridLayout(); 106 layout.numColumns = 2; 107 layout.makeColumnsEqualWidth = true; 108 group.setLayout(layout); 109 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 110 111 Label label = new Label(group, SWT.NONE); 112 label.setText(UpdateUIMessages.FeatureGeneralPropertyPage_os + extractValue(feature.getOS())); 113 114 label = new Label(group, SWT.NONE); 115 label.setText(UpdateUIMessages.FeatureGeneralPropertyPage_ws + extractValue(feature.getWS())); 116 117 label = new Label(group, SWT.NONE); 118 label.setText(UpdateUIMessages.FeatureGeneralPropertyPage_arch + extractValue(feature.getOSArch())); 119 120 label = new Label(group, SWT.NONE); 121 label.setText(UpdateUIMessages.FeatureGeneralPropertyPage_nl + extractValue(feature.getNL())); 122 } 123 124 private void addField(Composite parent, String property, String value) { 125 126 if (value != null && value.length() > 0) { 127 Label label = new Label(parent, SWT.NONE); 128 label.setText(property); 129 130 label = new Label(parent, SWT.NONE); 131 label.setText(getEscapedString(value)); 132 } 133 } 134 135 private String extractValue(String value) { 136 if (value == null || value.equals("*")) return UpdateUIMessages.FeatureGeneralPropertyPage_all; 138 return value; 139 } 140 141 private void addDescription(IFeature feature, Composite parent) { 142 IURLEntry description = feature.getDescription(); 143 if (description != null) { 144 String annotation = description.getAnnotation(); 145 if (annotation != null && annotation.length() > 0) { 146 Group group = new Group(parent, SWT.NONE); 147 group.setText(UpdateUIMessages.FeatureGeneralPropertyPage_desc); 148 group.setLayout(new GridLayout()); 149 group.setLayoutData(new GridData(GridData.FILL_BOTH)); 150 151 Text text = new Text(group, SWT.MULTI | SWT.WRAP); 152 GridData gd = new GridData(GridData.FILL_BOTH); 153 gd.heightHint = 200; 154 gd.widthHint = 350; 155 text.setEditable(false); 156 text.setText(annotation); 157 text.setLayoutData(gd); 158 } 159 } 160 } 161 162 private String getEscapedString(String value) { 163 StringBuffer result = new StringBuffer (value.length() + 10); 164 for (int i = 0; i < value.length(); ++i) { 165 char c = value.charAt(i); 166 if ('&' == c) { 167 result.append("&&"); } else { 169 result.append(c); 170 } 171 } 172 return result.toString(); 173 } 174 } 175 | Popular Tags |