1 11 package org.eclipse.update.internal.ui.properties; 12 13 import java.net.*; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.jface.dialogs.Dialog; 17 import org.eclipse.swt.*; 18 import org.eclipse.swt.events.*; 19 import org.eclipse.swt.graphics.*; 20 import org.eclipse.swt.layout.*; 21 import org.eclipse.swt.widgets.*; 22 import org.eclipse.ui.*; 23 import org.eclipse.ui.dialogs.*; 24 import org.eclipse.update.core.*; 25 import org.eclipse.update.internal.ui.model.*; 26 import org.eclipse.update.internal.ui.parts.*; 27 import org.eclipse.update.internal.ui.UpdateUI; 28 import org.eclipse.update.internal.ui.UpdateUIMessages; 29 30 33 public class FeatureCopyrightPropertyPage extends PropertyPage implements IWorkbenchPropertyPage { 34 37 public FeatureCopyrightPropertyPage() { 38 noDefaultAndApplyButton(); 39 } 40 41 protected Control createContents(Composite parent) { 42 try { 43 IFeatureAdapter adapter = (IFeatureAdapter) getElement(); 44 IFeature feature = adapter.getFeature(null); 45 46 Composite composite = new Composite(parent, SWT.NULL); 47 composite.setLayout(new GridLayout()); 48 49 Label label = new Label(composite, SWT.WRAP); 50 GridData gd = 51 new GridData( 52 GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); 53 gd.widthHint = computeWidthLimit(label, 80); 54 label.setLayoutData(gd); 55 56 IURLEntry copyright = feature.getCopyright(); 57 String annotation = (copyright != null) ? copyright.getAnnotation() : null; 58 59 if (annotation != null && annotation.length() > 0) { 60 label.setText(annotation); 61 final URL url = copyright.getURL(); 62 String filename = (url != null) ? url.getFile() : null; 63 if (filename != null 64 && (filename.endsWith(".htm") || filename.endsWith(".html"))) { Button button = new Button(composite, SWT.PUSH); 66 button.setText(UpdateUIMessages.FeatureCopyrightPropertyPage_showInBrowser); 67 button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); 68 SWTUtil.setButtonDimensionHint(button); 69 button.addSelectionListener(new SelectionAdapter() { 70 public void widgetSelected(SelectionEvent e) { 71 UpdateUI.showURL(url.toExternalForm()); 72 } 73 }); 74 } 75 } else { 76 label.setText(UpdateUIMessages.FeatureCopyrightPropertyPage_noCopyright); 77 } 78 Dialog.applyDialogFont(parent); 79 } catch (CoreException e) { 80 } 81 return null; 82 } 83 84 private int computeWidthLimit(Label label, int nchars) { 85 GC gc = new GC(label); 86 gc.setFont(label.getFont()); 87 FontMetrics fontMetrics= gc.getFontMetrics(); 88 gc.dispose(); 89 return Dialog.convertWidthInCharsToPixels(fontMetrics, nchars); 90 } 91 92 } 93 | Popular Tags |